medieval_latina 2.1.1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ <lexicon version='1.0' xmlns='http://www.w3.org/2005/01/pronunciation-lexicon' alphabet='ipa' xml:lang='en-US'>
2
+ <lexeme>
3
+ <grapheme>
4
+ vulnero
5
+ </grapheme>
6
+ <phoneme>
7
+ ˈvul.ne.ro
8
+ </phoneme>
9
+ </lexeme>
10
+ </lexicon>
@@ -0,0 +1,27 @@
1
+ class MedievalLatina
2
+ class Lexicon
3
+ LEXICON_DIR = File.expand_path("../../lexicons", __dir__)
4
+
5
+ def self.list_files
6
+ Dir.glob(File.join(LEXICON_DIR, "*.pls"))
7
+ end
8
+
9
+ def self.get_file_path(file_name)
10
+ path = File.join(LEXICON_DIR, file_name)
11
+ return path if File.exist?(path)
12
+ raise "Lexicon file not found: #{file_name}"
13
+ end
14
+
15
+ def self.get_file_content(file_name)
16
+ path = get_file_path(file_name)
17
+ File.read(path)
18
+ end
19
+
20
+ def self.file_names_with_contents
21
+ list_files.each_with_object({}) do |file_path, files_content|
22
+ file_name, extension = File.basename(file_path).split(".")
23
+ files_content[file_name] = get_file_content("#{file_name}.#{extension}")
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,61 +1,44 @@
1
- require "builder"
1
+ require "cgi"
2
+ require "rexml/document"
2
3
 
3
4
  class MedievalLatina
4
5
  class LexiconBuilder
5
- def self.write
6
- new.call.write
7
- end
8
-
9
- def initialize
10
- @hash = parts.each_with_object({}) do |part, hash|
11
- hash.merge(part)
12
- end
13
-
14
- FREQUENCY_LIST.each do |word, metadata|
15
- if metadata.key?(:ipa)
16
- @hash[word] = metadata[:ipa]
17
- end
18
- end
6
+ include REXML
19
7
 
20
- @xml = Builder::XmlMarkup.new(indent: 2)
8
+ def initialize(words)
9
+ @document = Document.new
10
+ @words = words
21
11
  end
22
12
 
23
13
  def call
24
- xml.instruct! :xml, encoding: "UTF-8"
25
- xml.lexicon(xmlns: URL, version: "1.0") do
26
- grouped_hash.each do |phonetics, words|
27
- xml.lexeme do
28
- words.each { |word| xml.grapheme word }
29
- xml.phoneme phonetics
30
- end
31
- end
32
- end
14
+ document.add_element "lexicon", SPECIFICATION
33
15
 
34
- self
35
- end
16
+ words.each do |word, pronunciation|
17
+ lexeme = Element.new("lexeme")
18
+ grapheme = Element.new("grapheme")
19
+ phoneme = Element.new("phoneme")
36
20
 
37
- def write
38
- File.open("lexicon.pls", "w") do |file|
39
- file.write(xml.target!)
40
- end
41
- end
42
-
43
- private
21
+ grapheme.text = CGI.unescapeHTML(word)
22
+ phoneme.text = pronunciation
44
23
 
45
- attr_reader :hash, :xml
24
+ lexeme.add_element(grapheme)
25
+ lexeme.add_element(phoneme)
46
26
 
47
- def grouped_hash
48
- hash.group_by do |_, phonetics|
49
- phonetics
50
- end.transform_values do |pairs|
51
- pairs.map(&:first)
27
+ document.root.add_element(lexeme)
52
28
  end
53
- end
54
29
 
55
- def parts
56
- [ADJECTIVES, ADVERBS, NOUNS, VERBS]
30
+ document
57
31
  end
58
32
 
59
- URL = "http://www.w3.org/2005/01/pronunciation-lexicon".freeze
33
+ private
34
+
35
+ attr_reader :document, :words
36
+
37
+ SPECIFICATION = {
38
+ "version" => "1.0",
39
+ "xmlns" => "http://www.w3.org/2005/01/pronunciation-lexicon",
40
+ "alphabet" => "ipa",
41
+ "xml:lang" => "en-US"
42
+ }.freeze
60
43
  end
61
44
  end
@@ -1,3 +1,3 @@
1
1
  class MedievalLatina
2
- VERSION = "2.1.1".freeze
2
+ VERSION = "3.1.0".freeze
3
3
  end
@@ -1,8 +1,8 @@
1
- require "medieval_latina/dictionary"
1
+ require "json"
2
2
  require "medieval_latina/initializer"
3
+ require "medieval_latina/lexicon"
3
4
  require "medieval_latina/lexicon_builder"
4
5
  require "medieval_latina/version"
5
- require "set"
6
6
 
7
7
  class MedievalLatina
8
8
  def self.[](text)
@@ -10,8 +10,8 @@ class MedievalLatina
10
10
  if word?(string)
11
11
  metadata = DICTIONARY.fetch(string, {})
12
12
 
13
- if metadata.key?(:pronunciation)
14
- metadata[:pronunciation]
13
+ if metadata.key?("pronunciation")
14
+ metadata["pronunciation"]
15
15
  else
16
16
  new(string).call
17
17
  end
@@ -23,6 +23,15 @@ class MedievalLatina
23
23
  rejoin_words(prepared_words)
24
24
  end
25
25
 
26
+ def self.dictionary
27
+ @data ||= load_data
28
+ end
29
+
30
+ def self.load_data
31
+ file_path = File.join(File.dirname(__FILE__), "../data/dictionary.json")
32
+ JSON.parse(File.read(file_path))
33
+ end
34
+
26
35
  def self.prepare_text(text)
27
36
  text.scan(/[\p{Alnum}'-]+|[[:punct:]]+/).map do |string|
28
37
  if word?(string)
@@ -38,31 +47,47 @@ class MedievalLatina
38
47
  end
39
48
 
40
49
  def self.adjective?(word)
41
- ADJECTIVES.key?(prepare_word(word))
50
+ adjectives.key?(prepare_word(word))
42
51
  end
43
52
 
44
53
  def self.adverb?(word)
45
- ADVERBS.key?(prepare_word(word))
54
+ adverbs.key?(prepare_word(word))
46
55
  end
47
56
 
48
57
  def self.noun?(word)
49
- NOUNS.key?(prepare_word(word))
58
+ nouns.key?(prepare_word(word))
50
59
  end
51
60
 
52
61
  def self.verb?(word)
53
- VERBS.key?(prepare_word(word))
62
+ verbs.key?(prepare_word(word))
54
63
  end
55
64
 
56
65
  def self.adjectives
57
- ADJECTIVES.keys
66
+ DICTIONARY.select do |word, metadata|
67
+ metadata["part"] == "Adjective"
68
+ end
58
69
  end
59
70
 
60
71
  def self.adverbs
61
- ADVERBS.keys
72
+ DICTIONARY.select do |word, metadata|
73
+ metadata["part"] == "Adverb"
74
+ end
62
75
  end
63
76
 
64
77
  def self.nouns
65
- NOUNS.keys
78
+ DICTIONARY.select do |word, metadata|
79
+ metadata["part"] == "Noun"
80
+ end
81
+ end
82
+
83
+ def self.pronunciations_for(words)
84
+ words.map(&:downcase).each_with_object({}) do |word, hash|
85
+ metadata = DICTIONARY[word]
86
+
87
+ if metadata && metadata["ipa"]
88
+ hash[word] = metadata["ipa"]
89
+ end
90
+ end
66
91
  end
67
92
 
68
93
  def self.rejoin_words(array)
@@ -75,7 +100,9 @@ class MedievalLatina
75
100
  end
76
101
 
77
102
  def self.verbs
78
- VERBS.keys
103
+ DICTIONARY.select do |word, metadata|
104
+ metadata["part"] == "Verb"
105
+ end
79
106
  end
80
107
 
81
108
  def self.word?(string)
@@ -83,13 +110,7 @@ class MedievalLatina
83
110
  end
84
111
 
85
112
  def self.words
86
- [
87
- ADJECTIVES,
88
- ADVERBS,
89
- DICTIONARY,
90
- NOUNS,
91
- VERBS
92
- ].flat_map(&:keys).each_with_object(Set.new) { |word, set| set.add(word) }
113
+ DICTIONARY.keys.to_set
93
114
  end
94
115
 
95
116
  def initialize(word)
@@ -123,6 +144,15 @@ class MedievalLatina
123
144
  x: ->(rest) { "ks" }
124
145
  }
125
146
  CONSONENT_TEAMS = {gn: "n-y", qu: "kw"}.freeze
147
+ PARTS_OF_SPEECH = [
148
+ "Adjective",
149
+ "Adverb",
150
+ "Conjunction",
151
+ "Noun",
152
+ "Preposition",
153
+ "Pronoun",
154
+ "Verb"
155
+ ].to_set.freeze
126
156
  SOFT_C = ["e", "i", "ae", "oe"].freeze
127
157
  SOFT_G = SOFT_C
128
158
  SOFT_T = ["i"].freeze
@@ -164,13 +194,13 @@ class MedievalLatina
164
194
  end
165
195
 
166
196
  def to_team
167
- "#{character}#{rest[0]}".intern
197
+ :"#{character}#{rest[0]}"
168
198
  end
169
199
  end
170
200
 
171
201
  class Error < StandardError; end
172
202
 
173
- DICTIONARY = FREQUENCY_LIST.each_with_object({}) do |(word, metadata), hash|
203
+ DICTIONARY = dictionary.each_with_object({}) do |(word, metadata), hash|
174
204
  hash[word] = metadata
175
205
 
176
206
  sanitized_word = I18n.transliterate(word)
@@ -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.7.0")
18
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.2.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
@@ -29,4 +29,9 @@ Gem::Specification.new do |spec|
29
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ["lib"]
31
31
  spec.add_dependency "i18n"
32
+ spec.add_development_dependency "rake", "~> 12.0"
33
+ spec.add_development_dependency "rspec", "~> 3.0"
34
+ spec.add_development_dependency "nokogiri"
35
+ spec.add_development_dependency "standardrb"
36
+ spec.add_development_dependency "jsonlint"
32
37
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: medieval_latina
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jayson Virissimo
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2023-11-30 00:00:00.000000000 Z
10
+ date: 2024-12-26 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: i18n
@@ -24,6 +23,76 @@ dependencies:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
25
  version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '12.0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '12.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: rspec
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: nokogiri
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: standardrb
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: jsonlint
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
27
96
  description: |
28
97
  There are good text-to-speech engines for English and classical Latin, but none for medieval Latin.
29
98
  MedievalLatina converts Latin text to a kind of phonetic spelling that can be read by English text-to-speech engines.
@@ -45,11 +114,22 @@ files:
45
114
  - Rakefile
46
115
  - bin/build
47
116
  - bin/console
117
+ - bin/lint
48
118
  - bin/setup
49
- - lexicon.pls
119
+ - data/dictionary.json
120
+ - lexicons/Latin00.pls
121
+ - lexicons/Latin01.pls
122
+ - lexicons/Latin02.pls
123
+ - lexicons/Latin03.pls
124
+ - lexicons/Latin04.pls
125
+ - lexicons/Latin05.pls
126
+ - lexicons/Latin06.pls
127
+ - lexicons/Latin07.pls
128
+ - lexicons/Latin08.pls
129
+ - lexicons/Latin09.pls
50
130
  - lib/medieval_latina.rb
51
- - lib/medieval_latina/dictionary.rb
52
131
  - lib/medieval_latina/initializer.rb
132
+ - lib/medieval_latina/lexicon.rb
53
133
  - lib/medieval_latina/lexicon_builder.rb
54
134
  - lib/medieval_latina/version.rb
55
135
  - medieval_latina.gemspec
@@ -61,7 +141,6 @@ metadata:
61
141
  homepage_uri: https://github.com/jaysonvirissimo/medieval_latina
62
142
  source_code_uri: https://github.com/jaysonvirissimo/medieval_latina
63
143
  changelog_uri: https://github.com/jaysonvirissimo/medieval_latina
64
- post_install_message:
65
144
  rdoc_options: []
66
145
  require_paths:
67
146
  - lib
@@ -69,15 +148,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
148
  requirements:
70
149
  - - ">="
71
150
  - !ruby/object:Gem::Version
72
- version: 2.7.0
151
+ version: 3.2.0
73
152
  required_rubygems_version: !ruby/object:Gem::Requirement
74
153
  requirements:
75
154
  - - ">="
76
155
  - !ruby/object:Gem::Version
77
156
  version: '0'
78
157
  requirements: []
79
- rubygems_version: 3.4.1
80
- signing_key:
158
+ rubygems_version: 3.6.2
81
159
  specification_version: 4
82
160
  summary: Transform medieval Latin text into phonetic English
83
161
  test_files: []