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.
875 876 877 878 |
# File 'lib/ruby-spacy.rb', line 875 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.
867 868 869 |
# File 'lib/ruby-spacy.rb', line 867 def nlp @nlp end |
#py_matcher ⇒ Object (readonly)
Returns a Python PhraseMatcher instance accessible via PyCall.
864 865 866 |
# File 'lib/ruby-spacy.rb', line 864 def py_matcher @py_matcher end |
Instance Method Details
#add(label, phrases) ⇒ Object
Adds phrase patterns to the matcher.
885 886 887 888 |
# File 'lib/ruby-spacy.rb', line 885 def add(label, phrases) patterns = phrases.map { |phrase| @nlp.py_nlp.call(phrase) } @py_matcher.add(label, patterns) end |