opener-chained-daemon 3.0.7 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f37e21fff5f35b6736a17e4d4efcad5d496c1c2ec63e74c7b8907db45210770
4
- data.tar.gz: 6e3b80ba665a950407b1c4bcba9e0f6074db41db86b2da233b21c1db638c792f
3
+ metadata.gz: 92671af787870253fad869667e547f56aa24f29880c823ba67076d1d4ec3fb11
4
+ data.tar.gz: ee03e7f43f81f869552725ebcb3f9067338657042d33f6583f9cef0932f46ec1
5
5
  SHA512:
6
- metadata.gz: 5738bfe0a4dbf5ff66010a9aa54ef7de4e951e7728d753000b99effbb0f4c17884791a8eb6c58fcfcafd51f0ba94520148f6d3699dd592c74145766e2c06917f
7
- data.tar.gz: 7100f63ac6fd859b98f28eac22dd73e60419f21fc40e3b59c34c6550915182ca0598eb74f2ec9eddaa870fd4b91f94b31a694f70fc62ed20307b1415c0e82804
6
+ metadata.gz: 6d9ecd68a2aebcef5531d70a7334126b8995ce93da7963408b953b5901c092ff1c23df467ab99970d4cb53ff950bfc6e47cde47344403e02145e06e149c614ad
7
+ data.tar.gz: 8852fb0af7e6b17156ca28ba57abad4b0e5d03a9d13bd64836165749a761bb996a5f6a431954f04b7246ffddd080bbc9499599c50570eb29e3e6f1d9b26be81f
@@ -3,6 +3,9 @@ require 'oga'
3
3
  require 'hashie'
4
4
  require 'google/cloud/translate'
5
5
 
6
+ require 'rexml/document'
7
+ require 'rexml/formatters/pretty'
8
+
6
9
  require 'opener/daemons'
7
10
 
8
11
  require_relative 'chained_daemon/languages_cache'
@@ -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
- params = JSON.parse ENV['PARAMS'] if ENV['PARAMS']
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
@@ -1,7 +1,7 @@
1
1
  module Opener
2
2
  class ChainedDaemon
3
3
 
4
- VERSION = '3.0.7'
4
+ VERSION = '3.1.0'
5
5
 
6
6
  end
7
7
  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',
@@ -46,14 +49,23 @@ module Opener
46
49
  tokens = JSON.parse response.body
47
50
 
48
51
  w_index = 0
52
+
53
+ tokens.map{ |t| t.reverse! } if RTL_LANGUAGES.include? kaf.language
49
54
  tokens.each_with_index do |sentence, s_index|
55
+ text = nil
56
+ misc = nil
50
57
  sentence.each_with_index do |word|
51
58
  w_index += 1
52
- misc = word['misc']
59
+ # fallback to previous token due to MWT
60
+ text = word['text'] || text
61
+ misc = word['misc'] || misc
62
+ next if misc.nil?
63
+
53
64
  offset = misc.match(/start_char=(\d+)|/)[1].to_i
54
65
  length = misc.match(/end_char=(\d+)/)[1].to_i - offset
55
66
 
56
67
  u_pos = word['upos']
68
+ next if u_pos.nil? # MWT
57
69
  pos = POS[u_pos]
58
70
  raise "Didn't find a map for #{u_pos}" if pos.nil?
59
71
  type = if POS_OPEN.include? pos then 'open' else 'close' end
@@ -65,7 +77,7 @@ module Opener
65
77
  para: 1,
66
78
  offset: offset,
67
79
  length: length,
68
- text: word['text'],
80
+ text: text,
69
81
  lemma: word['lemma'],
70
82
  morphofeat: u_pos,
71
83
  pos: pos,
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.0.7
4
+ version: 3.1.0
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 00:00:00.000000000 Z
11
+ date: 2020-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -308,9 +308,9 @@ description: OpeNER daemon for processing multiple queues at once
308
308
  email:
309
309
  executables:
310
310
  - chained-daemon
311
- - chained-daemon-daemon
312
311
  - chained-daemon-csv
313
312
  - console
313
+ - chained-daemon-daemon
314
314
  extensions: []
315
315
  extra_rdoc_files: []
316
316
  files:
@@ -352,7 +352,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
352
352
  version: '0'
353
353
  requirements: []
354
354
  rubyforge_project:
355
- rubygems_version: 2.7.6.2
355
+ rubygems_version: 2.7.8
356
356
  signing_key:
357
357
  specification_version: 4
358
358
  summary: OpeNER daemon for processing multiple queues at once