20.07.2013 Views

Notes on computational linguistics.pdf - UCLA Department of ...

Notes on computational linguistics.pdf - UCLA Department of ...

Notes on computational linguistics.pdf - UCLA Department of ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Stabler - Lx 185/209 2003<br />

(27) With this definiti<strong>on</strong>, if we also load the following theory,<br />

p :˜ [q,r].<br />

q :˜ [].<br />

r :˜ [].<br />

then we get the following sessi<strong>on</strong>:<br />

| ?- [] ?˜ [p]@[T].<br />

T = p/[q/[], r/[]] ;<br />

No<br />

| ?- [] ?˜ [p,q]@[T0,T].<br />

T0 = p/[q/[], r/[]]<br />

T = q/[] ;<br />

No<br />

What we are more interested in is pro<strong>of</strong>s from grammars, so here is a sessi<strong>on</strong> showing the use <strong>of</strong> our<br />

simple grammar g1.pl from page 45:<br />

| ?- [tdp,g1].<br />

Yes<br />

| ?- [the,idea,will,suffice] ?˜ [ip]@[T].<br />

T = ip/[dp/[d1/[d0/[the/[]], np/[n1/[n0/[idea/[]]]]]], i1/[i0/[will/[]], vp/[v1/[v0/[suffice/[]]]]]]<br />

3.6 Some basic relati<strong>on</strong>s <strong>on</strong> trees<br />

3.6.1 “Pretty printing” trees<br />

(28) Those big trees are not so easy to read! It is comm<strong>on</strong> to use a “pretty printer” to produce a more readable<br />

text display. Here is the simple pretty printer:<br />

/*<br />

* file: pp_tree.pl<br />

*/<br />

pp_tree(T) :- pp_tree(T, 0).<br />

pp_tree(Cat/Ts, Column) :- !, tab(Column), write(Cat), write(’ /[’), pp_trees(Ts, Column).<br />

pp_tree(X, Column) :- tab(Column), write(X).<br />

pp_trees([], _) :- write(’]’).<br />

pp_trees([T|Ts], Column) :- NextColumn is Column+4, nl, pp_tree(T, NextColumn), pp_rest_trees(Ts, NextColumn).<br />

pp_rest_trees([], _) :- write(’]’).<br />

pp_rest_trees([T|Ts], Column) :- write(’,’), nl, pp_tree(T, Column), pp_rest_trees(Ts, Column).<br />

The <strong>on</strong>ly reas<strong>on</strong> to study the implementati<strong>on</strong> <strong>of</strong> this pretty printer is as an opti<strong>on</strong>al exercise prolog.<br />

What is important is that we be able to use it for the work we do that is more directly linguistic.<br />

(29) Here is how to use the pretty printer:<br />

| ?- [tdp,g1,pp_tree].<br />

Yes<br />

| ?- ([the,idea,will,suffice] ?˜ [ip]@[T]),pp_tree(T).<br />

ip /[<br />

dp /[<br />

d1 /[<br />

d0 /[<br />

the /[]],<br />

np /[<br />

n1 /[<br />

n0 /[<br />

idea /[]]]]]],<br />

i1 /[<br />

i0 /[<br />

will /[]],<br />

vp /[<br />

v1 /[<br />

v0 /[<br />

suffice /[]]]]]]<br />

T = ip/[dp/[d1/[d0/[the/[]],np/[n1/[...]]]],i1/[i0/[will/[]],vp/[v1/[v0/[...]]]]] ?<br />

Yes<br />

48

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!