opener-property-tagger 3.1.1 → 3.2.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
- SHA1:
3
- metadata.gz: 3c33a6b3d4f58d431c9b6eca1c4a4a66239fa651
4
- data.tar.gz: 40f3ca343fe303d8b5bbe69576bafec5e0f555cf
2
+ SHA256:
3
+ metadata.gz: adec67a48fac849987e8347eeb0bc5a304e930ab6fdc604ae7029012c6505868
4
+ data.tar.gz: 9e1dda3b0fecc300a8ef8d4574563cf51e1eb3590601637a0a4d8160bbdccc40
5
5
  SHA512:
6
- metadata.gz: 810e45722da0010b75c49add4d9f83cab411c06b72c458402a6e37997c607c49a107bc874b9dd6f06f5ea61f93c7c2e155e03e1c234ba6aa567bc86f9ca2a8c4
7
- data.tar.gz: 01dd805a7355cd5109cc61085ca2a564bb5a81a5a1cdf8f90f2d8b199a18f1c4d69e9f263b8fc9872e918bd10e74e6a2ba9a18103e59287ccd52441cf5885488
6
+ metadata.gz: e15b757610a466b6bc1b15e7afcb2c207874c9f696a375a2f56630c88a686f9990a362422a76835685b06a6a6fce32130565fe37e27ca1f1c818ae8a263fe86e
7
+ data.tar.gz: a4ce0b27abba305fe0b440a6cb26fce829ceea37e775325be22aad5cc6efb6b45fe161ceb38e407040fb014881683ce0981f56b4defab07862fb81e539102588
@@ -2,6 +2,9 @@ require 'open3'
2
2
  require 'slop'
3
3
  require 'oga'
4
4
  require 'monitor'
5
+ require 'httpclient'
6
+ require 'hashie'
7
+ require 'json'
5
8
 
6
9
  require 'rexml/document'
7
10
  require 'rexml/formatters/pretty'
@@ -9,6 +12,7 @@ require 'rexml/formatters/pretty'
9
12
  require_relative 'property_tagger/version'
10
13
  require_relative 'property_tagger/cli'
11
14
  require_relative 'property_tagger/aspects_cache'
15
+ require_relative 'property_tagger/remote_aspects_cache'
12
16
  require_relative 'property_tagger/processor'
13
17
 
14
18
  module Opener
@@ -43,14 +47,20 @@ module Opener
43
47
  # @return [String]
44
48
  #
45
49
  def path
46
- path = options[:resource_path] || ENV['RESOURCE_PATH'] ||
50
+ return @path if @path
51
+
52
+ @path = options[:resource_path] || ENV['RESOURCE_PATH'] ||
47
53
  ENV['PROPERTY_TAGGER_LEXICONS_PATH']
48
54
 
49
- unless path
55
+ unless @path
50
56
  raise ArgumentError, 'No lexicon path provided'
51
57
  end
52
58
 
53
- return File.expand_path(path)
59
+ @path = File.expand_path @path
60
+ end
61
+
62
+ def remote_url
63
+ @remote_url ||= ENV['PROPERTY_TAGGER_LEXICONS_URL']
54
64
  end
55
65
 
56
66
  ##
@@ -59,11 +69,17 @@ module Opener
59
69
  # @param [String] input
60
70
  # @return [String]
61
71
  #
62
- def run(input)
72
+ def run input
63
73
  timestamp = !options[:no_time]
64
74
 
65
- return Processor.new(input, path, timestamp, options[:pretty]).process
75
+ Processor.new(input,
76
+ url: remote_url,
77
+ path: path,
78
+ timestamp: timestamp,
79
+ pretty: options[:pretty],
80
+ ).process
66
81
  end
67
- end # PolarityTagger
68
- end # Opener
82
+
83
+ end
84
+ end
69
85
 
@@ -22,8 +22,6 @@ module Opener
22
22
  synchronize do
23
23
  @cache[path] = load_aspects(path) unless @cache.key?(path)
24
24
  end
25
-
26
- return @cache[path]
27
25
  end
28
26
 
29
27
  alias_method :get, :[]
@@ -4,14 +4,18 @@ module Opener
4
4
  # Class that applies property tagging to a given input KAF file.
5
5
  #
6
6
  class Processor
7
- attr_accessor :document, :aspects_path, :timestamp, :pretty
7
+
8
+ attr_accessor :document
9
+ attr_accessor :aspects, :aspects_path, :aspects_url
10
+ attr_accessor :timestamp, :pretty
8
11
 
9
12
  ##
10
13
  # Global cache used for storing loaded aspects.
11
14
  #
12
15
  # @return [Opener::PropertyTagger::AspectsCache.new]
13
16
  #
14
- ASPECTS_CACHE = AspectsCache.new
17
+ ASPECTS_CACHE = AspectsCache.new
18
+ REMOTE_ASPECTS_CACHE = RemoteAspectsCache.new
15
19
 
16
20
  ##
17
21
  # @param [String|IO] file The KAF file/input to process.
@@ -20,13 +24,17 @@ module Opener
20
24
  # @param [TrueClass|FalseClass] pretty Enable pretty formatting, disabled
21
25
  # by default due to the performance overhead.
22
26
  #
23
- def initialize(file, aspects_path, timestamp = true, pretty = false)
24
- @document = Oga.parse_xml(file)
25
- @aspects_path = aspects_path
27
+ def initialize file, url: nil, path: nil, timestamp: true, pretty: false
28
+ @document = Oga.parse_xml file
29
+ raise 'Error parsing input. Input is required to be KAF' unless is_kaf?
26
30
  @timestamp = timestamp
27
31
  @pretty = pretty
28
32
 
29
- raise 'Error parsing input. Input is required to be KAF' unless is_kaf?
33
+ @remote = !url.nil?
34
+ @aspects_path = path
35
+ @aspects_url = url
36
+
37
+ @aspects = if @remote then REMOTE_ASPECTS_CACHE[language] else ASPECTS_CACHE[aspects_file] end
30
38
  end
31
39
 
32
40
  ##
@@ -50,13 +58,6 @@ module Opener
50
58
  return pretty ? pretty_print(document) : document.to_xml
51
59
  end
52
60
 
53
- ##
54
- # @return [Hash]
55
- #
56
- def aspects
57
- return ASPECTS_CACHE[aspects_file]
58
- end
59
-
60
61
  ##
61
62
  # Get the language of the input file.
62
63
  #
@@ -228,9 +229,9 @@ module Opener
228
229
  # @return [String]
229
230
  #
230
231
  def aspects_file
231
- return @aspects_file ||=
232
- File.expand_path("#{aspects_path}/#{language}.txt", __FILE__)
232
+ @aspects_file ||= File.expand_path "#{aspects_path}/#{language}.txt", __FILE__
233
233
  end
234
- end # Processor
235
- end # PropertyTagger
236
- end # Opener
234
+
235
+ end
236
+ end
237
+ end
@@ -0,0 +1,39 @@
1
+ module Opener
2
+ class PropertyTagger
3
+ ##
4
+ # Thread-safe cache for storing the contents of remote aspects.
5
+ #
6
+ class RemoteAspectsCache
7
+
8
+ include MonitorMixin
9
+
10
+ def initialize
11
+ super
12
+
13
+ @url = ENV['PROPERTY_TAGGER_LEXICONS_URL']
14
+ @cache = {}
15
+ end
16
+
17
+ def [] lang
18
+ synchronize do
19
+ @cache[lang] ||= load_aspects lang
20
+ end
21
+ end
22
+ alias_method :get, :[]
23
+
24
+ def load_aspects lang
25
+ mapping = Hash.new{ |hash, key| hash[key] = [] }
26
+ url = "#{@url}&language_code=#{lang}"
27
+ lexicons = JSON.parse HTTPClient.new.get(url).body
28
+ lexicons = lexicons['data'].map{ |l| Hashie::Mash.new l }
29
+
30
+ lexicons.each do |l|
31
+ mapping[l.lemma.to_sym] << l.aspect
32
+ end
33
+
34
+ return mapping
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -1,5 +1,7 @@
1
1
  module Opener
2
2
  class PropertyTagger
3
- VERSION = '3.1.1'
4
- end # PropertyTagger
5
- end # Opener
3
+
4
+ VERSION = '3.2.0'
5
+
6
+ end
7
+ end
@@ -29,6 +29,8 @@ Gem::Specification.new do |gem|
29
29
  gem.add_dependency 'opener-core', '~> 2.2'
30
30
 
31
31
  gem.add_dependency 'oga', ['~> 1.0', '>= 1.3.1']
32
+ gem.add_dependency 'httpclient'
33
+ gem.add_dependency 'hashie'
32
34
 
33
35
  gem.add_development_dependency 'rspec', '~> 3.0'
34
36
  gem.add_development_dependency 'cucumber'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opener-property-tagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - development@olery.com
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-07 00:00:00.000000000 Z
11
+ date: 2020-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opener-daemons
@@ -72,6 +72,34 @@ dependencies:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: 1.3.1
75
+ - !ruby/object:Gem::Dependency
76
+ name: httpclient
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: hashie
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
75
103
  - !ruby/object:Gem::Dependency
76
104
  name: rspec
77
105
  requirement: !ruby/object:Gem::Requirement
@@ -129,7 +157,7 @@ dependencies:
129
157
  - !ruby/object:Gem::Version
130
158
  version: '2.0'
131
159
  description: Property tagger for hotels in Dutch and English.
132
- email:
160
+ email:
133
161
  executables:
134
162
  - property-tagger
135
163
  - property-tagger-daemon
@@ -149,6 +177,7 @@ files:
149
177
  - lib/opener/property_tagger/cli.rb
150
178
  - lib/opener/property_tagger/processor.rb
151
179
  - lib/opener/property_tagger/public/markdown.css
180
+ - lib/opener/property_tagger/remote_aspects_cache.rb
152
181
  - lib/opener/property_tagger/server.rb
153
182
  - lib/opener/property_tagger/version.rb
154
183
  - lib/opener/property_tagger/views/index.erb
@@ -160,7 +189,7 @@ homepage: http://opener-project.github.com/
160
189
  licenses:
161
190
  - Apache 2.0
162
191
  metadata: {}
163
- post_install_message:
192
+ post_install_message:
164
193
  rdoc_options: []
165
194
  require_paths:
166
195
  - lib
@@ -175,10 +204,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
204
  - !ruby/object:Gem::Version
176
205
  version: '0'
177
206
  requirements: []
178
- rubyforge_project:
179
- rubygems_version: 2.4.8
180
- signing_key:
207
+ rubyforge_project:
208
+ rubygems_version: 2.7.8
209
+ signing_key:
181
210
  specification_version: 4
182
211
  summary: Property tagger for hotels in Dutch and English.
183
212
  test_files: []
184
- has_rdoc: