Sha256: b17c50229047688c1df5822d7e58ce0466f6350576b29899e7e86b66904440f2

Contents?: true

Size: 516 Bytes

Versions: 4

Compression:

Stored size: 516 Bytes

Contents

require "ruby-spacy"
require "terminal-table"

nlp = Spacy::Language.new("en_core_web_lg")
matcher = nlp.matcher
matcher.add("US_PRESIDENT", [[{LOWER: "barack"}, {LOWER: "obama"}]])
doc = nlp.read("Barack Obama was the 44th president of the United States")

matches = matcher.match(doc)

matches.each do |match|
  span = Spacy::Span.new(doc, start_index: match[:start_index], end_index: match[:end_index], options: {label: match[:match_id]})
  puts span.text + " / " + span.label_
end

# Barack Obama / US_PRESIDENT

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ruby-spacy-0.1.3 examples/rule_based_matching/creating_spans_from_matches.rb
ruby-spacy-0.1.2 examples/rule_based_matching/creating_spans_from_matches.rb
ruby-spacy-0.1.1 examples/rule_based_matching/creating_spans_from_matches.rb
ruby-spacy-0.1.0 examples/rule_based_matching/creating_spans_from_matches.rb