opener-polarity-tagger 3.1.3 → 3.2.5

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: b4362832bbbb35ee32747d662b0ed336a4999281474b7866c748f392cd7e4850
4
- data.tar.gz: 6882049bcdf93c02dec34023f472691d760f6f200370ba551d59036bf3f3e26b
3
+ metadata.gz: 8a00842dc62bfbc1a0a931ff6a6ebfc547d7beee4ef1b6fda17d7b55448bf480
4
+ data.tar.gz: f3104f7ad025703773ba242e85718ae5a1a69c825884e7603ce757d22158fa7e
5
5
  SHA512:
6
- metadata.gz: af13174d0deb82c077403daadb9ad046e945eae79e24f7cf2a1e50961b1e901ec94553da428057a9eeccaa2c0e5a8e007b28f685874ea21253a8e36701bb7599
7
- data.tar.gz: 3cd67f602a84d8674203579dc8e4bbba271ee49a57c5a34969e0cbef4bc29f32b25393ea0a45c77cff0d518e4355196734055d3f7774140d713bf675d0486fc0
6
+ metadata.gz: ea222d26e37687dd4cba7b6a99990501f282650261aa61ea2d1ca9fe9d77f11331b4b2f8d9db4daa566393a6154c8ba63320373e2d62611619c81242a26a6476
7
+ data.tar.gz: 30fed6d4308d3ee100b017dcd8eff05a04a797bc7c553bd624400e4f8908de42624641fe15475189783033a9fe9d14505d9ce2c0716d006587d7d1deae70200b
@@ -45,7 +45,9 @@ def load_lexicons(language, path=None):
45
45
  def show_lexicons(language, path=None):
46
46
  if path is None:
47
47
  path = __module_dir
48
- lexicons, default_id, this_folder, folder_per_lang = load_lexicons(language, path)
48
+ #lexicons, default_id, this_folder, folder_per_lang = load_lexicons(language, path)
49
+ LexiconSent(language,None,path)
50
+
49
51
  print
50
52
  print '#'*30
51
53
  print 'Available lexicons for',language
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env python
1
+ #!/usr/bin/env python2
2
2
 
3
3
  ##############################
4
4
  #
@@ -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
@@ -32,7 +32,7 @@ module Opener
32
32
  # @return [String]
33
33
  #
34
34
  def command
35
- return "#{adjust_python_path} python -E #{kernel} #{lexicon_path} #{args.join(" ")}"
35
+ "#{adjust_python_path} python2 -E #{kernel} #{lexicon_path} #{args.join(" ")}"
36
36
  end
37
37
 
38
38
  ##
@@ -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,18 @@ 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
+
29
+ raise Opener::Core::UnsupportedLanguageError, kaf.language if @map.blank?
30
+
24
31
  @kaf.terms.each do |t|
25
32
  lemma = t.lemma&.downcase
26
33
  pos = if @ignore_pos then nil else t.pos end
@@ -32,7 +39,6 @@ module Opener
32
39
  attrs.polarity = lexicon.polarity
33
40
  end
34
41
  if l = @map.by_negator(lemma)
35
- negators += 1
36
42
  lexicon, polarity_pos = l, nil
37
43
  attrs.sentiment_modifier = 'shifter'
38
44
  end
@@ -7,8 +7,21 @@ 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'
10
+ UNKNOWN = Hashie::Mash.new polarity: 'unknown'
11
+
12
+ POS_ORDER = 'NRVGAO'
13
+ DEFAULT_POS = 'O'
14
+ POS_SHORT_MAP = {
15
+ adj: 'G',
16
+ adv: 'A',
17
+ noun: 'N',
18
+ propernoun: 'N',
19
+ prep: 'P',
20
+ verb: 'V',
21
+ other: DEFAULT_POS,
22
+ nil => DEFAULT_POS,
23
+ multi_word_expression: DEFAULT_POS,
24
+ }
12
25
 
13
26
  def initialize lang:, lexicons:
14
27
  @lang = lang
@@ -20,19 +33,9 @@ module Opener
20
33
  map lexicons
21
34
  end
22
35
 
23
- DEFAULT_POS = 'O'
24
-
25
- POS_SHORT_MAP = {
26
- adj: 'G',
27
- adv: 'A',
28
- noun: 'N',
29
- propernoun: 'N',
30
- other: 'O',
31
- prep: 'P',
32
- verb: 'V',
33
- nil => DEFAULT_POS,
34
- multi_word_expression: 'O',
35
- }
36
+ def blank?
37
+ @lexicons.blank?
38
+ end
36
39
 
37
40
  def by_negator lemma
38
41
  @negators[lemma]
@@ -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
 
@@ -4,6 +4,8 @@ module Opener
4
4
 
5
5
  include MonitorMixin
6
6
 
7
+ UPDATE_INTERVAL = (ENV['CACHE_EXPIRE_MINS']&.to_i || 5).minutes
8
+
7
9
  def initialize
8
10
  super #MonitorMixin
9
11
 
@@ -12,28 +14,47 @@ module Opener
12
14
  @cache = {}
13
15
  end
14
16
 
15
- def [] lang
17
+ def [] **params
16
18
  synchronize do
17
- @cache[lang] ||= load_lexicons lang
19
+ existing = @cache[params]
20
+ break existing if existing and existing.from > UPDATE_INTERVAL.ago
21
+ @cache[params] = cache_update existing, **params
18
22
  end
19
23
  end
20
24
  alias_method :get, :[]
21
25
 
22
- def load_lexicons lang
23
- lexicons = if @url then load_from_url lang else load_from_path lang end
26
+ def cache_update existing = nil, **params
27
+ from = Time.now
28
+ lexicons = load_lexicons cache: existing, **params
29
+
30
+ if existing and lexicons.blank?
31
+ existing.from = from
32
+ return existing
33
+ end
34
+
35
+ Hashie::Mash.new(
36
+ lexicons: lexicons,
37
+ from: from,
38
+ )
39
+ end
40
+
41
+ def load_lexicons lang:, **params
42
+ lexicons = if @url then load_from_url lang: lang, **params else load_from_path lang: lang, **params end
24
43
 
25
44
  LexiconMap.new lang: lang, lexicons: lexicons
26
45
  end
27
46
 
28
- def load_from_url lang
29
- url = "#{@url}&language_code=#{lang}"
47
+ def load_from_url lang:, cache:, **params
48
+ url = "#{@url}&language_code=#{lang}&#{params.to_query}"
49
+ url += "&if_updated_since=#{cache.from.utc.iso8601}" if cache
30
50
  puts "#{lang}: loading lexicons from url #{url}"
31
- lexicons = JSON.parse HTTPClient.new.get(url).body
51
+
52
+ lexicons = JSON.parse http.get(url).body
32
53
  lexicons = lexicons['data'].map{ |l| Hashie::Mash.new l }
33
54
  lexicons
34
55
  end
35
56
 
36
- def load_from_path lang
57
+ def load_from_path lang:, **params
37
58
  @path ||= 'core/general-lexicons'
38
59
  dir = "#{@path}/#{lang.upcase}-lexicon"
39
60
  config = Nokogiri::XML File.read "#{dir}/config.xml"
@@ -64,6 +85,16 @@ module Opener
64
85
  lexicons
65
86
  end
66
87
 
88
+ def http
89
+ return @http if @http
90
+
91
+ @http = HTTPClient.new
92
+ @http.send_timeout = 120
93
+ @http.receive_timeout = 120
94
+ @http.connect_timeout = 120
95
+ @http
96
+ end
97
+
67
98
  end
68
99
  end
69
100
  end
@@ -1,7 +1,7 @@
1
1
  module Opener
2
2
  class PolarityTagger
3
3
 
4
- VERSION = '3.1.3'
4
+ VERSION = '3.2.5'
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'
@@ -2,6 +2,6 @@ desc 'Verifies the requirements'
2
2
  task :requirements do
3
3
  require 'cliver'
4
4
 
5
- Cliver.detect!('python', '~> 2.6')
6
- Cliver.detect!('pip', '>= 1.3')
5
+ Cliver.detect! 'python2', '~> 2.6'
6
+ Cliver.detect! 'pip2', '>= 1.3'
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.1.3
4
+ version: 3.2.5
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-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opener-daemons
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: hashie
57
71
  requirement: !ruby/object:Gem::Requirement