简体   繁体   English

使用python的NLTK fcfg语法

[英]NLTK fcfg grammar using python

I am new in NLP. 我是NLP的新手。 I found this file in nltk_data. 我在nltk_data中找到了这个文件。 I am trying to write my own grammar. 我想写自己的语法。 Before write these I need to know what is the meaning of (SEM=(?v + ?pp)). 在写这些之前我需要知道(SEM =(?v +?pp))的含义是什么。 please help me to know this. 请帮我知道这个。

% start S

S[SEM=(?np + WHERE + ?vp)] -> NP[SEM=?np] VP[SEM=?vp]

VP[SEM=(?v + ?pp)] -> IV[SEM=?v] PP[SEM=?pp]
VP[SEM=(?v + ?ap)] -> IV[SEM=?v] AP[SEM=?ap]
NP[SEM=(?det + ?n)] -> Det[SEM=?det] N[SEM=?n]
PP[SEM=(?p + ?np)] -> P[SEM=?p] NP[SEM=?np]
AP[SEM=?pp] -> A[SEM=?a] PP[SEM=?pp]

NP[SEM='Country="greece"'] -> 'Greece'
NP[SEM='Country="china"'] -> 'China'

Det[SEM='SELECT'] -> 'Which' | 'What'

N[SEM='City FROM city_table'] -> 'cities'

IV[SEM=''] -> 'are'
A[SEM=''] -> 'located'
P[SEM=''] -> 'in'

In this line: 在这一行:

VP[SEM=(?v + ?pp)] -> IV[SEM=?v] PP[SEM=?pp]

Short answer: SEM=(?v + ?pp) is concatenating two strings, first one from SEM feature of nodes in V and second coming from PP . 简答: SEM=(?v + ?pp)连接两个字符串,第一个来自V中节点的SEM特征,第二个来自PP

Longer answer: The grammar gives you a parser which you can form a tree structure for a given text. 更长的答案:语法为您提供了一个解析器,您可以为给定的文本形成树结构。 On each node of this tree, you can manipulate features while you building them up with the parser. 在此树的每个节点上,您可以在使用解析器构建功能时操纵功能。 This way you can form a semantic representation for the tree. 这样,您就可以为树形成语义表示。 Between these representations, you can see first order logic and lambda functions, and a useful representation is SQL query which you are using here. 在这些表示之间,您可以看到第一顺序逻辑和lambda函数,有用的表示是您在此处使用的SQL查询。 Depending on the parser you may need different manipulations of features. 根据解析器,您可能需要对功能进行不同的操作。 On lambda function, the parser needs function compositions and logical operations, and here on SQL-queries the parser mainly works with string concatenation. 在lambda函数上,解析器需要函数组合和逻辑运算,而在SQL查询中,解析器主要用于字符串连接。

UPDATE UPDATE

In this syntax, each line of rule has two sides (left hand side, and right hand side): lhs -> rhs The parser is expected to find a tree which parent-nodes are one of non-terminal lhs nodes and follow one of these rules as they only take children from rhs . 在这种语法中,每行规则都有两个边(左手边和右边): lhs -> rhs解析器应该找到一个树,其中父节点是非终端lhs节点之一并遵循其中一个这些规则因为他们只接受来自rhs孩子。

Then, for the Semantic part, the semantic representation of parent-node is the result of composing representations of its direct children. 然后,对于语义部分,父节点的语义表示是组成其直接子节点的表示的结果。

In this syntax, on right hand side, you can use question mark like: ?var to handle agreements between siblings on right hand side. 在这种语法中,在右侧,您可以使用问号: ?var来处理右侧兄弟姐妹之间的协议。 Then you can pass the value to left hand side by assigning them to another feature (or manipulate them if your parser supports such thing like function application or logical manipulation). 然后,您可以通过将值分配给另一个功能将值传递给左侧(如果您的解析器支持函数应用程序或逻辑操作等操作,则可以操作它们)。 The semantic representation of parent-node basically is result of manupulation of semantic representation of its children. 父节点的语义表示基本上是其子节点的语义表示的结果。 In FCFG, you pass semantic representations like a feature from right hand side to the left hand side. 在FCFG中,您将语义表示从右侧传递到左侧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM