Skip to main content

FinMeter

DOI DOI

FinMeter is a library for analyzing poetry in Finnish. It handels typical rhyming such as alliteration, assonance and consonance, Japanese meters and Kalevala meter. It can also be used to hyphenate Finnish.

pip install finmeter

If you use the methods relating to semantics, metaphors and sentiment, you will need to run:

python3 -m finmeter.download 

Sentiment analysis requires tensorflow (tested on 1.9.0 and numpy 1.16.4).

Hyphenation

Finnish words can be divided into syllables like so

import finmeter
finmeter.hyphenate("hattu")
>> hat-tu
finmeter.syllables("hattu")
>> ["hat", "tu"]
finmeter.count_sentence_syllables("kissa juoksi")
>> 4

Rhyming

FinMeter can be used to check whether two words rhyme

import finmeter
finmeter.assonance("ladata", "ravata") #True
finmeter.consonance("kettu", "katti") #True
finmeter.full_rhyme("pallolla", "kallolla") #True
finmeter.alliteration("voi", "vehnä") #True

Syllabic meters

Meters based on the number of syllables can be assessed by FinMeter

import finmeter
finmeter.list_possible_meters()
>> ['tanka', 'kalevala', 'katauta', 'sedooka', 'bussokusekika', 'haiku', 'chooka']
finmeter.assess_meter(u"kissa juoksee\nkovaa juoksee", "haiku")
>> {'verse_results': [(False, '4/5'), (False, '4/7')], 'poem_length_error': '2/3', 'poem_length_ok': False}

The result is a dictionary cointaining information about the meter for each verse in "verse results" and about the overall length in "poem_length_error". Note: For Kalevala you should use analyze_kalevala instead.

Kalevala meter

Kalevala meter functionality takes the poetic foot into account and accepts verses of upto 10 syllables providing that certain poetic rules are met. In addition, the method assess other features important in Kalevala

import finmeter
finmeter.analyze_kalevala(u"Vesi vanhin voitehista\nJänö juoksi järveen")
>> [{'base_rule': {'message': '', 'result': True}, 'verse': u'Vesi vanhin voitehista', 'normal_meter': True, 'style': {'alliteration': True, 'viskuri': True}}, {'base_rule': {'message': 'Not enough syllables', 'result': False}, 'verse': u'J\xe4n\xf6 juoksi j\xe4rveen', 'style': {'alliteration': True, 'viskuri': True}}]

The method returns a list of analysis results for each verse. If base_rule is True, it means that the verse follows the Kalevala meter, both in syllables and in foot.

Syllable length

To check if a syllable is short, use the following method

import finmeter
finmeter.is_short_syllable("tu") 
>> True

Semantics

The library has a variety of different functions realted to semantics

Concreteness

from finmeter import semantics

semantics.concreteness("kissa")
>> 4.615
semantics.is_concrete("kissa")
>> True

The former method outputs True if the concreteness of the word is equal or greater than 3. The latter method outputs a concreteness score from 1 to 5. Both of the methods will return None for out of vocabulary words.

Semantic clusters

from finmeter import semantics

semantics.semantic_clusters(["kissa", "koira", "näätä", "hauki", "vesi", "lemmikki", "puhelin", "tieto|kone", "toimisto"])
>> [['koira', 'lemmikki', 'kissa', 'näätä'], ['vesi', 'hauki'], ['toimisto', 'tieto|kone', 'puhelin']]
semantics.similarity_clusters(["koira", "kissa", "hevonen"], ["talo", "koti", "ovi"])
>> 0.18099508
semantics.cluster_centroid(["koira", "kissa", "hevonen"])
>> [-5.84886856e-02 -1.10119150e-03 -3.40119563e-03......]

The library can be used to cluster words together into semantic clusters and to assess the similarity of two word clusters.

Sentiment

The library provides a somewhat functional sentiment analysis, but I wouldn't hold my breath.

from finmeter import sentiment
sentiment.predict("Olipa kakkainen leffa")
>> -2
sentiment.predict("Kaikki on tosi kivaa")
>> 2

The possible values are -2 for strongly negative, -1 for negative, 1 for positive and 2 for strongly positive.

Metaphors

The library can give interpretations for metaphors. The lower the value, the more likely the interpretation. Example for mies on susi

from finmeter import metaphor
metaphor.interpret("mies", "susi", maximum=10)
>> {'A': [('yksinäinen', 0), ('nuori', 3)], 'Adv': [], 'V': [('raadella', 0), ('tappaa', 1), ('ampua', 2), ('liikkua', 2), ('kaataa', 4)], 'N': [('metsästäjä', 1), ('suu', 3), ('vaate', 4)], 'UNK': []}

maximum is an optional parameter to limit the number of interpretations. If you do not need POS tagging, you can pass pos_tags=False.

Cite

If you use this library, cite the following publication

Mika Hämäläinen and Khalid Alnajjar (In press). Let's FACE it. Finnish Poetry Generation with Aesthetics and Framing. In the Proceedings of The 12th International Conference on Natural Language Generation.

Metadata

Release files for finmeter 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for finmeter 2.0.1
File Size Uploaded Provenance Actions
finmeter-2.0.1.tar.gz 1.4 MB Without provenance Details for finmeter-2.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for finmeter 2.0.1
File Interpreter ABI Platform Actions
finmeter-2.0.1-py2.py3-none-any.whl Python 2, Python 3 none any Details for finmeter-2.0.1-py2.py3-none-any.whl

Total release size: 2.8 MB

Release files / finmeter-2.0.1.tar.gz

Download URL finmeter-2.0.1.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
d9e04cafa58cf53b4242f1e62725985da6a8b639fcd7181ef6fb3a207e4a50a3
BLAKE2b-256 checksum
How to use checksums
5851070588848fab5c39b080a186ad9d38ec814d180f059c26c07af31d15b844
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/18.5 requests-toolbelt/0.8.0 tqdm/4.15.0 CPython/2.7.10

Release files / finmeter-2.0.1-py2.py3-none-any.whl

Download URL finmeter-2.0.1-py2.py3-none-any.whl
Size 1.4 MB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
890a704aacc63f455f36798337aa741e0300c6c90289de38dc6ce9f6f9b3a05d
BLAKE2b-256 checksum
How to use checksums
c131c8045c5bdcc7dad30f7cc599c23cda1b55eb45492fe44c43f6831ba01efc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/18.5 requests-toolbelt/0.8.0 tqdm/4.15.0 CPython/2.7.10

Security for finmeter 2.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page