opener-polarity-tagger 3.2.3 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a62617dcfcc50787c56ac1243ecdacdd6c85d39621662e3c585a944453153469
4
- data.tar.gz: 818c317c7b7ce7ddc4668bcef407ceb41e9a96ed781c0dcf47e6bedfd016cfaf
3
+ metadata.gz: dcce63ff8ce9916a2387c5d0f48209b203eacbc3834eedcf3b5b4990084ac1ad
4
+ data.tar.gz: 495e79bfdec921d459ff78e50bdae28a2c6a0a8bc2aed150de27f49a7f99c423
5
5
  SHA512:
6
- metadata.gz: babc5afc6e4ab7b7845386e2493c88aa975429397aa695eac4b8705f3aa92417ce240b367844b7cdeec1f3f446a792e5d501a38f7e303c1587196bb4020ebf14
7
- data.tar.gz: 221d76e8fe87f56861e7a48ac5dd1ce3bae9dd85397ce0d165f67c13cfaf9241fc7cd31cd5f630b0fdb15b5d373ff3b307e73f7e993e6b576faf2ddcbaf2938b
6
+ metadata.gz: e51288c630084ce9be780b022ae23012337622b6df30de91962f5c73fd2ef32054435247bf850924a40ca723c3fe1a71fc9f688455b1ea5141acf80959fbe37a
7
+ data.tar.gz: e8f00bd36a27aab5242d91e3f350d4da94d2661ef5565590e1793e02eb65075cf7dd789682b2cd0e06cf4b84bb21a5d5671d51f7e9d94ec1748cd1c8012f33ac
@@ -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,33 +16,34 @@ 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
@@ -51,9 +52,9 @@ module Opener
51
52
  end
52
53
  end
53
54
 
54
- @kaf.add_linguistic_processor DESC, "#{LAST_EDITED}_#{VERSION}", 'terms'
55
+ kaf.add_linguistic_processor DESC, "#{LAST_EDITED}_#{VERSION}", 'terms'
55
56
 
56
- @kaf.to_xml
57
+ kaf.to_xml
57
58
  end
58
59
 
59
60
  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']
@@ -46,7 +46,7 @@ module Opener
46
46
 
47
47
  def load_from_url lang:, cache:, **params
48
48
  url = "#{@url}&language_code=#{lang}&#{params.to_query}"
49
- url += "&if_updated_since=#{cache.from.iso8601}" if cache
49
+ url += "&if_updated_since=#{cache.from.utc.iso8601}" if cache
50
50
  puts "#{lang}: loading lexicons from url #{url}"
51
51
 
52
52
  lexicons = JSON.parse http.get(url).body
@@ -1,7 +1,7 @@
1
1
  module Opener
2
2
  class PolarityTagger
3
3
 
4
- VERSION = '3.2.3'
4
+ VERSION = '3.3.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.3
4
+ version: 3.3.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: 2020-12-10 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