Skip to content
This repository was archived by the owner on Jul 3, 2022. It is now read-only.

kadircancetin/tureng

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This package is a very basic, python 3 https://tureng.com wrapper of thier mobile api. Please read the terms and conditions of the tureng before the use this package on any production.

Installation

pip install tureng  

Usage

Tureng.translate(word:str) method returns a TranslatedResult object. It has meta data like is_found and the translated words like grouped_results. If the translation can’t found it will suggest list of string on suggestions. You can get best translation results with TranslatedResult.best_tr_translation

grouped_results is a list of TurEngGroup class. You can search groups with group_search(patern, attribution="name_en") or you can get tr2en translatition groups with tr2en_groups.

Any group has .words attribute that is a list of TurEngWord objects. TurEngWord class is just a class that store the translation string’s some meta data.

Generaly: TurEngWord n –> 1 TurEngGroup n –> 1 TranslatedResult

Example usage:

from tureng import TurEng
tureng = TurEng()


yes_result = tureng.translate("yes")
yes_result.all_tr_translation_str
# ['evet', 'olumlu cevap', 'olumlu oy', 'hatta', 'bile', 'ya', 'baş üstüne', 'tamam', 'evet']
yes_result.best_tr_translation
# yes -> evet
yes_result.best_tr_translation.tr
# evet
yes_result.best_tr_translation.type_en
# 'n.'  # noun
yes_result.tr2en_groups
# []
yes_result.en2tr_groups
# [(en->tr) Yaygın Kullanım-Common Usage Group [1 word], (en->tr) Genel-General Group [8 word]]
yes_general_group = yes_result.en2tr_groups[1]
yes_general_group.orj_lang
# 'en'
yes_general_group.words
# [yes -> olumlu cevap, yes -> olumlu oy, yes -> hatta, yes -> bile, yes -> ya, yes -> baş üstüne, yes -> tamam, yes -> evet]
yes_general_group.words[0]
# yes -> olumlu cevap


yys_result = tureng.translate("yys") # random translation result for suggestion
yys_result.is_found
# 0
yys_result.suggestions
# ['yrs', 'yas', 'yds', 'ygs', 'dys', 'yes', 'öys', 'days', 'brys', 'yoyo']
yys_result.has_error
# False


car_result = tureng.translate("car")  # car_result
car_result.all_tr_translation_str
# ['otomobil', 'araba', 'kabin', 'araba', 'makine', 'vagon', 'yolcu taşıyan herhangi bir aracın bölmesi', 'oto', 'araç', 'vagonet', "ingiltere'de tekerlekli, motorlu veya motorsuz kara taşıma aracı", 'balık ve ıstakoz saklanan kutu', 'vagon', 'otomobil', 'binek otomobil', 'araba', 'yük ve yolcu taşıyan demiryolu arabası', 'yolcu vagonu', 'yük vagonu', 'vagon', 'karoser', 'hava gemisi yolcu bölmesi', 'bölme']
car_result.best_tr_translation
# car -> otomobil
car_result.grouped_results
# [(tr->en) Genel-General Group [3 word], (tr->en) Teknik-Technical Group [1 word], (tr->en) Bilgisayar-Computer Group [1 word], (tr->en) Tarih-History Group [1 word], .........]
car_result.group_search(".*ilgisayar.*", "name_tr")
# [(tr->en) Bilgisayar-Computer Group [1 word]]

car_bilgisayar_group = car_result.group_search(".*ilgisayar.*", "name_tr")[0]
car_bilgisayar_group.name_tr
# 'Bilgisayar'
car_bilgisayar_group.orj_lang
# 'tr'

car_bilg_word = car_bilgisayar_group.words[0]
car_bilg_word.tr
# 'car'
car_bilg_word.en
# 'wed'
car_bilg_word
# car -> wed

Tests

Please note that this package is an unofficial wrapper. So if the tureng API will change, the package will not work. Maybe you want to check is it run properley.

python tureng/tests.py

Thanks

Thanks to https://github.com/yozel/tureng yozel for the his open-source code which inspires to write this.

About

Unofficial, python tureng API wrapper

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages