soundcord 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/soundcord.rb +6 -1
- data/lib/soundcord/comparable.rb +9 -0
- data/lib/soundcord/integrations/array.rb +11 -1
- data/lib/soundcord/integrations/string.rb +12 -9
- data/lib/soundcord/phonetizable.rb +12 -0
- data/lib/soundcord/phrase.rb +39 -0
- data/lib/soundcord/regexable.rb +15 -15
- data/lib/soundcord/word.rb +15 -14
- data/soundcord.gemspec +1 -1
- data/test/languages/en/test_phrase.rb +33 -0
- data/test/languages/en/test_word.rb +59 -0
- data/test/languages/pt_br/test_phrase.rb +33 -0
- data/test/languages/pt_br/test_word.rb +46 -0
- data/test/test_array.rb +11 -0
- data/test/test_comparable.rb +15 -0
- data/test/test_performance.rb +1 -1
- data/test/test_string.rb +1 -0
- metadata +13 -7
- data/test/languages/en/test_soundcord.rb +0 -71
- data/test/languages/pt_br/test_soundcord.rb +0 -48
data/Rakefile
CHANGED
data/lib/soundcord.rb
CHANGED
@@ -6,10 +6,15 @@ require 'soundcord/integrations/string'
|
|
6
6
|
require 'soundcord/integrations/array'
|
7
7
|
|
8
8
|
require 'soundcord/word'
|
9
|
+
require 'soundcord/phrase'
|
9
10
|
|
10
11
|
module SoundCord
|
11
12
|
def self.phonetize text
|
12
|
-
|
13
|
+
if text.include? ' '
|
14
|
+
Phrase.new(text).to_sound
|
15
|
+
else
|
16
|
+
Word.new(text).to_sound
|
17
|
+
end
|
13
18
|
end
|
14
19
|
|
15
20
|
def self.compare term_1, term_2
|
@@ -2,7 +2,17 @@ class Array
|
|
2
2
|
# Search possible homphone matches within the array object for a given string word
|
3
3
|
# Params:
|
4
4
|
# +value+:: string to be phonetized and compared with the array items
|
5
|
-
def homophones
|
5
|
+
def homophones(value)
|
6
6
|
self.select { |i| i.homophone? value }
|
7
7
|
end
|
8
|
+
|
9
|
+
def to_sound
|
10
|
+
self.map do |item|
|
11
|
+
item.to_sound.phonetize
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def phonetize
|
16
|
+
self.to_sound
|
17
|
+
end
|
8
18
|
end
|
@@ -1,21 +1,24 @@
|
|
1
1
|
class String
|
2
|
-
# Returns the phonetic version of the
|
2
|
+
# Returns the phonetic version of the passed string
|
3
3
|
# Params:
|
4
|
-
# +
|
5
|
-
def phonetize
|
4
|
+
# +value+:: string to be phonetized
|
5
|
+
def self.phonetize value
|
6
|
+
value.to_sound
|
7
|
+
end
|
8
|
+
|
9
|
+
# Returns the phonetic version of the object string
|
10
|
+
def to_sound
|
6
11
|
SoundCord.phonetize self
|
7
12
|
end
|
8
13
|
|
9
|
-
# Returns the phonetic version of the
|
10
|
-
|
11
|
-
|
12
|
-
def self.phonetize value
|
13
|
-
value.phonetize
|
14
|
+
# Returns the phonetic version of the object string
|
15
|
+
def phonetize
|
16
|
+
self.to_sound
|
14
17
|
end
|
15
18
|
|
16
19
|
# Compares the passed value with the object value, both in their phonetic version
|
17
20
|
# Params:
|
18
|
-
# +
|
21
|
+
# +compared+:: the string the be compared with
|
19
22
|
def homophone? compared
|
20
23
|
SoundCord.homophone? self, compared
|
21
24
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'soundcord/regexable'
|
2
|
+
require 'soundcord/comparable'
|
3
|
+
|
4
|
+
class SoundCord::Phonetizable < Struct.new(:original, :homophone)
|
5
|
+
include SoundCord::Regexable
|
6
|
+
include SoundCord::Comparable
|
7
|
+
|
8
|
+
protected
|
9
|
+
def phonetize!
|
10
|
+
SoundCord.load_language unless SoundCord.language
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'soundcord/phonetizable'
|
2
|
+
require 'soundcord/word'
|
3
|
+
|
4
|
+
class SoundCord::Phrase < SoundCord::Phonetizable
|
5
|
+
|
6
|
+
def to_sound
|
7
|
+
self.homophone ||= self.phonetize!
|
8
|
+
end
|
9
|
+
|
10
|
+
protected
|
11
|
+
def phonetize!
|
12
|
+
super
|
13
|
+
|
14
|
+
self.homophone = phonetized_words.join(' ')
|
15
|
+
|
16
|
+
remove_extra_spaces!
|
17
|
+
trimmed!
|
18
|
+
|
19
|
+
self.homophone
|
20
|
+
end
|
21
|
+
|
22
|
+
def words
|
23
|
+
self.original.split ' '
|
24
|
+
end
|
25
|
+
|
26
|
+
def phonetized_words
|
27
|
+
self.words.map do |word|
|
28
|
+
SoundCord::Word.new(word).to_sound
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def remove_extra_spaces!
|
33
|
+
self.homophone.gsub! /\s{2,}/, ' '
|
34
|
+
end
|
35
|
+
|
36
|
+
def trimmed!
|
37
|
+
self.homophone.strip!
|
38
|
+
end
|
39
|
+
end
|
data/lib/soundcord/regexable.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
module Regexable
|
1
|
+
module SoundCord::Regexable
|
2
2
|
def mount_regexp sentence, options = { :terminations => false, :initiations => false }
|
3
|
-
regexp =
|
4
|
-
regexp +=
|
5
|
-
regexp +=
|
6
|
-
regexp += sentence.kind_of?(Array) ? sentence.join(
|
7
|
-
regexp +=
|
8
|
-
regexp +=
|
9
|
-
regexp +=
|
3
|
+
regexp = '/'
|
4
|
+
regexp += '^' if options[:initiations]
|
5
|
+
regexp += '('
|
6
|
+
regexp += sentence.kind_of?(Array) ? sentence.join('|') : sentence
|
7
|
+
regexp += ')'
|
8
|
+
regexp += '\\b' if options[:terminations]
|
9
|
+
regexp += '/'
|
10
10
|
eval(regexp)
|
11
11
|
end
|
12
12
|
|
13
13
|
def mount_follow_up_regexp prefix, sufix, options = {}
|
14
|
-
regexp = options[:not_eval] ?
|
14
|
+
regexp = options[:not_eval] ? '' : '/'
|
15
15
|
regexp += prefix
|
16
|
-
regexp +=
|
17
|
-
regexp +=
|
18
|
-
regexp += sufix.kind_of?(Array) ? sufix.join(
|
19
|
-
regexp +=
|
20
|
-
regexp +=
|
16
|
+
regexp += '(?='
|
17
|
+
regexp += '('
|
18
|
+
regexp += sufix.kind_of?(Array) ? sufix.join('|') : sufix
|
19
|
+
regexp += '))'
|
20
|
+
regexp += '/' unless options[:not_eval]
|
21
21
|
options[:not_eval] ? regexp : eval(regexp)
|
22
22
|
end
|
23
23
|
|
24
24
|
def mount_second_followed_by_regexp char, group
|
25
|
-
regexp =
|
25
|
+
regexp = '/' + not_first(char) + mount_follow_up_regexp(char, group, :not_eval => true) + '/'
|
26
26
|
eval regexp
|
27
27
|
end
|
28
28
|
|
data/lib/soundcord/word.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
|
-
|
1
|
+
require 'soundcord/phonetizable'
|
2
2
|
|
3
|
-
class SoundCord::Word <
|
4
|
-
include Regexable
|
3
|
+
class SoundCord::Word < SoundCord::Phonetizable
|
5
4
|
|
6
|
-
def
|
7
|
-
self.homophone
|
5
|
+
def to_sound
|
6
|
+
self.homophone ||= self.phonetize!
|
8
7
|
end
|
9
8
|
|
10
9
|
protected
|
11
|
-
def
|
12
|
-
|
10
|
+
def phonetize!
|
11
|
+
super
|
13
12
|
|
14
13
|
self.homophone = original.downcase
|
15
14
|
|
@@ -37,14 +36,14 @@ protected
|
|
37
36
|
def remove_duplicity!(options)
|
38
37
|
options[:duplicate_exceptions] = [] unless options[:duplicate_exceptions]
|
39
38
|
|
40
|
-
self.homophone = self.homophone.split(//).inject(
|
39
|
+
self.homophone = self.homophone.split(//).inject('') do |s, n|
|
41
40
|
last_s_char = s[s.length-1..s.length-1]
|
42
41
|
s + ((last_s_char === n and
|
43
42
|
!options[:duplicate_exceptions].include?(n)) ? '' : n )
|
44
43
|
end
|
45
44
|
end
|
46
45
|
|
47
|
-
def process_group!
|
46
|
+
def process_group!(group, options)
|
48
47
|
group.each do |key, values|
|
49
48
|
if values
|
50
49
|
simple_replace! key, values, options
|
@@ -54,7 +53,7 @@ protected
|
|
54
53
|
end
|
55
54
|
end
|
56
55
|
|
57
|
-
def process_follow_ups!
|
56
|
+
def process_follow_ups!(group, options = {})
|
58
57
|
group.each do |key, prefixes|
|
59
58
|
prefixes.each do |prefix, sufixes|
|
60
59
|
regexp = mount_follow_up_regexp prefix, sufixes
|
@@ -63,7 +62,7 @@ protected
|
|
63
62
|
end
|
64
63
|
end
|
65
64
|
|
66
|
-
def process_second_followed!
|
65
|
+
def process_second_followed!(group, options = {})
|
67
66
|
group.each do |key, prefixes|
|
68
67
|
prefixes.each do |prefix, sufixes|
|
69
68
|
regexp = mount_second_followed_by_regexp prefix, sufixes
|
@@ -74,7 +73,7 @@ protected
|
|
74
73
|
end
|
75
74
|
end
|
76
75
|
|
77
|
-
def process_vowels_pronunciation_insignificance!
|
76
|
+
def process_vowels_pronunciation_insignificance!(group, options = {})
|
78
77
|
group.each do |key, value|
|
79
78
|
regexp = mount_vowels_pronunciation_insignificance_regexp key
|
80
79
|
self.homophone =~ regexp
|
@@ -82,15 +81,17 @@ protected
|
|
82
81
|
end
|
83
82
|
end
|
84
83
|
|
85
|
-
def process_followed_by_consonant_regexp!
|
84
|
+
def process_followed_by_consonant_regexp!(group)
|
86
85
|
group.each do |key, value|
|
87
86
|
regexp = mount_followed_by_consonant_regexp value
|
88
87
|
self.homophone.gsub! regexp, ''
|
89
88
|
end
|
90
89
|
end
|
91
90
|
|
92
|
-
def simple_replace!
|
91
|
+
def simple_replace!(key, values, options)
|
93
92
|
regexp = mount_regexp values, options
|
93
|
+
# p self.homophone
|
94
|
+
# p regexp
|
94
95
|
self.homophone.gsub! regexp, key.to_s
|
95
96
|
end
|
96
97
|
end
|
data/soundcord.gemspec
CHANGED
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.author = 'Lukas Alexandre'
|
4
4
|
s.email = 'lukasalexandre@me.com'
|
5
5
|
s.homepage = 'http://lukelex.github.com/soundcord'
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.4.0"
|
7
7
|
s.date = Date.today
|
8
8
|
s.summary = %q{A phonetic algorithm for indexing of words by their pronunciation.}
|
9
9
|
s.description = %q{"Make comparisons of phonetically similar terms easier."}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'soundcord'
|
5
|
+
|
6
|
+
module SoundCord
|
7
|
+
class EnPhraseTest < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
SoundCord.load_language 'en'
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_short_phrase
|
13
|
+
short_phrase = 'Imagination is more important than knowledge.'
|
14
|
+
expected_phrase = 'MJNXN S MR MPRTNT 0N NLJ.'
|
15
|
+
|
16
|
+
assert_equal expected_phrase, short_phrase.phonetize
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_medium_phrase
|
20
|
+
medium_phrase = 'Too many of us look upon Americans as dollar chasers. This is a cruel libel, even if it is reiterated thoughtlessly by the Americans themselves.'
|
21
|
+
expected_phrase = 'T MN F S LK PN MRKNS S TLR XSRS. 0S S KRL LBL, FN F T S RTRT 0GHTLSL B 0 MRKNS 0MSLFS.'
|
22
|
+
|
23
|
+
assert_equal expected_phrase, medium_phrase.phonetize
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_large_phrase
|
27
|
+
large_phrase = 'He who joyfully marches to music rank and file, has already earned my contempt. He has been given a large brain by mistake, since for him the spinal cord would surely suffice. This disgrace to civilization should be done away with at once. Heroism at command, how violently I hate all this, how despicable and ignoble war is; I would rather be torn to shreds than be a part of so base an action. It is my conviction that killing under the cloak of war is nothing but an act of murder.'
|
28
|
+
expected_phrase = 'H JFL MRXS T MSK RNK NT FL, HS LRT RNT M KNTMPT. H HS BN JFN LRJ BRN B MSTK, SNS FR HM 0 SPNL KRT LT SRL SFS. 0S TSGRS T SFLSXN XLT B TN 0 T NS. HRSM T KMNT, H FLNTL HT L 0S, H TSPKBL NT GNBL R S; LT R0R B TRN T XRTS 0N B PRT F S BS N KXN. T S M KNFKXN 0T KLNG NTR 0 KLK F R S N0NG BT N KT F MRTR.'
|
29
|
+
|
30
|
+
assert_equal expected_phrase, large_phrase.phonetize
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'soundcord'
|
5
|
+
|
6
|
+
module SoundCord
|
7
|
+
class EnWordTest < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
SoundCord.load_language 'en'
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_initiations_en
|
13
|
+
assert_equal 'RL', 'aerial'.phonetize
|
14
|
+
assert_equal 'RP', 'wrap'.phonetize
|
15
|
+
assert_equal 'SN', 'xeno'.phonetize
|
16
|
+
assert_equal 'TFR', 'whatever'.phonetize
|
17
|
+
assert_equal 'NM', 'gnome'.phonetize
|
18
|
+
assert_equal 'NF', 'knife'.phonetize
|
19
|
+
assert_equal 'NMNK', 'pneumonic'.phonetize
|
20
|
+
end
|
21
|
+
def test_unusual_combinations_en
|
22
|
+
assert_equal '0TR', 'theater'.phonetize
|
23
|
+
assert_equal 'TX', 'touch'.phonetize
|
24
|
+
assert_equal 'XL', 'shell'.phonetize
|
25
|
+
assert_equal 'KRX', 'crutch'.phonetize
|
26
|
+
assert_equal 'FS', 'phase'.phonetize
|
27
|
+
assert_equal 'BKR', 'beggar'.phonetize
|
28
|
+
end
|
29
|
+
def test_terminations_en
|
30
|
+
assert_equal 'LM', 'lmb'.phonetize
|
31
|
+
end
|
32
|
+
def test_middle_en
|
33
|
+
# couldn't remember a better word with SCH in the middle
|
34
|
+
assert_equal 'PRSK', 'porsche'.phonetize
|
35
|
+
end
|
36
|
+
def test_duplicate_exceptions_en
|
37
|
+
assert_equal 'GKLS', 'goggles'.phonetize
|
38
|
+
end
|
39
|
+
def test_special_chars_en
|
40
|
+
assert_equal true, 'Qeyla'.homophone?('keyla')
|
41
|
+
assert_equal true, 'Courtiney'.homophone?('kourtiney')
|
42
|
+
assert_equal true, 'Quartz'.homophone?('kuarts')
|
43
|
+
assert_equal true, 'falue'.homophone?('value')
|
44
|
+
assert_equal true, 'data'.homophone?('tada')
|
45
|
+
end
|
46
|
+
def test_second_follwed_by_en
|
47
|
+
assert_equal 'JM', 'ogema'.phonetize
|
48
|
+
end
|
49
|
+
def test_vowels_pronunciation_insignificance_en
|
50
|
+
assert_equal 'MSX', 'messiah'.phonetize
|
51
|
+
assert_equal 'ML', 'mehlia'.phonetize
|
52
|
+
end
|
53
|
+
def test_find_in_collection_en
|
54
|
+
list = %w( mail male main Maine mane )
|
55
|
+
expected = %w( main Maine mane )
|
56
|
+
assert_equal expected, list.homophones('main')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'soundcord'
|
5
|
+
|
6
|
+
module SoundCord
|
7
|
+
class PtBrPhraseTest < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
SoundCord.load_language 'pt-BR'
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_short_phrase
|
13
|
+
short_phrase = 'Ser feliz sem motivo é a mais autêntica forma de felicidade.'
|
14
|
+
expected_phrase = 'S FL S MTV M TMTK FM D FLSD.'
|
15
|
+
|
16
|
+
assert_equal expected_phrase, short_phrase.phonetize
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_medium_phrase
|
20
|
+
medium_phrase = 'O amor é grande e cabe nesta janela sobre o mar. O mar é grande e cabe na cama e no colchão de amar. O amor é grande e cabe no breve espaço de beijar.'
|
21
|
+
expected_phrase = 'M GMD KB MT JML SB M. M GMD KB M KM M KLS D M. M GMD KB M BV SPS D BJ.'
|
22
|
+
|
23
|
+
assert_equal expected_phrase, medium_phrase.phonetize
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_large_phrase
|
27
|
+
large_phrase = 'A cada dia que vivo, mais me convenço de que o desperdício da vida está no amor que não damos, nas forças que não usamos, na prudência egoísta que nada arrisca e que, esquivando-nos do sofrimento, perdemos também a felicidade.'
|
28
|
+
expected_phrase = 'KD D K V, M M KMVMS D K DSPRDíS D VD T M M K M DM, M FS K M SM, M PDMS GíT K MD RSK K, SKVMD-M D SFRMT, PRDM TMB FLSD.'
|
29
|
+
|
30
|
+
assert_equal expected_phrase, large_phrase.phonetize
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'soundcord'
|
5
|
+
|
6
|
+
module SoundCord
|
7
|
+
class PtBrWordTest < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
SoundCord.load_language 'pt-BR'
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_simple_words_pt_br
|
13
|
+
assert_equal 'J', 'João'.phonetize
|
14
|
+
assert_equal 'MR', 'Maria'.phonetize
|
15
|
+
assert_equal 'LM', 'Helena'.phonetize
|
16
|
+
assert_equal 'VLM', 'Valmir'.phonetize
|
17
|
+
assert_equal 'VLM', 'Walmir'.phonetize
|
18
|
+
end
|
19
|
+
def test_simple_comparisons_pt_br
|
20
|
+
assert_equal true, 'Joao'.homophone?('João')
|
21
|
+
assert_equal true, 'Helena'.homophone?('Elena')
|
22
|
+
assert_equal true, 'Walmir'.homophone?('Valmir')
|
23
|
+
assert_equal true, 'Marria'.homophone?('Maria')
|
24
|
+
assert_equal true, 'Wagner'.homophone?('Vagner')
|
25
|
+
assert_equal true, 'Mirela'.homophone?('Mirella')
|
26
|
+
assert_equal true, 'Artur'.homophone?('Arthur')
|
27
|
+
assert_equal true, 'Diego'.homophone?('Dyego')
|
28
|
+
assert_equal true, 'Felipe'.homophone?('Phelipe')
|
29
|
+
assert_equal true, 'Filipe'.homophone?('Felipe')
|
30
|
+
assert_equal true, 'Phelipe'.homophone?('Filipe')
|
31
|
+
assert_equal true, 'Philippe'.homophone?('Felipe')
|
32
|
+
end
|
33
|
+
def test_special_chars_pt_br
|
34
|
+
assert_equal true, 'Luçia'.homophone?('lucia')
|
35
|
+
assert_equal true, 'Lúcio'.homophone?('lucio')
|
36
|
+
end
|
37
|
+
def test_find_in_collection_pt_br
|
38
|
+
list = %w( saola paulo saulo ricardo sallo )
|
39
|
+
expected = %w( saola saulo sallo )
|
40
|
+
assert_equal expected, list.homophones('saulo')
|
41
|
+
list = %w( leonardo lucene rodrigo luciana lussene )
|
42
|
+
expected = %w( lucene luciana lussene )
|
43
|
+
assert_equal expected, list.homophones('lucene')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/test/test_array.rb
CHANGED
@@ -6,5 +6,16 @@ require 'soundcord/integrations/array'
|
|
6
6
|
class SoundCordTest < Test::Unit::TestCase
|
7
7
|
def test_homophones_method_existance
|
8
8
|
assert_equal Array.new.respond_to?(:homophones), true
|
9
|
+
assert_equal Array.new.respond_to?(:phonetize), true
|
10
|
+
assert_equal Array.new.respond_to?(:to_sound), true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_phonetizing_the_array
|
14
|
+
SoundCord.load_language 'en'
|
15
|
+
|
16
|
+
result = %w(Lukas Marcy Richard John).to_sound
|
17
|
+
expected = %w(LKS MRS RXRT JN)
|
18
|
+
|
19
|
+
assert_equal expected, result
|
9
20
|
end
|
10
21
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'soundcord'
|
5
|
+
|
6
|
+
module SoundCord
|
7
|
+
class ComparableTest < Test::Unit::TestCase
|
8
|
+
def test_comparing_equals
|
9
|
+
assert_equal Word.new('lukas') == Word.new('lucas'), true
|
10
|
+
end
|
11
|
+
def test_comparing_differents
|
12
|
+
assert_equal Word.new('lukas') != Word.new('Maria'), true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/test/test_performance.rb
CHANGED
data/test/test_string.rb
CHANGED
@@ -6,6 +6,7 @@ require 'soundcord/integrations/string'
|
|
6
6
|
class SoundCordTest < Test::Unit::TestCase
|
7
7
|
def test_phonetize_method_existance_in_instance
|
8
8
|
assert_equal String.new.respond_to?(:phonetize), true
|
9
|
+
assert_equal String.new.respond_to?(:to_sound), true
|
9
10
|
end
|
10
11
|
def test_phonetize_method_existance_in_class
|
11
12
|
assert_equal String.respond_to?(:phonetize), true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soundcord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,23 +9,29 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-06 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description: "
|
14
|
+
description: ! '"Make comparisons of phonetically similar terms easier."'
|
15
15
|
email: lukasalexandre@me.com
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- lib/soundcord/comparable.rb
|
20
21
|
- lib/soundcord/config.rb
|
21
22
|
- lib/soundcord/integrations/array.rb
|
22
23
|
- lib/soundcord/integrations/string.rb
|
24
|
+
- lib/soundcord/phonetizable.rb
|
25
|
+
- lib/soundcord/phrase.rb
|
23
26
|
- lib/soundcord/regexable.rb
|
24
27
|
- lib/soundcord/word.rb
|
25
28
|
- lib/soundcord.rb
|
26
|
-
- test/languages/en/
|
27
|
-
- test/languages/
|
29
|
+
- test/languages/en/test_phrase.rb
|
30
|
+
- test/languages/en/test_word.rb
|
31
|
+
- test/languages/pt_br/test_phrase.rb
|
32
|
+
- test/languages/pt_br/test_word.rb
|
28
33
|
- test/test_array.rb
|
34
|
+
- test/test_comparable.rb
|
29
35
|
- test/test_config.rb
|
30
36
|
- test/test_performance.rb
|
31
37
|
- test/test_string.rb
|
@@ -40,13 +46,13 @@ require_paths:
|
|
40
46
|
required_ruby_version: !ruby/object:Gem::Requirement
|
41
47
|
none: false
|
42
48
|
requirements:
|
43
|
-
- -
|
49
|
+
- - ! '>='
|
44
50
|
- !ruby/object:Gem::Version
|
45
51
|
version: '0'
|
46
52
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
53
|
none: false
|
48
54
|
requirements:
|
49
|
-
- -
|
55
|
+
- - ! '>='
|
50
56
|
- !ruby/object:Gem::Version
|
51
57
|
version: '0'
|
52
58
|
requirements: []
|
@@ -1,71 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'soundcord'
|
5
|
-
|
6
|
-
class SoundCordTest < Test::Unit::TestCase
|
7
|
-
def test_initiations_en
|
8
|
-
SoundCord.load_language 'en'
|
9
|
-
|
10
|
-
assert_equal "RL", "aerial".phonetize
|
11
|
-
assert_equal "RP", "wrap".phonetize
|
12
|
-
assert_equal "SN", "xeno".phonetize
|
13
|
-
assert_equal "TFR", "whatever".phonetize
|
14
|
-
assert_equal "NM", "gnome".phonetize
|
15
|
-
assert_equal "NF", "knife".phonetize
|
16
|
-
assert_equal "NMNK", "pneumonic".phonetize
|
17
|
-
end
|
18
|
-
def test_unusual_combinations_en
|
19
|
-
SoundCord.load_language 'en'
|
20
|
-
|
21
|
-
assert_equal "0TR", "theater".phonetize
|
22
|
-
assert_equal "TX", "touch".phonetize
|
23
|
-
assert_equal "XL", "shell".phonetize
|
24
|
-
assert_equal "KRX", "crutch".phonetize
|
25
|
-
assert_equal "FS", "phase".phonetize
|
26
|
-
assert_equal "BKR", "beggar".phonetize
|
27
|
-
end
|
28
|
-
def test_terminations_en
|
29
|
-
SoundCord.load_language 'en'
|
30
|
-
|
31
|
-
assert_equal "LM", "lmb".phonetize
|
32
|
-
end
|
33
|
-
def test_middle_en
|
34
|
-
SoundCord.load_language 'en'
|
35
|
-
|
36
|
-
# couldn't remember a better word with SCH in the middle
|
37
|
-
assert_equal "PRSK", "porsche".phonetize
|
38
|
-
end
|
39
|
-
def test_duplicate_exceptions_en
|
40
|
-
SoundCord.load_language 'en'
|
41
|
-
|
42
|
-
assert_equal "GKLS", "goggles".phonetize
|
43
|
-
end
|
44
|
-
def test_special_chars_en
|
45
|
-
SoundCord.load_language 'en'
|
46
|
-
|
47
|
-
assert_equal true, "Qeyla".homophone?("keyla")
|
48
|
-
assert_equal true, "Courtiney".homophone?("kourtiney")
|
49
|
-
assert_equal true, "Quartz".homophone?("kuarts")
|
50
|
-
assert_equal true, "falue".homophone?("value")
|
51
|
-
assert_equal true, "data".homophone?("tada")
|
52
|
-
end
|
53
|
-
def test_second_follwed_by_en
|
54
|
-
SoundCord.load_language 'en'
|
55
|
-
|
56
|
-
assert_equal "JM", "ogema".phonetize
|
57
|
-
end
|
58
|
-
def test_vowels_pronunciation_insignificance_en
|
59
|
-
SoundCord.load_language 'en'
|
60
|
-
|
61
|
-
assert_equal "MSX", "messiah".phonetize
|
62
|
-
assert_equal "ML", "mehlia".phonetize
|
63
|
-
end
|
64
|
-
def test_find_in_collection_en
|
65
|
-
SoundCord.load_language 'en'
|
66
|
-
|
67
|
-
list = %w( mail male main Maine mane )
|
68
|
-
expected = %w( main Maine mane )
|
69
|
-
assert_equal expected, list.homophones("main")
|
70
|
-
end
|
71
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'soundcord'
|
5
|
-
|
6
|
-
class SoundCordTest < Test::Unit::TestCase
|
7
|
-
def test_simple_words_pt_br
|
8
|
-
SoundCord.load_language 'pt-BR'
|
9
|
-
|
10
|
-
assert_equal "J", "João".phonetize
|
11
|
-
assert_equal "MR", "Maria".phonetize
|
12
|
-
assert_equal "LM", "Helena".phonetize
|
13
|
-
assert_equal "VLM", "Valmir".phonetize
|
14
|
-
assert_equal "VLM", "Walmir".phonetize
|
15
|
-
end
|
16
|
-
def test_simple_comparisons_pt_br
|
17
|
-
SoundCord.load_language 'pt-BR'
|
18
|
-
|
19
|
-
assert_equal true, "Joao".homophone?("João")
|
20
|
-
assert_equal true, "Helena".homophone?("Elena")
|
21
|
-
assert_equal true, "Walmir".homophone?("Valmir")
|
22
|
-
assert_equal true, "Marria".homophone?("Maria")
|
23
|
-
assert_equal true, "Wagner".homophone?("Vagner")
|
24
|
-
assert_equal true, "Mirela".homophone?("Mirella")
|
25
|
-
assert_equal true, "Artur".homophone?("Arthur")
|
26
|
-
assert_equal true, "Diego".homophone?("Dyego")
|
27
|
-
assert_equal true, "Felipe".homophone?("Phelipe")
|
28
|
-
assert_equal true, "Filipe".homophone?("Felipe")
|
29
|
-
assert_equal true, "Phelipe".homophone?("Filipe")
|
30
|
-
assert_equal true, "Philippe".homophone?("Felipe")
|
31
|
-
end
|
32
|
-
def test_special_chars_pt_br
|
33
|
-
SoundCord.load_language 'pt-BR'
|
34
|
-
|
35
|
-
assert_equal true, "Luçia".homophone?("lucia")
|
36
|
-
assert_equal true, "Lúcio".homophone?("lucio")
|
37
|
-
end
|
38
|
-
def test_find_in_collection_pt_br
|
39
|
-
SoundCord.load_language 'pt-BR'
|
40
|
-
|
41
|
-
list = %w( saola paulo saulo ricardo sallo )
|
42
|
-
expected = %w( saola saulo sallo )
|
43
|
-
assert_equal expected, list.homophones("saulo")
|
44
|
-
list = %w( leonardo lucene rodrigo luciana lussene )
|
45
|
-
expected = %w( lucene luciana lussene )
|
46
|
-
assert_equal expected, list.homophones("lucene")
|
47
|
-
end
|
48
|
-
end
|