class Opener::OpinionDetectorBasic::Kaf::Term

Constants

CONJUNCTIONS

Map of conjunctions per language code Deprecated

Attributes

accumulated_strength[RW]
document[R]
is_conjunction[R]
list_ids[RW]
node[R]
sentence[R]
use[RW]

Public Class Methods

new(node, document, language) click to toggle source
# 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

get_sentence(document) click to toggle source

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
head() click to toggle source

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
head_term() click to toggle source
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 60
def head_term
  return if root?
  document.terms[head-1]
end
id() click to toggle source

Returns the term id.

@return [String]

# File lib/opener/opinion_detector_basic/kaf/term.rb, line 38
def id
  @id ||= node.attr :tid
end
is_conjunction?(language) click to toggle source

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
is_expression?() click to toggle source

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
is_intensifier?() click to toggle source

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
is_shifter?() click to toggle source

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
lemma() click to toggle source

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
lexicon_id() click to toggle source
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 82
def lexicon_id
  @lexicon_id ||= node.attr('lexicon-id')
end
polarity() click to toggle source

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
pos() click to toggle source

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
root?() click to toggle source
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 65
def root?
  head == 0
end
sentiment_modifier() click to toggle source

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
strength() click to toggle source

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
target_ids() click to toggle source

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
xpos() click to toggle source
# File lib/opener/opinion_detector_basic/kaf/term.rb, line 78
def xpos
  @xpos ||= node.attr('xpos')
end

Private Instance Methods

first_sentiment() click to toggle source

@return [Oga::XML::Element]

# File lib/opener/opinion_detector_basic/kaf/term.rb, line 179
def first_sentiment
  @first_sentiment ||= node.at :sentiment
end