Skip to main content

A pure-python wrapper for the pykko Finnish morphological analyser and inflector

Project description

PyPykko

PyPykko is a wrapper around pykko. It provides the basic analysis and generation API in an easily installable package. PyPykko can be installed without compiling anything (as the transducers are pre-compiled) or pulling in any native dependencies (such as hfst).

This package contains (slightly modified for kfst compatibility versions of) all the files in the tools directory of pykko as well as constants.py and file_tools.py from the scripts directory and utils.py from the scripts directory as scriptutils.py. It also provides the novel reinflect.py and extras.py.

Installation

PyPykko is available on PyPI and can be installed with pip:

pip install pypykko

Usage

There are two main Python methods utils.analyze and generate.generate_wordform inherited from Pykko proper; besides these there is reinflect.reinflect that is perhaps a more suitable interface for general reinflection. There is also bolted-on alignment support in extras.analyze_with_compound_parts.

reinflect.reinflect

reinflect.reinflect tries to reinflect a word to the best of its ability. It can be instructed either with a model word or with a specific form. Further, it can be given the form the original word was in if known ahead of time and the part-of-speech of the word.

>>> from pypykko.reinflect import reinflect
>>> reinflect("mökkiammeemme", model="talossa")
{'mökkiammeessa'}
>>> reinflect("esijuosta", model="katselemme")
{'esijuoksemme'}
>>> reinflect("mökkiammeemme", new_form="+sg+nom")
{'mökkiamme'}
>>> reinflect("möhkö", new_form="+pl+ine+ko")
{'möhköissäkö'}
>>> reinflect("viinissä", model="talot")
{'viinet'}
>>> reinflect("viinissä", model="talot", orig_form="+sg+ine")
{'viinit'}
>>> reinflect("hömppäämme", model="juokset", pos="verb")
{'hömppäät'}
>>> reinflect("hömppäämme", model="juokset", pos="noun")
{'hömpät'}

utils.analyze and extras.analyze_with_compound_parts

utils.analyze should be used in most cases:

>>> from pypykko.utils import analyze
>>> analyze("hätkähtäneet")
[('hätkähtäneet', 'Lexicon', 'hätkähtää', 'verb', '', '', '+past+conneg+pl', 0.0), ('hätkähtäneet', 'Lexicon', 'hätkähtää', 'verb', '', '', '+part_past+pl+nom', 0.0)]

The fields of the outcoming tuple are:

  1. Surface form (input as it is given)
  2. The source of the word: eg. Lexicon if it is a word known ahead of time, Guesser|Any for unknown words and Lexicon|Pfx for words analyzed as the compounds of known words.
  3. The lemma form of the word; notably this can contain pipe symbols to delimit compound parts: ilma|luukku. Sometimes Finnish has infix inflection, and the compound parts can be separately inflected (eg. uudenvuoden -> uusi|vuosi).
  4. The part of speech of the word.
  5. The homonym number of the word (can be empty). Eg. the word viini has two senses that have slightly different inflection: wine (viini -> viinin) and quiver (viini -> viinen). In cases where such homonyms exist but it is impossible to tell which form is presented (the nominative form viini here), we get both interpretations:
[('viini', 'Lexicon', 'viini', 'noun', '1', '', '+sg+nom', 0.0), ('viini', 'Lexicon', 'viini', 'noun', '2', '', '+sg+nom', 0.0)]

In cases where the form is unambiguous (eg. viinen), we get only the homonym number that is relevant:

[('viinen', 'Lexicon', 'viini', 'noun', '2', '', '+sg+gen', 0.0)]

In cases where the homonym is different in different interpretations, we get annotated interpretations:

[('viinin', 'Lexicon', 'viini', 'noun', '2', '', '+pl+ins', 0.0), ('viinin', 'Lexicon', 'viini', 'noun', '1', '', '+sg+gen', 0.0)]
  1. Register annotation, eg:
>>> analyze("höpsöillä")
[('höpsöillä', 'Lexicon', 'höpsö', 'noun', '', '⟨coll⟩', '+pl+ade', 0.0), ('höpsöillä', 'Lexicon', 'höpsö', 'adjective', '', '⟨coll⟩', '+pl+ade', 0.0)]
  1. Morphological tags that name the inflectional form.

extras.analyze\_with\_compound\_parts is of use when it is useful to know the exact inflected forms of the compound parts of a word. Eg. when looking at "isonvarpaan", one might want to not only know that it is the compound of "iso" and "varvas" but also that they are in the forms "ison" and "varpaan". extras.anlyze\_with\_compound\_parts returns the character ranges matching compound parts.

>>> analyze_with_compound_parts("isonvarpaan")
('isonvarpaan', 'Lexicon', 'iso|varvas', 'noun', '', '', '+sg+gen', 0.0, (range(0, 4), range(4, 11)))

generate.generate_wordform

generate\_wordform is a simple-to-use api to inflect in-lexicon words.

>>> from pypykko.generate import generate_wordform
>>> generate_wordform("höpönassu", "noun", '+pl+abe+ko')
{'höpönassuittako'}

License

PyPykko is licensed under the MIT license like Pykko itself, as it is mostly constituted of Pykko's files with minor modifications. See the LICENSE file for details. Note that kfst (and kfst-rs) have less permissive licenses.

Files from Pykko itself are modified from the version in commit 95f3d51f0e94a1e88ab7c750f2bedcb6b3fd5edd. The compiled transducers are from the same commit.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pypykko-0.2.0b2.tar.gz (8.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pypykko-0.2.0b2-py3-none-any.whl (8.0 MB view details)

Uploaded Python 3

File details

Details for the file pypykko-0.2.0b2.tar.gz.

File metadata

  • Download URL: pypykko-0.2.0b2.tar.gz
  • Upload date:
  • Size: 8.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for pypykko-0.2.0b2.tar.gz
Algorithm Hash digest
SHA256 e9b6368847c66dc0b8178507339a6e74cac7ac0b3e1ced8eedd2a70ba7a23c9e
MD5 490bb4f5991151918c5549a1bf2ea98e
BLAKE2b-256 9a9a57a35249fc62858f5d1c77000af4d74600ad6714b08e69e957f30dc8e104

See more details on using hashes here.

File details

Details for the file pypykko-0.2.0b2-py3-none-any.whl.

File metadata

  • Download URL: pypykko-0.2.0b2-py3-none-any.whl
  • Upload date:
  • Size: 8.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for pypykko-0.2.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 37c5fbec1d8101b0d2011eb79dbef07719142a06a8611faa9f131b1db55f3908
MD5 5926da3bc15bdfed2c6f8fca23fde376
BLAKE2b-256 e129759ad294fa2e54cd27fefbc4a2a2442fe49c2e6baa31df23d981f395c237

See more details on using hashes here.

Supported by

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