An NLG tool for Finnish
Project description
syntax_maker is a script that tries to create syntactically correct Finnish sentences based on a hand written grammar and automatically learned information about the language.
** NOTE 1: ** This tool requires Omorfi, you can download the correct binary version from http://mikakalevi.com/omorfi ** NOTE 2: ** You need to install libhfst and hfst from https://kitwiki.csc.fi/twiki/bin/view/KitWiki/HfstCommandLineTools
## Creating a sentence ##
Everything starts with a verb. To start a new sentece, call createVerbPharse with the desired verb. This will select the correct verb phrase template in grammar.json based on what is known about the verb’s valency. E.g. for the verb sammua VP1 is chosen and for the verb nuolla VP2 gets selected. If you need to create sentences with the copula, use createCopulaPhrase.
Example:
from syntaxmaker.syntax_maker import * vp = createVerbPharse(“uneksia”)
The next thing we’ll need to do is to add a subject for the verb pharse. This can be done by creating a noun phrase based on a noun or personal pronoun. If you want to use a personal pronoun, call createPersonalPronounPhrase. Otherwise, a regular noun phrase can be created by createPhrase(“NP”, noun).
Let’s add a subject and an object to our verb phrase:
vp.components[“subject”] = createPhrase(“NP”, “rantaleijona”, {u”NUM”: “PL”})
dir_object = createPhrase(“NP”, “aalto”, {u”NUM”: “PL”}) vp.components[“dir_object”] = dir_object
We can get a string representation of the sentence:
>>>print vp.to_string() rantaleijonat uneksivat aalloista
Furthermore, we can add an adjective to define one of our noun phrases by creating an adjective phrase with createPhrase(“AP”, adjective). An adverb can be added to the adjective phrase when we create an adverb phrase createPhrase(“AdvP”, adverb).
Let’s add an adjective to our object:
ap = createPhrase(“AP”, “korkea”) dir_object.components[“attribute”] = ap
And an adverb to the adjective phrase:
ap.components[“attribute”] = createPhrase(“AdvP”, “erittäin”)
The new string representation of the sentence will thus be:
>>>print vp.to_string() rantaleijonat uneksivat erittäin korkeista aalloista
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for syntaxmaker-1.0.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a0d2d593f02d9d669e1d96f00f216546441aef91d15c6ba30193483057d55db |
|
MD5 | 1f62fa5f8ac6e4e9c39054a43f54d6c1 |
|
BLAKE2b-256 | bd042bd576b992e6091311166d0c624f9d394e8a8b9f5c91864beecdc245ff56 |