nltk.translate.Alignment¶
- class nltk.translate.Alignment[source]¶
Bases:
frozenset
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
- classmethod fromstring(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 (str) – the positional alignments in giza format
- Return type
- Returns
An Alignment object corresponding to the string representation
s
.
- range(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.
- copy()¶
Return a shallow copy of a set.
- difference()¶
Return the difference of two or more sets as a new set.
(i.e. all elements that are in this set but not the others.)
- intersection()¶
Return the intersection of two sets as a new set.
(i.e. all elements that are in both sets.)
- isdisjoint()¶
Return True if two sets have a null intersection.
- issubset()¶
Report whether another set contains this set.
- issuperset()¶
Report whether this set contains another set.
- symmetric_difference()¶
Return the symmetric difference of two sets as a new set.
(i.e. all elements that are in exactly one of the sets.)
- union()¶
Return the union of sets as a new set.
(i.e. all elements that are in either set.)