From abfbc2ac31434babe9bb3f34751d268dd73142fb Mon Sep 17 00:00:00 2001 From: Adam Shannon Date: Tue, 14 Jan 2025 15:42:21 -0600 Subject: [PATCH] search: remove .Titles from root of Entity --- pkg/ofac/mapper.go | 3 +- pkg/ofac/mapper_business_test.go | 2 -- pkg/ofac/mapper_person_test.go | 7 ++--- pkg/search/model_searched_entity_test.go | 1 - pkg/search/models.go | 1 - pkg/search/models_test.go | 1 - pkg/search/similarity.go | 3 -- pkg/search/similarity_fuzzy.go | 8 ++--- pkg/search/similarity_fuzzy_test.go | 40 ++++++++++++++++++------ 9 files changed, 38 insertions(+), 28 deletions(-) diff --git a/pkg/ofac/mapper.go b/pkg/ofac/mapper.go index b779d082..9682d4e2 100644 --- a/pkg/ofac/mapper.go +++ b/pkg/ofac/mapper.go @@ -190,7 +190,6 @@ func ToEntity(sdn SDN, addresses []Address, comments []SDNComments, altIds []Alt out.Affiliations = affiliations out.SanctionsInfo = sanctionsInfo out.HistoricalInfo = historicalInfo - out.Titles = titles out.CryptoAddresses = parseCryptoAddresses(remarks) // Extract common fields regardless of entity type @@ -257,7 +256,7 @@ func ToEntity(sdn SDN, addresses []Address, comments []SDNComments, altIds []Alt if sdn.Title != "" { titles = append([]string{sdn.Title}, titles...) } - out.Titles = titles + out.Person.Titles = titles // Handle birth date out.Person.BirthDate = withFirstP(findMatchingRemarks(remarks, "DOB"), func(in remark) *time.Time { diff --git a/pkg/ofac/mapper_business_test.go b/pkg/ofac/mapper_business_test.go index e55a14a0..d2301475 100644 --- a/pkg/ofac/mapper_business_test.go +++ b/pkg/ofac/mapper_business_test.go @@ -78,7 +78,6 @@ func TestMapperBusiness__FromSource(t *testing.T) { require.Empty(t, found.Affiliations) require.Nil(t, found.SanctionsInfo) require.Empty(t, found.HistoricalInfo) - require.Empty(t, found.Titles) sdn, ok := found.SourceData.(ofac.SDN) require.True(t, ok) @@ -150,7 +149,6 @@ func TestMapperBusiness__FromSource(t *testing.T) { require.Nil(t, found.SanctionsInfo) require.Empty(t, found.HistoricalInfo) - require.Empty(t, found.Titles) sdn, ok := found.SourceData.(ofac.SDN) require.True(t, ok) diff --git a/pkg/ofac/mapper_person_test.go b/pkg/ofac/mapper_person_test.go index 9ffe83a6..06bb1427 100644 --- a/pkg/ofac/mapper_person_test.go +++ b/pkg/ofac/mapper_person_test.go @@ -81,7 +81,6 @@ func TestMapperPerson__FromSource(t *testing.T) { require.Empty(t, found.Affiliations) require.Nil(t, found.SanctionsInfo) require.Empty(t, found.HistoricalInfo) - require.Empty(t, found.Titles) sdn, ok := found.SourceData.(ofac.SDN) require.True(t, ok) @@ -194,7 +193,7 @@ func TestMapper__CompletePersonWithRemarks(t *testing.T) { require.Equal(t, "AL-ZAYDI, Muhammad", e.HistoricalInfo[0].Value) // Test titles - require.Equal(t, []string{"Commander"}, e.Titles) + require.Equal(t, []string{"Commander"}, e.Person.Titles) } func TestMapper__PersonWithTitle(t *testing.T) { @@ -211,6 +210,6 @@ func TestMapper__PersonWithTitle(t *testing.T) { require.Equal(t, search.EntityPerson, e.Type) // Should have both titles - from SDN field and remarks - require.Contains(t, e.Titles, "Chief Financial Officer") - require.Contains(t, e.Titles, "Regional Director") + require.Contains(t, e.Person.Titles, "Chief Financial Officer") + require.Contains(t, e.Person.Titles, "Regional Director") } diff --git a/pkg/search/model_searched_entity_test.go b/pkg/search/model_searched_entity_test.go index 4ec5fa1c..326552eb 100644 --- a/pkg/search/model_searched_entity_test.go +++ b/pkg/search/model_searched_entity_test.go @@ -44,7 +44,6 @@ func TestSearchedEntityJSON(t *testing.T) { "affiliations": null, "sanctionsInfo": null, "historicalInfo": null, - "titles": null, "sourceData": { "entityID": "12345" }, diff --git a/pkg/search/models.go b/pkg/search/models.go index 315e803f..73700296 100644 --- a/pkg/search/models.go +++ b/pkg/search/models.go @@ -32,7 +32,6 @@ type Entity[T Value] struct { Affiliations []Affiliation `json:"affiliations"` SanctionsInfo *SanctionsInfo `json:"sanctionsInfo"` HistoricalInfo []HistoricalInfo `json:"historicalInfo"` - Titles []string `json:"titles"` SourceData T `json:"sourceData"` // Contains all original list data with source list naming } diff --git a/pkg/search/models_test.go b/pkg/search/models_test.go index d9150a1f..6d226958 100644 --- a/pkg/search/models_test.go +++ b/pkg/search/models_test.go @@ -40,7 +40,6 @@ func TestEntityJSON(t *testing.T) { "affiliations": null, "sanctionsInfo": null, "historicalInfo": null, - "titles": null, "sourceData": { "entityID": "12345" } diff --git a/pkg/search/similarity.go b/pkg/search/similarity.go index 48c14975..936ecc10 100644 --- a/pkg/search/similarity.go +++ b/pkg/search/similarity.go @@ -328,9 +328,6 @@ func countCommonFields[I any](index Entity[I]) int { if len(index.Affiliations) > 0 { count++ } - if len(index.Titles) > 0 { - count++ - } if len(index.Addresses) > 0 { count++ } diff --git a/pkg/search/similarity_fuzzy.go b/pkg/search/similarity_fuzzy.go index 692620dd..d81151e3 100644 --- a/pkg/search/similarity_fuzzy.go +++ b/pkg/search/similarity_fuzzy.go @@ -250,13 +250,13 @@ var ( ) func compareEntityTitlesFuzzy[Q any, I any](w io.Writer, query Entity[Q], index Entity[I], weight float64) scorePiece { - if len(query.Titles) == 0 { + if query.Person == nil || index.Person == nil { return scorePiece{score: 0, weight: 0, fieldsCompared: 0, pieceType: "titles"} } // Prepare normalized index titles once - normalizedIndexTitles := make([]string, 0, len(index.Titles)) - for _, title := range index.Titles { + normalizedIndexTitles := make([]string, 0, len(index.Person.Titles)) + for _, title := range index.Person.Titles { if normalized := normalizeTitle(title); normalized != "" { normalizedIndexTitles = append(normalizedIndexTitles, normalized) } @@ -270,7 +270,7 @@ func compareEntityTitlesFuzzy[Q any, I any](w io.Writer, query Entity[Q], index matches := 0 total := 0 - for _, qTitle := range query.Titles { + for _, qTitle := range query.Person.Titles { normalizedQuery := normalizeTitle(qTitle) if normalizedQuery == "" { continue diff --git a/pkg/search/similarity_fuzzy_test.go b/pkg/search/similarity_fuzzy_test.go index 14bf4e41..25a45c61 100644 --- a/pkg/search/similarity_fuzzy_test.go +++ b/pkg/search/similarity_fuzzy_test.go @@ -183,10 +183,14 @@ func TestCompareEntityTitlesFuzzy(t *testing.T) { { name: "exact title match", query: Entity[any]{ - Titles: []string{"Chief Executive Officer"}, + Person: &Person{ + Titles: []string{"Chief Executive Officer"}, + }, }, index: Entity[any]{ - Titles: []string{"Chief Executive Officer"}, + Person: &Person{ + Titles: []string{"Chief Executive Officer"}, + }, }, expectedScore: 1.0, shouldMatch: true, @@ -195,10 +199,14 @@ func TestCompareEntityTitlesFuzzy(t *testing.T) { { name: "abbreviated title match", query: Entity[any]{ - Titles: []string{"CEO"}, + Person: &Person{ + Titles: []string{"CEO"}, + }, }, index: Entity[any]{ - Titles: []string{"Chief Executive Officer"}, + Person: &Person{ + Titles: []string{"Chief Executive Officer"}, + }, }, expectedScore: 0.0, // TODO(adam): needs fixed shouldMatch: false, @@ -207,10 +215,14 @@ func TestCompareEntityTitlesFuzzy(t *testing.T) { { name: "multiple titles with partial matches", query: Entity[any]{ - Titles: []string{"CEO", "Director of Operations"}, + Person: &Person{ + Titles: []string{"CEO", "Director of Operations"}, + }, }, index: Entity[any]{ - Titles: []string{"Chief Executive Officer", "Operations Director"}, + Person: &Person{ + Titles: []string{"Chief Executive Officer", "Operations Director"}, + }, }, expectedScore: 0.50, shouldMatch: false, @@ -219,10 +231,14 @@ func TestCompareEntityTitlesFuzzy(t *testing.T) { { name: "similar but not exact titles", query: Entity[any]{ - Titles: []string{"Senior Technical Manager"}, + Person: &Person{ + Titles: []string{"Senior Technical Manager"}, + }, }, index: Entity[any]{ - Titles: []string{"Technical Manager"}, + Person: &Person{ + Titles: []string{"Technical Manager"}, + }, }, expectedScore: 0.0, // TODO(adam): needs fixed shouldMatch: false, @@ -231,10 +247,14 @@ func TestCompareEntityTitlesFuzzy(t *testing.T) { { name: "no matching titles", query: Entity[any]{ - Titles: []string{"Chief Financial Officer"}, + Person: &Person{ + Titles: []string{"Chief Financial Officer"}, + }, }, index: Entity[any]{ - Titles: []string{"Sales Director", "Regional Manager"}, + Person: &Person{ + Titles: []string{"Sales Director", "Regional Manager"}, + }, }, expectedScore: 0.0, shouldMatch: false,