def test_condition_annotation(self): ant = ConditionAnnotation(coords=(1, 41), condition='in case of', pre='murder', post='dial "M"') self.assertEqual('en', ant.locale) s = ant.__repr__() self.assertGreater(len(s), 0) cite = ant.get_cite() self.assertEqual('/en/condition/in case of/murder/dial "M"', cite)
def get_condition_annotations(text: str, strict=True) \ -> Generator[ConditionAnnotation, None, None]: """ Find possible conditions in natural language. :param text: :param strict: :return: """ # Iterate through all potential matches for sentence in get_sentence_list(text): for match in RE_CONDITION.finditer(sentence): # Get individual group matches captures = match.capturesdict() num_pre = len(captures["pre"]) num_post = len(captures["post"]) # Skip if strict and empty pre/post if strict and (num_pre == 0 or num_post == 0): continue ant = ConditionAnnotation( coords=match.span(), condition=captures["condition"].pop().lower(), pre=captures["pre"].pop(), post=captures["post"].pop()) yield ant