Skip to content

Commit f4a3d58

Browse files
Add readme
1 parent 104251c commit f4a3d58

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Read AI
2+
3+
A simple artificial intelligence capable of basic reading comprehension.
4+
5+
[Blog post here](http://blog.ayoungprogrammer.com/2015/09/a-simple-artificial-intelligence.html)
6+
7+
## Setup
8+
9+
Install Python 2.7
10+
11+
[Download Stanford Parser](http://nlp.stanford.edu/software/stanford-parser-full-2015-04-20.zip)
12+
13+
[Download Nodebox Linguistics](https://www.nodebox.net/code/data/media/linguistics.zip)
14+
15+
python readai.py

readai.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def complete(self, tokens, qtype):
4040
prev_node = prev_node.prev
4141
ret.append(prev_node.label)
4242

43-
print ret
4443
while cur_node.label not in smap and len(cur_node) > 0:
4544
ret.append(cur_node.label)
4645
cur_node = cur_node[0][1]
@@ -113,7 +112,6 @@ def get_root_word(word):
113112
def get_node(label):
114113
if label not in smap:
115114
smap[label] = Node(label)
116-
smap[label].set('->', Node(label + "'s properties"))
117115
return smap[label]
118116

119117
def flatten_tree(tree):
@@ -266,8 +264,10 @@ def describe(tree):
266264
action_node.set('.', obj)
267265

268266
if matches('( VP ( VB/VBZ/VBP/VPZ/VBD/VBG/VBN ) ( NP ) ( PP ) )', tree):
269-
prop, prop_node = describe(tree[2])
270-
action_node.set(prop, prop_node)
267+
# Assume rest is PP
268+
for pp_node in tree[2:]:
269+
prop, prop_node = describe(pp_node)
270+
action_node.set(prop, prop_node)
271271

272272
return action, action_node
273273

@@ -348,32 +348,19 @@ def answer(tree):
348348
return "Nothing"
349349
return ','.join(objs)
350350

351-
if matches("""
352-
( SBARQ
353-
( WHNP ( . ) ( NN ) )
354-
( SQ ( VBP ) ( NP ) ) )""", tree):
355-
# Ex: What color are blueberries
356-
qtype = get_word(tree[0][0])
357-
propy = get_word(tree[0][1])
358-
action = get_root_word(get_word(tree[1][0]))
359-
360-
print "%s %s %s ____" % (subject, propy, action)
361-
362-
return get_node(subject).get('->').get(propy).get(action).label
363-
364351
print "ERROR answering"
365352

366353

367354
line = raw_input("Enter line: ")
368355

369356
while line != 'stop':
370357
sent = list(parser.raw_parse(line))[0]
371-
# print sent
358+
#print sent
372359
if sent[0].label() == "SBARQ":
373360
print answer(sent)
374361
else:
375362
describe(sent)
376-
# print smap
363+
#print smap
377364
line = raw_input("Enter line: ")
378365

379366
"""

0 commit comments

Comments
 (0)