用于自然语言处理和翻译的glr解析器

GLRParser的Python项目详细描述


用于自然语言处理和翻译的glr解析器

glrparser不仅仅是一个解析器。是

  • 处理不明确语法的自然语言分析器
  • 处理功能统一的统一引擎
  • 基于语法的自然语言翻译引擎

有关详细信息,请参见wiki页面:https://github.com/mdolgun/GLRParser/wiki

用于解析和翻译的示例代码应该如下:

fromGLRParserimportParser,ParseError,GrammarError,Treetry:parser=Parser()# initialize parser objectparser.load_grammar("GLRParser\grm\simple_trans.grm")# load grammar from a filesent="i saw the man in the house with the telescope"# sentence to parseparser.compile()# constructs parsing tablesparser.parse(sent)# parse the sentencetree=parser.make_tree()# generates parse forestttree=parser.trans_tree(tree)# translate the parse forestprint(ttree.pformatr())# pretty-print the translated parse forestfortransinttree.enum():# enumerate and print all alternative translations in the parse forestprint(trans.replace(" -",""))# concat suffixesexceptGrammarErrorasge:print(ge)exceptParseErroraspe:print(pe))

英语的简单语法->;土耳其语翻译(请参见simple_trans.grm)

S -> NP VP : NP VP
S -> S in NP : NP -de S
S -> S with NP : NP -la S
NP -> i :
NP -> the man : adam
NP -> the telescope : teleskop
NP -> the house : ev
NP -> NP-1 in NP-2 : NP-2 -deki NP-1
NP -> NP-1 with NP-2 : NP-2 -lu NP-1
VP -> saw NP : NP -ı gördüm

给定上述语法和输入字符串:

i saw the man in the house with the telescope

它生成一个解析林和5个可选翻译(of 哪两个相同):

1. teleskopla evde adamı gördüm
2. teleskopla evdeki adamı gördüm
3. teleskoplu evde adamı gördüm
4. teleskoplu evdeki adamı gördüm
5. teleskoplu evdeki adamı gördüm

语义解释如下:

1. saw(in the house) saw(with the telescope)
2. man(in the house) saw(with the telescope)
3. saw(in the house) house(with the telescope)
4. man(in the house) man(with the telescope)
5. man(in the house) house(with the telescope)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java将getAttribute()scriptlet重写为JSP/HTML中的JSTL?   java接口,用于在KeyClope中执行电子邮件操作   java我试图将今天的日期添加到我的对象,但构造函数有问题   关于生成示例图表示(RDF或VEV元组)的java建议   httpclient在Java中使用空格编码URL的工作方式不正确   java NDimensional点类   java在编写查找ArrayList中最大整数索引的方法时遇到问题   java生成对象并放入arraylist,无重复项   在Java中使用泛型   在Java中使用“h=Math.min(h,h)”有什么逻辑原因吗?   安卓 Java for loop总是返回true   覆盖率java工具   java试图发送int时出现“空对象引用”错误