class Opener::OpinionDetectorBasic::Kaf::Term
Constants
- CONJUNCTIONS
Map of conjunctions per language code Deprecated
Attributes
Public Class Methods
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 23 def initialize node, document, language @document = document @node = node @sentence = get_sentence document @use = true @accumulated_strength = strength @list_ids = [id] @is_conjunction = is_conjunction? language end
Public Instance Methods
Returns the sentence id that the term belongs to in the document.
@return [String]
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 133 def get_sentence(document) document .xpath("KAF/text/wf[@wid='#{target_ids.first}']") .first .attr('sent') end
Returns the head of the term.
@return [String]
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 56 def head @head ||= node.attr(:head).to_i end
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 60 def head_term return if root? document.terms[head-1] end
Returns the term id.
@return [String]
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 38 def id @id ||= node.attr :tid end
Checks if a term is a conjunction. Comma is identified as conjunction by default Sometimes, comma comes with space after it
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 172 def is_conjunction?(language) pos == 'J' || xpos == ',' || lemma == ',' || CONJUNCTIONS[language]&.include?(lemma) end
Checks if a term is an expression.
@return [TrueClass|FalseClass]
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 163 def is_expression? use && !!polarity end
Checks if a term is an intensifier.
@return [TrueClass|FalseClass]
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 145 def is_intensifier? sentiment_modifier == 'intensifier' end
Checks if a term is a shifter.
@return [TrueClass|FalseClass]
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 154 def is_shifter? sentiment_modifier == 'shifter' end
Returns the lemma of the term.
@return [String]
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 47 def lemma @lemma ||= node.attr :lemma end
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 82 def lexicon_id @lexicon_id ||= node.attr('lexicon-id') end
Returns the polarity of the term if it exists.
@return [String|NilClass]
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 101 def polarity @polarity ||= first_sentiment ? first_sentiment.attr('polarity') : nil end
Returns the part of speech of the term.
@return [String]
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 74 def pos @pos ||= node.attr('pos') end
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 65 def root? head == 0 end
Returns the sentiment modifier type if it exists.
@return [String|NilClass]
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 91 def sentiment_modifier @sentiment_modifier ||= first_sentiment ? first_sentiment.attr('sentiment_modifier') : nil end
Returns the strength of the term depending on its type.
@return [Integer]
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 120 def strength return 1 if polarity == 'positive' return -1 if polarity == 'negative' return 2 if is_intensifier? return -1 if is_shifter? return 0 end
Returns the actual word ids that construct the lemma.
@return [Array]
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 110 def target_ids @target_ids ||= node.xpath('span/target') .map { |target| target.attr('id') } end
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 78 def xpos @xpos ||= node.attr('xpos') end
Private Instance Methods
@return [Oga::XML::Element]
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 179 def first_sentiment @first_sentiment ||= node.at :sentiment end