Skip to main content

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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

syntaxmaker-1.0.1-py2.py3-none-any.whl (2.5 MB view hashes)

Uploaded Python 2 Python 3

syntaxmaker-1.0.1-py2.7.egg (2.5 MB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page