Creating your own transliterator

The simplest way to create your own transliterator is to instantiate TRuleBasedTransliterator, providing your own set of transliteration rules. To provide a different transliteration mechanism, derive a class from TRuleBasedTransliterator or TTransliterator.

Providing transliteration rules

In later releases the framework will include an interactive editor for creating and modifying rule-based transliterators. Until this feature is available, you can instantiate TRuleBasedTransliterator with rules read in from a text file.

Your file should contain an ordered list of:

Character identifiers Format: Example: identifier = Unicode grAl=$0391 (Greek character capital Alpha)
Range variables Format: Example: variable : values @:aeiou
Forward rules Format: Examples: precedeContext]keyText[succeedContext>resultText A>{grAl} red[light>green red]light>signal
Backward rules Format: Example: precedeContext]keyText[succeedContext<resultText A<{grAl}

CAUTION Make sure that any character identifiers representing the hexadecimal values for a Unicode character (in the form $xxxx) are defined at the beginning of the file, and that the last identifier for this file appears in the final position on the line. If these variables are defined later in the file, the transliterator will hang. This will be fixed in a future release.

To instantiate a transliterator using your file, create a token naming the file and pass it to the transliterator constructor.

Adding rules individually

TRuleBasedTransliterator also provides member functions--AdoptTranslationRule and AdoptTranslationBackRule--for adding rules individually. You can create rules individually, as instances of TTransliterateRule, and add them to the transliteration table using these functions. The transliterator takes responsibility for storing added rules.

Deriving your own transliterator classes

To create a transliterator that provides a different variation of rule-based transliteration, derive a class from TRuleBasedTransliterator. To provide a translation mechanism that is not rule-based, derive a new class directly from TTransliterator.

In either case, you need to override the member functions that perform the actual text translations:

DoTranslate transforms the text according to this transliterator's rules or algorithm.

DoTranslateBack reverses the transliteration, returning text that is as close as possible to the original text input to the transliterator.

These functions do not modify the input text. They return the translated text in a second text instance. DoTranslate and DoTranslateBack are called by the public Translate and TranslateBack functions.

If you derive from TTransliterator, you also need to override these pure virtual functions:


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker