Sha256: 9f0f7a0ebf2e1e65e6122ca1d1d8e3a71070ced319362ee09019d890c9e71e70

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

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.1.4.1 examples/linguistic_features/retokenize_1.rb
ruby-spacy-0.1.4 examples/linguistic_features/retokenize_1.rb