上的端口和移民法案提交由參議員布朗巴克,堪薩斯CoreNLP斯坦福依賴格式
的 共和黨從上面的句子,我期待得到以下類型的依賴關係:
nsubjpass(submitted, Bills)
auxpass(submitted, were)
agent(submitted, Brownback)
nn(Brownback, Senator)
appos(Brownback, Republican)
prep_of(Republican, Kansas)
prep_on(Bills, ports)
conj_and(ports, immigration)
prep_on(Bills, immigration)
這應該是可能根據表1,圖1的文件Stanford Dependencies。
使用下面的代碼,我只能夠達到以下依賴化妝(代碼輸出,這一點):
root(ROOT-0, submitted-7)
nmod:on(Bills-1, ports-3)
nmod:on(Bills-1, immigration-5)
case(ports-3, on-2)
cc(ports-3, and-4)
conj:and(ports-3, immigration-5)
nsubjpass(submitted-7, Bills-1)
auxpass(submitted-7, were-6)
nmod:agent(submitted-7, Brownback-10)
case(Brownback-10, by-8)
compound(Brownback-10, Senator-9)
punct(Brownback-10, ,-11)
appos(Brownback-10, Republican-12)
nmod:of(Republican-12, Kansas-14)
case(Kansas-14, of-13)
問題 - 如何實現上述期望的輸出?
代碼
public void processTestCoreNLP() {
String text = "Bills on ports and immigration were submitted " +
"by Senator Brownback, Republican of Kansas";
Annotation annotation = new Annotation(text);
Properties properties = PropertiesUtils.asProperties(
"annotators", "tokenize,ssplit,pos,lemma,depparse"
);
AnnotationPipeline pipeline = new StanfordCoreNLP(properties);
pipeline.annotate(annotation);
for (CoreMap sentence : annotation.get(SentencesAnnotation.class)) {
SemanticGraph sg = sentence.get(EnhancedPlusPlusDependenciesAnnotation.class);
Collection<TypedDependency> dependencies = sg.typedDependencies();
for (TypedDependency td : dependencies) {
System.out.println(td);
}
}
}
是什麼代碼實際打印出來,然後呢? – errantlinguist
不明確的道歉。代碼輸出第二個依賴關係塊。我編輯得更清楚。 – gimg1