用于自然语言处理和翻译的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如何在创建对话框时设置模糊背景   java支持clojure中的xml和json REST响应   java在Android中通过多个JSON对象循环   java如何创建T类型的新对象   Java应用程序的设计   java使用GridView、适配器和毕加索制作流行电影应用程序   java在映射中交换值   java在同一活动/布局中多次使用同一片段   使用FixedLengthTokenizer使用java Spring FlatFileItemReader   javajavax。xml。ws。WebServiceException:javax。xml。肥皂SOAPException:错误代码QName必须是命名空间限定的!在weblogic server 12c中部署时   当我在构造函数中调用java Autowired属性时,该属性为null   线程“main”java中的linux异常。网BindException:地址已在使用中   java检查两个日期周期是否重叠   有没有办法通过安卓应用程序自动检测java服务器应用程序是否在线?   java检查2D数组中4个连续相同的对角线元素(连接4个游戏)   向Java数组添加数据   java组织。弹性搜索。客户运输NoNodeAvailableException:配置的节点均不可用:[]