Sha256: 86685dc04abe9abe3031c52d758e31de4d1a2353ba466f3a9a9be64756a53426

Contents?: true

Size: 1.79 KB

Versions: 2

Compression:

Stored size: 1.79 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("ja_core_news_sm")

doc = nlp.read("自動運転車は保険責任を製造者に転嫁する。")

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

# +------+----------+-----------+----------+------------------------+
# | text | dep      | head text | head pos | children               |
# +------+----------+-----------+----------+------------------------+
# | 自動 | compound | 車        | 92       |                        |
# | 運転 | compound | 車        | 92       |                        |
# | 車   | nsubj    | 転嫁      | 100      | 自動, 運転, は         |
# | は   | case     | 車        | 92       |                        |
# | 保険 | compound | 責任      | 92       |                        |
# | 責任 | obj      | 転嫁      | 100      | 保険, を               |
# | を   | case     | 責任      | 92       |                        |
# | 製造 | compound | 者        | 92       |                        |
# | 者   | obl      | 転嫁      | 100      | 製造, に               |
# | に   | case     | 者        | 92       |                        |
# | 転嫁 | ROOT     | 転嫁      | 100      | 車, 責任, 者, する, 。 |
# | する | aux      | 転嫁      | 100      |                        |
# | 。   | punct    | 転嫁      | 100      |                        |
# +------+----------+-----------+----------+------------------------+

Version data entries

2 entries across 2 versions & 1 rubygems

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