pattern.de
The pattern.de module contains a fast, regular expressions-based tagger/chunker for German (identifies nouns, adjectives, verbs, etc. in a sentence) and tools for German verb conjugation and noun singularization & pluralization.
It can be used by itself or with other pattern modules: web | db | en | search | vector | graph.
Documentation
The functions in this module take the same parameters and return the same values as their counterparts in pattern.en. Refer to the documentation there for more details.
Noun singularization & pluralization
For German nouns there is singularize() and pluralize(). The implementation uses a statistical approach with 84% accuracy for singularization and 72% for pluralization.
>>> from pattern.de import singularize, pluralize >>> print singularize('Katzen') >>> print pluralize('Katze') Katze Katzen
Verb conjugation
For German verbs there is conjugate(), lemma(), lexeme() and tenses(). The lexicon for verb conjugation contains about 2,000 common German verbs; for unknown verbs it will fall back to a rule-based approach with an accuracy of about 87%.
>>> from pattern.de import conjugate, INFINITIVE, PRESENT, SG, SUBJUNCTIVE >>> print conjugate('war', tense=INFINITIVE) >>> print conjugate('war', PRESENT, 1, SG, mood=SUBJUNCTIVE) sein sei
German verbs have more tenses than English verbs. In particular, the plural differs for each person and there are additional forms for the IMPERATIVE and SUBJUNCTIVE mood. The conjugate() function takes the following optional parameters:
Tense | Person | Number | Mood | Aspect | Alias | Example |
INFINITVE | None | None | None | None | "inf" | sein |
PRESENT | 1 | SG | INDICATIVE | IMPERFECTIVE | "1sg" | ich bin |
PRESENT | 2 | SG | INDICATIVE | IMPERFECTIVE | "2sg" | du bist |
PRESENT | 3 | SG | INDICATIVE | IMPERFECTIVE | "3sg" | er ist |
PRESENT | 1 | PL | INDICATIVE | IMPERFECTIVE | "1pl" | wir sind |
PRESENT | 2 | PL | INDICATIVE | IMPERFECTIVE | "2pl" | ihr seid |
PRESENT | 3 | PL | INDICATIVE | IMPERFECTIVE | "3pl" | sie sind |
PRESENT | None | None | INDICATIVE | PROGRESSIVE | "part" | seiend |
PRESENT | 2 | SG | IMPERATIVE | IMPERFECTIVE | "2sg!" | sei |
PRESENT | 1 | PL | IMPERATIVE | IMPERFECTIVE | "1pl!" | seien |
PRESENT | 2 | PL | IMPERATIVE | IMPERFECTIVE | "2pl!" | seid |
PRESENT | 1 | SG | SUBJUNCTIVE | IMPERFECTIVE | "1sg?" | ich sei |
PRESENT | 2 | SG | SUBJUNCTIVE | IMPERFECTIVE | "2sg?" | du seiest |
PRESENT | 3 | SG | SUBJUNCTIVE | IMPERFECTIVE | "3sg?" | ihr sei |
PRESENT | 1 | PL | SUBJUNCTIVE | IMPERFECTIVE | "1pl?" | wir seien |
PRESENT | 2 | PL | SUBJUNCTIVE | IMPERFECTIVE | "2pl?" | ihr seiet |
PRESENT | 3 | PL | SUBJUNCTIVE | IMPERFECTIVE | "3pl?" | sie seien |
PAST | 1 | SG | INDICATIVE | IMPERFECTIVE | "1sgp" | ich war |
PAST | 2 | SG | INDICATIVE | IMPERFECTIVE | "2sgp" | du warst |
PAST | 3 | SG | INDICATIVE | IMPERFECTIVE | "3sgp" | er war |
PAST | 1 | PL | INDICATIVE | IMPERFECTIVE | "1ppl" | wir waren |
PAST | 2 | PL | INDICATIVE | IMPERFECTIVE | "2ppl" | ihr wart |
PAST | 3 | PL | INDICATIVE | IMPERFECTIVE | "3ppl" | sie waren |
PAST | None | None | INDICATIVE | PROGRESSIVE | "ppart" | gewesen |
PAST | 1 | SG | SUBJUNCTIVE | IMPERFECTIVE | "1sgp?" | ich wäre |
PAST | 2 | SG | SUBJUNCTIVE | IMPERFECTIVE | "2sgp?" | du wärest |
PAST | 3 | SG | SUBJUNCTIVE | IMPERFECTIVE | "3sgp?" | er wäre |
PAST | 1 | PL | SUBJUNCTIVE | IMPERFECTIVE | "1ppl?" | wir wären |
PAST | 2 | PL | SUBJUNCTIVE | IMPERFECTIVE | "2ppl?" | ihr wäret |
PAST | 3 | PL | SUBJUNCTIVE | IMPERFECTIVE | "3ppl?" | sie wären |
Instead of optional parameters, a single short alias, the part-of-speech tag, PARTICIPLE or PAST+PARTICIPLE can also be given. With no parameters, the infinitive form of the verb is returned.
Attributive & predicative adjectives
German adjectives inflect with an -e, -em , -en, -er, or -es suffix (e.g., neugierig → die neugierige Katze) depending on gender and role. You can get the base form with the predicative() command, or vice versa with attributive().
For predicative, a statistical approach is used with an accuracy of 98%. For attributive, you need to supply gender (MALE, FEMALE, NEUTRAL) and role (SUBJECT, OBJECT, INDIRECT, PROPERTY) as parameters. The gender() function can be used to guess the gender of a given noun, with about 75% accuracy.
>>> from pattern.de import attributive, predicative >>> from pattern.de import MALE, FEMALE, SUBJECT, OBJECT >>> print predicative('neugierige') >>> print attributive('neugierig', gender=FEMALE) >>> print attributive('neugierig', gender=FEMALE, role=OBJECT) >>> print attributive('neugierig', gender=FEMALE, role=INDIRECT, article="die") neugierig neugierige neugierige neugierigen
Parser
For parsing there is parse(), parsetree() and split(). Words processed with parse() are assigned tags such as NN (nouns) or VB (verbs). See the pattern.en documentation (here) how to manipulate Sentence objects returned from split().
>>> from pattern.de import parse, split >>> s = parse('Die Katze liegt auf der Matte.') >>> s = split(s) >>> print s.sentences[0] Sentence('Die/DT/B-NP/O Katze/NN/I-NP/O liegt/VB/B-VP/O' 'auf/IN/B-PP/B-PNP der/DT/B-NP/I-PNP Matte/NN/I-NP/I-PNP ././O/O')
The parser is built on Gerold Schneider & Martin Volk's German language model. The accuracy is reported around 95% (for 15% unknown words), but the score for the implementation in Pattern can vary slightly, since the original STTS tagset is mapped to Penn Treebank tagset. If you need to work with the original tags you can also use parse() with an optional parameter tagset="STTS".
Reference: Schneider, G., Volk, M. (1998). Adding manual constraints and lexical look-up to a Brill-tagger for German. Proceedings of ESSLLI-98.
Sentiment analysis
There's no sentiment() function for German yet.
Note: We did a test by assigning scores (-1.0–1.0) to adjectives but, unlike for English and Dutch, for German this approach only had 35% accuracy. So we need to try other approaches.