Skip to content

Commit

Permalink
search: remove .Titles from root of Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Jan 14, 2025
1 parent e880004 commit abfbc2a
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 28 deletions.
3 changes: 1 addition & 2 deletions pkg/ofac/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions pkg/ofac/mapper_business_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions pkg/ofac/mapper_person_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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")
}
1 change: 0 additions & 1 deletion pkg/search/model_searched_entity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func TestSearchedEntityJSON(t *testing.T) {
"affiliations": null,
"sanctionsInfo": null,
"historicalInfo": null,
"titles": null,
"sourceData": {
"entityID": "12345"
},
Expand Down
1 change: 0 additions & 1 deletion pkg/search/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion pkg/search/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func TestEntityJSON(t *testing.T) {
"affiliations": null,
"sanctionsInfo": null,
"historicalInfo": null,
"titles": null,
"sourceData": {
"entityID": "12345"
}
Expand Down
3 changes: 0 additions & 3 deletions pkg/search/similarity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/search/similarity_fuzzy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand Down
40 changes: 30 additions & 10 deletions pkg/search/similarity_fuzzy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit abfbc2a

Please sign in to comment.