Skip to main content

Lookup Foma FSTs

Project description

FST Lookup

Build Status Python test package codecov PyPI version calver YYYY.MM.DD

Implements lookup for Foma finite state transducers.

Supports Python 3.5 and up.

Install

pip install fst-lookup

Usage

Import the library, and load an FST from a file:

Hint: Test this module by downloading the eat FST!

>>> from fst_lookup import FST
>>> fst = FST.from_file('eat.fomabin')

Assumed format of the FSTs

fst_lookup assumes that the lower label corresponds to the surface form, while the upper label corresponds to the lemma, and linguistic tags and features: e.g., your LEXC will look something like this—note what is on each side of the colon (:):

Multichar_Symbols +N +Sg +Pl
Lexicon Root
    cow+N+Sg:cow #;
    cow+N+Pl:cows #;
    goose+N+Sg:goose #;
    goose+N+Pl:geese #;
    sheep+N+Sg:sheep #;
    sheep+N+Pl:sheep #;

If your FST has labels on the opposite sides—e.g., the upper label corresponds to the surface form and the upper label corresponds to the lemma and linguistic tags—then instantiate the FST by providing the labels="invert" keyword argument:

fst = FST.from_file('eat-inverted.fomabin', labels="invert")

Hint: FSTs originating from the HFST suite are often inverted, so try to loading the FST inverted first if .generate() or .analyze() aren't working correctly!

Analyze a word form

To analyze a form (take a word form, and get its linguistic analyzes) call the analyze() function:

def analyze(self, surface_form: str) -> Iterator[Analysis]

This will yield all possible linguistic analyses produced by the FST.

An analysis is a tuple of strings. The strings are either linguistic tags, or the lemma (base form of the word).

FST.analyze() is a generator, so you must call list() to get a list.

>>> list(sorted(fst.analyze('eats')))
[('eat', '+N', '+Mass'),
 ('eat', '+V', '+3P', '+Sg')]

Generate a word form

To generate a form (take a linguistic analysis, and get its concrete word forms), call the generate() function:

def generate(self, analysis: str) -> Iterator[str]

FST.generate() is a Python generator, so you must call list() to get a list.

>>> list(fst.generate('eat+V+Past')))
['ate']

Contributing

If you plan to contribute code, it is recommended you use Poetry. Fork and clone this repository, then install development dependencies by typing:

poetry install

Then, do all your development within a virtual environment, managed by Poetry:

poetry shell

Type-checking

This project uses mypy to check static types. To invoke it on this package, type the following:

mypy -p fst_lookup

Running tests

To run this project's tests, we use py.test:

poetry run pytest

C Extension

Building the C extension is handled in build.py

To disable building the C extension, add the following line to .env:

export FST_LOOKUP_BUILD_EXT=False

(by default, this is True).

To enable debugging flags while working on the C extension, add the following line to .env:

export FST_LOOKUP_DEBUG=TRUE

(by default, this is False).

Fixtures

If you are creating or modifying existing test fixtures (i.e., mostly pre-built FSTs used for testing), you will need the following dependencies:

Fixtures are stored in tests/data/. Here, you will use make to compile all pre-built FSTs from source:

make

License

FST Copyright © 2019–2020 Eddie Antonio Santos. Released under the terms of the Apache license. See LICENSE for more info.

Project details


Download files

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

Files for fst-lookup, version 2020.5.24.post8
Filename, size File type Python version Upload date Hashes
Filename, size fst_lookup-2020.5.24.post8-cp36-cp36m-macosx_10_14_x86_64.whl (28.4 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size fst_lookup-2020.5.24.post8-cp36-cp36m-manylinux1_x86_64.whl (46.2 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size fst_lookup-2020.5.24.post8-cp36-cp36m-manylinux2010_x86_64.whl (46.3 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size fst_lookup-2020.5.24.post8-cp37-cp37m-macosx_10_14_x86_64.whl (28.4 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size fst_lookup-2020.5.24.post8-cp37-cp37m-manylinux1_x86_64.whl (47.2 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size fst_lookup-2020.5.24.post8-cp37-cp37m-manylinux2010_x86_64.whl (47.2 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size fst_lookup-2020.5.24.post8-cp38-cp38-macosx_10_14_x86_64.whl (28.5 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size fst_lookup-2020.5.24.post8-cp38-cp38-manylinux1_x86_64.whl (47.6 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size fst_lookup-2020.5.24.post8-cp38-cp38-manylinux2010_x86_64.whl (47.6 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size fst-lookup-2020.5.24.post8.tar.gz (21.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page