Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
caffix committed Feb 17, 2025
1 parent d244bf9 commit 9a83fa1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 26 deletions.
28 changes: 18 additions & 10 deletions engine/plugins/api/gleif/fuzzy.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func (fc *fuzzyCompletions) lookup(e *et.Event, orgent *dbt.Entity, since time.T
}

func (fc *fuzzyCompletions) query(e *et.Event, orgent *dbt.Entity) *dbt.Entity {
exclusive := true
var leiList []*general.Identifier

if leient := fc.plugin.orgEntityToLEI(e, orgent); leient != nil {
Expand Down Expand Up @@ -113,27 +112,36 @@ func (fc *fuzzyCompletions) query(e *et.Event, orgent *dbt.Entity) *dbt.Entity {
if err := json.Unmarshal([]byte(resp.Body), &result); err != nil || len(result.Data) == 0 {
return nil
}
exclusive = len(result.Data) == 1

var names []string
m := make(map[string]string)
for _, d := range result.Data {
if support.OrganizationNameMatch(e.Session, orgent, d.Attributes.Value) {
leiList = append(leiList, &general.Identifier{
UniqueID: fmt.Sprintf("%s:%s", general.LEICode, d.Relationships.LEIRecords.Data.ID),
EntityID: d.Relationships.LEIRecords.Data.ID,
Type: general.LEICode,
})
break
if d.Type == "fuzzycompletions" && d.Relationships.LEIRecords.Data.Type == "lei-records" {
names = append(names, d.Attributes.Value)
m[d.Attributes.Value] = d.Relationships.LEIRecords.Data.ID
}
}

for _, match := range support.OrganizationNameMatch(e.Session, orgent, names) {
lei := m[match]

leiList = append(leiList, &general.Identifier{
UniqueID: fmt.Sprintf("%s:%s", general.LEICode, lei),
EntityID: lei,
Type: general.LEICode,
})
}

if len(leiList) == 0 {
return nil
}
}

var rec *leiRecord
exclusive := len(leiList) == 1
for _, lei := range leiList {
r, err := fc.plugin.getLEIRecord(lei)
if err == nil && r != nil && (exclusive || fc.locMatch(e, orgent, rec)) {
if err == nil && r != nil && (exclusive || fc.locMatch(e, orgent, r)) {
rec = r
break
}
Expand Down
4 changes: 2 additions & 2 deletions engine/plugins/api/gleif/related.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ func (ro *relatedOrgs) lookup(e *et.Event, ident *dbt.Entity, since time.Time) [
}

var p *dbt.Entity
if edges, err := e.Session.Cache().OutgoingEdges(o, since, "parent"); err == nil {
if edges, err := e.Session.Cache().IncomingEdges(o, since, "subsidiary"); err == nil {
for _, edge := range edges {
if tags, err := e.Session.Cache().GetEdgeTags(edge, since, ro.plugin.source.Name); err != nil || len(tags) == 0 {
continue
}
if a, err := e.Session.Cache().FindEntityById(edge.ToEntity.ID); err == nil && a != nil {
if a, err := e.Session.Cache().FindEntityById(edge.FromEntity.ID); err == nil && a != nil {
if _, ok := a.Asset.(*org.Organization); ok {
p = a
break
Expand Down
43 changes: 29 additions & 14 deletions engine/plugins/support/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,16 @@ func orgDedupChecks(session et.Session, obj *dbt.Entity, o *org.Organization) *d
return nil
}

func OrganizationNameMatch(session et.Session, orgent *dbt.Entity, name string) bool {
if orgent == nil {
return false
func OrganizationNameMatch(session et.Session, orgent *dbt.Entity, names []string) []string {
var matches []string

if orgent == nil || len(names) == 0 {
return matches
}

o, ok := orgent.Asset.(*org.Organization)
if !ok {
return false
return matches
}

var orgNames []string
Expand Down Expand Up @@ -362,16 +364,26 @@ func OrganizationNameMatch(session et.Session, orgent *dbt.Entity, name string)
Mismatch: -0.5,
}

for _, n := range orgNames {
if strings.EqualFold(n, name) {
return true
for _, orgname := range orgNames {
var found bool

for _, name := range names {
if strings.EqualFold(orgname, name) {
found = true
matches = append(matches, name)
}
}
if strutil.Similarity(n, name, swg) >= 0.85 {
return true

if !found {
for _, name := range names {
if strutil.Similarity(orgname, name, swg) >= 0.85 {
matches = append(matches, name)
}
}
}
}

return false
return matches
}

func orgNameExistsInContactRecord(session et.Session, cr *dbt.Entity, name string) (*dbt.Entity, bool) {
Expand All @@ -382,7 +394,8 @@ func orgNameExistsInContactRecord(session et.Session, cr *dbt.Entity, name strin
if edges, err := session.Cache().OutgoingEdges(cr, time.Time{}, "organization"); err == nil && len(edges) > 0 {
for _, edge := range edges {
if a, err := session.Cache().FindEntityById(edge.ToEntity.ID); err == nil && a != nil {
if _, ok := a.Asset.(*org.Organization); ok && OrganizationNameMatch(session, a, name) {
if _, ok := a.Asset.(*org.Organization); ok &&
len(OrganizationNameMatch(session, a, []string{name})) > 0 {
return a, true
}
}
Expand All @@ -399,7 +412,8 @@ func orgNameRelatedToOrganization(session et.Session, orgent *dbt.Entity, name s
if edges, err := session.Cache().IncomingEdges(orgent, time.Time{}, "subsidiary"); err == nil && len(edges) > 0 {
for _, edge := range edges {
if a, err := session.Cache().FindEntityById(edge.FromEntity.ID); err == nil && a != nil {
if _, ok := a.Asset.(*org.Organization); ok && OrganizationNameMatch(session, a, name) {
if _, ok := a.Asset.(*org.Organization); ok &&
len(OrganizationNameMatch(session, a, []string{name})) > 0 {
return a, true
}
}
Expand All @@ -408,7 +422,8 @@ func orgNameRelatedToOrganization(session et.Session, orgent *dbt.Entity, name s
if edges, err := session.Cache().OutgoingEdges(orgent, time.Time{}, "subsidiary"); err == nil && len(edges) > 0 {
for _, edge := range edges {
if a, err := session.Cache().FindEntityById(edge.ToEntity.ID); err == nil && a != nil {
if _, ok := a.Asset.(*org.Organization); ok && OrganizationNameMatch(session, a, name) {
if _, ok := a.Asset.(*org.Organization); ok &&
len(OrganizationNameMatch(session, a, []string{name})) > 0 {
return a, true
}
}
Expand Down Expand Up @@ -458,7 +473,7 @@ func orgExistsAndSharesLocEntity(session et.Session, obj *dbt.Entity, o *org.Org
}

for _, orgent := range orgents {
if strings.EqualFold(orgent.Asset.(*org.Organization).Name, o.Name) {
if len(OrganizationNameMatch(session, orgent, []string{o.Name, o.LegalName})) > 0 {
return orgent, nil
}
}
Expand Down

0 comments on commit 9a83fa1

Please sign in to comment.