Home | Tutorial | Flags
» »
Help
Phrase code reference
Phrase code reference
Coding phrases
This is the code reference for The Grammar Project's phrase programming language.
The phrase() function
The phrase() function describes a phrase in one or more languages. A phrase() function contains a list of statements that define the words used in the phrase, the translations of the phrase and the tests used to confirm the phrase compiles correctly.
Here is an example of a phrase() function that describes the phrase "the dog runs through the garden" in English and German:
phrase()
{
    article1 = dict(deter).words(en, the).words(de, der).pin();
    noun1 = list(noun).words(en, boy+girl+horse+man+woman);
    noun1 = list(noun).words(de, hund+katze);
    noun2 = list(noun).words(en, garden+house);
    run = dict(verb).words(en, run).words(de, laufen).pin();
    through = dict(prep).words(en, through).words(de, durch).pin();
    translation = translation(en, "the dog runs through the garden")
    {
        code = "(article1) (noun1:nom+sing+anno+isSubject) (run:3rd+present,number←noun1) (through) (article1) (noun2:acc+sing)";
    }
    translation = translation(de, "der Hund läuft durch den Garten")
    {
        code = "(article1:CGN←noun1) (noun1:nom+sing+isSubject) (run:3rd+present,number←noun1) (through) (article1:CGN←noun2) (noun2:acc+sing)";
    }
    test = test(en+the boy runs through the garden, de+der Junge läuft durch den Garten);
    test = test(en+the dog runs through the garden, de+der Hund läuft durch den Garten);
    test = test(en+the boy runs through the house, de+der Junge läuft durchs Haus);
    test = test(en+the dog runs through the house, de+der Hund läuft durchs Haus);
}
The words used in the phrase, article1, noun1, etc..., are defined at the top of the phrase. Each word definition has a variable name such as noun1, and a word filter. Word filters are described below.
The translation() functions describe the phrase in a specific language. Phrases can also contain multiple translations in the same language.
The test() functions describe the test phrases, groups of phrases that the phrase() function is expected to produce. A compiler warning is displayed when the phrase() function cannot generate the test phrases. Test phrase are also used to create tutorials for a phrase when no other words have been provided for testing.
The translation() function
The translation() function takes two parameters, the language of the translation and the name of the translation.
The most important statement in a translation() function is the code definition, which defines the grammar of the translation using the words declared in the phrase() function.
The example below is the most basic code declaration and consists of raw text
code = "the dog runs through the garden";
In the next example "the" has been replaced by a reference to the word article1.
code = "(article1) dog runs through the garden";
In the next example "dog" has been replaced by a reference to the word noun1.
code = "the (noun1:nom+sing) runs through the garden";
This is similar to the example, above, except there are two new parameters added, nom and sing, abbreviations of nominative and singular, which specify the declension of noun1.
Grammatical declensions often come from other words. For example, in the phrase "he runs" the declension of the verb is "runs" and not "run" because the pronoun "he" is first person singular. The example below shows the syntax for this.
code = "the (noun1:nom+sing) (toRun:3rd+present,number←dog) through the garden";
In this example a binding is used. The syntax number←dog binds the number of noun1 to the declension of toRun. The noun noun1 is singular so the declension of toRun will be 3rd person singular, "he runs".
Bindings are essential if the phrase is going to be grammatically correct. They are usually employed between pronouns and verbs, and between adjectives and nouns. The arrow ← character can also be typed as <-.
Multiple properties can be bound to the same word like this (the:number+gender+case←noun1). Some bindings are initialized. For example, in (the:CGN←noun1) the CGN is Case, Gender and Number. CGN (case+gender+number) is often used to bind german adjectives with nouns, and FGNP (formality+gender+number+person) to bind pronouns and verbs.
Word filter functions
The table below shows the functions for declaring list of words.
Code
Description
list(wordType)
Filters a restricted list of words for the wordType.
word1 = list(noun);
Filters the nouns from a restricted list of words.
dict(wordType)
Filters all words for the wordType.
word1 = dict(adj);
Filters the adjectives from all words.
copyOf(src)
Copies the result of another filter src.
word1 = copyOf(word2);
Declares a new list of words word1, including all the words in word2.
cats(language,category[])
Filters words by category.
word1 = dict(noun).cats(*,animal);
Fills word1 with nouns that have the category "animal".
word1 = dict(noun).cats(*,animal+furniture);
Fills word1 with nouns that have the category "animal" or "furniture".
word1 = dict(noun).cats(*,animal-pet);
Fills word1 with nouns that have the category "animal", but do not have the category "pet".
word1 = dict(noun).cats(en,animal);
Fills word1 with nouns that have the category "animal" in their English translation.
props(language,property[])
Filters words by property.
word1 = dict(pronoun).props(en,sing+fem);
Fills word1 with pronouns that are singular and feminine in their English translation.
words(language,name[])
Filters words by word name.
word1 = dict(pronoun).words(en,dog+cat);
Fills word1 with nouns "dog" or "cat" in their English translation.
word1 = dict(pronoun).words(en,-dog-cat);
Fills word1 with nouns "dog" or "cat" in their English translation.
word1 = dict(noun).words(en,train).words(de,zug);
Fills word1 with nouns "train" in English and "zug" in German. word1 will contain "train", "zug" and "bahn".
pin()
Pins a translation together.
word1 = dict(noun).words(en,train).words(de,zug).pin();
Fills word1 with the translation "train" and "zug".
word1 = dict(noun).words(en,dog).words(de,katze).pin();
Fills word1 with no words, there is no translation of "dog" and "katze".
Match functions
The match functions define the relationships between two or more word variables.
Code
Description
tag(tagName[])
Specifies the words for a match. This function must come first in every match chain.
match = tags(noun1+noun2)...
Creates a new match for noun1 and noun2.
same()
Matches words that are the same.
match = tags(noun1+noun2).same();
Matches words from noun1 and noun2 that are the same.
different()
Matches words that are not the same.
match = tags(noun1+noun2).different();
Matches words from noun1 and noun2 that are not the same.
strict(property[])
Matches words using a strict comparison of one or more word properties.
match = tags(pronoun1+pronoun2).strict(gender);
Matches words from pronoun1 and pronoun2 that have the same gender. For example, "he" and "himself" have the same gender. A strict comparison means that if either word being compared does not have gender, the words are not matched. For example, "he" and "I" cannot be matched because "I" does not have gender.
flexible(property[])
Matches words using a flexible comparison of one or more word properties.
match = tags(pronoun1+pronoun2).flexible(gender);
Matches words from pronoun1 and pronoun2 that have the same gender. A flexible comparison means that if one of the words has no gender, and the other does, the words are matched. For example, "he" and "I" are matched, but "I" and "you", neither of which have gender, are not matched.
loose(property[])
Matches words using a loose comparison of one or more word properties.
match = tags(pronoun1+pronoun2).loose(gender);
Matches words from pronoun1 and pronoun2 that have the same gender. A loose comparison means that if either or both words being compared does not have gender, the words are matched. For example, "he" and "I" are matched because "I" does not have gender, and "I" and "you" are matched, neither of which have gender.
invert()
Inverts the result of a match.
match = tags(pronoun1+pronoun2).strict(number).invert();
Matches words that do no have the same number, "he" and "they" would match because one is singular and one is plural.
reality()
Applies the reality map to nouns and adjectives.
match = tags(noun1+adj1).reality();
In this example "blue" and "car" would match because a car can be blue. "angry" and "chair" would not match because a chair cannot be angry.
find(wordNames[])
Matches words using a list of word names.
match = tags(pronoun1+pronoun2).find(i+we,i,we).invert();
This match is useful for sentences like "I will see him today". The sentence will look odd if the pronouns are "i" and "we": "we will see me today".
props(property[])
Limits the match to words sharing the same properties.
match = tags(pronoun1+pronoun2).props(2nd).loose(number+gender);
This match will only apply to pronouns that are second person.
eval(expr)
Matches words using their numeric value.
match = tags(number1+number2).eval(number1 == number2 + 1);
This will match number1 "five" and number2 "four".
match = tags(number1+number2).eval(number1 == number2 - 1);
This will match number1 "five" and number2 "six".
Object values
These are the constants used when defining gender, number, verb part and German adjective form:
Object
Code
Gender
masculine, masc, feminine, fem, neuter or neut.
Number
singular, sing, plural or plur.
Verb part
fixedPart, fixPart, variablePart, varPart, joinedPart or joinPart.
German adjective forms
withNoArticle, noArt, withDefiniteArticle, withThe, withIndefiniteArticle or withA.
Verb tenses
Code
Description
present or pres
The present tense.
English: I ask
German: ich singe
presentProgressive or presProg
The present progressive or present continuous, only available in English.
English: I am asking
perfectProgressive or perfProg
The perfect progressive or present continuous, only available in English.
English: I have been asking
imperfectProgressive or imperfProg
The imperfect progressive or present continuous, only available in English.
English: I was asking
perfect
The perfect tense.
English: I have asked
German: ich habe gefragt
imperfect or imperf
The imperfect tense.
English: I asked
German: ich fragte
pluperfect or pluperf
The pluperfect tense.
English: I had asked
German: ich hatte gefragt
presentConditional or presCond
The present conditional tense.
English: I would asked
German: ich würde fragen
future or fut
The future tense.
English: I will ask
German: ich werde fragen
presentConjunctive or presConj
The present conjunctive tense, only available in German.
German: ich frage
imperfectConjunctive or impConj
The imperfect conjunctive tense, only available in German.
German: ich fragte
imperative or impera
The imperative tense.
English: ask!
German: fragen!
gerund
The verb gerund, a verb functioning as a noun, only available in English.
English: asking (e.g. "he likes asking")
pastParticiple or pastPart
The verb past participle.
presentParticiple or presPart
The verb present participle.