def correct_grammatical_mistake(request): # if not verify_logged_in(request): # 未登录 # result = {} # result['code'] = 1 # response = HttpResponse(json.dumps(result, ensure_ascii=False)) # # return response data = simplejson.loads(request.body) text = data['gcSource'] parser = GingerIt() gc_res = parser.parse(text) #correct_res = client.rpc_correct(src=text) result = {} result['code'] = 0 result['data'] = {} result['data']['gcResult'] = gc_res["result"] #result['data']['gcResult'] = correct_res response = HttpResponse(json.dumps(result, ensure_ascii=False)) # response['Access-Control-Allow-Origin'] = '*' return response
def correct_sentences(sentences): parser = GingerIt() corrections = [] for s in sentences: feedback = parser.parse(s) corrections.append(feedback) return corrections
def test(self): text = 'The smelt of fliwers bring back memories.' parser = GingerIt() output = parser.parse(text) self.assertEqual(output.get("result"), "The smell of flowers brings back memories")
def gramarize(self, sent): f = open('Value-json/logic_activation.json') activation = json.load(f) if activation['grammar_logic'] == "active": test_str = sent splitter = SentenceSplitter(language='en') sente = splitter.split(text=test_str) gram_sent = [] for sent in sente: parser = GingerIt() output = parser.parse(sent) output_1 = (output.get("result")) output_1 = output_1 gram_sent.append(output_1) f_output = ' '.join(gram_sent) if f_output[-1] == '.' and f_output[-2] == '.': f_output = f_output[:-2] f_output = f_output + '.' f_output = self.remove_trailing_dots(f_output) f_output = f_output.replace('..', '.') return f_output else: return sent
def output(): text2 = text.get("1.0", "end-1c") parser = GingerIt() output1 = parser.parse(text2) text3 = tk.Text(root, width=40, height=30) text3.place(x=500, y=50) text3.insert(tk.END, output1.get("result"))
def sent_correct(): print("1231") if request.method == 'POST': text = request.form["SENT"] parser = GingerIt() print(parser.parse(text)['corrections']) result=parser.parse(text)['result'] return render_template('index.html', output1=result)
def check(filename): f = word(filename, 'sentence') corrections = 0 for s in f: g = GingerIt() h = g.parse(s) corrections += len(h['corrections']) return [corrections]
def test(self): j = 0 text = "".join([int_to_vocab[i] for i in noise_maker(good_sentences[j], 0.99)]) + " " parser = GingerIt() output = parser.parse(text) self.assertEqual( output.get("result"), "".join([int_to_vocab[i] for i in good_sentences[j]]) )
def test(self): text = 'The smelt of fliwers bring back memories.' parser = GingerIt() output = parser.parse(text) self.assertEqual( output.get("result"), "The smell of flowers brings back memories" )
def check(mail): f = word(mail, 'sentence') corrections = 0 for s in f: g = GingerIt() h = g.parse(s) corrections += len(h['corrections']) return corrections
def callginger(self): for i in range(self.n): Ginger = GingerIt() if len(self.line[i])>0: parastyle = self.doc.paragraphs[i].style paraalign = self.doc.paragraphs[i].alignment parabold=self.doc.paragraphs[i].runs[0].bold paraitalic = self.doc.paragraphs[i].runs[0].italic paraunderline = self.doc.paragraphs[i].runs[0].underline parafont=self.doc.paragraphs[i].runs[0].text gin_dic = Ginger.parse(self.line[i]) gin_dic["corrections"]=gin_dic["corrections"][::-1] #Reversing dictionary if len(gin_dic["corrections"]) > 0: if gin_dic["corrections"][0]["start"] == 0: paraObj = self.docf.add_paragraph("") else: paraObj = self.docf.add_paragraph(self.doc.paragraphs[i].text[0: gin_dic["corrections"][0]["start"]]) for j in range(len(gin_dic["corrections"])): index = gin_dic["corrections"][j]["start"] word = gin_dic["corrections"][j]["correct"] run = paraObj.add_run(gin_dic["result"][index: index + len(word)]) run.font.color.rgb = RGBColor(0, 100, 0) if j!=len(gin_dic["corrections"])-1: paraObj.add_run(gin_dic["result"][index + len(word) : gin_dic["corrections"][j + 1]["start"]]) else: run = paraObj.add_run(gin_dic["result"][index + len(word) ::]) else: paraObj = self.docf.add_paragraph(self.doc.paragraphs[i].text) #Formatting done here paraObj.style = parastyle paraObj.alignment=paraalign for run in paraObj.runs: run.font.bold = parabold run.font.italic = paraitalic run.font.underline = paraunderline else: self.docf.add_paragraph("")
def text_grammar_check(text): # initialize parser = GingerIt() corrected_text_string = '' corrected_words_string = '' changes_count = 0 formatter_words = 'At sentence {} word {}, the "{}" is replaced by "{}".<br>' header_string = '{} change(s) are made to original text. <br><br> The changed text is:<br><br>' try: # sentences tokenization sentence_blob = TextBlob(text) sentences_count = 1 for cur_sentence in sentence_blob.sentences: # parse text parsed = parser.parse(str(cur_sentence)) parsed_text = parsed['result'] parsed_corrections = parsed['corrections'] parsed_corrections = parsed_corrections[::-1] # words in original sentence blob = TextBlob(text) original_words = [i for i in blob.words] # changed words corrected_words = [] original_text = [] for item in parsed_corrections: original_text.append(item['text']) corrected_words.append(item['correct']) changed_index = [] for i in original_text: changed_index.append(original_words.index(i)) # string result corrected_text_string += parsed_text for i in range(len(corrected_words)): corrected_words_string += formatter_words.format( sentences_count, i + 1, original_text[i], corrected_words[i]) changes_count += 1 sentences_count += 1 # output string corrected_text_string += '<br><br>' output_string = header_string.format( changes_count) + corrected_text_string + corrected_words_string except: return "Sorry, the function can't handle the text. Please try another one." return Markup(output_string)
def correction(request): overlay = False api_key = '6a8ff7d36d88957' language = 'eng' if request.method == 'POST': myfile = request.FILES['image'] fs = FileSystemStorage() filename = fs.save(myfile.name, myfile) #filename="C:/Users/maitr/Desktop/django-upload-example-master/django-upload-example-master/"+uploaded_file #filename=type(filename) #print(uploaded_file) payload = { 'isOverlayRequired': overlay, 'apikey': api_key, 'language': language, } with open(filename, 'rb') as f: r = requests.post( 'https://api.ocr.space/parse/image', files={filename: f}, data=payload, ) output = r.content.decode() ini_string = json.dumps(output) final_dictionary = json.loads(ini_string) bad_chars = ['\\r'] chg = ['\\n'] if 'ParsedText' in final_dictionary: final_dictionary = final_dictionary[ final_dictionary.index('ParsedText') + 12:final_dictionary.index('ErrorMessage') - 2] for i in bad_chars: final_dictionary = final_dictionary.replace(i, ' ') for i in chg: final = final_dictionary.replace(i, ' \n') words = [] parser = GingerIt() words = parser.parse(final) #'content':final, return render(request, 'correction.html', { 'content': final, 'word': words }) return render(request, 'correction.html')
def correct_sentence(text): """Applica le correzioni del correttore gingerit alla stringa text Args: text: stringa da correggere Returns: my_new_text: stringa corretta """ text = text.replace("\n", " ").replace("\t", "").replace(" ", " ").replace(" ", " ") parser = GingerIt() my_new_text = parser.parse(text)["result"] return my_new_text
def FilterTweet(tweet): try: if tweet == '': return False if (detect(tweet) != 'en'): return False ginger_parser = GingerIt() ginger_grammar_results = ginger_parser.parse(tweet) ginger_corrections = ginger_grammar_results['corrections'] if len(ginger_corrections) >= 5: return False return True except: return False
async def gramme(event): if Redis("AUTOCORRECT") != "True": return t = event.text tt = tr.translate(t) if t.startswith((HNDLR, ".", "?", "#", "_", "*", "'", "@", "[", "(", "+")): return if t.endswith(".."): return if tt.src != "en": return xx = GingerIt() x = xx.parse(t) res = x["result"] await event.edit(res)
def correct_string(self): text = self.input_textEdit.toPlainText() #self.input_textEdit.clear() text = text + " " #added because wasnt parsing till the end text_compare = text parser = GingerIt() a = parser.parse(text) #stored in a dictionary #print(a) if a["result"][0] == " ": self.output_textEdit.setText(a["result"][1:]) else: self.output_textEdit.setText(a["result"]) '''if a["result"][0]==" ":
def checker_model_messages(id): all_data = Messages.query.get(id) text_message_unknown = all_data.message_unknown parser = GingerIt() results_dictionary = parser.parse(text_message_unknown) all_data.message_unknown = results_dictionary['result'] db.session.commit() flash("Row {} has been corrected successfully!".format(all_data.id), "success") return redirect(url_for('table'))
async def gramme(event): if not udB.get_key("AUTOCORRECT"): return t = event.text if t[0] == HNDLR or t[0].lower( ) not in string.ascii_lowercase or t.endswith(".."): return tt = google_translator().detect(t) if tt[0] != "en": return xx = GingerIt() x = xx.parse(t) res = x["result"] try: await event.edit(res) except BaseException: pass
def gramarize(self, sent): anti_grammar_words = [] file = open('Value-json/anti_grammar.txt') for lines in file.read().splitlines(): lines = lines.rstrip() lines = lines.lstrip() anti_grammar_words.append(lines) f = open('Value-json/logic_activation.json') activation = json.load(f) if activation['grammar_logic'] == "active": test_str = sent splitter = SentenceSplitter(language='en') sente = splitter.split(text=test_str) gram_sent = [] for sent in sente: parser = GingerIt() ani = False for ani_words in anti_grammar_words: if ani_words in sent: ani = True break else: continue if ani == False: output = parser.parse(sent) output_1 = (output.get("result")) output_1 = output_1 else: output_1 = sent gram_sent.append(output_1) f_output = ' '.join(gram_sent) f_output = f_output + '.' f_output = self.remove_trailing_dots(f_output) f_output = f_output.replace('..', '.') return f_output else: return sent
async def gramme(event): if Redis("AUTOCORRECT") != "True": return t = event.text if t.startswith((HNDLR, ".", "?", "#", "_", "*", "'", "@", "[", "(", "+")): return if t.endswith(".."): return tt = google_translator().detect(t) if tt[0] != "en": return xx = GingerIt() x = xx.parse(t) res = x["result"] try: await event.edit(res) except BaseException: pass
def start(self, text): ret = [] result = GingerIt().parse(text) for correction in result.get('corrections'): if len(result.get('corrections')) > 0: self.start_positions.append(correction.get('start')) self.end_positions.append( correction.get('start') + len(correction.get('text')) - 1) self.my_mistakes.append(correction.get('text')) self.my_corrections.append(correction.get('correct')) ret = { "mistakes": self.my_mistakes, "corrections": self.my_corrections, "start_posititons": self.start_positions, "end_position": self.end_positions } return len(result.get('corrections')), ret
def text_score(text): # initialize parser = GingerIt() grammar_count = 0 spelling_count = 0 grammar_string = 'Grammar error: ' spelling_string = 'Spelling error: ' # check error try: # sentences tokenization sentence_blob = TextBlob(text) for cur_sentence in sentence_blob.sentences: # spelling error for cur_word in cur_sentence.words: corrected = cur_word.correct() if corrected != cur_word: spelling_string += str(cur_word) + ', ' spelling_count += 1 cur_sentence = cur_sentence.correct() # grammar error parsed = parser.parse(str(cur_sentence)) grammar_count += len(parsed['corrections']) for item in parsed['corrections']: grammar_string += item['text'] + ', ' except: return "Please try another text." # calculate score the_score = 100 - 3 * grammar_count - 3 * spelling_count if the_score < 0: the_score = 0 # return string return_string_formatter = "The score of the text is {}.<br>(Each grammar error: -3, Each spelling error: -3))<br><br>" return_string_formatter += grammar_string + '<br>' + spelling_string return_string = return_string_formatter.format(the_score) return Markup(return_string)
def check(filename_or_text): try: if filename_or_text.rsplit('.', 1)[1].lower() in extensions: text = picture(filename_or_text) p = GingerIt() q = p.parse(text) return len(q['corrections']) else: text = txt(filename_or_text) g = GingerIt() h = g.parse(text) return len(h['corrections']) except IndexError: text = txt(filename_or_text) g = GingerIt() h = g.parse(text) return len(h['corrections'])
def text_checking_with_index(text, i): result = GingerIt().parse(text) if len(result['corrections']) == 0: print("Statement {} is correct".format(i)) return 0 correct_text = result['result'] original_text = result['text'] print("The line number {} is incorrect.".format(i)) print("\nOriginal Text :{}".format(original_text)) print("\nCorrected Text: {}\n".format(correct_text))
def text_checking(text): result = GingerIt().parse(text) if len(result['corrections']) == 0: print("Statement is correct") return 0 correct_text = result['result'] original_text = result['text'] print("The text is incorrect.") print("\nOriginal Text :{}".format(original_text)) print("\nCorrected Text: {}\n".format(correct_text))
def __tweet_filters(self,tweet): #Boolean filter for outputs from generated tweets parser = GingerIt() grammatical = False while tweet[-1] == "'": tweet = tweet[:-1] try: parsed = parser.parse(tweet) if "corrections" in parsed: grammatical = (len(parser.parse(tweet)["corrections"]) < 2) except Exception as e: pass lenght = (len(tweet) < 160) is_new = (not self.__is_prev(tweet)) is_acceptable = (not self.__is_bad(tweet)) return (grammatical and lenght and is_new and is_acceptable)
def btnAdd(): sentence = " ".join(str(inputText.get()).split()) #removes extra spaces result = GingerIt().parse(sentence) #corrects grammar and spellings sentence = str(result['result']).lower() #convert to corpus format textpredmarkov.update_corpus(sentence) historylines.append(sentence) sentences = "" if (len(historylines) <= 3): sentences = "\n".join(historylines[-3:]) else: sentences = ":\n" + "\n".join(historylines[-2:]) historyText.set(sentences) inputText.set("")
def useInSentence(secretWord): ''' secretWor: list, word + data Starts up an interactive module of using word in sentence. * At the start of the game, let the user know the secret word. * Ask the user to supply one grammatically sentence containing the secret word. * The user should receive feedback immediately whether their sentence is correct. ''' # 'exiguous', 'scanty; meager; small; slender', 'adjective', '19', '51-Few English speakers likely know this word', 'Late Latin' word = secretWord[0] meaning = secretWord[1] usage = secretWord[2] points = secretWord[3] difficulty = secretWord[4] origin = secretWord[5] print "Welcome to the use in a sentence module!" print "Use the following word in a sentence: " + word print "The meaning of " + word + " is: " + meaning print "It is generally used as (a/an): " + usage print "Points assigned: " + points print "Difficulty: " + difficulty print "Origin: " + origin sentence = raw_input("Sentence containing the above mentioned word: ") if word not in sentence.split(' '): print "You have not used %s in the sentence. Please check if the spelling and form used is correct!" % (word) else: parser = GingerIt() op = parser.parse(sentence) if not op['corrections']: print "Your sentence is correct!" else: print "The correct sentence should be: " + op['result'] + sentence[-1]
def btnAdd(): sentence = " ".join(str(inputText.get()).split()) #removes extra spaces result = GingerIt().parse(sentence) sentence = str(result['result']).lower() textpredmarkov.update_corpus(sentence) #adds the corrected sentence to the corpus historylines.append(sentence) sentences = "" if(len(historylines) <= 3): sentences = "\n".join(historylines[-3:]) else: sentences = ":\n"+"\n".join(historylines[-2:]) historyText.set(sentences) inputText.set("")
def spell_checker(sentence): sentence = "a brief history of apache hadoop hadoop wa sstarted at yahool to provide a data processing infrastructure to the apache nutch web search engine the project wa sstarted by doug cutting and michael j cafarella in 2005 the name hadoop came from cutting given his toy elephant the name hadoops d a portion o fthe technica linspiration came from the google file system gfs and a 2004 google paper on the mapreduce algorithm yahool began embracing hadoop in 2006 and by 2008 the yahoo search index was being generated by hadoop one key design decision was to use lowcost commodity servers for both computing and storage indeed one of the important principles of early hadoop mapreduce process ing was the capability to move the computation to the datals becaus elt was faster than moving data from scrve rto server the design also required that hadoop software be scalable handle large amount sao fdata and tolerate hardwar efailures s the hadoo pdesign also sacrifices some efficiency 1n favor of massiv escalability at a small scale hadoop ma ypresen tan inefficient approach for some problems other tools may in fact provide better performanc e1n these cases as the problem or data set scales co massive proportions however hadoop begin sto sho wits ability to handle problem so fsizes that are impossible to manage on other systems some dreas where hadoo pis used include the following whos eson had e social media retail web commerce financial services web search government s research and development many others sa some prominen tusers include the following yahool facebook amazon ebay american airlines the new york times" print(len(sentence)) if (len(sentence) > 500): corrected_sentence = "" i = 0 j = 500 while (j <= len(sentence)): parser = GingerIt() corrected_sentence += parser.parse(sentence[i:j])['result'] i = j j = (j + 500, len(sentence))[j + 500 <= len(sentence)] else: parser = GingerIt() corrected_sentence = parser.parse(sentence)['result'] print("GingerIT():::\n", corrected_sentence) return corrected_sentence
from nltk.sentiment.vader import SentimentIntensityAnalyzer from gingerit.gingerit import GingerIt import json sid = SentimentIntensityAnalyzer() parser = GingerIt() def analyse_text(message_text): # Calling the polarity_scores method on sid and passing in the message_text outputs a dictionary with negative, neutral, positive, and compound scores for the input text scores = sid.polarity_scores(message_text) return json.dumps(scores) def text_checker(text): return parser.parse(text) # print(analyse_text('we have a good response for facial recognition'));