Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Commit

Permalink
Adds a method to run a SpaCy matcher over the doc.
Browse files Browse the repository at this point in the history
  • Loading branch information
dodijk committed Aug 28, 2018
1 parent fa69ffa commit 561568b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions textpipe/doc.py
Expand Up @@ -161,6 +161,18 @@ def find_ents(self, model_name=None):
lang = self.hint_language if self.language == 'un' else self.language
return list({(ent.text, ent.label_) for ent in self._load_spacy_doc(lang, model_name).ents})

def match(self, matcher):
"""
Run a SpaCy matcher over the cleaned content
>>> matcher = spacy.matcher.Matcher(spacy.lang.en.English().vocab)
>>> matcher.add('HASHTAG', None, [{'ORTH': '#'}, {'IS_ASCII': True}])
>>> Doc('Test with #hashtag').match(matcher)
[('#hashtag', 'HASHTAG')]
"""
return [(self.spacy_doc[start:end].text, matcher.vocab.strings[match_id])
for match_id, start, end in matcher(self.spacy_doc)]

@property
def nsents(self):
"""
Expand Down

0 comments on commit 561568b

Please sign in to comment.