0

使用SharpNLOpenNLPen-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 的 Head 并且没有孩子。这是我使用的模型的问题吗?或者我是如何使用它的?

4

1 回答 1

1

而不是这个:

var p = parser.Parse(Parse.ParseParse("..."));

我只需要使用这个:

var p = ParserTool.ParseLine("...", parser, 1);
于 2016-06-10T04:34:57.123 回答