class TwitterCldr::Resources::TransformTestsImporter

This class should be used with JRuby in 1.9 mode

Constants

BGN_SAMPLES
TEXT_SAMPLES

most of these were taken from wikipedia, lol

Public Instance Methods

execute() click to toggle source
# File lib/twitter_cldr/resources/transform_tests_importer.rb, line 52
def execute
  File.open(params.fetch(:output_path), 'w+') do |f|
    f.write(
      YAML.dump(
        generate_test_data(transformer.each_transform)
      )
    )
  end
end

Private Instance Methods

bgn_sample?(script) click to toggle source
# File lib/twitter_cldr/resources/transform_tests_importer.rb, line 93
def bgn_sample?(script)
  BGN_SAMPLES.include?(script.downcase.to_sym)
end
generate_test_data(transforms) click to toggle source
# File lib/twitter_cldr/resources/transform_tests_importer.rb, line 64
def generate_test_data(transforms)
  transforms.each_with_object([]) do |transform_id_str, ret|
    forward_id = transform_id.parse(transform_id_str)

    [forward_id, forward_id.reverse].each do |id|
      if id_exists?(id)
        if bgn_sample?(id.source)
          bgn_id = TwitterCldr::Transforms::TransformId.parse("#{id.to_s}/BGN") rescue nil
          id = bgn_id if bgn_id
        end

        if have_text_samples_for?(id.source)
          samples = text_samples_for(id.source)
          transformed_samples = generate_transform_samples(id, samples)

          if transformed_samples
            ret << {
              id: id.to_s,
              samples: transformed_samples
            }
          end
        end
      end
    end
  end
end
generate_transform_samples(id, samples) click to toggle source
# File lib/twitter_cldr/resources/transform_tests_importer.rb, line 105
def generate_transform_samples(id, samples)
  trans = transliterator_class.getInstance(id.to_s)
  samples.each_with_object({}) do |sample, ret|
    ret[sample] = trans.transliterate(sample)
  end
rescue Java::JavaLang::IllegalArgumentException
  # illegal transform id
  # this happens specifically with Serbian-Latin, although
  # that appears to be a totally valid transform id
  nil
end
have_text_samples_for?(script) click to toggle source
# File lib/twitter_cldr/resources/transform_tests_importer.rb, line 117
def have_text_samples_for?(script)
  TEXT_SAMPLES.include?(script.downcase.to_sym)
end
id_exists?(id) click to toggle source
# File lib/twitter_cldr/resources/transform_tests_importer.rb, line 97
def id_exists?(id)
  TwitterCldr::Transforms::Transformer.exists?(id)
end
text_samples_for(script) click to toggle source
# File lib/twitter_cldr/resources/transform_tests_importer.rb, line 121
def text_samples_for(script)
  TEXT_SAMPLES.fetch(script.downcase.to_sym)
end
transform_id() click to toggle source
# File lib/twitter_cldr/resources/transform_tests_importer.rb, line 129
def transform_id
  TwitterCldr::Transforms::TransformId
end
transformer() click to toggle source
# File lib/twitter_cldr/resources/transform_tests_importer.rb, line 125
def transformer
  TwitterCldr::Transforms::Transformer
end
transliterator_class() click to toggle source
# File lib/twitter_cldr/resources/transform_tests_importer.rb, line 101
def transliterator_class
  @transliterator_class ||= requirements[:icu].get_class('com.ibm.icu.text.Transliterator')
end