Assignment Three - Due
at the final (Monday, May 9th)
The main purpose of
this assignment is to give you an opportunity to explain what code
does in the context of natural language processing.
0) Read through Chapter
10, which can be found at:
http://www.nltk.org/book/ch10.html
1) Read the
following code:
>>> lp =
nltk.LogicParser()
>>> SnF =
lp.parse('SnF')
>>> NotFnS =
lp.parse('-FnS')
>>> R =
lp.parse('SnF -> -FnS')
>>> prover =
nltk.Prover9()
>>>
prover.prove(NotFnS, [SnF, R])
Explain what you
think it does.
2) READ the
following code using the NLTK:
>>> tlp =
nltk.LogicParser(type_check=True)
>>> parsed =
tlp.parse('walk(angus)')
>>>
parsed.argument
<ConstantExpression
angus>
>>>
parsed.argument.type
>>>
parsed.function
<ConstantExpression
walk>
>>>
parsed.function.type
Explain what you
think it does.
3) READ the
following code:
>>> sig =
{'walk': '<e, t>'}
>>> parsed =
tlp.parse('walk(angus)', sig)
>>>
parsed.function.type
>>> a4 =
lp.parse('exists y. (woman(y) & all x. (man(x) ->
love(x,y)))')
>>> a5 =
lp.parse('man(adam)')
>>> a6 =
lp.parse('woman(eve)')
>>> g =
lp.parse('love(adam,eve)')
>>> mc =
nltk.MaceCommand(g, assumptions=[a4, a5, a6])
>>>
mc.build_model()
Explain what you
think it does.
4) READ
the following code:
>>> v = """
... bertie => b
... olive => o
... cyril => c
... boy => {b}
... girl => {o}
... dog => {c}
... walk => {o, c}
... see => {(b, o),
(c, b), (o, c)}
... """
>>> val =
nltk.parse_valuation(v)
>>> print val
{'bertie': 'b',
'boy': set([('b',)]),
'cyril': 'c',
'dog': set([('c',)]),
'girl': set([('o',)]),
'olive': 'o',
'see': set([('o',
'c'), ('c', 'b'), ('b', 'o')]),
'walk': set([('c',),
('o',)])}
Explain what you
think it does.
5) READ the
following code:
>>> lp =
nltk.LogicParser()
>>> e =
lp.parse(r'\x.(walk(x) & chew_gum(x))')
>>> e
<LambdaExpression
\x.(walk(x) & chew_gum(x))>
>>> e.free()
set([])
>>> print
lp.parse(r'\x.(walk(x) & chew_gum(y))')
\x.(walk(x) &
chew_gum(y))
Explain
what you think it does.