Commit f7e42934 authored by jfschaefer's avatar jfschaefer

added assignment 1

parent 52534827
This diff is collapsed.
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Assignment 1\n",
"\n",
"In this assignment we will develop a small grammar for parsing and translating sentences about animals, such as:\n",
"* *the lion sleeps*\n",
"* *the big lion sleeps*\n",
"* *the lion is big*\n",
"* *the big lion is fast*\n",
"* *the big fast hungry lion sleeps*\n",
"* ..."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We will start with the abstract syntax.\n",
"Suggestions for the categories are already filled in. Feel free to change them."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"abstract AnimalGrammar = {\n",
" cat\n",
" S; -- sentence (\"the lion sleeps\")\n",
" NP; -- noun phrase (\"the big lion\")\n",
" VP; -- verb phrase (\"sleeps\" or \"is big\")\n",
" Adj; -- adjective (\"big\")\n",
" N; -- (common) nouns (\"lion\", \"big lion\")\n",
" fun\n",
" -- TODO: Fill this in\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And here is a lexicon:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"abstract AnimalLexicon = AnimalGrammar ** {\n",
" fun\n",
" lion, elephant, giraffe, zebra : N;\n",
" big, small, fast, slow, hungry : Adj;\n",
" sleep, run, eat : VP;\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now it's time to create a concrete syntax for the English language:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"concrete AnimalGrammarEng of AnimalGrammar = {\n",
" lincat\n",
" -- again, just a suggestion:\n",
" S = Str; NP = Str; VP = Str; Adj = Str; N = Str;\n",
" lin\n",
" -- TODO: Fill this in\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"concrete AnimalLexiconEng of AnimalLexicon = AnimalGrammarEng ** {\n",
" lin\n",
" lion = \"lion\"; elephant = \"elephant\"; giraffe = \"giraffe\"; zebra = \"zebra\";\n",
" big = \"big\"; small = \"small\"; fast = \"fast\"; slow = \"slow\"; hungry = \"hungry\";\n",
" sleep = \"sleeps\"; run = \"runs\"; eat = \"eats\";\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, the grammar should be able to parse some sentences:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"parse -lang=Eng \"the giraffe sleeps\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"parse -lang=Eng \"the hungry lion eats\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"parse -lang=Eng \"the big slow elephant sleeps\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"parse -lang=Eng \"the big zebra is slow\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## German Translations\n",
"\n",
"Now, we also want to be able to translate to German.\n",
"You should be able to do this without knowing any German (all necessary information should be provided).\n",
"The good news is that the word order stays the same in German.\n",
"However, there will be challenges when it comes to picking the right articles and adjective endings.\n",
"\n",
"#### Articles\n",
"\n",
"In English, you can use the definite article \"*the*\" for any noun.\n",
"In German, the article form depends on the gender of the noun.\n",
"\n",
"There are three grammatical genders in German:\n",
"\n",
"| | masculine | feminine | neuter |\n",
"|--------|-----------|----------|--------|\n",
"| article | *der* | *die* | *das* |\n",
"| Examples | *der Löwe* (the lion) | *die Giraffe* (the giraffe) | *das Zebra* (the zebra) |\n",
"| | *der Elefant* (the elephant) | | |\n",
"\n",
"\n",
"#### Adjective Endings\n",
"\n",
"The endings of German adjectives depend on how they are used. In our small example we fortunately need only two forms.\n",
"Lets take for example the German adjective *klein* (small).\n",
"If you say that something is small you use the base form *klein*.\n",
"If you use it after a definite article, you have to use the ending *-e*. Example\n",
"* *das Zebra ist klein* (the zebra is small)\n",
"* *das kleine Zebra rennt* (the small zebra runs)\n",
"\n",
"### Summary (i.e. what you need to do)\n",
"\n",
"Each noun has a gender (masculine, feminine, neuter), which we need to store.\n",
"Each adjective has two forms: one for using it after *ist* (is) and one for using it after a definite article.\n",
"When you create a noun phrase, you need to pick the article based on the gender of the noun.\n",
"\n",
"Some more example sentences:\n",
"* *der Löwe schläft* (the lion sleeps)\n",
"* *das kleine Zebra rennt* (the little zebra runs)\n",
"* *der große Löwe schläft* (the big lion sleeps)\n",
"* *der Löwe ist groß* (the lion is big)\n",
"* *der große schnelle Löwe schläft* (the big fast lion sleeps)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"concrete AnimalGrammarGer of AnimalGrammar = {\n",
" param\n",
" -- TODO: you will need some parameter types\n",
" lincat\n",
" S = Str;\n",
" NP = Str;\n",
" VP = Str;\n",
" -- TODO: Add `Adj` and `N` (remember record types and table types)\n",
" lin\n",
" -- TODO\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"concrete AnimalLexiconGer of AnimalLexicon = AnimalGrammarGer ** {\n",
" oper\n",
" -- TODO: implement operations mkN and mkAdj for the lexicon below.\n",
" -- Feel free to replace `masculine` etc. by whatever you chose above.\n",
" -- Note: you will have to append an \"e\" to the adjectives.\n",
" -- You can do this in GF using the + operator:\n",
" -- If `s` is the string, then `s + \"e\"` is the string with an \"e\" appended.\n",
" -- This only works in operations, because they are executed during run time.\n",
" lin\n",
" lion = mkN \"Löwe\" masculine;\n",
" elephant = mkN \"Elefant\" masculine;\n",
" giraffe = mkN \"Giraffe\" feminine;\n",
" zebra = mkN \"Zebra\" neuter;\n",
" \n",
" big = mkAdj \"groß\";\n",
" small = mkAdj \"klein\";\n",
" fast = mkAdj \"schnell\";\n",
" slow = mkAdj \"langsam\";\n",
" hungry = mkAdj \"hungrig\";\n",
" \n",
" sleep = \"schläft\";\n",
" run = \"rennt\";\n",
" eat = \"isst\";\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now the following sentences should be parsable:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"parse -lang=Ger \"der Löwe ist klein\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"parse -lang=Ger \"das schnelle Zebra ist groß\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"parse -lang=Ger \"die große schnelle Giraffe rennt\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"What GF command can you use to translate the German sentence \"*das kleine Zebra ist schnell*\"?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "GF",
"language": "gf",
"name": "gf"
},
"language_info": {
"file_extension": ".gf",
"mimetype": "text/gf",
"name": "gf"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment