def createAnnotations(parts,patterns): types = {} ok = True for i in range(len(patterns)): if patterns[i][1] in ["$","@"] and not parts[0] == "": oneORmore = 1 l = len(patterns[i].strip()) - 2 if patterns[i][l+1] == "]": oneORmore = 0 l += 1 pat = patterns[i].strip() pat = pat[2:l] if patterns[i][1] == "@": #print pat if pat.find("_") > -1: pat = pat[:len(pat)-2] pats = initPattern() res = findPattern(parts[i].strip(),pats,pat) types[i] = res else: #print pat,i, parts[i] if pat.find("|") > -1: annotations = annotateOR(parts[i].strip(),pat,oneORmore) #print annotations if len(annotations) == 0: ok = False types[i] = annotations else: if pat[len(pat)-2] == "_": pat = pat[:len(pat)-2] try: #print pat #print parts[i].strip() trie = getTrie(pat) annotations = pyannotate.annotate(parts[i].strip(),trie,oneORmore) #print "createAnnotations",annotations if len(annotations) == 0: ok = False #print annotations types[i] = annotations except: #print "No " + pat + " class found" return False,None return ok,types
def annotateOR(part,pat,oneORmore): #print part annotations = [] pats = pat.split("|") for p in pats: if p[0] in ["$","@"]: p = p[1:] #print p try: trie = getTrie(p) annotations += pyannotate.annotate(part,trie,oneORmore) except: #print "No " + p + " class found" return False,None return annotations