當前位置: 首頁>>代碼示例>>Java>>正文


Java CoreLabel.setLemma方法代碼示例

本文整理匯總了Java中edu.stanford.nlp.ling.CoreLabel.setLemma方法的典型用法代碼示例。如果您正苦於以下問題:Java CoreLabel.setLemma方法的具體用法?Java CoreLabel.setLemma怎麽用?Java CoreLabel.setLemma使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在edu.stanford.nlp.ling.CoreLabel的用法示例。


在下文中一共展示了CoreLabel.setLemma方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: namedEntityDictionaryMinimization

import edu.stanford.nlp.ling.CoreLabel; //導入方法依賴的package包/類
/** Given a phrase, if it contains NERs, make a dictionary minimization around them **/
public void namedEntityDictionaryMinimization(List<CoreMap> remWords, List<CoreMap> matchWords){
    // If (.* DT+ [RB|JJ]* NER+ .*) => drop (DT+)
    this.tPattern = TokenSequencePattern.compile(REGEX.T_RB_JJ_NER);
    this.tMatcher = tPattern.getMatcher(this.phrase.getWordCoreLabelList());
    while (this.tMatcher.find()){         
        matchWords = tMatcher.groupNodes();
        
        for (CoreMap cm: matchWords){
            CoreLabel cl = new CoreLabel(cm);
            if (cl.lemma() == null) cl.setLemma(cl.word());
            
            // Check if the word is DT, drop it
            if ((CoreNLPUtils.isAdj(cl.tag()) || CoreNLPUtils.isAdverb(cl.tag())) 
                    && cl.ner().equals(NE_TYPE.NO_NER)){
                remWords.add(cm);   
            }
        }
        
        // Drop the words not found in dict. 
        this.dropWordsNotFoundInDict(matchWords, remWords);
    }
    
    // Do the safe minimization
    this.namedEntitySafeMinimization(remWords, matchWords);
}
 
開發者ID:gkiril,項目名稱:minie,代碼行數:27,代碼來源:Minimization.java

示例2: verbPhraseSafeMinimization

import edu.stanford.nlp.ling.CoreLabel; //導入方法依賴的package包/類
/** Given a phrase, if it contains a verb phrase, make a verb phrase safe minimization **/
public void verbPhraseSafeMinimization(List<CoreMap> remWords, List<CoreMap> matchWords){
    // Flags for checking certain conditions
    boolean isAdverb;
    boolean isNotNER;
    boolean containsNEG;
    
    // If the relation starts with a RB+ VB+, drop RB+
    this.tPattern = TokenSequencePattern.compile(REGEX.T_RB_VB);
    this.tMatcher = tPattern.getMatcher(this.phrase.getWordCoreLabelList());
    while (this.tMatcher.find()){   
        matchWords = tMatcher.groupNodes();
        
        for (CoreMap cm: matchWords){
            CoreLabel cl = new CoreLabel(cm);
            if (cl.lemma() == null) cl.setLemma(cl.word());
            
            isAdverb = CoreNLPUtils.isAdverb(cl.tag());
            isNotNER = cl.ner().equals(NE_TYPE.NO_NER);
            containsNEG = Polarity.NEG_WORDS.contains(cl.lemma().toLowerCase());
            
            // Check if the word is RB which is not a NER
            if (isAdverb && isNotNER && !containsNEG){
                remWords.add(cm);   
            }
        }
        this.dropWords(remWords, matchWords);
    }
}
 
開發者ID:gkiril,項目名稱:minie,代碼行數:30,代碼來源:Minimization.java

示例3: lemmatize

import edu.stanford.nlp.ling.CoreLabel; //導入方法依賴的package包/類
private List<CoreLabel> lemmatize(List<CoreLabel> words) {
    Morphology lemmatizer = new Morphology();
    for (CoreLabel word : words) {
        word.setLemma(lemmatizer.lemma(word.word(), word.tag()));
    }
    return words;
}
 
開發者ID:clearwsd,項目名稱:clearwsd,代碼行數:8,代碼來源:StanfordDependencyParser.java

示例4: removeVerbsBeforeNouns

import edu.stanford.nlp.ling.CoreLabel; //導入方法依賴的package包/類
/** Given a phrase, if there is (DT* VB+ NN+), remove (DT* VB+) */
public void removeVerbsBeforeNouns(List<CoreMap> remWords, List<CoreMap> matchWords){
    // Flags for checking certain conditions
    boolean isDT;
    boolean isVerb;
    boolean isNotNER;
    boolean containsNEG;
    boolean hasDT = false;
    
    this.tPattern = TokenSequencePattern.compile(REGEX.T_DT_VB_NN_END);
    this.tMatcher = tPattern.getMatcher(this.phrase.getWordCoreLabelList());
    while (this.tMatcher.find()){
        matchWords = tMatcher.groupNodes();
        
        for (CoreMap cm: matchWords){
            CoreLabel cl = new CoreLabel(cm);
            if (cl.lemma() == null) cl.setLemma(cl.word());
            // Check if the word is a determiner, no ner and the first word in the phrase
            isDT = cl.tag().equals(POS_TAG.DT);
            isNotNER = cl.ner().equals(NE_TYPE.NO_NER);
            containsNEG = Polarity.NEG_WORDS.contains(cl.lemma().toLowerCase());
            isVerb = CoreNLPUtils.isVerb(cl.tag());
            
            if (isDT && isNotNER && !containsNEG){
                if (cl.index() == this.phrase.getWordCoreLabelList().get(0).index()){
                    remWords.add(cm);
                    hasDT = true;
                } else break;
            }
            // Check if the word is a verb, no ner
            else if (isVerb && isNotNER && !containsNEG){
                // If it's not preceded by DT, check if it's the first word in the phrase
                if (!hasDT) {
                    if (cl.index() == this.phrase.getWordCoreLabelList().get(0).index()){
                        if (!this.sg.hasChildren(new IndexedWord(cl))){
                            remWords.add(cm);
                        }
                    } else break;
                } else {
                    if (!this.sg.hasChildren(new IndexedWord(cl))){
                        remWords.add(cm);
                    }
                }
            }
        }
        
        // If the multi-word expression is found in the dictionary - don't drop it
        if (this.isCoreMapListInDictionary(matchWords)){
            matchWords.clear();
            remWords.clear();
            continue;
        }
        
        this.dropWords(remWords, matchWords);
    }
}
 
開發者ID:gkiril,項目名稱:minie,代碼行數:57,代碼來源:Minimization.java


注:本文中的edu.stanford.nlp.ling.CoreLabel.setLemma方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。