Class: StanfordParser::StandoffSentence
- Inherits:
-
Array
- Object
- Array
- StanfordParser::StandoffSentence
- Defined in:
- lib/stanfordparser.rb
Overview
A sentence is an array of StandoffToken objects.
Instance Method Summary collapse
-
#initialize(stanford_parser_sentence) ⇒ StandoffSentence
constructor
Construct an array of StandoffToken objects from a Java list sentence object returned by the preprocessor.
-
#inspect ⇒ Object
Return the original string verbatim.
-
#to_s ⇒ Object
Return the original string verbatim.
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
#inspect ⇒ Object
Return the original string verbatim.
306 307 308 |
# File 'lib/stanfordparser.rb', line 306 def inspect to_s end |
#to_s ⇒ Object
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 |