/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package aspects_doublepropagation;
import java.util.*;
import preprocessing.*;
import java.io.*;
import java.util.ArrayList;
import mira.token;
import seekfeel.dataholders.Review;
import seekfeel.utilities.stanfordwrapper.DependencyRelation;
import seekfeel.utilities.stanfordwrapper.ParsedData;
import seekfeel.utilities.stanfordwrapper.WordPos;
/**
*
* @author Tarek
*/
public class DoublePropagationManager {
PreProcessor pr ;
DoublePropServices dp;
ArrayList<WordPos> posTags = new ArrayList<WordPos>();
ArrayList<String> words = new ArrayList<String>();
public DoublePropagationManager()
{
pr = new PreProcessor();
dp = new DoublePropServices();
dp.initialize();
}
public void updateDictionary()
{
Collection<DictionaryEntry> values = Lexicons.reviewTargets.values();
ArrayList<String> list = new ArrayList<String>(Lexicons.reviewTargets.keySet());
int index = 0;
for(DictionaryEntry dic : values)
{
String extFeat = list.get(index);
index++;
Lexicons.targetDictionary.put(extFeat,dic);
}
values = Lexicons.reviewOpinions.values();
list = new ArrayList<String>(Lexicons.reviewOpinions.keySet());
index = 0;
for(DictionaryEntry dic : values)
{
String extOp = list.get(index);
index++;
Lexicons.opinionDictionary.put(extOp, dic);
}
}
void processor(Review r)
{
}
private void setWordsPos(Formatted_Text sentence)
{
ArrayList<token> tokens = sentence.getTokenizedSentence();
int index =0;
for(token t : tokens)
{
WordPos wordPos = new WordPos();
wordPos.setWordTag(t.getPos());
wordPos.setWordIndex(index);
index++;
posTags.add(wordPos);
words.add(t.getWord());
}
}
public ArrayList<String> extractAspects(Review r) throws IOException
{
ParsedData parsedData = new ParsedData();
boolean skipReview = false;
// ArrayList<ArrayList<String>> cleanSentences = pr.process(r, dp.textpro);
do
{
Lexicons.reviewTargets.clear();
Lexicons.reviewOpinions.clear();
int sentenceNum = r.Review_Sentences.size();
try
{
for(int j =0; j < r.formatedSentences.size(); j++)
{
Formatted_Text sentence = r.formatedSentences.get(j);
ArrayList<DependencyRelation> depRelation = sentence.getTextDependencyRelations();
setWordsPos(sentence);
parsedData.setDependencyRelations(depRelation);
parsedData.setTaggedWords(posTags);
dp.setParsedData(parsedData);
dp.extractTargets(words);
posTags.clear();
words.clear();
}
updateDictionary();
for(int j =0; j < r.formatedSentences.size(); j++)
{
Formatted_Text sentence = r.formatedSentences.get(j);
ArrayList<DependencyRelation> depRelation = sentence.getTextDependencyRelations();
setWordsPos(sentence);
parsedData.setDependencyRelations(depRelation);
parsedData.setTaggedWords(posTags);
dp.setParsedData(parsedData);
dp.partWholeRel(words);
posTags.clear();
words.clear();
}
updateDictionary();
}
catch(Exception e)
{
skipReview = true;
continue;
}
Lexicons.reviewTargets.clear();
Lexicons.reviewOpinions.clear();
try
{
//ArrayList<ArrayList<String>> cleanSentences = pr.process(r, dp.textpro);
for(int j =0; j < r.formatedSentences.size(); j++)
{
Formatted_Text sentence = r.formatedSentences.get(j);
ArrayList<DependencyRelation> depRelation = sentence.getTextDependencyRelations();
setWordsPos(sentence);
parsedData.setDependencyRelations(depRelation);
parsedData.setTaggedWords(posTags);
dp.setParsedData(parsedData);
dp.expandLexicon(words);
posTags.clear();
words.clear();
}
updateDictionary();
}
catch(Exception e)
{
skipReview = true;
continue;
}
}while(!Lexicons.reviewTargets.isEmpty() || !Lexicons.reviewOpinions.isEmpty());
if(!skipReview)
{
}
ArrayList<String> aspects = new ArrayList<String>(Lexicons.targetDictionary.keySet());
Lexicons.targetDictionary.clear();
SentenceOperations.clearReviewNouns();
return aspects;
}
}