Permalink
Browse files

First working version

  • Loading branch information...
Mike Lynch
Mike Lynch committed Apr 22, 2017
1 parent cb30cde commit 1c6bc167da4b93ea1cbcfd7cf377529ebfed1932
Showing with 41 additions and 15 deletions.
  1. +41 −15 jumper.py
@@ -1,15 +1,26 @@
#!/usr/bin/env python3

from nltk.corpus import framenet as fn
import random
import random, re, argparse, sys

MAX = 3;
MAX = 3

QUOTES_RE = re.compile("'([^']*)'")

seen = {}
lines = {}

def frame_to_sentence(frame):
for en, elt in frame.FE.items():
for sentence in QUOTES_RE.findall(elt.definition):
if sentence not in lines:
print(sentence)
lines[sentence] = 1


def explode_frames(n, lu):
print(' ' * n, lu.name)
if n < MAX:

def explode_frames(depth, lu):
if depth:
f = lu.frame
frames = [ f ]
for fr in f.frameRelations:
@@ -21,16 +32,31 @@ def explode_frames(n, lu):
for fr in frames:
if fr.name not in fr_seen:
fr_seen[fr.name] = 1
frame_to_sentence(fr)
for ln in fr.lexUnit:
if ln not in seen:
seen[ln] = 1
explode_frames(n + 1, fr.lexUnit[ln])


lus = fn.lus()

l0 = random.choice(lus)

#print(l0)
explode_frames(0, l0)
seen[ln] = 1
explode_frames(depth - 1, fr.lexUnit[ln])


if __name__ == '__main__':
ap = argparse.ArgumentParser()
ap.add_argument('-s', '--start', type=str, help="Seed word")
ap.add_argument('-d', '--depth', type=int, default=MAX, help="Maximum recursion depth")
args = ap.parse_args()
l0 = ''
if args.start:
r = re.compile(args.start)
lus = fn.lus(r)
if lus:
l0 = random.choice(lus)
else:
print("No matches found for {}".format(args.start))
sys.exit(-1)
else:
lus = fn.lus()
l0 = random.choice(lus)

print(l0.name)
explode_frames(args.depth, l0)

0 comments on commit 1c6bc16

Please sign in to comment.