Sha256: 2ff9eef90d781ac57adfa20ee8be66c9dba27e8d5a0734f7fc03a2724d0c1920

Contents?: true

Size: 1009 Bytes

Versions: 4

Compression:

Stored size: 1009 Bytes

Contents

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

4 entries across 4 versions & 1 rubygems

Version Path
ruby-spacy-0.1.3 examples/linguistic_features/noun_chunks.rb
ruby-spacy-0.1.2 examples/linguistic_features/noun_chunks.rb
ruby-spacy-0.1.1 examples/linguistic_features/noun_chunks.rb
ruby-spacy-0.1.0 examples/linguistic_features/noun_chunks.rb