Sha256: 44f28f770fe60f31ab562d5ffc7e02f5f327cb5295f1a009f033d95b2820bd47
Contents?: true
Size: 1.45 KB
Versions: 2
Compression:
Stored size: 1.45 KB
Contents
require_relative 'lexicons_cache' require_relative 'lexicon_map' require_relative 'kaf/document' module Opener class PolarityTagger class Internal DESC = 'VUA polarity tagger multilanguage' LAST_EDITED = '21may2014' VERSION = '1.2' CACHE = LexiconsCache.new def initialize ignore_pos: false, **params @ignore_pos = ignore_pos end def run input @kaf = KAF::Document.from_xml input @map = @kaf.map = CACHE[@kaf.language] negators = 0 @kaf.terms.each do |t| lemma = t.lemma&.downcase pos = if @ignore_pos then nil else t.pos end attrs = Hashie::Mash.new lexicon, polarity_pos = @map.by_polarity lemma, pos if lexicon.polarity != 'unknown' attrs.polarity = lexicon.polarity end if l = @map.by_negator(lemma) negators += 1 lexicon, polarity_pos = l, nil attrs.sentiment_modifier = 'shifter' end if l = @map.by_intensifier(lemma) lexicon, polarity_pos = l, nil attrs.sentiment_modifier = 'intensifier' end if attrs.size > 0 attrs.resource = lexicon.resource if lexicon.resource t.setPolarity attrs, polarity_pos end end @kaf.add_linguistic_processor DESC, "#{LAST_EDITED}_#{VERSION}", 'terms' @kaf.to_xml end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
opener-polarity-tagger-3.1.3 | lib/opener/polarity_tagger/internal.rb |
opener-polarity-tagger-3.1.2 | lib/opener/polarity_tagger/internal.rb |