我正在尝试使用ViterbiParser和ChartParser来解析句子"鸟飞"。 跟踪该过程,似乎它应该工作,但总是返回None
这是痕迹。(维特比(:
Inserting tokens into the most likely constituents table...
Insert: |=.| Birds
Insert: |.=| fly
Finding the most likely constituents spanning 1 text elements...
Insert: |=.| NNS -> 'Birds' [1.0]
Insert: |=.| NP -> NNS [0.206897]
Insert: |.=| VB -> 'fly' [1.0]
Insert: |.=| VP -> VB [0.21875]
Finding the most likely constituents spanning 2 text elements...
Insert: |==| S -> NP VP [1.0]
图表解析器:
|. Birds . fly .|
Leaf Init Rule:
|[---------------] .| [0:1] 'Birds'
|. [---------------]| [1:2] 'fly'
Bottom Up Predict Combine Rule:
|[---------------] .| [0:1] NNS -> 'Birds' *
Bottom Up Predict Combine Rule:
|[---------------] .| [0:1] NP -> NNS *
Bottom Up Predict Combine Rule:
|[---------------> .| [0:1] NP -> NP * NP
|[---------------> .| [0:1] S -> NP * VP
Bottom Up Predict Combine Rule:
|. [---------------]| [1:2] VB -> 'fly' *
Bottom Up Predict Combine Rule:
|. [---------------]| [1:2] VP -> VB *
|. [--------------->| [1:2] VP -> VB * VP
|. [--------------->| [1:2] VP -> VB * ADJP
|. [--------------->| [1:2] VP -> VB * PP
Bottom Up Predict Combine Rule:
|. [--------------->| [1:2] VP -> VP * PP
|. [--------------->| [1:2] VP -> VP * NP
|. [--------------->| [1:2] VP -> VP * VP
Single Edge Fundamental Rule:
|[===============================]| [0:2] S -> NP VP *
两个解析器似乎都正确构建了句子,但仍返回 None。 这是怎么回事?
在为此工作了几个小时后,我实际上发现了问题所在。我正在使用 PCFG 语法。语法中加载的第一个规则需要将左侧设置为语法的开始状态。没有明确的方法来覆盖它。我更改了语法规则的顺序,现在它正在工作。
问题的确切原因... PCFG正试图提出一种规则安排,创建一棵植根于"开始状态"的树。 在我的情况下,它是"S"(句子(我把规则加载得乱七八糟,所以它试图得到一个名词短语,因此无法想出一棵有效的树。