interscript 2.1.0rc4 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -6
  3. data/Rakefile +1 -9
  4. data/bin/console +8 -4
  5. data/interscript.gemspec +1 -2
  6. data/lib/interscript/compiler/javascript.rb +1 -6
  7. data/lib/interscript/compiler/ruby.rb +0 -5
  8. data/lib/interscript/dsl/document.rb +1 -2
  9. data/lib/interscript/dsl/group/parallel.rb +2 -2
  10. data/lib/interscript/dsl/group.rb +6 -7
  11. data/lib/interscript/dsl/tests.rb +2 -2
  12. data/lib/interscript/dsl.rb +2 -35
  13. data/lib/interscript/interpreter.rb +1 -5
  14. data/lib/interscript/node/alias_def.rb +0 -6
  15. data/lib/interscript/node/dependency.rb +0 -16
  16. data/lib/interscript/node/document.rb +0 -34
  17. data/lib/interscript/node/group.rb +2 -13
  18. data/lib/interscript/node/item/alias.rb +0 -12
  19. data/lib/interscript/node/item/any.rb +0 -7
  20. data/lib/interscript/node/item/capture.rb +0 -11
  21. data/lib/interscript/node/item/group.rb +1 -29
  22. data/lib/interscript/node/item/repeat.rb +0 -4
  23. data/lib/interscript/node/item/stage.rb +0 -4
  24. data/lib/interscript/node/item/string.rb +0 -7
  25. data/lib/interscript/node/item.rb +0 -4
  26. data/lib/interscript/node/metadata.rb +0 -10
  27. data/lib/interscript/node/rule/funcall.rb +2 -12
  28. data/lib/interscript/node/rule/run.rb +3 -16
  29. data/lib/interscript/node/rule/sub.rb +4 -165
  30. data/lib/interscript/node/rule.rb +0 -3
  31. data/lib/interscript/node/stage.rb +4 -30
  32. data/lib/interscript/node/tests.rb +0 -10
  33. data/lib/interscript/node.rb +0 -4
  34. data/lib/interscript/stdlib.rb +3 -45
  35. data/lib/interscript/version.rb +1 -1
  36. data/lib/interscript/visualize/json.rb +4 -12
  37. data/lib/interscript.rb +0 -78
  38. metadata +3 -19
  39. data/lib/interscript/detector.rb +0 -60
  40. data/lib/interscript/utils/helpers.rb +0 -39
@@ -1,8 +1,7 @@
1
1
  class Interscript::Node::Rule::Run < Interscript::Node::Rule
2
- attr_accessor :stage, :reverse_run
3
- def initialize stage, reverse_run: nil
2
+ attr_accessor :stage
3
+ def initialize stage
4
4
  @stage = stage
5
- @reverse_run = reverse_run
6
5
  end
7
6
 
8
7
  def to_hash
@@ -10,19 +9,7 @@ class Interscript::Node::Rule::Run < Interscript::Node::Rule
10
9
  :stage => self.stage.to_hash }
11
10
  end
12
11
 
13
- def reverse
14
- Interscript::Node::Rule::Run.new(stage,
15
- reverse_run: reverse_run.nil? ? nil : !reverse_run
16
- )
17
- end
18
-
19
- def ==(other)
20
- super && self.stage == other.stage
21
- end
22
-
23
12
  def inspect
24
- out = "run #{@stage.inspect}"
25
- out += ", reverse_run: #{@reverse_run.inspect}" unless reverse_run.nil?
26
- out
13
+ "run #{@stage.inspect}"
27
14
  end
28
15
  end
@@ -1,19 +1,12 @@
1
1
  class Interscript::Node::Rule::Sub < Interscript::Node::Rule
2
2
  attr_accessor :from, :to
3
3
  attr_accessor :before, :not_before, :after, :not_after
4
- attr_accessor :reverse_before, :reverse_not_before, :reverse_after, :reverse_not_after
5
- attr_accessor :reverse_run
6
4
  attr_accessor :priority
7
5
 
8
- def initialize (from, to,
9
- before: nil, not_before: nil,
10
- after: nil, not_after: nil,
11
- priority: nil, reverse_run: nil)
6
+ def initialize from, to, before: nil, not_before: nil, after: nil, not_after: nil, priority: nil
12
7
  self.from = Interscript::Node::Item.try_convert from
13
8
  if to == :upcase
14
9
  self.to = :upcase
15
- elsif to == :downcase
16
- self.to = :downcase
17
10
  else
18
11
  self.to = Interscript::Node::Item.try_convert to
19
12
  end
@@ -23,8 +16,6 @@ class Interscript::Node::Rule::Sub < Interscript::Node::Rule
23
16
  #raise TypeError, "Can't supply both before and not_before" if before && not_before
24
17
  #raise TypeError, "Can't supply both after and not_after" if after && not_after
25
18
 
26
- self.reverse_run = reverse_run
27
-
28
19
  self.before = Interscript::Node::Item.try_convert(before) if before
29
20
  self.after = Interscript::Node::Item.try_convert(after) if after
30
21
  self.not_before = Interscript::Node::Item.try_convert(not_before) if not_before
@@ -46,13 +37,7 @@ class Interscript::Node::Rule::Sub < Interscript::Node::Rule
46
37
  puts params.inspect if $DEBUG
47
38
  hash = { :class => self.class.to_s,
48
39
  :from => self.from.to_hash,
49
- :to => Symbol === self.to ? self.to : self.to.to_hash,
50
- :reverse_run => self.reverse_run,
51
- :before => self.before&.to_hash,
52
- :not_before => self.not_before&.to_hash,
53
- :after => self.after&.to_hash,
54
- :not_after => self.not_after&.to_hash,
55
- :priority => self.priority
40
+ :to => Symbol === self.to ? self.to : self.to.to_hash
56
41
  }
57
42
 
58
43
  hash[:before] = self.before&.to_hash if self.before
@@ -64,165 +49,19 @@ class Interscript::Node::Rule::Sub < Interscript::Node::Rule
64
49
  hash
65
50
  end
66
51
 
67
- def reverse
68
- if to == :upcase
69
- xfrom = from.downcase
70
- xto = :downcase
71
- elsif to == :downcase
72
- xfrom = from.upcase
73
- xto = :upcase
74
- else
75
- xto, xfrom = reverse_transfer(from, to)
76
- end
77
-
78
- # A special case: sub "a", "" shouldn't be present in a reverse map
79
- rrun = self.reverse_run.nil? ? nil : !self.reverse_run
80
- if rrun.nil? && !has_assertions? &&
81
- (xfrom == "" ||
82
- (Interscript::Node::Item::String === xfrom && xfrom.data == '') ||
83
- (Interscript::Node::Item::Alias === xfrom && xfrom.name == :none)
84
- )
85
-
86
- rrun = true
87
- end
88
-
89
- Interscript::Node::Rule::Sub.new(xfrom, xto,
90
- before: before, after: after,
91
- not_before: not_before, not_after: not_after,
92
-
93
- reverse_run: rrun,
94
-
95
- priority: priority ? -priority : nil
96
- )
97
- end
98
-
99
- def has_assertions?
100
- !!(before || not_before || not_after || after)
101
- end
102
-
103
- # Attempt to transfer some references to boundary/line_begin around.
104
- # Those in general should go into before/after clauses, but for now
105
- # let's try to get the best compatibility possible. Also, CaptureGroup,
106
- # CaptureRef need to be shifted around
107
- def reverse_transfer from, to
108
- # This part is about moving initial and final boundary like aliases
109
- case from
110
- when Interscript::Node::Item::Group
111
- first = from.children.first
112
- last = from.children.last
113
-
114
- if Interscript::Node::Item::Alias === first && first.boundary_like?
115
- out = Interscript::Node::Item::Group.new + first + to
116
- to = out.compact
117
-
118
- from = from.dup.tap do |i|
119
- i.children = i.children[1..-1]
120
- end.compact
121
- end
122
-
123
- if Interscript::Node::Item::Alias === last && last.boundary_like?
124
- out = Interscript::Node::Item::Group.new + to + last
125
- to = out.compact
126
-
127
- from = from.dup.tap do |i|
128
- i.children = i.children[0..-2]
129
- end.compact
130
- end
131
- when Interscript::Node::Item::Alias
132
- if from.boundary_like?
133
- to = if from.name.to_s.end_with? "_end"
134
- Interscript::Node::Item::Group.new + to + from
135
- else
136
- Interscript::Node::Item::Group.new + from + to
137
- end
138
- from = Interscript::Node::Item::Alias.new(:none)
139
- end
140
- end
141
-
142
- # This part is about moving backreferences
143
- state = {left:[], right:[]}
144
-
145
- from = reverse_transfer_visit(from, :from, state)
146
- to = reverse_transfer_visit(to, :to, state)
147
-
148
- [from, to]
149
- end
150
-
151
- private def reverse_transfer_visit(node, type, state)
152
- node = Interscript::Node::Item.try_convert(node)
153
-
154
- case node
155
- when Interscript::Node::Item::Alias
156
- if node.name == :kor_maybedash
157
- state[:left] << node
158
- Interscript::Node::Item::CaptureRef.new(state[:left].length)
159
- else
160
- node
161
- end
162
- when Interscript::Node::Item::String
163
- node
164
- when Interscript::Node::Item::Any
165
- if Array === node.value
166
- node.dup.tap do |i|
167
- i.value = i.value.map { |c| reverse_transfer_visit(c, type, state) }
168
- end
169
- else
170
- node
171
- end
172
- when Interscript::Node::Item::Group
173
- node.dup.tap do |i|
174
- i.children = i.children.map { |c| reverse_transfer_visit(c, type, state) }
175
- end
176
- when Interscript::Node::Item::Repeat
177
- node.dup.tap do |i|
178
- i.data = reverse_transfer_visit(i.data, type, state)
179
- end
180
- when Interscript::Node::Item::CaptureRef
181
- if type == :from
182
- node
183
- elsif state[:right][node.id]
184
- node
185
- else
186
- state[:right][node.id] = true
187
- state[:left][node.id - 1] or raise "Capture count doesn't match"
188
- end
189
- when Interscript::Node::Item::CaptureGroup
190
- state[:left] << node
191
- out = Interscript::Node::Item::CaptureRef.new(state[:left].length)
192
- reverse_transfer_visit(node.data, type, state) # Visit but don't care
193
- out
194
- else
195
- raise "Type #{node.class} unhandled!"
196
- end
197
- end
198
-
199
- def ==(other)
200
- super &&
201
- self.from == other.from &&
202
- self.to == other.to &&
203
- self.before == other.before &&
204
- self.after == other.after &&
205
- self.not_before == other.not_before &&
206
- self.not_after == other.not_after &&
207
- self.priority == other.priority
208
- end
209
-
210
52
  def inspect
211
53
  out = "sub "
212
54
  params = []
213
55
  params << @from.inspect
214
- if Symbol === @to
215
- params << @to.to_s
56
+ if @to == :upcase
57
+ params << "upcase"
216
58
  else
217
59
  params << @to.inspect
218
60
  end
219
- params << "reverse_run: #{@reverse_run.inspect}" unless @reverse_run.nil?
220
-
221
61
  params << "before: #{@before.inspect}" if @before
222
62
  params << "after: #{@after.inspect}" if @after
223
63
  params << "not_before: #{@not_before.inspect}" if @not_before
224
64
  params << "not_after: #{@not_after.inspect}" if @not_after
225
-
226
65
  params << "priority: #{@priority.inspect}" if @priority
227
66
  out << params.join(", ")
228
67
  end
@@ -1,7 +1,4 @@
1
1
  class Interscript::Node::Rule < Interscript::Node
2
- def ==(other)
3
- super && self.reverse_run == other.reverse_run
4
- end
5
2
  end
6
3
 
7
4
  require "interscript/node/rule/sub"
@@ -1,11 +1,9 @@
1
1
  class Interscript::Node::Stage < Interscript::Node::Group::Sequential
2
- attr_accessor :name, :doc_name, :dont_reverse
2
+ attr_accessor :name, :doc_name
3
3
 
4
- def initialize(name = :main, reverse_run: nil, doc_name: nil, dont_reverse: false)
4
+ def initialize name = :main
5
5
  @name = name
6
- @doc_name = doc_name
7
- @dont_reverse = dont_reverse
8
- super(reverse_run: reverse_run)
6
+ super()
9
7
  end
10
8
 
11
9
  def to_hash
@@ -14,32 +12,8 @@ class Interscript::Node::Stage < Interscript::Node::Group::Sequential
14
12
  :children => @children.map{|x| x.to_hash} }
15
13
  end
16
14
 
17
- def reverse
18
- return self if dont_reverse
19
-
20
- @reverse ||= begin
21
- self.class.new(name,
22
- doc_name: Interscript::Node::Document.reverse_name(doc_name),
23
- reverse_run: reverse_run.nil? ? nil : !reverse_run
24
- ).tap do |r|
25
- r.children = self.children.reverse.map(&:reverse)
26
- end
27
- end
28
- end
29
-
30
- def ==(other)
31
- super &&
32
- self.name == other.name &&
33
- self.reverse_run == other.reverse_run &&
34
- self.dont_reverse == other.dont_reverse
35
- end
36
-
37
15
  def inspect
38
- args = []
39
- args << "#{@name}" if @name != :main
40
- args << "dont_reverse: true" if dont_reverse
41
- name = ""
42
- name = "(#{args.join(", ")})" unless args.empty?
16
+ name = "(#{@name})" if @name != :main
43
17
  "stage#{name} {\n#{super}\n}"
44
18
  end
45
19
  end
@@ -8,16 +8,6 @@ class Interscript::Node::Tests < Interscript::Node
8
8
  @data << pair
9
9
  end
10
10
 
11
- def reverse
12
- self.class.new(data.map do |from,to,reverse_run|
13
- [to, from, reverse_run == nil ? nil : !reverse_run]
14
- end)
15
- end
16
-
17
- def ==(other)
18
- super && self.data == other.data
19
- end
20
-
21
11
  def to_hash
22
12
  { :class => self.class.to_s,
23
13
  :data => @data }
@@ -4,10 +4,6 @@ class Interscript::Node
4
4
  raise NotImplementedError, "You can't construct a Node directly"
5
5
  end
6
6
 
7
- def ==(other)
8
- self.class == other.class
9
- end
10
-
11
7
  def to_hash
12
8
  { :class => self.class.to_s,
13
9
  :question => "is something missing?"
@@ -22,10 +22,6 @@ class Interscript::Stdlib
22
22
  ! %i[none space].include?(a)
23
23
  end
24
24
 
25
- def self.boundary_like_alias?(a)
26
- %i[line_start line_end string_start string_end boundary non_word_boundary].include?(a)
27
- end
28
-
29
25
  @treecache = {}
30
26
 
31
27
  def self.parallel_regexp_compile(subs_hash)
@@ -171,20 +167,7 @@ class Interscript::Stdlib
171
167
  end
172
168
 
173
169
  def self.available_functions
174
- %i[title_case downcase compose decompose separate unseparate secryst rababa]
175
- end
176
-
177
- def self.reverse_function
178
- {
179
- title_case: :downcase, # Those two are best-effort,
180
- downcase: :title_case, # but probably wrong.
181
-
182
- compose: :decompose,
183
- decompose: :compose,
184
-
185
- separate: :unseparate,
186
- unseparate: :separate
187
- }
170
+ %i[title_case downcase compose decompose separate secryst]
188
171
  end
189
172
 
190
173
  module Functions
@@ -194,13 +177,8 @@ class Interscript::Stdlib
194
177
  output
195
178
  end
196
179
 
197
- def self.downcase(output, word_separator: nil)
198
- if word_separator
199
- output = output.gsub(/^(.)/, &:downcase)
200
- output = output.gsub(/#{word_separator}(.)/, &:downcase) unless word_separator == ''
201
- else
202
- output.downcase
203
- end
180
+ def self.downcase(output, _:nil)
181
+ output.downcase
204
182
  end
205
183
 
206
184
  def self.compose(output, _:nil)
@@ -215,10 +193,6 @@ class Interscript::Stdlib
215
193
  output.split("").join(separator)
216
194
  end
217
195
 
218
- def self.unseparate(output, separator: " ")
219
- output.split(separator).join("")
220
- end
221
-
222
196
  @secryst_models = {}
223
197
  def self.secryst(output, model:)
224
198
  require "secryst" rescue nil # Try to load secryst, but don't fail hard if not possible.
@@ -233,21 +207,5 @@ class Interscript::Stdlib
233
207
  @secryst_models[model].translate(i)
234
208
  end.join("\n")
235
209
  end
236
-
237
- def self.rababa(output, config:)
238
- require "rababa" rescue nil # Try to load rababa, but don't fail hard if not possible.
239
- unless defined? Rababa
240
- raise StandardError, "Rababa is not loaded. Please read docs/Usage_with_Rababa.adoc"
241
- end
242
-
243
- config_value = Interscript.rababa_configs[config]
244
- model_uri = config_value['model']
245
- rababa_config = config_value['config']
246
- model_path = Interscript.rababa_provision(config, model_uri)
247
-
248
- @rababa_diacritizer ||= Rababa::Diacritizer.new(model_path, rababa_config)
249
-
250
- @rababa_diacritizer.diacritize_text(output)
251
- end
252
210
  end
253
211
  end
@@ -1,3 +1,3 @@
1
1
  module Interscript
2
- VERSION = "2.1.0rc4"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -10,7 +10,6 @@ class Interscript::Node::Group
10
10
  more << "after: #{rule.after.to_html(map)}" if rule.after
11
11
  more << "<nobr>not before:</nobr> #{rule.not_before.to_html(map)}" if rule.not_before
12
12
  more << "<nobr>not after:</nobr> #{rule.not_after.to_html(map)}" if rule.not_after
13
- more << "<nobr>reverse run:</nobr> #{rule.reverse_run}" unless rule.reverse_run.nil?
14
13
  more = more.join(", ")
15
14
 
16
15
  out << {
@@ -25,14 +24,11 @@ class Interscript::Node::Group
25
24
  children: rule.to_visualization_array(map)
26
25
  }
27
26
  when Interscript::Node::Rule::Funcall
28
- more = rule.kwargs.map do |k,v|
29
- "#{k.to_s.gsub("_", " ")}: #{v}"
30
- end
31
- more << "<nobr>reverse run:</nobr> #{rule.reverse_run}" unless rule.reverse_run.nil?
32
-
33
27
  out << {
34
28
  type: rule.name.to_s.gsub("_", " ").gsub(/^(.)/, &:upcase),
35
- more: more.join(", ")
29
+ more: rule.kwargs.map do |k,v|
30
+ "#{k.to_s.gsub("_", " ")}: #{v}"
31
+ end.join(", ")
36
32
  }
37
33
  when Interscript::Node::Rule::Run
38
34
  if rule.stage.map
@@ -43,14 +39,10 @@ class Interscript::Node::Group
43
39
  stage = rule.stage.name
44
40
  end
45
41
 
46
- more = []
47
- more << "<nobr>reverse run:</nobr> #{rule.reverse_run}" unless rule.reverse_run.nil?
48
-
49
42
  out << {
50
43
  type: "Run",
51
44
  doc: doc.name,
52
- stage: stage,
53
- more: more.join(", "),
45
+ stage: stage
54
46
  }
55
47
  else
56
48
  out << {
data/lib/interscript.rb CHANGED
@@ -53,16 +53,6 @@ module Interscript
53
53
  output_file
54
54
  end
55
55
 
56
- # Detects the transliteration that gives the most close approximation
57
- # of transliterating source into destination.
58
- #
59
- # Set multiple: true to get a full report.
60
- def detect(source, destination, **kwargs)
61
- detector = Detector.new
62
- detector.set_from_kwargs(**kwargs)
63
- detector.(source, destination)
64
- end
65
-
66
56
  def map_gems
67
57
  @map_gems ||= Gem.find_latest_files('interscript-maps.yaml').map do |i|
68
58
  [i, YAML.load_file(i)]
@@ -86,56 +76,6 @@ module Interscript
86
76
  end.compact.flatten
87
77
  end
88
78
 
89
- def rababa_configs
90
- @rababa_configs ||= map_gems.map do |i,v|
91
- v["rababa-configs"]
92
- end.compact.inject({}) do |a,b|
93
- a.merge(b)
94
- end
95
- end
96
-
97
- # This code is borrowed from Secryst and should end up in Rababa, but for now,
98
- # let's keep it here.
99
- def rababa_provision(model_name, model_uri)
100
- require 'fileutils'
101
- require 'open-uri'
102
-
103
- # We provision the environment in the following way:
104
- # First, we try the RABABA_DATA environment variable. If that's available,
105
- # we use it to store the Rababa data we need. Otherwise, we try the following
106
- # paths:
107
-
108
- possible_paths = [
109
- "/var/lib/rababa",
110
- "/usr/local/share/rababa",
111
- "/usr/share/rababa",
112
- File.join(Dir.home, ".local/share/rababa")
113
- ]
114
-
115
- # We find the first writable path
116
-
117
- write_path = nil
118
-
119
- ([ENV["RABABA_DATA"]] + possible_paths).compact.each do |path|
120
- FileUtils.mkdir_p(path)
121
- write_path = path unless write_path
122
- rescue
123
- end
124
-
125
- raise StandardError, "Can't find a writable path for Rababa. Consider setting a RABABA_DATA environment variable" unless write_path
126
-
127
- model_path = "#{write_path}/model-#{model_name}.onnx"
128
-
129
- # Redownload every hour
130
- if File.exist?(model_path) && File.mtime(model_path) + 3600 >= Time.now
131
- return model_path
132
- else
133
- data = URI.open(model_uri).read
134
- File.write(model_path, data)
135
- return model_path
136
- end
137
- end
138
-
139
79
  def map_aliases
140
80
  return @map_aliases if @map_aliases
141
81
 
@@ -159,22 +99,6 @@ module Interscript
159
99
 
160
100
  basename ? imps.map { |j| File.basename(j, ".#{ext}") } : imps
161
101
  end
162
-
163
- # Removes the excluded maps for a given compiler and RUBY_PLATFORM.
164
- # To be used by tests
165
- # and builders. It uses the `skip` directive in interscript-maps.yaml
166
- def exclude_maps(maps, compiler:, platform: true)
167
- map_gems.each do |i,v|
168
- [compiler.name, (Gem::Platform.local.os if platform)].compact.each do |name|
169
- skips = v.dig('skip', name) || []
170
- skips.each do |skip|
171
- skip_re = /#{Regexp.escape(skip).gsub("\\*", ".*?")}/
172
- maps = maps.grep_v(skip_re)
173
- end
174
- end
175
- end
176
- maps
177
- end
178
102
  end
179
103
  end
180
104
 
@@ -185,5 +109,3 @@ require "interscript/interpreter"
185
109
 
186
110
  require 'interscript/dsl'
187
111
  require 'interscript/node'
188
-
189
- require 'interscript/detector'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interscript
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0rc4
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -26,20 +26,6 @@ dependencies:
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: interscript-maps
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 2.1.0a
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 2.1.0a
41
- - !ruby/object:Gem::Dependency
42
- name: text
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - ">="
@@ -84,7 +70,6 @@ files:
84
70
  - lib/interscript/compiler.rb
85
71
  - lib/interscript/compiler/javascript.rb
86
72
  - lib/interscript/compiler/ruby.rb
87
- - lib/interscript/detector.rb
88
73
  - lib/interscript/dsl.rb
89
74
  - lib/interscript/dsl/aliases.rb
90
75
  - lib/interscript/dsl/document.rb
@@ -119,7 +104,6 @@ files:
119
104
  - lib/interscript/node/stage.rb
120
105
  - lib/interscript/node/tests.rb
121
106
  - lib/interscript/stdlib.rb
122
- - lib/interscript/utils/helpers.rb
123
107
  - lib/interscript/utils/regexp_converter.rb
124
108
  - lib/interscript/version.rb
125
109
  - lib/interscript/visualize.rb
@@ -145,9 +129,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
129
  version: 2.3.0
146
130
  required_rubygems_version: !ruby/object:Gem::Requirement
147
131
  requirements:
148
- - - ">"
132
+ - - ">="
149
133
  - !ruby/object:Gem::Version
150
- version: 1.3.1
134
+ version: '0'
151
135
  requirements: []
152
136
  rubygems_version: 3.1.6
153
137
  signing_key:
@@ -1,60 +0,0 @@
1
- require "text"
2
-
3
- class Interscript::Detector
4
- attr_accessor :compiler
5
- attr_accessor :distance_computer
6
- attr_accessor :map_pattern
7
-
8
- # TODO: use transliterate_each
9
- attr_accessor :each
10
-
11
- attr_accessor :load_path
12
- attr_accessor :cache
13
-
14
- # Returns a summary of all detected transliterations
15
- attr_accessor :multiple
16
-
17
- def initialize
18
- @compiler = Interscript::Interpreter
19
- @distance_computer = DistanceComputer::Levenshtein
20
- @map_pattern = "*"
21
-
22
- @each = false
23
-
24
- @load_path = false
25
- @cache = CACHE
26
- end
27
-
28
- def set_from_kwargs(**kwargs)
29
- kwargs.each do |k,v|
30
- self.public_send(:"#{k}=", v)
31
- end
32
- end
33
-
34
- def call(source, destination)
35
- maps = Interscript.maps(select: @map_pattern, load_path: @load_path)
36
-
37
- summary = maps.map do |map|
38
- try_dest = Interscript.transliterate(map, source, compiler: @compiler)
39
-
40
- [map, try_dest]
41
- end.map do |map, try_dest|
42
- dist = @distance_computer.(try_dest, destination)
43
-
44
- [map, dist]
45
- end.sort_by(&:last).to_h
46
-
47
- if @multiple
48
- summary.to_h
49
- else
50
- summary.first.first
51
- end
52
- end
53
-
54
- CACHE = {}
55
-
56
- # A DistanceComputer needs to respond to #call(source, destination)
57
- module DistanceComputer
58
- Levenshtein = Text::Levenshtein.method(:distance)
59
- end
60
- end