Sha256: bdc0450a3c580f3e581a4a1814972b999cc5255dfee1f15dc3e66d837c813e3a
Contents?: true
Size: 1.19 KB
Versions: 2
Compression:
Stored size: 1.19 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") sentence = "Credit and mortgage account holders must submit their requests" doc = nlp.read(sentence) headings = ["text", "pos", "dep", "head text"] rows = [] doc.retokenize(doc[4].left_edge.i, doc[4].right_edge.i) doc.each do |token| rows << [token.text, token.pos, token.dep, token.head.text] end table = Terminal::Table.new rows: rows, headings: headings puts table # +-------------------------------------+------+-------+-----------+ # | text | pos | dep | head text | # +-------------------------------------+------+-------+-----------+ # | Credit and mortgage account holders | NOUN | nsubj | submit | # | must | AUX | aux | submit | # | submit | VERB | ROOT | submit | # | their | PRON | poss | requests | # | requests | NOUN | dobj | submit | # +-------------------------------------+------+-------+-----------+
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ruby-spacy-0.2.3 | examples/linguistic_features/retokenize_1.rb |
ruby-spacy-0.2.2 | examples/linguistic_features/retokenize_1.rb |