nltk.Alignment
¶
-
class
nltk.
Alignment
[source]¶ 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
Methods¶
copy |
Return a shallow copy of a set. |
difference |
Return the difference of two or more sets as a new set. |
fromstring (s) |
Read a giza-formatted string and return an Alignment object. |
intersection |
Return the intersection of two or more sets as a new set. |
invert () |
Return an Alignment object, being the inverted mapping. |
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. |
range ([positions]) |
Work out the range of the mapping from the given positions. |
symmetric_difference |
Return the symmetric difference of two sets as a new set. |
unicode_repr () |
Produce a Giza-formatted string representing the alignment. |
union |
Return the union of sets as a new set. |