forked from stensaethf/CKY-Parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.py
87 lines (71 loc) · 1.57 KB
/
node.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
'''
parser.py
Frederik Roenn Stensaeth
11.05.15
A Node class used for a Python implementation of the CKY algorithm for
generating parse trees, given a CFG (in almost-CNF) and a sentence.
'''
class Node:
"""
The Node clas functions as a way to construct a tree using nodes that have
children.
Methods:
- root
- left
- right
- status
- terminal
"""
def __init__(self, root, left, right, end):
"""
Constructor for the Node class. Root, left, right, terminal and status
are set up here. Status is infered from whether a terminal value is
provided or not.
"""
self._root = root
self._left = left
self._right = right
self._terminal = end
self._status = True
if end == None:
self._status = False
@property
def root(self):
"""
root allows the user to get the root of the node.
@params: n/a.
@return: the root.
"""
return self._root
@property
def left(self):
"""
left allows the user to get the left subtree of the node.
@params: n/a.
@return: the left subtree.
"""
return self._left
@property
def right(self):
"""
right allows the user to get the right subtree of the node.
@params: n/a.
@return: the right subtree.
"""
return self._right
@property
def status(self):
"""
status allows the user to get the status of the node.
@params: n/a.
@return: boolean for whether it is a terminal node or not.
"""
return self._status
@property
def terminal(self):
"""
terminal allows the user to get the terminal value of the node.
@params: n/a.
@return: the terminal value.
"""
return self._terminal