用 SharpNL & en-parser-chunking.bin 解析一个句子
Parsing a sentence with SharpNL & en-parser-chunking.bin
使用 SharpNL and 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的Head,没有children。这是我使用的模型的问题吗?或者我是如何使用它的?
而不是这个:
var p = parser.Parse(Parse.ParseParse("..."));
我只需要使用这个:
var p = ParserTool.ParseLine("...", parser, 1);
使用 SharpNL and 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的Head,没有children。这是我使用的模型的问题吗?或者我是如何使用它的?
而不是这个:
var p = parser.Parse(Parse.ParseParse("..."));
我只需要使用这个:
var p = ParserTool.ParseLine("...", parser, 1);