scorer 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2011 Matt Duncan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,102 @@
1
+ String Scorer
2
+ =============
3
+
4
+ String scorer is a port of Joshaven Potter's [string_score][0] to Ruby.
5
+
6
+ Usage
7
+ -----
8
+
9
+ Install using `gem install scorer`
10
+
11
+ "Hello World".score("HW") # => 0.681818181818182
12
+ "Hello World".score("Hello World") # => 1
13
+ "Hello World".score("Hellz") # => 0
14
+
15
+ Benchmarks
16
+ ----------
17
+
18
+ All benchmarks below were run on a 2GHz Intel Core i7 MacBook Pro.
19
+
20
+ Ruby 1.8.7-p334
21
+
22
+ Benchmarking 4000 iterations...
23
+ Rehearsal ------------------------------------------------------
24
+ one letter 0.050000 0.000000 0.050000 ( 0.051634)
25
+ two letters 0.080000 0.000000 0.080000 ( 0.079367)
26
+ full match 0.010000 0.000000 0.010000 ( 0.008245)
27
+ 13 char / 32 char 0.400000 0.000000 0.400000 ( 0.400755)
28
+ 70 char / 446 char 2.160000 0.020000 2.180000 ( 2.175756)
29
+ --------------------------------------------- total: 2.720000sec
30
+
31
+ user system total real
32
+ one letter 0.050000 0.000000 0.050000 ( 0.050115)
33
+ two letters 0.080000 0.000000 0.080000 ( 0.079156)
34
+ full match 0.000000 0.000000 0.000000 ( 0.002531)
35
+ 13 char / 32 char 0.400000 0.000000 0.400000 ( 0.399183)
36
+ 70 char / 446 char 2.140000 0.020000 2.160000 ( 2.150696)
37
+
38
+ REE 1.8.7-2011.03
39
+
40
+ Benchmarking 4000 iterations...
41
+ Rehearsal ------------------------------------------------------
42
+ one letter 0.050000 0.000000 0.050000 ( 0.044487)
43
+ two letters 0.080000 0.000000 0.080000 ( 0.079872)
44
+ full match 0.000000 0.000000 0.000000 ( 0.002488)
45
+ 13 char / 32 char 0.370000 0.000000 0.370000 ( 0.375615)
46
+ 70 char / 446 char 2.030000 0.020000 2.050000 ( 2.052322)
47
+ --------------------------------------------- total: 2.550000sec
48
+
49
+ user system total real
50
+ one letter 0.040000 0.000000 0.040000 ( 0.043564)
51
+ two letters 0.070000 0.000000 0.070000 ( 0.072628)
52
+ full match 0.010000 0.000000 0.010000 ( 0.002404)
53
+ 13 char / 32 char 0.380000 0.010000 0.390000 ( 0.379886)
54
+ 70 char / 446 char 2.070000 0.020000 2.090000 ( 2.087970)
55
+
56
+ Ruby 1.9.2-p180
57
+
58
+ Benchmarking 4000 iterations...
59
+ Rehearsal ------------------------------------------------------
60
+ one letter 0.030000 0.000000 0.030000 ( 0.031515)
61
+ two letters 0.040000 0.000000 0.040000 ( 0.046282)
62
+ full match 0.010000 0.000000 0.010000 ( 0.003206)
63
+ 13 char / 32 char 0.220000 0.000000 0.220000 ( 0.228381)
64
+ 70 char / 446 char 1.250000 0.000000 1.250000 ( 1.244834)
65
+ --------------------------------------------- total: 1.550000sec
66
+
67
+ user system total real
68
+ one letter 0.030000 0.000000 0.030000 ( 0.027971)
69
+ two letters 0.050000 0.000000 0.050000 ( 0.047023)
70
+ full match 0.000000 0.000000 0.000000 ( 0.001183)
71
+ 13 char / 32 char 0.240000 0.000000 0.240000 ( 0.232444)
72
+ 70 char / 446 char 1.270000 0.010000 1.280000 ( 1.275776)
73
+
74
+ JRuby 1.6.0
75
+
76
+ Benchmarking 4000 iterations...
77
+ Rehearsal ------------------------------------------------------
78
+ one letter 0.435000 0.000000 0.435000 ( 0.434000)
79
+ two letters 0.314000 0.000000 0.314000 ( 0.314000)
80
+ full match 0.018000 0.000000 0.018000 ( 0.018000)
81
+ 13 char / 32 char 0.345000 0.000000 0.345000 ( 0.345000)
82
+ 70 char / 446 char 0.607000 0.000000 0.607000 ( 0.608000)
83
+ --------------------------------------------- total: 1.719000sec
84
+
85
+ user system total real
86
+ one letter 0.022000 0.000000 0.022000 ( 0.022000)
87
+ two letters 0.027000 0.000000 0.027000 ( 0.027000)
88
+ full match 0.001000 0.000000 0.001000 ( 0.001000)
89
+ 13 char / 32 char 0.113000 0.000000 0.113000 ( 0.113000)
90
+ 70 char / 446 char 0.600000 0.000000 0.600000 ( 0.600000)
91
+
92
+ TODO
93
+ ----
94
+
95
+ - Speed improvements (currently just a direct translation from JS)
96
+
97
+ Author
98
+ ------
99
+ Matt Duncan | [mattduncan.org](http://mattduncan.org) |
100
+ [matt@mattduncan.org](mailto:matt@mattduncan.org)
101
+
102
+ [0]: http://github.com/joshaven/string_score
@@ -0,0 +1,13 @@
1
+ require 'rake'
2
+ require 'rspec/core/rake_task'
3
+
4
+ task :default => :spec
5
+
6
+ desc "Run all examples"
7
+ RSpec::Core::RakeTask.new(:spec) do |t|
8
+ t.rspec_opts = %w[--color]
9
+ end
10
+
11
+ task :benchmark do
12
+ require File.expand_path(File.join(File.dirname(__FILE__), "/test/benchmark"))
13
+ end
@@ -0,0 +1,933 @@
1
+ !RBIX
2
+ 10937318184790222022
3
+ x
4
+ M
5
+ 1
6
+ n
7
+ n
8
+ x
9
+ 10
10
+ __script__
11
+ i
12
+ 55
13
+ 99
14
+ 7
15
+ 0
16
+ 65
17
+ 49
18
+ 1
19
+ 2
20
+ 13
21
+ 99
22
+ 12
23
+ 7
24
+ 2
25
+ 12
26
+ 7
27
+ 3
28
+ 12
29
+ 65
30
+ 12
31
+ 49
32
+ 4
33
+ 4
34
+ 15
35
+ 49
36
+ 2
37
+ 0
38
+ 15
39
+ 99
40
+ 7
41
+ 5
42
+ 1
43
+ 65
44
+ 49
45
+ 6
46
+ 3
47
+ 13
48
+ 99
49
+ 12
50
+ 7
51
+ 7
52
+ 12
53
+ 7
54
+ 8
55
+ 12
56
+ 65
57
+ 12
58
+ 49
59
+ 4
60
+ 4
61
+ 15
62
+ 49
63
+ 7
64
+ 0
65
+ 15
66
+ 2
67
+ 11
68
+ I
69
+ 6
70
+ I
71
+ 0
72
+ I
73
+ 0
74
+ I
75
+ 0
76
+ n
77
+ p
78
+ 9
79
+ x
80
+ 5
81
+ Score
82
+ x
83
+ 11
84
+ open_module
85
+ x
86
+ 15
87
+ __module_init__
88
+ M
89
+ 1
90
+ n
91
+ n
92
+ x
93
+ 5
94
+ Score
95
+ i
96
+ 16
97
+ 5
98
+ 66
99
+ 99
100
+ 7
101
+ 0
102
+ 7
103
+ 1
104
+ 65
105
+ 67
106
+ 49
107
+ 2
108
+ 0
109
+ 49
110
+ 3
111
+ 4
112
+ 11
113
+ I
114
+ 5
115
+ I
116
+ 0
117
+ I
118
+ 0
119
+ I
120
+ 0
121
+ n
122
+ p
123
+ 4
124
+ x
125
+ 5
126
+ score
127
+ M
128
+ 1
129
+ n
130
+ n
131
+ x
132
+ 5
133
+ score
134
+ i
135
+ 152
136
+ 23
137
+ 1
138
+ 10
139
+ 8
140
+ 1
141
+ 19
142
+ 1
143
+ 15
144
+ 5
145
+ 20
146
+ 0
147
+ 83
148
+ 0
149
+ 9
150
+ 19
151
+ 79
152
+ 11
153
+ 8
154
+ 20
155
+ 1
156
+ 15
157
+ 5
158
+ 19
159
+ 2
160
+ 15
161
+ 20
162
+ 2
163
+ 49
164
+ 1
165
+ 0
166
+ 49
167
+ 2
168
+ 0
169
+ 19
170
+ 3
171
+ 15
172
+ 78
173
+ 19
174
+ 4
175
+ 15
176
+ 3
177
+ 19
178
+ 5
179
+ 15
180
+ 79
181
+ 19
182
+ 6
183
+ 15
184
+ 20
185
+ 0
186
+ 49
187
+ 3
188
+ 0
189
+ 56
190
+ 4
191
+ 50
192
+ 5
193
+ 0
194
+ 15
195
+ 20
196
+ 4
197
+ 20
198
+ 0
199
+ 49
200
+ 1
201
+ 0
202
+ 49
203
+ 6
204
+ 1
205
+ 19
206
+ 7
207
+ 15
208
+ 20
209
+ 0
210
+ 49
211
+ 1
212
+ 0
213
+ 20
214
+ 3
215
+ 49
216
+ 6
217
+ 1
218
+ 19
219
+ 8
220
+ 15
221
+ 20
222
+ 7
223
+ 20
224
+ 8
225
+ 49
226
+ 7
227
+ 1
228
+ 19
229
+ 9
230
+ 15
231
+ 20
232
+ 9
233
+ 20
234
+ 7
235
+ 81
236
+ 8
237
+ 7
238
+ 9
239
+ 49
240
+ 6
241
+ 1
242
+ 19
243
+ 10
244
+ 15
245
+ 20
246
+ 10
247
+ 20
248
+ 6
249
+ 49
250
+ 6
251
+ 1
252
+ 19
253
+ 10
254
+ 15
255
+ 20
256
+ 5
257
+ 13
258
+ 9
259
+ 134
260
+ 15
261
+ 20
262
+ 10
263
+ 7
264
+ 10
265
+ 81
266
+ 8
267
+ 79
268
+ 84
269
+ 11
270
+ 9
271
+ 146
272
+ 20
273
+ 10
274
+ 7
275
+ 12
276
+ 81
277
+ 8
278
+ 19
279
+ 10
280
+ 8
281
+ 147
282
+ 1
283
+ 15
284
+ 20
285
+ 10
286
+ 11
287
+ 11
288
+ I
289
+ d
290
+ I
291
+ b
292
+ I
293
+ 1
294
+ I
295
+ 2
296
+ n
297
+ p
298
+ 13
299
+ x
300
+ 2
301
+ ==
302
+ x
303
+ 6
304
+ length
305
+ x
306
+ 4
307
+ to_f
308
+ x
309
+ 5
310
+ chars
311
+ M
312
+ 1
313
+ p
314
+ 2
315
+ x
316
+ 9
317
+ for_block
318
+ t
319
+ n
320
+ x
321
+ 5
322
+ score
323
+ i
324
+ 219
325
+ 58
326
+ 37
327
+ 19
328
+ 0
329
+ 15
330
+ 37
331
+ 19
332
+ 1
333
+ 15
334
+ 15
335
+ 21
336
+ 1
337
+ 2
338
+ 20
339
+ 0
340
+ 49
341
+ 0
342
+ 0
343
+ 49
344
+ 1
345
+ 1
346
+ 21
347
+ 1
348
+ 2
349
+ 20
350
+ 0
351
+ 49
352
+ 2
353
+ 0
354
+ 49
355
+ 1
356
+ 1
357
+ 35
358
+ 2
359
+ 19
360
+ 2
361
+ 15
362
+ 20
363
+ 2
364
+ 1
365
+ 35
366
+ 1
367
+ 82
368
+ 3
369
+ 19
370
+ 2
371
+ 15
372
+ 20
373
+ 2
374
+ 49
375
+ 4
376
+ 0
377
+ 19
378
+ 3
379
+ 15
380
+ 20
381
+ 3
382
+ 9
383
+ 65
384
+ 7
385
+ 5
386
+ 19
387
+ 4
388
+ 8
389
+ 93
390
+ 21
391
+ 1
392
+ 1
393
+ 9
394
+ 73
395
+ 1
396
+ 8
397
+ 75
398
+ 78
399
+ 31
400
+ 15
401
+ 21
402
+ 1
403
+ 6
404
+ 79
405
+ 21
406
+ 1
407
+ 1
408
+ 82
409
+ 3
410
+ 81
411
+ 6
412
+ 22
413
+ 1
414
+ 6
415
+ 15
416
+ 1
417
+ 11
418
+ 15
419
+ 21
420
+ 1
421
+ 2
422
+ 20
423
+ 3
424
+ 49
425
+ 7
426
+ 1
427
+ 49
428
+ 8
429
+ 0
430
+ 20
431
+ 0
432
+ 83
433
+ 9
434
+ 9
435
+ 121
436
+ 20
437
+ 4
438
+ 7
439
+ 10
440
+ 81
441
+ 6
442
+ 19
443
+ 4
444
+ 8
445
+ 122
446
+ 1
447
+ 15
448
+ 20
449
+ 3
450
+ 78
451
+ 83
452
+ 9
453
+ 9
454
+ 155
455
+ 20
456
+ 4
457
+ 7
458
+ 11
459
+ 81
460
+ 6
461
+ 19
462
+ 4
463
+ 15
464
+ 20
465
+ 1
466
+ 78
467
+ 83
468
+ 9
469
+ 9
470
+ 152
471
+ 2
472
+ 22
473
+ 1
474
+ 5
475
+ 8
476
+ 153
477
+ 1
478
+ 8
479
+ 156
480
+ 1
481
+ 15
482
+ 21
483
+ 1
484
+ 2
485
+ 20
486
+ 3
487
+ 79
488
+ 82
489
+ 3
490
+ 49
491
+ 7
492
+ 1
493
+ 49
494
+ 8
495
+ 0
496
+ 7
497
+ 12
498
+ 64
499
+ 83
500
+ 9
501
+ 9
502
+ 188
503
+ 20
504
+ 4
505
+ 7
506
+ 13
507
+ 81
508
+ 6
509
+ 19
510
+ 4
511
+ 8
512
+ 189
513
+ 1
514
+ 15
515
+ 21
516
+ 1
517
+ 2
518
+ 20
519
+ 3
520
+ 79
521
+ 81
522
+ 6
523
+ 21
524
+ 1
525
+ 3
526
+ 49
527
+ 14
528
+ 2
529
+ 22
530
+ 1
531
+ 2
532
+ 15
533
+ 21
534
+ 1
535
+ 4
536
+ 20
537
+ 4
538
+ 81
539
+ 6
540
+ 22
541
+ 1
542
+ 4
543
+ 11
544
+ I
545
+ 9
546
+ I
547
+ 5
548
+ I
549
+ 2
550
+ I
551
+ 2
552
+ n
553
+ p
554
+ 15
555
+ x
556
+ 8
557
+ downcase
558
+ x
559
+ 5
560
+ index
561
+ x
562
+ 6
563
+ upcase
564
+ x
565
+ 1
566
+ -
567
+ x
568
+ 3
569
+ min
570
+ d
571
+ +0.800000000000000044408920985006261616945266723632812500 -3
572
+ x
573
+ 1
574
+ +
575
+ x
576
+ 2
577
+ []
578
+ x
579
+ 3
580
+ chr
581
+ x
582
+ 2
583
+ ==
584
+ d
585
+ +0.800000000000000044408920985006261616945266723632812500 -3
586
+ d
587
+ +0.599999999999999977795539507496869191527366638183593750 0
588
+ s
589
+ 1
590
+
591
+ d
592
+ +0.800000000000000044408920985006261616945266723632812500 0
593
+ x
594
+ 5
595
+ slice
596
+ p
597
+ 43
598
+ I
599
+ 0
600
+ I
601
+ d
602
+ I
603
+ a
604
+ I
605
+ f
606
+ I
607
+ 25
608
+ I
609
+ 10
610
+ I
611
+ 2f
612
+ I
613
+ 11
614
+ I
615
+ 37
616
+ I
617
+ 13
618
+ I
619
+ 3b
620
+ I
621
+ 15
622
+ I
623
+ 41
624
+ I
625
+ 17
626
+ I
627
+ 4c
628
+ I
629
+ 18
630
+ I
631
+ 5b
632
+ I
633
+ 19
634
+ I
635
+ 5e
636
+ I
637
+ 1d
638
+ I
639
+ 6f
640
+ I
641
+ 1e
642
+ I
643
+ 79
644
+ I
645
+ 1d
646
+ I
647
+ 7b
648
+ I
649
+ 22
650
+ I
651
+ 82
652
+ I
653
+ 25
654
+ I
655
+ 8b
656
+ I
657
+ 2a
658
+ I
659
+ 9b
660
+ I
661
+ 22
662
+ I
663
+ 9d
664
+ I
665
+ 30
666
+ I
667
+ b2
668
+ I
669
+ 31
670
+ I
671
+ bc
672
+ I
673
+ 30
674
+ I
675
+ be
676
+ I
677
+ 36
678
+ I
679
+ d0
680
+ I
681
+ 39
682
+ I
683
+ db
684
+ x
685
+ 34
686
+ /Users/matt/src/score/lib/score.rb
687
+ p
688
+ 5
689
+ x
690
+ 1
691
+ c
692
+ x
693
+ 1
694
+ i
695
+ x
696
+ 7
697
+ indexes
698
+ x
699
+ 15
700
+ index_in_string
701
+ x
702
+ 15
703
+ character_score
704
+ x
705
+ 15
706
+ each_with_index
707
+ x
708
+ 1
709
+ /
710
+ x
711
+ 1
712
+ *
713
+ x
714
+ 1
715
+ +
716
+ d
717
+ +0.500000000000000000000000000000000000000000000000000000 2
718
+ d
719
+ +0.599999999999999977795539507496869191527366638183593750 -2
720
+ x
721
+ 1
722
+ <
723
+ d
724
+ +0.599999999999999977795539507496869191527366638183593750 -2
725
+ p
726
+ 35
727
+ I
728
+ -1
729
+ I
730
+ 2
731
+ I
732
+ 8
733
+ I
734
+ 4
735
+ I
736
+ 15
737
+ I
738
+ 6
739
+ I
740
+ 19
741
+ I
742
+ 7
743
+ I
744
+ 24
745
+ I
746
+ 8
747
+ I
748
+ 28
749
+ I
750
+ 9
751
+ I
752
+ 2c
753
+ I
754
+ a
755
+ I
756
+ 30
757
+ I
758
+ d
759
+ I
760
+ 3b
761
+ I
762
+ 3c
763
+ I
764
+ 48
765
+ I
766
+ 3f
767
+ I
768
+ 55
769
+ I
770
+ 40
771
+ I
772
+ 5f
773
+ I
774
+ 41
775
+ I
776
+ 6d
777
+ I
778
+ 44
779
+ I
780
+ 77
781
+ I
782
+ 47
783
+ I
784
+ 88
785
+ I
786
+ 48
787
+ I
788
+ 92
789
+ I
790
+ 47
791
+ I
792
+ 94
793
+ I
794
+ 4b
795
+ I
796
+ 98
797
+ x
798
+ 34
799
+ /Users/matt/src/score/lib/score.rb
800
+ p
801
+ 11
802
+ x
803
+ 12
804
+ abbreviation
805
+ x
806
+ 9
807
+ fuzziness
808
+ x
809
+ 6
810
+ string
811
+ x
812
+ 13
813
+ string_length
814
+ x
815
+ 21
816
+ total_character_score
817
+ x
818
+ 32
819
+ should_award_common_prefix_bonus
820
+ x
821
+ 7
822
+ fuzzies
823
+ x
824
+ 18
825
+ abbreviation_score
826
+ x
827
+ 28
828
+ percentage_of_matched_string
829
+ x
830
+ 10
831
+ word_score
832
+ x
833
+ 11
834
+ final_score
835
+ x
836
+ 17
837
+ method_visibility
838
+ x
839
+ 15
840
+ add_defn_method
841
+ p
842
+ 3
843
+ I
844
+ 2
845
+ I
846
+ 2
847
+ I
848
+ 10
849
+ x
850
+ 34
851
+ /Users/matt/src/score/lib/score.rb
852
+ p
853
+ 0
854
+ x
855
+ 13
856
+ attach_method
857
+ x
858
+ 6
859
+ String
860
+ x
861
+ 10
862
+ open_class
863
+ x
864
+ 14
865
+ __class_init__
866
+ M
867
+ 1
868
+ n
869
+ n
870
+ x
871
+ 6
872
+ String
873
+ i
874
+ 11
875
+ 5
876
+ 66
877
+ 5
878
+ 45
879
+ 0
880
+ 1
881
+ 47
882
+ 49
883
+ 2
884
+ 1
885
+ 11
886
+ I
887
+ 2
888
+ I
889
+ 0
890
+ I
891
+ 0
892
+ I
893
+ 0
894
+ n
895
+ p
896
+ 3
897
+ x
898
+ 5
899
+ Score
900
+ n
901
+ x
902
+ 7
903
+ include
904
+ p
905
+ 3
906
+ I
907
+ 2
908
+ I
909
+ 50
910
+ I
911
+ b
912
+ x
913
+ 34
914
+ /Users/matt/src/score/lib/score.rb
915
+ p
916
+ 0
917
+ p
918
+ 5
919
+ I
920
+ 0
921
+ I
922
+ 1
923
+ I
924
+ 1a
925
+ I
926
+ 4f
927
+ I
928
+ 37
929
+ x
930
+ 34
931
+ /Users/matt/src/score/lib/score.rb
932
+ p
933
+ 0