interscript 2.2.1 → 2.3.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: 2088a63470d6a75261e2a774c73cf30b33e06e69b91d679b0eef5d7431197ef0
4
- data.tar.gz: fafd8fa34f47f600c1dc0f7d8da2628a264aec9c5387b21bbcf483e9606c915f
3
+ metadata.gz: 9dd918129c2ea6f94d0bf346869fe9a4baca90e7b59524787ebe5fe58c22a1af
4
+ data.tar.gz: 7ab737080e82d26da28b631ba46fc75547b8492b250841dc5a8e8527f6b73736
5
5
  SHA512:
6
- metadata.gz: b9e25faac07f4c517c291a7fd61ab435b70c84e0e9404b6cc4da8196e044e603ed6475d66d20f36d48fb75b8117d454dd1fce61244dafd99f588298fcbd96844
7
- data.tar.gz: 95c6a784bcca66f9b05f39260c2dd5a6a4a945f044c955d518d661381eb8de0610be7f7ec029fe923273f6624933f5affd7f825d94b80b838866f35fd7797d15
6
+ metadata.gz: f47f197ec26a7df2dfd49ecee799c33bb8f78cee4e6453cfc191fd165c9fa8925ebca1612c4305469a5ece2ee904e81d2a6e8d6d49bcd7e5f983d9890ac4ff9e
7
+ data.tar.gz: c4a3d287564512c48c25069100dbfce537939c339e9289d894cf55d48af25e980f48f744161fd57bc44eb8af345d659ed703da9981cdb99bd819c9c00960c8c7
data/Gemfile CHANGED
@@ -26,6 +26,10 @@ unless ENV["SKIP_JS"]
26
26
  end
27
27
  end
28
28
 
29
+ group :rababa do
30
+ gem 'rababa', github: 'interscript/rababa', ref: '70051da'
31
+ end
32
+
29
33
  gem 'pry'
30
34
 
31
35
  gem 'simplecov', require: false, group: :test
data/Rakefile CHANGED
@@ -20,7 +20,10 @@ task :compile, [:compiler, :target] do |t, args|
20
20
 
21
21
  maplist = {}
22
22
 
23
- Interscript.maps.each do |map|
23
+ maps = Interscript.maps
24
+ maps = Interscript.exclude_maps(maps, compiler: compiler, platform: false)
25
+
26
+ maps.each do |map|
24
27
  code = compiler.(map).code
25
28
  File.write(args[:target] + "/" + map + "." + ext, code)
26
29
  maplist[map] = nil
@@ -68,6 +71,7 @@ task :generate_metadata_json do
68
71
  require "fileutils"
69
72
  require "json"
70
73
  require "interscript"
74
+ require "interscript/compiler/javascript"
71
75
 
72
76
  FileUtils.rm_rf(file = __dir__+"/metadata.json")
73
77
 
@@ -75,6 +79,10 @@ task :generate_metadata_json do
75
79
  parsed_map = Interscript.parse(map)
76
80
  md = parsed_map.metadata.to_hash
77
81
  md["test"] = parsed_map.tests&.data&.first
82
+ md["skip_js"] = Interscript.exclude_maps([map],
83
+ compiler: Interscript::Compiler::Javascript,
84
+ platform: false,
85
+ ).empty?
78
86
  [map, md]
79
87
  end.to_h
80
88
 
data/interscript.gemspec CHANGED
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
27
27
  spec.require_paths = ["lib"]
28
28
 
29
29
  spec.add_dependency "thor"
30
- spec.add_dependency "interscript-maps", "~> #{Interscript::VERSION.split('.')[0,2].join(".")}.0"
30
+ spec.add_dependency "interscript-maps", "~> #{Interscript::VERSION.split('.')[0,2].join(".")}.0a"
31
31
  spec.add_dependency "text"
32
32
  end
data/lib/interscript.rb CHANGED
@@ -86,6 +86,56 @@ module Interscript
86
86
  end.compact.flatten
87
87
  end
88
88
 
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
+
89
139
  def map_aliases
90
140
  return @map_aliases if @map_aliases
91
141
 
@@ -109,6 +159,22 @@ module Interscript
109
159
 
110
160
  basename ? imps.map { |j| File.basename(j, ".#{ext}") } : imps
111
161
  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
112
178
  end
113
179
  end
114
180
 
@@ -37,10 +37,11 @@ class Interscript::DSL::Document
37
37
  @node.dep_aliases[dep.name] = dep if dep.name
38
38
  end
39
39
 
40
- def stage(name = :main, &block)
40
+ def stage(name = :main, dont_reverse: false, &block)
41
41
  puts "stage(#{name}) from #{self.inspect}" if $DEBUG
42
42
  stage = Interscript::DSL::Stage.new(name, &block)
43
43
  stage.node.doc_name = @node.name
44
+ stage.node.dont_reverse = dont_reverse
44
45
  @node.stages[name] = stage.node
45
46
  end
46
47
  end
@@ -6,7 +6,7 @@ class Interscript::DSL::Tests
6
6
  self.instance_exec(&block)
7
7
  end
8
8
 
9
- def test(from,to)
10
- @node << [from, to]
9
+ def test(from, to, reverse_run: nil)
10
+ @node << [from, to, reverse_run]
11
11
  end
12
12
  end
@@ -1,6 +1,7 @@
1
1
  class Interscript::Node::Document
2
2
  attr_accessor :metadata, :tests, :name
3
3
  attr_accessor :dependencies, :aliases, :stages, :dep_aliases
4
+ attr_accessor :reversed_from
4
5
 
5
6
  def initialize
6
7
  puts "Interscript::Node::Document.new " if $DEBUG
@@ -1,9 +1,10 @@
1
1
  class Interscript::Node::Stage < Interscript::Node::Group::Sequential
2
- attr_accessor :name, :doc_name
2
+ attr_accessor :name, :doc_name, :dont_reverse
3
3
 
4
- def initialize(name = :main, reverse_run: nil, doc_name: nil)
4
+ def initialize(name = :main, reverse_run: nil, doc_name: nil, dont_reverse: false)
5
5
  @name = name
6
6
  @doc_name = doc_name
7
+ @dont_reverse = dont_reverse
7
8
  super(reverse_run: reverse_run)
8
9
  end
9
10
 
@@ -14,6 +15,8 @@ class Interscript::Node::Stage < Interscript::Node::Group::Sequential
14
15
  end
15
16
 
16
17
  def reverse
18
+ return self if dont_reverse
19
+
17
20
  @reverse ||= begin
18
21
  self.class.new(name,
19
22
  doc_name: Interscript::Node::Document.reverse_name(doc_name),
@@ -27,11 +30,16 @@ class Interscript::Node::Stage < Interscript::Node::Group::Sequential
27
30
  def ==(other)
28
31
  super &&
29
32
  self.name == other.name &&
30
- self.reverse_run == other.reverse_run
33
+ self.reverse_run == other.reverse_run &&
34
+ self.dont_reverse == other.dont_reverse
31
35
  end
32
36
 
33
37
  def inspect
34
- name = "(#{@name})" if @name != :main
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?
35
43
  "stage#{name} {\n#{super}\n}"
36
44
  end
37
45
  end
@@ -9,7 +9,9 @@ class Interscript::Node::Tests < Interscript::Node
9
9
  end
10
10
 
11
11
  def reverse
12
- self.class.new(data.map(&:reverse))
12
+ self.class.new(data.map do |from,to,reverse_run|
13
+ [to, from, reverse_run == nil ? nil : !reverse_run]
14
+ end)
13
15
  end
14
16
 
15
17
  def ==(other)
@@ -171,7 +171,7 @@ class Interscript::Stdlib
171
171
  end
172
172
 
173
173
  def self.available_functions
174
- %i[title_case downcase compose decompose separate unseparate secryst]
174
+ %i[title_case downcase compose decompose separate unseparate secryst rababa]
175
175
  end
176
176
 
177
177
  def self.reverse_function
@@ -233,5 +233,21 @@ class Interscript::Stdlib
233
233
  @secryst_models[model].translate(i)
234
234
  end.join("\n")
235
235
  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
236
252
  end
237
253
  end
@@ -1,3 +1,3 @@
1
1
  module Interscript
2
- VERSION = "2.2.1"
2
+ VERSION = "2.3.0"
3
3
  end
@@ -10,6 +10,7 @@ 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?
13
14
  more = more.join(", ")
14
15
 
15
16
  out << {
@@ -24,11 +25,14 @@ class Interscript::Node::Group
24
25
  children: rule.to_visualization_array(map)
25
26
  }
26
27
  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
+
27
33
  out << {
28
34
  type: rule.name.to_s.gsub("_", " ").gsub(/^(.)/, &:upcase),
29
- more: rule.kwargs.map do |k,v|
30
- "#{k.to_s.gsub("_", " ")}: #{v}"
31
- end.join(", ")
35
+ more: more.join(", ")
32
36
  }
33
37
  when Interscript::Node::Rule::Run
34
38
  if rule.stage.map
@@ -39,10 +43,14 @@ class Interscript::Node::Group
39
43
  stage = rule.stage.name
40
44
  end
41
45
 
46
+ more = []
47
+ more << "<nobr>reverse run:</nobr> #{rule.reverse_run}" unless rule.reverse_run.nil?
48
+
42
49
  out << {
43
50
  type: "Run",
44
51
  doc: doc.name,
45
- stage: stage
52
+ stage: stage,
53
+ more: more.join(", "),
46
54
  }
47
55
  else
48
56
  out << {
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.2.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.2.0
33
+ version: 2.3.0a
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.2.0
40
+ version: 2.3.0a
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: text
43
43
  requirement: !ruby/object:Gem::Requirement