~ubuntu-branches/ubuntu/quantal/ruby-ferret/quantal

« back to all changes in this revision

Viewing changes to test/unit/analysis/tc_analyzer.rb

  • Committer: Package Import Robot
  • Author(s): Cédric Boutillier
  • Date: 2012-06-14 23:04:48 UTC
  • mfrom: (2.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20120614230448-wd5se4ia1yz7dvms
Tags: 0.11.8.4+debian-1
* New upstream version from a new source
  + the new code fixes format security issues (Closes: #672069)
  + change homepage to https://github.com/jkraemer/ferret/
* Build for all Ruby versions (Closes: #655636)
  + change depends accordingly
  + do not set shebang of bin/ferret to ruby1.8
* Repack source to remove convenience copy of bzlib
  + build-dep on libbz2-dev
  + dversionmangle in debian/watch
  + add debian/README.source explaining how to clean the source
* debian/patches:
  + disable_load_path_manipulation.patch: do not override $LOAD_PATH
  + disable_test_causing_segfault.patch: temporarily disable a test known to
    cause segfaults
  + fix_compatibility_with_minitest.patch: fix a failing test with Ruby1.9
  + use_system_bzlib.patch: adapt the source to use system libbz2
  + fix_typos_in_source_code.patch: correct some spelling errors in the
    source code
  + block_variables_have_local_scopes.patch: fix syntax in
    bin/ferret-browser
* Override dh_auto_clean to remove test/temp when cleaning
* Bump Standards-Version to 3.9.3 (no changes needed)
* Set priority of transitional packages to extra
* Add myself to Uploaders:
* Update copyright to DEP-5 copyright-format/1.0
* Add TUTORIAL and debian/README.source to documents
* Override lintian warnings about duplicate descriptions of transitional
  packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# encoding: utf-8
 
2
 
1
3
require File.dirname(__FILE__) + "/../../test_helper"
2
4
 
3
5
class AnalyzerTest < Test::Unit::TestCase
4
6
  include Ferret::Analysis
5
7
 
6
8
  def test_analyzer()
7
 
    input = 'DBalmain@gmail.com is My E-Mail 523@#$ ADDRESS. 23#@$'
 
9
    input = 'DBalmain@gmail.com is My E-Mail 523@#$ ADDRESS. 23#!$'
8
10
    a = Analyzer.new()
9
11
    t = a.token_stream("fieldname", input)
10
12
    t2 = a.token_stream("fieldname", input)
44
46
  include Ferret::Analysis
45
47
 
46
48
  def test_letter_analyzer()
47
 
    input = 'DBalmain@gmail.com is My E-Mail 523@#$ ADDRESS. 23#@$'
 
49
    input = 'DBalmain@gmail.com is My E-Mail 523@#$ ADDRESS. 23#!$'
48
50
    a = AsciiLetterAnalyzer.new()
49
51
    t = a.token_stream("fieldname", input)
50
52
    t2 = a.token_stream("fieldname", input)
85
87
 
86
88
  def test_letter_analyzer()
87
89
    Ferret.locale = ""
88
 
    input = 'DBalmän@gmail.com is My e-mail 52   #$ address. 23#@$ ÁÄGÇ®ÊË̯ÚØìÖÎÍ'
 
90
    input = 'DBalmän@gmail.com is My e-mail 52   #$ address. 23#!$ ÁÄGÇ®ÊË̯ÚØìÖÎÍ'
89
91
    a = LetterAnalyzer.new(false)
90
92
    t = a.token_stream("fieldname", input)
91
93
    t2 = a.token_stream("fieldname", input)
137
139
  include Ferret::Analysis
138
140
 
139
141
  def test_white_space_analyzer()
140
 
    input = 'DBalmain@gmail.com is My E-Mail 52   #$ ADDRESS. 23#@$'
 
142
    input = 'DBalmain@gmail.com is My E-Mail 52   #$ ADDRESS. 23#!$'
141
143
    a = AsciiWhiteSpaceAnalyzer.new()
142
144
    t = a.token_stream("fieldname", input)
143
145
    t2 = a.token_stream("fieldname", input)
148
150
    assert_equal(Token.new('52', 32, 34), t.next)
149
151
    assert_equal(Token.new('#$', 37, 39), t.next)
150
152
    assert_equal(Token.new('ADDRESS.', 40, 48), t.next)
151
 
    assert_equal(Token.new('23#@$', 49, 54), t.next)
 
153
    assert_equal(Token.new('23#!$', 49, 54), t.next)
152
154
    assert(! t.next())
153
155
    assert_equal(Token.new('DBalmain@gmail.com', 0, 18), t2.next)
154
156
    assert_equal(Token.new('is', 19, 21), t2.next)
157
159
    assert_equal(Token.new('52', 32, 34), t2.next)
158
160
    assert_equal(Token.new('#$', 37, 39), t2.next)
159
161
    assert_equal(Token.new('ADDRESS.', 40, 48), t2.next)
160
 
    assert_equal(Token.new('23#@$', 49, 54), t2.next)
 
162
    assert_equal(Token.new('23#!$', 49, 54), t2.next)
161
163
    assert(! t2.next())
162
164
    a = AsciiWhiteSpaceAnalyzer.new(true)
163
165
    t = a.token_stream("fieldname", input)
168
170
    assert_equal(Token.new('52', 32, 34), t.next)
169
171
    assert_equal(Token.new('#$', 37, 39), t.next)
170
172
    assert_equal(Token.new('address.', 40, 48), t.next)
171
 
    assert_equal(Token.new('23#@$', 49, 54), t.next)
 
173
    assert_equal(Token.new('23#!$', 49, 54), t.next)
172
174
    assert(! t.next())
173
175
  end
174
176
end
177
179
  include Ferret::Analysis
178
180
 
179
181
  def test_white_space_analyzer()
180
 
    input = 'DBalmän@gmail.com is My e-mail 52   #$ address. 23#@$ ÁÄGÇ®ÊË̯ÚØìÖÎÍ'
 
182
    input = 'DBalmän@gmail.com is My e-mail 52   #$ address. 23#!$ ÁÄGÇ®ÊË̯ÚØìÖÎÍ'
181
183
    a = WhiteSpaceAnalyzer.new()
182
184
    t = a.token_stream("fieldname", input)
183
185
    t2 = a.token_stream("fieldname", input)
188
190
    assert_equal(Token.new('52', 32, 34), t.next)
189
191
    assert_equal(Token.new('#$', 37, 39), t.next)
190
192
    assert_equal(Token.new('address.', 40, 48), t.next)
191
 
    assert_equal(Token.new('23#@$', 49, 54), t.next)
 
193
    assert_equal(Token.new('23#!$', 49, 54), t.next)
192
194
    assert_equal(Token.new('ÁÄGÇ®ÊË̯ÚØìÖÎÍ', 55, 86), t.next)
193
195
    assert(! t.next())
194
196
    assert_equal(Token.new('DBalmän@gmail.com', 0, 18), t2.next)
198
200
    assert_equal(Token.new('52', 32, 34), t2.next)
199
201
    assert_equal(Token.new('#$', 37, 39), t2.next)
200
202
    assert_equal(Token.new('address.', 40, 48), t2.next)
201
 
    assert_equal(Token.new('23#@$', 49, 54), t2.next)
 
203
    assert_equal(Token.new('23#!$', 49, 54), t2.next)
202
204
    assert_equal(Token.new('ÁÄGÇ®ÊË̯ÚØìÖÎÍ', 55, 86), t2.next)
203
205
    assert(! t2.next())
204
206
    a = WhiteSpaceAnalyzer.new(true)
210
212
    assert_equal(Token.new('52', 32, 34), t.next)
211
213
    assert_equal(Token.new('#$', 37, 39), t.next)
212
214
    assert_equal(Token.new('address.', 40, 48), t.next)
213
 
    assert_equal(Token.new('23#@$', 49, 54), t.next)
 
215
    assert_equal(Token.new('23#!$', 49, 54), t.next)
214
216
    assert_equal(Token.new('áägç®êëì¯úøã¬öîí', 55, 86), t.next)
215
217
    assert(! t.next())
216
218
  end
220
222
  include Ferret::Analysis
221
223
 
222
224
  def test_standard_analyzer()
223
 
    input = 'DBalmain@gmail.com is My e-mail 52   #$ Address. 23#@$ http://www.google.com/results/ T.N.T. 123-1235-ASD-1234'
 
225
    input = 'DBalmain@gmail.com is My e-mail 52   #$ Address. 23#!$ http://www.google.com/results/ T.N.T. 123-1235-ASD-1234'
224
226
    a = AsciiStandardAnalyzer.new()
225
227
    t = a.token_stream("fieldname", input)
226
228
    t2 = a.token_stream("fieldname", input)
231
233
    assert_equal(Token.new('52', 32, 34), t.next)
232
234
    assert_equal(Token.new('address', 40, 47), t.next)
233
235
    assert_equal(Token.new('23', 49, 51), t.next)
234
 
    assert_equal(Token.new('www.google.com/results', 55, 84), t.next)
 
236
    assert_equal(Token.new('www.google.com/results', 55, 85), t.next)
235
237
    assert_equal(Token.new('tnt', 86, 91), t.next)
236
238
    assert_equal(Token.new('123-1235-asd-1234', 93, 110), t.next)
237
239
    assert(! t.next())
242
244
    assert_equal(Token.new('52', 32, 34), t2.next)
243
245
    assert_equal(Token.new('address', 40, 47), t2.next)
244
246
    assert_equal(Token.new('23', 49, 51), t2.next)
245
 
    assert_equal(Token.new('www.google.com/results', 55, 84), t2.next)
 
247
    assert_equal(Token.new('www.google.com/results', 55, 85), t2.next)
246
248
    assert_equal(Token.new('tnt', 86, 91), t2.next)
247
249
    assert_equal(Token.new('123-1235-asd-1234', 93, 110), t2.next)
248
250
    assert(! t2.next())
257
259
    assert_equal(Token.new('52', 32, 34), t.next)
258
260
    assert_equal(Token.new('Address', 40, 47), t.next)
259
261
    assert_equal(Token.new('23', 49, 51), t.next)
260
 
    assert_equal(Token.new('www.google.com/results', 55, 84), t.next)
 
262
    assert_equal(Token.new('www.google.com/results', 55, 85), t.next)
261
263
    assert_equal(Token.new('TNT', 86, 91), t.next)
262
264
    assert_equal(Token.new('123-1235-ASD-1234', 93, 110), t.next)
263
265
    assert(! t.next())
268
270
  include Ferret::Analysis
269
271
 
270
272
  def test_standard_analyzer()
271
 
    input = 'DBalmán@gmail.com is My e-mail and the Address. 23#@$ http://www.google.com/results/ T.N.T. 123-1235-ASD-1234 23#@$ ÁÄGÇ®ÊË̯ÚØìÖÎÍ'
 
273
    input = 'DBalmán@gmail.com is My e-mail and the Address. 23#!$ http://www.google.com/results/ T.N.T. 123-1235-ASD-1234 23#!$ ÁÄGÇ®ÊË̯ÚØìÖÎÍ'
272
274
    a = StandardAnalyzer.new()
273
275
    t = a.token_stream("fieldname", input)
274
276
    t2 = a.token_stream("fieldname", input)
278
280
    assert_equal(Token.new('mail', 27, 31), t.next)
279
281
    assert_equal(Token.new('address', 40, 47), t.next)
280
282
    assert_equal(Token.new('23', 49, 51), t.next)
281
 
    assert_equal(Token.new('www.google.com/results', 55, 84), t.next)
 
283
    assert_equal(Token.new('www.google.com/results', 55, 85), t.next)
282
284
    assert_equal(Token.new('tnt', 86, 91), t.next)
283
285
    assert_equal(Token.new('123-1235-asd-1234', 93, 110), t.next)
284
286
    assert_equal(Token.new('23', 111, 113), t.next)
293
295
    assert_equal(Token.new('mail', 27, 31), t2.next)
294
296
    assert_equal(Token.new('address', 40, 47), t2.next)
295
297
    assert_equal(Token.new('23', 49, 51), t2.next)
296
 
    assert_equal(Token.new('www.google.com/results', 55, 84), t2.next)
 
298
    assert_equal(Token.new('www.google.com/results', 55, 85), t2.next)
297
299
    assert_equal(Token.new('tnt', 86, 91), t2.next)
298
300
    assert_equal(Token.new('123-1235-asd-1234', 93, 110), t2.next)
299
301
    assert_equal(Token.new('23', 111, 113), t2.next)
311
313
    assert_equal(Token.new('mail', 27, 31), t.next)
312
314
    assert_equal(Token.new('Address', 40, 47), t.next)
313
315
    assert_equal(Token.new('23', 49, 51), t.next)
314
 
    assert_equal(Token.new('www.google.com/results', 55, 84), t.next)
 
316
    assert_equal(Token.new('www.google.com/results', 55, 85), t.next)
315
317
    assert_equal(Token.new('TNT', 86, 91), t.next)
316
318
    assert_equal(Token.new('123-1235-ASD-1234', 93, 110), t.next)
317
319
    assert_equal(Token.new('23', 111, 113), t.next)
329
331
    assert_equal(Token.new('and', 32, 35), t.next)
330
332
    assert_equal(Token.new('the', 36, 39), t.next)
331
333
    assert_equal(Token.new('address', 40, 47), t.next)
332
 
    assert_equal(Token.new('www.google.com/results', 55, 84), t.next)
 
334
    assert_equal(Token.new('www.google.com/results', 55, 85), t.next)
333
335
    assert_equal(Token.new('123-1235-asd-1234', 93, 110), t.next)
334
336
    assert_equal(Token.new('áägç', 117, 124), t.next)
335
337
    assert_equal(Token.new('êëì', 126, 132), t.next)
342
344
    assert_equal(Token.new('and', 32, 35), t2.next)
343
345
    assert_equal(Token.new('the', 36, 39), t2.next)
344
346
    assert_equal(Token.new('address', 40, 47), t2.next)
345
 
    assert_equal(Token.new('www.google.com/results', 55, 84), t2.next)
 
347
    assert_equal(Token.new('www.google.com/results', 55, 85), t2.next)
346
348
    assert_equal(Token.new('123-1235-asd-1234', 93, 110), t2.next)
347
349
    assert_equal(Token.new('áägç', 117, 124), t2.next)
348
350
    assert_equal(Token.new('êëì', 126, 132), t2.next)
355
357
class PerFieldAnalyzerTest < Test::Unit::TestCase
356
358
  include Ferret::Analysis
357
359
  def test_per_field_analyzer()
358
 
    input = 'DBalmain@gmail.com is My e-mail 52   #$ address. 23#@$'
 
360
    input = 'DBalmain@gmail.com is My e-mail 52   #$ address. 23#!$'
359
361
    pfa = PerFieldAnalyzer.new(StandardAnalyzer.new())
360
362
    pfa['white'] = WhiteSpaceAnalyzer.new(false)
361
363
    pfa['white_l'] = WhiteSpaceAnalyzer.new(true)
370
372
    assert_equal(Token.new('52', 32, 34), t.next)
371
373
    assert_equal(Token.new('#$', 37, 39), t.next)
372
374
    assert_equal(Token.new('address.', 40, 48), t.next)
373
 
    assert_equal(Token.new('23#@$', 49, 54), t.next)
 
375
    assert_equal(Token.new('23#!$', 49, 54), t.next)
374
376
    assert(! t.next())
375
377
    t = pfa.token_stream('white_l', input)
376
378
    assert_equal(Token.new('dbalmain@gmail.com', 0, 18), t.next)
380
382
    assert_equal(Token.new('52', 32, 34), t.next)
381
383
    assert_equal(Token.new('#$', 37, 39), t.next)
382
384
    assert_equal(Token.new('address.', 40, 48), t.next)
383
 
    assert_equal(Token.new('23#@$', 49, 54), t.next)
 
385
    assert_equal(Token.new('23#!$', 49, 54), t.next)
384
386
    assert(! t.next())
385
387
    t = pfa.token_stream('letter_u', input)
386
388
    assert_equal(Token.new('DBalmain', 0, 8), t.next)
418
420
  include Ferret::Analysis
419
421
 
420
422
  def test_reg_exp_analyzer()
421
 
    input = 'DBalmain@gmail.com is My e-mail 52   #$ Address. 23#@$ http://www.google.com/RESULT_3.html T.N.T. 123-1235-ASD-1234 23 Rob\'s'
 
423
    input = 'DBalmain@gmail.com is My e-mail 52   #$ Address. 23#!$ http://www.google.com/RESULT_3.html T.N.T. 123-1235-ASD-1234 23 Rob\'s'
422
424
    a = RegExpAnalyzer.new()
423
425
    t = a.token_stream('XXX', input)
424
426
    t2 = a.token_stream('XXX', "one_Two three")
510
512
  include Ferret::Analysis
511
513
 
512
514
  def test_custom_filter()
513
 
    input = 'DBalmán@gmail.com is My e-mail and the Address. 23#@$ http://www.google.com/results/ T.N.T. 123-1235-ASD-1234 23#@$ ÁÄGÇ®ÊË̯ÚØìÖÎÍ'
 
515
    input = 'DBalmán@gmail.com is My e-mail and the Address. 23#!$ http://www.google.com/results/ T.N.T. 123-1235-ASD-1234 23#!$ ÁÄGÇ®ÊË̯ÚØìÖÎÍ'
514
516
    a = StemmingStandardAnalyzer.new()
515
517
    t = a.token_stream("fieldname", input)
516
518
    assert_equal(Token.new('dbalmán@gmail.com', 0, 18), t.next)
519
521
    assert_equal(Token.new('mail', 27, 31), t.next)
520
522
    assert_equal(Token.new('address', 40, 47), t.next)
521
523
    assert_equal(Token.new('23', 49, 51), t.next)
522
 
    assert_equal(Token.new('www.google.com/result', 55, 84), t.next)
 
524
    assert_equal(Token.new('www.google.com/result', 55, 85), t.next)
523
525
    assert_equal(Token.new('tnt', 86, 91), t.next)
524
526
    assert_equal(Token.new('123-1235-asd-1234', 93, 110), t.next)
525
527
    assert_equal(Token.new('23', 111, 113), t.next)