# PyPykko
PyPykko is a wrapper around [pykko](https://github.com/pkauppin/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.
## Installation
PyPykko is available on PyPI and can be installed with pip:
```sh
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.
### 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.
```py
>>> 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
```py
>>> 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)]
```
6. 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)]
```
7. Morphological tags that name the inflectional form.
### generate.generate_wordform
`generate_wordform` is a simple-to-use api to inflect in-lexicon words.
```py
>>> 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 79aede77eb8ed1f91dd9a20c685f29da6c786d65. The compiled transducers are from the same commit.
Raw data
{
"_id": null,
"home_page": "https://github.com/fergusq/fst-python",
"name": "pypykko",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "finnish nlp morphology",
"author": "Th\u00e9o Salmenkivi-Friberg",
"author_email": "theo.friberg@helsinki.f",
"download_url": "https://files.pythonhosted.org/packages/0d/5c/2e9e1baf68311ff58be19fb499bb5fc951db6c1c3ba2656ab288c70db01d/pypykko-0.1.tar.gz",
"platform": null,
"description": "# PyPykko\n\nPyPykko is a wrapper around [pykko](https://github.com/pkauppin/pykko). It provides the basic analysis and generation API in an easily installable package.\nPyPykko can be installed without compiling anything (as the transducers are pre-compiled) or pulling in any native dependencies (such as hfst).\n\nThis 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.\n\n## Installation\n\nPyPykko is available on PyPI and can be installed with pip:\n\n```sh\npip install pypykko\n```\n\n## Usage\n\nThere 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.\n\n### reinflect.reinflect\n\n`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.\n\n```py\n>>> from pypykko.reinflect import reinflect\n>>> reinflect(\"m\u00f6kkiammeemme\", model=\"talossa\")\n{'m\u00f6kkiammeessa'}\n>>> reinflect(\"esijuosta\", model=\"katselemme\")\n{'esijuoksemme'}\n>>> reinflect(\"m\u00f6kkiammeemme\", new_form=\"+sg+nom\")\n{'m\u00f6kkiamme'}\n>>> reinflect(\"m\u00f6hk\u00f6\", new_form=\"+pl+ine+ko\")\n{'m\u00f6hk\u00f6iss\u00e4k\u00f6'}\n>>> reinflect(\"viiniss\u00e4\", model=\"talot\")\n{'viinet'}\n>>> reinflect(\"viiniss\u00e4\", model=\"talot\", orig_form=\"+sg+ine\")\n{'viinit'}\n>>> reinflect(\"h\u00f6mpp\u00e4\u00e4mme\", model=\"juokset\", pos=\"verb\")\n{'h\u00f6mpp\u00e4\u00e4t'}\n>>> reinflect(\"h\u00f6mpp\u00e4\u00e4mme\", model=\"juokset\", pos=\"noun\")\n{'h\u00f6mp\u00e4t'}\n```\n\n\n### utils.analyze\n\n```py\n>>> from pypykko.utils import analyze\n>>> analyze(\"h\u00e4tk\u00e4ht\u00e4neet\")\n[('h\u00e4tk\u00e4ht\u00e4neet', 'Lexicon', 'h\u00e4tk\u00e4ht\u00e4\u00e4', 'verb', '', '', '+past+conneg+pl', 0.0), ('h\u00e4tk\u00e4ht\u00e4neet', 'Lexicon', 'h\u00e4tk\u00e4ht\u00e4\u00e4', 'verb', '', '', '+part_past+pl+nom', 0.0)]\n```\n\nThe fields of the outcoming tuple are:\n\n1. Surface form (input as it is given)\n2. 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.\n3. 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`).\n4. The part of speech of the word.\n5. 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:\n```\n[('viini', 'Lexicon', 'viini', 'noun', '1', '', '+sg+nom', 0.0), ('viini', 'Lexicon', 'viini', 'noun', '2', '', '+sg+nom', 0.0)]\n```\nIn cases where the form is unambiguous (eg. viinen), we get only the homonym number that is relevant:\n```\n[('viinen', 'Lexicon', 'viini', 'noun', '2', '', '+sg+gen', 0.0)]\n```\nIn cases where the homonym is different in different interpretations, we get annotated interpretations:\n```\n[('viinin', 'Lexicon', 'viini', 'noun', '2', '', '+pl+ins', 0.0), ('viinin', 'Lexicon', 'viini', 'noun', '1', '', '+sg+gen', 0.0)]\n```\n6. Register annotation, eg:\n```\n>>> analyze(\"h\u00f6ps\u00f6ill\u00e4\")\n[('h\u00f6ps\u00f6ill\u00e4', 'Lexicon', 'h\u00f6ps\u00f6', 'noun', '', '\u27e8coll\u27e9', '+pl+ade', 0.0), ('h\u00f6ps\u00f6ill\u00e4', 'Lexicon', 'h\u00f6ps\u00f6', 'adjective', '', '\u27e8coll\u27e9', '+pl+ade', 0.0)]\n```\n7. Morphological tags that name the inflectional form.\n\n### generate.generate_wordform\n\n`generate_wordform` is a simple-to-use api to inflect in-lexicon words.\n\n```py\n>>> from pypykko.generate import generate_wordform\n>>> generate_wordform(\"h\u00f6p\u00f6nassu\", \"noun\", '+pl+abe+ko')\n{'h\u00f6p\u00f6nassuittako'}\n```\n\n\n## License\n\nPyPykko 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.\n\nFiles from Pykko itself are modified from the version in commit 79aede77eb8ed1f91dd9a20c685f29da6c786d65. The compiled transducers are from the same commit.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A pure-python wrapper for the pykko Finnish morphological analyser and inflector",
"version": "0.1",
"project_urls": {
"Bug Tracker": "https://github.com/fergusq/fst-python/issues",
"Homepage": "https://github.com/fergusq/fst-python"
},
"split_keywords": [
"finnish",
"nlp",
"morphology"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "f94c8b3568c923fefefc1fa03b5580af6274af3b6fe6f1e0109ecb456990ff79",
"md5": "24a322f4a2d717bf47df818df99728e8",
"sha256": "5c444d7d7acaf49e404f6ede302623d26f9e81c9bdffcf0bd7d146cf39fe8028"
},
"downloads": -1,
"filename": "pypykko-0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "24a322f4a2d717bf47df818df99728e8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 8062563,
"upload_time": "2025-07-23T13:39:27",
"upload_time_iso_8601": "2025-07-23T13:39:27.493777Z",
"url": "https://files.pythonhosted.org/packages/f9/4c/8b3568c923fefefc1fa03b5580af6274af3b6fe6f1e0109ecb456990ff79/pypykko-0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "0d5c2e9e1baf68311ff58be19fb499bb5fc951db6c1c3ba2656ab288c70db01d",
"md5": "5b60ba7ff4d9aafac65f37d5ad376c22",
"sha256": "6ef23ea0938e48142cc48fa28cf6c099a4f72680bec7931be18663b5827a599c"
},
"downloads": -1,
"filename": "pypykko-0.1.tar.gz",
"has_sig": false,
"md5_digest": "5b60ba7ff4d9aafac65f37d5ad376c22",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 8055946,
"upload_time": "2025-07-23T13:39:34",
"upload_time_iso_8601": "2025-07-23T13:39:34.291117Z",
"url": "https://files.pythonhosted.org/packages/0d/5c/2e9e1baf68311ff58be19fb499bb5fc951db6c1c3ba2656ab288c70db01d/pypykko-0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-23 13:39:34",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "fergusq",
"github_project": "fst-python",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pypykko"
}