114 lines
3.9 KiB
Python
Executable File
114 lines
3.9 KiB
Python
Executable File
from indictrans import Transliterator
|
|
from libindic.transliteration import getInstance
|
|
# import final_transliteration_only.py
|
|
t = getInstance()
|
|
from indic_transliteration import sanscript
|
|
from indic_transliteration.sanscript import transliterate
|
|
import requests, uuid, json
|
|
from transliterate import translit, get_available_language_codes
|
|
# import polyglot
|
|
from polyglot.transliteration import Transliterator as polygolot_transliterator
|
|
from polyglot.text import Text
|
|
# blob = """We will meet at eight o'clock on Thursday morning."""
|
|
# text1212 = Text(blob)
|
|
# # for x in text1212.transliterate("ar"):
|
|
# # print(x)
|
|
# trans_text = text1212.transliterate("ar")
|
|
# print(trans_text)
|
|
# from polyglot.downloader import downloader
|
|
# downloader.download("TASK:transliteration2", quiet=True)
|
|
|
|
|
|
# from transliterate import translit
|
|
# text = "Lorem ipsum dolor sit amet"
|
|
# print(translit(text, 'hy'))
|
|
# transliterator = Transliterator(source_lang="en", target_lang="ru")
|
|
# print(transliterator.transliterate(u"preprocessing"))
|
|
# indic_src_lang = "eng"
|
|
# indic_dest_lang = "urd"
|
|
|
|
# # azure_src_script = ""
|
|
# # azure_dest_script = "Deva"
|
|
# # azure_src_lang = "Arab"
|
|
|
|
# # libindic_dest_script = "en"
|
|
|
|
# text = """ Hello """
|
|
# # out = translit(text, 'ru')
|
|
# # print(out)
|
|
# # #indic-transliteration
|
|
|
|
# trn = Transliterator(source=indic_src_lang, target=indic_dest_lang, build_lookup=True)
|
|
# trans_text = trn.transform(text)
|
|
# print("Indic-trans: ", trans_text)
|
|
# with open('readme.txt', 'w') as f:
|
|
# f.write('Indic Translierated' + "\n")
|
|
# f.write(trans_text + "\n")
|
|
# f.close()
|
|
|
|
# # #libindic-translation
|
|
|
|
# # code = libindic_dest_script+'_IN'
|
|
# # lib_out = t.transliterate(text, code)
|
|
# # # print("Libindic: ", lib_out)
|
|
# # with open('readme.txt', 'w') as f:
|
|
# # f.write('Libindic Translierated' + "\n")
|
|
# # f.write(lib_out + "\n")
|
|
# # f.close()
|
|
|
|
# # #indic-trans-IAST
|
|
|
|
# # # ind_out = transliterate(text, sanscript.H, sanscript.)
|
|
# # # # print("Indic-trans-IAST: ", ind_out)
|
|
# # # with open('readme.txt', 'w') as f:
|
|
# # # f.write('Indic-trans IAST Translierated' + "\n")
|
|
# # # f.write(lib_out + "\n")
|
|
# # # f.close()
|
|
|
|
# # #comparing results
|
|
|
|
# # # sources_name = {'0':'indic_trans', '1':'libindic', '2':'indic_trans_IAST'}
|
|
# # # priority_list =['indic_trans', 'libindic', 'indic_trans_IAST']
|
|
# # # Out = []
|
|
# # # out = [trans_text, lib_out, ind_out]
|
|
# # # Out = all_transliteration.compare_outputs_transliteration(text, out, sources_name, priority_list)
|
|
# # # print(Out)
|
|
|
|
# # #azure-transliteration
|
|
text = "Hello this is dharmesh"
|
|
text2 = "שמי דהרש"
|
|
azure_src_lang = "iw"
|
|
azure_src_script = 'Hebr'
|
|
azure_dest_script = "Latn"
|
|
subscription_key = "83ce6233419541929f7ab0d3035fca58"
|
|
endpoint = "https://api.cognitive.microsofttranslator.com"
|
|
location = "eastus"
|
|
path = '/translate'
|
|
constructed_url = endpoint + path
|
|
headers = {
|
|
'Ocp-Apim-Subscription-Key': subscription_key,
|
|
'Ocp-Apim-Subscription-Region': location,
|
|
'Content-type': 'application/json',
|
|
'X-ClientTraceId': str(uuid.uuid4())
|
|
}
|
|
constructed_url1 = "https://api.cognitive.microsofttranslator.com/transliterate?api-version=3.0"
|
|
|
|
params = {'api-version': '3.0', 'language':azure_src_lang, 'fromScript': azure_src_script, 'toScript': azure_dest_script}
|
|
body = [{'text': text2}]
|
|
request = requests.post(constructed_url1, params=params, headers=headers, json=body)
|
|
response = request.json()
|
|
print(response)
|
|
# with open('readme.txt', 'w') as f:
|
|
# f.write(response[0]['text'])
|
|
# azure_out = response
|
|
# print(response, encoding="utf-8")
|
|
|
|
#print(transliterate(azure_dest_script,azure_src_script,azure_src_lang,text))
|
|
|
|
|
|
# # azure = azure_transliteration(text, azure_src_lang, azure_dest_script)
|
|
# # with open('readme.txt', 'a') as f:
|
|
# # f.write('Azure Translierated' + "\n")
|
|
# # f.write(azure_out + "\n")
|
|
# # f.close()
|