Class: Spacy::Matcher
- Inherits:
-
Object
- Object
- Spacy::Matcher
- Defined in:
- lib/ruby-spacy.rb
Overview
See also spaCy Python API document for Matcher.
Instance Attribute Summary collapse
-
#py_matcher ⇒ Object
readonly
A Python
Matcherinstance accessible viaPyCall.
Instance Method Summary collapse
-
#add(text, pattern) ⇒ Object
Adds a label string and a text pattern.
-
#initialize(nlp) ⇒ Matcher
constructor
Creates a Matcher instance.
-
#match(doc) ⇒ Array<Hash{:match_id => Integer, :start_index => Integer, :end_index => Integer, :label => String}>
Execute the match.
Constructor Details
#initialize(nlp) ⇒ Matcher
Creates a Spacy::Matcher instance
838 839 840 |
# File 'lib/ruby-spacy.rb', line 838 def initialize(nlp) @py_matcher = PyMatcher.call(nlp.vocab) end |
Instance Attribute Details
#py_matcher ⇒ Object (readonly)
Returns a Python Matcher instance accessible via PyCall.
834 835 836 |
# File 'lib/ruby-spacy.rb', line 834 def py_matcher @py_matcher end |
Instance Method Details
#add(text, pattern) ⇒ Object
Adds a label string and a text pattern.
845 846 847 |
# File 'lib/ruby-spacy.rb', line 845 def add(text, pattern) @py_matcher.add(text, pattern) end |
#match(doc) ⇒ Array<Hash{:match_id => Integer, :start_index => Integer, :end_index => Integer, :label => String}>
Execute the match.
852 853 854 855 856 |
# File 'lib/ruby-spacy.rb', line 852 def match(doc) PyCall::List.call(PyHelpers.matcher_matches(@py_matcher, doc.py_doc)).map do |py_match| { match_id: py_match[0].to_i, start_index: py_match[1], end_index: py_match[2] - 1, label: py_match[3] } end end |