Created
July 16, 2015 01:48
-
-
Save mgalgs/990feefbbcae6e39b239 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
import sys | |
import string | |
text = '' | |
caps = set() | |
with open(sys.argv[1]) as f: | |
for line in f: | |
text += line | |
for word in line.split(' '): | |
if word[0] in string.uppercase: | |
caps.add(word.strip()) | |
undefined = set() | |
defined = {} | |
textlen = len(text) | |
for cap in caps: | |
definition = cap + " is" | |
if definition not in text: | |
undefined.add(cap) | |
else: | |
idx = text.index(definition) | |
defined[cap] = text[idx:min(idx + 30, textlen)].strip() | |
for cap,definition in defined.iteritems(): | |
print "=========================================" | |
print "Possible definition for " + cap + ":" | |
print definition | |
print "=========================================\n" | |
for cap in undefined: | |
print "Possibly undefined term: " + cap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result: