Sha256: c99e3ba1b0ea06c686609a587bc119ac75410ac5dad844ca65302765035db771

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 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", "dep", "head text", "head pos", "children"]
rows = []

doc.each do |token|
  rows << [token.text, token.dep, token.head.text, token.head.pos, token.children.map(&:text).join(", ")]
end

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

# Lemmatizer mode: rule
# +---------------+----------+-----------+----------+-------------------------+
# | text          | dep      | head text | head pos | children                |
# +---------------+----------+-----------+----------+-------------------------+
# | Autonomous    | amod     | cars      | NOUN     |                         |
# | cars          | nsubj    | shift     | VERB     | Autonomous              |
# | shift         | ROOT     | shift     | VERB     | cars, liability, toward |
# | insurance     | compound | liability | NOUN     |                         |
# | liability     | dobj     | shift     | VERB     | insurance               |
# | toward        | prep     | shift     | VERB     | manufacturers           |
# | manufacturers | pobj     | toward    | ADP      |                         |
# +---------------+----------+-----------+----------+-------------------------+

Version data entries

2 entries across 2 versions & 1 rubygems

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