Class: Opener::PolarityTagger::LexiconMap

Inherits:
Object
  • Object
show all
Defined in:
lib/opener/polarity_tagger/lexicon_map.rb

Constant Summary collapse

POS_ORDER =
'ONRVGA'
DEFAULT_POS =
'O'
POS_SHORT_MAP =
{
  adj:         'G',
  adv:         'A',
  noun:        'N',
  propernoun:  'N',
  prep:        'P',
  verb:        'V',
  other:       DEFAULT_POS,
  nil =>       DEFAULT_POS,
  multi_word_expression: DEFAULT_POS,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lang:, lexicons:) ⇒ LexiconMap

Returns a new instance of LexiconMap.



24
25
26
27
28
29
30
31
32
# File 'lib/opener/polarity_tagger/lexicon_map.rb', line 24

def initialize lang:, lexicons:
  @lang          = lang
  @lexicons      = lexicons

  @negators      = {}
  @intensifiers  = {}
  @with_polarity = {}
  map lexicons
end

Instance Attribute Details

#intensifiersObject (readonly)

Returns the value of attribute intensifiers.



7
8
9
# File 'lib/opener/polarity_tagger/lexicon_map.rb', line 7

def intensifiers
  @intensifiers
end

#negatorsObject (readonly)

Returns the value of attribute negators.



6
7
8
# File 'lib/opener/polarity_tagger/lexicon_map.rb', line 6

def negators
  @negators
end

#resourceObject (readonly)

Returns the value of attribute resource.



5
6
7
# File 'lib/opener/polarity_tagger/lexicon_map.rb', line 5

def resource
  @resource
end

#with_polarityObject (readonly)

Returns the value of attribute with_polarity.



8
9
10
# File 'lib/opener/polarity_tagger/lexicon_map.rb', line 8

def with_polarity
  @with_polarity
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/opener/polarity_tagger/lexicon_map.rb', line 34

def blank?
  @lexicons.blank?
end

#by_intensifier(lemma) ⇒ Object



42
43
44
# File 'lib/opener/polarity_tagger/lexicon_map.rb', line 42

def by_intensifier lemma
  @intensifiers[lemma]
end

#by_negator(lemma) ⇒ Object



38
39
40
# File 'lib/opener/polarity_tagger/lexicon_map.rb', line 38

def by_negator lemma
  @negators[lemma]
end

#by_polarity(lemma, identified_short_pos) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/opener/polarity_tagger/lexicon_map.rb', line 46

def by_polarity lemma, identified_short_pos
  hash = Hashie::Mash.new multi: (@with_polarity[lemma] || [])

  if identified_short_pos and lexicon = @with_polarity[lemma+identified_short_pos]
    hash[:single] = lexicon
    return [hash, identified_short_pos]
  end

  POS_ORDER.chars.each do |short_pos|
    if lexicon = @with_polarity[lemma+short_pos]
      hash[:single] = lexicon
      return [hash, identified_short_pos]
    end
  end

  [hash, 'unknown']
end