iuliia-rb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.idea/iiulia-rb.iml +19 -0
  4. data/.idea/misc.xml +7 -0
  5. data/.idea/modules.xml +8 -0
  6. data/.idea/workspace.xml +4 -0
  7. data/.rspec +3 -0
  8. data/.travis.yml +7 -0
  9. data/CHANGELOG.md +8 -0
  10. data/CODE_OF_CONDUCT.md +74 -0
  11. data/Gemfile +8 -0
  12. data/Gemfile.lock +37 -0
  13. data/LICENSE.txt +21 -0
  14. data/README.md +80 -0
  15. data/Rakefile +6 -0
  16. data/bin/console +15 -0
  17. data/bin/setup +8 -0
  18. data/iiulia-rb.gemspec +43 -0
  19. data/lib/iuliia/iuliia.rb +9 -0
  20. data/lib/iuliia/schema.rb +53 -0
  21. data/lib/iuliia/translit.rb +89 -0
  22. data/lib/iuliia/version.rb +5 -0
  23. data/lib/iuliia.rb +8 -0
  24. data/lib/schemas/LICENSE +21 -0
  25. data/lib/schemas/README.md +20 -0
  26. data/lib/schemas/ala_lc.json +49 -0
  27. data/lib/schemas/ala_lc_alt.json +49 -0
  28. data/lib/schemas/bgn_pcgn.json +147 -0
  29. data/lib/schemas/bgn_pcgn_alt.json +106 -0
  30. data/lib/schemas/bs_2979.json +55 -0
  31. data/lib/schemas/bs_2979_alt.json +49 -0
  32. data/lib/schemas/gost_16876.json +49 -0
  33. data/lib/schemas/gost_16876_alt.json +49 -0
  34. data/lib/schemas/gost_52290.json +92 -0
  35. data/lib/schemas/gost_52535.json +50 -0
  36. data/lib/schemas/gost_7034.json +62 -0
  37. data/lib/schemas/gost_779.json +50 -0
  38. data/lib/schemas/gost_779_alt.json +54 -0
  39. data/lib/schemas/icao_doc_9303.json +57 -0
  40. data/lib/schemas/iso_9_1954.json +49 -0
  41. data/lib/schemas/iso_9_1968.json +49 -0
  42. data/lib/schemas/iso_9_1968_alt.json +49 -0
  43. data/lib/schemas/mosmetro.json +102 -0
  44. data/lib/schemas/mvd_310.json +52 -0
  45. data/lib/schemas/mvd_310_fr.json +66 -0
  46. data/lib/schemas/mvd_782.json +96 -0
  47. data/lib/schemas/scientific.json +49 -0
  48. data/lib/schemas/telegram.json +49 -0
  49. data/lib/schemas/ungegn_1987.json +53 -0
  50. data/lib/schemas/wikipedia.json +95 -0
  51. data/lib/schemas/yandex_maps.json +58 -0
  52. data/lib/schemas/yandex_money.json +52 -0
  53. metadata +150 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 876f5a93f34261da9f5f94131bafdc301976e627d9f2016671a512b2ddd4c872
4
+ data.tar.gz: fbec866a5c2a808ebcaa04c3d0e9ad2449e676c8e071e4fcdb9960aec35f7219
5
+ SHA512:
6
+ metadata.gz: fc513edc37525c16bbfa7c5873f8c4b6d4680e0f94393feecb58467ea0bbc818b865d03a13526fff6180a03060c1dcdcca25a7198681b7939a1ac7f22f2f0678
7
+ data.tar.gz: bf8b4ccbd91d0c8204e64f05365e7c7bd40a8f24d44dcf78f81be6669acc97d3fb58deed9ce6eb2a181eb36833e958477cddb16e37c23c828002f4c057f23dae
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$" />
8
+ <orderEntry type="jdk" jdkName="RVM: ruby-2.6.6" jdkType="RUBY_SDK" />
9
+ <orderEntry type="sourceFolder" forTests="false" />
10
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v1.17.3, RVM: ruby-2.6.6) [gem]" level="application" />
11
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.3, RVM: ruby-2.6.6) [gem]" level="application" />
12
+ <orderEntry type="library" scope="PROVIDED" name="json (v2.3.0, RVM: ruby-2.6.6) [gem]" level="application" />
13
+ <orderEntry type="library" scope="PROVIDED" name="rake (v12.3.3, RVM: ruby-2.6.6) [gem]" level="application" />
14
+ <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.9.1, RVM: ruby-2.6.6) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.9.1, RVM: ruby-2.6.6) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.9.1, RVM: ruby-2.6.6) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.9.2, RVM: ruby-2.6.6) [gem]" level="application" />
18
+ </component>
19
+ </module>
data/.idea/misc.xml ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="JavaScriptSettings">
4
+ <option name="languageLevel" value="ES6" />
5
+ </component>
6
+ <component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-2.4.5 [global]" project-jdk-type="RUBY_SDK" />
7
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/iiulia-rb.iml" filepath="$PROJECT_DIR$/.idea/iiulia-rb.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectId" id="1bEGnmEDYzBnl6qIoQ8XtjqEJc9" />
4
+ </project>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.6
7
+ before_install: gem install bundler -v 1.17.3
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [0.1.0] - 2020-04-30
8
+ ### Initial release
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at a.d.nikiforov@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in iiulia-rb.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ iuliia-rb (0.1.0)
5
+ json
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ json (2.3.0)
12
+ rake (13.0.1)
13
+ rspec (3.9.0)
14
+ rspec-core (~> 3.9.0)
15
+ rspec-expectations (~> 3.9.0)
16
+ rspec-mocks (~> 3.9.0)
17
+ rspec-core (3.9.1)
18
+ rspec-support (~> 3.9.1)
19
+ rspec-expectations (3.9.1)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.9.0)
22
+ rspec-mocks (3.9.1)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.9.0)
25
+ rspec-support (3.9.2)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler
32
+ iuliia-rb!
33
+ rake
34
+ rspec
35
+
36
+ BUNDLED WITH
37
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Andrey Nikiforov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # Iuliia
2
+
3
+ Small gem to properly transliterate cyrillic to latin. Use https://github.com/nalgeon/iuliia for transliteration schemas.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'iuliia-rb'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install iuliia-rb
20
+
21
+ ## Usage
22
+
23
+ Get available schemas (dynamically generated from JSON definitions in `lib/schemas`)
24
+ ```ruby
25
+ Iuliia::Schema.available_schemas
26
+
27
+ [
28
+ ['mvd_310', 'MVD 310-1997 transliteration schema'],
29
+ ['bs_2979', 'British Standard 2979:1958 transliteration schema'],
30
+ ['gost_779_alt', 'GOST 7.79-2000 (aka ISO 9:1995) transliteration schema'],
31
+ ['icao_doc_9303', 'ICAO DOC 9303 transliteration schema'],
32
+ ['mvd_310_fr', 'MVD 310-1997 transliteration schema'],
33
+ ['mvd_782', 'MVD 782-2000 transliteration schema'],
34
+ ['iso_9_1968_alt', 'ISO/R 9:1968 transliteration schema'],
35
+ ['mosmetro', 'Moscow Metro map transliteration schema'],
36
+ ['gost_7034', 'GOST R 7.0.34-2014 transliteration schema'],
37
+ ['gost_16876_alt', 'GOST 16876-71 (aka GOST 1983) transliteration schema'],
38
+ ['gost_52290', 'GOST R 52290-2004 transliteration schema'],
39
+ ['ungegn_1987', 'UNGEGN 1987 V/18 transliteration schema'],
40
+ ['telegram', 'Telegram transliteration schema'],
41
+ ['gost_16876', 'GOST 16876-71 (aka GOST 1983) transliteration schema'],
42
+ ['gost_779', 'GOST 7.79-2000 (aka ISO 9:1995) transliteration schema'],
43
+ ['wikipedia', 'Wikipedia transliteration schema'],
44
+ ['bgn_pcgn', 'BGN/PCGN transliteration schema'],
45
+ ['iso_9_1968', 'ISO/R 9:1968 transliteration schema'],
46
+ ['yandex_money', 'Yandex.Money transliteration schema'],
47
+ ['ala_lc', 'ALA-LC transliteration schema.'],
48
+ ['yandex_maps', 'Yandex.Maps transliteration schema'],
49
+ ['gost_52535', 'GOST R 52535.1-2006 transliteration schema'],
50
+ ['bgn_pcgn_alt', 'BGN/PCGN transliteration schema'],
51
+ ['iso_9_1954', 'ISO/R 9:1954 transliteration schema'],
52
+ ['bs_2979_alt', 'British Standard 2979:1958 transliteration schema'],
53
+ ['scientific', 'Scientific transliteration schema'],
54
+ ['ala_lc_alt', 'ALA-LC transliteration schema.']
55
+ ]
56
+ ```
57
+
58
+ Pick one and transliterate
59
+
60
+ ```ruby
61
+ Iuliia.translit('Юлия, съешь ещё этих мягких французских булок из Йошкар-Олы, да выпей алтайского чаю', schema: 'mvd_782')
62
+
63
+ "Yuliya, syesh' eshche etikh myagkikh frantsuzskikh bulok iz Yoshkar-Oly, da vypey altayskogo chayu"
64
+ ```
65
+
66
+ ## TODO
67
+
68
+ * Add documentation
69
+ * Maybe some more specs
70
+ * Implement reverse translit (not available for all schemas though)
71
+
72
+ ## Development
73
+
74
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
75
+
76
+ To install this gem onto your local machine, run `bundle exec rake install`.
77
+
78
+ ## License
79
+
80
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'iuliia'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/iiulia-rb.gemspec ADDED
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'iuliia/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'iuliia-rb'
9
+ spec.version = Iuliia::VERSION
10
+ spec.authors = ['Andrey Nikiforov']
11
+ spec.email = ['a.d.nikiforov@gmail.com']
12
+
13
+ spec.summary = 'Russian transliteration using nalgeon/iuliia schemas'
14
+ spec.homepage = 'https://github.com/adnikiforov/iuliia-rb'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+
22
+ # spec.metadata['homepage_uri'] = spec.homepage
23
+ # spec.metadata['source_code_uri'] = "TODO: Put your gem's public repo URL here."
24
+ # spec.metadata['changelog_uri'] = "TODO: Put your gem's CHANGELOG.md URL here."
25
+ else
26
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = 'exe'
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ['lib']
37
+
38
+ spec.add_development_dependency 'bundler'
39
+ spec.add_development_dependency 'rake'
40
+ spec.add_development_dependency 'rspec'
41
+
42
+ spec.add_dependency 'json'
43
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Iuliia
4
+ module_function
5
+
6
+ def translit(string, schema:)
7
+ Iuliia::Translit.new(string, schema).translit
8
+ end
9
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Iuliia
4
+ module Schema
5
+ extend self
6
+
7
+ SCHEMA = Struct.new(
8
+ :description,
9
+ :url,
10
+ :mapping,
11
+ :prev_mapping,
12
+ :next_mapping,
13
+ :ending_mapping
14
+ )
15
+
16
+ def schema(schema_name)
17
+ schemas[schema_name]
18
+ end
19
+
20
+ def available_schemas
21
+ schemas.map do |schema_name, schema|
22
+ [schema_name, schema.description]
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def schemas
29
+ @schemas ||= load_schemas
30
+ end
31
+
32
+ def load_schemas
33
+ Dir['lib/schemas/*.json'].map do |schema_file|
34
+ file = File.read(schema_file)
35
+ parse_and_create_schema(file)
36
+ end.reduce({}, :update)
37
+ end
38
+
39
+ def parse_and_create_schema(file)
40
+ parsed_data = JSON.parse(file)
41
+ schema = SCHEMA.new(
42
+ parsed_data['description'],
43
+ parsed_data['url'],
44
+ parsed_data['mapping'],
45
+ parsed_data['prev_mapping'],
46
+ parsed_data['next_mapping'],
47
+ parsed_data['ending_mapping']
48
+ )
49
+
50
+ { parsed_data['name'] => schema }
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Iuliia
4
+ class Translit
5
+ ENDING_LENGTH = 2
6
+
7
+ def initialize(string, schema)
8
+ @string = string
9
+ @schema = Iuliia::Schema.schema(schema)
10
+ end
11
+
12
+ def translit
13
+ string.split(/\b/).map { |chunk| translit_chunk(chunk) }.join
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :string, :schema
19
+
20
+ def translit_chunk(chunk)
21
+ return chunk unless /\p{l}+/.match?(chunk)
22
+
23
+ stem, ending = split_word(chunk)
24
+
25
+ return translit_stem(chunk) if ending.empty?
26
+
27
+ translited_ending = schema.ending_mapping&.dig(ending)
28
+ return translit_stem(chunk) if translited_ending.nil?
29
+
30
+ translited_stem = translit_stem(stem)
31
+
32
+ [translited_stem, translited_ending].join
33
+ end
34
+
35
+ def translit_stem(stem)
36
+ translited_stem = stem.chars.each_with_index.map do |char, index|
37
+ translit_char(stem.chars, char, index)
38
+ end
39
+
40
+ camelcase(translited_stem.join)
41
+ end
42
+
43
+ def translit_char(chars, char, index)
44
+ translited_char = translit_prev(chars, index)
45
+ translited_char = translit_next(chars, index) if translited_char.nil?
46
+ translited_char = schema.mapping[char.downcase] if translited_char.nil?
47
+
48
+ upcase?(char) ? translited_char.upcase : translited_char
49
+ end
50
+
51
+ def translit_prev(chars, index)
52
+ prev_char = if index.positive?
53
+ chars[index - 1..index].join.downcase
54
+ else
55
+ chars[index].downcase
56
+ end
57
+
58
+ schema.prev_mapping&.dig(prev_char)
59
+ end
60
+
61
+ def translit_next(chars, index)
62
+ next_char = chars[index..index + 1].join.downcase
63
+ schema.next_mapping&.dig(next_char)
64
+ end
65
+
66
+ def split_word(word)
67
+ if word.length <= ENDING_LENGTH
68
+ [word, '']
69
+ else
70
+ ending = word.length > ENDING_LENGTH ? word[-ENDING_LENGTH..-1] : ''
71
+ stem = word[0..(word.length - ENDING_LENGTH - 1)] || word
72
+
73
+ [stem, ending]
74
+ end
75
+ end
76
+
77
+ def upcase?(char)
78
+ /[[:upper:]]/.match(char)
79
+ end
80
+
81
+ def camelcase(string)
82
+ return string unless upcase?(string[0])
83
+
84
+ string = string.downcase
85
+ string[0] = string[0].capitalize
86
+ string
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Iuliia
4
+ VERSION = '0.1.0'.freeze
5
+ end
data/lib/iuliia.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ require 'iuliia/version'
6
+ require 'iuliia/translit'
7
+ require 'iuliia/schema'
8
+ require 'iuliia/iuliia'
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Anton Zhiyanov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,20 @@
1
+ # `Iuliia`
2
+
3
+ > Transliterate Cyrillic → Latin in every possible way
4
+
5
+ Transliteration means representing Cyrillic data (mainly names and geographic locations) with Latin letters. It is used for international passports, visas, green cards, driving licenses, mail and goods delivery etc.
6
+
7
+ `Iuliia` makes transliteration easy as calling `iuliia.translate()` in your favorite programming language.
8
+
9
+ Why use `Iuliia`:
10
+
11
+ - 20 transliteration schemas (rule sets), including all main international and Russian standards.
12
+ - Correctly implements not only the base mapping, but all the special rules for letter combinations and word endings (AFAIK, Iuliia is the only library which does so).
13
+ - Simple API and zero third-party dependencies.
14
+
15
+ Supported languages:
16
+
17
+ - [JavaScript](https://github.com/nalgeon/iuliia-js)
18
+ - [Python](https://github.com/nalgeon/iuliia-py)
19
+
20
+ This repo contains schema descriptions. It is not intended to be used directly. If you want to add another schema — send a PR! Use [wikipedia.json](wikipedia.json) as a reference.
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "ala_lc",
3
+ "description": "ALA-LC transliteration schema.",
4
+ "url": "https://dangry.ru/iuliia/ala-lc/",
5
+ "mapping": {
6
+ "а": "a",
7
+ "б": "b",
8
+ "в": "v",
9
+ "г": "g",
10
+ "д": "d",
11
+ "е": "e",
12
+ "ё": "ё",
13
+ "ж": "zh",
14
+ "з": "z",
15
+ "и": "i",
16
+ "й": "ĭ",
17
+ "к": "k",
18
+ "л": "l",
19
+ "м": "m",
20
+ "н": "n",
21
+ "о": "o",
22
+ "п": "p",
23
+ "р": "r",
24
+ "с": "s",
25
+ "т": "t",
26
+ "у": "u",
27
+ "ф": "f",
28
+ "х": "kh",
29
+ "ц": "t͡s",
30
+ "ч": "ch",
31
+ "ш": "sh",
32
+ "щ": "shch",
33
+ "ъ": "ʺ",
34
+ "ы": "y",
35
+ "ь": "ʹ",
36
+ "э": "ė",
37
+ "ю": "i͡u",
38
+ "я": "i͡a"
39
+ },
40
+ "prev_mapping": null,
41
+ "next_mapping": null,
42
+ "ending_mapping": null,
43
+ "samples": [
44
+ [
45
+ "Юлия, съешь ещё этих мягких французских булок из Йошкар-Олы, да выпей алтайского чаю",
46
+ "I͡ulii͡a, sʺeshʹ eshchё ėtikh mi͡agkikh frant͡suzskikh bulok iz Ĭoshkar-Oly, da vypeĭ altaĭskogo chai͡u"
47
+ ]
48
+ ]
49
+ }