class documentation

class Alignment(frozenset): (source)

Constructor: Alignment(pairs)

View In Hierarchy

A storage class for representing alignment between two sequences, s1, s2. In general, an alignment is a set of tuples of the form (i, j, ...) representing an alignment between the i-th element of s1 and the j-th element of s2. Tuples are extensible (they might contain additional data, such as a boolean to indicate sure vs possible alignments).

>>> from nltk.translate import Alignment
>>> a = Alignment([(0, 0), (0, 1), (1, 2), (2, 2)])
>>> a.invert()
Alignment([(0, 0), (1, 0), (2, 1), (2, 2)])
>>> print(a.invert())
0-0 1-0 2-1 2-2
>>> a[0]
[(0, 1), (0, 0)]
>>> a.invert()[2]
[(2, 1), (2, 2)]
>>> b = Alignment([(0, 0), (0, 1)])
>>> b.issubset(a)
True
>>> c = Alignment.fromstring('0-0 0-1')
>>> b == c
True
Class Method fromstring Read a giza-formatted string and return an Alignment object.
Method __getitem__ Look up the alignments that map from a given index or slice.
Method __new__ Undocumented
Method __repr__ Produce a Giza-formatted string representing the alignment.
Method __str__ Produce a Giza-formatted string representing the alignment.
Method invert Return an Alignment object, being the inverted mapping.
Method range Work out the range of the mapping from the given positions. If no positions are specified, compute the range of the entire mapping.
Method _build_index Build a list self._index such that self._index[i] is a list of the alignments originating from word i.
Instance Variable _index Undocumented
Instance Variable _len Undocumented
@classmethod
def fromstring(cls, s): (source)

Read a giza-formatted string and return an Alignment object.

>>> Alignment.fromstring('0-0 2-1 9-2 21-3 10-4 7-5')
Alignment([(0, 0), (2, 1), (7, 5), (9, 2), (10, 4), (21, 3)])
Parameters
s:strthe positional alignments in giza format
Returns
AlignmentAn Alignment object corresponding to the string representation s.
def __getitem__(self, key): (source)

Look up the alignments that map from a given index or slice.

def __new__(cls, pairs): (source)

Undocumented

def __repr__(self): (source)

Produce a Giza-formatted string representing the alignment.

def __str__(self): (source)

Produce a Giza-formatted string representing the alignment.

def invert(self): (source)

Return an Alignment object, being the inverted mapping.

def range(self, positions=None): (source)

Work out the range of the mapping from the given positions. If no positions are specified, compute the range of the entire mapping.

def _build_index(self): (source)

Build a list self._index such that self._index[i] is a list of the alignments originating from word i.

Undocumented

Undocumented