Skip to main content

pyigt: Handling interlinear glossed text with Python

Build Status codecov PyPI

This library provides easy access to Interlinear Glossed Text (IGT) according to the Leipzig Glossing Rules, stored as CLDF examples.

Installation

Installing pyigt via pip

pip install pyigt

will install the Python package along with a command line interface igt.

Usage

CLI

$ igt -h
usage: igt [-h] [--log-level LOG_LEVEL] COMMAND ...

optional arguments:
  -h, --help            show this help message and exit
  --log-level LOG_LEVEL
                        log level [ERROR|WARN|INFO|DEBUG] (default: 20)

available commands:
  Run "COMAMND -h" to get help for a specific command.

  COMMAND
    ls                  List IGTs in a CLDF dataset
    stats               Describe the IGTs in a CLDF dataset

The igt ls command allows inspecting IGTs from the commandline, formatted using the four standard lines described in the Leipzig Glossing Rules, where analyzed text and glosses are aligned, e.g.

$ igt ls tests/fixtures/examples.csv 
Example 1:
zəple: ȵike: peji qeʴlotʂuʁɑ,
zəp-le:       ȵi-ke:       pe-ji       qeʴlotʂu-ʁɑ,
earth-DEF:CL  WH-INDEF:CL  become-CSM  in.the.past-LOC

...

Example 5:
zuɑməɸu oʐgutɑ ipiχuɑȵi,
zuɑmə-ɸu      o-ʐgu-tɑ    i-pi-χuɑ-ȵi,
cypress-tree  one-CL-LOC  DIR-hide-because-ADV

IGT corpus at tests/fixtures/examples.csv

igt ls can be chained with other commandline tools such as commands from the csvkit package for filtering:

$ csvgrep -c Primary_Text -m"ȵi"  tests/fixtures/examples.csv | csvgrep -c Gloss -m"ADV" |  igt ls -
Example 5:
zuɑməɸu oʐgutɑ ipiχuɑȵi,
zuɑmə-ɸu      o-ʐgu-tɑ    i-pi-χuɑ-ȵi,
cypress-tree  one-CL-LOC  DIR-hide-because-ADV

Python API

You can read all IGT examples provided with an CLDF dataset

>>> from pyigt import Corpus
>>> corpus = Corpus.from_path('tests/fixtures/cldf-metadata.json')
>>> len(corpus)
>>> len(corpus)
5
>>> for igt in corpus:
...     print(igt)
...     break
... 
zəple: ȵike: peji qeʴlotʂuʁɑ,
zəp-le:       ȵi-ke:       pe-ji       qeʴlotʂu-ʁɑ,
earth-DEF:CL  WH-INDEF:CL  become-CSM  in.the.past-LOC

or instantiate individual IGT examples, e.g. to check for validity:

>>> from pyigt import IGT
>>> ex = IGT(phrase="palasi=lu", gloss="priest-and")
>>> ex.check(strict=True, verbose=True)
palasi=lu
priest-and
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/robert_forkel/projects/cldf/pyigt/src/pyigt/igt.py", line 287, in check
    raise ValueError(
ValueError: Rule 2 or 10 violated: Mismatch of element separators in word and gloss! 

or to expand known gloss abbreviations:

>>> ex = IGT(phrase="Gila abur-u-n ferma hamišaluǧ güǧüna amuq’-da-č.",
...          gloss="now they-OBL-GEN farm forever behind stay-FUT-NEG", 
...          translation="Now their farm will not stay behind forever.")
>>> ex.pprint()
Gila aburun ferma hamišaluǧ güǧüna amuq’dač.
Gila    abur-u-n      ferma    hamišaluǧ    güǧüna    amuq’-da-č.
now     they-OBL-GEN  farm     forever      behind    stay-FUT-NEG
‘Now their farm will not stay behind forever.’
  OBL = oblique
  GEN = genitive
  FUT = future
  NEG = negation, negative

Morpheme parsing

And you can go deeper, parsing morphemes and glosses according to the LGR (see module pyigt.lgrmorphemes):

>> > igt = IGT(phrase="zəp-le: ȵi-ke: pe-ji qeʴlotʂu-ʁɑ,", gloss="earth-DEF:CL WH-INDEF:CL become-CSM in.the.past-LOC")
>> > igt.glossed_words[1].gloss_morphemes
[ < Morpheme
"WH" >, < Morpheme
"INDEF:CL" >]
>> > igt.glossed_words[1].gloss_morphemes[1].elements
[ < GlossElement
"INDEF" >, < GlossElementAfterColon
"CL" >]

See also

  • interlineaR - an R package with similar functionality, but support for more input formats.

Metadata

Release files for pyigt 1.2.0

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

Source distribution (sdist)

Source distribution for pyigt 1.2.0
File Size Uploaded
pyigt-1.2.0.tar.gz 30.6 kB Details

Built distribution (wheel)

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

Total release size: 60.4 kB

Release files / pyigt-1.2.0.tar.gz

Download URL pyigt-1.2.0.tar.gz
Size 30.6 kB
Tags Source
SHA-256 checksum
How to use checksums
bd59edf8247e2d1808da4003481e802c4cbb63aaaac333d306af19b4fa514e78
BLAKE2b-256 checksum
How to use checksums
b54e5bec1a7bcc080a534b862a7e5949b8b86614ebf4f7bf971882e7d935aa68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/28.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.6 tqdm/4.56.2 importlib-metadata/4.10.1 keyring/22.0.1 rfc3986/1.5.0 colorama/0.4.3 CPython/3.8.10

Release files / pyigt-1.2.0-py2.py3-none-any.whl

Download URL pyigt-1.2.0-py2.py3-none-any.whl
Size 29.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
acf5893f122bb8c78ddb29a0b644981bbc37dbd940160d4ac63b0888a823454c
BLAKE2b-256 checksum
How to use checksums
872f6cf21756d1158c39e1df25f68ec20df04bd066dc5e8629ac0b447645c747
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/28.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.6 tqdm/4.56.2 importlib-metadata/4.10.1 keyring/22.0.1 rfc3986/1.5.0 colorama/0.4.3 CPython/3.8.10

Release history Release notifications | RSS feed

2.3.0

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.0

2 release files

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

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