Sha256: b0a0f97eea424e0ec30d03996f92fa486017c9b6ffeef945a7f3459a0b1f1c07

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

# add path to ruby-spacy lib to load path
$LOAD_PATH.unshift(File.expand_path("../../lib", __dir__))

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

nlp = Spacy::Language.new("en_core_web_sm")

lemmatizer = nlp.get_pipe("lemmatizer")
puts "Lemmatizer mode: #{lemmatizer.mode}"

doc = nlp.read("Autonomous cars shift insurance liability toward manufacturers")

headings = ["text", "root.text", "root.dep", "root.head.text"]
rows = []

doc.noun_chunks.each do |chunk|
  rows << [chunk.text, chunk.root.text, chunk.root.dep, chunk.root.head.text]
end

table = Terminal::Table.new rows: rows, headings: headings
puts table

# +---------------------+---------------+----------+----------------+
# | text                | root.text     | root.dep | root.head.text |
# +---------------------+---------------+----------+----------------+
# | Autonomous cars     | cars          | nsubj    | shift          |
# | insurance liability | liability     | dobj     | shift          |
# | manufacturers       | manufacturers | pobj     | toward         |
# +---------------------+---------------+----------+----------------+

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby-spacy-0.2.3 examples/linguistic_features/noun_chunks.rb
ruby-spacy-0.2.2 examples/linguistic_features/noun_chunks.rb