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!"
Beispiel #2
0
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!"
Beispiel #3
0
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!"