opener-chained-daemon 3.0.7 → 3.1.4
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f4ae996f2569fd72fbb224a89aa6f1bd6335419a514db0714858e9c60e51511
|
4
|
+
data.tar.gz: ce58d5715abd85083f70e2b6bb7789581f7007a3be4583050af0c401c61a224e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cfb8fc04839f942f05d182bbac523764502a8f204679bf81515272839763572d72707ec9156f662f1538149a7f20b79741e3ad941b7da98bdb1ab0a7dcfd82b
|
7
|
+
data.tar.gz: 6d03594f42b21240fc2210747884cd0de4296c469b581561b9c3845a86cb2696265052cae19002c7e1308cc28ab118927c2978ff67e88e6ea7e57dba2eceefaf
|
@@ -47,6 +47,7 @@ module Opener
|
|
47
47
|
output = xml.to_s
|
48
48
|
end
|
49
49
|
|
50
|
+
output = pretty_print output if params[:cache_keys][:environment] == 'staging'
|
50
51
|
output
|
51
52
|
|
52
53
|
rescue Core::UnsupportedLanguageError
|
@@ -54,6 +55,17 @@ module Opener
|
|
54
55
|
output
|
55
56
|
end
|
56
57
|
|
58
|
+
def pretty_print(output)
|
59
|
+
doc = REXML::Document.new output
|
60
|
+
doc.context[:attribute_quote] = :quote
|
61
|
+
out = ""
|
62
|
+
formatter = REXML::Formatters::Pretty.new
|
63
|
+
formatter.compact = true
|
64
|
+
formatter.write(doc, out)
|
65
|
+
|
66
|
+
out.strip
|
67
|
+
end
|
68
|
+
|
57
69
|
def translate xml, params
|
58
70
|
raw = xml.at :raw
|
59
71
|
case translate_service params
|
@@ -47,7 +47,14 @@ Example:
|
|
47
47
|
run do |opts, args|
|
48
48
|
daemon = ChainedDaemon.new args: args
|
49
49
|
input = STDIN.tty? ? nil : STDIN.read
|
50
|
-
|
50
|
+
|
51
|
+
params = if ENV['PARAMS']
|
52
|
+
JSON.parse ENV['PARAMS']
|
53
|
+
else
|
54
|
+
{}
|
55
|
+
end
|
56
|
+
# Set environment as staging from console for testing purposes
|
57
|
+
params[:cache_keys] = { environment: 'staging', merged: true }
|
51
58
|
|
52
59
|
puts daemon.run input, params || {}
|
53
60
|
end
|
@@ -8,6 +8,9 @@ module Opener
|
|
8
8
|
BASE_URL = ENV['STANZA_SERVER']
|
9
9
|
LANGUAGES_CACHE = Opener::ChainedDaemon::LanguagesCache.new
|
10
10
|
|
11
|
+
RTL_LANGUAGES = [ "ar", "ara", "arc", "ae", "ave", "egy", "he", "heb", "nqo", "pal", "phn", "sam",
|
12
|
+
"syc", "syr", "fa", "per", "fas", "ku", "kur", "ur", "urd" ]
|
13
|
+
|
11
14
|
POS = {
|
12
15
|
'DET' => 'D',
|
13
16
|
'ADJ' => 'G',
|
@@ -40,16 +43,31 @@ module Opener
|
|
40
43
|
raise Core::UnsupportedLanguageError.new kaf.language
|
41
44
|
end
|
42
45
|
|
43
|
-
|
46
|
+
input = kaf.raw
|
47
|
+
input = input.gsub(/\,[^\ ]/, ', ')
|
48
|
+
response = Faraday.post BASE_URL, {lang: kaf.language, input: input}.to_query
|
44
49
|
raise Core::UnsupportedLanguageError, kaf.language if response.status == 406
|
45
50
|
raise response.body if response.status >= 400
|
46
51
|
tokens = JSON.parse response.body
|
47
52
|
|
48
53
|
w_index = 0
|
54
|
+
|
55
|
+
tokens.map{ |t| t.reverse! } if RTL_LANGUAGES.include? kaf.language
|
49
56
|
tokens.each_with_index do |sentence, s_index|
|
57
|
+
miscs = {}
|
50
58
|
sentence.each_with_index do |word|
|
51
59
|
w_index += 1
|
52
|
-
misc
|
60
|
+
# save misc for later usase in a MWT case
|
61
|
+
if word['id'].is_a? Array
|
62
|
+
word['id'].each { |id| miscs[id] = word['misc'] }
|
63
|
+
next
|
64
|
+
end
|
65
|
+
misc = word['misc'] || miscs[word['id']]
|
66
|
+
|
67
|
+
Rollbar.scoped({ input: input, params: params, tokens: tokens, word: word }) do
|
68
|
+
raise 'Missing misc'
|
69
|
+
end if misc.nil?
|
70
|
+
|
53
71
|
offset = misc.match(/start_char=(\d+)|/)[1].to_i
|
54
72
|
length = misc.match(/end_char=(\d+)/)[1].to_i - offset
|
55
73
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opener-chained-daemon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.4
|
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-
|
11
|
+
date: 2020-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|