phonetics 3.0.7 → 3.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +1 -0
- data/.rubocop.yml +1 -0
- data/VERSION +1 -1
- data/lib/phonetics/code_generator.rb +1 -1
- data/lib/phonetics/distances.rb +9 -3
- data/lib/phonetics/levenshtein.rb +2 -0
- data/lib/phonetics/ruby_levenshtein.rb +6 -4
- data/lib/phonetics/transcriptions.rb +6 -4
- data/phonetics.gemspec +2 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d643b3ab5556532c58d98e833a24d5d51fb63f2ad35cfe3c9a6d45cda7857f1
|
4
|
+
data.tar.gz: 70151659ab727a05ebdc940ef9fc9135fb90f7ffbf84457a3f81ce66ef470ea5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81399b9bacb9eb9f66bc149f2b628f877f6e18cb5009c897db93065a5311e5b90dce62c8d3b5dedd4aff25009c66da30ba1484be21beea3f318cdfda67be25d4
|
7
|
+
data.tar.gz: 76225613a5a2a1865637a0ad0673129e1923235242aa6d46239098c95bf69d0e40c9c220c550249ba62f8285d50f6ae17fb27dc0e533af9f22e983badfc4042a
|
data/.github/workflows/test.yml
CHANGED
data/.rubocop.yml
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0.
|
1
|
+
3.0.8
|
data/lib/phonetics/distances.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'delegate'
|
4
|
+
require 'set'
|
4
5
|
|
5
6
|
module Phonetics
|
6
7
|
extend self
|
@@ -131,6 +132,8 @@ module Phonetics
|
|
131
132
|
)
|
132
133
|
# rubocop:enable Layout/TrailingWhitespace
|
133
134
|
|
135
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
136
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
134
137
|
# Parse the ChartData into a lookup table where we can retrieve attributes
|
135
138
|
# for each phoneme
|
136
139
|
def features
|
@@ -176,6 +179,8 @@ module Phonetics
|
|
176
179
|
end
|
177
180
|
end
|
178
181
|
end
|
182
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
183
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
179
184
|
|
180
185
|
def phonemes
|
181
186
|
@phonemes ||= features.keys
|
@@ -228,11 +233,12 @@ module Phonetics
|
|
228
233
|
|
229
234
|
def _distance(phoneme1, phoneme2)
|
230
235
|
types = [Symbols.fetch(phoneme1), Symbols.fetch(phoneme2)].sort
|
231
|
-
|
236
|
+
case types
|
237
|
+
when %i[consonant vowel]
|
232
238
|
1.0
|
233
|
-
|
239
|
+
when %i[vowel vowel]
|
234
240
|
Vowels.distance(phoneme1, phoneme2)
|
235
|
-
|
241
|
+
when %i[consonant consonant]
|
236
242
|
Consonants.distance(phoneme1, phoneme2)
|
237
243
|
end
|
238
244
|
end
|
@@ -16,10 +16,12 @@ module Phonetics
|
|
16
16
|
module Levenshtein
|
17
17
|
extend ::PhoneticsLevenshteinCBinding
|
18
18
|
|
19
|
+
# rubocop:disable Style/OptionalBooleanParameter
|
19
20
|
def self.distance(str1, str2, verbose = false)
|
20
21
|
return if str1.nil? || str2.nil?
|
21
22
|
|
22
23
|
internal_phonetic_distance(str1, str2, verbose)
|
23
24
|
end
|
25
|
+
# rubocop:enable Style/OptionalBooleanParameter
|
24
26
|
end
|
25
27
|
end
|
@@ -16,6 +16,7 @@ module Phonetics
|
|
16
16
|
class RubyLevenshtein
|
17
17
|
attr_reader :str1, :str2, :len1, :len2, :matrix
|
18
18
|
|
19
|
+
# rubocop:disable Style/OptionalBooleanParameter
|
19
20
|
def initialize(ipa_str1, ipa_str2, verbose = false)
|
20
21
|
@str1 = ipa_str1.each_char.select { |c| Phonetics.phonemes.include?(c) }.join
|
21
22
|
@str2 = ipa_str2.each_char.select { |c| Phonetics.phonemes.include?(c) }.join
|
@@ -26,6 +27,11 @@ module Phonetics
|
|
26
27
|
set_edit_distances(@str1, @str2)
|
27
28
|
end
|
28
29
|
|
30
|
+
def self.distance(str1, str2, verbose = false)
|
31
|
+
new(str1, str2, verbose).distance
|
32
|
+
end
|
33
|
+
# rubocop:enable Style/OptionalBooleanParameter
|
34
|
+
|
29
35
|
def distance
|
30
36
|
return 0 if walk.empty?
|
31
37
|
|
@@ -33,10 +39,6 @@ module Phonetics
|
|
33
39
|
walk.last[:distance]
|
34
40
|
end
|
35
41
|
|
36
|
-
def self.distance(str1, str2, verbose = false)
|
37
|
-
new(str1, str2, verbose).distance
|
38
|
-
end
|
39
|
-
|
40
42
|
private
|
41
43
|
|
42
44
|
def walk
|
@@ -22,7 +22,7 @@ module Phonetics
|
|
22
22
|
return unless entry['ipa']
|
23
23
|
|
24
24
|
SourcesByPreference.each do |preferred_source|
|
25
|
-
entry['ipa'].
|
25
|
+
entry['ipa'].each_key do |source|
|
26
26
|
return entry['ipa'][source] if source =~ preferred_source
|
27
27
|
end
|
28
28
|
end
|
@@ -41,10 +41,13 @@ module Phonetics
|
|
41
41
|
@transcriptions = JSON.parse(File.read(TranscriptionFile))
|
42
42
|
end
|
43
43
|
|
44
|
+
# rubocop:disable Security/Open
|
44
45
|
def download!
|
45
46
|
File.open(Transcriptions, 'w') { |f| f.write(URI.open(TranscriptionsURL).read) }
|
46
47
|
end
|
48
|
+
# rubocop:enable Security/Open
|
47
49
|
|
50
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
48
51
|
def trie(max_rarity = nil)
|
49
52
|
# Let's turn this:
|
50
53
|
#
|
@@ -114,9 +117,7 @@ module Phonetics
|
|
114
117
|
@tries[max_rarity] ||= begin
|
115
118
|
base_trie = {}
|
116
119
|
transcriptions.each do |key, entry|
|
117
|
-
if max_rarity
|
118
|
-
next if entry['rarity'].nil? || entry['rarity'] > max_rarity
|
119
|
-
end
|
120
|
+
next if max_rarity && (entry['rarity'].nil? || entry['rarity'] > max_rarity)
|
120
121
|
|
121
122
|
entry_data = {
|
122
123
|
word: key,
|
@@ -129,6 +130,7 @@ module Phonetics
|
|
129
130
|
base_trie.freeze
|
130
131
|
end
|
131
132
|
end
|
133
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
132
134
|
|
133
135
|
def walk(ipa)
|
134
136
|
ipa.each_char.reduce(trie) { |acc, char| acc[char] }
|
data/phonetics.gemspec
CHANGED
@@ -11,6 +11,8 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.homepage = 'https://github.com/JackDanger/phonetics'
|
12
12
|
spec.license = 'MIT'
|
13
13
|
|
14
|
+
spec.required_ruby_version = '>= 2.5'
|
15
|
+
|
14
16
|
spec.extensions = ['ext/c_levenshtein/extconf.rb']
|
15
17
|
|
16
18
|
# Specify which files should be added to the gem when it is released.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phonetics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jack Danger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -149,14 +149,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
149
149
|
requirements:
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: '
|
152
|
+
version: '2.5'
|
153
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
154
|
requirements:
|
155
155
|
- - ">="
|
156
156
|
- !ruby/object:Gem::Version
|
157
157
|
version: '0'
|
158
158
|
requirements: []
|
159
|
-
rubygems_version: 3.0.3
|
159
|
+
rubygems_version: 3.0.3.1
|
160
160
|
signing_key:
|
161
161
|
specification_version: 4
|
162
162
|
summary: tools for linguistic code using the International Phonetic Alphabet
|