explosion / explosion/spacy-course
Missing implementation to output matches from the matcher at chapter1_03_rule-based-matching.md
- Dominant language
- Python
- Stars
- 2.4k
- Forks
- 377
- PR merge metrics
- No merged PRs in 30d
Description
## Phenomenon
There is the output of the matches from the matcher at [chapter1_03_rule-based-matching.md Matching lexical attributes](https://github.com/ines/spacy-course/blob/master/chapters/en/slides/chapter1_03_rule-based-matching.md#matching-lexical-attributes), but the implementation to get it is missing.
```py
doc = nlp("2018 FIFA World Cup: France won!")
```
**(The implementation is missing to output the following `2018 FIFA World Cup:` from `doc`.**
```
2018 FIFA World Cup:
```
## Proposal
Add the implementation to get the output. The following code is one of the candidate.
```py
matcher = Matcher(nlp.vocab)
matcher.add("IPHONE_PATTERN", None, pattern)
matches = matcher(doc)
for match_id, start, end in matches:
matched_span = doc[start:end]
print(matched_span.text)
```
But a little verbose. We can avoid the repetition of the code by function.
```py
def print_matches(doc, pattern);
matcher = Matcher(nlp.vocab)
matcher.add("PATTERN", None, pattern)
matches = matcher(doc)
for match_id, start, end in matches:
matched_span = doc[start:end]
print(matched_span.text)
```
Then, we can write as following.
```py
doc = nlp("2018 FIFA World Cup: France won!")
print_matches(doc, pattern)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.