opener-polarity-tagger 3.1.3 → 3.2.1

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: b4362832bbbb35ee32747d662b0ed336a4999281474b7866c748f392cd7e4850
4
- data.tar.gz: 6882049bcdf93c02dec34023f472691d760f6f200370ba551d59036bf3f3e26b
3
+ metadata.gz: 4f5521ee603c20f1efe4008895c88409afbe7994fe5eab72a1de08766ac36da1
4
+ data.tar.gz: 0345c08ea80a4b55c0003a02763fa31837d72e6e38f7fcbb2b7c63a720e00712
5
5
  SHA512:
6
- metadata.gz: af13174d0deb82c077403daadb9ad046e945eae79e24f7cf2a1e50961b1e901ec94553da428057a9eeccaa2c0e5a8e007b28f685874ea21253a8e36701bb7599
7
- data.tar.gz: 3cd67f602a84d8674203579dc8e4bbba271ee49a57c5a34969e0cbef4bc29f32b25393ea0a45c77cff0d518e4355196734055d3f7774140d713bf675d0486fc0
6
+ metadata.gz: '02932a66b68aeb50c5c7f77f597ca8f6f6dd55d839796c6609a42eed2afd066ef531316abf1b600e48d7f3f4619a8f1de84d28b7c6858b47fbce4223ec08013f'
7
+ data.tar.gz: 41a68399fb4631e5aee6f6c2110d2e6da96ee1d96101b4a95548fc9def1f3e0e5e861cdad453dfb78cebf5de2a7d85dea76af7f9462ae86c55619bff7314a5a6
@@ -2,6 +2,7 @@ require 'open3'
2
2
  require 'opener/core'
3
3
  require 'nokogiri'
4
4
  require 'hashie'
5
+ require 'active_support/all'
5
6
 
6
7
  require_relative 'polarity_tagger/version'
7
8
  require_relative 'polarity_tagger/cli'
@@ -19,8 +20,12 @@ module Opener
19
20
  @proc = @klass.new args: @args
20
21
  end
21
22
 
22
- def run input
23
- @proc.run input
23
+ def clear_cache params = {}
24
+ @proc.clear_cache(**params)
25
+ end
26
+
27
+ def run input, params = {}
28
+ @proc.run input, params
24
29
  end
25
30
 
26
31
  end
@@ -52,7 +52,7 @@ module Opener
52
52
  # @param [String] input The text of which to detect the language.
53
53
  # @return [Array]
54
54
  #
55
- def run(input)
55
+ def run input, params
56
56
  stdout, stderr, process = capture(input)
57
57
 
58
58
  raise stderr unless process.success?
@@ -16,11 +16,16 @@ module Opener
16
16
  @ignore_pos = ignore_pos
17
17
  end
18
18
 
19
- def run input
19
+ def clear_cache lang: nil, environment:
20
+ end
21
+
22
+ def run input, params = {}
20
23
  @kaf = KAF::Document.from_xml input
21
- @map = @kaf.map = CACHE[@kaf.language]
22
24
 
23
- negators = 0
25
+ @cache_keys = params[:cache_keys] ||= {}
26
+ @cache_keys.merge! lang: @kaf.language
27
+ @map = @kaf.map = CACHE[**@cache_keys].lexicons
28
+
24
29
  @kaf.terms.each do |t|
25
30
  lemma = t.lemma&.downcase
26
31
  pos = if @ignore_pos then nil else t.pos end
@@ -32,7 +37,6 @@ module Opener
32
37
  attrs.polarity = lexicon.polarity
33
38
  end
34
39
  if l = @map.by_negator(lemma)
35
- negators += 1
36
40
  lexicon, polarity_pos = l, nil
37
41
  attrs.sentiment_modifier = 'shifter'
38
42
  end
@@ -7,21 +7,10 @@ module Opener
7
7
  attr_reader :intensifiers
8
8
  attr_reader :with_polarity
9
9
 
10
- POS_ORDER = 'NRVGAO'
11
- UNKNOWN = Hashie::Mash.new polarity: 'unknown'
12
-
13
- def initialize lang:, lexicons:
14
- @lang = lang
15
- @lexicons = lexicons
16
-
17
- @negators = {}
18
- @intensifiers = {}
19
- @with_polarity = {}
20
- map lexicons
21
- end
22
-
23
- DEFAULT_POS = 'O'
10
+ UNKNOWN = Hashie::Mash.new polarity: 'unknown'
24
11
 
12
+ POS_ORDER = 'NRVGAO'
13
+ DEFAULT_POS = 'O'
25
14
  POS_SHORT_MAP = {
26
15
  adj: 'G',
27
16
  adv: 'A',
@@ -34,6 +23,20 @@ module Opener
34
23
  multi_word_expression: 'O',
35
24
  }
36
25
 
26
+ def initialize lang:, lexicons:
27
+ @lang = lang
28
+ @lexicons = lexicons
29
+
30
+ @negators = {}
31
+ @intensifiers = {}
32
+ @with_polarity = {}
33
+ map lexicons
34
+ end
35
+
36
+ def blank?
37
+ @lexicons.blank?
38
+ end
39
+
37
40
  def by_negator lemma
38
41
  @negators[lemma]
39
42
  end
@@ -58,6 +61,8 @@ module Opener
58
61
  protected
59
62
 
60
63
  def map lexicons
64
+ return if blank?
65
+
61
66
  lexicons.each do |l|
62
67
  next if l.lemma.nil?
63
68
 
@@ -12,28 +12,47 @@ module Opener
12
12
  @cache = {}
13
13
  end
14
14
 
15
- def [] lang
15
+ def [] **params
16
16
  synchronize do
17
- @cache[lang] ||= load_lexicons lang
17
+ if existing = @cache[params]
18
+ existing.tap do
19
+ Thread.new{ @cache[params] = cache_update existing, **params }
20
+ end
21
+ else
22
+ @cache[params] = cache_update **params
23
+ end
18
24
  end
19
25
  end
20
26
  alias_method :get, :[]
21
27
 
22
- def load_lexicons lang
23
- lexicons = if @url then load_from_url lang else load_from_path lang end
28
+ def cache_update existing = nil, **params
29
+ from = Time.now
30
+ lexicons = load_lexicons cache: existing, **params
31
+
32
+ return existing if existing and lexicons.blank?
33
+ Hashie::Mash.new(
34
+ lexicons: lexicons,
35
+ from: from,
36
+ )
37
+ end
38
+
39
+ def load_lexicons lang:, **params
40
+ lexicons = if @url then load_from_url lang: lang, **params else load_from_path lang: lang, **params end
24
41
 
25
42
  LexiconMap.new lang: lang, lexicons: lexicons
26
43
  end
27
44
 
28
- def load_from_url lang
29
- url = "#{@url}&language_code=#{lang}"
45
+ def load_from_url lang:, cache:, **params
46
+ url = "#{@url}&language_code=#{lang}&#{params.to_query}"
47
+ url += "&if_updated_since=#{cache.from.iso8601}" if cache
30
48
  puts "#{lang}: loading lexicons from url #{url}"
49
+
31
50
  lexicons = JSON.parse HTTPClient.new.get(url).body
32
51
  lexicons = lexicons['data'].map{ |l| Hashie::Mash.new l }
33
52
  lexicons
34
53
  end
35
54
 
36
- def load_from_path lang
55
+ def load_from_path lang:, **params
37
56
  @path ||= 'core/general-lexicons'
38
57
  dir = "#{@path}/#{lang.upcase}-lexicon"
39
58
  config = Nokogiri::XML File.read "#{dir}/config.xml"
@@ -1,7 +1,7 @@
1
1
  module Opener
2
2
  class PolarityTagger
3
3
 
4
- VERSION = '3.1.3'
4
+ VERSION = '3.2.1'
5
5
 
6
6
  end
7
7
  end
@@ -33,6 +33,7 @@ Gem::Specification.new do |gem|
33
33
  gem.add_dependency 'opener-webservice', '~> 2.1'
34
34
  gem.add_dependency 'opener-core', '~> 2.2'
35
35
 
36
+ gem.add_dependency 'activesupport'
36
37
  gem.add_dependency 'hashie'
37
38
  gem.add_dependency 'rake'
38
39
  gem.add_dependency 'nokogiri'
metadata CHANGED
@@ -1,164 +1,178 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opener-polarity-tagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.3
4
+ version: 3.2.1
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-09-23 00:00:00.000000000 Z
11
+ date: 2020-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: opener-daemons
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
18
  version: '2.2'
20
- type: :runtime
19
+ name: opener-daemons
21
20
  prerelease: false
21
+ type: :runtime
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.2'
27
27
  - !ruby/object:Gem::Dependency
28
- name: opener-webservice
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - "~>"
32
31
  - !ruby/object:Gem::Version
33
32
  version: '2.1'
34
- type: :runtime
33
+ name: opener-webservice
35
34
  prerelease: false
35
+ type: :runtime
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.1'
41
41
  - !ruby/object:Gem::Dependency
42
- name: opener-core
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - "~>"
46
45
  - !ruby/object:Gem::Version
47
46
  version: '2.2'
48
- type: :runtime
47
+ name: opener-core
49
48
  prerelease: false
49
+ type: :runtime
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.2'
55
55
  - !ruby/object:Gem::Dependency
56
- name: hashie
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - ">="
60
59
  - !ruby/object:Gem::Version
61
60
  version: '0'
62
- type: :runtime
61
+ name: activesupport
63
62
  prerelease: false
63
+ type: :runtime
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rake
71
70
  requirement: !ruby/object:Gem::Requirement
72
71
  requirements:
73
72
  - - ">="
74
73
  - !ruby/object:Gem::Version
75
74
  version: '0'
76
- type: :runtime
75
+ name: hashie
77
76
  prerelease: false
77
+ type: :runtime
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: nokogiri
85
84
  requirement: !ruby/object:Gem::Requirement
86
85
  requirements:
87
86
  - - ">="
88
87
  - !ruby/object:Gem::Version
89
88
  version: '0'
90
- type: :runtime
89
+ name: rake
91
90
  prerelease: false
91
+ type: :runtime
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: cliver
99
98
  requirement: !ruby/object:Gem::Requirement
100
99
  requirements:
101
100
  - - ">="
102
101
  - !ruby/object:Gem::Version
103
102
  version: '0'
103
+ name: nokogiri
104
+ prerelease: false
104
105
  type: :runtime
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ name: cliver
105
118
  prerelease: false
119
+ type: :runtime
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - ">="
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
- name: slop
113
126
  requirement: !ruby/object:Gem::Requirement
114
127
  requirements:
115
128
  - - "~>"
116
129
  - !ruby/object:Gem::Version
117
130
  version: '3.5'
118
- type: :runtime
131
+ name: slop
119
132
  prerelease: false
133
+ type: :runtime
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
138
  version: '3.5'
125
139
  - !ruby/object:Gem::Dependency
126
- name: pry
127
140
  requirement: !ruby/object:Gem::Requirement
128
141
  requirements:
129
142
  - - ">="
130
143
  - !ruby/object:Gem::Version
131
144
  version: '0'
132
- type: :development
145
+ name: pry
133
146
  prerelease: false
147
+ type: :development
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
150
  - - ">="
137
151
  - !ruby/object:Gem::Version
138
152
  version: '0'
139
153
  - !ruby/object:Gem::Dependency
140
- name: rspec
141
154
  requirement: !ruby/object:Gem::Requirement
142
155
  requirements:
143
156
  - - "~>"
144
157
  - !ruby/object:Gem::Version
145
158
  version: '3.0'
146
- type: :development
159
+ name: rspec
147
160
  prerelease: false
161
+ type: :development
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
164
  - - "~>"
151
165
  - !ruby/object:Gem::Version
152
166
  version: '3.0'
153
167
  - !ruby/object:Gem::Dependency
154
- name: cucumber
155
168
  requirement: !ruby/object:Gem::Requirement
156
169
  requirements:
157
170
  - - ">="
158
171
  - !ruby/object:Gem::Version
159
172
  version: '0'
160
- type: :development
173
+ name: cucumber
161
174
  prerelease: false
175
+ type: :development
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
178
  - - ">="
@@ -237,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
251
  version: '0'
238
252
  requirements: []
239
253
  rubyforge_project:
240
- rubygems_version: 2.7.8
254
+ rubygems_version: 2.7.9
241
255
  signing_key:
242
256
  specification_version: 4
243
257
  summary: Polarity tagger for various languages.