1

我正在尝试使用 ViterbiParser 和 ChartParser 来解析句子“Birds fly”。跟踪过程,似乎它应该工作,但总是返回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。这是怎么回事?

4

1 回答 1

1

经过几个小时的工作,我实际上发现了问题。我正在使用 PCFG 语法。语法中加载的第一条规则需要将左侧设置为语法的起始状态。没有明确的方法可以覆盖它。我改变了我的语法规则的顺序,它现在可以工作了。

问题的确切原因... PCFG 正试图提出一种规则安排,以创建以“开始状态”为根的树。在我的情况下,它是“S”(用于句子)我已经无序地加载了规则,所以它试图找到一个名词短语,因此无法找到一个有效的树。

于 2017-06-11T01:28:01.993 回答