opener-property-tagger 3.2.1 → 3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/opener/property_tagger.rb +4 -2
- data/lib/opener/property_tagger/{aspects_cache.rb → file_aspects_cache.rb} +6 -4
- data/lib/opener/property_tagger/processor.rb +6 -4
- data/lib/opener/property_tagger/remote_aspects_cache.rb +26 -8
- data/lib/opener/property_tagger/version.rb +1 -1
- data/opener-property-tagger.gemspec +1 -0
- metadata +37 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d732e35937583e6fbad1452c2dc72f894df668979a9259c19f4a84a9557b8971
|
4
|
+
data.tar.gz: 6999b3814921c0ec9cefd59b096c89b18c4ac4e9c5a9529f0fa3141c463ea306
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d1d7714bfeab24e5505ea3d442b423ab3fe6daa26dfe214b412add729e2544543d0ccadf078bec3d852bb3fa2b1ec541b131a064b9a2598e38bebbeb58a6061
|
7
|
+
data.tar.gz: 24a4b3b4dcd85edd9249b16e79673487a174c58e7c826820c4b1a67aed56a8f92ec4e228e0d773598b3ed6ce14b5196a2163b48c63646d3442014fcfc2af561c
|
@@ -5,14 +5,15 @@ require 'monitor'
|
|
5
5
|
require 'httpclient'
|
6
6
|
require 'hashie'
|
7
7
|
require 'json'
|
8
|
+
require 'active_support/all'
|
8
9
|
|
9
10
|
require 'rexml/document'
|
10
11
|
require 'rexml/formatters/pretty'
|
11
12
|
|
12
13
|
require_relative 'property_tagger/version'
|
13
14
|
require_relative 'property_tagger/cli'
|
14
|
-
require_relative 'property_tagger/aspects_cache'
|
15
15
|
require_relative 'property_tagger/remote_aspects_cache'
|
16
|
+
require_relative 'property_tagger/file_aspects_cache'
|
16
17
|
require_relative 'property_tagger/processor'
|
17
18
|
|
18
19
|
module Opener
|
@@ -66,10 +67,11 @@ module Opener
|
|
66
67
|
# @param [String] input
|
67
68
|
# @return [String]
|
68
69
|
#
|
69
|
-
def run input
|
70
|
+
def run input, params = {}
|
70
71
|
timestamp = !options[:no_time]
|
71
72
|
|
72
73
|
Processor.new(input,
|
74
|
+
params: params,
|
73
75
|
url: remote_url,
|
74
76
|
path: path,
|
75
77
|
timestamp: timestamp,
|
@@ -3,7 +3,8 @@ module Opener
|
|
3
3
|
##
|
4
4
|
# Thread-safe cache for storing the contents of aspect files.
|
5
5
|
#
|
6
|
-
class
|
6
|
+
class FileAspectsCache
|
7
|
+
|
7
8
|
include MonitorMixin
|
8
9
|
|
9
10
|
def initialize
|
@@ -42,6 +43,7 @@ module Opener
|
|
42
43
|
|
43
44
|
return mapping
|
44
45
|
end
|
45
|
-
|
46
|
-
|
47
|
-
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -12,9 +12,9 @@ module Opener
|
|
12
12
|
##
|
13
13
|
# Global cache used for storing loaded aspects.
|
14
14
|
#
|
15
|
-
# @return [Opener::PropertyTagger::
|
15
|
+
# @return [Opener::PropertyTagger::FileAspectsCache.new]
|
16
16
|
#
|
17
|
-
|
17
|
+
FILE_ASPECTS_CACHE = FileAspectsCache.new
|
18
18
|
REMOTE_ASPECTS_CACHE = RemoteAspectsCache.new
|
19
19
|
|
20
20
|
##
|
@@ -24,17 +24,19 @@ module Opener
|
|
24
24
|
# @param [TrueClass|FalseClass] pretty Enable pretty formatting, disabled
|
25
25
|
# by default due to the performance overhead.
|
26
26
|
#
|
27
|
-
def initialize file, url: nil, path: nil, timestamp: true, pretty: false
|
27
|
+
def initialize file, params: {}, url: nil, path: nil, timestamp: true, pretty: false
|
28
28
|
@document = Oga.parse_xml file
|
29
29
|
raise 'Error parsing input. Input is required to be KAF' unless is_kaf?
|
30
30
|
@timestamp = timestamp
|
31
31
|
@pretty = pretty
|
32
32
|
|
33
|
+
@params = params
|
34
|
+
@cache_keys = params[:cache_keys] || {lang: language}
|
33
35
|
@remote = !url.nil?
|
34
36
|
@aspects_path = path
|
35
37
|
@aspects_url = url
|
36
38
|
|
37
|
-
@aspects = if @remote then REMOTE_ASPECTS_CACHE[
|
39
|
+
@aspects = if @remote then REMOTE_ASPECTS_CACHE[**@cache_keys].aspects else FILE_ASPECTS_CACHE[aspects_file] end
|
38
40
|
end
|
39
41
|
|
40
42
|
##
|
@@ -14,25 +14,43 @@ module Opener
|
|
14
14
|
@cache = {}
|
15
15
|
end
|
16
16
|
|
17
|
-
def []
|
17
|
+
def [] **params
|
18
18
|
synchronize do
|
19
|
-
@cache[
|
19
|
+
if existing = @cache[params]
|
20
|
+
existing.tap do
|
21
|
+
Thread.new{ @cache[params] = cache_update existing, **params }
|
22
|
+
end
|
23
|
+
else
|
24
|
+
@cache[params] = cache_update **params
|
25
|
+
end
|
20
26
|
end
|
21
27
|
end
|
22
28
|
alias_method :get, :[]
|
23
29
|
|
24
|
-
def
|
25
|
-
|
26
|
-
|
30
|
+
def cache_update existing = nil, **params
|
31
|
+
from = Time.now
|
32
|
+
lexicons = load_aspects cache: existing, **params
|
33
|
+
|
34
|
+
return existing if existing and lexicons.blank?
|
35
|
+
Hashie::Mash.new(
|
36
|
+
aspects: lexicons,
|
37
|
+
from: from,
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def load_aspects lang:, cache:, **params
|
42
|
+
url = "#{@url}&language_code=#{lang}&#{params.to_query}"
|
43
|
+
url += "&if_updated_since=#{cache.from.iso8601}" if cache
|
44
|
+
puts "#{lang}: loading aspects from #{url}"
|
45
|
+
|
27
46
|
lexicons = JSON.parse HTTPClient.new.get(url).body
|
28
47
|
lexicons = lexicons['data'].map{ |l| Hashie::Mash.new l }
|
29
|
-
|
30
|
-
|
48
|
+
mapping = Hash.new{ |hash, key| hash[key] = [] }
|
31
49
|
lexicons.each do |l|
|
32
50
|
mapping[l.lemma.to_sym] << l.aspect
|
33
51
|
end
|
34
52
|
|
35
|
-
|
53
|
+
mapping
|
36
54
|
end
|
37
55
|
|
38
56
|
end
|
@@ -31,6 +31,7 @@ Gem::Specification.new do |gem|
|
|
31
31
|
gem.add_dependency 'oga', ['~> 1.0', '>= 1.3.1']
|
32
32
|
gem.add_dependency 'httpclient'
|
33
33
|
gem.add_dependency 'hashie'
|
34
|
+
gem.add_dependency 'activesupport'
|
34
35
|
|
35
36
|
gem.add_development_dependency 'rspec', '~> 3.0'
|
36
37
|
gem.add_development_dependency 'cucumber'
|
metadata
CHANGED
@@ -1,59 +1,58 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opener-property-tagger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.3.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-
|
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
|
-
|
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
|
-
|
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
|
-
|
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: oga
|
57
56
|
requirement: !ruby/object:Gem::Requirement
|
58
57
|
requirements:
|
59
58
|
- - "~>"
|
@@ -62,8 +61,9 @@ dependencies:
|
|
62
61
|
- - ">="
|
63
62
|
- !ruby/object:Gem::Version
|
64
63
|
version: 1.3.1
|
65
|
-
|
64
|
+
name: oga
|
66
65
|
prerelease: false
|
66
|
+
type: :runtime
|
67
67
|
version_requirements: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
69
|
- - "~>"
|
@@ -73,84 +73,98 @@ dependencies:
|
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: 1.3.1
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
|
-
name: httpclient
|
77
76
|
requirement: !ruby/object:Gem::Requirement
|
78
77
|
requirements:
|
79
78
|
- - ">="
|
80
79
|
- !ruby/object:Gem::Version
|
81
80
|
version: '0'
|
82
|
-
|
81
|
+
name: httpclient
|
83
82
|
prerelease: false
|
83
|
+
type: :runtime
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
|
-
name: hashie
|
91
90
|
requirement: !ruby/object:Gem::Requirement
|
92
91
|
requirements:
|
93
92
|
- - ">="
|
94
93
|
- !ruby/object:Gem::Version
|
95
94
|
version: '0'
|
95
|
+
name: hashie
|
96
|
+
prerelease: false
|
96
97
|
type: :runtime
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
requirement: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
name: activesupport
|
97
110
|
prerelease: false
|
111
|
+
type: :runtime
|
98
112
|
version_requirements: !ruby/object:Gem::Requirement
|
99
113
|
requirements:
|
100
114
|
- - ">="
|
101
115
|
- !ruby/object:Gem::Version
|
102
116
|
version: '0'
|
103
117
|
- !ruby/object:Gem::Dependency
|
104
|
-
name: rspec
|
105
118
|
requirement: !ruby/object:Gem::Requirement
|
106
119
|
requirements:
|
107
120
|
- - "~>"
|
108
121
|
- !ruby/object:Gem::Version
|
109
122
|
version: '3.0'
|
110
|
-
|
123
|
+
name: rspec
|
111
124
|
prerelease: false
|
125
|
+
type: :development
|
112
126
|
version_requirements: !ruby/object:Gem::Requirement
|
113
127
|
requirements:
|
114
128
|
- - "~>"
|
115
129
|
- !ruby/object:Gem::Version
|
116
130
|
version: '3.0'
|
117
131
|
- !ruby/object:Gem::Dependency
|
118
|
-
name: cucumber
|
119
132
|
requirement: !ruby/object:Gem::Requirement
|
120
133
|
requirements:
|
121
134
|
- - ">="
|
122
135
|
- !ruby/object:Gem::Version
|
123
136
|
version: '0'
|
124
|
-
|
137
|
+
name: cucumber
|
125
138
|
prerelease: false
|
139
|
+
type: :development
|
126
140
|
version_requirements: !ruby/object:Gem::Requirement
|
127
141
|
requirements:
|
128
142
|
- - ">="
|
129
143
|
- !ruby/object:Gem::Version
|
130
144
|
version: '0'
|
131
145
|
- !ruby/object:Gem::Dependency
|
132
|
-
name: rake
|
133
146
|
requirement: !ruby/object:Gem::Requirement
|
134
147
|
requirements:
|
135
148
|
- - ">="
|
136
149
|
- !ruby/object:Gem::Version
|
137
150
|
version: '0'
|
138
|
-
|
151
|
+
name: rake
|
139
152
|
prerelease: false
|
153
|
+
type: :development
|
140
154
|
version_requirements: !ruby/object:Gem::Requirement
|
141
155
|
requirements:
|
142
156
|
- - ">="
|
143
157
|
- !ruby/object:Gem::Version
|
144
158
|
version: '0'
|
145
159
|
- !ruby/object:Gem::Dependency
|
146
|
-
name: benchmark-ips
|
147
160
|
requirement: !ruby/object:Gem::Requirement
|
148
161
|
requirements:
|
149
162
|
- - "~>"
|
150
163
|
- !ruby/object:Gem::Version
|
151
164
|
version: '2.0'
|
152
|
-
|
165
|
+
name: benchmark-ips
|
153
166
|
prerelease: false
|
167
|
+
type: :development
|
154
168
|
version_requirements: !ruby/object:Gem::Requirement
|
155
169
|
requirements:
|
156
170
|
- - "~>"
|
@@ -173,8 +187,8 @@ files:
|
|
173
187
|
- config.ru
|
174
188
|
- exec/property-tagger.rb
|
175
189
|
- lib/opener/property_tagger.rb
|
176
|
-
- lib/opener/property_tagger/aspects_cache.rb
|
177
190
|
- lib/opener/property_tagger/cli.rb
|
191
|
+
- lib/opener/property_tagger/file_aspects_cache.rb
|
178
192
|
- lib/opener/property_tagger/processor.rb
|
179
193
|
- lib/opener/property_tagger/public/markdown.css
|
180
194
|
- lib/opener/property_tagger/remote_aspects_cache.rb
|
@@ -205,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
205
219
|
version: '0'
|
206
220
|
requirements: []
|
207
221
|
rubyforge_project:
|
208
|
-
rubygems_version: 2.7.
|
222
|
+
rubygems_version: 2.7.9
|
209
223
|
signing_key:
|
210
224
|
specification_version: 4
|
211
225
|
summary: Property tagger for hotels in Dutch and English.
|