medieval_latina 1.3.1 → 2.0.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.
@@ -0,0 +1,3 @@
1
+ require "i18n"
2
+
3
+ I18n.config.available_locales = :en
@@ -1,3 +1,3 @@
1
1
  class MedievalLatina
2
- VERSION = "1.3.1".freeze
2
+ VERSION = "2.0.0".freeze
3
3
  end
@@ -1,22 +1,39 @@
1
1
  require "medieval_latina/dictionary"
2
+ require "medieval_latina/initializer"
2
3
  require "medieval_latina/version"
3
4
  require "set"
4
5
 
5
6
  class MedievalLatina
6
7
  def self.[](text)
7
- prepare_text(text).map do |word|
8
- DICTIONARY[word] || new(word).call
9
- end.join(" ")
8
+ prepared_words = prepare_text(text).map do |string|
9
+ if word?(string)
10
+ metadata = DICTIONARY.fetch(string, {})
11
+
12
+ if metadata.key?(:pronunciation)
13
+ metadata[:pronunciation]
14
+ else
15
+ new(string).call
16
+ end
17
+ else
18
+ string
19
+ end
20
+ end
21
+
22
+ rejoin_words(prepared_words)
10
23
  end
11
24
 
12
25
  def self.prepare_text(text)
13
- text.split(" ").map do |word|
14
- prepare_word(word)
26
+ text.scan(/[\p{Alnum}'-]+|[[:punct:]]+/).map do |string|
27
+ if word?(string)
28
+ prepare_word(string)
29
+ else
30
+ string
31
+ end
15
32
  end
16
33
  end
17
34
 
18
35
  def self.prepare_word(word)
19
- word.gsub(/\W+/, " ").strip.downcase
36
+ word.gsub(/\P{Alnum}+/, " ").strip.downcase
20
37
  end
21
38
 
22
39
  def self.adjective?(word)
@@ -47,17 +64,30 @@ class MedievalLatina
47
64
  NOUNS
48
65
  end
49
66
 
67
+ def self.rejoin_words(array)
68
+ array
69
+ .join(" ")
70
+ .gsub(/ +?,/, ",")
71
+ .gsub(/ +?;/, ";")
72
+ .gsub(/ +?\./, ".")
73
+ .gsub(/ +?\?/, "?")
74
+ end
75
+
50
76
  def self.verbs
51
77
  VERBS
52
78
  end
53
79
 
80
+ def self.word?(string)
81
+ string.match?(/\w/)
82
+ end
83
+
54
84
  def self.words
55
85
  ADJECTIVES | ADVERBS | Set.new(DICTIONARY.keys) | NOUNS | VERBS
56
86
  end
57
87
 
58
88
  def initialize(word)
59
89
  @index = 0
60
- @word = word.downcase
90
+ @word = I18n.transliterate(word.downcase)
61
91
  end
62
92
 
63
93
  def call
@@ -123,7 +153,7 @@ class MedievalLatina
123
153
 
124
154
  def initialize(text, index)
125
155
  @character = text[index]
126
- @rest = text[index + 1..-1].chars.join
156
+ @rest = text[index + 1..].chars.join
127
157
  end
128
158
 
129
159
  def to_team
@@ -132,4 +162,13 @@ class MedievalLatina
132
162
  end
133
163
 
134
164
  class Error < StandardError; end
165
+
166
+ DICTIONARY = FREQUENCY_LIST.each_with_object({}) do |(word, metadata), hash|
167
+ hash[word] = metadata
168
+
169
+ sanitized_word = I18n.transliterate(word)
170
+ unless hash.key?(sanitized_word)
171
+ hash[sanitized_word] = metadata
172
+ end
173
+ end
135
174
  end
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.description = description
16
16
  spec.homepage = "https://github.com/jaysonvirissimo/medieval_latina"
17
17
  spec.license = "MIT"
18
- spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
18
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
19
19
  spec.metadata["allowed_push_host"] = "https://rubygems.org/"
20
20
  spec.metadata["homepage_uri"] = spec.homepage
21
21
  spec.metadata["source_code_uri"] = github_uri
@@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.bindir = "exe"
29
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ["lib"]
31
+ spec.add_dependency "i18n"
31
32
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: medieval_latina
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jayson Virissimo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-27 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2023-08-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: i18n
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: |
14
28
  There are good text-to-speech engines for English and classical Latin, but none for medieval Latin.
15
29
  MedievalLatina converts Latin text to a kind of phonetic spelling that can be read by English text-to-speech engines.
@@ -22,6 +36,7 @@ files:
22
36
  - ".github/workflows/tests.yml"
23
37
  - ".gitignore"
24
38
  - ".rspec"
39
+ - ".standard.yml"
25
40
  - ".tool-versions"
26
41
  - Gemfile
27
42
  - Gemfile.lock
@@ -32,6 +47,7 @@ files:
32
47
  - bin/setup
33
48
  - lib/medieval_latina.rb
34
49
  - lib/medieval_latina/dictionary.rb
50
+ - lib/medieval_latina/initializer.rb
35
51
  - lib/medieval_latina/version.rb
36
52
  - medieval_latina.gemspec
37
53
  homepage: https://github.com/jaysonvirissimo/medieval_latina
@@ -50,7 +66,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
50
66
  requirements:
51
67
  - - ">="
52
68
  - !ruby/object:Gem::Version
53
- version: 2.6.0
69
+ version: 2.7.0
54
70
  required_rubygems_version: !ruby/object:Gem::Requirement
55
71
  requirements:
56
72
  - - ">="