当前位置: 首页>>代码示例>>Java>>正文


Java IndexedWord.setValue方法代码示例

本文整理汇总了Java中edu.stanford.nlp.ling.IndexedWord.setValue方法的典型用法代码示例。如果您正苦于以下问题:Java IndexedWord.setValue方法的具体用法?Java IndexedWord.setValue怎么用?Java IndexedWord.setValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.stanford.nlp.ling.IndexedWord的用法示例。


在下文中一共展示了IndexedWord.setValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setIsARelation

import edu.stanford.nlp.ling.IndexedWord; //导入方法依赖的package包/类
/** Set the the relation to a is-a relation **/
public void setIsARelation() {
    this.rel = new AnnotatedPhrase();
    IndexedWord beWord = new IndexedWord();
    beWord.setWord("is");
    beWord.setOriginalText("is");
    beWord.setTag(POS_TAG.VBZ);
    beWord.setNER(NE_TYPE.NO_NER);
    beWord.setLemma("be");
    beWord.setValue("is");
    beWord.setIndex(-2);
    this.rel.addWordToList(beWord);
    this.rel.setRoot(beWord);
}
 
开发者ID:gkiril,项目名称:minie,代码行数:15,代码来源:ImplicitExtractions.java

示例2: extractPersonIsNPOfOrg

import edu.stanford.nlp.ling.IndexedWord; //导入方法依赖的package包/类
/** If   ORG+ POS? NP PERSON+ => "PERSON" "is NP of" "ORG" (if there are , and or -> make multiple extractions) **/
public void extractPersonIsNPOfOrg() {
    // Reusable variables
    ObjectArrayList<AnnotatedPhrase> tempProp = new ObjectArrayList<>();
    ObjectArrayList<AnnotatedPhrase> subjects = new ObjectArrayList<>();
    IndexedWord subjRoot;
    IndexedWord objRoot;
    
    this.tPattern = TokenSequencePattern.compile(REGEX.T_ORG_NP_PERSON);
    this.tMatcher = this.tPattern.getMatcher(CoreNLPUtils.getCoreLabelListFromIndexedWordList(this.sentence));
    while (this.tMatcher.find()){    
        // Set the relation to be "is-a" relation
        this.setIsARelation();
        
        for (IndexedWord w: CoreNLPUtils.listOfCoreMapWordsToIndexedWordList(this.tMatcher.groupNodes())) {
            if (w.ner().equals(NE_TYPE.PERSON))
                this.subj.addWordToList(w);
            else if (w.ner().equals(NE_TYPE.ORGANIZATION))
                this.obj.addWordToList(w);
            else if (w.tag().equals(POS_TAG.POS))
                continue;
            else if (w.lemma().equals(CHARACTER.COMMA) || w.lemma().equals("and") || w.lemma().equals("or")) {
                subjRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, this.subj.getWordList());
                subjects.add(new AnnotatedPhrase(this.subj.getWordList().clone(), subjRoot));
                this.subj.clear();
            }
            else this.rel.addWordToList(w);
        }
        subjRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, this.subj.getWordList());
        subjects.add(new AnnotatedPhrase(this.subj.getWordList().clone(), subjRoot));
        objRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, this.obj.getWordList());
        
        IndexedWord ofWord = new IndexedWord();
        ofWord.setWord("of");
        ofWord.setOriginalText("of");
        ofWord.setTag(POS_TAG.IN);
        ofWord.setNER(NE_TYPE.NO_NER);
        ofWord.setLemma("of");
        ofWord.setValue("of");
        ofWord.setIndex(-2);
        this.rel.addWordToList(ofWord);
        
        for (AnnotatedPhrase subject: subjects) {
            // Add the subj/rel/obj to the temporary proposition and then to the real propositions
            subjRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, subject.getWordList());
            tempProp.add(new AnnotatedPhrase(subject.getWordList(), subjRoot));
            tempProp.add(new AnnotatedPhrase(this.rel.getWordList().clone(), this.rel.getRoot()));
            tempProp.add(new AnnotatedPhrase(this.obj.getWordList().clone(), objRoot));
            this.propositions.add(new AnnotatedProposition(tempProp.clone(), new Attribution()));
            tempProp.clear();
        }
        
        // Clean the variables
        this.subj.clear();
        this.obj.clear();
        this.rel.clear();
    }
}
 
开发者ID:gkiril,项目名称:minie,代码行数:59,代码来源:ImplicitExtractions.java

示例3: extractNounPerson

import edu.stanford.nlp.ling.IndexedWord; //导入方法依赖的package包/类
/** If (NP+ PERSON) => "PERSON" "is" "NP" **/
public void extractNounPerson() {
    // Reusable variables
    ObjectArrayList<AnnotatedPhrase> tempProp = new ObjectArrayList<>();
    IndexedWord subjRoot;
    IndexedWord objRoot;
    
    // Set the relation to be "is-a" relation
    this.setIsARelation();
    
    this.tPattern = TokenSequencePattern.compile(REGEX.T_NP_PERSON);
    this.tMatcher = this.tPattern.getMatcher(CoreNLPUtils.getCoreLabelListFromIndexedWordList(this.sentence));
    while (this.tMatcher.find()){         
        for (IndexedWord w: CoreNLPUtils.listOfCoreMapWordsToIndexedWordList(this.tMatcher.groupNodes())) {
            if (w.ner().equals(NE_TYPE.PERSON)) {
                this.subj.addWordToList(w);
            }
            else {
                if (w.lemma().toLowerCase().equals("mrs.") || w.lemma().toLowerCase().equals("ms.") || 
                    w.lemma().toLowerCase().equals("mrs") || w.lemma().toLowerCase().equals("ms")) {
                    IndexedWord female = new IndexedWord();
                    female.setWord("female");
                    female.setOriginalText("female");
                    female.setTag(POS_TAG.NN);
                    female.setNER(NE_TYPE.NO_NER);
                    female.setLemma("female");
                    female.setValue("female");
                    female.setIndex(-2);
                    this.obj.addWordToList(female);
                }
                else if (w.lemma().toLowerCase().equals("mr.") || w.lemma().toLowerCase().equals("mr")) {
                    IndexedWord male = new IndexedWord();
                    male.setWord("male");
                    male.setOriginalText("male");
                    male.setTag(POS_TAG.NN);
                    male.setNER(NE_TYPE.NO_NER);
                    male.setLemma("male");
                    male.setValue("male");
                    male.setIndex(-2);
                    this.obj.addWordToList(male);
                }
                else if (Polarity.NEG_WORDS.contains(w.lemma().toLowerCase())) {
                    continue;
                }
                else {
                    this.obj.addWordToList(w);
                }
            }
        }
            
        // Add the subj/rel/obj to the temporary proposition and then to the real propositions
        subjRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, this.subj.getWordList());
        objRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, this.obj.getWordList());
        tempProp.add(new AnnotatedPhrase(this.subj.getWordList().clone(), subjRoot));
        tempProp.add(new AnnotatedPhrase(this.rel.getWordList().clone(), this.rel.getRoot()));
        tempProp.add(new AnnotatedPhrase(this.obj.getWordList().clone(), objRoot));
        this.propositions.add(new AnnotatedProposition(tempProp.clone(), new Attribution()));
            
        // Clean the variables
        tempProp.clear();
        this.subj.clear();
        this.obj.clear();
    }

    // Clear the relation
    this.rel.clear();
}
 
开发者ID:gkiril,项目名称:minie,代码行数:68,代码来源:ImplicitExtractions.java

示例4: addApposClause

import edu.stanford.nlp.ling.IndexedWord; //导入方法依赖的package包/类
/** Generates a clause from an apposition 
 * @param subject The subject of the clause (first argument of the appos relation)
 * @param object  The object of the clause (second argument of the appos relation)
 */
private static void addApposClause(ClausIE clausIE, IndexedWord subject, IndexedWord object) {
    Clause clause = new Clause();
    clause.setSubject(0);
    clause.verb = 1;
    clause.complement = 2;
    Clause.Type clauseType = Clause.Type.SVC;
    Constituent.Type argumentConstType = Constituent.Type.COMPLEMENT;
    
    // Create a relation phrase with the possessive verb 'is' 
    Phrase apposPhrase = new Phrase();
    IndexedWord appositionVerb = new IndexedWord();
    appositionVerb.setWord("is");
    appositionVerb.setTag(POS_TAG.VBZ);
    appositionVerb.setNER(NE_TYPE.NO_NER);
    appositionVerb.setLemma("be");
    appositionVerb.setValue("be");
    appositionVerb.setIndex(-2);
    apposPhrase.addWordToList(appositionVerb);
    apposPhrase.setRoot(appositionVerb);
    
    PhraseConstituent verbConstit = new PhraseConstituent(apposPhrase, Constituent.Type.VERB);
    
    if (subject.ner().equals(NE_TYPE.DATE) || object.ner().equals(NE_TYPE.DATE))
        return;
    if (subject.ner().equals(NE_TYPE.TIME) || object.ner().equals(NE_TYPE.TIME))
        return;
    
    // If both the subject and the objects are LOCATION-ners, then clause type is SVA and the appos. verb "is in" 
    if ((subject.ner().equals(NE_TYPE.ORGANIZATION) || 
            subject.ner().equals(NE_TYPE.LOCATION)) && object.ner().equals(NE_TYPE.LOCATION)){
        clauseType = Clause.Type.SVA;
        
        // Create a relation phrase with the verb 'is' and the preposition 'in'
        IndexedWord prepWord = new IndexedWord();
        prepWord.setWord("in");
        prepWord.setTag(POS_TAG.IN);
        prepWord.setNER(NE_TYPE.NO_NER);
        prepWord.setLemma("in");
        prepWord.setValue("in");
        prepWord.setIndex(-2);
        apposPhrase.addWordToList(prepWord);
        
        verbConstit = new PhraseConstituent(apposPhrase, Constituent.Type.VERB);
        argumentConstType = Constituent.Type.ADVERBIAL;
        clause.adverbials.add(2);
        clause.complement = -1;
    }
    
    clause.constituents.add(new IndexedConstituent(clausIE.getSemanticGraph(), subject, Constituent.Type.SUBJECT));
    clause.constituents.add(verbConstit);
    clause.constituents.add(new IndexedConstituent(clausIE.getSemanticGraph(), object, argumentConstType));
    clause.setType(clauseType);
    clausIE.getClauses().add(clause);
}
 
开发者ID:gkiril,项目名称:minie,代码行数:59,代码来源:ClauseDetector.java

示例5: addPossessiveClause

import edu.stanford.nlp.ling.IndexedWord; //导入方法依赖的package包/类
/** Generates a clause from a possessive relation
* @param subject The subject of the clause
* @param object  The object of the clause 
*/
private static void addPossessiveClause(ClausIE clausIE, IndexedWord subject, IndexedWord object) {
    Clause clause = new Clause();
    SemanticGraph newSemanticGraph = new SemanticGraph(clausIE.getSemanticGraph());
    clause.setSubject(0);
    clause.verb = 1;
    clause.dobjects.add(2);
    Set<IndexedWord> excludesub = new TreeSet<IndexedWord>();
    Set<IndexedWord> excludeobj = new TreeSet<IndexedWord>();

    excludeobj.add(subject);
    List<SemanticGraphEdge> outedobj = newSemanticGraph.getOutEdgesSorted(object);
    excludeVertexPoss(outedobj, excludeobj, clausIE);

    SemanticGraphEdge rcmod = null;
    if (subject.tag().charAt(0) == 'W') {
        IndexedWord root = newSemanticGraph.getParent(object); 
        if (root != null){
            if (root.tag().equals(POS_TAG.IN)){
                root = newSemanticGraph.getParent(root); // "I saw the man in whose wife I trust"
            }
            List<SemanticGraphEdge> inedges = newSemanticGraph.getIncomingEdgesSorted(root);
            rcmod = DpUtils.findFirstOfRelation(inedges, EnglishGrammaticalRelations.RELATIVE_CLAUSE_MODIFIER);
        }
    } else {
        List<SemanticGraphEdge> outedges = newSemanticGraph.getOutEdgesSorted(subject);
        SemanticGraphEdge ps = DpUtils.findFirstOfRelation(outedges, EnglishGrammaticalRelations.POSSESSIVE_MODIFIER);
        if (ps != null){
            excludesub.add(ps.getDependent());
        }
    }

    if (rcmod != null) {
        clause.constituents.add(createRelConstituent(newSemanticGraph, rcmod.getGovernor(), Type.SUBJECT));
        // To avoid the s in  "Bill's clothes are great".
        ((IndexedConstituent) clause.constituents.get(0)).getExcludedVertexes().addAll(excludesub);
    } else {
        clause.constituents.add(new IndexedConstituent(newSemanticGraph, subject, Collections.<IndexedWord> emptySet(), 
                                                        excludesub, Type.SUBJECT));
    }
    
    // Create a relation phrase with the possessive verb 'has'
    Phrase possPhrase = new Phrase();
    IndexedWord possessiveVerb = new IndexedWord();
    possessiveVerb.setWord("has");
    possessiveVerb.setTag(POS_TAG.VBZ);
    possessiveVerb.setNER(NE_TYPE.NO_NER);
    possessiveVerb.setLemma("have");
    possessiveVerb.setValue("has");
    possessiveVerb.setIndex(-2);
    possPhrase.addWordToList(possessiveVerb);
    possPhrase.setRoot(possessiveVerb);
    
    clause.constituents.add(new PhraseConstituent(possPhrase, Constituent.Type.VERB));
    clause.constituents.add(new IndexedConstituent(newSemanticGraph, object, Collections.<IndexedWord> emptySet(), 
                                                    excludeobj, Constituent.Type.DOBJ));
    clause.setType(Clause.Type.SVO);
    clausIE.getClauses().add(clause);
}
 
开发者ID:gkiril,项目名称:minie,代码行数:63,代码来源:ClauseDetector.java


注:本文中的edu.stanford.nlp.ling.IndexedWord.setValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。