使用Stanford Parser获得句子的K个最佳解析 [英] Get the K best parses of a sentence with Stanford Parser

查看:78
本文介绍了使用Stanford Parser获得句子的K个最佳解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想拥有一个句子的K个最佳解析,我想这可以用ExhaustivePCFGParser类来完成,问题是我不知道如何使用该类,更确切地说,我可以实例化该类吗? (构造函数是:ExhaustivePCFGParser(BinaryGrammar bg,UnaryGrammar ug,Lexicon lex,Options op,Index stateIndex,Index wordIndex,Index tagIndex)),但我不知道如何适合所有这些参数

I want to have the K best parses of a sentence, I figured that this can be done with ExhaustivePCFGParser Class , the problem is that I don't know how to use this class , more precisely haw can I instantiate this class ? ( the constructor is : ExhaustivePCFGParser(BinaryGrammar bg, UnaryGrammar ug, Lexicon lex, Options op, Index stateIndex, Index wordIndex, Index tagIndex) ) but i don't know how to fit all this parameters

是否有更简单的方法来获得K个最佳解析?

Is there any more easy way to have the K best parses ?

推荐答案

通常,您通过LexicalizedParser对象执行操作,该对象是提供所有这些内容(语法,词典,索引等)的语法".

In general you do things via a LexicalizedParser object which is a "grammar" which provides all these things (the grammars, lexicon, indices, etc.).

从命令行执行以下操作:

From the command-line, the following will work:

java -mx500m -cp "*" edu.stanford.nlp.parser.lexparser.LexicalizedParser -printPCFGkBest 20 edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz data/testsent.txt

在API级别,您需要获取 LexicalizedParserQuery 对象.拥有LexicalizedParser lp(如ParserDemo.java中一样)后,您可以执行以下操作:

At the API level, you need to get a LexicalizedParserQuery object. Once you have a LexicalizedParser lp (as in ParserDemo.java) you can do the following:

LexicalizedParser lp = ... // Load / train a model
LexicalizedParserQuery lpq = lp.parserQuery();
lpq.parse(sentence);
List<ScoredObject<Tree>> kBest = lpq.getKBestPCFGParses(20);

A LexicalizedParserQuery 相当于Java正则表达式Matcher.

注意:目前,kBest解析仅对PCFG而不是因式语法有效.

Note: at present kBest parsing works well only for PCFG not factored grammars.

这篇关于使用Stanford Parser获得句子的K个最佳解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆