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.
719 720 721 722 |
# File 'lib/ruby-spacy.rb', line 719 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.
711 712 713 |
# File 'lib/ruby-spacy.rb', line 711 def nlp @nlp end |
#py_matcher ⇒ Object (readonly)
Returns a Python PhraseMatcher instance accessible via PyCall.
708 709 710 |
# File 'lib/ruby-spacy.rb', line 708 def py_matcher @py_matcher end |
Instance Method Details
#add(label, phrases) ⇒ Object
Adds phrase patterns to the matcher.
729 730 731 732 |
# File 'lib/ruby-spacy.rb', line 729 def add(label, phrases) patterns = phrases.map { |phrase| @nlp.py_nlp.call(phrase) } @py_matcher.add(label, patterns) end |