nltk.AlignedSent

class nltk.AlignedSent(words, mots, alignment=None)[source]

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

>>> from nltk.translate import AlignedSent, Alignment
>>> algnsent = AlignedSent(['klein', 'ist', 'das', 'Haus'],
...     ['the', 'house', 'is', 'small'], Alignment.fromstring('0-2 1-3 2-1 3-0'))
>>> algnsent.words
['klein', 'ist', 'das', 'Haus']
>>> algnsent.mots
['the', 'house', 'is', 'small']
>>> algnsent.alignment
Alignment([(0, 2), (1, 3), (2, 1), (3, 0)])
>>> 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:
  • words (list(str)) – source language words
  • mots (list(str)) – target language words
  • alignment (Alignment) – the word-level alignments between the source and target language

Methods

__init__(words, mots[, alignment])
invert() Return the aligned sentence pair, reversing the directionality
unicode_repr() Return a string representation for this AlignedSent.

Attributes

alignment
mots
words