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…的问题解决
445 0
‘settings.xml’ has syntax errors less… 和Parent ‘org.springframework.boot’has problems less…的问题解决
|
2月前
|
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
90 1
|
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为非常量值的情况。
9383 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]
323 0
|
机器学习/深度学习 人工智能 自然语言处理
One SPRING to Rule Them Both Symmetric AMR Semantic Parsing and Generation without Complex Pipeline
在文本到AMR解析中,当前最先进的语义解析器集成了几个不同模块或组件的繁琐管道,并利用图重新分类,即在训练集的基础上开发的一组特定内容的启发式方法。
129 0
|
JavaScript 前端开发
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression...
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression...
144 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
87 0
《How to Integrate Spark MLlib and Apache Solr to Build Real-Time Entity Type Recognition System for Better Query Understanding》电子版地址
|
存储 算法 测试技术
【论文阅读】(2022)A goal-driven ruin and recreate heuristic for the 2D variable-sized bin packing prob...
【论文阅读】(2022)A goal-driven ruin and recreate heuristic for the 2D variable-sized bin packing prob...
126 0
【论文阅读】(2022)A goal-driven ruin and recreate heuristic for the 2D variable-sized bin packing prob...
《AVPASS-Leaking-And-Bypassing-Anitvirus-Detection-Model-Automatically》电子版地址
AVPASS-Leaking-And-Bypassing-Anitvirus-Detection-Model-Automatically
59 0
《AVPASS-Leaking-And-Bypassing-Anitvirus-Detection-Model-Automatically》电子版地址
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