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

Class PinyinBrailleConverter

source code


PinyinBrailleConverter defines a converter between the Chinese romanisation Hanyu Pinyin (with tone marks as numbers) and the Braille system for Mandarin.

Conversion from Braille to Pinyin is ambiguous. The syllable pairs mo/me, e/o and le/lo will yield an AmbiguousConversionError.


See Also:

To Do (Impl): Move the toneMarks option to the MandarinBrailleOperator.

Instance Methods [hide private]
 
__init__(self, *args, **options)
Creates an instance of the PinyinBrailleConverter.
source code
 
_createMappings(self)
Creates the mappings of syllable initials and finals from the database.
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
str
convertBasicEntity(self, entity, fromReading, toReading)
Converts a basic entity (a syllable) in the source reading to the given target reading.
source code

Inherited from ReadingConverter: convert, getOption

Inherited from ReadingConverter (private): _getFromOperator, _getToOperator

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 = [('Pinyin', 'MandarinBraille'), ('Mand...
List of tuples for specifying supported conversion directions from reading A to reading B.
  PUNCTUATION_SIGNS_MAPPING = {u'!': u'⠰⠂', u'(': u'⠰⠄', u')': u...
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

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

source code 

Creates an instance of the PinyinBrailleConverter.

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.
  • toneMarks - if set to True tone marks will be used when converted to Braille representation.
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.
Overrides: ReadingConverter.getDefaultOptions
(inherited documentation)

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 entities written in source reading
  • fromReading - name of the source reading
  • toReading - 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.
Overrides: ReadingConverter.convertEntities
(inherited documentation)

convertBasicEntity(self, entity, fromReading, toReading)

source code 

Converts a basic entity (a syllable) in the source reading to the given target reading.

This method is called by convertEntities() and a single entity is given for conversion.

If a single entity needs to be converted it is recommended to use convertEntities() instead. In the general case it can not be ensured that a mapping from one reading to another can be done by the simple conversion of a basic entity. One-to-many mappings are possible and there is no guarantee that any entity of a reading recognised by operator.ReadingOperator.isReadingEntity() will be mapped here.

Parameters:
  • entity (str) - string written in the source reading in lower case letters
  • fromReading (str) - name of the source reading
  • toReading (str) - name of the target reading, different from the source reading
Returns: str
the entity converted to the toReading in lower case
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:
[('Pinyin', 'MandarinBraille'), ('MandarinBraille', 'Pinyin')]

PUNCTUATION_SIGNS_MAPPING

Value:
{u'!': u'⠰⠂',
 u'(': u'⠰⠄',
 u')': u'⠠⠆',
 u',': u'',
 u'-': u'⠠⠤',
 u':': u'',
 u';': u'',
 u'?': u'⠐⠄',
...