Document PhraseMatcher.remove [ci skip]

This commit is contained in:
Ines Montani 2019-09-27 16:34:53 +02:00
parent c23edf302b
commit aad66d9bb9
2 changed files with 21 additions and 0 deletions

View File

@ -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)

View File

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