Skip to content

Commit

Permalink
Introduce lexicon builder
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysonvirissimo committed Nov 30, 2023
1 parent 6807a32 commit 4a930eb
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ gemspec
gem "i18n"
gem "rake", "~> 12.0"
gem "rspec", "~> 3.0"
gem "builder"
gem "standard", group: [:development, :test]
4 changes: 3 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
PATH
remote: .
specs:
medieval_latina (2.0.6)
medieval_latina (2.1.0)
i18n

GEM
remote: https://rubygems.org/
specs:
ast (2.4.0)
builder (3.2.4)
concurrent-ruby (1.2.2)
diff-lcs (1.3)
i18n (1.13.0)
Expand Down Expand Up @@ -50,6 +51,7 @@ PLATFORMS
ruby

DEPENDENCIES
builder
i18n
medieval_latina!
rake (~> 12.0)
Expand Down
1 change: 1 addition & 0 deletions lib/medieval_latina.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "medieval_latina/dictionary"
require "medieval_latina/initializer"
require "medieval_latina/lexicon_builder"
require "medieval_latina/version"
require "set"

Expand Down
49 changes: 49 additions & 0 deletions lib/medieval_latina/lexicon_builder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require "builder"

class MedievalLatina
class LexiconBuilder
def initialize
@hash = parts.each_with_object({}) do |part, hash|
hash.merge(part)
end

FREQUENCY_LIST.each do |word, metadata|
if metadata.key?(:ipa)
@hash[word] = metadata[:ipa]
end
end

@xml = Builder::XmlMarkup.new(indent: 2)
end

def call
xml.instruct! :xml, encoding: "UTF-8"
xml.lexicon(xmlns: URL, version: "1.0") do
grouped_hash.each do |phonetics, words|
xml.lexeme do
words.each { |word| xml.grapheme word }
xml.phoneme phonetics
end
end
end
end

private

attr_reader :hash, :xml

def grouped_hash
hash.group_by do |_, phonetics|
phonetics
end.transform_values do |pairs|
pairs.map(&:first)
end
end

def parts
[ADJECTIVES, ADVERBS, NOUNS, VERBS]
end

URL = "http://www.w3.org/2005/01/pronunciation-lexicon".freeze
end
end
2 changes: 1 addition & 1 deletion lib/medieval_latina/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class MedievalLatina
VERSION = "2.0.6".freeze
VERSION = "2.1.0".freeze
end

0 comments on commit 4a930eb

Please sign in to comment.