Class: Spacy::PhraseMatcher
- Inherits:
-
Object
- Object
- Spacy::PhraseMatcher
- Defined in:
- lib/ruby-spacy.rb
Overview
See also spaCy Python API document for PhraseMatcher.
PhraseMatcher is useful for efficiently matching large terminology lists.
It's faster than Matcher when matching many phrase patterns.
Instance Attribute Summary collapse
-
#nlp ⇒ Language
readonly
The language model used by this matcher.
-
#py_matcher ⇒ Object
readonly
A Python
PhraseMatcherinstance accessible viaPyCall.
Instance Method Summary collapse
-
#add(label, phrases) ⇒ Object
Adds phrase patterns to the matcher.
-
#initialize(nlp, attr: "ORTH") ⇒ PhraseMatcher
constructor
Creates a PhraseMatcher instance.
-
#match(doc) ⇒ Array<Span>
Execute the phrase match and return matching spans.
Constructor Details
#initialize(nlp, attr: "ORTH") ⇒ PhraseMatcher
Creates a Spacy::PhraseMatcher instance.
767 768 769 770 |
# File 'lib/ruby-spacy.rb', line 767 def initialize(nlp, attr: "ORTH") @nlp = nlp @py_matcher = PyPhraseMatcher.call(nlp.py_nlp.vocab, attr: attr) end |
Instance Attribute Details
#nlp ⇒ Language (readonly)
Returns the language model used by this matcher.
759 760 761 |
# File 'lib/ruby-spacy.rb', line 759 def nlp @nlp end |
#py_matcher ⇒ Object (readonly)
Returns a Python PhraseMatcher instance accessible via PyCall.
756 757 758 |
# File 'lib/ruby-spacy.rb', line 756 def py_matcher @py_matcher end |
Instance Method Details
#add(label, phrases) ⇒ Object
Adds phrase patterns to the matcher.
777 778 779 780 |
# File 'lib/ruby-spacy.rb', line 777 def add(label, phrases) patterns = phrases.map { |phrase| @nlp.py_nlp.call(phrase) } @py_matcher.add(label, patterns) end |