I am trying to implement a python grammar checker on web2py. I  already 
have the part of the code that needs modification. What I need is a code 
that can highlight text on the searched words that need replacing by 
showing a drop down list of better suggestions when you point at it. The 
code should highlight text with a different color and warn the user before 
the replacement is made like what microsoft word does. My code on the 
terminal does not do that at all. It just changes the words without warning 
the user which can be risky. I will share with you the part of the code 
that needs modification. Please help!

Please tell me the parts that need modification or changing:

class WordReplacer(object):
            def __init__(self, word_map):
                self.word_map = word_map
    
            def replace(self, word):
                return self.word_map.get(word, word)


class CsvWordReplacer(WordReplacer):
            def __init__(self, fname):
                word_map = {}
                for line in csv.reader(open(fname)):
                    word, syn = line
                    word_map[word] = syn
                super(CsvWordReplacer, self).__init__(word_map)


class YamlWordReplacer(WordReplacer):
            def __init__(self, fname):
                word_map = yaml.load(open(fname))
                super(YamlWordReplacer, self).__init__(word_map)



class AntonymReplacer(object):
            def replace(self, word, pos=None):
                antonyms = set()
                for syn in wordnet.synset(word, pos=pos):
                    for lemma in syn.lemmas:
                        for antonym in lemma.antonyms():
                            antonyms.add(antonym.name)
                if len(antonyms) == 1:
                    return antonyms.pop()

                else:
                    return None


            def replace_negations(self, sent):
                i, l = 0, len(sent)
                words = []
                while i < l:
                    word = sent[i]
                    if word == 'not' and i+1 < l:
                        ant = self.replace(sent[i+1])
                        if ant:
                            words.append(ant)
                            i += 2
                            continue
                        words.append(word)
                        i += 1
                    return words


class AntonymWordReplacer(WordReplacer, AntonymReplacer):
        pass

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to