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. |