本文整理匯總了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);
}
示例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);
}
}
示例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;
}
示例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);
}
}