Package cjklib :: Package reading :: Module converter :: Class ReadingConverter
[hide private]
[frames] | no frames]

Class ReadingConverter

source code


Defines an abstract converter between two or more character readings.

The basic method is convert() which converts one input string from one reading to another.

The methods getDefaultOptions() and getOption() provide means to handle conversion specific settings.

The class itself can't be used directly, it has to be subclassed and its methods need to be extended.

Instance Methods [hide private]
 
__init__(self, *args, **options)
Creates an instance of the ReadingConverter.
source code
 
getOption(self, option)
Returns the value of the reading converter's option.
source code
str
convert(self, string, fromReading, toReading)
Converts a string in the source reading to the given target reading.
source code
list of str
convertEntities(self, readingEntities, fromReading, toReading)
Converts a list of entities in the source reading to the given target reading.
source code
instance
_getFromOperator(self, readingN)
Gets a reading operator instance for conversion from the given reading.
source code
instance
_getToOperator(self, readingN)
Gets a reading operator instance for conversion to the given reading.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Methods [hide private]
dict
getDefaultOptions(cls)
Returns the reading converter's default options.
source code
Class Variables [hide private]
  CONVERSION_DIRECTIONS = []
List of tuples for specifying supported conversion directions from reading A to reading B.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, *args, **options)
(Constructor)

source code 

Creates an instance of the ReadingConverter.

Parameters:
  • args - optional list of RomanisationOperators to use for handling source and target readings.
  • options - extra options
  • dbConnectInst - instance of a DatabaseConnector, if none is given, default settings will be assumed.
  • sourceOperators - list of ReadingOperators used for handling source readings.
  • targetOperators - list of ReadingOperators used for handling target readings.
Overrides: object.__init__

getDefaultOptions(cls)
Class Method

source code 

Returns the reading converter's default options.

The keyword 'dbConnectInst' is not regarded a configuration option of the converter and is thus not included in the dict returned.

Returns: dict
the reading converter's default options.

getOption(self, option)

source code 

Returns the value of the reading converter's option.

Returns:
the value of the given reading converter's option.

convert(self, string, fromReading, toReading)

source code 

Converts a string in the source reading to the given target reading.

Parameters:
  • string (str) - string written in the source reading
  • fromReading (str) - name of the source reading
  • toReading (str) - name of the target reading
Returns: str
the input string converted to the toReading
Raises:
  • DecompositionError - if the string can not be decomposed into basic entities with regards to the source reading or the given information is insufficient.
  • ConversionError - on operations specific to the conversion between the two readings (e.g. error on converting entities).
  • UnsupportedError - if source or target reading is not supported for conversion.

convertEntities(self, readingEntities, fromReading, toReading)

source code 

Converts a list of entities in the source reading to the given target reading.

The default implementation will raise a NotImplementedError.

Parameters:
  • readingEntities (list of str) - list of entities written in source reading
  • fromReading (str) - name of the source reading
  • toReading (str) - name of the target reading
Returns: list of str
list of entities written in target reading
Raises:
  • ConversionError - on operations specific to the conversion between the two readings (e.g. error on converting entities).
  • UnsupportedError - if source or target reading is not supported for conversion.
  • InvalidEntityError - if an invalid entity is given.

_getFromOperator(self, readingN)

source code 

Gets a reading operator instance for conversion from the given reading.

Parameters:
  • readingN (str) - name of reading
Returns: instance
a ReadingOperator instance
Raises:

_getToOperator(self, readingN)

source code 

Gets a reading operator instance for conversion to the given reading.

Parameters:
  • readingN (str) - name of reading
Returns: instance
a ReadingOperator instance
Raises:

Class Variable Details [hide private]

CONVERSION_DIRECTIONS

List of tuples for specifying supported conversion directions from reading A to reading B. If both directions are supported, two tuples (A, B) and (B, A) are given.

Value:
[]