voxbi 1.0.4 → 1.0.5
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.
- checksums.yaml +4 -4
- data/data/pairs.wav +0 -0
- data/lib/modules/rule_parsable.rb +30 -0
- data/lib/rule_store.rb +22 -0
- data/lib/services/get_pairs_service.rb +1 -5
- data/lib/services/linkage_service.rb +1 -5
- data/lib/services/phonetics_converter_service.rb +1 -5
- data/lib/voxbi.rb +1 -5
- data/voxbi-1.0.4.gem +0 -0
- data/voxbi.gemspec +1 -1
- metadata +4 -2
- data/lib/modules/rulable.rb +0 -56
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41108b63c80b692d9f0c3eba09782a7565c6bd68
|
4
|
+
data.tar.gz: 465f1b68e7ee7e455bfe3bffc074322f8478f257
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65a76f3ed1361264dad019b6926c0ca03f4b5529cb0a1849691dbf62eda709f0c3ef87235f54356c4b525507e72bf1b8d0605e63b6b856fc63e92054b659fd52
|
7
|
+
data.tar.gz: 2f6b3087dbee91a0fc32397bda8c94de254f9b5fa1e860356824f9450328ae399917549322568fa6573c22fdaada08f524c7394a5889437a358928a510847b60
|
data/data/pairs.wav
CHANGED
Binary file
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "json"
|
2
|
+
require "csv"
|
3
|
+
|
4
|
+
module RuleParsable
|
5
|
+
DATA_PATH = File.expand_path('../../data', __dir__)
|
6
|
+
|
7
|
+
def self.included(klass)
|
8
|
+
klass.extend(ClassMethods)
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def parse_rule_file(filename, file_format)
|
13
|
+
absolute_file_path = absolute_path_for(filename, file_format)
|
14
|
+
|
15
|
+
case file_format
|
16
|
+
when :csv then parse_csv(absolute_file_path)
|
17
|
+
when :json then JSON.parse(File.read(absolute_file_path))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse_csv(file_path)
|
22
|
+
parsed_csv = CSV.read(file_path, col_sep: '#')
|
23
|
+
parsed_csv.first.length > 1 ? Hash[parsed_csv] : parsed_csv.flatten
|
24
|
+
end
|
25
|
+
|
26
|
+
def absolute_path_for(filename, file_format)
|
27
|
+
"#{DATA_PATH}/#{filename}" + ".#{file_format}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/rule_store.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
class RuleStore
|
2
|
+
include RuleParsable
|
3
|
+
|
4
|
+
CSV_FILENAMES = %i(conversion linkage exceptions available_pairs).freeze
|
5
|
+
JSON_FILENAMES = %i(dictionary).freeze
|
6
|
+
|
7
|
+
def self.class_memoize(filename, file_format)
|
8
|
+
class_variable_set(:"@@#{filename}", parse_rule_file(filename, file_format))
|
9
|
+
|
10
|
+
self.define_singleton_method(filename) do
|
11
|
+
class_variable_get(:"@@#{filename}")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
CSV_FILENAMES.each do |filename|
|
16
|
+
class_memoize filename, :csv
|
17
|
+
end
|
18
|
+
|
19
|
+
JSON_FILENAMES.each do |filename|
|
20
|
+
class_memoize filename, :json
|
21
|
+
end
|
22
|
+
end
|
@@ -1,8 +1,4 @@
|
|
1
1
|
class GetPairsService
|
2
|
-
include Rulable
|
3
|
-
|
4
|
-
memoize_csv :available_pairs
|
5
|
-
|
6
2
|
attr_reader :phonetic_text
|
7
3
|
|
8
4
|
def initialize(phonetic_text)
|
@@ -22,7 +18,7 @@ class GetPairsService
|
|
22
18
|
|
23
19
|
[].tap do |pairs|
|
24
20
|
while word.length != 0
|
25
|
-
matching_pair = available_pairs.detect{ |pair| word.match(/^#{pair}/) }
|
21
|
+
matching_pair = RuleStore.available_pairs.detect{ |pair| word.match(/^#{pair}/) }
|
26
22
|
word.sub!(/^#{matching_pair}/,"")
|
27
23
|
pairs << matching_pair
|
28
24
|
end
|
@@ -1,8 +1,4 @@
|
|
1
1
|
class LinkageService
|
2
|
-
include Rulable
|
3
|
-
|
4
|
-
memoize_csv :linkage
|
5
|
-
|
6
2
|
attr_accessor :prepared_text, :phonetic_text
|
7
3
|
|
8
4
|
def initialize(prepared_text, phonetic_text)
|
@@ -36,6 +32,6 @@ class LinkageService
|
|
36
32
|
end
|
37
33
|
|
38
34
|
def linkage_rule_for(link_string)
|
39
|
-
linkage.select {|k,v| link_string =~ /#{k}/ }.first
|
35
|
+
RuleStore.linkage.select {|k,v| link_string =~ /#{k}/ }.first
|
40
36
|
end
|
41
37
|
end
|
@@ -1,10 +1,6 @@
|
|
1
1
|
require "timeout"
|
2
2
|
|
3
3
|
class PhoneticsConverterService
|
4
|
-
include Rulable
|
5
|
-
|
6
|
-
memoize_csv :conversion
|
7
|
-
|
8
4
|
DEFAULT_TIMEOUT = 5.freeze
|
9
5
|
|
10
6
|
attr_accessor :word, :phonetized_word
|
@@ -39,6 +35,6 @@ class PhoneticsConverterService
|
|
39
35
|
end
|
40
36
|
|
41
37
|
def conversion_rule_for(word)
|
42
|
-
conversion.detect{ |rule, phonetic| word =~ /#{rule}/ }
|
38
|
+
RuleStore.conversion.detect{ |rule, phonetic| word =~ /#{rule}/ }
|
43
39
|
end
|
44
40
|
end
|
data/lib/voxbi.rb
CHANGED
@@ -5,10 +5,6 @@ File.expand_path('..', __dir__).tap do |root_path|
|
|
5
5
|
end
|
6
6
|
|
7
7
|
class Voxbi
|
8
|
-
include Rulable
|
9
|
-
|
10
|
-
memoize_json :dictionary
|
11
|
-
|
12
8
|
attr_accessor :text
|
13
9
|
|
14
10
|
ROOT_PATH = File.expand_path('..', __dir__).freeze
|
@@ -46,7 +42,7 @@ class Voxbi
|
|
46
42
|
|
47
43
|
def phonetic_text
|
48
44
|
@phonetic_text ||= prepared_text.map do |word|
|
49
|
-
dictionary[word] ||
|
45
|
+
RuleStore.dictionary[word] ||
|
50
46
|
PhoneticsConverterService.new(word).call
|
51
47
|
end
|
52
48
|
end
|
data/voxbi-1.0.4.gem
ADDED
Binary file
|
data/voxbi.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: voxbi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Galaad Gauthier
|
@@ -318,7 +318,8 @@ files:
|
|
318
318
|
- data/pairs/σ.ogg
|
319
319
|
- data/pairs/ϵ.ogg
|
320
320
|
- lib/extensions/string.rb
|
321
|
-
- lib/modules/
|
321
|
+
- lib/modules/rule_parsable.rb
|
322
|
+
- lib/rule_store.rb
|
322
323
|
- lib/services/get_pairs_service.rb
|
323
324
|
- lib/services/get_syllables_service.rb
|
324
325
|
- lib/services/linkage_service.rb
|
@@ -326,6 +327,7 @@ files:
|
|
326
327
|
- lib/services/prepare_text_service.rb
|
327
328
|
- lib/voxbi.rb
|
328
329
|
- voxbi-1.0.1.gem
|
330
|
+
- voxbi-1.0.4.gem
|
329
331
|
- voxbi-1.0.gem
|
330
332
|
- voxbi.gemspec
|
331
333
|
homepage: https://github.com/Galaad-Gauthier/VoxBi
|
data/lib/modules/rulable.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require "json"
|
2
|
-
require "csv"
|
3
|
-
|
4
|
-
module Rulable
|
5
|
-
DATA_PATH = File.expand_path('../../data', __dir__)
|
6
|
-
CSV_FILENAMES = %i(conversion linkage exceptions available_pairs).freeze
|
7
|
-
JSON_FILENAMES = %i(dictionary).freeze
|
8
|
-
|
9
|
-
def self.included(klass)
|
10
|
-
klass.extend(Macros)
|
11
|
-
end
|
12
|
-
|
13
|
-
def memoize_file_content(filename, file_format)
|
14
|
-
instance_variable_get("@#{filename}") ||
|
15
|
-
instance_variable_set("@#{filename}", parse_rule_file(filename, file_format))
|
16
|
-
end
|
17
|
-
|
18
|
-
def parse_rule_file(filename, file_format)
|
19
|
-
absolute_file_path = absolute_path_for(filename, file_format)
|
20
|
-
|
21
|
-
case file_format
|
22
|
-
when :csv then parse_csv(absolute_file_path)
|
23
|
-
when :json then JSON.parse(File.read(absolute_file_path))
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def parse_csv(file_path)
|
28
|
-
parsed_csv = CSV.read(file_path, col_sep: '#')
|
29
|
-
|
30
|
-
parsed_csv.first.length > 1 ? Hash[parsed_csv] : parsed_csv.flatten
|
31
|
-
end
|
32
|
-
|
33
|
-
def absolute_path_for(filename, file_format)
|
34
|
-
"#{DATA_PATH}/#{filename}" + ".#{file_format}"
|
35
|
-
end
|
36
|
-
|
37
|
-
module Macros
|
38
|
-
def memoize_csv(*filenames)
|
39
|
-
permitted_filenames = filenames.select{ |filename| CSV_FILENAMES.include?(filename) }
|
40
|
-
memoize_file(permitted_filenames, file_format: :csv)
|
41
|
-
end
|
42
|
-
|
43
|
-
def memoize_json(*filenames)
|
44
|
-
permitted_filenames = filenames.select{ |filename| JSON_FILENAMES.include?(filename) }
|
45
|
-
memoize_file(permitted_filenames, file_format: :json)
|
46
|
-
end
|
47
|
-
|
48
|
-
def memoize_file(filenames, file_format:)
|
49
|
-
filenames.each do |filename|
|
50
|
-
define_method(filename) do
|
51
|
-
memoize_file_content(filename, file_format)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|