fonetica 0.4.0 → 1.0.0

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.
data/CHANGELOG CHANGED
@@ -1,3 +1,21 @@
1
+ 1.0.0 [Sun Jun 19 2011]
2
+
3
+ * Use replacements table proposed by Marcos Rodrigues Caso (see:
4
+ http://caso.somee.com/siteTCC/docs/TCCMarcosRC.pdf)
5
+
6
+ This change will catch current cases and more like 'willian' and 'uillian'
7
+
8
+ Note that this change is backwards-incompatible. But you can update your
9
+ database using a rake task like that:
10
+
11
+ task :update_fonetica => :environment do
12
+ Person.transaction do
13
+ Person.find_each do |person|
14
+ person.update_attribute(:fonetica, person.name.foneticalize)
15
+ end
16
+ end
17
+ end
18
+
1
19
  0.4.0 [Sat Feb 12 2010]
2
20
 
3
21
  * Compatibility with Ruby 1.9
@@ -11,10 +11,10 @@ Then Google suggested me to read the "BuscaBR algorithm":http://www.unibratec.co
11
11
  h2. Usage
12
12
 
13
13
  <pre>
14
- require 'fonetica'
14
+ require 'fonetica'
15
15
 
16
- 'Wagner Batista'.foneticalize #=> "VM BT"
17
- 'Vagner Baptista'.foneticalize #=> "VM BT"
16
+ 'wagner batista'.foneticalize #=> "VM BT"
17
+ 'vagner baptista'.foneticalize #=> "VM BT"
18
18
  </pre>
19
19
 
20
20
  h3. Using with ActiveRecord
@@ -22,23 +22,23 @@ h3. Using with ActiveRecord
22
22
  You can use the fonetica to search on ActiveRecord like this:
23
23
 
24
24
  <pre>
25
- class Person < ActiveRecord::Base
26
- scope :search, lambda { |name| where("#{quoted_table_name}.fonetica LIKE ?", "#{name.foneticalize}%") }
25
+ class Person < ActiveRecord::Base
26
+ scope :search, lambda { |name| where("#{quoted_table_name}.fonetica LIKE ?", "#{name.foneticalize}%") }
27
27
 
28
- before_save :foneticalize
28
+ before_save :foneticalize
29
29
 
30
- protected
30
+ protected
31
31
 
32
- def foneticalize
33
- self.fonetica = name.foneticalize
34
- end
32
+ def foneticalize
33
+ self.fonetica = name.foneticalize
35
34
  end
35
+ end
36
36
  </pre>
37
37
 
38
38
  If you want to match any part, you should change scope to:
39
39
 
40
40
  <pre>
41
- scope :search, lambda { |name| where("#{quoted_table_name}.fonetica LIKE ?", "%#{name.foneticalize}%") }
41
+ scope :search, lambda { |name| where("#{quoted_table_name}.fonetica LIKE ?", "%#{name.foneticalize}%") }
42
42
  </pre>
43
43
 
44
44
  Remember to add a index on fonetica column.
@@ -52,10 +52,10 @@ Please also keep your commits *atomic* so that they are more likely to apply cle
52
52
  h2. Development environment
53
53
 
54
54
  <pre>
55
- $ git clone http://github.com/sobrinho/fonetica
56
- $ cd fonetica
57
- $ bundle install
58
- $ rake test
55
+ $ git clone http://github.com/sobrinho/fonetica
56
+ $ cd fonetica
57
+ $ bundle install
58
+ $ rake test
59
59
  </pre>
60
60
 
61
61
  h2. Project info
data/Rakefile CHANGED
@@ -1,8 +1,6 @@
1
- require 'bundler'
1
+ require 'bundler/gem_tasks'
2
2
  require 'rake/testtask'
3
3
 
4
- Bundler::GemHelper.install_tasks
5
-
6
4
  Rake::TestTask.new(:test) do |t|
7
5
  t.libs << 'test'
8
6
  t.pattern = 'test/**/*_test.rb'
@@ -4,7 +4,7 @@ require "fonetica/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "fonetica"
7
- s.version = Fonetica::Version::STRING
7
+ s.version = Fonetica::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Gabriel Sobrinho"]
10
10
  s.email = ["gabriel.sobrinho@gmail.com"]
@@ -11,28 +11,22 @@ class Fonetica
11
11
  class_attribute :replacements
12
12
 
13
13
  self.replacements = [
14
- ['Y', 'I'],
15
- [/BR|BL/, 'B'],
14
+ [/BL|BR/, 'B'],
16
15
  ['PH', 'F'],
17
- [/MG|NG|RG/, 'G'],
18
- [/GE|GI|RJ|MJ|NJ/, 'J'],
19
- [/GR|GL/, 'G'],
20
- [/CE|CI|CH/, 'S'],
21
- [/PT|CT/, 'T'],
22
- ['CS', 'S'],
23
- [/Q|C|CA|CO|CU|CK/, 'K'],
24
- ['LH', 'L'],
25
- ['RM', 'SM'],
16
+ [/GL|GR|MG|NG|RG/, 'G'],
17
+ ['Y', 'I'],
18
+ [/GE|GI|RJ|MJ/, 'J'],
19
+ [/CA|CO|CU|CK|Q/, 'K'],
26
20
  ['N', 'M'],
27
- [/MD|GM|AO\b/, 'M'],
28
- ['NH', 'N'],
21
+ [/AO|AUM|GM|MD|OM|ON/, 'M'],
29
22
  ['PR', 'P'],
30
- [/X|TS|C|Z|RS/, 'S'],
31
- [/TR|TL/, 'T'],
32
- [/LT|RT|ST/, 'T'],
33
- ['W', 'V'],
34
- [/[SZRMNL]\b/, ''],
35
23
  ['L', 'R'],
24
+ [/CE|CI|CH|CS|RS|TS|X|Z/, 'S'],
25
+ [/TR|TL/, 'T'],
26
+ [/CT|RT|ST|PT/, 'T'],
27
+ [/\b[UW]/, 'V'],
28
+ ['RM', 'SM'],
29
+ [/[MRS]\b/, ''],
36
30
  [/[AEIOUH]/, '']
37
31
  ]
38
32
 
@@ -1,9 +1,3 @@
1
1
  class Fonetica
2
- module Version #:nodoc:
3
- MAJOR = 0
4
- MINOR = 4
5
- TINY = 0
6
-
7
- STRING = [MAJOR, MINOR, TINY].join('.')
8
- end
2
+ VERSION = '1.0.0'
9
3
  end
@@ -0,0 +1,158 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ class FoneticaTest < Test::Unit::TestCase
5
+ def test_broco_and_bloco
6
+ assert_fonetica 'broco', 'bloco'
7
+ end
8
+
9
+ def test_casa_and_kasa
10
+ assert_fonetica 'casa', 'kasa'
11
+ end
12
+
13
+ def test_cela_and_sela
14
+ assert_fonetica 'sela', 'cela'
15
+ end
16
+
17
+ def test_circo_and_sirco
18
+ assert_fonetica 'circo', 'sirco'
19
+ end
20
+
21
+ def test_coroar_and_koroar
22
+ assert_fonetica 'coroar', 'koroar'
23
+ end
24
+
25
+ def test_cuba_and_kuba
26
+ assert_fonetica 'cuba', 'kuba'
27
+ end
28
+
29
+ def test_roca_and_rosa
30
+ assert_fonetica 'roça', 'rosa'
31
+ end
32
+
33
+ def test_ameixa_and_ameicha
34
+ assert_fonetica 'ameixa', 'ameicha'
35
+ end
36
+
37
+ def test_toracs_and_torax
38
+ assert_fonetica 'toracs', 'torax'
39
+ end
40
+
41
+ def test_compactar_and_compatar
42
+ assert_fonetica 'compactar', 'compatar'
43
+ end
44
+
45
+ def test_fleuma_and_fleugma
46
+ assert_fonetica 'fleuma', 'fleugma'
47
+ end
48
+
49
+ def test_hieroglifo_and_hierogrifo
50
+ assert_fonetica 'hieroglifo', 'hierogrifo'
51
+ end
52
+
53
+ def test_negro_and_nego
54
+ assert_fonetica 'negro', 'nego'
55
+ end
56
+
57
+ def test_luminar_and_ruminar
58
+ assert_fonetica 'luminar', 'ruminar'
59
+ end
60
+
61
+ def test_mudez_and_nudez
62
+ assert_fonetica 'mudez', 'nudez'
63
+ end
64
+
65
+ def test_comendo_and_comeno
66
+ assert_fonetica 'comendo', 'comeno'
67
+ end
68
+
69
+ def test_bunginganga_and_bugiganga
70
+ assert_fonetica 'bunginganga', 'bugiganga'
71
+ end
72
+
73
+ def test_philipe_and_felipe
74
+ assert_fonetica 'philipe', 'felipe'
75
+ end
76
+
77
+ def test_estupro_and_estrupo
78
+ assert_fonetica 'estupro', 'estrupo'
79
+ end
80
+
81
+ def test_queijo_and_keijo
82
+ assert_fonetica 'queijo', 'keijo'
83
+ end
84
+
85
+ def test_lagarto_and_largarto
86
+ assert_fonetica 'lagarto', 'largarto'
87
+ end
88
+
89
+ def test_perspectiva_and_pespectiva
90
+ assert_fonetica 'perspectiva', 'pespectiva'
91
+ end
92
+
93
+ def test_lagartixa_and_largatixa
94
+ assert_fonetica 'lagartixa', 'largatixa'
95
+ end
96
+
97
+ def test_mesmo_and_mermo
98
+ assert_fonetica 'mesmo', 'mermo'
99
+ end
100
+
101
+ def test_virgem_and_virge
102
+ assert_fonetica 'virgem', 'virge'
103
+ end
104
+
105
+ def test_supersticao_and_superticao
106
+ assert_fonetica 'supersticao', 'superticao'
107
+ end
108
+
109
+ def test_estupro_and_estrupo
110
+ assert_fonetica 'estupro', 'estrupo'
111
+ end
112
+
113
+ def test_contrato_and_contlato
114
+ assert_fonetica 'contrato', 'contlato'
115
+ end
116
+
117
+ def test_kubitscheck_and_kubixeque
118
+ assert_fonetica 'kubitscheck', 'kubixeque'
119
+ end
120
+
121
+ def test_walter_and_valter
122
+ assert_fonetica 'walter', 'valter'
123
+ end
124
+
125
+ def test_exceder_and_esceder
126
+ assert_fonetica 'exceder', 'esceder'
127
+ end
128
+
129
+ def test_yara_and_iara
130
+ assert_fonetica 'yara', 'iara'
131
+ end
132
+
133
+ def test_casa_and_caza
134
+ assert_fonetica 'casa', 'caza'
135
+ end
136
+
137
+ def test_wilson_and_uilson
138
+ assert_fonetica 'wilson', 'uilson'
139
+ end
140
+
141
+ def test_optico_and_otico
142
+ assert_fonetica 'óptico', 'ótico'
143
+ end
144
+
145
+ def test_orgaozinho
146
+ assert_fonetica 'órgãozinho', 'órgaozinho'
147
+ end
148
+
149
+ def test_batista_and_baptista
150
+ assert_fonetica 'batista', 'baptista'
151
+ end
152
+
153
+ protected
154
+
155
+ def assert_fonetica(first, second)
156
+ assert_equal first.foneticalize, second.foneticalize, "#{first.inspect} and #{second.inspect} do not match"
157
+ end
158
+ end
@@ -2,4 +2,3 @@ require 'rubygems'
2
2
  require 'bundler/setup'
3
3
  require 'fonetica'
4
4
  require 'test/unit'
5
- require 'active_support/test_case'
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fonetica
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- - 0
10
- version: 0.4.0
5
+ version: 1.0.0
11
6
  platform: ruby
12
7
  authors:
13
8
  - Gabriel Sobrinho
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-02-12 00:00:00 -02:00
13
+ date: 2011-06-19 00:00:00 -03:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,11 +21,6 @@ dependencies:
26
21
  requirements:
27
22
  - - ">="
28
23
  - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 3
32
- - 0
33
- - 0
34
24
  version: 3.0.0
35
25
  type: :runtime
36
26
  version_requirements: *id001
@@ -42,11 +32,6 @@ dependencies:
42
32
  requirements:
43
33
  - - ">="
44
34
  - !ruby/object:Gem::Version
45
- hash: 13
46
- segments:
47
- - 0
48
- - 4
49
- - 1
50
35
  version: 0.4.1
51
36
  type: :runtime
52
37
  version_requirements: *id002
@@ -70,7 +55,7 @@ files:
70
55
  - lib/fonetica.rb
71
56
  - lib/fonetica/core_ext/string.rb
72
57
  - lib/fonetica/version.rb
73
- - test/string_test.rb
58
+ - test/fonetica_test.rb
74
59
  - test/test_helper.rb
75
60
  has_rdoc: true
76
61
  homepage: http://github.com/sobrinho/fonetica
@@ -86,18 +71,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
71
  requirements:
87
72
  - - ">="
88
73
  - !ruby/object:Gem::Version
89
- hash: 3
90
- segments:
91
- - 0
92
74
  version: "0"
93
75
  required_rubygems_version: !ruby/object:Gem::Requirement
94
76
  none: false
95
77
  requirements:
96
78
  - - ">="
97
79
  - !ruby/object:Gem::Version
98
- hash: 3
99
- segments:
100
- - 0
101
80
  version: "0"
102
81
  requirements: []
103
82
 
@@ -107,5 +86,5 @@ signing_key:
107
86
  specification_version: 3
108
87
  summary: BuscaBR algorithm which allow the comparison of words based on their phonetic likeness
109
88
  test_files:
110
- - test/string_test.rb
89
+ - test/fonetica_test.rb
111
90
  - test/test_helper.rb
@@ -1,188 +0,0 @@
1
- # encoding: utf-8
2
- require 'test_helper'
3
-
4
- class StringTest < ActiveSupport::TestCase
5
- test 'broco and bloco should fonetica to BK' do
6
- assert_equal 'BK', 'broco'.foneticalize
7
- assert_equal 'BK', 'bloco'.foneticalize
8
- end
9
-
10
- test 'casa and kasa should fonetica to KS' do
11
- assert_equal 'KS', 'casa'.foneticalize
12
- assert_equal 'KS', 'kasa'.foneticalize
13
- end
14
-
15
- test 'coroar and koroar should fonetica to KR' do
16
- assert_equal 'KR', 'coroar'.foneticalize
17
- assert_equal 'KR', 'koroar'.foneticalize
18
- end
19
-
20
- test 'cuba and kuba should fonetica to KB' do
21
- assert_equal 'KB', 'cuba'.foneticalize
22
- assert_equal 'KB', 'kuba'.foneticalize
23
- end
24
-
25
- test 'cela and sela should fonetica to SR' do
26
- assert_equal 'SR', 'cela'.foneticalize
27
- assert_equal 'SR', 'sela'.foneticalize
28
- end
29
-
30
- test 'circo and sirco should fonetica to SRK' do
31
- assert_equal 'SRK', 'circo'.foneticalize
32
- assert_equal 'SRK', 'sirco'.foneticalize
33
- end
34
-
35
- test 'roça and rosa should fonetica to RS' do
36
- assert_equal 'RS', 'roça'.foneticalize
37
- assert_equal 'RS', 'rosa'.foneticalize
38
- end
39
-
40
- test 'ameixa and ameicha should fonetica to MS' do
41
- assert_equal 'MS', 'ameixa'.foneticalize
42
- assert_equal 'MS', 'ameicha'.foneticalize
43
- end
44
-
45
- test 'toracs and torax should fonetica to TR' do
46
- assert_equal 'TR', 'toracs'.foneticalize
47
- assert_equal 'TR', 'torax'.foneticalize
48
- end
49
-
50
- test 'compactar and compatar should fonetica to KMPT' do
51
- assert_equal 'KMPT', 'compactar'.foneticalize
52
- assert_equal 'KMPT', 'compatar'.foneticalize
53
- end
54
-
55
- test 'batista and baptista should fonetica to BT' do
56
- assert_equal 'BT', 'batista'.foneticalize
57
- assert_equal 'BT', 'baptista'.foneticalize
58
- end
59
-
60
- test 'gana should fonetica to KMPT' do
61
- assert_equal 'GM', 'gana'.foneticalize
62
- end
63
-
64
- test 'gostar should fonetica to GT' do
65
- assert_equal 'GT', 'gostar'.foneticalize
66
- end
67
-
68
- test 'guabiru should fonetica to GBR' do
69
- assert_equal 'GBR', 'guabiru'.foneticalize
70
- end
71
-
72
- test 'negro and nego should fonetica to MG' do
73
- assert_equal 'MG', 'negro'.foneticalize
74
- assert_equal 'MG', 'nego'.foneticalize
75
- end
76
-
77
- test 'hieróglifo and hierógrifo should fonetica to RGF' do
78
- assert_equal 'RGF', 'hieróglifo'.foneticalize
79
- assert_equal 'RGF', 'hierógrifo'.foneticalize
80
- end
81
-
82
- test 'gene should fonetica to JM' do
83
- assert_equal 'JM', 'gene'.foneticalize
84
- end
85
-
86
- test 'gibi should fonetica to JB' do
87
- assert_equal 'JB', 'gibi'.foneticalize
88
- end
89
-
90
- test 'fleugma should fonetica to FRM' do
91
- assert_equal 'FRM', 'fleugma'.foneticalize
92
- end
93
-
94
- test 'luminar and ruminar should fonetica to RM' do
95
- assert_equal 'RM', 'luminar'.foneticalize
96
- assert_equal 'RM', 'ruminar'.foneticalize
97
- end
98
-
99
- test 'mudez and nudez should fonetica to MD' do
100
- assert_equal 'MD', 'mudez'.foneticalize
101
- assert_equal 'MD', 'nudez'.foneticalize
102
- end
103
-
104
- test 'comendo and comeno should fonetica to KM' do
105
- assert_equal 'KM', 'comendo'.foneticalize
106
- assert_equal 'KM', 'comeno'.foneticalize
107
- end
108
-
109
- test 'bunginganga and bugiganga should fonetica to BJG' do
110
- assert_equal 'BJG', 'bunginganga'.foneticalize
111
- assert_equal 'BJG', 'bugiganga'.foneticalize
112
- end
113
-
114
- test 'philipe and felipe should fonetica to FRP' do
115
- assert_equal 'FRP', 'philipe'.foneticalize
116
- assert_equal 'FRP', 'felipe'.foneticalize
117
- end
118
-
119
- test 'queijo and keijo should fonetica to KJ' do
120
- assert_equal 'KJ', 'queijo'.foneticalize
121
- assert_equal 'KJ', 'keijo'.foneticalize
122
- end
123
-
124
- test 'lagarto and largato should fonetica to RGT' do
125
- assert_equal 'RGT', 'lagarto'.foneticalize
126
- assert_equal 'RGT', 'largato'.foneticalize
127
- end
128
-
129
- test 'perspectiva and pespectiva should fonetica to PSPTV' do
130
- assert_equal 'PSPTV', 'perspectiva'.foneticalize
131
- assert_equal 'PSPTV', 'pespectiva'.foneticalize
132
- end
133
-
134
- test 'lagartixa and largatixa should fonetica to RGTS' do
135
- assert_equal 'RGTS', 'lagartixa'.foneticalize
136
- assert_equal 'RGTS', 'largatixa'.foneticalize
137
- end
138
-
139
- test 'mesmo and mermo should fonetica to MSM' do
140
- assert_equal 'MSM', 'mesmo'.foneticalize
141
- assert_equal 'MSM', 'mermo'.foneticalize
142
- end
143
-
144
- test 'virgem and vige should fonetica to VJ' do
145
- assert_equal 'VJ', 'virgem'.foneticalize
146
- assert_equal 'VJ', 'vige'.foneticalize
147
- end
148
-
149
- test 'superstição and supertição should fonetica to SPTS' do
150
- assert_equal 'SPTS', 'superstição'.foneticalize
151
- assert_equal 'SPTS', 'supertição'.foneticalize
152
- end
153
-
154
- test 'estupro and estrupo should fonetica to TP' do
155
- assert_equal 'TP', 'estupro'.foneticalize
156
- assert_equal 'TP', 'estrupo'.foneticalize
157
- end
158
-
159
- test 'contrato and contlato should fonetica to KMT' do
160
- assert_equal 'KMT', 'contrato'.foneticalize
161
- assert_equal 'KMT', 'contlato'.foneticalize
162
- end
163
-
164
- test 'kubitscheck and kubixeque should fonetica to KBSK' do
165
- assert_equal 'KBSK', 'kubitscheck'.foneticalize
166
- assert_equal 'KBSK', 'kubixeque'.foneticalize
167
- end
168
-
169
- test 'walter and valter should fonetica to VT' do
170
- assert_equal 'VT', 'walter'.foneticalize
171
- assert_equal 'VT', 'valter'.foneticalize
172
- end
173
-
174
- test 'exceder and esceder should fonetica to SD' do
175
- assert_equal 'SD', 'exceder'.foneticalize
176
- assert_equal 'SD', 'esceder'.foneticalize
177
- end
178
-
179
- test 'yara and iara should fonetica to R' do
180
- assert_equal 'R', 'yara'.foneticalize
181
- assert_equal 'R', 'iara'.foneticalize
182
- end
183
-
184
- test 'casa and caza should fonetica to KS' do
185
- assert_equal 'KS', 'casa'.foneticalize
186
- assert_equal 'KS', 'caza'.foneticalize
187
- end
188
- end