def test_translate_work_code(self): """ Проверка на ответ 200 :return: """ answer_json = translate("Привет") self.assertEqual(answer_json['code'], 200)
def retriveText1(self): rna = self.plainTextEdit.toPlainText() translator = translate(rna) rna = translator.get_rna() percentage = round(translator.get_cgpercent(), 3) self.textEdit.setText(rna) self.textEdit_3.setText(str(percentage) + '%') self.textEdit_4.setText(str(100 - percentage) + '%')
def test_correct_translation(self): """ ПРоверил на правильный перевод :return: """ answer_json = translate("Привет") result = answer_json.get('text') self.assertEqual(result[0], "Hi")
def tr(): sentence = request.form.get("sentence") # Got the sentence. if request.method == "GET": sentence = request.args.get("sentence") # Overriding for GET try: sentence = translate(sentence) # Translating from the main.translate() function. return json.jsonify(sentence=sentence) except socket_error as error: print "Exception when translating '" + sentence + "', socket_error: " + str(error) return json.jsonify(error=str(error))
def wikiResponse(self, userMessage, lan): # Set the wiki language and get a response m.setWikiLan(lan) topResult, summary = m.getTopSearch(userMessage) if topResult != -1: # Translate the wrapping text, and get the display that response outputStr = f'{m.translate("Are you talking about","en",lan)} {topResult.title}? {m.translate("Here is what I know about this based on wikipedia.","en",lan)} \n{m.translate("A link to the page is:","en",lan)} {topResult.url}\n{m.translate("Here is the first 3 sentences of the summary:","en",lan)}\n{summary}' else: # If the wiki search returned no results, return this string translated outputStr = m.translate( "I don\'t have any hits for that search, sorry!", "en", lan) return outputStr
def getResponse(self): # Get user message userMessage = self.userInput.get() # Language is usable forms shortLan = self.languages[self.lan.get()] # Ignore empty messages if userMessage == "": return # Clear the user input self.userInput.delete(0, "end") # Check if the wiki command is in the chat if "wiki " == userMessage.lower()[0:5]: # Send user message without the wiki portion, and save the response wikiReply = self.wikiResponse(userMessage[5:], shortLan) self.addExchange(userMessage, wikiReply) return # Translate input to english to send to our bot userEnglish = m.translate(userMessage, shortLan, 'en') # Get our reply reply = m.getFinalOutput(self.loaded_clf, userEnglish) # Translate reply to proper language replyLan = m.translate(reply, 'en', shortLan) self.addExchange(userMessage, replyLan)
def btnPress2_clicked(self): #以Html的格式输出多行文本框,字体红色,字号6号 text = self.deal_control_char(self.textEdit1.toPlainText()).strip() if text == '': return print(text) # return tk = self.js.getTk(text) result=main.translate(text,tk) print ("result: ", result) end = result.find("\",") if end > 4: print(result[4:end]) self.textEdit2.setText(result[4:end])
def abc(): js = Py4Js() # JS执行器 msg_cn = translate('A very good app. Easy to use, reliable and hasn\'t given any problems.', js, 'zh') print(msg_cn) pass
def command_line(): output = "" if len(sys.argv) == 5: if sys.argv[1] == "-i": dataset_path = sys.argv[2] if sys.argv[3] == "-p": parameter_path = sys.argv[4] elif sys.argv[1] == "-p": parameter_path = sys.argv[2] if sys.argv[3] == "-i": dataset_path = sys.argv[4] elif len(sys.argv) == 7: if sys.argv[1] == "-i": dataset_path = sys.argv[2] if sys.argv[3] == "-p": parameter_path = sys.argv[4] if sys.argv[5] == "-o": output = sys.argv[6] elif sys.argv[3] == "-o": output = sys.argv[4] if sys.argv[5] == "-p": parameter_path = sys.argv[6] elif sys.argv[1] == "-p": parameter_path = sys.argv[2] if sys.argv[3] == "-i": dataset_path = sys.argv[4] if sys.argv[5] == "-o": output = sys.argv[6] elif sys.argv[3] == "-o": output = sys.argv[4] if sys.argv[5] == "-i": dataset_path = sys.argv[6] elif sys.argv[1] == "-o": output = sys.argv[2] if sys.argv[3] == "-i": dataset_path = sys.argv[4] if sys.argv[5] == "-p": parameter_path = sys.argv[6] elif sys.argv[3] == "-p": parameter_path = sys.argv[4] if sys.argv[5] == "-i": dataset_path = sys.argv[6] else: print ("Erro\n.") if output == "": output = dataset_path samples = read_samples(dataset_path) parameters = open(parameter_path).read() parameters = parameters.lower() parameters = parameters.replace(" ", "") parameters = parameters.replace("\t", "") original = False normalization = False use_wordnet = False use_wikipedia = False concepts = False disambiguation = False All = False if 'all=yes' in parameters: All = True if 'original=yes' in parameters: original = True if 'normalization=yes' in parameters: normalization = True if 'concepts=yes' in parameters: concepts = True if 'disambiguation=yes' in parameters: disambiguation = True if 'use_wordnet=yes' in parameters: use_wordnet = True if 'use_wikipedia=yes' in parameters: use_wikipedia = True if not use_wordnet and not use_wikipedia: use_wordnet = use_wikipedia = True parameter_file = open(parameter_path, "r") lines = [l.strip("\n") for l in parameter_file.readlines()] pos = 0 for l in lines: if l.upper() == "CUSTOM_DICTIONARIES": break; else: pos = pos + 1 custom_dictionaries = [] for i in range(pos + 1, len(lines)): if len(lines[i]) > 0 and lines[i][0] != '#': custom_dictionaries.append(lines[i]) main.translate(samples, normalization, original, concepts, use_wordnet, use_wikipedia, disambiguation, All, custom_dictionaries, output)
def retriveText2(self): protien = self.plainTextEdit.toPlainText() translator = translate(protien) protien = translator.get_protien() protien = "\n-".join(protien) self.textEdit_2.setText(protien)
def clean(self): if (self.title is not None) and (self.titleru == ''): self.titleru = translate(self.title) if (self.body is not None) and (self.bodyru == ''): self.bodyru = translate(self.body)