lingpy package

Subpackages

Submodules

lingpy.cache module

Implements the lingpy cache.

Some operations in lingpy may be time consuming, so we provide a mechanism to cache the results of these operations.

lingpy.cache.dump(data, filename)
lingpy.cache.load(filename)
lingpy.cache.path(filename)

lingpy.cli module

class lingpy.cli.Command

Bases: object

Base class for subcommands of the lingpy command line interface.

help = None
output(args, content)
classmethod subparser(parser)

Hook to define subcommand arguments.

class lingpy.cli.CommandMeta(name, bases, dct)

Bases: type

A metaclass which keeps track of subclasses, if they have all-lowercase names.

lingpy.cli.add_align_method_option(p)
lingpy.cli.add_cognate_identifier_option(p, default)
lingpy.cli.add_format_option(p, default, choices)
lingpy.cli.add_method_option(p, default, choices, spec='')
lingpy.cli.add_mode_option(p, choices)
lingpy.cli.add_option(parser, name_, default_, help_, short_opt=None, **kw)
lingpy.cli.add_shared_args(p)
lingpy.cli.add_strings_option(p, n)
lingpy.cli.add_tree_calc_option(p)
class lingpy.cli.alignments

Bases: lingpy.cli.Command

Carry out alignment analysis of a wordlist file with readily detected cognates.

classmethod subparser(p)
lingpy.cli.get_parser()
class lingpy.cli.help

Bases: lingpy.cli.Command

Show help for commands.

classmethod subparser(parser)
class lingpy.cli.lexstat

Bases: lingpy.cli.Command

classmethod subparser(p)
lingpy.cli.main(*args)

LingPy command line interface.

class lingpy.cli.multiple

Bases: lingpy.cli.Command

Multiple alignment console interface for LingPy.

classmethod subparser(p)
class lingpy.cli.pairwise

Bases: lingpy.cli.Command

Run pairwise analyses from command line in LingPy

Notes

Currently, the following options are supported:

  • run normal analyses without sound class strings
  • run sound-class based analyses

Furthermore, input output is handled as follows:

  • define user input using psa-formats in lingpy
  • define user output (stdout, file)
classmethod subparser(p)
class lingpy.cli.settings

Bases: lingpy.cli.Command

classmethod subparser(p)
class lingpy.cli.wordlist

Bases: lingpy.cli.Command

Load a wordlist and carry out simple checks.

classmethod subparser(p)

lingpy.compat module

Functionality to provide compatibility across supported python versions

lingpy.config module

Configuration management for lingpy.

Various aspects of lingpy can be configured and customized by the user. This is done with configuration files in the user’s config dir.

class lingpy.config.Config(name, default=None, **kw)

Bases: configparser.RawConfigParser

lingpy.log module

Logging utilities

class lingpy.log.CustomFilter(name='')

Bases: logging.Filter

filter(record)
lingpy.log.debug(msg, **kw)
lingpy.log.deprecated(old, new)
lingpy.log.error(msg, **kw)
lingpy.log.file_written(fname, logger=None)
lingpy.log.get_level()
lingpy.log.get_logger(config_dir=None, force_default_config=False, test=False)

Get a logger configured according to the lingpy log config file.

Note: If no logging configuration file exists, it will be created.

Parameters:
  • config_dir – Directory in which to look for/create the log config file.
  • force_default_config – Configure the logger using the default config.
  • test – Force reconfiguration of the logger.
Returns:

A logger.

lingpy.log.info(msg, **kw)
lingpy.log.missing_module(name, logger=None)
lingpy.log.warn(msg)

lingpy.settings module

Module handels all global parameters used in a LingPy session.

lingpy.settings.rc(rval=None, **keywords)

Function changes parameters globally set for LingPy sessions.

Parameters:

rval : string (default=None)

Use this keyword to specify a return-value for the rc-function.

schema : {“ipa”, “asjp”}

Change the basic schema for sequence comparison. When switching to “asjp”, this means that sequences will be treated as sequences in ASJP code, otherwise, they will be treated as sequences written in basic IPA.

Notes

This function is the standard way to communicate with the rcParams dictionary which is not imported as a default. If you want to see which parameters there are, you can load the rcParams dictonary directly:

>>> from lingpy.settings import rcParams

However, be careful when changing the values. They might produce some unexpected behavior.

Examples

Import LingPy:

>>> from lingpy import *

Switch from IPA transcriptions to ASJP transcriptions:

>>> rc(schema="asjp")

You can check which “basic orthography” is currently loaded:

>>> rc(basic_orthography)
'asjp'
>>> rc(schema='ipa')
>>> rc(basic_orthography)
'fuzzy'

lingpy.util module

class lingpy.util.ProgressBar(title, task_count, cols=100)

Bases: object

A progress bar using console output.

Notes

Usage example:

>>> with ProgressBar('here is the title', 50) as pb:
>>>     for i in range(50):
>>>         # do stuff
>>>         pb.update()
update()
class lingpy.util.TemporaryPath(suffix='')

Bases: object

class lingpy.util.TextFile(path, log=True)

Bases: object

lingpy.util.as_string(obj, pprint=False)
class lingpy.util.cached_property

Bases: object

Decorator for read-only properties evaluated only once.

Notes

It can be used to create a cached property like this:

import random

# the class containing the property must be a new-style class
class MyClass(object):
    # create property whose value is cached
    @cached_property()
    def randint(self):
        # will only be evaluated once.
        return random.randint(0, 100)

The value is cached in the ‘_cache’ attribute of the object instance that has the property getter method wrapped by this decorator. The ‘_cache’ attribute value is a dictionary which has a key for every property of the object which is wrapped by this decorator. Each entry in the cache is created only when the property is accessed for the first time and is the last computed property value.

To expire a cached property value manually just do:

del instance._cache[<property name>]

Inspired by the recipe by Christopher Arndt in the PythonDecoratorLibrary

lingpy.util.charstring(id_, char='X', cls='-')
lingpy.util.combinations2(iterable)

Convenience shortcut

lingpy.util.confirm(question, default=False)

Ask user a yes/no question and return their response as True or False.

Parameters:

question : str

The question you want to answer.

Notes

question should be a simple, grammatically complete question such as “Do you wish to continue?”, and will have a string similar to ” [Y/n] ” appended automatically. This function will not append a question mark for you.

By default, when the user presses Enter without typing anything, or the user is not recognized as “yes” or “no”, “no” is assumed. This can be changed by specifying default=True.

Adapted from fabric.contrib.console.confirm

lingpy.util.identity(x)
lingpy.util.join(sep, *args, **kw)

Convenience shortcut. Strings to be joined do not have to be passed as list or tuple.

Notes

An implicit conversion of objects to strings is performed as well.

lingpy.util.jsondump(obj, path, **kw)

python 2 + 3 compatible version of json.dump.

Parameters:

obj : object

The object to be dumped.

path : { str, Path }

The path of the JSON file to be written.

lingpy.util.jsonload(path, **kw)

python 2 + 3 compatible version of json.load.

Returns:

obj : object

The python object read from path.

lingpy.util.lines_to_text(lines)
lingpy.util.lingpy_path(*comps)
lingpy.util.multicombinations2(iterable)

Convenience shortcut, for the name, see the Wikipedia article on Combination.

https://en.wikipedia.org/wiki/Combination#Number_of_combinations_with_repetition

lingpy.util.read_config_file(path, **kw)

Read lines of a file ignoring commented lines and empty lines.

lingpy.util.read_csv_file(path, delimiter=', ', quotechar='"', normalize=None)

Load a normal CSV file.

Parameters:

path : str

The path to your CSV file.

delimiter : str

The delimiter in the CSV file.

quotechar : str

The quote character in your data.

normalize : { None, “NFC”, “NFC” }

If not None a valid unicode normalization mode must be passed.

lingpy.util.read_text_file(path, normalize=None, lines=False)

Read a text file encoded in utf-8.

Parameters:

path : { Path, str }

File-system path of the file.

normalize : { None, “NFC”, “NFC” }

If not None a valid unicode normalization mode must be passed.

lines : bool (default=False)

Flag signalling whether to return a list of lines (without the line-separation character).

Returns:

file_content : { list, str }

File content as unicode object or list of lines as unicode objects.

Notes

The whole file is read into memory.

lingpy.util.setdefaults(d, **kw)

Shortcut for a common idiom, setting multiple default values at once.

Parameters:

d : dict

Dictionary to be updated.

kw : dict

Dictionary with default values.

lingpy.util.write_text_file(path, content, normalize=None, log=True)

Write a text file encoded in utf-8.

Parameters:

path : str

File-system path of the file.

content : str

The text content to be written.

normalize : { None, “NFC”, “NFD” } (default=False)

If not None a valid unicode normalization mode must be passed.

log : bool (default=True)

Indicate whether you want to log the result of the file writing process.

Module contents

LingPy package for quantitative tasks in historical linguistics.

Documentation is available in the docstrings. Online documentation is available at http://lingpy.org

Subpackages

algorithm — Basic Algorithms for Sequence Comparison align — Specific Algorithms Alignment Analyses basic — Basic Classes for Language Comparison compare — Basic Modules for Language Comparison convert — Functions for Format Conversion data — Data Handling evaluate — Basic Classes and Functions for Algorithm Evaluation read — Basic Functions for Data Input sequence — Basic Functions for Sequence Modeling thirdparty — Temporary Forks of Third-Party-Modules