def spellchecker(): if request.method == 'POST': print(request.form.keys(), file=sys.stderr) print(request.form['lang'], file=sys.stderr) lang = request.form['lang'] text = request.form['text'] if lang != "ta_IN": return json.dumps({ 'error': 'Language ' + lang + ' is not supported; only takes Tamil (code ta_IN))' }) lang = "TA" spell_checker = Speller(lang=lang, mode="web") result_dict = {'words': {}} for itr, word in enumerate(filter(len, re.split('\s+', text))): if word.find("<") >= 0: #HTML Tags, skip continue print("checking word %d" % itr, file=sys.stderr) ok, suggs = spell_checker.REST_interface(word) if not ok: result_dict['words'][word] = suggs return json.dumps(result_dict) else: return "RPC interface for TinyMCE Spell Checker!"
def spellchecker(): if request.method == "POST": print(request.form.keys(), file=sys.stderr) print(request.form["lang"], file=sys.stderr) lang = request.form["lang"] text = request.form["text"] if lang != "ta_IN": return json.dumps({ "error": "Language " + lang + " is not supported; only takes Tamil (code ta_IN))" }) lang = "TA" spell_checker = Speller(lang=lang, mode="web") result_dict = {"words": {}} for itr, word in enumerate(filter(len, re.split("\s+", text))): if word.find("<") >= 0: # HTML Tags, skip continue print("checking word %d" % itr, file=sys.stderr) try: ok, suggs = spell_checker.REST_interface(word) pprint.pprint(suggs) except Exception as ioe: ok = True pprint.pprint(ioe) if not ok: word = Speller.scrub_ws(word) result_dict["words"][word] = list(suggs) return json.dumps(result_dict) else: return "RPC interface for TinyMCE Spell Checker!"
def spell_check(request,k1): speller = Speller(lang=u"TA",mode="web") notok,suggs = speller.check_word_and_suggest( k1 ) json_string = json.dumps(suggs,ensure_ascii = False) #creating a Response object to set the content type and the encoding response = HttpResponse(json_string,content_type="application/json; charset=utf-8" ) return response
def spell_check(request, k1): speller = Speller(lang="TA", mode="web") notok, suggs = speller.check_word_and_suggest(k1) json_string = json.dumps(suggs, ensure_ascii=False) # creating a Response object to set the content type and the encoding response = HttpResponse(json_string, content_type="application/json; charset=utf-8") return response
class SpellTestTamil(unittest.TestCase): def setUp(self): self.speller = Speller(lang=u"TA", mode="web") def test_words_in_dictionary(self): # test if all the words are in the dictionary for w in [ u"சவால்", u"மகதம்", u"ஆரதம்", u"பல்லவன்", u"பாதம்", u"கவணம்", u"செயல்" ]: ok, _ = self.speller.check_word_and_suggest(w) self.assertTrue(ok, w) return def test_words_in_error(self): # test if the words in error are flagged # further test if suggestion contains the right word debug = False words_and_fixes = {u"எந்திர": u"எந்திரம்", u"செயல்பட": u"செயல்"} for w, right_word in words_and_fixes.items(): notok, suggs = self.speller.check_word_and_suggest(w) if (debug): pprint(notok) pprint(suggs) self.assertFalse(notok, w) self.assertTrue(right_word in suggs, u"%s -> (%s)" % (right_word, u", ".join(suggs))) return
class SpellTestTamil(unittest.TestCase): def setUp(self): self.speller = Speller(lang=u"TA",mode="web") def test_words_in_dictionary(self): # test if all the words are in the dictionary for w in [u"சவால்",u"மகதம்",u"ஆரதம்", u"பல்லவன்",u"பாதம்",u"கவணம்", u"செயல்"]: ok,_ = self.speller.check_word_and_suggest(w) self.assertTrue( ok, w ) return def test_words_in_error(self): # test if the words in error are flagged # further test if suggestion contains the right word debug = False words_and_fixes = { u"எந்திர" : u"எந்திரம்", u"செயல்பட":u"செயல்"} for w,right_word in words_and_fixes.items(): notok,suggs = self.speller.check_word_and_suggest( w ) if ( debug ): pprint(notok) pprint(suggs) self.assertFalse( notok, w ) self.assertTrue( right_word in suggs, u"%s -> (%s)"%(right_word,u", ".join(suggs) )) return
def spell(): if request.method == "GET": return render_template("spell.html", solution=False) if request.method != "POST": return "<B>404! Error</B>" if u'word' in request.form: word = request.form['word'] if not word: return "Enter word!" lang = "TA" if "lang" in request.form: lang = request.form["lang"] ok, suggs = Speller(lang=lang, mode="web").REST_interface(word) if ok: HTML = "<B style='color:green;'>OK!</B>" else: data_suggs = json.loads(suggs) data_suggs2 = u"<br/>\n".join([ u"<option>%d %s</option>" % (itr + 1, s_word) for itr, s_word in enumerate(data_suggs.values()[0]) ]) HTML = "<B style='color:red;'>Not OK!</B><br /><select>" + data_suggs2 + "\n</select><br/>" return render_template("spell.html", solution=True, HTML=HTML, word=word) return redirect(url_for('spell'))
def spellchecker(): if request.method == 'POST': print(request.form.keys(),file=sys.stderr) print(request.form['lang'],file=sys.stderr) lang = request.form['lang'] text = request.form['text'] if lang != "ta_IN": return json.dumps({'error':'Language '+lang+' is not supported; only takes Tamil (code ta_IN))'}) lang = "TA" spell_checker = Speller(lang=lang,mode="web") result_dict = {'words':{}} for itr,word in enumerate( filter(len,re.split('\s+',text)) ): if word.find("<") >= 0: #HTML Tags, skip continue print("checking word %d"%itr,file=sys.stderr) try: ok,suggs = spell_checker.REST_interface(word) pprint.pprint(suggs) except Exception as ioe: ok = True pprint.pprint(ioe) if not ok: word = Speller.scrub_ws(word) result_dict['words'][word] = suggs return json.dumps(result_dict) else: return "RPC interface for TinyMCE Spell Checker!"
def spell_get_only(): if u'word' in request.args: word = request.args['word'] if not word: return "Enter word!" lang="TA" if "lang" in request.args: lang = request.args["lang"] ok,suggs = Speller(lang=lang,mode="web").REST_interface(word) if ok: return "<B style='color:green;'>OK!</B>" data_suggs = suggs data_suggs2 = u"<br/>\n".join( [u"%d %s"%(itr+1,s_word) for itr,s_word in enumerate( data_suggs.values()[0])]) return "<B style='color:red;'>Not OK!</B><br />"+data_suggs2+"\n<br/>"+suggs return 'spell check with ?word=$word&lang=en'
# -*- coding: utf-8 -*- # (C) 2016-17 Muthiah Annamalai import codecs import os from pprint import pprint from opentamiltests import * from spell import Speller, LoadDictionary, OttruSplit, Mayangoli from tamil import utf8 TA_SPELLER = Speller(lang=u"TA", mode="web") class SpellTestFiles(unittest.TestCase): def setUp(self): self.speller = TA_SPELLER def test_file10(self): nwords = 31 npass = 13 nfail = 18 fail_n_suggs = dict() obj = { "total": nwords, "correct_words": npass, "wrong_words": nfail, "word_suggestions": fail_n_suggs, } filename = "data/doc10.spell" self._tester(filename, obj)
def test_basic(self): filename = os.path.join("data", "doc1.spell") sys.stdin.close() obj = Speller(filename, lang="ta") self.assertTrue(obj.in_tamil_mode())
def setUp(self): self.speller = Speller(lang=u"TA", mode="web")
def setUp(self): self.speller = Speller(lang=u"TA",mode="web")
def test_basic(self): filename = os.path.join("data","doc1.spell") sys.stdin.close() obj = Speller(filename,lang="ta") self.assertTrue(obj.in_tamil_mode())