Stanford Parser - Constituent to Dependency Conversion

简介: Constituent to Dependency Conversion目的:已经处理好的短语句法分析树转成依存句法分析树短语句法分析的例子:(ROOT (IP-HLN (NP-SBJ (NP-PN (NR 中国...

Constituent to Dependency Conversion

目的:已经处理好的短语句法分析树转成依存句法分析树

短语句法分析的例子:

(ROOT (IP-HLN (NP-SBJ (NP-PN (NR 中国)) (ADJP (JJ 最大)) (NP (NN 氨纶丝) (NN 生产) (NN 基地))) (VP (PP-LOC (P 在) (NP-PN (NR 连云港))) (VP (VV 建成)))))

依存句法分析的例子:

[nn(基地-5, 中国-1), amod(基地-5, 最大-2), nn(基地-5, 氨纶丝-3), nn(基地-5, 生产-4), nsubj(建成-8, 基地-5), prep(建成-8, 在-6), pobj(在-6, 连云港-7), root(ROOT-0, 建成-8)]

或者

1 中国 _ NR NR _ 5 nn _ _
2 最大 _ ADJ JJ _ 5 amod _ _
3 氨纶丝 _ NOUN NN _ 5 nn _ _
4 生产 _ NOUN NN _ 5 nn _ _
5 基地 _ NOUN NN _ 8 nsubj _ _
6 在 _ P P _ 7 case _ _
7 连云港 _ NR NR _ 8 prep _ _
8 建成 _ VV VV _ 0 root _ _

具体代码

这里需要导入https://nlp.stanford.edu/software/lex-parser.shtml#Download最新的包

    TreebankLanguagePack ctlp = new ChineseTreebankLanguagePack();
    //ctlp.setGenerateOriginalDependencies(true);
    Predicate<String> predicate = (v1) -> {
           return true;
       }; 
    GrammaticalStructureFactory gsf = ctlp.grammaticalStructureFactory(predicate);
    String str = "(ROOT (IP-HLN (NP-SBJ (NP-PN (NR 中国)) (ADJP (JJ 最大)) (NP (NN 氨纶丝) (NN 生产) (NN 基地))) (VP (PP-LOC (P 在) (NP-PN (NR 连云港))) (VP (VV 建成)))))";
    Tree parseTree = Tree.valueOf(str);
    GrammaticalStructure gs = gsf.newGrammaticalStructure(parseTree);
    Collection<TypedDependency> tdl = gs.typedDependencies();
    System.out.println(tdl);

如果需要保留标点符号,或者生成更加Conll格式,最好使用老版本的jar包。

相关文章
|
缓存 Ubuntu Java
‘settings.xml’ has syntax errors less… 和Parent ‘org.springframework.boot’has problems less…的问题解决
‘settings.xml’ has syntax errors less… 和Parent ‘org.springframework.boot’has problems less…的问题解决
310 0
‘settings.xml’ has syntax errors less… 和Parent ‘org.springframework.boot’has problems less…的问题解决
|
JSON Java 数据格式
springboot后台下载文件报错: Could not find acceptable representation
使用springboot实现从服务器下载文件功能时,报错:Could not find acceptable representation
1175 0
|
Java Maven
Maven - Error:java: Annotation processing is not supported for module cycles. Please ensure that all
Maven - Error:java: Annotation processing is not supported for module cycles. Please ensure that all
766 0
Maven - Error:java: Annotation processing is not supported for module cycles. Please ensure that all
|
Java Maven
Maven3 package时报 &#39;version&#39; contains an expression but should be a constant
父pom文件: 4.0.0 com.wey WEY ${com.wey.version} pom 子Module 4.0.0 com.wey WEY ${com.wey.version} pom package web工程时报 'version' contains an expression but should be a constant这个错误提示,这是因为Maven3 不允许出现version为非常量值的情况。
9229 0
|
8月前
|
机器学习/深度学习 人工智能 自然语言处理
One SPRING to Rule Them Both Symmetric AMR Semantic Parsing and Generation without Complex Pipeline
在文本到AMR解析中,当前最先进的语义解析器集成了几个不同模块或组件的繁琐管道,并利用图重新分类,即在训练集的基础上开发的一组特定内容的启发式方法。
84 0
|
9月前
|
JSON 数据格式
UE4 structure and JSON conversion - DTBPJson plugin description
UE4 structure and JSON conversion - DTBPJson plugin description
57 0
|
10月前
|
JavaScript 前端开发
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression...
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression...
108 0
|
前端开发 Java
java:How to use variable parameter? (easy to understand)
It's the first time to write a blog in English for me. (About variable parameter)
70 0
java:How to use variable parameter? (easy to understand)
|
分布式计算 Apache Spark
《How to Integrate Spark MLlib and Apache Solr to Build Real-Time Entity Type Recognition System for Better Query Understanding》电子版地址
How to Integrate Spark MLlib and Apache Solr to Build Real-Time Entity Type Recognition System for Better Query Understanding
59 0
《How to Integrate Spark MLlib and Apache Solr to Build Real-Time Entity Type Recognition System for Better Query Understanding》电子版地址
Caused by: org.yaml.snakeyaml.parser.ParserException: while parsing a block mapping
Caused by: org.yaml.snakeyaml.parser.ParserException: while parsing a block mapping
Caused by: org.yaml.snakeyaml.parser.ParserException: while parsing a block mapping