diff --git a/spacy/matcher.pyx b/spacy/matcher.pyx index 46a40903b..b9afe48c1 100644 --- a/spacy/matcher.pyx +++ b/spacy/matcher.pyx @@ -268,7 +268,7 @@ cdef class Matcher: return key in self._patterns def get(self, key, default=None): - """Retrieve the pattern stored for an entity. + """Retrieve the pattern stored for a key. key (unicode or int): The key to retrieve. RETURNS (tuple): The rule, as an (on_match, patterns) tuple. diff --git a/website/docs/api/matcher.jade b/website/docs/api/matcher.jade index 63c1f9a1e..00d2a626d 100644 --- a/website/docs/api/matcher.jade +++ b/website/docs/api/matcher.jade @@ -8,10 +8,10 @@ p Match sequences of tokens, based on pattern rules. | As of spaCy 2.0, #[code Matcher.add_pattern] and #[code Matcher.add_entity] | are deprecated and have been replaced with a simpler | #[+api("matcher#add") #[code Matcher.add]] that lets you add a list of - | patterns and a callback for a given match ID. + | patterns and a callback for a given match ID. #[code Matcher.get_entity] + | is now called #[+api("matcher#get") #[code matcher.get]]. | #[code Matcher.load] (not useful, as it didn't allow specifying callbacks), - | #[code Matcher.has_entity] and #[code Matcher.get_entity] (now redundant) - | have been removed. + | and #[code Matcher.has_entity] (now redundant) have been removed. +h(2, "init") Matcher.__init__ +tag method @@ -218,3 +218,28 @@ p +cell #[code key] +cell unicode +cell The ID of the match rule. + ++h(2, "get") Matcher.get + +tag method + +p + | Retrieve the pattern stored for a key. Returns the rule as an + | #[code (on_match, patterns)] tuple containing the callback and available + | patterns. + ++aside-code("Example"). + pattern = [{ORTH: 'test'}] + matcher.add('Rule', None, pattern) + (on_match, patterns) = matcher.get('Rule') + assert patterns = [pattern] + ++table(["Name", "Type", "Description"]) + +row + +cell #[code key] + +cell unicode + +cell The ID of the match rule. + + +footrow + +cell returns + +cell tuple + +cell The rule, as an #[code (on_match, patterns)] tuple. diff --git a/website/docs/usage/v2.jade b/website/docs/usage/v2.jade index 05a90a84e..8faae9d32 100644 --- a/website/docs/usage/v2.jade +++ b/website/docs/usage/v2.jade @@ -98,6 +98,8 @@ p matcher.add('HelloWorld', on_match=None, [{LOWER: 'hello'}, {IS_PUNCT: True}, {LOWER: 'world'}], [{LOWER: 'hello'}, {LOWER: 'world'}]) + assert len(matcher) == 1 + assert 'HelloWorld' in matcher p | Patterns can now be added to the matcher by calling @@ -197,12 +199,12 @@ p +cell #[+api("matcher#add") #[code Matcher.add]] +row - +cell #[code Matcher.has_entity] - +cell #[+api("matcher#contains") #[code Matcher.__contains__]] + +cell #[code Matcher.get_entity] + +cell #[+api("matcher#get") #[code Matcher.get]] +row - +cell #[code Matcher.get_entity] - +cell - + +cell #[code Matcher.has_entity] + +cell #[+api("matcher#contains") #[code Matcher.__contains__]] +row +cell #[code Doc.read_bytes]