您應該使用的主要分佈以確保你擁有的一切,並下載了西班牙模特
(點擊此處下載:http://stanfordnlp.github.io/CoreNLP/download.html)
package edu.stanford.nlp.examples;
import edu.stanford.nlp.ling.*;
import edu.stanford.nlp.pipeline.*;
import edu.stanford.nlp.trees.*;
import edu.stanford.nlp.trees.tregex.*;
import edu.stanford.nlp.util.*;
import java.util.*;
public class TregexExample {
public static void main(String[] args) {
// set up pipeline
Properties props = StringUtils.argsToProperties("-props", "StanfordCoreNLP-spanish.properties");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
// Spanish example
Annotation spanishDoc = new Annotation("...insert Spanish text...");
pipeline.annotate(spanishDoc);
// get first sentence
CoreMap firstSentence = spanishDoc.get(CoreAnnotations.SentencesAnnotation.class).get(0);
Tree firstSentenceTree = firstSentence.get(TreeCoreAnnotations.TreeAnnotation.class);
// use Tregex to match
String nounPhrasePattern = "/grup\\.nom/";
TregexPattern nounPhraseTregexPattern = TregexPattern.compile(nounPhrasePattern);
TregexMatcher nounPhraseTregexMatcher = nounPhraseTregexPattern.matcher(firstSentenceTree);
while (nounPhraseTregexMatcher.find()) {
nounPhraseTregexMatcher.getMatch().pennPrint();
}
}
}
感謝。我應該對更改名詞PrasePattern的動詞組進行相同的操作嗎? –
是的,只需將其更改爲「/grup\\.verb/」即可。 – StanfordNLPHelp
完美。非常感謝。 –