Class: StanfordParser::StandoffSentence

Inherits:
Array
  • Object
show all
Defined in:
lib/stanfordparser.rb

Overview

A sentence is an array of StandoffToken objects.

Instance Method Summary collapse

Constructor Details

#initialize(stanford_parser_sentence) ⇒ StandoffSentence

Construct an array of StandoffToken objects from a Java list sentence object returned by the preprocessor.



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/stanfordparser.rb', line 283

def initialize(stanford_parser_sentence)
  # Convert FeatureStructure wrappers to StandoffToken objects.
  s = stanford_parser_sentence.to_a.collect do |fs|
    current = fs.current
    word = fs.word
    before = fs.before
    after = fs.after
    # The to_s.to_i is necessary because the get function returns
    # java.lang.Integer objects instead of Ruby integers.
    begin_position = fs.get(fs.BEGIN_POSITION_KEY).to_s.to_i
    end_position = fs.get(fs.END_POSITION_KEY).to_s.to_i
    StandoffToken.new(current, word, before, after,
                      begin_position, end_position)
  end
  super(s)
end

Instance Method Details

#inspectObject

Return the original string verbatim.



306
307
308
# File 'lib/stanfordparser.rb', line 306

def inspect
  to_s
end

#to_sObject

Return the original string verbatim.



301
302
303
# File 'lib/stanfordparser.rb', line 301

def to_s
  self[0..-2].inject(""){|s, word| s + word.current + word.after} + last.current
end