opener-polarity-tagger 3.2.4 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 062fd54795d572d62bb63481dbce896c918f9b9e80a55df36b5e19f2a0be97ad
4
- data.tar.gz: 6a4ff6d3ef761a22d044b7301064bc7eb0e2f75df8f806d6359aa5e5a01c42f4
3
+ metadata.gz: e7d99cc90032fe712bac6fa6952d1dc482d7ea5a86d9db9544f17e52d75d68f6
4
+ data.tar.gz: 8c8a5126f8a63a55bea7062c06d078bc87b0ff9286201956524755fb163e1172
5
5
  SHA512:
6
- metadata.gz: f40d2703af5e936a3f2c747c2fc5938606ec4a8d8d65bfc8b7bd5aeaa2836de9090912c91d7f699b978d324be921128d743bfb69367539947e3202dca50abcb7
7
- data.tar.gz: 884bbe39961248e5158f0b3b4c8c84ebc46bdce1fc7292a7b27eb4737fac7497a273f3a9fa91706aa283f2a814bf88b92439df3bd2dcfb8cfe0991461061b06d
6
+ metadata.gz: 185160b82b01008ed03ce4a26e0d93ca18b1aab91e20c57acfe7425fa103c557606e0151e161ad7d36dc7380b2f26c9daae9e9649e4b1f7b65ce29c98f270ccc
7
+ data.tar.gz: 73f6b42eba61db2004fff08f54a1636767e8e77e93ec817717530accfa9fcd3001097e630c043fea0d3afd462c42b755a03f274c4d74e427c1753cf70fb30648
@@ -18,6 +18,10 @@ module Opener
18
18
  @node.attr :lemma
19
19
  end
20
20
 
21
+ def text
22
+ @node.attr :text
23
+ end
24
+
21
25
  def pos
22
26
  @node.attr :pos
23
27
  end
@@ -1,6 +1,6 @@
1
1
  require_relative 'lexicons_cache'
2
2
  require_relative 'lexicon_map'
3
- require_relative 'kaf/document'
3
+ require_relative '../kaf/document'
4
4
 
5
5
  module Opener
6
6
  class PolarityTagger
@@ -16,44 +16,46 @@ module Opener
16
16
  @ignore_pos = ignore_pos
17
17
  end
18
18
 
19
- def clear_cache lang: nil, environment:
20
- end
21
-
22
19
  def run input, params = {}
23
- @kaf = KAF::Document.from_xml input
20
+ kaf = KAF::Document.from_xml input
24
21
 
25
22
  @cache_keys = params[:cache_keys] ||= {}
26
- @cache_keys.merge! lang: @kaf.language
27
- @map = @kaf.map = CACHE[**@cache_keys].lexicons
23
+ @cache_keys.merge! lang: kaf.language
24
+ @map = kaf.map = CACHE[**@cache_keys].lexicons
28
25
 
29
- @kaf.terms.each do |t|
26
+ raise Opener::Core::UnsupportedLanguageError, kaf.language if @map.blank?
27
+
28
+ kaf.terms.each do |t|
30
29
  lemma = t.lemma&.downcase
30
+ text = t.text.to_s.downcase
31
31
  pos = if @ignore_pos then nil else t.pos end
32
32
  attrs = Hashie::Mash.new
33
33
 
34
- lexicon, polarity_pos = @map.by_polarity lemma, pos
34
+ # text matching have priority as sometimes
35
+ # the lemma provided by Stanza is a different word
36
+ lexicon, polarity_pos = @map.by_polarity text, pos
37
+ lexicon, polarity_pos = @map.by_polarity lemma, pos if lexicon.polarity == 'unknown'
35
38
 
36
- if lexicon.polarity != 'unknown'
37
- attrs.polarity = lexicon.polarity
38
- end
39
- if l = @map.by_negator(lemma)
39
+ if l = @map.by_negator(text) || @map.by_negator(lemma)
40
40
  lexicon, polarity_pos = l, nil
41
41
  attrs.sentiment_modifier = 'shifter'
42
- end
43
- if l = @map.by_intensifier(lemma)
42
+ elsif l = @map.by_intensifier(text) || @map.by_intensifier(lemma)
44
43
  lexicon, polarity_pos = l, nil
45
44
  attrs.sentiment_modifier = 'intensifier'
45
+ elsif lexicon.polarity != 'unknown'
46
+ attrs.polarity = lexicon.polarity
46
47
  end
47
48
 
48
49
  if attrs.size > 0
49
- attrs.resource = lexicon.resource if lexicon.resource
50
+ attrs['lexicon-id'] = lexicon.id.to_s if lexicon.id
51
+ attrs.resource = lexicon.resource if lexicon.resource
50
52
  t.setPolarity attrs, polarity_pos
51
53
  end
52
54
  end
53
55
 
54
- @kaf.add_linguistic_processor DESC, "#{LAST_EDITED}_#{VERSION}", 'terms'
56
+ kaf.add_linguistic_processor DESC, "#{LAST_EDITED}_#{VERSION}", 'terms'
55
57
 
56
- @kaf.to_xml
58
+ kaf.to_xml
57
59
  end
58
60
 
59
61
  end
@@ -16,11 +16,11 @@ module Opener
16
16
  adv: 'A',
17
17
  noun: 'N',
18
18
  propernoun: 'N',
19
- other: 'O',
20
19
  prep: 'P',
21
20
  verb: 'V',
21
+ other: DEFAULT_POS,
22
22
  nil => DEFAULT_POS,
23
- multi_word_expression: 'O',
23
+ multi_word_expression: DEFAULT_POS,
24
24
  }
25
25
 
26
26
  def initialize lang:, lexicons:
@@ -46,13 +46,12 @@ module Opener
46
46
  end
47
47
 
48
48
  def by_polarity lemma, short_pos
49
- return [@with_polarity[lemma+short_pos] || UNKNOWN, short_pos] if short_pos
49
+ l = @with_polarity[lemma+short_pos] if short_pos
50
+ return [l, short_pos] if l
50
51
 
51
52
  POS_ORDER.chars.each do |short_pos|
52
- if l = @with_polarity[lemma+short_pos]
53
- puts "Found polarify #{l.polarity} for #{lemma} with PoS #{short_pos}"
54
- return [l, short_pos]
55
- end
53
+ l = @with_polarity[lemma+short_pos]
54
+ return [l, short_pos] if l
56
55
  end
57
56
 
58
57
  [UNKNOWN, 'unknown']
@@ -60,6 +59,14 @@ module Opener
60
59
 
61
60
  protected
62
61
 
62
+ def map_one_polarity l
63
+ poses = if l.poses.present? then l.poses else [l.pos] end
64
+ poses.each do |pos|
65
+ short_pos = POS_SHORT_MAP[pos&.to_sym] || DEFAULT_POS
66
+ @with_polarity[l.lemma+short_pos] = l
67
+ end
68
+ end
69
+
63
70
  def map lexicons
64
71
  return if blank?
65
72
 
@@ -71,8 +78,10 @@ module Opener
71
78
  when 'intensifier' then @intensifiers[l.lemma] = l
72
79
  else
73
80
  if l.polarity
74
- short_pos = POS_SHORT_MAP[l.pos&.to_sym] || DEFAULT_POS
75
- @with_polarity[l.lemma+short_pos] = l
81
+ map_one_polarity l
82
+ l.variants&.each do |v|
83
+ map_one_polarity v
84
+ end
76
85
  end
77
86
  end
78
87
  end
@@ -1,7 +1,7 @@
1
1
  module Opener
2
2
  class PolarityTagger
3
3
 
4
- VERSION = '3.2.4'
4
+ VERSION = '3.4.0'
5
5
 
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opener-polarity-tagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.4
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - development@olery.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-02 00:00:00.000000000 Z
11
+ date: 2021-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opener-daemons
@@ -181,10 +181,10 @@ dependencies:
181
181
  description: Polarity tagger for various languages.
182
182
  email:
183
183
  executables:
184
- - polarity-tagger-server
185
- - console
186
184
  - polarity-tagger
187
185
  - polarity-tagger-daemon
186
+ - polarity-tagger-server
187
+ - console
188
188
  extensions:
189
189
  - ext/hack/Rakefile
190
190
  extra_rdoc_files: []
@@ -212,12 +212,12 @@ files:
212
212
  - core/poltagger-basic-multi.py
213
213
  - exec/polarity-tagger.rb
214
214
  - ext/hack/Rakefile
215
+ - lib/opener/kaf/document.rb
216
+ - lib/opener/kaf/term.rb
215
217
  - lib/opener/polarity_tagger.rb
216
218
  - lib/opener/polarity_tagger/cli.rb
217
219
  - lib/opener/polarity_tagger/external.rb
218
220
  - lib/opener/polarity_tagger/internal.rb
219
- - lib/opener/polarity_tagger/kaf/document.rb
220
- - lib/opener/polarity_tagger/kaf/term.rb
221
221
  - lib/opener/polarity_tagger/lexicon_map.rb
222
222
  - lib/opener/polarity_tagger/lexicons_cache.rb
223
223
  - lib/opener/polarity_tagger/public/markdown.css