Skip to content

Commit

Permalink
Update NP extracting scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
evelinacs committed Jul 30, 2018
1 parent c498a88 commit 461573c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions exp/alto/tools/get_np_terminals.py
@@ -1,4 +1,5 @@
import sys

from nltk.tree import Tree

TEMPLATE = ('{0} -> {1}_{0}\n[tree] {0}({1})\n[ud] "({1}<root> / {1})"\n' +
Expand All @@ -16,7 +17,7 @@ def get_np_terminals():

#print(seen)
for tuples in seen:
print(TEMPLATE.format(tuples[1], tuples[0]))
print TEMPLATE.format(tuples[1], tuples[0])


get_np_terminals()
get_np_terminals()
@@ -1,9 +1,20 @@
from nltk.corpus import treebank

from common import sanitize_word

def format_tree(tree):
if tree.height() == 2: #word, pos
tree[0] = sanitize_word(tree[0]) #tree[0] == word
else:
for subtree in tree:
format_tree(subtree)


for n in range(1,200):
tree_file = "wsj_{}.mrg".format(str(n).zfill(4))
sentences = treebank.parsed_sents(tree_file)
for s in sentences:
for subtree in s.subtrees(lambda t: t.label() == "NP"):
format_tree(subtree)
print(subtree.pformat(100000))
#print(subtree)

0 comments on commit 461573c

Please sign in to comment.