class documentation
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 |
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 |
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:str | the positional alignments in giza format |
Returns | |
Alignment | An Alignment object corresponding to the string representation s. |
Work out the range of the mapping from the given positions. If no positions are specified, compute the range of the entire mapping.