tibetan 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +57 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +63 -4
- data/LICENSE.txt +1 -1
- data/README.md +26 -2
- data/Rakefile +6 -1
- data/exe/tibetan +51 -0
- data/lib/tibetan/version.rb +3 -1
- data/lib/tibetan.rb +112 -53
- metadata +25 -24
- data/.gitignore +0 -8
- data/.travis.yml +0 -5
- data/Gemfile +0 -6
- data/Gemfile.lock +0 -26
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/tibetan.gemspec +0 -27
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a4cab1f9b9a538564a7e94f0d3abbae373ba8dfcaf6a066edc6b1e3819643e0e
|
|
4
|
+
data.tar.gz: a4f5b00a4e9f7c0f5709cebeca12225572138ed2ba7f90fc9ca902ce6fdf48cd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a304ccec1a4f2df92f68b98e8989128f1af3187c0f055057daaa39ba5a2d0070a1381e0949f89e035308213457799dd23bb6b6fce92922cea338fbbde9c82a0e
|
|
7
|
+
data.tar.gz: cd070ffdcda052027fc46efb04fc0b41a7c10d99e181d9c09f45ada43150a6d6b8c2dee9bdae6f3c42b2e679c3b831c3b7fa2f3f3b1de63751ee6aec63c0d6e5
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
plugins:
|
|
2
|
+
- rubocop-rake
|
|
3
|
+
- rubocop-minitest
|
|
4
|
+
|
|
5
|
+
AllCops:
|
|
6
|
+
TargetRubyVersion: 3.0
|
|
7
|
+
NewCops: enable
|
|
8
|
+
SuggestExtensions: false
|
|
9
|
+
Exclude:
|
|
10
|
+
- "bin/**/*"
|
|
11
|
+
- "pkg/**/*"
|
|
12
|
+
- "vendor/**/*"
|
|
13
|
+
|
|
14
|
+
Layout/LineLength:
|
|
15
|
+
Max: 120
|
|
16
|
+
AllowedPatterns:
|
|
17
|
+
- '^\s*assert_equal'
|
|
18
|
+
- '^\s*#'
|
|
19
|
+
- '^\s*"'
|
|
20
|
+
- 'spec\.description'
|
|
21
|
+
|
|
22
|
+
Style/StringLiterals:
|
|
23
|
+
Enabled: false
|
|
24
|
+
|
|
25
|
+
Style/Documentation:
|
|
26
|
+
Enabled: false
|
|
27
|
+
|
|
28
|
+
Style/AsciiComments:
|
|
29
|
+
Enabled: false
|
|
30
|
+
|
|
31
|
+
Style/PercentLiteralDelimiters:
|
|
32
|
+
Enabled: false
|
|
33
|
+
|
|
34
|
+
Gemspec/DevelopmentDependencies:
|
|
35
|
+
Enabled: false
|
|
36
|
+
|
|
37
|
+
Minitest/MultipleAssertions:
|
|
38
|
+
Enabled: false
|
|
39
|
+
|
|
40
|
+
Metrics/AbcSize:
|
|
41
|
+
Enabled: false
|
|
42
|
+
|
|
43
|
+
Metrics/MethodLength:
|
|
44
|
+
Enabled: false
|
|
45
|
+
|
|
46
|
+
Metrics/CyclomaticComplexity:
|
|
47
|
+
Enabled: false
|
|
48
|
+
|
|
49
|
+
Metrics/PerceivedComplexity:
|
|
50
|
+
Enabled: false
|
|
51
|
+
|
|
52
|
+
Metrics/BlockNesting:
|
|
53
|
+
Enabled: false
|
|
54
|
+
|
|
55
|
+
Metrics/ModuleLength:
|
|
56
|
+
Max: 250
|
|
57
|
+
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
4.0.6
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## Version 0.2.0 (2026-09-17)
|
|
6
|
+
|
|
7
|
+
* **Performance:**
|
|
8
|
+
* ~15.4x transliteration speedup via precompiled regular expressions and Set-based character lookup.
|
|
9
|
+
* Eliminated redundant array allocations and `string.chars` calls during root consonant detection.
|
|
10
|
+
* **Extended Wylie (EWTS) & Sanskrit Support:**
|
|
11
|
+
* Added Sanskrit aspirated consonants (`གྷ`, `ཌྷ`, `དྷ`, `བྷ`, `ཛྷ`) and their subjoined forms (`ྒྷ`, `ྜྷ`, `ྡྷ`, `ྦྷ`, `ྫྷ`, `ྐྵ`).
|
|
12
|
+
* Added Sanskrit signs: avagraha `྅` (`` ` ``), anusvara `ཾ` (`ṃ`), candrabindu `ྃ` (`~ṃ`), and visarga `ཿ` (`ḥ`).
|
|
13
|
+
* Added punctuation support for centered point `・` (space) and angle brackets `《 ... 》` (`"..."`).
|
|
14
|
+
* Fixed errant tab character in character mapping for U+0F07 (`"༇"`).
|
|
15
|
+
* **CLI Executable:**
|
|
16
|
+
* Added `exe/tibetan` command-line tool supporting arguments, file reading, and piped STDIN input (`-v`, `--help`).
|
|
17
|
+
* **Documentation & Developer Experience:**
|
|
18
|
+
* Added comprehensive YARD documentation for all public APIs (`Tibetan.transliterate`, `Tibetan.t`).
|
|
19
|
+
* Updated README with CLI instructions and EWTS Sanskrit transliteration examples.
|
|
20
|
+
* **Testing:**
|
|
21
|
+
* Added extensive real-world integration test suite with 500 Tibetan terms from the UMA (University of Virginia) glossaries fixture.
|
|
22
|
+
* Added integration tests for the CLI executable covering arguments, pipes, and version display.
|
|
23
|
+
* **Architecture & Encapsulation:**
|
|
24
|
+
* Encapsulated internal helper `insert_default_vowel!` as a private class method.
|
|
25
|
+
* Added defensive edge case handling for `nil`, empty strings, and mixed non-Tibetan text.
|
|
26
|
+
* **Infrastructure & Tooling:**
|
|
27
|
+
* Replaced deprecated Travis CI with GitHub Actions matrix (Ruby 3.1 - head).
|
|
28
|
+
* Modernized gemspec (`required_ruby_version >= 3.0.0`, metadata URIs, resilient packaging).
|
|
29
|
+
* Added RuboCop with custom configuration integrated into default `rake` task.
|
|
30
|
+
* Updated default branch references from `master` to `main`.
|
|
31
|
+
* Added Dependabot configuration for GitHub Actions automated updates.
|
|
32
|
+
* Pinned Ruby version in `.ruby-version`.
|
|
33
|
+
|
|
34
|
+
## Version 0.1.5
|
|
35
|
+
|
|
36
|
+
* Improve transliteration accuracy and add more tests.
|
|
37
|
+
* Add rule to insert implicit vowel 'a' before 'a-chung (`འ`) preceded by consonant/subscript.
|
|
38
|
+
* Distinguish prefix `g` and root `y` (`g.y`) from root `g` and subjoined `y` (`gy`).
|
|
39
|
+
* Clean up erroneous spaces before closing brackets and punctuation.
|
|
40
|
+
|
|
41
|
+
## Version 0.1.4
|
|
42
|
+
|
|
43
|
+
* Fix string mutation warnings on modern Ruby versions.
|
|
44
|
+
* Update development dependencies: `bundler`, `rake`, `minitest`.
|
|
45
|
+
|
|
46
|
+
## Version 0.1.3
|
|
47
|
+
|
|
48
|
+
* Add comprehensive references on Tibetan transliteration.
|
|
49
|
+
|
|
50
|
+
## Version 0.1.2
|
|
51
|
+
|
|
52
|
+
* Insert default vowel "a".
|
|
53
|
+
* Split long phrases into smaller parts and transliterate separately.
|
|
54
|
+
* Expand test coverage.
|
|
55
|
+
|
|
56
|
+
## Version 0.1.1
|
|
57
|
+
|
|
58
|
+
* Convert spaces to underscores.
|
|
59
|
+
* Update test suite.
|
|
60
|
+
|
|
61
|
+
## Version 0.1.0
|
|
62
|
+
|
|
63
|
+
* Initial release.
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Tibetan -> Wylie
|
|
2
2
|
|
|
3
|
+
[](https://github.com/rovetz/tibetan/actions/workflows/ci.yml)
|
|
4
|
+
[](https://badge.fury.io/rb/tibetan)
|
|
5
|
+
|
|
3
6
|
Romanization of Tibetan. It transliterates Tibetan text to the Latin script using THL EWTS (Extended Wylie Transliteration Scheme).
|
|
4
7
|
|
|
5
8
|
## Installation
|
|
@@ -31,12 +34,33 @@ Tibetan.transliterate("བོད་སྐད་") # => "bod skad"
|
|
|
31
34
|
Tibetan.transliterate("༡༢༣") # => "123"
|
|
32
35
|
Tibetan.transliterate("༪") # => "0.5"
|
|
33
36
|
```
|
|
34
|
-
or
|
|
37
|
+
or using the shorthand alias `.t`:
|
|
35
38
|
|
|
36
39
|
```ruby
|
|
37
40
|
Tibetan.t("བོད་སྐད་") # => "bod skad"
|
|
38
41
|
Tibetan.t("༡༢༣") # => "123"
|
|
39
42
|
Tibetan.t("༪") # => "0.5"
|
|
43
|
+
|
|
44
|
+
# Extended Wylie (EWTS) & Sanskrit loanwords support:
|
|
45
|
+
Tibetan.t("ཨོཾ་ཨཱཿཧཱུྃ") # => "oṃ āḥ hūṃ"
|
|
46
|
+
Tibetan.t("ཤུདྡྷོ྅ཧཾ") # => "shuddho`haṃ"
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Command Line Interface (CLI)
|
|
50
|
+
|
|
51
|
+
You can also use `tibetan` directly from the command line:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# Direct argument
|
|
55
|
+
$ tibetan "བོད་སྐད་"
|
|
56
|
+
bod skad
|
|
57
|
+
|
|
58
|
+
# Piped input (STDIN)
|
|
59
|
+
$ echo "བོད་སྐད་" | tibetan
|
|
60
|
+
bod skad
|
|
61
|
+
|
|
62
|
+
# File input
|
|
63
|
+
$ tibetan text.txt
|
|
40
64
|
```
|
|
41
65
|
|
|
42
66
|
## References
|
|
@@ -68,4 +92,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
68
92
|
|
|
69
93
|
## Code of Conduct
|
|
70
94
|
|
|
71
|
-
Everyone interacting in the Tibetan project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rovetz/tibetan/blob/
|
|
95
|
+
Everyone interacting in the Tibetan project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rovetz/tibetan/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "bundler/gem_tasks"
|
|
2
4
|
require "rake/testtask"
|
|
5
|
+
require "rubocop/rake_task"
|
|
3
6
|
|
|
4
7
|
Rake::TestTask.new(:test) do |t|
|
|
5
8
|
t.libs << "test"
|
|
@@ -7,4 +10,6 @@ Rake::TestTask.new(:test) do |t|
|
|
|
7
10
|
t.test_files = FileList["test/**/*_test.rb"]
|
|
8
11
|
end
|
|
9
12
|
|
|
10
|
-
|
|
13
|
+
RuboCop::RakeTask.new(:rubocop)
|
|
14
|
+
|
|
15
|
+
task default: %i[test rubocop]
|
data/exe/tibetan
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "optparse"
|
|
5
|
+
require "tibetan"
|
|
6
|
+
|
|
7
|
+
parser = OptionParser.new do |opts|
|
|
8
|
+
opts.banner = "Usage: tibetan [options] [text | file...]"
|
|
9
|
+
opts.separator ""
|
|
10
|
+
opts.separator "Transliterate Tibetan text to Roman script (Extended Wylie)."
|
|
11
|
+
opts.separator ""
|
|
12
|
+
opts.separator "Examples:"
|
|
13
|
+
opts.separator " tibetan 'བོད་སྐད་'"
|
|
14
|
+
opts.separator " echo 'བོད་སྐད་' | tibetan"
|
|
15
|
+
opts.separator " tibetan text.txt"
|
|
16
|
+
opts.separator ""
|
|
17
|
+
opts.separator "Options:"
|
|
18
|
+
|
|
19
|
+
opts.on("-v", "--version", "Show version") do
|
|
20
|
+
puts "tibetan #{Tibetan::VERSION}"
|
|
21
|
+
exit
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
opts.on("-h", "--help", "Show this help message") do
|
|
25
|
+
puts opts
|
|
26
|
+
exit
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
parser.parse!
|
|
31
|
+
|
|
32
|
+
if ARGV.empty?
|
|
33
|
+
if $stdin.tty?
|
|
34
|
+
puts parser
|
|
35
|
+
exit 1
|
|
36
|
+
else
|
|
37
|
+
$stdin.each_line do |line|
|
|
38
|
+
puts Tibetan.t(line.chomp)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
else
|
|
42
|
+
ARGV.each do |arg|
|
|
43
|
+
if File.file?(arg)
|
|
44
|
+
File.foreach(arg) do |line|
|
|
45
|
+
puts Tibetan.t(line.chomp)
|
|
46
|
+
end
|
|
47
|
+
else
|
|
48
|
+
puts Tibetan.t(arg)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
data/lib/tibetan/version.rb
CHANGED
data/lib/tibetan.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "set"
|
|
4
|
+
require_relative "tibetan/version"
|
|
4
5
|
|
|
5
6
|
module Tibetan
|
|
6
7
|
# Extended Wylie Transliteration Scheme (EWTS)
|
|
@@ -42,12 +43,15 @@ module Tibetan
|
|
|
42
43
|
"༄" => "@",
|
|
43
44
|
"༅" => "#",
|
|
44
45
|
"༆" => "$",
|
|
45
|
-
"༇" => "
|
|
46
|
+
"༇" => "%",
|
|
46
47
|
# Paired Punctuation Marks (brackets)
|
|
47
48
|
"༺" => "<",
|
|
48
49
|
"༻" => ">",
|
|
49
50
|
"༼" => "(",
|
|
50
51
|
"༽" => ")",
|
|
52
|
+
"・" => " ",
|
|
53
|
+
"《" => "\"",
|
|
54
|
+
"》" => "\"",
|
|
51
55
|
# Consonants, subjoined consonants
|
|
52
56
|
"ཀ" => "k",
|
|
53
57
|
"ྐ" => "k",
|
|
@@ -115,86 +119,141 @@ module Tibetan
|
|
|
115
119
|
"ཌ" => "Da", "ྜ" => "D",
|
|
116
120
|
"ཎ" => "N", "ྞ" => "N",
|
|
117
121
|
"ཥ" => "S", "ྵ" => "S",
|
|
122
|
+
# Sanskrit Consonants
|
|
123
|
+
"གྷ" => "gh", "ྒྷ" => "gh",
|
|
124
|
+
"ཌྷ" => "Dh", "ྜྷ" => "Dh",
|
|
125
|
+
"དྷ" => "dh", "ྡྷ" => "dh",
|
|
126
|
+
"བྷ" => "bh", "ྦྷ" => "bh",
|
|
127
|
+
"ཛྷ" => "dzh", "ྫྷ" => "dzh",
|
|
128
|
+
"ྐྵ" => "kSh",
|
|
129
|
+
# Sanskrit Signs
|
|
130
|
+
"྅" => "`",
|
|
131
|
+
"ཾ" => "ṃ",
|
|
132
|
+
"ྃ" => "~ṃ",
|
|
133
|
+
"ཿ" => "ḥ",
|
|
118
134
|
# Vowels
|
|
119
|
-
"ི"
|
|
135
|
+
"ི" => "i",
|
|
120
136
|
"ུ" => "u",
|
|
121
|
-
"ེ"
|
|
122
|
-
"ོ"
|
|
137
|
+
"ེ" => "e",
|
|
138
|
+
"ོ" => "o",
|
|
123
139
|
# Sanskrit Vowels
|
|
124
|
-
"ཱ"
|
|
125
|
-
"ཱི"
|
|
140
|
+
"ཱ" => "ā",
|
|
141
|
+
"ཱི" => "ī",
|
|
126
142
|
"ཱུ" => "ū",
|
|
127
|
-
"ཻ"
|
|
128
|
-
"ཽ"
|
|
129
|
-
"ྲྀ"
|
|
143
|
+
"ཻ" => "ai",
|
|
144
|
+
"ཽ" => "au",
|
|
145
|
+
"ྲྀ" => "ṛ",
|
|
130
146
|
"ཷ" => "ṝ",
|
|
131
|
-
"ླྀ"
|
|
132
|
-
"ཹ" => "ḹ"
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
CONSONANTS = %w
|
|
136
|
-
|
|
137
|
-
|
|
147
|
+
"ླྀ" => "ḷ",
|
|
148
|
+
"ཹ" => "ḹ"
|
|
149
|
+
}.freeze
|
|
150
|
+
|
|
151
|
+
CONSONANTS = %w[
|
|
152
|
+
ཀ ཁ ག ང ཅ ཆ ཇ ཉ ཏ ཐ ད ན པ ཕ བ མ ཙ ཚ ཛ ཝ ཞ ཟ འ ཡ ར ལ ཤ ས ཧ ཊ ཋ ཌ ཎ ཥ གྷ ཌྷ དྷ བྷ ཛྷ
|
|
153
|
+
].freeze
|
|
154
|
+
SUBSCRIPTS = %w[
|
|
155
|
+
ྐ ྑ ྒ ྔ ྕ ྖ ྗ ྙ ྟ ྠ ྡ ྣ ྤ ྥ ྦ ྨ ྩ ྪ ྫ ྭ ྮ ྯ ྰ ྱ ྲ ླ ྴ ྶ ྷ ྚ ྛ ྜ ྞ ྵ ྒྷ ྜྷ ྡྷ ྦྷ ྫྷ ྐྵ
|
|
156
|
+
].freeze
|
|
157
|
+
VOWELS = %w[ྸ ི ུ ེ ོ a].freeze
|
|
138
158
|
SEP = "་"
|
|
139
159
|
DEFAULT_VOWEL = "a"
|
|
140
160
|
|
|
161
|
+
CONSONANTS_SUBSCRIPTS = (CONSONANTS + SUBSCRIPTS).freeze
|
|
162
|
+
CONSONANTS_SUBSCRIPTS_SET = Set.new(CONSONANTS_SUBSCRIPTS).freeze
|
|
163
|
+
|
|
164
|
+
SPLIT_REGEX = /([^#{Regexp.escape((CONSONANTS + SUBSCRIPTS + VOWELS).join)}]+)/
|
|
165
|
+
A_CHUNG_REGEX = /([#{Regexp.escape(CONSONANTS_SUBSCRIPTS.join)}])འ/
|
|
166
|
+
CHARACTER_TABLE_REGEX = /#{Regexp.union(CHARACTER_TABLE.keys).source}/i
|
|
167
|
+
SUBSCRIPTS_REGEX = /[#{Regexp.escape(SUBSCRIPTS.join)}]/
|
|
168
|
+
VOWELS_REGEX = /[#{Regexp.escape(VOWELS.join)}]/
|
|
169
|
+
CONSONANTS_REGEX = /[#{Regexp.escape(CONSONANTS.join)}]/
|
|
170
|
+
TRAILING_SPACES_REGEX = / +([»\])》"]|\Z)/
|
|
171
|
+
|
|
141
172
|
class << self
|
|
142
|
-
|
|
173
|
+
# Transliterates Tibetan text into Roman (Latin) script using the Extended Wylie
|
|
174
|
+
# Transliteration Scheme (THL EWTS).
|
|
175
|
+
#
|
|
176
|
+
# @param string [String, nil] The Tibetan text to transliterate.
|
|
177
|
+
# @param to [Symbol] The character mapping table to use (defaults to :tibetan).
|
|
178
|
+
# @return [String] The transliterated Roman text (Extended Wylie).
|
|
179
|
+
#
|
|
180
|
+
# @example Transliterate standard Tibetan
|
|
181
|
+
# Tibetan.transliterate("བོད་སྐད་")
|
|
182
|
+
# #=> "bod skad"
|
|
183
|
+
#
|
|
184
|
+
# @example Using the short alias
|
|
185
|
+
# Tibetan.t("༡༢༣")
|
|
186
|
+
# #=> "123"
|
|
187
|
+
#
|
|
188
|
+
# @example Transliterating text with Sanskrit symbols
|
|
189
|
+
# Tibetan.t("ཤུདྡྷོ྅ཧཾ")
|
|
190
|
+
# #=> "shuddho`haṃ"
|
|
191
|
+
def transliterate(string = "", to = :tibetan)
|
|
192
|
+
return "" if string.nil?
|
|
193
|
+
|
|
143
194
|
string = string.to_s.dup
|
|
144
|
-
|
|
195
|
+
return "" if string.empty?
|
|
196
|
+
|
|
145
197
|
# Split long phrase into small parts and transliterate separately
|
|
146
198
|
# Split by anything that isn't a Tibetan consonant, subscript, or vowel
|
|
147
|
-
parts = string.split(
|
|
199
|
+
parts = string.split(SPLIT_REGEX).reject(&:empty?)
|
|
148
200
|
if parts.size > 1
|
|
149
201
|
res = parts.map do |str|
|
|
150
|
-
transliterate(str)
|
|
202
|
+
transliterate(str, to)
|
|
151
203
|
end.join
|
|
152
|
-
# During mapping, trailing tseks become spaces. This cleans up erroneous spaces
|
|
204
|
+
# During mapping, trailing tseks become spaces. This cleans up erroneous spaces
|
|
153
205
|
# before closing punctuation (e.g. «pe » -> «pe») and drops trailing spaces.
|
|
154
|
-
res.gsub!(
|
|
206
|
+
res.gsub!(TRAILING_SPACES_REGEX, '\1')
|
|
155
207
|
return res
|
|
156
208
|
end
|
|
157
209
|
|
|
158
210
|
# Implicit vowel 'a' before 'a-chung preceded by a consonant/subscript
|
|
159
|
-
string.gsub!(
|
|
211
|
+
string.gsub!(A_CHUNG_REGEX, '\1aའ')
|
|
160
212
|
|
|
161
213
|
insert_default_vowel!(string)
|
|
162
214
|
|
|
163
215
|
# Exception: distinguish prefix 'g' and root 'y' (g.y) from root 'g' and subjoined 'y' (gy)
|
|
164
216
|
string.gsub!("གཡ", "ག.ཡ")
|
|
165
217
|
|
|
166
|
-
|
|
167
|
-
|
|
218
|
+
if to == :tibetan
|
|
219
|
+
string.gsub(CHARACTER_TABLE_REGEX, CHARACTER_TABLE)
|
|
220
|
+
else
|
|
221
|
+
character_table = Module.const_get(to.to_s.capitalize)::CHARACTER_TABLE
|
|
222
|
+
string.gsub(/#{Regexp.union(character_table.keys).source}/i, character_table)
|
|
223
|
+
end
|
|
168
224
|
end
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
225
|
+
alias t transliterate
|
|
226
|
+
|
|
227
|
+
private
|
|
228
|
+
|
|
229
|
+
def insert_default_vowel!(string)
|
|
230
|
+
return if VOWELS_REGEX.match?(string)
|
|
231
|
+
|
|
232
|
+
if (sub_idx = string.rindex(SUBSCRIPTS_REGEX))
|
|
233
|
+
string.insert(sub_idx + 1, DEFAULT_VOWEL)
|
|
234
|
+
elsif CONSONANTS_REGEX.match?(string)
|
|
235
|
+
# Count ONLY Tibetan consonants/subscripts to identify the root letter.
|
|
236
|
+
# We ignore inline punctuation (like ») to avoid inflating the string size
|
|
237
|
+
# and placing the implicit 'a' in the wrong position.
|
|
238
|
+
tibetan_chars_count = 0
|
|
239
|
+
string.each_char do |c|
|
|
240
|
+
tibetan_chars_count += 1 if CONSONANTS_SUBSCRIPTS_SET.include?(c)
|
|
241
|
+
end
|
|
242
|
+
root_idx = tibetan_chars_count > 2 ? 1 : 0
|
|
243
|
+
|
|
244
|
+
# Find the actual string index corresponding to the root consonant
|
|
245
|
+
current = -1
|
|
246
|
+
actual_index = -1
|
|
247
|
+
string.each_char.with_index do |c, i|
|
|
248
|
+
next unless CONSONANTS_SUBSCRIPTS_SET.include?(c)
|
|
249
|
+
|
|
250
|
+
current += 1
|
|
251
|
+
if current == root_idx
|
|
252
|
+
actual_index = i
|
|
253
|
+
break
|
|
195
254
|
end
|
|
196
|
-
string = string.insert(actual_index+1, DEFAULT_VOWEL) if actual_index >= 0
|
|
197
255
|
end
|
|
256
|
+
string.insert(actual_index + 1, DEFAULT_VOWEL) if actual_index >= 0
|
|
198
257
|
end
|
|
199
258
|
end
|
|
200
259
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tibetan
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- rovetz
|
|
@@ -15,68 +15,69 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '2.
|
|
18
|
+
version: '2.0'
|
|
19
19
|
type: :development
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '2.
|
|
25
|
+
version: '2.0'
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
|
-
name:
|
|
27
|
+
name: minitest
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
29
29
|
requirements:
|
|
30
|
-
- - "
|
|
30
|
+
- - ">="
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '
|
|
32
|
+
version: '5.16'
|
|
33
33
|
type: :development
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
|
-
- - "
|
|
37
|
+
- - ">="
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: '
|
|
39
|
+
version: '5.16'
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
|
-
name:
|
|
41
|
+
name: rake
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
|
43
43
|
requirements:
|
|
44
|
-
- - "
|
|
44
|
+
- - ">="
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: '
|
|
46
|
+
version: '13.0'
|
|
47
47
|
type: :development
|
|
48
48
|
prerelease: false
|
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
50
50
|
requirements:
|
|
51
|
-
- - "
|
|
51
|
+
- - ">="
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
|
-
version: '
|
|
53
|
+
version: '13.0'
|
|
54
54
|
description: Romanization (transliteration) of Tibetan. Converts Tibetan text to the
|
|
55
55
|
Roman (Latin) script using THL EWTS (Extended Wylie Transliteration Scheme)
|
|
56
56
|
email:
|
|
57
57
|
- zakbox@gmail.com
|
|
58
|
-
executables:
|
|
58
|
+
executables:
|
|
59
|
+
- tibetan
|
|
59
60
|
extensions: []
|
|
60
61
|
extra_rdoc_files: []
|
|
61
62
|
files:
|
|
62
|
-
- ".
|
|
63
|
-
- ".
|
|
63
|
+
- ".rubocop.yml"
|
|
64
|
+
- ".ruby-version"
|
|
64
65
|
- CHANGELOG.md
|
|
65
66
|
- CODE_OF_CONDUCT.md
|
|
66
|
-
- Gemfile
|
|
67
|
-
- Gemfile.lock
|
|
68
67
|
- LICENSE.txt
|
|
69
68
|
- README.md
|
|
70
69
|
- Rakefile
|
|
71
|
-
-
|
|
72
|
-
- bin/setup
|
|
70
|
+
- exe/tibetan
|
|
73
71
|
- lib/tibetan.rb
|
|
74
72
|
- lib/tibetan/version.rb
|
|
75
|
-
- tibetan.gemspec
|
|
76
73
|
homepage: https://github.com/rovetz/tibetan
|
|
77
74
|
licenses:
|
|
78
75
|
- MIT
|
|
79
|
-
metadata:
|
|
76
|
+
metadata:
|
|
77
|
+
source_code_uri: https://github.com/rovetz/tibetan
|
|
78
|
+
changelog_uri: https://github.com/rovetz/tibetan/blob/main/CHANGELOG.md
|
|
79
|
+
bug_tracker_uri: https://github.com/rovetz/tibetan/issues
|
|
80
|
+
rubygems_mfa_required: 'true'
|
|
80
81
|
rdoc_options: []
|
|
81
82
|
require_paths:
|
|
82
83
|
- lib
|
|
@@ -84,14 +85,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
84
85
|
requirements:
|
|
85
86
|
- - ">="
|
|
86
87
|
- !ruby/object:Gem::Version
|
|
87
|
-
version:
|
|
88
|
+
version: 3.0.0
|
|
88
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
90
|
requirements:
|
|
90
91
|
- - ">="
|
|
91
92
|
- !ruby/object:Gem::Version
|
|
92
93
|
version: '0'
|
|
93
94
|
requirements: []
|
|
94
|
-
rubygems_version: 4.0.
|
|
95
|
+
rubygems_version: 4.0.16
|
|
95
96
|
specification_version: 4
|
|
96
97
|
summary: Romanization (transliteration) of Tibetan
|
|
97
98
|
test_files: []
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: .
|
|
3
|
-
specs:
|
|
4
|
-
tibetan (0.1.5)
|
|
5
|
-
|
|
6
|
-
GEM
|
|
7
|
-
remote: https://rubygems.org/
|
|
8
|
-
specs:
|
|
9
|
-
drb (2.2.3)
|
|
10
|
-
minitest (6.0.2)
|
|
11
|
-
drb (~> 2.0)
|
|
12
|
-
prism (~> 1.5)
|
|
13
|
-
prism (1.9.0)
|
|
14
|
-
rake (13.3.1)
|
|
15
|
-
|
|
16
|
-
PLATFORMS
|
|
17
|
-
ruby
|
|
18
|
-
|
|
19
|
-
DEPENDENCIES
|
|
20
|
-
bundler (>= 2.6)
|
|
21
|
-
minitest (~> 6.0)
|
|
22
|
-
rake (~> 13.3)
|
|
23
|
-
tibetan!
|
|
24
|
-
|
|
25
|
-
BUNDLED WITH
|
|
26
|
-
4.0.9
|
data/bin/console
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
require "bundler/setup"
|
|
4
|
-
require "tibetan"
|
|
5
|
-
|
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
-
|
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
-
# require "pry"
|
|
11
|
-
# Pry.start
|
|
12
|
-
|
|
13
|
-
require "irb"
|
|
14
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED
data/tibetan.gemspec
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
lib = File.expand_path("../lib", __FILE__)
|
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
-
|
|
4
|
-
require "tibetan/version"
|
|
5
|
-
|
|
6
|
-
Gem::Specification.new do |spec|
|
|
7
|
-
spec.name = "tibetan"
|
|
8
|
-
spec.version = Tibetan::VERSION
|
|
9
|
-
spec.authors = ["rovetz"]
|
|
10
|
-
spec.email = ["zakbox@gmail.com"]
|
|
11
|
-
|
|
12
|
-
spec.summary = "Romanization (transliteration) of Tibetan"
|
|
13
|
-
spec.description = "Romanization (transliteration) of Tibetan. Converts Tibetan text to the Roman (Latin) script using THL EWTS (Extended Wylie Transliteration Scheme)"
|
|
14
|
-
spec.homepage = "https://github.com/rovetz/tibetan"
|
|
15
|
-
spec.license = "MIT"
|
|
16
|
-
|
|
17
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
18
|
-
f.match(%r{^(test|spec|features)/})
|
|
19
|
-
end
|
|
20
|
-
spec.bindir = "exe"
|
|
21
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
22
|
-
spec.require_paths = ["lib"]
|
|
23
|
-
|
|
24
|
-
spec.add_development_dependency "bundler", ">= 2.6"
|
|
25
|
-
spec.add_development_dependency "rake", "~> 13.3"
|
|
26
|
-
spec.add_development_dependency "minitest", "~> 6.0"
|
|
27
|
-
end
|