def test_entity_ruler_fix8216(nlp, patterns, entity_ruler_factory):
    """Test that patterns don't get added excessively."""
    ruler = nlp.add_pipe(
        entity_ruler_factory, name="entity_ruler", config={"validate": True}
    )
    ruler.add_patterns(patterns)
    pattern_count = sum(len(mm) for mm in ruler.matcher._patterns.values())
    assert pattern_count > 0
    ruler.add_patterns([])
    after_count = sum(len(mm) for mm in ruler.matcher._patterns.values())
    assert after_count == pattern_count
Test that patterns don't get added excessively.
spacy/tests/pipeline/test_entity_ruler.py