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…的问题解决
486 0
‘settings.xml’ has syntax errors less… 和Parent ‘org.springframework.boot’has problems less…的问题解决
|
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为非常量值的情况。
9456 0
|
4月前
|
Java
flyway报错Correct the classpath of your application so that it contains compatible versions of the
flyway报错Correct the classpath of your application so that it contains compatible versions of the
105 1
|
7月前
|
Java API Apache
Apache POI(Poor Obfuscation Implementation
Apache POI(Poor Obfuscation Implementation
198 0
poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]
poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]
418 0
|
机器学习/深度学习 人工智能 自然语言处理
One SPRING to Rule Them Both Symmetric AMR Semantic Parsing and Generation without Complex Pipeline
在文本到AMR解析中,当前最先进的语义解析器集成了几个不同模块或组件的繁琐管道,并利用图重新分类,即在训练集的基础上开发的一组特定内容的启发式方法。
140 0
|
JavaScript 前端开发
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression...
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression...
151 0
|
分布式计算 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
95 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
|
机器学习/深度学习 缓存 自然语言处理
【CS224n】(assignment3)Dependency Parsing
多问题都可以转为分类问题,基于转移的依存句法分析器就由预测树结构问题转为预测动作序列问题。 有一种方法:
261 0
【CS224n】(assignment3)Dependency Parsing