Sha256: 49975ff452bb79366002c3ea3f2830c21867a84df6e4e619fe02c5246c8cc204

Contents?: true

Size: 1.71 KB

Versions: 2

Compression:

Stored size: 1.71 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")
doc = nlp.read("Apple is looking at buying U.K. startup for $1 billion")

headings = %w[text lemma pos tag dep shape is_alpha is_stop]
rows = []

doc.each do |token|
  rows << [token.text, token.lemma, token.pos, token.tag, token.dep, token.shape, token.is_alpha, token.is_stop]
end

table = Terminal::Table.new rows: rows, headings: headings
puts table

# +---------+---------+-------+-----+----------+-------+----------+---------+
# | text    | lemma   | pos   | tag | dep      | shape | is_alpha | is_stop |
# +---------+---------+-------+-----+----------+-------+----------+---------+
# | Apple   | Apple   | PROPN | NNP | nsubj    | Xxxxx | true     | false   |
# | is      | be      | AUX   | VBZ | aux      | xx    | true     | true    |
# | looking | look    | VERB  | VBG | ROOT     | xxxx  | true     | false   |
# | at      | at      | ADP   | IN  | prep     | xx    | true     | true    |
# | buying  | buy     | VERB  | VBG | pcomp    | xxxx  | true     | false   |
# | U.K.    | U.K.    | PROPN | NNP | dobj     | X.X.  | false    | false   |
# | startup | startup | NOUN  | NN  | advcl    | xxxx  | true     | false   |
# | for     | for     | ADP   | IN  | prep     | xxx   | true     | true    |
# | $       | $       | SYM   | $   | quantmod | $     | false    | false   |
# | 1       | 1       | NUM   | CD  | compound | d     | false    | false   |
# | billion | billion | NUM   | CD  | pobj     | xxxx  | true     | false   |
# +---------+---------+-------+-----+----------+-------+----------+---------+

Version data entries

2 entries across 2 versions & 1 rubygems

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