two new functions

Bug #763168 reported by --deleted--
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Lightproof
Invalid
Undecided
Unassigned

Bug Description

In order to translate more easily some rules from LT, I created two functions :

The first one (“morphex”) checks if one of the morphologies of a word matches the first pattern and if all morphologies do NOT match the second pattern. That’s useful to exclude some kinds of words.

The second function (“stemchk”) searches if the stem matches the pattern. The strict parameter, as in the modified “morph” function, defines if all the stems must match the pattern or only one of them.

# search and exclude morphologies
def morphex(rLoc, word, pattern, negpattern):
    global analyses
    if word == None:
        return False
    if word not in analyses:
        x = spellchecker.spell(u"<?xml?><query type='analyze'><word>" + word + "</word></query>", rLoc, ())
        if not x:
            return None
        t = x.getAlternatives()
        if not t:
            t = ['']
        analyses[word] = t[0].split("</a>")[:-1]
    a = analyses[word]
    # check negative condition
    np = re.compile(negpattern)
    for s in a:
        res = np.search(s)
        if res:
            return False
    # search pattern
    p = re.compile(pattern)
    for s in a:
        res = p.search(s)
        if res:
            return True
    return False

# check pattern on stems
def stemchk(rLoc, word, pattern, strict=True):
    global stems
    if word == None:
        return False
    if word not in stems:
        x = spellchecker.spell(u"<?xml?><query type='stem'><word>" + word + "</word></query>", rLoc, ())
        if not x:
            return False
        t = x.getAlternatives()
        if not t:
            t = ['']
        stems[word] = t
    a = stems[word]
    p = re.compile(pattern)
    if strict:
        for s in a:
            res = p.search(s)
            if not res:
                return False
        return True
    else:
        for s in a:
            res = p.search(s)
            if res:
                return True
        return False

Modify the first line of “prepare_for_eval” in Compile.py :
s = re.sub("(affix|spell|morph|morphex|stem|stemchk|option|suggest)\(", r'\1(rLoc,', s)

Revision history for this message
--deleted-- (trash-noreply) wrote :

Unsuitable.

Changed in lightproof:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.