Package aspects_doublepropagation

Source Code of aspects_doublepropagation.DoublePropServices

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package aspects_doublepropagation;
import java.io.IOException;
//import CaseCorrection.*;
import java.util.ArrayList;
import edu.stanford.nlp.ling.Word;
import java.util.logging.Level;
import java.util.logging.Logger;
import seekfeel.utilities.stanfordwrapper.ParsedData;
import seekfeel.utilities.stanfordwrapper.ParsingOptions;
import seekfeel.utilities.stanfordwrapper.StanfordParser;
import seekfeel.utilities.stanfordwrapper.StringToWordsTokenizer;

/**
*
* @author Tarek
*/
public class DoublePropServices {
    static ArrayList<Integer> nounIndexes = new ArrayList<Integer>();
    static ArrayList<Integer> opinionIndexes = new ArrayList<Integer>();
    StanfordParser stParser;
    ParsedData parsedData;
    JtextWrap textpro;
    RuleChecker rc = new RuleChecker();
    public void setParsedData(ParsedData pData)
    {
        parsedData = pData;
    }
    public JtextWrap getTextpro()
    {
        return textpro;
    }
    static private void loadDictionaries()
    {
                String path = "inquiryNeg.txt";
                Lexicons.fillNegSentiWordLexicon(path);
                path = "inquiryPos.txt";
                Lexicons.fillPosSentiWordLexicon(path);
                path = "subjclueslen1-HLTEMNLP05.tff";
                try
                {
                    Lexicons.fillSeedWords(path);
                }
                catch (IOException ex)
                {
                    Logger.getLogger(DoublePropServices.class.getName()).log(Level.SEVERE, null, ex);
                }
                DictionaryEntry dic = new DictionaryEntry();
                dic.source = "";
                dic.polarity = 0;
    path = "relations.txt";
    Lexicons.fillDependenciesDictionary(path);
                Lexicons.fillprepositionRelations();
                Lexicons.fillDealerWords();
                Lexicons.fillNoWords();
                Lexicons.fillProductWords();
                Lexicons.fillPossesiveWords();
  }
        public void initialize()
        {
            loadDictionaries();
      parsedData  = new ParsedData();        // create ParsedData object
            textpro = new JtextWrap();
            textpro.initialize();
        }
        private ArrayList<Word> getWords(String sentence)
        {
            ArrayList<Word> words = StringToWordsTokenizer.tokenize(sentence);
            return words;
        }
        private ArrayList<String> converWordToString(ArrayList<Word> words)
        {
            ArrayList<String> tokens = new ArrayList<String>();
            for(int i =0; i < words.size(); i++)
            {
                tokens.add(words.get(i).toString());
            }
            return tokens;
        }
        private ParsedData parse(ArrayList<Word> words)
        {
            ParsingOptions opts = new ParsingOptions();
            opts.setPosTag(true);
            opts.setParseRelations(true);
            ParsedData resultData = stParser.parse(words, opts);
            return resultData;

        }
  public void extractTargets(ArrayList<String> st)
        {
                boolean rule1_1, rule1_2, rule4_1, rule4_2;
        //String[] sentences = SentenceOperations.getSentences(reviewBody);  // divide review into senten
          //st = SentenceOperations.tokenize(sentences[m].trim());   // divide the sentence into words
                        //st = new ArrayList(Arrays.asList(sentences.get(m)));

                    //st = (ArrayList)textpro.tokenize(sentence);
                //st = converWordToString(words);
                //parsedData = parse(st);       // parse sentence
                //ArrayList<DependencyRelation> dep =  mp.parse(sentence, st);
                //parsedData.setDependencyRelations(dep);
                st = SentenceOperations.toLowerCase(st);
                nounIndexes = SentenceOperations.extractTargets(parsedData,st); // gets the nouns and adjectives in the sentence and put their indexes in noundIndexes and opinionIndexes respectively
                opinionIndexes = SentenceOperations.extractOpinions(parsedData,st);
                rc.setAttributes(parsedData, nounIndexes, opinionIndexes, st, textpro);
                if (!(nounIndexes.isEmpty()))//&& !Lexicons.targetDictionary.containsKey(st.get(nounIndexes.get(0))))  // if the sentence contains a noun and this noun is not in the target dictionary
                {
                        nounIndexes = rc.checkProductIndi();
                        nounIndexes = rc.checkDealerIndi();
                        //#check nounPhrase
                         rule1_1 = rc.checkRule1_1();      //Rules1_1 and 1_2 gets a target from an opinion word
                         rule1_2 = rc.checkRule1_2();
                         int y = 0;
                }
                if (!(opinionIndexes.isEmpty()))
                {
                         rule4_1 = rc.checkRule4_1();   // Rules 4_1 and 4_2 gets an opinion word from an opinion word
                         rule4_2 = rc.checkRule4_2();
                }

                SentenceOperations.updateNounCounts(nounIndexes, st);
                rc.checkNoPattern(st, nounIndexes);
                opinionIndexes.clear();
                nounIndexes.clear();

       
        }
        public void partWholeRel(ArrayList<String> st)
        {
             //////////////////////////Part Whole //////////////////////
                String freqNoun = SentenceOperations.getMostFreqNoun();
                st = SentenceOperations.toLowerCase(st);
                nounIndexes = SentenceOperations.extractTargets(parsedData,st); // gets the nouns and adjectives in the sentence and put their indexes in noundIndexes and opinionIndexes respectively
                opinionIndexes = SentenceOperations.extractOpinions(parsedData,st);
                rc.setAttributes(parsedData, nounIndexes, opinionIndexes, st, textpro);
                if (!freqNoun.equals(""))
                    rc.checkPartWholePattern(freqNoun);      
        }
        public void expandLexicon(ArrayList<String> st)
        {
            st = SentenceOperations.toLowerCase(st);
            nounIndexes = SentenceOperations.extractTargets(parsedData,st); // gets the nouns and adjectives in the sentence and put their indexes in noundIndexes and opinionIndexes respectively
            opinionIndexes = SentenceOperations.extractOpinions(parsedData,st);
            if(!nounIndexes.isEmpty())
            {
                rc.setAttributes(parsedData, nounIndexes, opinionIndexes, st, textpro);
                boolean rule3_1 = rc.checkRule3_1();            // Rules 3_1 and 3_2 gets a target from a target
                boolean rule3_2 = rc.checkRule3_2();
            }
            if(!opinionIndexes.isEmpty())
            {
                boolean rule2_1 = rc.checkRule2_1();      // Rules 2_1 and 2_2 gets an opinion word from a target
                boolean rule2_2 = rc.checkRule2_2();
            }
         }
}
TOP

Related Classes of aspects_doublepropagation.DoublePropServices

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.