class Opener::OpinionDetectorBasic::BaseProcessor

Attributes

document[RW]
sentences[R]
terms[R]

Public Class Methods

new(file, options = {}) click to toggle source

@param [String|IO] file The KAF file/input to process. @param [Hash] options. Options for timestamp and including strength to opinions. @param [TrueClass|FalseClass] pretty Enable pretty formatting, disabled

by default due to the performance overhead.
# File lib/opener/opinion_detector_basic/base_processor.rb, line 15
def initialize file, options = {}
  @document  = Kaf::Document.new file, options
  @terms     = @document.terms
  @sentences = @document.sentences
end

Public Instance Methods

pretty_print(document) click to toggle source

Format the output document properly.

TODO: this should be handled by Oga in a nice way.

@return [String]

# File lib/opener/opinion_detector_basic/base_processor.rb, line 43
def pretty_print document
  doc = REXML::Document.new document.to_xml
  doc.context[:attribute_quote] = :quote
  out = ""
  formatter = REXML::Formatters::Pretty.new
  formatter.compact = true
  formatter.write doc, out

  out.strip
end
process() click to toggle source

Processes the input and returns the new KAF output. @return [String]

# File lib/opener/opinion_detector_basic/base_processor.rb, line 25
def process
  document.add_opinions_layer
  opinions.each.with_index do |opinion, index|
    document.add_opinion opinion, index+1
  end

  document.add_linguistic_processor

  if document.pretty then pretty_print document else document.to_xml end
end