Package cjklib :: Package reading :: Module operator :: Class ReadingOperator
[hide private]
[frames] | no frames]

Class ReadingOperator

source code


Defines an abstract operator on text written in a character reading.

The two basic methods are decompose() and compose(). decompose() breaks down a text into the basic entities of that reading (additional non reading substrings are accepted though). compose() joins these entities together again and applies formating rules needed by the reading. Additionally the method isReadingEntity() is provided to check which of the strings returned by decompose() are supported entities for the given reading.

The methods getDefaultOptions() and getOption() provide means to handle the reading dialect's 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, **options)
Creates an instance of the ReadingOperator.
source code
 
getOption(self, option)
Returns the value of the reading operator's option.
source code
list of str
decompose(self, string)
Decomposes the given string into basic entities that can be mapped to one Chinese character each (exceptions possible).
source code
str
compose(self, readingEntities)
Composes the given list of basic entities to a string.
source code
bool
isReadingEntity(self, entity)
Returns true if the given entity is recognised by the reading operator, i.e.
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 operator's default options.
source code
Class Variables [hide private]
  READING_NAME = None
Unique name of reading
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, **options)
(Constructor)

source code 

Creates an instance of the ReadingOperator.

Parameters:
  • options - extra options
  • dbConnectInst - instance of a DatabaseConnector, if none is given, default settings will be assumed.
Overrides: object.__init__

getDefaultOptions(cls)
Class Method

source code 

Returns the reading operator's default options.

The default implementation returns an empty dictionary. The keyword 'dbConnectInst' is not regarded a configuration option of the operator and is thus not included in the dict returned.

Returns: dict
the reading operator's default options.

getOption(self, option)

source code 

Returns the value of the reading operator's option.

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

decompose(self, string)

source code 

Decomposes the given string into basic entities that can be mapped to one Chinese character each (exceptions possible).

The given input string can contain other non reading characters, e.g. punctuation marks.

The returned list contains a mix of basic reading entities and other characters e.g. spaces and punctuation marks.

The default implementation will raise a NotImplementedError.

Parameters:
  • string (str) - reading string
Returns: list of str
a list of basic entities of the input string
Raises:

compose(self, readingEntities)

source code 

Composes the given list of basic entities to a string.

The default implementation will raise a NotImplementedError.

Parameters:
  • readingEntities (list of str) - list of basic entities or other content
Returns: str
composed entities

isReadingEntity(self, entity)

source code 

Returns true if the given entity is recognised by the reading operator, i.e. it is a valid entity of the reading returned by decompose().

The default implementation will raise a NotImplementedError.

Parameters:
  • entity (str) - entity to check
Returns: bool
true if string is an entity of the reading, false otherwise.