Practical Grammar 2: Difference between revisions
Line 106: | Line 106: | ||
* Save the grammar. | * Save the grammar. | ||
* Parse. | * Parse. | ||
Now, the output window should open and display a constituent structure (= phrase structure) for our sentence. This means that our grammar recognizes the string "John disappears" as grammatical! |
Revision as of 15:30, 5 November 2020
xlfg
Your first grammar in xlfg
Please do the following:
You first log onto xlfg:
- Go to https://xlfg.labri.fr/ and log in.
Then you locate our workshop:
- Choose Workshops|All Workshops.
- Look for the workshop "Practical Grammar".
- In the column "Action", click the button "Consult the workshop".
Now you find a project of the workshop:
- On the right side of the screen is the list of projects of our workshop.
- Look for "Practical_Grammar 1" and click on "Create your own version".
- Now click on "Edit your version".
You have now arrived in the grammar editor for the grammar "Practical_Grammar 1", where you can make changes to the grammar.
Look around a bit, but leave the buttons "Output Parameters" and "Output" alone for now.
Clicking on the buttons in the row beginning with "Sentences". Whenever you do, a window will open where you can enter or change information. Do not make any changes yet. To get to a different input window, just click on its button.
The four input buttons have the following functions:
- Sentences: here you can type in example sentences that you want to test.
- Declarations: here you can enter information that determines the behavior of the program.
- Grammar: this where you add phrase structure rules.
- Lexicon: the place to write lexical entries.
Exercise 2
We are now going to write a first grammar. The goal of the grammar is to recognize all the sentences from Exercise 1 in Week 1. Here they are one more time, together with the syntactic categories we want to use in the exercise:
Sentences
(1) John [disappeared].
(2) The bottle [broke].
(3) Martha [stayed at the hospital].
(4) Fred [resides in Chicago].
(5) Robert [went to the hospital].
(6) Alice [moved into the room].
(7) Joe [saw Fred].
(8) Alice [broke the bottle].
(9) We [moved it into the room].
(10) Fred [took Alice to the hospital].
(11) John [sent Martha a check].
(12) We [gave Fred a wastebasket].
Syntactic Categories
S, NP, N, VP, V, PP, P, AP, A, D
The first example sentence
- Go to the xlfg window.
- Click on "Sentences".
Under "Sentences to parse" you see all the test sentences for the grammar. Our first example sentence is already listed. Eventually, you will have to enter the other example sentences as well.
The example sentences is "John disappeared" and on the right we have told the program that this sentence is grammatical in English.
We will now test this example against the our grammar. To this end,
- Click on the blue "Parse" button right below the name of our project. "to parse" in German means "Daten analysieren".
This instructs xlfg to inspect all test sentences to see whether the grammar licenses them.
The result is diappointing: a new window opens and we see our test sentence in red. This means that the grammar could find a well formed constituent structure for the sentence and predicts that it is ungrammatical in English. This prediction is wrong, which means we need to change the grammar.
- Click on "Input" to get back to the editor window.
Let us find out why the grammar cannot parse the sentence "John disappeared". Let us inspect the grammar!
- Click on "Lexicon". There is only one line:
John N;
This says that there is a lexical entry spelled "John" and that its syntactic category is "N". This makes sense.
When you think about it for a moment, you realize why the grammar does not recognize our example sentence "John disappeared". The reason is that the grammar does not know the word "disappeared" yet and therefore cannot handle sentences containing that word!
Let us repair that shortcoming:
- Enter the following into the second line of the "Lexicon" editor:
disappeared V;
Make sure that you end every lexical entry with a semicolon. Otherwise, xlfg will create an error message. It needs to know where one lexical entry ends and the next one starts.
Now we come to one of the most important things for you to remember!
After every change to the grammar that you want to save, you need to go to the menu "Projects" and choose the item "Save this version". If you forget to do that and want to parse, then xlfg still uses your old grammar! Worse yet, if you leave the editor you are in (say, "Lexicon") and click on another one (say "Grammar"), then the changes you made will be lost and you need to type in the information again!
- Click on the menu "Projects" and choose the item "Save this version".
Now that the grammar knows both words of our sentence, we parse the sentence again:
- Click on parse.
The output window opens again and again we see our example sentence in depressing red: the grammar still does not recognize our sentence!
- Click on "Input" to get back to the editor. When you click on "Grammar", you will see immediately why the sentence is not recognized: the grammar does not have all the phrase structure rules need to draw a complete tree for the sentence!
Let's fix this problem next.
- Add the following PS rules, one per line, making sure that you end each rule with a semicolon:
NP -> N; VP -> V;
Use the button labeled "->" above line 1 to enter the arrow!
- Save the grammar.
- Parse.
Now, the output window should open and display a constituent structure (= phrase structure) for our sentence. This means that our grammar recognizes the string "John disappears" as grammatical!