Skip to main content

URBAN: Universal Rule-Based Machine Translation toolkit

A tool for translating text from source grammar to target grammar (context-free) with corresponding dictionary.

Why not translate it yourself when Google Translate cannot satisfy you❓

CircleCI Codacy Badge Codacy Badge PyPI version GitHub release Maintenance License

⚙️ Installation

pip install urban

✨ What is good about URBAN?

  • Rule-based, deterministic translation; unlike Google Translate - giving only 1 non-deterministic result
  • Using NLTK parsing interface and is built on top of already-efficient NLTK backend
  • Can be used for data augmentation

📖 Usage

from urban import Translator

# Source sentence to be translated
src_sentences = ["I love good dogs", "I hate bad dogs"]

# Source grammar in nltk parsing style
src_grammar = """
                S -> NP VP
                NP -> PRP
                VP -> VB NP
                NP -> JJ NN
                PRP -> 'I'
                VB -> 'love' | 'hate'
                JJ -> 'good' | 'bad'
                NN -> 'dogs'
                """

# Some edit within source grammar to target grammar
src_to_target_grammar =  {
    "NP -> JJ NN": "NP -> NN JJ" # in Vietnamese NN goes before JJ
}

# Word-by-word dictionary from source language to target language
en_to_vi_dict = {
    "I":"tôi",
    "love":"yêu",
    "hate":"ghét",
    "dogs":"những chú_chó",
    "good":"ngoan",
    "bad":"hư"
    }

translator = Translator(src_grammar = src_grammar,
                        src_to_tgt_grammar = src_to_target_grammar,
                        src_to_tgt_dictionary = en_to_vi_dict)

trans_sentences = translator.translate(src_sentences) 
# This should returns ['tôi yêu những chú_chó ngoan', 'tôi ghét những chú_chó hư']

⚖️ License

This repository is using the Apache 2.0 license that is listed in the repo. Please take a look at LICENSE as you wish.

✍️ BibTeX

If you wish to cite the framework feel free to use this (but only if you loved it 😊):

@misc{phat2020urban,
  author = {Truong-Phat Nguyen},
  title = {URBAN: Universal Rule-Based Machine Translation NLP toolkit},
  year = {2020},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/nlp-urban/urban}},
}

Contributors:

  • Patrick Phat Nguyen

Metadata

Release files for ruby 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ruby 0.0.1
File Size Uploaded
ruby-0.0.1.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ruby 0.0.1
File Interpreter ABI Platform
ruby-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.8 kB

Release files / ruby-0.0.1.tar.gz

Download URL ruby-0.0.1.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
21bd25903f5aef174aa1835403675a9df0ffe9088e241cdbfe44bb64dd75dee9
BLAKE2b-256 checksum
How to use checksums
41cdd0b7e3881fc2a840ccba95005a381a06a7691bf8d6cf6abfe9103618953e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.6.12

Release files / ruby-0.0.1-py3-none-any.whl

Download URL ruby-0.0.1-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e125f2025628028d431ade5562d2989ce63573dc2e69720901ae904fc353b0df
BLAKE2b-256 checksum
How to use checksums
80a87a914d7f88cd9efa41f1c662ce8da6aadd740fcd534cd2cdb3529f46771c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.6.12

Release history Release notifications | RSS feed

0.0.2

2 release files

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page