Skip to content

Commit

Permalink
Replace builder with bin/build script
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysonvirissimo committed Apr 28, 2024
1 parent 68f0d39 commit 8fe27c1
Show file tree
Hide file tree
Showing 17 changed files with 19,404 additions and 7,299 deletions.
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ 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 @@ -56,7 +55,6 @@ PLATFORMS
ruby

DEPENDENCIES
builder
medieval_latina!
nokogiri
rake (~> 12.0)
Expand Down
53 changes: 49 additions & 4 deletions bin/build
Original file line number Diff line number Diff line change
@@ -1,7 +1,52 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "medieval_latina"
require "medieval_latina/lexicon_builder"
require 'json'
require 'rexml/document'
require 'cgi'
include REXML

MedievalLatina::LexiconBuilder.write
def create_pls_file(file_path, words)
doc = Document.new
doc.add_element 'lexicon', {'version' => '1.0',
'xmlns' => 'http://www.w3.org/2005/01/pronunciation-lexicon',
'alphabet' => 'ipa',
'xml:lang' => 'en-US'}

words.each do |word, pronunciation|
lexeme = Element.new('lexeme')
grapheme = Element.new('grapheme')
phoneme = Element.new('phoneme')

grapheme.text = CGI.unescapeHTML(word)
phoneme.text = pronunciation

lexeme.add_element(grapheme)
lexeme.add_element(phoneme)

doc.root.add_element(lexeme)
end

File.open(file_path, 'w') do |file|
doc.write(file, 2)
file.write("\n")
end
end

file_path = File.join(File.dirname(__FILE__), '..', 'data', 'dictionary.json')
pronunciation_guide = JSON
.parse(File.read(file_path))
.each_with_object({}) do |(word, metadata), hash|
if metadata["ipa"]
hash[word] = metadata["ipa"]
end
end

# Split the words across multiple PLS files
lexicons_dir = File.join(File.dirname(__FILE__), '..', 'lexicons')
size = pronunciation_guide.size
number = size / 256
fraction = size / number
pronunciation_guide.each_slice(fraction).to_a.each_with_index do |array, index|
formatted_index = sprintf("%02d", index)
create_pls_file(File.join(lexicons_dir, "Latin#{formatted_index}.pls"), array.to_h)
end
Loading

0 comments on commit 8fe27c1

Please sign in to comment.