Module: Interscript::Stdlib::Functions
- Defined in:
- lib/interscript/stdlib.rb
Class Method Summary collapse
- .compose(output, _: nil) ⇒ Object
- .decompose(output, _: nil) ⇒ Object
- .downcase(output, word_separator: nil) ⇒ Object
- .rababa(output, config:) ⇒ Object
- .rababa_reverse(output, config:) ⇒ Object
- .secryst(output, model:) ⇒ Object
- .separate(output, separator: " ") ⇒ Object
- .title_case(output, word_separator: " ") ⇒ Object
- .unseparate(output, separator: " ") ⇒ Object
Class Method Details
.compose(output, _: nil) ⇒ Object
209 210 211 |
# File 'lib/interscript/stdlib.rb', line 209 def self.compose(output, _:nil) output.unicode_normalize(:nfc) end |
.decompose(output, _: nil) ⇒ Object
213 214 215 |
# File 'lib/interscript/stdlib.rb', line 213 def self.decompose(output, _:nil) output.unicode_normalize(:nfd) end |
.downcase(output, word_separator: nil) ⇒ Object
200 201 202 203 204 205 206 207 |
# File 'lib/interscript/stdlib.rb', line 200 def self.downcase(output, word_separator: nil) if word_separator output = output.gsub(/^(.)/, &:downcase) output = output.gsub(/#{word_separator}(.)/, &:downcase) unless word_separator == '' else output.downcase end end |
.rababa(output, config:) ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/interscript/stdlib.rb', line 240 def self.rababa(output, config:) require "rababa" rescue nil # Try to load rababa, but don't fail hard if not possible. unless defined? Rababa raise Interscript::ExternalUtilError, "Rababa is not loaded. Please read docs/Usage_with_Rababa.adoc" end config_value = Interscript.rababa_configs[config] model_uri = config_value['model'] rababa_config = config_value['config'] model_path = Interscript.rababa_provision(config, model_uri) @rababa_diacritizer ||= Rababa::Diacritizer.new(model_path, rababa_config) @rababa_diacritizer.diacritize_text(output) end |
.rababa_reverse(output, config:) ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/interscript/stdlib.rb', line 256 def self.rababa_reverse(output, config:) # require "rababa" rescue nil # Try to load rababa, but don't fail hard if not possible. # unless defined? Rababa # raise StandardError, "Rababa is not loaded. Please read docs/Usage_with_Rababa.adoc" # end # A call to allocate allows us to remove diacritics without initializing the model # Rababa::Diacritizer.allocate.remove_diacritics(output) # Unfortunately, this is broken as of now. output.gsub(/[\u064e\u064b\u064f\u064c\u0650\u064d\u0652\u0651]/, '') end |
.secryst(output, model:) ⇒ Object
226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/interscript/stdlib.rb', line 226 def self.secryst(output, model:) require "secryst" rescue nil # Try to load secryst, but don't fail hard if not possible. unless defined? Secryst raise Interscript::ExternalUtilError, "Secryst is not loaded. Please read docs/Usage_with_Secryst.adoc" end Interscript.secryst_index_locations.each do |remote| Secryst::Provisioning.add_remote(remote) end @secryst_models[model] ||= Secryst::Translator.new(model_file: model) output.split("\n").map(&:chomp).map do |i| @secryst_models[model].translate(i) end.join("\n") end |
.separate(output, separator: " ") ⇒ Object
217 218 219 |
# File 'lib/interscript/stdlib.rb', line 217 def self.separate(output, separator: " ") output.split("").join(separator) end |
.title_case(output, word_separator: " ") ⇒ Object
194 195 196 197 198 |
# File 'lib/interscript/stdlib.rb', line 194 def self.title_case(output, word_separator: " ") output = output.gsub(/^(.)/, &:upcase) output = output.gsub(/#{word_separator}(.)/, &:upcase) unless word_separator == '' output end |
.unseparate(output, separator: " ") ⇒ Object
221 222 223 |
# File 'lib/interscript/stdlib.rb', line 221 def self.unseparate(output, separator: " ") output.split(separator).join("") end |