mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 01:16:28 +03:00
Update attribute ruler
This commit is contained in:
parent
a8404c3517
commit
fc9a4fe827
|
@ -17,13 +17,18 @@ MatcherPatternType = List[Dict[Union[int, str], Any]]
|
||||||
AttributeRulerPatternType = Dict[str, Union[MatcherPatternType, Dict, int]]
|
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(
|
def make_attribute_ruler(
|
||||||
nlp: Language,
|
nlp: Language,
|
||||||
name: str,
|
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):
|
class AttributeRuler(Pipe):
|
||||||
|
@ -39,6 +44,7 @@ class AttributeRuler(Pipe):
|
||||||
name: str = "attribute_ruler",
|
name: str = "attribute_ruler",
|
||||||
*,
|
*,
|
||||||
pattern_dicts: Optional[Iterable[AttributeRulerPatternType]] = None,
|
pattern_dicts: Optional[Iterable[AttributeRulerPatternType]] = None,
|
||||||
|
validate: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the AttributeRuler.
|
"""Initialize the AttributeRuler.
|
||||||
|
|
||||||
|
@ -54,7 +60,7 @@ class AttributeRuler(Pipe):
|
||||||
"""
|
"""
|
||||||
self.name = name
|
self.name = name
|
||||||
self.vocab = vocab
|
self.vocab = vocab
|
||||||
self.matcher = Matcher(self.vocab)
|
self.matcher = Matcher(self.vocab, validate=validate)
|
||||||
self.attrs = []
|
self.attrs = []
|
||||||
self._attrs_unnormed = [] # store for reference
|
self._attrs_unnormed = [] # store for reference
|
||||||
self.indices = []
|
self.indices = []
|
||||||
|
|
Loading…
Reference in New Issue
Block a user