0

In Python, I have an input of list like following-

[('S', ['NP', 'VP']),
('A', ['V', 'NP']),
('VP', ['V', 'NP']),
('NP', ['DET', 'NP']),
('N', "'mouse'"),
('NP', "'mouse'"),
('DET', "'the'"),
('V', "'saw'"),
('N', "'Ron'"),
('NP', "'Ron'")]

This is the result of the following CYK algorithm-

S -> NP VP
VP -> A NP | V NP
NP -> N N | DET NP | 'chocolate' | 'cat' | 'John' | 'Ron' | 'mouse'
DET -> 'the'
N -> 'chocolate' | 'cat' | 'John' | 'Ron' | 'mouse'
V -> 'saw' | 'bought' | 'ate'
A -> V NP

The string that I want to match with is "Ron saw the mouse"

I want to relate output like this-

(S (NP Ron) (VP (V saw) (NP (DET the) (NP mouse))))

I am not sure how the algorithm should be constructed especially with an ambiguous algorithm which may contain multiple outputs. How should I construct code? Any suggestion what should be a better approach with/without recursion?

UPDATE---

I managed to get a single exact parse tree after adding extra parents and child nodes position values with the input list. But my problem doesn't solve with the ambiguous sentence.

Touhidul Alam
  • 321
  • 2
  • 11
  • Normally, the CYK algorithm would supply start & end positions for each instance of a production that it finds in the string. This extra information would make it easier to construct a parse tree. Is there a reason you don't have the position info? – Michael Dyck Jun 15 '18 at 14:36
  • Thank you for the reply, I managed to get the positions of the parents and children node information. My current shortcoming is solving ambiguous tree. I managed to get single exact correct parse tree. – Touhidul Alam Jun 17 '18 at 22:13

0 Answers0