nltk.metrics.aline module

ALINE Copyright 2002 by Grzegorz Kondrak.

ALINE is an algorithm for aligning phonetic sequences, described in [1]. This module is a port of Kondrak’s (2002) ALINE. It provides functions for phonetic sequence alignment and similarity analysis. These are useful in historical linguistics, sociolinguistics and synchronic phonology.

ALINE has parameters that can be tuned for desired output. These parameters are: - C_skip, C_sub, C_exp, C_vwl - Salience weights - Segmental features

In this implementation, some parameters have been changed from their default values as described in [1], in order to replicate published results. All changes are noted in comments.

Example usage

# Get optimal alignment of two phonetic sequences

>>> align('θin', 'tenwis') 
[[('θ', 't'), ('i', 'e'), ('n', 'n'), ('-', 'w'), ('-', 'i'), ('-', 's')]]

[1] G. Kondrak. Algorithms for Language Reconstruction. PhD dissertation, University of Toronto.

nltk.metrics.aline.R(p, q)[source]

Return relevant features for segment comparison.

(Kondrak 2002: 54)


Return vowel weight if P is vowel.

(Kondrak 2002: 54)

nltk.metrics.aline.align(str1, str2, epsilon=0)[source]

Compute the alignment of two phonetic strings.

  • str1 (str) – First string to be aligned

  • str2 (str) – Second string to be aligned

  • epsilon (float (0.0 to 1.0)) – Adjusts threshold similarity score for near-optimal alignments

Return type

list(list(tuple(str, str)))


Alignment(s) of str1 and str2

(Kondrak 2002: 51), q)[source]

Return weighted sum of difference between P and Q.

(Kondrak 2002: 54)


A demonstration of the result of aligning phonetic sequences used in Kondrak’s (2002) dissertation.

nltk.metrics.aline.diff(p, q, f)[source]

Returns difference between phonetic segments P and Q for feature F.

(Kondrak 2002: 52, 54)

nltk.metrics.aline.sigma_exp(p, q)[source]

Returns score of an expansion/compression.

(Kondrak 2002: 54)


Returns score of an indel of P.

(Kondrak 2002: 54)

nltk.metrics.aline.sigma_sub(p, q)[source]

Returns score of a substitution of P with Q.

(Kondrak 2002: 54)