Skip to main content

uroman is a universal romanizer. It converts text in any script to the standard Latin alphabet.

Project description

uroman

uroman is a universal romanizer. It converts text in any script to the standard Latin alphabet.
    Example (Greek): Νεπάλ → Nepal
    Example (Hindi):  नेपाल → nepaal
    Example (Urdu):  نیپال → nypal
    Example (Chinese): 三万一 → 31000

  • uroman enables the application of string-similarity metrics to texts from different scripts without the need and complexity of an intermediate phonetic representation.
  • uroman converts digital numbers in various scripts to Western Arabic numerals.
  • uroman uses m-to-n character mappings, context, and a user-provided language code (optional), i.e. uroman does not just replace characters one by one.
  • uroman expects all input to be encoded in UTF-8.

New Python version: 1.3.1 (released on June 27, 2024)
Last Perl version: 1.2.8 (released on April 23, 2021)
Author: Ulf Hermjakob, USC Information Sciences Institute

(New) Python version

Installation

python3 -m pip install uroman

Command Line Interface (CLI)

Examples

python3 -m uroman "Игорь Стравинский"
python3 -m uroman Игорь -l ukr
python3 -m uroman Ντέιβις Καπ -l ell
python3 -m uroman "\u03C0\u03B9" -d
python3 -m uroman -l hin -i mini-test/hin.txt
python3 -m uroman -l fas -i mini-test/fas.txt -o mini-test/fas-rom.jsonl -f edges
python3 -m uroman < mini-test/multi-script.txt > mini-test/multi-script.uroman.txt
python3 -m uroman -h

Note: Using the uroman CLI for single strings can be useful for simple tests, but it is inefficient at scale because data resources are loaded every time. It is more efficient to romanize entire files or to use uroman inside Python as shown further below.
Note: The mini-test directory is included in this release. Use command   python3 -m uroman x --verbose   to find it. You can compare your output mini-test/multi-script.uroman.txt with reference output mini-test/multi-script.uroman-ref.txt

uroman.py   Argument Structure Highlights

Direct inputs (zero or more)such as ‘Игорь Стравинский’ and ‘Ντέιβις’ above.
-l
--lcode
language code according to ISO-639-3, e.g. -l ukr for Ukrainian, -l hin for Hindi, -l fas for Persian
-i
--input_filename
alternative: stdin
Note: If both direct inputs and input_filename are given, the romanization results for direct inputs will be written to stderr.
-o
--output_filename
alternative: stdout
-f
--rom_format
Output format choices:
  • -f str       (best string, default, output format: string)
  • -f edges (best edges, includes offset information, output format: JSONL)
  • -f alts      (lattice including alternative edges, output format: JSONL)
  • -f lattice (lattice including alternative and superseded edges, output format: JSONL)
-d
--decode_unicode
Decode Unicode escape sequences such as ‘\u03C0\u03B9’ to ‘πι’ which in turn will be romanized to ‘pi’. This is useful for input formats such as JSON.
-h
--help
Use this option to see the full argument structure with all options.

Using uroman inside Python

Examples

import uroman as ur

uroman = ur.Uroman()   # load uroman data (takes about a second or so)
print(uroman.romanize_string('Игорь Стравинский'))
print(uroman.romanize_string('Игорь', lcode='ukr'))
uroman.romanize_file(input_filename='mini-test/multi-script.txt',
                     output_filename='mini-test/multi-script.uroman.jsonl',
                     rom_format=ur.RomFormat.LATTICE)

Methods

uroman = ur.Uroman(data_dir)

This constructor method loads data needed for the romanization of different languages. This constructor call might take about a second (real time) to load all of the romanization data, but it is necessary only once for multiple subsequent romanization calls.

data_dirdata directory (optional, default: standard uroman data directory)

uroman.romanize_string(s, lcode, rom_format)

This method takes a string s and returns its romanization in the format according to rom_format: a string (default), or a list of edges.

sstring to be romanized, e.g. "ایران"
lcodelanguage code, optional, a 3-letter code such as 'eng' for English (ISO-639-3)
rom_formatOutput format choices:
  • ur.RomFormat.STR       (best string, default, output format: string)
  • ur.RomFormat.EDGES  (best edges, includes offset information, output format: JSONL)
  • ur.RomFormat.ALTS     (lattice including alternative edges, output format: JSONL)
  • ur.RomFormat.LATTICE (lattice including alternative and superseded edges, output format: JSONL)

uroman.romanize_file(input_filename, output_filename, lcode)

This method romanizes a file input_filename to output_filename.

input_filenamedefault: stdin (for input_filename value of None)
output_filenamedefault: stdout (for output_filename value of None)
lcodelanguage code (optional), a 3-letter code such as 'eng' for English (ISO-639-3)

Old Perl Version

Old Perl Version included on GitHub, but not included on PyPI.

Usage

$ uroman.pl [-l <lang-code>] [--chart] [--no-cache] < STDIN
       where the optional <lang-code> is a 3-letter languages code, e.g. ara, bel, bul, deu, ell, eng, fas,
            grc, ell, eng, heb, kaz, kir, lav, lit, mkd, mkd2, oss, pnt, pus, rus, srp, srp2, tur, uig, ukr, yid.
       --chart specifies chart output (in JSON format) to represent alternative romanizations.
       --no-cache disables caching.

Examples

Note: Directories text and test are under uroman's root directory on GitHub.

uroman.pl < text/zho.txt
uroman.pl -l tur < text/tur.txt
uroman.pl -l heb --chart < text/heb.txt
uroman.pl < test/multi-script.txt > test/multi-script.uroman-perl.txt

Identifying the input as Arabic, Belarusian, Bulgarian, English, German, Ancient Greek, Modern Greek, Pontic Greek, Hebrew, Kazakh, Kyrgyz, Latvian, Lithuanian, Macedonian, Ossetian, Persian, Russian, Serbian, Turkish, Ukrainian, Uyghur or Yiddish will improve romanization for those languages as some letters in those languages have different sound values from other languages using the same script (Arabic vs. Persian, Russian vs. Ukrainian, Hebrew vs. Yiddish). No effect for other languages in this version.

Bibliography

Ulf Hermjakob, Jonathan May, and Kevin Knight. 2018. Out-of-the-box universal romanization tool uroman. In Proceedings of the 56th Annual Meeting of Association for Computational Linguistics, Demo Track. ACL-2018 Best Demo Paper Award. Paper in ACL Anthology | Poster | BibTex

Change History

Changes in version 1.3.0

  • Added Python version.
  • Initial dedicated support for Coptic (Egypt); significantly improved support for Thai; improved support for Khmer, Tibetan and several Indian languages incl. better final schwa deletion.
  • Chinese fractions and percentages.
  • Various small improvements.

Changes in version 1.2.8

  • Updated to Unicode 13.0 (2021), which supports several new scripts (10% larger UnicodeData.txt).
  • Improved support for Georgian.
  • Preserve various symbols (as opposed to mapping to the symbols' names).
  • Various small improvements.

Changes in version 1.2.7

  • Improved support for Pashto.

Changes in version 1.2.6

  • Improved support for Ukrainian, Russian and Ogham (ancient Irish script).
  • Added support for English Braille.
  • Added alternative Romanization for Macedonian and Serbian (mkd2/srp2) reflecting a casual style that many native speakers of those languages use when writing text in Latin script, e.g. non-accented single letters (e.g. "s") rather than phonetically motivated combinations of letters (e.g. "sh").
  • When a line starts with "::lcode xyz ", the new uroman version will switch to that language for that line. This is used for the new reference test file.
  • Various small improvements.

Changes in version 1.2.5

  • Improved support for Armenian and eight languages using Cyrillic scripts. -- For Serbian and Macedonian, which are often written in both Cyrillic and Latin scripts, uroman will map both official versions to the same romanized text, e.g. both "Ниш" and "Niš" will be mapped to "Nish" (which properly reflects the pronunciation of the city's name). For both Serbian and Macedonian, casual writers often use a simplified Latin form without diacritics, e.g. "s" to represent not only Cyrillic "с" and Latin "s", but also "ш" or "š", even if this conflates "s" and "sh" and other such pairs. The casual romanization can be simulated by using alternative uroman language codes "srp2" and "mkd2", which romanize both "Ниш" and "Niš" to "Nis" to reflect the casual Latin spelling.
  • Various small improvements.

Changes in version 1.2.4

  • Bug-fix that generated two emtpy lines for each empty line in cache mode.

Changes in version 1.2

  • Run-time improvement based on (1) token-based caching and (2) shortcut romanization (identity) of ASCII strings for default 1-best (non-chart) output. Speed-up by a factor of 10 for Bengali and Uyghur on medium and large size texts.
  • Incremental improvements for Farsi, Amharic, Russian, Hebrew and related languages.
  • Richer lattice structure (more alternatives) for "Romanization" of English to support better matching to romanizations of other languages. Changes output only when --chart option is specified. No change in output for default 1-best output, which for ASCII characters is always the input string.

Changes in version 1.1 (major upgrade)

  • Offers chart output (in JSON format) to represent alternative romanizations.
    • Location of first character is defined to be "line: 1, start:0, end:0".
  • Incremental improvements of Hebrew and Greek romanization; Chinese numbers.
  • Improved web-interface (now) at https://uhermjakob.github.io/uroman.html
    • Shows corresponding original and romanization text in red when hovering over a text segment.
    • Shows alternative romanizations when hovering over romanized text marked by dotted underline.
    • Added right-to-left script detection and improved display for right-to-left script text (as determined line by line).
    • On-page support for some scripts that are often not pre-installed on users' computers (Burmese, Egyptian, Klingon).

Changes in version 1.0 (major upgrade)

  • Upgraded principal internal data structure from string to lattice.
  • Improvements mostly in vowelization of South and Southeast Asian languages.
  • Vocalic 'r' more consistently treated as vowel (no additional vowel added).
  • Repetition signs (Japanese/Chinese/Thai/Khmer/Lao) are mapped to superscript 2.
  • Japanese Katakana middle dots now mapped to ASCII space.
  • Tibetan intersyllabic mark now mapped to middle dot (U+00B7).
  • Some corrections regarding analysis of Chinese numbers.
  • Many more foreign diacritics and punctuation marks dropped or mapped to ASCII.
  • Zero-width characters dropped, except line/sentence-initial byte order marks.
  • Spaces normalized to ASCII space.
  • Fixed bug that in some cases mapped signs (such as dagger or bullet) to their verbal descriptions.
  • Tested against previous version of uroman with a new uroman visual diff tool.
  • Almost an order of magnitude faster.

Changes in version 0.7 (minor upgrade)

  • Added script uroman-quick.pl for Arabic script languages, incl. Uyghur. Much faster, pre-caching mapping of Arabic to Latin characters, simple greedy processing. Will not convert material from non-Arabic blocks such as any (somewhat unusual) Cyrillic or Chinese characters in Uyghur texts.

Changes in version 0.6 (minor upgrade)

  • Added support for two letter characters used in Uzbek: (1) character "ʻ" ("modifier letter turned comma", which modifies preceding "g" and "u" letters) (2) character "ʼ" ("modifier letter apostrophe", which Uzbek uses to mark a glottal stop). Both are now mapped to "'" (plain ASCII apostrophe).
  • Added support for Uyghur vowel characters such as "ې" (Arabic e) and "ۆ" (Arabic oe) even when they are not preceded by "ئ" (yeh with hamza above).
  • Added support for Arabic semicolon "؛", Arabic ligature forms for phrases such as "ﷺ" ("sallallahou alayhe wasallam" = "prayer of God be upon him and his family and peace")
  • Added robustness for Arabic letter presentation forms (initial/medial/final/isolated). However, it is strongly recommended to normalize any presentation form Arabic letters to their non-presentation form before calling uroman.
  • Added force flush directive ($|=1;).

Changes in version 0.5 (minor upgrade)

  • Improvements for Uyghur (make sure to use language option: -l uig)

Changes in version 0.4 (minor upgrade)

  • Improvements for Thai (special cases for vowel/consonant reordering, e.g. for "sara o"; dropped some aspiration 'h's)
  • Minor change for Arabic (added "alef+fathatan" = "an")

New features in version 0.3

  • Covers Mandarin (Chinese)
  • Improved romanization for numerous languages
  • Preserves capitalization (e.g. from Latin, Cyrillic, Greek scripts)
  • Maps from native digits to Western numbers
  • Faster for South Asian languages

Other features

Limitations

  • The current version of uroman has a few limitations, some of which we plan to address in future versions. For Japanese, uroman currently romanizes hiragana and katakana as expected, but kanji are interpreted as Chinese characters and romanized as such. For Egyptian hieroglyphs, only single-sound phonetic characters and numbers are currently romanized. For Linear B, only phonetic syllabic characters are romanized. For some other extinct scripts such as cuneiform, no romanization is provided.
  • A romanizer is not a full transliterator. For example, this version of uroman does not vowelize text that lacks explicit vowelization such as normal text in Arabic and Hebrew (without diacritics/points).

Acknowledgments

Earlier versions of this tool were based upon work supported in part by the Office of the Director of National Intelligence (ODNI), Intelligence Advanced Research Projects Activity (IARPA), via contract # FA8650-17-C-9116, and by research sponsored by Air Force Research Laboratory (AFRL) under agreement number FA8750-19-1-1000. The views and conclusions contained herein are those of the authors and should not be interpreted as necessarily representing the official policies, either expressed or implied, of ODNI, IARPA, Air Force Laboratory, DARPA, or the U.S. Government. The U.S. Government is authorized to reproduce and distribute reprints for governmental purposes notwithstanding any copyright annotation therein.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uroman-1.3.1.1.tar.gz (896.7 kB view details)

Uploaded Source

Built Distribution

uroman-1.3.1.1-py3-none-any.whl (930.7 kB view details)

Uploaded Python 3

File details

Details for the file uroman-1.3.1.1.tar.gz.

File metadata

  • Download URL: uroman-1.3.1.1.tar.gz
  • Upload date:
  • Size: 896.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.5

File hashes

Hashes for uroman-1.3.1.1.tar.gz
Algorithm Hash digest
SHA256 6aaf2d5265f24f15201cbbf92c86720b2b804ac53294ce43a3307fcd242387d5
MD5 150906cb3de3fae7185d0766e2c175ae
BLAKE2b-256 73037d23f79d9b259861c31437ed76007eb8dc6f6c419b709f5b2ef37d4fa7da

See more details on using hashes here.

File details

Details for the file uroman-1.3.1.1-py3-none-any.whl.

File metadata

  • Download URL: uroman-1.3.1.1-py3-none-any.whl
  • Upload date:
  • Size: 930.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.5

File hashes

Hashes for uroman-1.3.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 394f965f7011fd56a84aca098a6c3b50082f365324f5d94c992852137918c8f5
MD5 4f4c3e3196f094cd0ef5cb6fa01ffab3
BLAKE2b-256 78e143722c41eebab0592c6f83410e5e35edc1d6e333f44feb0a543bd38dba3e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page