class documentation

class AlignedSent(object): (source)

Constructor: AlignedSent(words, mots, alignment)

View In Hierarchy

Return an aligned sentence object, which encapsulates two sentences along with an Alignment between them.

Typically used in machine translation to represent a sentence and its translation.

>>> from nltk.translate import AlignedSent, Alignment
>>> algnsent = AlignedSent(['klein', 'ist', 'das', 'Haus'],
...     ['the', 'house', 'is', 'small'], Alignment.fromstring('0-3 1-2 2-0 3-1'))
>>> algnsent.words
['klein', 'ist', 'das', 'Haus']
>>> algnsent.mots
['the', 'house', 'is', 'small']
>>> algnsent.alignment
Alignment([(0, 3), (1, 2), (2, 0), (3, 1)])
>>> from nltk.corpus import comtrans
>>> print(comtrans.aligned_sents()[54])
<AlignedSent: 'Weshalb also sollten...' -> 'So why should EU arm...'>
>>> print(comtrans.aligned_sents()[54].alignment)
0-0 0-1 1-0 2-2 3-4 3-5 4-7 5-8 6-3 7-9 8-9 9-10 9-11 10-12 11-6 12-6 13-13
Parameters
wordsWords in the target language sentence
motsWords in the source language sentence
alignmentWord-level alignments between words and mots. Each alignment is represented as a 2-tuple (words_index, mots_index).
Method __init__ Undocumented
Method __repr__ Return a string representation for this AlignedSent.
Method __str__ Return a human-readable string representation for this AlignedSent.
Method invert Return the aligned sentence pair, reversing the directionality
Instance Variable alignment Undocumented
Property mots Undocumented
Property words Undocumented
Method _get_alignment Undocumented
Method _repr_svg_ Ipython magic : show SVG representation of this AlignedSent.
Method _set_alignment Undocumented
Method _to_dot Dot representation of the aligned sentence
Instance Variable _alignment Undocumented
Instance Variable _mots Undocumented
Instance Variable _words Undocumented
def __init__(self, words, mots, alignment=None): (source)

Undocumented

def __repr__(self): (source)

Return a string representation for this AlignedSent.

Returns
strUndocumented
def __str__(self): (source)

Return a human-readable string representation for this AlignedSent.

Returns
strUndocumented
def invert(self): (source)

Return the aligned sentence pair, reversing the directionality

Returns
AlignedSentUndocumented
alignment: Alignment = (source)

Undocumented

@property
mots = (source)

Undocumented

@property
words = (source)

Undocumented

def _get_alignment(self): (source)

Undocumented

def _repr_svg_(self): (source)

Ipython magic : show SVG representation of this AlignedSent.

def _set_alignment(self, alignment): (source)

Undocumented

def _to_dot(self): (source)

Dot representation of the aligned sentence

_alignment = (source)

Undocumented

Undocumented

Undocumented