Skip to main content

A natural language parser for Icelandic

Project description

License: MIT Python 3.9 Release PyPI Build

Greynir

GreynirEngine

A fast, efficient natural language processing engine for Icelandic

Overview

Greynir is a Python 3 (>=3.9) package, published by Miðeind ehf., for working with Icelandic natural language text. Greynir can parse text into sentence trees, find lemmas, inflect noun phrases, assign part-of-speech tags and much more.

Greynir's sentence trees can inter alia be used to extract information from text, for instance about people, titles, entities, facts, actions and opinions.

Full documentation for Greynir is available here.

Greynir is the engine of Greynir.is, a natural-language front end for a database of over 10 million sentences parsed from Icelandic news articles, and Embla, a voice-driven virtual assistant app for smart devices such as iOS and Android phones.

Greynir includes a hand-written context-free grammar for the Icelandic language, consisting of over 7,000 lines of grammatical productions in extended Backus-Naur format. Its fast C++ parser core is able to cope with long and ambiguous sentences, using an Earley-type parser as enhanced by Scott and Johnstone.

Greynir employs the Tokenizer package, by the same authors, to tokenize text, and uses BinPackage as its database of Icelandic vocabulary and morphology.

Examples

Use Greynir to easily inflect noun phrases

from reynir import NounPhrase as Nl

# Create a NounPhrase ('nafnliður') object
karfa = Nl("þrír lúxus-miðar á Star Wars og tveir brimsaltir pokar af poppi")

# Print the NounPhrase in the correct case for each context
# (þf=þolfall/accusative, þgf=þágufall/dative). Note that
# the NounPhrase class implements __format__(), allowing you
# to use the case as a format specification, for instance in f-strings.

print(f"Þú keyptir {karfa:þf}.")
print(f"Hér er kvittunin þín fyrir {karfa:þgf}.")

The program outputs the following text, correctly inflected:

Þú keyptir þrjá lúxus-miða á Star Wars og tvo brimsalta poka af poppi.
Hér er kvittunin þín fyrir þremur lúxus-miðum á Star Wars og tveimur brimsöltum pokum af poppi.

Use Greynir to parse a sentence

>>> from reynir import Greynir
>>> g = Greynir()
>>> sent = g.parse_single("Ása sá sól.")
>>> print(sent.tree.view)
P                               # Root
+-S-MAIN                        # Main sentence
    +-IP                          # Inflected phrase
    +-NP-SUBJ                   # Noun phrase, subject
        +-no_et_nf_kvk: 'Ása'     # Noun, singular, nominative, feminine
    +-VP                        # Verb phrase containing arguments
        +-VP                      # Verb phrase containing verb
        +-so_1_þf_et_p3: 'sá'   # Verb, 1 accusative arg, singular, 3rd p
        +-NP-OBJ                  # Noun phrase, object
        +-no_et_þf_kvk: 'sól'   # Noun, singular, accusative, feminine
+-'.'                           # Punctuation
>>> sent.tree.nouns
['Ása', 'sól']
>>> sent.tree.verbs
['sjá']
>>> sent.tree.flat
'P S-MAIN IP NP-SUBJ no_et_nf_kvk /NP-SUBJ VP so_1_þf_et_p3
    NP-OBJ no_et_þf_kvk /NP-OBJ /VP /IP /S-MAIN p /P'
>>> # The subject noun phrase (S.IP.NP also works)
>>> sent.tree.S.IP.NP_SUBJ.lemmas
['Ása']
>>> # The verb phrase
>>> sent.tree.S.IP.VP.lemmas
['sjá', 'sól']
>>> # The object within the verb phrase (S.IP.VP.NP also works)
>>> sent.tree.S.IP.VP.NP_OBJ.lemmas
['sól']

Extracting lemmas and POS tags for web display

Greynir preserves the original text of each token, including surrounding whitespace. This allows you to reconstruct the exact original input while annotating it with linguistic information such as lemmas and part-of-speech (POS) tags.

from reynir import Greynir

g = Greynir()
sent = g.parse_single("Ása   sá   sól.")

# Build a map from token index to terminal node
terminal_map = {node.index: node for node in sent.terminal_nodes}

html_parts = []
for i, tok in enumerate(sent.tokens):
    # tok.original preserves the original text with spacing
    original = tok.original or ""
    if i in terminal_map:
        node = terminal_map[i]
        # Wrap with linguistic info (lemma and POS tag)
        html_parts.append(
            f'<span data-lemma="{node.lemma}" data-pos="{node.tcat}">'
            f'{original}</span>'
        )
    else:
        html_parts.append(original)

html = "".join(html_parts)
print(html)

The program outputs the following HTML, with the original spacing preserved and each token annotated with its lemma and POS tag (no=noun, so=verb):

<span data-lemma="Ása" data-pos="no">Ása</span><span data-lemma="sjá" data-pos="so"></span><span data-lemma="sól" data-pos="no">   sól</span><span data-lemma="." data-pos="">.</span>

Prerequisites

This package runs on CPython 3.9 or newer, and on PyPy 3.11 or newer.

To find out which version of Python you have, enter:

python --version

If a binary wheel package isn't available on PyPI for your system, you may need to have the python3-dev package (or its Windows equivalent) installed on your system to set up Greynir successfully. This is because a source distribution install requires a C++ compiler and linker:

# Debian or Ubuntu
sudo apt-get install python3-dev

Depending on your system, you may also need to install libffi-dev:

# Debian or Ubuntu
sudo apt-get install libffi-dev

Installation

To install this package, assuming Python 3 is your default Python:

pip install reynir

If you have git installed and want to be able to edit the source, do like so:

git clone https://github.com/mideind/GreynirEngine
cd GreynirEngine
# [ Activate your virtualenv here if you have one ]
pip install -e .

The package source code is in GreynirEngine/src/reynir.

Tests

To run the built-in tests, install pytest, cd to your GreynirEngine subdirectory (and optionally activate your virtualenv), then run:

python -m pytest

Evaluation

A parsing test pipeline for different parsing schemas, including the Greynir schema, has been developed. It is available here.

Documentation

Please consult Greynir's documentation for detailed installation instructions, a quickstart guide, and reference information, as well as important information about copyright and licensing.

Troubleshooting

If parsing seems to hang, it is possible that a lock file that GreynirEngine uses has been left locked. This can happen if a Python process that uses GreynirEngine is killed abruptly. The solution is to delete the lock file and try again:

On Linux and macOS:

rm /tmp/greynir-grammar  # May require sudo privileges

On Windows:

del %TEMP%\greynir-grammar

Copyright and licensing

Greynir is Copyright © 2016-2025 by Miðeind ehf.. The original author of this software is Vilhjálmur Þorsteinsson.

Miðeind ehf.

This software is licensed under the MIT License:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

If you would like to use this software in ways that are incompatible with the standard MIT license, contact Miðeind ehf. to negotiate custom arrangements.


GreynirEngine indirectly embeds the Database of Icelandic Morphology, (Beygingarlýsing íslensks nútímamáls), abbreviated BÍN. GreynirEngine does not claim any endorsement by the BÍN authors or copyright holders.

The BÍN source data are publicly available under the CC BY-SA 4.0 license, as further detailed here in English and here in Icelandic.

In accordance with the BÍN license terms, credit is hereby given as follows:

Beygingarlýsing íslensks nútímamáls. Stofnun Árna Magnússonar í íslenskum fræðum. Höfundur og ritstjóri Kristín Bjarnadóttir.

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

reynir-3.6.2.tar.gz (424.7 kB view details)

Uploaded Source

Built Distributions

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

reynir-3.6.2-pp311-pypy311_pp73-win_amd64.whl (425.7 kB view details)

Uploaded PyPyWindows x86-64

reynir-3.6.2-pp311-pypy311_pp73-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (429.6 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

reynir-3.6.2-pp311-pypy311_pp73-macosx_11_0_arm64.whl (426.6 kB view details)

Uploaded PyPymacOS 11.0+ ARM64

reynir-3.6.2-pp311-pypy311_pp73-macosx_10_15_x86_64.whl (426.0 kB view details)

Uploaded PyPymacOS 10.15+ x86-64

reynir-3.6.2-cp39-cp39-win_amd64.whl (427.8 kB view details)

Uploaded CPython 3.9Windows x86-64

reynir-3.6.2-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (486.2 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

reynir-3.6.2-cp39-cp39-macosx_11_0_arm64.whl (431.1 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

reynir-3.6.2-cp39-cp39-macosx_10_9_x86_64.whl (430.6 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

File details

Details for the file reynir-3.6.2.tar.gz.

File metadata

  • Download URL: reynir-3.6.2.tar.gz
  • Upload date:
  • Size: 424.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for reynir-3.6.2.tar.gz
Algorithm Hash digest
SHA256 a8730b1db9b521c59e640b6a24393b92f7caa527e02894fdceb42892fe0f9d53
MD5 72aa087fa97ad94e79a20bdac5ab3c68
BLAKE2b-256 f0e8ffac3e583fd1a0ead59e6519f9da0e7fdcd41f6bcbf092d534af850120e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for reynir-3.6.2.tar.gz:

Publisher: wheels.yml on mideind/GreynirEngine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file reynir-3.6.2-pp311-pypy311_pp73-win_amd64.whl.

File metadata

File hashes

Hashes for reynir-3.6.2-pp311-pypy311_pp73-win_amd64.whl
Algorithm Hash digest
SHA256 2a29835823cf584d2fa42dea467b3aa94c8d301e5c6798f45ff2ae6c6bfc29e4
MD5 c583f5faa67da740f50476cb73498ff3
BLAKE2b-256 5bee64f48b83f90c5877031ae8fa8dbd6e926066924329e86c4625b5877fa607

See more details on using hashes here.

Provenance

The following attestation bundles were made for reynir-3.6.2-pp311-pypy311_pp73-win_amd64.whl:

Publisher: wheels.yml on mideind/GreynirEngine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file reynir-3.6.2-pp311-pypy311_pp73-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for reynir-3.6.2-pp311-pypy311_pp73-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1a89d392a742364e6c3c7fe435f658cdb6eec99da557761ed720afd66c1f922a
MD5 c09fe9562e63b2af7da71fdb4f50cba9
BLAKE2b-256 fd855c097db9d0485f0ff14b52913d06aeddb024eee5e1488af5e54e4c69e809

See more details on using hashes here.

Provenance

The following attestation bundles were made for reynir-3.6.2-pp311-pypy311_pp73-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on mideind/GreynirEngine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file reynir-3.6.2-pp311-pypy311_pp73-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for reynir-3.6.2-pp311-pypy311_pp73-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 32f5da1764d820902f63e310a965e7c9ab3bb3b4baf2812beed6ec57dfc645ed
MD5 94064669b3908d126d0175876bbf1bbc
BLAKE2b-256 b29a86028c971e1c45ea0eae21f03fa225547d7226e8965c00b22083175e80c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for reynir-3.6.2-pp311-pypy311_pp73-macosx_11_0_arm64.whl:

Publisher: wheels.yml on mideind/GreynirEngine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file reynir-3.6.2-pp311-pypy311_pp73-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for reynir-3.6.2-pp311-pypy311_pp73-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 46119c467e67bcab079d7bb0ab2a834ece18b56a1e15033380b415587d39fe37
MD5 78c8d3cc6f8c56da5a88edb4feffbf49
BLAKE2b-256 772f865dbeddf387b8f30790efa87b8984c28e96914e8186867fd8b215f2d45f

See more details on using hashes here.

Provenance

The following attestation bundles were made for reynir-3.6.2-pp311-pypy311_pp73-macosx_10_15_x86_64.whl:

Publisher: wheels.yml on mideind/GreynirEngine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file reynir-3.6.2-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: reynir-3.6.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 427.8 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for reynir-3.6.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 ebcbdaa55a552336e49da561a129f009bf08bde41476c4ec0f98ad2226709f5d
MD5 3f9409eec69745f93cb50dd066858688
BLAKE2b-256 1ae1625f19ec76e7de18425127c5d0a6395c4951d1b4c12fe72797167dc05516

See more details on using hashes here.

Provenance

The following attestation bundles were made for reynir-3.6.2-cp39-cp39-win_amd64.whl:

Publisher: wheels.yml on mideind/GreynirEngine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file reynir-3.6.2-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for reynir-3.6.2-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f29c0bfad7dd0cf3657921d4c0bd2d65aedf73829e545bee0b6810e465e835d5
MD5 0695059d1fa3e46c1ef1e9d8110fa80f
BLAKE2b-256 6e0492907348f31c6ecd6ac85e060caa17038499589f4220f7231bddfd3a953f

See more details on using hashes here.

Provenance

The following attestation bundles were made for reynir-3.6.2-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on mideind/GreynirEngine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file reynir-3.6.2-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for reynir-3.6.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 57ec3759e06361f15d0fc66a2d95c4ed27641b23ac340ac945bb595bace851fb
MD5 e4bf4797042ab7ce9b52c9284b7cd80b
BLAKE2b-256 b51494976562c46f32376a65d8225ddf9146d7884963e18810a8e1c86aedcc6e

See more details on using hashes here.

Provenance

The following attestation bundles were made for reynir-3.6.2-cp39-cp39-macosx_11_0_arm64.whl:

Publisher: wheels.yml on mideind/GreynirEngine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file reynir-3.6.2-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for reynir-3.6.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0cd21ee9e1be3a98fb00b40c7827f3f4a74f2ab08cdf96c3cc6fc4a1db06f2cf
MD5 00bb4175fd9f18f8693a1f8418bbd2f0
BLAKE2b-256 5bc7b37bcaa5cdeb2bc71eee5f0376db88aa400323a975fcf22cca71a370d5bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for reynir-3.6.2-cp39-cp39-macosx_10_9_x86_64.whl:

Publisher: wheels.yml on mideind/GreynirEngine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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