def analyze(line, linenum, lang):
annotations = []
if lang is Language.en_EN or lang is None:
contractions = CONTRACTIONS_EN
elif lang is Language.de_DE:
contractions = CONTRACTIONS_DE
for pattern in contractions:
for match in re.finditer(pattern, line, flags=re.IGNORECASE):
if (not verify_match(match, line)) or (not matches_whole_words(match, line)):
continue
index = match.start()
replaced_contraction = re.sub(pattern, contractions[pattern], match.group(0), flags=re.IGNORECASE)
annotation = Contraction(linenum, line, index, word=match.group(0), contraction=replaced_contraction)
annotations.append(annotation)
return annotations
评论列表
文章目录