From fc9a4fe8278d11f8078be991fa11c090910bb473 Mon Sep 17 00:00:00 2001 From: Ines Montani Date: Fri, 7 Aug 2020 14:43:55 +0200 Subject: [PATCH] Update attribute ruler --- spacy/pipeline/attributeruler.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/spacy/pipeline/attributeruler.py b/spacy/pipeline/attributeruler.py index 42a505025..aba76664c 100644 --- a/spacy/pipeline/attributeruler.py +++ b/spacy/pipeline/attributeruler.py @@ -17,13 +17,18 @@ MatcherPatternType = List[Dict[Union[int, str], Any]] AttributeRulerPatternType = Dict[str, Union[MatcherPatternType, Dict, int]] -@Language.factory("attribute_ruler") +@Language.factory( + "attribute_ruler", default_config={"pattern_dicts": None, "validate": False} +) def make_attribute_ruler( nlp: Language, name: str, - pattern_dicts: Optional[Iterable[AttributeRulerPatternType]] = None, + pattern_dicts: Optional[Iterable[AttributeRulerPatternType]], + validate: bool, ): - return AttributeRuler(nlp.vocab, name, pattern_dicts=pattern_dicts) + return AttributeRuler( + nlp.vocab, name, pattern_dicts=pattern_dicts, validate=validate + ) class AttributeRuler(Pipe): @@ -39,6 +44,7 @@ class AttributeRuler(Pipe): name: str = "attribute_ruler", *, pattern_dicts: Optional[Iterable[AttributeRulerPatternType]] = None, + validate: bool = False, ) -> None: """Initialize the AttributeRuler. @@ -54,7 +60,7 @@ class AttributeRuler(Pipe): """ self.name = name self.vocab = vocab - self.matcher = Matcher(self.vocab) + self.matcher = Matcher(self.vocab, validate=validate) self.attrs = [] self._attrs_unnormed = [] # store for reference self.indices = []