Skip to main content

Library for manipulation of phonological distinctive features

Project description

DistFeat Python library

DistFeat is a Python library for manipulating segmental/distinctive phonological features.

Codacy Badge PyPI Build Status codecov

Installation and usage

The library can be installed as any standard Python library with pip, and used as demonstrated in the following snippet:

In any standard Python environment, distfeat can be installed with:

$ pip install distfeat

Note that the command above will install the pyclts depency, but will not download any version of the CLTS data by default.

Detailed instructions on how to use the library will be made available in the official documentation. Code documentation and test cases detail usage, along with the following section.

Showcase

Functionality is provided by means of a DistFeat class, which will automatically load the standard model upon instantiation:

>>> import distfeat
>>> df = distfeat.DistFeat()

The most common functionality, obtaining a dictionary of features for a grapheme, is performed by the .grapheme2features() method.

>>> df.grapheme2features('a')
{'anterior': True, 'approximant': True, 'back': False, 'click': False, 'consonantal': False, 'constricted': False, 'continuant': True, 'coronal': True, 'distributed': True, 'dorsal': True, 'high': False, 'labial': False, 'laryngeal': True, 'lateral': False, 'long': None, 'low': True, 'nasal': False, 'pharyngeal': None, 'place': True, 'preaspirated': None, 'preglottalized': None, 'prenasal': None, 'round': None, 'sibilant': False, 'sonorant': True, 'spread': False, 'strident': False, 'syllabic': True, 'tense': True, 'voice': True}

The .graphemes2features() method will by default returning a dictionary with boolean values, with sorted feature names. Arguments allow to skip the truth value conversion, returning the strings used for their representation, and to return a vector of values as a list.

>>> df.grapheme2features('a', t_values=False)
{'anterior': '+', 'approximant': '+', 'back': '-', 'click': '-', 'consonantal': '-', 'constricted': '-', 'continuant': '+', 'coronal': '+', 'distributed': '+', 'dorsal': '+', 'high': '-', 'labial': '-', 'laryngeal': '+', 'lateral': '-', 'long': '0', 'low': '+', 'nasal': '-', 'pharyngeal': '0', 'place': '+', 'preaspirated': '0', 'preglottalized': '0', 'prenasal': '0', 'round': '0', 'sibilant': '-', 'sonorant': '+', 'spread': '-', 'strident': '-', 'syllabic': '+', 'tense': '+', 'voice': '+'}

>>> df.grapheme2features('a', vector=True)
[True, True, False, False, False, False, True, True, True, True, False, False, True, False, None, True, False, None, True, None, None, None, None, False, True, False, False, True, True, True]

The operationally inverse method .features2graphemes() returns a list of all graphemes that satisfy a set of features and their values (which can be provided both as truth values or as their strings). It is possible to drop undefined values by means of the drop_na argument.

>>> df.features2graphemes({"consonantal": "-", "anterior": "+", "high": "-"})
['a', 'aː', 'ã', 'ãː', 'ă', 'ḁ', 'a̯', 'e', 'eː', 'ẽ', 'ẽː', 'ĕ', 'e̤', 'e̥', 'e̯', 'æ', 'æː', 'æ̃', 'æ̃ː', 'ø', 'øː', 'ø̃', 'ø̃ː', 'œ', 'œː', 'œ̃', 'œ̃ː', 'ɶ', 'ɶː', 'ɶ̃', 'ɶ̃ː']

A minimal matrix of features needed to distinguish a set of graphemes can be obtained with the .minimal_matrix() method, which also allows to use strings for truth values and to drip undefined values. Like in the case of .grapheme2features(), a vector argument can be passed in order to obtain a list of values. As expected, the larger and more heterogeneous the set of graphemes, the larger the number of features needed. The snippet below also used the auxiliary tabulate_matrix() function, a wrapper to the tabulate library.

>>> distfeat.tabulate_matrix(df.minimal_matrix(["t", "d"]))
    constricted    laryngeal    spread    voice
--  -------------  -----------  --------  -------
d   False          True         False     True
t                  False

>>> distfeat.tabulate_matrix(df.minimal_matrix(["t", "d", "s"]))
    constricted    continuant    laryngeal    sibilant    spread    strident    voice
--  -------------  ------------  -----------  ----------  --------  ----------  -------
d   False          False         True         False       False     False       True
s                  True          False        True                  True
t                  False         False        False                 False

>>> df.minimal_matrix(["t", "d"], vector=True)
{'d': [False, True, False, True], 't': [None, False, None, None]}

The operationally inverse method to the one above is .class_features(), which provides a dictionary of features and values to constitute a class of sounds from a set of graphemes. Note that, while possible, this method does not drop undefined values by default. As expected, the larger and more heterogeneous the set graphemes, the fewer the number of feature/value pairs in common.

>>> df.class_features(["t", "d"])
{'anterior': True, 'approximant': False, 'click': False, 'consonantal': True, 'continuant': False, 'coronal': True, 'distributed': False, 'dorsal': False, 'labial': False, 'lateral': False, 'nasal': False, 'place': True, 'sibilant': False, 'sonorant': False, 'strident': False, 'syllabic': False, 'tense': False}

>>> df.class_features(["t", "d", "s"])
{'anterior': True, 'approximant': False, 'click': False, 'consonantal': True, 'coronal': True, 'distributed': False, 'dorsal': False, 'labial': False, 'lateral': False, 'nasal': False, 'place': True, 'sonorant': False, 'syllabic': False, 'tense': False}

A simple command-line tool for querying the database is also provided.

Changelog

Version 0.1.1:

  • Added unround open-mid front vowels which were missing from the default model
  • Added a model derived from Phoible

Version 0.1:

  • First public release

TODO

  • Allow to specify, check, and derive geometries
  • Decide whether to have .features2graphemes() defaulting to boolean values (i.e., t_values=True)
  • Decide on how to specify undefined when using truth values, such as in .features2graphemes() (considering that None cannot be passed as a value)
  • Extend the command-line tool to call most if not all functions

Community guidelines

While the author can be contacted directly for support, it is recommended that third parties use GitHub standard features, such as issues and pull requests, to contribute, report problems, or seek support.

Contributing guidelines, including a code of conduct, can be found in the CONTRIBUTING.md file.

Author and citation

The library is developed by Tiago Tresoldi (tresoldi@shh.mpg.de).

The author has received funding from the European Research Council (ERC) under the European Union’s Horizon 2020 research and innovation programme (grant agreement No. ERC Grant #715618, Computer-Assisted Language Comparison.

If you use distfeat or the standard feature model distributed with it, please cite it as:

Tresoldi, Tiago (2020). DistFeat, a Python library for manipulating segmental and distinctive features. Version 0.1. Jena. Available at https://github.com/tresoldi/distfeat

In BibTeX:

@misc{Tresoldi2020distfeat,
  author = {Tresoldi, Tiago},
  title = {DistFeat,  a Python library for manipulating segmental and distinctive features. Version 0.1.},
  howpublished = {\url{https://github.com/tresoldi/distfeat}},
  address = {Jena},
  year = {2020},
}

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 distfeat, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size distfeat-0.1.1-py3-none-any.whl (40.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size distfeat-0.1.1.tar.gz (42.4 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