Example #1
0
def test_subhamming():
    assert subhamming('hello there sir', 'hallo') == (1, 0)
    assert subhamming('hello there sir', 'halti') == (3, 0)
    assert subhamming('hello there sir', 'e') == (0, 1)
    assert subhamming('hello there sir', '') == (15, 0)
    assert subhamming('hello there sir', 'there') == (0, 6)
    assert subhamming('hello there sir', 'sir') == (0, 12)
    with pytest.raises(ValueError):
        subhamming('hello', 'hello there dear sir')
Example #2
0
    def _distance_start(self, source, durl):
        """Get a `(distance, start)` tuple indicating the minimal distance
        between `source` and `durl`, and the position of `source`'s substring
        that achieves that minimum.

        This is in fact an alias for what the model considers to be valid
        transformations and how to define them, but provides proper
        encapsulation of concerns.

        """

        # We allow for substrings.
        # Note here that there can be a difference in lemmas without
        # there being a difference in tokens, because of fluctuations
        # in lemmatization. This is caught later on in the validation
        # of substitutions (see SubstitutionValidatorMixin.validate()),
        # instead of making this function more complicated.
        return subhamming(source.lemmas, durl.quote.lemmas)