Sha256: 7c9686155fa5a0d6d78fa83cb8434ed50f520a359fe334b7c596ac37728ca9dc
Contents?: true
Size: 1.47 KB
Versions: 6
Compression:
Stored size: 1.47 KB
Contents
module Opener class OpinionDetectorBasic class BaseProcessor attr_accessor :document attr_reader :terms, :sentences ## # @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. # def initialize file, options = {} @document = Kaf::Document.new file, options @terms = @document.terms @sentences = @document.sentences end ## # Processes the input and returns the new KAF output. # @return [String] # 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 ## # Format the output document properly. # # TODO: this should be handled by Oga in a nice way. # # @return [String] # 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 end end end
Version data entries
6 entries across 6 versions & 1 rubygems