-
Notifications
You must be signed in to change notification settings - Fork 0
Using YuConv
To import YuConv in your Python code, you can import 2 classes:
- YuConverter (Class for text transliteration)
- TransliterationMode (Class for transliteration mode CyrillicToLatin, and LatinToCyrillic)
To import YuConv in your code, please type the following in your .py file:
from yuconv import YuConverter, TransliterationModeTo declare the YuConverter class, you can assign class name to a variable using 2 methods:
yu_converter = YuConverter()
yu_converter = YuConverter(test.txt)You can assign the class name to a variable without, or with file name as the optional parameter. If you pass a file name, you do not have to pass the input_file parameter to transliterate_text_file, and transliterate_word_document functions of the YuConverter class.
To transliterate text, you can use transliterate_text function from the YuConverter class.
- Text (str) Text to be transliterated
- transliteration_mode (str) Transliteration mode (CyrToLat, or LatToCyr)
from yuconv import YuConverter, TransliterationMode
yu_converter = YuConverter()
source_text = 'Svinja je domaća životinja'
dest_text = yu_converter.transliterate_text(source_text, TransliterationMode().LatinToCyrillic)
print(dest_text)After the transliteration, you will get text like Свиња је домаћа животиња.
also, you can transliterate and text files using the transliterate_text_file function from the YuConverter class.
- input_file (str) Input text file to be transliterated. If you specify a text file when you declaring YuConverter class, you don't need to pass the input_file parameter.
- output_file (str) A text file where transliteration results are saved
- transliteration_mode (str) Transliteration mode (CyrToLat, or LatToCyr)
from yuconv import YuConverter, TransliterationMode
yu_converter = YuConverter(file.txt)
mode = TransliterationMode()
transliterate_text_file(output_file="output.txt", transliteration_mode=mode.CyrillicToLatin)As you can see, the input_file parameter is not used, and variable mode has been asigned to the class TransliterationMode In the following example, we will use boath parameters input_file, and the output_file
from yuconv import YuConverter, TransliterationMode
inputfile = 'file1.txt'
outputfile = 'file2.txt'
yu_converter = YuConverter()
transliterate_text_file(inputfile, outputfile, TransliterationMode().LatinToCyrillic)Copyright (C) 2004, Darko Milošević