From aad66d9bb9ff0060085f61cd096885bbded77381 Mon Sep 17 00:00:00 2001 From: Ines Montani Date: Fri, 27 Sep 2019 16:34:53 +0200 Subject: [PATCH] Document PhraseMatcher.remove [ci skip] --- spacy/matcher/phrasematcher.pyx | 2 ++ website/docs/api/phrasematcher.md | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/spacy/matcher/phrasematcher.pyx b/spacy/matcher/phrasematcher.pyx index a93c34288..ce7cbbf9f 100644 --- a/spacy/matcher/phrasematcher.pyx +++ b/spacy/matcher/phrasematcher.pyx @@ -87,6 +87,8 @@ cdef class PhraseMatcher: the key does not exist. key (unicode): The match ID. + + DOCS: https://spacy.io/api/phrasematcher#remove """ if key not in self._docs: raise KeyError(key) diff --git a/website/docs/api/phrasematcher.md b/website/docs/api/phrasematcher.md index 36a412e34..40b8d6c1a 100644 --- a/website/docs/api/phrasematcher.md +++ b/website/docs/api/phrasematcher.md @@ -152,3 +152,22 @@ overwritten. | `match_id` | unicode | An ID for the thing you're matching. | | `on_match` | callable or `None` | Callback function to act on matches. Takes the arguments `matcher`, `doc`, `i` and `matches`. | | `*docs` | list | `Doc` objects of the phrases to match. | + +## PhraseMatcher.remove {#remove tag="method" new="2.2"} + +Remove a rule from the matcher by match ID. A `KeyError` is raised if the key +does not exist. + +> #### Example +> +> ```python +> matcher = PhraseMatcher(nlp.vocab) +> matcher.add("OBAMA", None, nlp("Barack Obama")) +> assert "OBAMA" in matcher +> matcher.remove("OBAMA") +> assert "OBAMA" not in matcher +> ``` + +| Name | Type | Description | +| ----- | ------- | ------------------------- | +| `key` | unicode | The ID of the match rule. |