예제 #1
0
 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
예제 #2
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
예제 #3
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 == []
예제 #4
0
def test_eq_2():
    t1 = AnnotatedText("hello word")
    t2 = AnnotatedText("hello word")
    t1.annotate(0, 5, "Hello")
    t1.annotate(6, 10, "world")
    t2.annotate(6, 10, "world")
    t2.annotate(0, 5, "Hello")
    assert t1 == t2
예제 #5
0
 def test_error(self):
     text = AnnotatedText("{helllo=>Hello} {world=>World}")
     with pytest.raises(OverlapError):
         text.annotate(2, 5, "ll")
예제 #6
0
 def test_annotate_empty_lengthy_intersect(self):
     text = AnnotatedText("Did n't know it.")
     text.annotate(12, 12, [" about"])
     with pytest.raises(OverlapError):
         text.annotate(0, len("Did n't know it."), ["Did n't know it"])
예제 #7
0
 def test_forbid_joining_annotation_with_multiple_suggestions(self):
     text = AnnotatedText("helloworld")
     text.annotate(0, len("helloworld"), ["hello", "hola", "hi"])
     with pytest.raises(OverlapError):
         text.annotate(0, len("helloworld"), "world")