Skip to main content

Feature set algebra for linguistics

Project description

Latest PyPI Version License Supported Python Versions Format Readthedocs

Travis Codecov

Features is a simple implementation of feature set algebra in Python.

Linguistic analyses commonly use sets of binary or privative features to refer to different groups of linguistic objects: for example a group of phonemes that share some phonological features like [-consonantal, +high] or a set of morphemes that occur in context of a specific person/number combination like [-participant, GROUP]. Usually, the features are applied in a way such that only some of their combinations are valid, while others are impossible (i.e. refer to no object) – for example [+high, +low], or [-participant, +speaker].

With this package, such feature systems can be defined with a simple contingency table definition (feature matrix) and stored under a section name in a simple clear-text configuration file. Each feature system can then be loaded by its name and provides its own FeatureSet subclass that implements all comparisons and operations between its feature sets according to the given definition (compatibility, entailment, intersection, unification, etc.).

Features creates the complete lattice structure between the possible feature sets of each feature system and lets you navigate and visualize their relations using the Graphviz graph layout software.

Installation

This package runs under Python 2.7 and 3.4+, use pip to install:

$ pip install features

This will also install the concepts package from PyPI providing the Formal Concept Analysis (FCA) algorithms on which this package is based.

Quickstart

Load a predefined feature system by name (in this case features for a six-way person/number distinction, cf. the definitions in the bundled config.ini in the source repository).

>>> import features

>>> fs = features.FeatureSystem('plural')

>>> print(fs.context)  # doctest: +ELLIPSIS
<Context object mapping 6 objects to 10 properties at 0x...>
      |+1|-1|+2|-2|+3|-3|+sg|+pl|-sg|-pl|
    1s|X |  |  |X |  |X |X  |   |   |X  |
    1p|X |  |  |X |  |X |   |X  |X  |   |
    2s|  |X |X |  |  |X |X  |   |   |X  |
    2p|  |X |X |  |  |X |   |X  |X  |   |
    3s|  |X |  |X |X |  |X  |   |   |X  |
    3p|  |X |  |X |X |  |   |X  |X  |   |

Create feature sets from strings or string sequences. Use feature string parsing, get back string sequences and feature or extent strings in their canonical order (definition order):

>>> fs('+1 +sg'), fs(['+2', '+2', '+sg']), fs(['+sg', '+3'])
(FeatureSet('+1 +sg'), FeatureSet('+2 +sg'), FeatureSet('+3 +sg'))

>>> fs('SG1').concept.intent
('+1', '-2', '-3', '+sg', '-pl')

>>> fs('1').string, fs('1').string_maximal, fs('1').string_extent
('+1', '+1 -2 -3', '1s 1p')

Use feature algebra: intersection (join) , union/unification (meet), set inclusion (extension/subsumption). Do feature set comparisons (logical connectives).

>>> fs('+1 +sg') % fs('+2 +sg')
FeatureSet('-3 +sg')

>>> fs('-3') ^ fs('+1') ^ fs('-pl')
FeatureSet('+1 +sg')

>>> fs('+3') > fs('-1') and fs('+pl') < fs('+2 -sg')
True

>>> fs('+1').incompatible_with(fs('+3')) and fs('+sg').complement_of(fs('+pl'))
True

Navigate the created subsumption lattice (Hasse graph) of all valid feature sets:

>>> fs('+1').upper_neighbors, fs('+1').lower_neighbors
([FeatureSet('-3'), FeatureSet('-2')], [FeatureSet('+1 +sg'), FeatureSet('+1 +pl')])

>>> fs('+1').upset()
[FeatureSet('+1'), FeatureSet('-3'), FeatureSet('-2'), FeatureSet('')]

>>> for f in fs:  # doctest: +ELLIPSIS
...     print('[%s] <-> {%s}' % (f.string_maximal, f.string_extent))
[+1 -1 +2 -2 +3 -3 +sg +pl -sg -pl] <-> {}
[+1 -2 -3 +sg -pl] <-> {1s}
...
[-1] <-> {2s 2p 3s 3p}
[] <-> {1s 1p 2s 2p 3s 3p}

See the docs on how to define, load, and use your own feature systems.

Further reading

See also

  • concepts – Formal Concept Analysis with Python

  • fileconfig – Config file sections as objects

  • graphviz – Simple Python interface for Graphviz

License

Features is distributed under the MIT license.

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

features-0.5.10.zip (125.3 kB view details)

Uploaded Source

Built Distribution

features-0.5.10-py2.py3-none-any.whl (15.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file features-0.5.10.zip.

File metadata

  • Download URL: features-0.5.10.zip
  • Upload date:
  • Size: 125.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for features-0.5.10.zip
Algorithm Hash digest
SHA256 1919fbaa080213316c8f8e1ed8d3c0fd365a5f625e6376a95330e5771324732b
MD5 e74c52b521827aedf2b91848d40c1c19
BLAKE2b-256 afc2d047aa7b459f8054a66aebe27723772968ca7fe28ae46e853f6181149486

See more details on using hashes here.

File details

Details for the file features-0.5.10-py2.py3-none-any.whl.

File metadata

  • Download URL: features-0.5.10-py2.py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for features-0.5.10-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9b6d1a380de2be088de6be4759017f53da097aeb66abc766850904382a848ccb
MD5 966eddecff959f48651ceddf2ee3a2bb
BLAKE2b-256 fa8116b4fed373bdc76d5c0429bb82fa3c25ee08dade8da7ae588c2770adb5c4

See more details on using hashes here.

Supported by

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