phrase_assembler 1.2.6 → 1.2.7

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.
@@ -9,8 +9,10 @@ module PACsvProxy
9
9
 
10
10
  def to_csv(file_name, options = {})
11
11
  self.current_replace_token = "AAA"
12
- substitute_default_tokens(data, options)
13
- end
12
+ substituted_values = substitute_default_tokens(data, options)
13
+ File.open(file_name, 'w') {|f| f.write(substituted_values) }
14
+ return substituted_values
15
+ end
14
16
 
15
17
  def get_csv_safe_string_line(s)
16
18
  return "\"#{s.gsub('"', '""')}\"\n"
@@ -58,12 +60,22 @@ module PACsvProxy
58
60
  end
59
61
  }
60
62
 
63
+ add_lang_options = {}
61
64
  #Odi po svim vrijednostim za jezik
62
65
  p_data.gsub(/\{\*[^\{\}\*\?]+\?[^\{\}\*:]+(:[^\{\}\*:]+)+\*\}/){|token|
63
66
  clear_token = token[2...-2]
64
67
  key = clear_token[/[^\?]+/]
68
+
69
+ opt_params = key[/\(.+\)/]
70
+ unless opt_params.nil?
71
+ opt_params = opt_params[1...-1].split(',').each{|v|
72
+ add_options[v.strip.to_sym] = 1
73
+ }
74
+ end
75
+
65
76
  key = key[/[^(\(.+\))]+/]
66
77
  keys = key.split('_')
78
+
67
79
  if keys.length <= 1
68
80
  options_key = "default"
69
81
  grammar_key = keys[0]
@@ -71,16 +83,27 @@ module PACsvProxy
71
83
  options_key = keys[0...keys.length-1].join("_")
72
84
  grammar_key = keys[keys.length - 1]
73
85
  end
86
+ add_lang_options["#{options_key}_#{grammar_key}".to_sym] = [] if add_lang_options["#{options_key}_#{grammar_key}".to_sym].nil?
74
87
  self.grammar[grammar_key.to_s.to_sym].keys.sort{|a, b| a.to_s <=> b.to_s}.each{|k|
75
88
  if k == :default
76
- add_options["#{options_key}_#{grammar_key}".to_sym] = nil
89
+ add_lang_options["#{options_key}_#{grammar_key}".to_sym] << nil
77
90
  else
78
- add_options["#{options_key}_#{grammar_key}".to_sym] = k.to_s
91
+ add_lang_options["#{options_key}_#{grammar_key}".to_sym] << k.to_s
79
92
  end
80
- result << get_csv_safe_string_line(substitute_token(String.new(p_data), p_options, PATokenProxyOptions.new_if_needed(add_options)))
81
93
  }
82
94
  }
83
- result << get_csv_safe_string_line(substitute_token(p_data, p_options, PATokenProxyOptions.new_if_needed(add_options))) if result == ""
95
+ unless add_lang_options == {}
96
+ max_length = 0
97
+ add_lang_options.values.each{|v| max_length = v.length if v.length > max_length}
98
+ for i in 0...max_length
99
+ temp_lang_options = {}
100
+ add_lang_options.keys.each{|k| v=add_lang_options[k]; temp_lang_options[k] = v[((i > v.length - 1) ? (v.length - 1) : i)]}
101
+ result << get_csv_safe_string_line(substitute_token(String.new(p_data), p_options, PATokenProxyOptions.new_if_needed(temp_lang_options.merge(add_options))))
102
+ end
103
+ else
104
+ result << get_csv_safe_string_line(substitute_token(p_data, p_options, PATokenProxyOptions.new_if_needed(add_options)))
105
+ end
106
+
84
107
  return result
85
108
  end
86
109
 
@@ -1,3 +1,4 @@
1
+ require 'pa_proxies/pa_composite_proxy'
1
2
  namespace :phrase_assembler do
2
3
  task(:get_csv_file) do
3
4
  if ENV['out'].nil?
@@ -20,9 +21,9 @@ namespace :phrase_assembler do
20
21
  end
21
22
 
22
23
  cache = {}
23
- PACompositeProxy.new(cache)
24
- PACompositeProxy.load(File.join(default_dir, file_name))
25
- PACompositeProxy.load_grammar(File.join(default_dir, grammar_file_name))
26
- PACompositeProxy.to_csv(ENV['out'])
24
+ proxy = PACompositeProxy.new(cache)
25
+ proxy.load(File.join(default_dir, file_name))
26
+ proxy.load_grammar(File.join(default_dir, grammar_file_name))
27
+ proxy.to_csv(ENV['out'])
27
28
  end
28
29
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phrase_assembler
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 6
10
- version: 1.2.6
9
+ - 7
10
+ version: 1.2.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Lovro \xC5\xBDmak, Radan Skori\xC4\x87, Drap"