Skip to content

Commit

Permalink
search: strip "-" from GovernmentIDs for similarity
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Jan 16, 2025
1 parent 8b061bd commit 22b54ed
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
14 changes: 14 additions & 0 deletions pkg/ofac/mapper_business_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ func TestMapperBusiness__FromSource(t *testing.T) {
require.Equal(t, expectedContact, found.Contact)
})

t.Run("44525", func(t *testing.T) {
found := ofactest.FindEntity(t, "44525")
require.Equal(t, "BEL-KAP-STEEL LLC", found.Name)

t.Logf("%#v", found.Business)

expectedGovernmentIDs := []search.GovernmentID{
{Type: "tax-id", Country: "United States", Identifier: "52-2083095"},
{Type: "business-registration", Country: "Connecticut", Identifier: "0582030"},
{Type: "business-registration", Country: "Florida", Identifier: "M99000000961"},
}
require.ElementsMatch(t, expectedGovernmentIDs, found.Business.GovernmentIDs)
})

t.Run("50544", func(t *testing.T) {
found := ofactest.FindEntity(t, "50544")

Expand Down
10 changes: 7 additions & 3 deletions pkg/search/similarity_exact.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func compareExactIdentifiers[Q any, I any](w io.Writer, query Entity[Q], index E
}
}

func normalizeIdentifier(id string) string {
return strings.ReplaceAll(id, "-", "")
}

// comparePersonExactIDs checks exact matches for Person-specific identifiers
func comparePersonExactIDs(w io.Writer, query *Person, index *Person, weight float64) scorePiece {
if query == nil || index == nil {
Expand All @@ -57,7 +61,7 @@ func comparePersonExactIDs(w io.Writer, query *Person, index *Person, weight flo
for _, iID := range index.GovernmentIDs {
if strings.EqualFold(string(qID.Type), string(iID.Type)) &&
strings.EqualFold(qID.Country, iID.Country) &&
strings.EqualFold(qID.Identifier, iID.Identifier) {
strings.EqualFold(normalizeIdentifier(qID.Identifier), normalizeIdentifier(iID.Identifier)) {
score += 15.0
hasMatch = true
goto GovIDDone // Break both loops on first match
Expand Down Expand Up @@ -103,7 +107,7 @@ func compareBusinessExactIDs(w io.Writer, query *Business, index *Business, weig
// Exact match on all identifier fields
if strings.EqualFold(string(qID.Type), string(iID.Type)) &&
strings.EqualFold(qID.Country, iID.Country) &&
strings.EqualFold(qID.Identifier, iID.Identifier) {
strings.EqualFold(normalizeIdentifier(qID.Identifier), normalizeIdentifier(iID.Identifier)) {
score += 15.0
hasMatch = true
goto IdentifierDone
Expand Down Expand Up @@ -149,7 +153,7 @@ func compareOrgExactIDs(w io.Writer, query *Organization, index *Organization, w
// Exact match on all identifier fields
if strings.EqualFold(string(qID.Type), string(iID.Type)) &&
strings.EqualFold(qID.Country, iID.Country) &&
strings.EqualFold(qID.Identifier, iID.Identifier) {
strings.EqualFold(normalizeIdentifier(qID.Identifier), normalizeIdentifier(iID.Identifier)) {
score += 15.0
hasMatch = true
goto IdentifierDone
Expand Down
43 changes: 43 additions & 0 deletions pkg/search/similarity_exact_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package search

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
)

func TestCompareBusinessExactIDs(t *testing.T) {
cases := []struct {
query, index Business
expected scorePiece
}{
{
query: Business{
GovernmentIDs: []GovernmentID{
{Type: GovernmentIDTax, Country: "United States", Identifier: "522083095"},
},
},
index: Business{
GovernmentIDs: []GovernmentID{
{Type: GovernmentIDTax, Country: "United States", Identifier: "52-2083095"},
},
},
expected: scorePiece{
score: 1.0,
weight: 50,
matched: true,
required: true,
exact: true,
fieldsCompared: 1,
pieceType: "identifiers",
},
},
}
for _, tc := range cases {
t.Run(fmt.Sprintf("%#v", tc.query.GovernmentIDs), func(t *testing.T) {
got := compareBusinessExactIDs(nil, &tc.query, &tc.index, criticalIdWeight)
require.Equal(t, tc.expected, got)
})
}
}

0 comments on commit 22b54ed

Please sign in to comment.