|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import requests |
|
import time |
|
import sys |
|
import config |
|
|
|
from MTUOC_misc import printLOG |
|
|
|
|
|
def connect_to_OpenNMT(): |
|
config.urlOpenNMT = "http://"+config.MTEngineIP+":"+str(config.MTEnginePort)+"/translator/translate" |
|
config.headersOpenNMT = {'content-type': 'application/json'} |
|
|
|
|
|
def translate_segment_OpenNMT(segmentPre): |
|
translation_candidates={} |
|
translation_candidates["segmentNOTAGSPre"]=segmentPre |
|
params = [{ "src" : segmentPre}] |
|
response = requests.post(config.urlOpenNMT, json=params, headers=config.headersOpenNMT) |
|
target = response.json() |
|
selectedtranslationPre=target[0][0]["tgt"] |
|
if "align" in target[0][0]: |
|
selectedalignments=target[0][0]["align"][0] |
|
else: |
|
selectedalignments="" |
|
translation_candidates["translationNOTAGSPre"]=[selectedtranslationPre] |
|
translation_candidates["alignments"]=[selectedalignments] |
|
return(translation_candidates) |
|
|