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 +4 -4
- data/Gemfile +4 -0
- data/Rakefile +9 -1
- data/interscript.gemspec +1 -1
- data/lib/interscript.rb +66 -0
- data/lib/interscript/dsl/document.rb +2 -1
- data/lib/interscript/dsl/tests.rb +2 -2
- data/lib/interscript/node/document.rb +1 -0
- data/lib/interscript/node/stage.rb +12 -4
- data/lib/interscript/node/tests.rb +3 -1
- data/lib/interscript/stdlib.rb +17 -1
- data/lib/interscript/version.rb +1 -1
- data/lib/interscript/visualize/json.rb +12 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9dd918129c2ea6f94d0bf346869fe9a4baca90e7b59524787ebe5fe58c22a1af
|
4
|
+
data.tar.gz: 7ab737080e82d26da28b631ba46fc75547b8492b250841dc5a8e8527f6b73736
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f47f197ec26a7df2dfd49ecee799c33bb8f78cee4e6453cfc191fd165c9fa8925ebca1612c4305469a5ece2ee904e81d2a6e8d6d49bcd7e5f983d9890ac4ff9e
|
7
|
+
data.tar.gz: c4a3d287564512c48c25069100dbfce537939c339e9289d894cf55d48af25e980f48f744161fd57bc44eb8af345d659ed703da9981cdb99bd819c9c00960c8c7
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -20,7 +20,10 @@ task :compile, [:compiler, :target] do |t, args|
|
|
20
20
|
|
21
21
|
maplist = {}
|
22
22
|
|
23
|
-
Interscript.maps
|
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(".")}.
|
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
|
@@ -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
|
-
|
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
|
data/lib/interscript/stdlib.rb
CHANGED
@@ -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
|
data/lib/interscript/version.rb
CHANGED
@@ -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:
|
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.
|
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.
|
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.
|
40
|
+
version: 2.3.0a
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: text
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|