[英]How to obtain the “Grammatical Relation” using Stanford NLP Parser?
我絕對不熟悉Java開發。
有人可以詳細說明如何使用斯坦福大學的自然語言處理詞匯解析器-開源Java代碼獲取“語法關系”嗎?
謝謝!
請參閱我代碼中第一個文件的第88行, 以編程方式運行Stanford Parser
GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);
Collection tdl = gs.typedDependenciesCollapsed();
System.out.println("words: "+words);
System.out.println("POStags: "+tags);
System.out.println("stemmedWordsAndTags: "+stems);
System.out.println("typedDependencies: "+tdl);
集合tdl是這些類型的依賴項的列表。 如果您在Javadoc上查找TypedDependency,您會發現使用.reln()方法可以使您獲得語法關系。
我的代碼中第三個文件的第311-318行顯示了如何使用該類型的依賴關系列表。 我碰巧得到該關系的名稱,但是您可以得到該關系本身,該關系屬於GrammaticalRelation類。
for( Iterator<TypedDependency> iter = tdl.iterator(); iter.hasNext(); ) {
TypedDependency var = iter.next();
TreeGraphNode dep = var.dep();
TreeGraphNode gov = var.gov();
// All useful information for a node in the tree
String reln = var.reln().getShortName();
別難過,我花了一兩天的時間試圖弄清楚如何使用解析器。 我不知道這些文檔是否有所改進,但是當我使用它們時,它們簡直太糟糕了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.