def test_apply_correction_insert_word(): text = AnnotatedText("{=>Hello} {word=>World}!") ann = text.get_annotations()[0] # {=>Hello} text.apply_correction(ann) assert text.get_annotated_text() == "Hello {word=>World}!"
def test_to_str(self): text = AnnotatedText("helo world") text.annotate(0, 4, ["hello", "hola"], meta={"key": "value with spaces"}) expected = "{helo=>hello|hola:::key=value with spaces} world" assert text.get_annotated_text() == expected
def test_apply_correction_with_no_suggestions(): # Given annotated text text = AnnotatedText("Hi {sdf=>NO_SUGGESTIONS}!") # When applyinng a no-suggestions annotation ann = text.get_annotations()[0] text.apply_correction(ann) # Then the annotation should be replaced with the original text assert text.get_annotated_text() == "Hi sdf!"
def test_apply_correction(): # Given annotated text text = AnnotatedText("{helo=>Hello}{...=>,} {word=>World}!") # When applying the corrected text of an annotation ann = text.get_annotations()[1] # {...=>,} text.apply_correction(ann) # Then annotation should be removed, and the correct text used instead assert text.get_annotated_text() == "{helo=>Hello}, {word=>World}!"
def test_annotate_with_none(self): # Some checks return None in place of suggestions, meaning # that there are no good suggestions. # The convention for those in the light-annotated format is # {bad=>NO_SUGGESTIONS} annotation. text = AnnotatedText("asdasd") text.annotate(0, len("asdasd"), correct_value=None) assert text.get_annotated_text() == "{asdasd=>NO_SUGGESTIONS}" # When parsed, special value of "NO_SUGGESTIONS" should be # represented as empty suggestions list assert text.get_annotations()[0].suggestions == []
def test_iter_annotations(): # Given annotated text text = AnnotatedText("{helo=>Hello}{...=>,} {word=>World}!") # When changing annotations during annotations iteration for i, ann in enumerate(text.iter_annotations()): if i == 1: text.remove(ann) # {...=>,} else: text.apply_correction(ann) # Then the text should be correctly updated assert text.get_annotated_text() == "Hello... World!"
def test_remove(): # Given annotated text text = AnnotatedText("{helo=>Hello} {word=>World}!") # When removing single annotation annotation = text.get_annotations()[1] assert annotation.source_text == "word" text.remove(annotation) # Then all other annotations should stay expected = "{helo=>Hello} word!" assert text.get_annotated_text() == expected assert len(text.get_annotations()) == 1
def test_get_annotated_text_same_span(): text = AnnotatedText("{=>b}{=>a}") assert text.get_annotated_text() == "{=>b}{=>a}"
def test_get_annotated_text_with_highlight(): text = AnnotatedText("{helo=>NO_SUGGESTIONS} world!") expected = "{helo=>NO_SUGGESTIONS} world!" assert text.get_annotated_text() == expected