Package nltk :: Module align :: Class AlignedSent
[hide private]
[frames] | no frames]

type AlignedSent

source code

object --+
         |
        AlignedSent

Aligned sentence object. Encapsulates two sentences along with an Alignment between them.

Instance Methods [hide private]
 
__init__(self, words=[], mots=[], alignment='', encoding='latin-1')
Initialize a new AlignedSent.
source code
 
alignment(self, alignment) source code
boolean
_check_align(self, a)
Returns: True if passed alignment check
source code
string
__repr__(self)
Returns: A string representation for this AlignedSent.
source code
string
__str__(self)
Returns: A string representation for this AlignedSent.
source code
AlignedSent
invert(self)
Returns: the invert object
source code
float or None
precision(self, reference)
Calculates the precision of an aligned sentence with respect to a "gold standard" reference AlignedSent.
source code
float or None
recall(self, reference)
Calculates the recall of an aligned sentence with respect to a "gold standard" reference AlignedSent.
source code
float or None
alignment_error_rate(self, reference, possible=None)
Calculates the Alignment Error Rate (AER) of an aligned sentence with respect to a "gold standard" reference AlignedSent.
source code
Properties [hide private]
  words
  mots
Method Details [hide private]

__init__(self, words=[], mots=[], alignment='', encoding='latin-1')
(Constructor)

source code 

Initialize a new AlignedSent.

Parameters:
  • words (list of str) - source language words
  • mots (list of str) - target language words
  • alignment (Alignment) - the word-level alignments between the source and target language
Overrides: object.__init__

_check_align(self, a)

source code 
Parameters:
  • a - alignment to be checked
Returns: boolean
True if passed alignment check
Raises:
  • IndexError - if alignment is out of sentence boundary

__repr__(self)
(Representation operator)

source code 
Returns: string
A string representation for this AlignedSent.
Overrides: object.__repr__

__str__(self)
(Informal representation operator)

source code 
Returns: string
A string representation for this AlignedSent.
Overrides: object.__str__

invert(self)

source code 
Returns: AlignedSent
the invert object

precision(self, reference)

source code 

Calculates the precision of an aligned sentence with respect to a "gold standard" reference AlignedSent.

The "possible" precision is used since it doesn't penalise for finding an alignment that was marked as "possible".

Parameters:
  • reference (AlignedSent or Alignment) - A "gold standard" reference aligned sentence.
Returns: float or None

recall(self, reference)

source code 

Calculates the recall of an aligned sentence with respect to a "gold standard" reference AlignedSent.

The "sure" recall is used so we don't penalise for missing an alignment that was only marked as "possible".

Parameters:
  • reference (AlignedSent or Alignment) - A "gold standard" reference aligned sentence.
Returns: float or None

alignment_error_rate(self, reference, possible=None)

source code 

Calculates the Alignment Error Rate (AER) of an aligned sentence with respect to a "gold standard" reference AlignedSent.

Return an error rate between 0.0 (perfect alignment) and 1.0 (no alignment).

Parameters:
  • reference (AlignedSent or Alignment) - A "gold standard" reference aligned sentence.
  • possible (AlignedSent or Alignment or None) - A "gold standard" reference of possible alignments (defaults to reference if None)
Returns: float or None

Property Details [hide private]

words

mots