all the nessecary files will be loaded, this might take about one or two seconds. But right after the module is imported generating works fast.
fromgermaNLGimportPhrase
2. Creating simple sentences
A verb, a subject and an object can be added by simple functions of the Phrase class
After the settings are made, the sentence can be realised and it will be printed out
# creating a new phrasep=Phrase()
# setting a verbp.VERB("suchen")
# setting a subject p.SUBJECT("Person")
# setting an objectp.OBJECT("Schlüssel")
# Satz realisierenp.realise()
'die Person sucht den Schlüssel'
2.1 Person, numer and pronouns
Person and number can be set by using the methods setPERSON() and setNUMBER()
Otherwise person and number are handled automaticly
pronouns can be filled in as subjects or objects (pronouns need to be lowercased!)
possessive pronouns can be put in front of a noun
p=Phrase()
p.VERB("lieben")
# pronoun as subject p.SUBJECT("ich")
# setting an object with a possessive pronounp.OBJECT("mein Hund")
p.realise()
'ich liebe meinen Hund'
3 Adding adjectives
Adjectives can be added to components
The degree of an adjective can be set by giving one of the following arguments: positive, comparative, superlative (Default: positive)
more adjectives can be added, by multiple uses of the function addADJ()
# adding an adjective to the objectp.object.addADJ("alt")
p.realise()
'ich liebe meinen alten Hund'
# setting adjective degreee to comparativep.object.setADJdegree("comparative")
p.realise()
'ich liebe meinen älteren Hund'
# setting adjective degreee to superlativep.object.setADJdegree("superlative")
p.realise()
'ich liebe meinen ältesten Hund'
3.1 More complex adjectival constructions
It's possible to add more than one word when setting an adjective
In this case the last word of the string will be inflected
Gender, stem changes and irregularities are handled by the module automaticly
Since german has a complex declination system and the fact, that different verbs need to be handled differently it might be useful to specify how Objects should be handled, to avoid mistakes
To make sure there will be no mistake generated features can be set for the the Objects, also for subjects
If there are no modifications made the system will handle declination by it self (which can lead to mistakes)
the following features can be set:
cases: "nom","dat","acc","gen"
number: "sg","pl"
articles: "def","indef","null"
negated article (kein): "neg"
gender: "f","m","n"
p=Phrase()
p.VERB("vergeben")
p.SUBJECT("Mädchen")
p.OBJECT("Junge")
# setting the features of the subjectp.subject.setFEATURES(["pl"])
# setting the features of the objectp.object.setFEATURES(["dat","indef"])
p.realise()
'die Mädchen vergeben einem Jungen'
4.1 Specifiying gender
There are some nouns in German which have the same form but may have different gender
For this reason it's possible to set the gender features "m","f","n"
For all other nouns gender is handled automaticly
p=Phrase()
p.VERB("operieren")
p.SUBJECT("Arzt")
p.OBJECT("Beamte")
# set gender to femininp.object.setFEATURES(["f"])
p.realise()
'der Arzt operiert die Beamte'
# set gender to masculinp.object.setFEATURES(["m"])
p.realise()
'der Arzt operiert den Beamten'
4.2 Extending a subject or an object
Subjects and objects can be extended to create PP's, complements with conjunctions or genetive complements
if an extension is created and no other parameters are set, by default a conjunctional phrase will be realised with the conjunction "und"
p=Phrase()
p.VERB("suchen")
p.SUBJECT("Frau")
p.OBJECT("Schlüssel")
# features: accusative and indefinitep.object.setFEATURES(["acc","indef"])
# extending subjectp.subject.extend("Mann")
# add a conjunctionp.subject.addCONJUNCTION("und")
# extending objectp.object.extend("Kühlschrank")
# add a preposition (a prepositional phrase will be created)p.object.addPREPOSITION("in","dat")
p.realise()
'die Frau und der Mann suchen einen Schlüssel im Kühlschrank'
# Example for a genitive complementp=Phrase()
p.SUBJECT("Freund")
p.subject.extend("Junge")
p.subject.setGENITIVE()
p.realise()
'der Freund des Jungen'
4.3 Modifying extensions
The created extension is an object of the instance it was created for
It can be modified like a subject or an object
p=Phrase()
p.SUBJECT("Vater")
p.subject.addADJ("alt")
p.subject.extend("Junge")
# adding an adjective to the extension# (by default the conjunction "und" is used)p.subject.extension.addADJ("flink")
p.realise()
'der alte Vater und der flinke Junge'
4.4 Adding an object
A second object may be added and will be treated as an indirect object
instance an object by using the method addOBJECT()
the new created object can be modified, by corresponding to "object2"
p=Phrase()
p.SUBJECT("Mutter")
p.VERB("schreiben")
p.OBJECT("Tochter")
# Adding another objectp.addOBJECT("Brief")
# Modifying the new objectp.object2.setFEATURES(["indef"])
p.realise()
'die Mutter schreibt der Tochter einen Brief'
4.5 Reflexive
The reflexive can be activated by using the method setREFLEXIVE()
When reflexive was set to True the Object will refer to the subject, so a reflexive Pronoun is treated like the object and can be modified like it