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.
940 941 942 943 |
# File 'lib/ruby-spacy.rb', line 940 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.
932 933 934 |
# File 'lib/ruby-spacy.rb', line 932 def nlp @nlp end |
#py_matcher ⇒ Object (readonly)
Returns a Python PhraseMatcher instance accessible via PyCall.
929 930 931 |
# File 'lib/ruby-spacy.rb', line 929 def py_matcher @py_matcher end |
Instance Method Details
#add(label, phrases) ⇒ Object
Adds phrase patterns to the matcher.
950 951 952 953 |
# File 'lib/ruby-spacy.rb', line 950 def add(label, phrases) patterns = phrases.map { |phrase| @nlp.py_nlp.call(phrase) } @py_matcher.add(label, patterns) end |