TREE DRAWING PRETTY PRINTERS:
NYU VANILLA ||
If you have any comments about these workbook
pages, please let us know. Should we place more of these pages on line? Do you
benefit from these pages? If you are a student at NYU, you may help in
developing these pages, see the
Your ideas and comments will lead to modifications and improvements.
1. Sending Parse Trees to the Screen or Disk.
One of the Prolog programs in the program file work002.txt
(work002.zip) is a parser, tree_1(LIST), that
will convert the following (a) strings to phrase markers using Lehner's tree
drawing program and present the display on the computer screen. This produces an
ASCII tree diagram . (If tree_1(X) does not work on your machine, try
tree_prn(LIST) converts the (a) strings to phrase markers and writes
them to a disk. The screen does not display the tree, but a message appears
indicating if the parser was successful, and if successful, what the name of the
file is. tree_prn(X) automatically picks the file names. wbfile1
is the first file, wbfile2 is the second, and so on. As long as you
remain in Prolog, the numbers will increase. If you quit Prolog and reload the
program, work002.pl, then the filenames will restart with the name wbfile1,
wbfile2, on up. If you quit Prolog, save your work.
- (a) The man sees in the house.
- (b) tree_1([the,man,sees,in,the,house]).
- (c) tree_prn([the,man,sees,in,the,house]). (wbfile#)
- (a) The woman sees under the table.
- (b) tree_1([the,woman,sees,under,the,table]). (screen
- (c) tree_prn([the,woman,sees,under,the,table]).
A labeled bracketing of constituents can be difficult to read. A common
notation in linguistics is a
that spreads constituent structure information into two dimensions. These
parsing programs produce phrase markers.
The following diagrams shows the screen contents (scriptfile, or screen
capture) of what happens when you are using tree_1(X) in SWI-PROLOG on
an IBM PC under Windows to parse simple strings to obtain phrase markers. The
program also runs in Quintus Prolog.
The English grammar upon which this parser is based is discussed in Workbook
2.1. If you want to parse your own sentences, you may modify the lexicon.
2. Computer requirements to run this parser.
- You must download and install
- This particular program, called work002 (ascii),
here compressed work002.zip, must be called work002.pl
in the c:\pl directory of your computer.
- The active directory must be c:\pl.
The program has a tiny lexicon and a simple set of
combinatory principles. It is intended as a pedigogical tool for introductory
classes intending to show how to encode Chomsky's ideas about generative grammar
(particularly the merge operation) into Prolog.
3. Graphic: How to Print Trees to Disk.
- 1. Download the file work002.txt (work002.zip) to the directory c:\pl.
- 2. Copy work002.txt to work002.pl. Or, unzip work002.pl
- 3. Open SWI-Prolog and load work002.pl.
- 4. Ignore the huge number of warnings that appear.
- 5. Type: tree_1([the,woman,sees,under,the,tree]).
- 6. The machine will display a tree on the screen.
- 7. Type: tree_prn([the,woman,sees,under,the,table]).
- 8. The machine will respond that it is writing the tree to a file and it
will give the filename of the destination file.
- ### The machine will automatically pick a filename. A Prolog function
called gensym will label each file with a new number. The first tree_prn
will be in wbfile1, the second in wbfile2, and so on. Each time
you call tree_prn(LIST), the machine will increment the name/number of
the output file. ###
- ### The numbers increase until you quit SWI Prolog. ###
- ### The next time you start SWI Prolog, the filenames will start with wbfile1
and increment up. This will erase whatever you may have done earlier. ###
- ### tree_prn(LIST) prints a file header including the filename in
the file. The filename also appears on the screen when you execute the function.
4. Opening the wbfile# in Desktop Editor
- 9. The phrase markers in the output files (wbfile1, wbfile2,
wbfile3, and so on) are ASCII files.
- 10. They can be opened in any text editor: Desktop editor, Word,
- 11. Here is wbfile1 opened in Desktop Editor.
- 12. Here is wbfile2 opened in the Desktop Editor.
5. Opening the file wbfile# in WordPerfect
- 13. Here is wbfile1 opened in WordPerfect.
6. Inserting the file wbfile# into WWW
- 14. The wbfile#'s can also be inserted into World Wide Web
documents as preformatted code.
- 15. Here is an example of the file wbfile1 in preformatted code.
Beginners Workbook in Computational Linguistics
PROGRAM FILE: work002
Prolog Function Name: tree_prn(LIST)
LIST = [the,woman,sees,under,the,table]
/ \ / \
det n v pp
| | | ___|___
| | | / \
the woman sees p np
| / \
under det n
- 16. Here is the HTML code that generated the above example. The HTML
editor used here is HoTMetal 2.0. This is a free HTML editor.
7. Overview of the Parser to Disk to Editor Process.
The basic process involves three applications in Windows:
- You parse a sentence in the Prolog Window using tree_prn(LIST).
- Tree_prn(LIST) writes a file wbfile# to the c:\pl
- You can open the wbfile# in any text editor, here it is Desktop
Using the skills you acquired in the exercises in Workbook 2.1, modify the
lexicon of the parser to generate parse trees for these sentences:
- Any cat rubs on any pole.
- No child depends on their blanket.
Parse these sentences and write the trees to disk.
Using a text editor, write a short essay:
- describe what you did
- list the lexicical items
- include the parse trees in your essay
- eliminate the identification headings added to the ascii files by the
E-mail me the essay with the comment field: Your name, WB Assignment 2.2.
Compose your short essay plus graphics as an HTML Web Page and place it
on-line. E-mail me a letter containing the URL with the comment field: Your
name, WB Assignment 2.2
Some of the figures are scaled to fill a 1200 x 650 screen.
If you enlarge the browser window, you will be able to read
even the small print.
These figures are used in
courses at NYU
with a computer connected to the WWW and an
using an overhead/computer attachment. One need not carry overheads,
they are on the WWW
for use anytime, anywhere.