opener-property-tagger 3.0.6 → 3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/opener/property_tagger.rb +25 -10
- data/lib/opener/property_tagger/{aspects_cache.rb → file_aspects_cache.rb} +6 -6
- data/lib/opener/property_tagger/processor.rb +22 -19
- data/lib/opener/property_tagger/remote_aspects_cache.rb +58 -0
- data/lib/opener/property_tagger/version.rb +5 -3
- data/opener-property-tagger.gemspec +4 -1
- metadata +72 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
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
|
@@ -2,13 +2,18 @@ require 'open3'
|
|
2
2
|
require 'slop'
|
3
3
|
require 'oga'
|
4
4
|
require 'monitor'
|
5
|
+
require 'httpclient'
|
6
|
+
require 'hashie'
|
7
|
+
require 'json'
|
8
|
+
require 'active_support/all'
|
5
9
|
|
6
10
|
require 'rexml/document'
|
7
11
|
require 'rexml/formatters/pretty'
|
8
12
|
|
9
13
|
require_relative 'property_tagger/version'
|
10
14
|
require_relative 'property_tagger/cli'
|
11
|
-
require_relative 'property_tagger/
|
15
|
+
require_relative 'property_tagger/remote_aspects_cache'
|
16
|
+
require_relative 'property_tagger/file_aspects_cache'
|
12
17
|
require_relative 'property_tagger/processor'
|
13
18
|
|
14
19
|
module Opener
|
@@ -43,14 +48,17 @@ module Opener
|
|
43
48
|
# @return [String]
|
44
49
|
#
|
45
50
|
def path
|
46
|
-
path
|
51
|
+
return @path if @path
|
52
|
+
|
53
|
+
@path = options[:resource_path] || ENV['RESOURCE_PATH'] ||
|
47
54
|
ENV['PROPERTY_TAGGER_LEXICONS_PATH']
|
55
|
+
return unless @path
|
48
56
|
|
49
|
-
|
50
|
-
|
51
|
-
end
|
57
|
+
@path = File.expand_path @path
|
58
|
+
end
|
52
59
|
|
53
|
-
|
60
|
+
def remote_url
|
61
|
+
@remote_url ||= ENV['PROPERTY_TAGGER_LEXICONS_URL']
|
54
62
|
end
|
55
63
|
|
56
64
|
##
|
@@ -59,11 +67,18 @@ module Opener
|
|
59
67
|
# @param [String] input
|
60
68
|
# @return [String]
|
61
69
|
#
|
62
|
-
def run
|
70
|
+
def run input, params = {}
|
63
71
|
timestamp = !options[:no_time]
|
64
72
|
|
65
|
-
|
73
|
+
Processor.new(input,
|
74
|
+
params: params,
|
75
|
+
url: remote_url,
|
76
|
+
path: path,
|
77
|
+
timestamp: timestamp,
|
78
|
+
pretty: options[:pretty],
|
79
|
+
).process
|
66
80
|
end
|
67
|
-
|
68
|
-
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
69
84
|
|
@@ -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
|
@@ -22,8 +23,6 @@ module Opener
|
|
22
23
|
synchronize do
|
23
24
|
@cache[path] = load_aspects(path) unless @cache.key?(path)
|
24
25
|
end
|
25
|
-
|
26
|
-
return @cache[path]
|
27
26
|
end
|
28
27
|
|
29
28
|
alias_method :get, :[]
|
@@ -44,6 +43,7 @@ module Opener
|
|
44
43
|
|
45
44
|
return mapping
|
46
45
|
end
|
47
|
-
|
48
|
-
|
49
|
-
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -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
|
-
|
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
|
-
# @return [Opener::PropertyTagger::
|
15
|
+
# @return [Opener::PropertyTagger::FileAspectsCache.new]
|
13
16
|
#
|
14
|
-
|
17
|
+
FILE_ASPECTS_CACHE = FileAspectsCache.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,19 @@ 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
|
24
|
-
@document = Oga.parse_xml
|
25
|
-
|
27
|
+
def initialize file, params: {}, 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
|
-
|
33
|
+
@params = params
|
34
|
+
@cache_keys = params[:cache_keys] || {lang: language}
|
35
|
+
@remote = !url.nil?
|
36
|
+
@aspects_path = path
|
37
|
+
@aspects_url = url
|
38
|
+
|
39
|
+
@aspects = if @remote then REMOTE_ASPECTS_CACHE[**@cache_keys].aspects else FILE_ASPECTS_CACHE[aspects_file] end
|
30
40
|
end
|
31
41
|
|
32
42
|
##
|
@@ -50,13 +60,6 @@ module Opener
|
|
50
60
|
return pretty ? pretty_print(document) : document.to_xml
|
51
61
|
end
|
52
62
|
|
53
|
-
##
|
54
|
-
# @return [Hash]
|
55
|
-
#
|
56
|
-
def aspects
|
57
|
-
return ASPECTS_CACHE[aspects_file]
|
58
|
-
end
|
59
|
-
|
60
63
|
##
|
61
64
|
# Get the language of the input file.
|
62
65
|
#
|
@@ -228,9 +231,9 @@ module Opener
|
|
228
231
|
# @return [String]
|
229
232
|
#
|
230
233
|
def aspects_file
|
231
|
-
|
232
|
-
File.expand_path("#{aspects_path}/#{language}.txt", __FILE__)
|
234
|
+
@aspects_file ||= File.expand_path "#{aspects_path}/#{language}.txt", __FILE__
|
233
235
|
end
|
234
|
-
|
235
|
-
|
236
|
-
end
|
236
|
+
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
@@ -0,0 +1,58 @@
|
|
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 [] **params
|
18
|
+
synchronize do
|
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
|
26
|
+
end
|
27
|
+
end
|
28
|
+
alias_method :get, :[]
|
29
|
+
|
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
|
+
|
46
|
+
lexicons = JSON.parse HTTPClient.new.get(url).body
|
47
|
+
lexicons = lexicons['data'].map{ |l| Hashie::Mash.new l }
|
48
|
+
mapping = Hash.new{ |hash, key| hash[key] = [] }
|
49
|
+
lexicons.each do |l|
|
50
|
+
mapping[l.lemma.to_sym] << l.aspect
|
51
|
+
end
|
52
|
+
|
53
|
+
mapping
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -28,7 +28,10 @@ Gem::Specification.new do |gem|
|
|
28
28
|
gem.add_dependency 'opener-webservice', '~> 2.1'
|
29
29
|
gem.add_dependency 'opener-core', '~> 2.2'
|
30
30
|
|
31
|
-
gem.add_dependency 'oga'
|
31
|
+
gem.add_dependency 'oga', ['~> 1.0', '>= 1.3.1']
|
32
|
+
gem.add_dependency 'httpclient'
|
33
|
+
gem.add_dependency 'hashie'
|
34
|
+
gem.add_dependency 'activesupport'
|
32
35
|
|
33
36
|
gem.add_development_dependency 'rspec', '~> 3.0'
|
34
37
|
gem.add_development_dependency 'cucumber'
|
metadata
CHANGED
@@ -1,129 +1,177 @@
|
|
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
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
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
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.0'
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 1.3.1
|
56
64
|
name: oga
|
65
|
+
prerelease: false
|
66
|
+
type: :runtime
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '1.0'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.3.1
|
75
|
+
- !ruby/object:Gem::Dependency
|
57
76
|
requirement: !ruby/object:Gem::Requirement
|
58
77
|
requirements:
|
59
78
|
- - ">="
|
60
79
|
- !ruby/object:Gem::Version
|
61
80
|
version: '0'
|
81
|
+
name: httpclient
|
82
|
+
prerelease: false
|
62
83
|
type: :runtime
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
requirement: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
name: hashie
|
63
96
|
prerelease: false
|
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
|
110
|
+
prerelease: false
|
111
|
+
type: :runtime
|
64
112
|
version_requirements: !ruby/object:Gem::Requirement
|
65
113
|
requirements:
|
66
114
|
- - ">="
|
67
115
|
- !ruby/object:Gem::Version
|
68
116
|
version: '0'
|
69
117
|
- !ruby/object:Gem::Dependency
|
70
|
-
name: rspec
|
71
118
|
requirement: !ruby/object:Gem::Requirement
|
72
119
|
requirements:
|
73
120
|
- - "~>"
|
74
121
|
- !ruby/object:Gem::Version
|
75
122
|
version: '3.0'
|
76
|
-
|
123
|
+
name: rspec
|
77
124
|
prerelease: false
|
125
|
+
type: :development
|
78
126
|
version_requirements: !ruby/object:Gem::Requirement
|
79
127
|
requirements:
|
80
128
|
- - "~>"
|
81
129
|
- !ruby/object:Gem::Version
|
82
130
|
version: '3.0'
|
83
131
|
- !ruby/object:Gem::Dependency
|
84
|
-
name: cucumber
|
85
132
|
requirement: !ruby/object:Gem::Requirement
|
86
133
|
requirements:
|
87
134
|
- - ">="
|
88
135
|
- !ruby/object:Gem::Version
|
89
136
|
version: '0'
|
90
|
-
|
137
|
+
name: cucumber
|
91
138
|
prerelease: false
|
139
|
+
type: :development
|
92
140
|
version_requirements: !ruby/object:Gem::Requirement
|
93
141
|
requirements:
|
94
142
|
- - ">="
|
95
143
|
- !ruby/object:Gem::Version
|
96
144
|
version: '0'
|
97
145
|
- !ruby/object:Gem::Dependency
|
98
|
-
name: rake
|
99
146
|
requirement: !ruby/object:Gem::Requirement
|
100
147
|
requirements:
|
101
148
|
- - ">="
|
102
149
|
- !ruby/object:Gem::Version
|
103
150
|
version: '0'
|
104
|
-
|
151
|
+
name: rake
|
105
152
|
prerelease: false
|
153
|
+
type: :development
|
106
154
|
version_requirements: !ruby/object:Gem::Requirement
|
107
155
|
requirements:
|
108
156
|
- - ">="
|
109
157
|
- !ruby/object:Gem::Version
|
110
158
|
version: '0'
|
111
159
|
- !ruby/object:Gem::Dependency
|
112
|
-
name: benchmark-ips
|
113
160
|
requirement: !ruby/object:Gem::Requirement
|
114
161
|
requirements:
|
115
162
|
- - "~>"
|
116
163
|
- !ruby/object:Gem::Version
|
117
164
|
version: '2.0'
|
118
|
-
|
165
|
+
name: benchmark-ips
|
119
166
|
prerelease: false
|
167
|
+
type: :development
|
120
168
|
version_requirements: !ruby/object:Gem::Requirement
|
121
169
|
requirements:
|
122
170
|
- - "~>"
|
123
171
|
- !ruby/object:Gem::Version
|
124
172
|
version: '2.0'
|
125
173
|
description: Property tagger for hotels in Dutch and English.
|
126
|
-
email:
|
174
|
+
email:
|
127
175
|
executables:
|
128
176
|
- property-tagger
|
129
177
|
- property-tagger-daemon
|
@@ -139,10 +187,11 @@ files:
|
|
139
187
|
- config.ru
|
140
188
|
- exec/property-tagger.rb
|
141
189
|
- lib/opener/property_tagger.rb
|
142
|
-
- lib/opener/property_tagger/aspects_cache.rb
|
143
190
|
- lib/opener/property_tagger/cli.rb
|
191
|
+
- lib/opener/property_tagger/file_aspects_cache.rb
|
144
192
|
- lib/opener/property_tagger/processor.rb
|
145
193
|
- lib/opener/property_tagger/public/markdown.css
|
194
|
+
- lib/opener/property_tagger/remote_aspects_cache.rb
|
146
195
|
- lib/opener/property_tagger/server.rb
|
147
196
|
- lib/opener/property_tagger/version.rb
|
148
197
|
- lib/opener/property_tagger/views/index.erb
|
@@ -154,7 +203,7 @@ homepage: http://opener-project.github.com/
|
|
154
203
|
licenses:
|
155
204
|
- Apache 2.0
|
156
205
|
metadata: {}
|
157
|
-
post_install_message:
|
206
|
+
post_install_message:
|
158
207
|
rdoc_options: []
|
159
208
|
require_paths:
|
160
209
|
- lib
|
@@ -169,10 +218,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
218
|
- !ruby/object:Gem::Version
|
170
219
|
version: '0'
|
171
220
|
requirements: []
|
172
|
-
rubyforge_project:
|
173
|
-
rubygems_version: 2.
|
174
|
-
signing_key:
|
221
|
+
rubyforge_project:
|
222
|
+
rubygems_version: 2.7.9
|
223
|
+
signing_key:
|
175
224
|
specification_version: 4
|
176
225
|
summary: Property tagger for hotels in Dutch and English.
|
177
226
|
test_files: []
|
178
|
-
has_rdoc:
|