7

There are lots of parsers and lexers for scripts (i.e. structured computer languages). But I'm looking for one which can break a (almost) non-structured text document into larger sections e.g. chapters, paragraphs, etc.

It's relatively easy for a person to identify them: where the Table of Contents, acknowledgements, or where the main body starts and it is possible to build rule based systems to identify some of these (such as paragraphs).

I don't expect it to be perfect, but does any one know of such a broad 'block based' lexer / parser? Or could you point me in the direction of literature which may help?

4

4 回答 4

1

许多轻量级标记语言,如markdown(偶然使用 SO)、reStructured text和(可以说)POD,与您所说的类似。它们具有最少的语法并将输入分解为可解析的语法片段。您可能可以通过阅读他们的实现来获得一些信息。

于 2010-01-18T17:05:41.767 回答
0
  1. 定义注释标准,这表明您希望如何分解。
  2. 继续访问 Amazon Mechanical Turk 并要求人们使用您的注释标准标记 10K 文档。
  3. 在此训练数据上训练 CRF(类似于 HMM,但更好)。

如果你真的想走这条路,我可以详细说明。但这将是很多工作。

于 2010-01-22T05:23:08.420 回答
0

大多数lex/yacc类型的程序都使用定义良好的语法。如果您可以按照类似BNF的格式(大多数解析器接受类似的语法)来定义您的语法,那么您可以使用它们中的任何一个。这可能是显而易见的。但是,您仍然可能对作为语法一部分的文本“块”(标记)有些模糊。毕竟,您为令牌定义了规则。

我过去曾使用Parse-RecDescent Perl 模块,在类似项目中取得了不同程度的成功。

抱歉,这可能不是一个好的答案,但更多的是分享我在类似项目上的经验。

于 2010-01-18T17:10:48.147 回答
0

尝试:pygmentsgeshiprettify

他们几乎可以处理您扔给他们的任何东西,并且非常宽容您的语法和文档中的错误。

参考:
gitorius 使用 prettify,
github 使用 pygments,
rosettacode 使用 geshi,

于 2010-05-17T06:17:27.177 回答