standFord parser 和dependencyparser 使用说明及其符号含义

首先,下载地址

一、简单实例

1、standFord Parser

from nltk.parse.stanford import StanfordParser
import nltk
import os

if __name__ == '__main__':
    nltk.internals.config_java('C:/Program Files/Java/jdk1.8.0_202/bin/java.exe')
    java_path = "C:/Program Files/Java/jdk1.8.0_202/bin/java.exe"
    os.environ['JAVAHOME'] = java_path
    stanford_parser_dir = 'D:/work/standford_parser/stanford-parser-full-2018-10-17/'
    eng_model_path = "D:/work/standford_parser/stanford-parser-full-2018-10-17/stanford-parser-3.9.2-models/edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz"
    my_path_to_models_jar = stanford_parser_dir + "stanford-parser-3.9.2-models.jar"
    my_path_to_jar = stanford_parser_dir + "stanford-parser.jar"

    parser = StanfordParser(model_path=eng_model_path, path_to_models_jar=my_path_to_models_jar,
                            path_to_jar=my_path_to_jar)

    s = list(parser.parse(
        "The President of th
  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
好的,我了解了你的问题。首先,需要安装Stanford CoreNLP工具包,然后使用Java代码进行句法分析。 下面是一个简单的Java代码示例,可以对输入的句子进行句法分析并输出句法树: ``` import java.util.*; import edu.stanford.nlp.ling.*; import edu.stanford.nlp.pipeline.*; import edu.stanford.nlp.trees.*; import edu.stanford.nlp.util.*; public class ParserExample { public static void main(String[] args) { // set up pipeline properties Properties props = new Properties(); props.setProperty("annotators", "tokenize, ssplit, pos, lemma, parse, sentiment"); // set up Stanford CoreNLP pipeline StanfordCoreNLP pipeline = new StanfordCoreNLP(props); // create an empty Annotation just with the given text Annotation document = new Annotation("This is a complex sentence with a subordinate clause."); // run all Annotators on this text pipeline.annotate(document); // get the Tree object representing the parsed sentence Tree tree = document.get(SentencesAnnotation.class).get(0).get(TreeAnnotation.class); // output the parse tree System.out.println("Parse tree:\n" + tree.toString()); } } ``` 在运行该代码之前,需要先下载并安装Stanford CoreNLP工具包,并将其添加到Java类路径中。运行代码后,会输出句子的句法树,例如: ``` Parse tree: (ROOT (S (NP (DT This)) (VP (VBZ is) (NP (NP (DT a) (JJ complex) (NN sentence)) (PP (IN with) (NP (NP (DT a) (JJ subordinate) (NN clause)))))))) ``` 这就是句子的句法树,可以看出这是一个由主句和从句构成的复杂句。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值