Пример #1
0
    def test_parse_colon(self):
        text = AnnotatedText("text {.=>::::key=R:PUNCT}")

        expected = AnnotatedText("text .")
        expected.annotate(5, 6, ":", meta={"key": "R:PUNCT"})

        ann = text.get_annotations()[0]
        expected_ann = expected.get_annotations()[0]
        assert ann.meta == expected_ann.meta
        assert ann.suggestions == expected_ann.suggestions
        assert ann.source_text == expected_ann.source_text
Пример #2
0
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
Пример #3
0
    def test_parse_no_suggestions(self):
        # When parsing text with the special "NO_SUGGESTIONS" value
        text = AnnotatedText("{asdasd=>NO_SUGGESTIONS}")

        # Then empty suggestions list should be returned
        ann = text.get_annotations()[0]
        assert ann.suggestions == []
Пример #4
0
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}!"
Пример #5
0
def test_get_annoation_at():
    text = AnnotatedText("Hello {word=>world}")
    print(text.get_annotations())
    assert text.get_annotation_at(0) is None
    assert text.get_annotation_at(0, 100) is None
    assert text.get_annotation_at(6, 10).source_text == "word"
    assert text.get_annotation_at(6).source_text == "word"
    assert text.get_annotation_at(7).source_text == "word"
    assert text.get_annotation_at(10) is None
    assert text.get_annotation_at(11) is None
Пример #6
0
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!"
Пример #7
0
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}!"
Пример #8
0
def test_remove_non_existing_annotation():
    # Given annotated text
    text = AnnotatedText("{helo=>Hello} {word=>World}!")

    # When removing annotation that doesn't exists in the text
    # Then error should be raised
    annotation = text.get_annotations()[0]
    text.remove(annotation)
    with pytest.raises(ValueError):
        text.remove(annotation)
Пример #9
0
    def test_parse(self):
        text = AnnotatedText(
            "Hello {wold=>World|world:::type=OOV Spell:::status=ok}")

        expected_original = "wold"
        expected_sugg = ["World", "world"]
        expected_meta = {"type": "OOV Spell", "status": "ok"}

        ann = text.get_annotations()[0]
        assert ann.meta == expected_meta
        assert ann.suggestions == expected_sugg
        assert ann.source_text == expected_original
Пример #10
0
    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 == []
Пример #11
0
def test_get_annotations():
    text = AnnotatedText(
        "this {was=>is|will be} an {anotated=>annotated} text")
    anns = text.get_annotations()
    assert len(anns) == 2
    assert anns[0].source_text == "was"
    assert anns[0].suggestions == ["is", "will be"]
    assert anns[0].start == len("this ")
    assert anns[0].end == len("this was")

    assert anns[1].source_text == "anotated"
    assert anns[1].suggestions == ["annotated"]
    assert anns[1].start == len("this was an ")
    assert anns[1].end == len("this was an anotated")