Sha256: 8eaa1047c1e8f9e30a301ebff246c5e9e00237b45815afd0efb186579dd5fa94

Contents?: true

Size: 1004 Bytes

Versions: 2

Compression:

Stored size: 1004 Bytes

Contents

require "ruby-spacy"
require "terminal-table"

nlp = Spacy::Language.new("en_core_web_sm")

nlp.add_pipe("merge_entities")
nlp.add_pipe("merge_noun_chunks")

sentence = "Credit and mortgage account holders must submit their requests"
doc = nlp.read(sentence)

texts = [
    "Net income was $9.4 million compared to the prior year of $2.7 million.",
    "Revenue exceeded twelve billion dollars, with a loss of $1b.",
]

texts.each do |text|
  doc = nlp.read(text)
  doc.each do |token|
    if token.ent_type_ == "MONEY"
      if ["attr", "dobj"].index token.dep_ 
        subj = Spacy.generator_to_array(token.head.lefts).select{|t| t.dep == "nsubj"}
        if !subj.empty?
          puts(subj[0].text + " --> " + token.text)
        end
      elsif token.dep_ == "pobj" and token.head.dep == "prep"
        puts token.head.head.text + " --> " + token.text
      end
    end
  end
end

# Net income --> $9.4 million
# the prior year --> $2.7 million
# Revenue --> twelve billion dollars
# a loss --> 1b

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby-spacy-0.1.4.1 examples/linguistic_features/information_extraction.rb
ruby-spacy-0.1.4 examples/linguistic_features/information_extraction.rb