使用SharpNL和OpenNLP' en-parser-chunking.bin
,我试图将一个句子解析为一棵树。 SharpNL的一项测试显示,给定一个模型,您可以按如下方式解析句子:
var model = SharpNL.Parser.TreeInsert.Parser.Train("en", parseSamples, headRules, 100, 0);
var parser = ParserFactory.Create(model);
// Tests parsing to make sure the code does not has
// a bug which fails always with a runtime exception
var p = parser.Parse(Parse.ParseParse("She was just another freighter from the " +
"States and she seemed as commonplace as her name ."));
所以我下载了en-parser-chunking.bin文件,从中创建了一个模型以及一个解析器并尝试解析相同的输入:
var parserModelStream = new FileStream(@"en-parser-chunking.bin", FileMode.Open, FileAccess.Read);
var parserModel = new ParserModel(parserModelStream);
var parser = ParserFactory.Create(parserModel);
var p = parser.Parse(Parse.ParseParse("She was just another freighter from the " +
"States and she seemed as commonplace as her name ."));
此代码运行,但是当我在调试器中分析p
时,它有一个TOP头且没有子节点。这是我使用的模型的问题吗?或者我如何使用它?
答案 0 :(得分:1)
而不是:
var p = parser.Parse(Parse.ParseParse("..."));
我只需要使用它:
var p = ParserTool.ParseLine("...", parser, 1);