kevintyll-ofac 1.1.0 → 1.1.1

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/History.txt CHANGED
@@ -11,4 +11,11 @@
11
11
  == 1.1.0 2009-05-12
12
12
 
13
13
  * 1 minor enhancement:
14
- * Modified the match alogorithm to reduct the score if there is not an address or city match if the data is in the database.
14
+ * Modified the match alogorithm to reduct the score if there is not an address or city match if the data is in the database.
15
+
16
+ == 1.1.1 2009-05-13
17
+
18
+ * 2 minor changes:
19
+ * Changed the sql in the initial search to do a like instead of a soundex. For short names, the soundex returned almost the entire table
20
+ making the process take too long.
21
+ * Also changed the sql to only return individuals, also for the sake of performance.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 1
3
- :patch: 0
3
+ :patch: 1
4
4
  :major: 1
@@ -22,6 +22,7 @@ class CreateOfacSdnTable < ActiveRecord::Migration
22
22
  t.string :alternate_identity_remarks
23
23
  t.timestamps
24
24
  end
25
+ add_index :ofac_sdns, :sdn_type
25
26
  end
26
27
 
27
28
  def self.down
@@ -1,6 +1,3 @@
1
- require 'activerecord'
2
- require 'active_record/connection_adapters/mysql_adapter'
3
-
4
1
  class Ofac
5
2
 
6
3
 
@@ -99,29 +96,26 @@ class Ofac
99
96
 
100
97
  def calculate_score
101
98
  unless @identity[:name].to_s == ''
102
- if OfacSdn.connection.kind_of?(ActiveRecord::ConnectionAdapters::MysqlAdapter)
103
- #first get a list from the database of possible matches by name
104
- #this query is pretty liberal, we just want to get a list of possible
105
- #matches from the database that we can run through our ruby matching algorithm
106
- partial_name = @identity[:name].gsub!(/\W/,'|')
107
- name_array = partial_name.split('|')
108
- name_array.delete('')
109
- sql_name_partial = name_array.collect {|partial_name| "INSTR(SUBSTR(SOUNDEX(concat('O',name)), 2), REPLACE(SUBSTR(SOUNDEX('O#{partial_name}'), 2), '0', '')) > 0"}.join(' and ')
110
- sql_alt_name_partial = name_array.collect {|partial_name| "INSTR(SUBSTR(SOUNDEX(concat('O',alternate_identity_name)), 2), REPLACE(SUBSTR(SOUNDEX('O#{partial_name}'), 2), '0', '')) > 0"}.join(' and ')
111
- ##this sql for getting "accurate sounds like" functionality comes from:
112
- #http://jgeewax.wordpress.com/2006/07/21/efficient-sounds-like-searches-in-mysql/
113
- possible_sdns = OfacSdn.connection.select_all("select concat(name,'|', alternate_identity_name) name, address, city
99
+
100
+ #first get a list from the database of possible matches by name
101
+ #this query is pretty liberal, we just want to get a list of possible
102
+ #matches from the database that we can run through our ruby matching algorithm
103
+ partial_name = @identity[:name].gsub(/\W/,'|')
104
+ name_array = partial_name.split('|')
105
+ name_array.delete('')
106
+ sql_name_partial = name_array.collect {|partial_name| "name like '%#{partial_name}%'"}.join(' or ')
107
+ sql_alt_name_partial = name_array.collect {|partial_name| "alternate_identity_name like '%#{partial_name}%'"}.join(' or ')
108
+ possible_sdns = OfacSdn.connection.select_all("select name, alternate_identity_name, address, city
114
109
  from ofac_sdns
115
110
  where name is not null
116
- and (((#{sql_name_partial}))
117
- or ((#{sql_alt_name_partial})))")
118
- else
119
- possible_sdns = OfacSdn.find(:all, :select => 'name, alternate_identity_name, address, city').collect{|sdn| {:name => "#{sdn.name}|#{sdn.alternate_identity_name}", :address => sdn.address, :city => sdn.city}}
120
- end
121
-
111
+ and sdn_type = 'individual'
112
+ and #{sql_name_partial}
113
+ or #{sql_alt_name_partial}")
114
+ possible_sdns = possible_sdns.collect {|sdn|{:name => "#{sdn['name']}|#{sdn['alternate_identity_name']}", :city => sdn['city'], :address => sdn['address']}}
115
+
122
116
  match = OfacMatch.new({:name => {:weight => 60, :token => "#{@identity[:name]}"},
123
- :address => {:weight => 10, :token => @identity[:address]},
124
- :city => {:weight => 30, :token => @identity[:city]}})
117
+ :address => {:weight => 10, :token => @identity[:address]},
118
+ :city => {:weight => 30, :token => @identity[:city]}})
125
119
 
126
120
  score = match.score(possible_sdns)
127
121
  @possible_hits = match.possible_hits
data/test/test_helper.rb CHANGED
@@ -41,6 +41,7 @@ class Test::Unit::TestCase
41
41
  t.string :alternate_identity_remarks
42
42
  t.timestamps
43
43
  end
44
+ add_index :ofac_sdns, :sdn_type
44
45
  end
45
46
  end
46
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kevintyll-ofac
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Tyll
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-12 00:00:00 -07:00
12
+ date: 2009-05-13 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15