loose_tight_dictionary 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/benchmark/memory.rb CHANGED
@@ -47,7 +47,7 @@ FINAL_OPTIONS = {
47
47
  Memprof.start
48
48
 
49
49
  d = LooseTightDictionary.new HAYSTACK, FINAL_OPTIONS
50
- record = d.find('boeing 707(100)', false)
50
+ record = d.find('boeing 707(100)', :gather_last_result => false)
51
51
  # d.free
52
52
 
53
53
  Memprof.stats
@@ -42,17 +42,21 @@ class LooseTightDictionary
42
42
  def log(str = '') #:nodoc:
43
43
  (options[:log] || $stderr).puts str unless options[:log] == false
44
44
  end
45
-
46
- def find_with_score(needle)
47
- record = find needle
48
- [ record, last_result.score ]
45
+
46
+ def find_all(needle, options = {})
47
+ options = options.symbolize_keys.merge(:find_all => true)
48
+ find needle, options
49
49
  end
50
50
 
51
51
  # todo fix record.record confusion (should be wrapper.record or smth)
52
- def find(needle, gather_last_result = true)
52
+ def find(needle, options = {})
53
53
  raise Freed if freed?
54
54
  free_last_result
55
55
 
56
+ options = options.symbolize_keys
57
+ gather_last_result = options.fetch(:gather_last_result, true)
58
+ find_all = options.fetch(:find_all, false)
59
+
56
60
  if gather_last_result
57
61
  last_result.tighteners = tighteners
58
62
  last_result.identities = identities
@@ -65,7 +69,13 @@ class LooseTightDictionary
65
69
  last_result.needle = needle
66
70
  end
67
71
 
68
- return if strict_blocking and blockings.none? { |blocking| blocking.encompass? needle }
72
+ if strict_blocking and blockings.none? { |blocking| blocking.encompass? needle }
73
+ if find_all
74
+ return []
75
+ else
76
+ return nil
77
+ end
78
+ end
69
79
 
70
80
  encompassed, unencompassed = if strict_blocking and blockings.any?
71
81
  haystack.partition do |record|
@@ -98,6 +108,10 @@ class LooseTightDictionary
98
108
  last_result.certainly_different = certainly_different
99
109
  end
100
110
 
111
+ if find_all
112
+ return possibly_identical.map { |record| record.record }
113
+ end
114
+
101
115
  similarities = possibly_identical.map do |record|
102
116
  needle.similarity record
103
117
  end.sort
@@ -1,3 +1,3 @@
1
1
  class LooseTightDictionary
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -17,7 +17,8 @@ class TestLooseTightDictionary < Test::Unit::TestCase
17
17
 
18
18
  def test_002_find_with_score
19
19
  d = LooseTightDictionary.new %w{ NISSAN HONDA }
20
- assert_equal ['NISSAN', 0.6], d.find_with_score('MISSAM')
20
+ assert_equal 'NISSAN', d.find('MISSAM')
21
+ assert_equal 0.6, d.last_result.score
21
22
  end
22
23
 
23
24
  def test_003_last_result
@@ -75,4 +76,10 @@ class TestLooseTightDictionary < Test::Unit::TestCase
75
76
  d.find('foobar')
76
77
  end
77
78
  end
79
+
80
+ def test_012_find_all
81
+ d = LooseTightDictionary.new [ 'X', 'X22', 'Y', 'Y4' ], :blockings => [ /X/, /Y/ ], :strict_blocking => true
82
+ assert_equal ['X', 'X22' ], d.find_all('X')
83
+ assert_equal [], d.find_all('A')
84
+ end
78
85
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: loose_tight_dictionary
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Seamus Abshere