-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace builder with bin/build script
- Loading branch information
1 parent
68f0d39
commit 8fe27c1
Showing
17 changed files
with
19,404 additions
and
7,299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.