コード例 #1
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}!"
コード例 #2
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!"
コード例 #3
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}!"
コード例 #4
0
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!"