Skip to content

Commit

Permalink
Modify these files to respond for the recents changes in dependency g…
Browse files Browse the repository at this point in the history
…raph ['deps'] field
  • Loading branch information
longdt219 committed Feb 4, 2015
1 parent d892272 commit 4e6531c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 10 additions & 5 deletions nltk/sem/glue.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,13 @@ def __str__(self):
def to_glueformula_list(self, depgraph, node=None, counter=None, verbose=False):
if node is None:
top = depgraph.nodes[0]
root = depgraph.nodes[top['deps'][0]]
depList = sum(list(top['deps'].values()), [])
root = depgraph.nodes[depList[0]]
#print (root)
return self.to_glueformula_list(depgraph, root, Counter(), verbose)

glueformulas = self.lookup(node, depgraph, counter)
for dep_idx in node['deps']:
for dep_idx in sum(list(node['deps'].values()), []):
dep = depgraph.nodes[dep_idx]
glueformulas.extend(self.to_glueformula_list(depgraph, dep, counter, verbose))
return glueformulas
Expand Down Expand Up @@ -271,12 +273,15 @@ def add_missing_dependencies(self, node, depgraph):
if rel == 'main':
headnode = depgraph.nodes[node['head']]
subj = self.lookup_unique('subj', headnode, depgraph)
node['deps'].append(subj['address'])
relation = subj['rel']
node['deps'].setdefault(relation,[])
node['deps'][relation].append(subj['address'])
#node['deps'].append(subj['address'])

def _lookup_semtype_option(self, semtype, node, depgraph):
relationships = frozenset(
depgraph.nodes[dep]['rel'].lower()
for dep in node['deps']
for dep in sum(list(node['deps'].values()), [])
if depgraph.nodes[dep]['rel'].lower() not in OPTIONAL_RELATIONSHIPS
)

Expand Down Expand Up @@ -409,7 +414,7 @@ def lookup_unique(self, rel, node, depgraph):
"""
deps = [
depgraph.nodes[dep]
for dep in node['deps']
for dep in sum(list(node['deps'].values()), [])
if depgraph.nodes[dep]['rel'].lower() == rel.lower()
]

Expand Down
6 changes: 4 additions & 2 deletions nltk/sem/lfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def to_depgraph(self, rel=None):
for address, node in nodes.items():
for n2 in (n for n in nodes.values() if n['rel'] != 'TOP'):
if n2['head'] == address:
node['deps'].append(n2['address'])
relation = n2['rel']
node['deps'].setdefault(relation,[])
node['deps'][relation].append(n2['address'])

depgraph.root = nodes[1]

Expand Down Expand Up @@ -115,7 +117,7 @@ def _read_depgraph(node, depgraph, label_counter=None, parent=None):
if not fstruct.pred:
fstruct.pred = (word, tag)

children = [depgraph.nodes[idx] for idx in node['deps']]
children = [depgraph.nodes[idx] for idx in sum(list(node['deps'].values()), [])]
for child in children:
fstruct.safeappend(child['rel'], FStructure._read_depgraph(child, depgraph, label_counter, fstruct))

Expand Down

0 comments on commit 4e6531c

Please sign in to comment.