Sha256: 3046d9589cfad70258641da2d49d23c71ac6bed374a5595d79de14da1450b41d

Contents?: true

Size: 503 Bytes

Versions: 2

Compression:

Stored size: 503 Bytes

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")

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

results = []

doc.each do |token|
  next unless token.pos_ == "VERB"

  token.children.each do |child|
    results << child.head.text if child.dep_ == "nsubj"
  end
end

puts results

# ["shift"]

Version data entries

2 entries across 2 versions & 1 rubygems

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