Skip to content

Commit

Permalink
Removing unnecessary check statement.
Browse files Browse the repository at this point in the history
Simplifying filtering and sorting.
  • Loading branch information
Eng3lFT committed Jan 17, 2023
1 parent 56a7d05 commit 2adf62c
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions pkg/mapper/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,46 +95,46 @@ func (h *Handler) ToIndexModel(enrichedContent schema.EnrichedContent, contentTy

func (h *Handler) populatePrimaryTheme(model *schema.IndexModel, annotations []schema.Thing, ids map[string][]string, predicateKey string) {
predicate := h.Config.Predicates.Get(predicateKey)
sorted := filterSortAnnotations(annotations, ids, predicate)
if len(sorted) == 0 {
annotations = filterAnnotations(annotations, ids, predicate)
if len(annotations) == 0 {
return
}
annotation := sorted[0]

sort.Slice(annotations, func(i, j int) bool {
return annotations[i].PrefLabel < annotations[j].PrefLabel
})

annotation := annotations[0]
annIDs := ids[annotation.ID]
conceptTypes := h.Config.ConceptTypes

for _, taxonomy := range annotation.Types {
if annotation.Predicate == predicate {
tme := ""
switch taxonomy {
case conceptTypes.Get("organisation"):
tme = tmeOrganisations
case conceptTypes.Get("person"):
tme = tmePeople
case conceptTypes.Get("topic"):
tme = tmeTopics
case conceptTypes.Get("location"):
tme = tmeRegions
}
if tme != "" {
setPrimaryTheme(model, annotation.PrefLabel, getCmrIDWithFallback(tme, annIDs))
break
}
tme := ""
switch taxonomy {
case conceptTypes.Get("organisation"):
tme = tmeOrganisations
case conceptTypes.Get("person"):
tme = tmePeople
case conceptTypes.Get("topic"):
tme = tmeTopics
case conceptTypes.Get("location"):
tme = tmeRegions
}
if tme != "" {
setPrimaryTheme(model, annotation.PrefLabel, getCmrIDWithFallback(tme, annIDs))
break
}
}
}

func filterSortAnnotations(annotations []schema.Thing, ids map[string][]string, predicate string) []schema.Thing {
func filterAnnotations(annotations []schema.Thing, ids map[string][]string, predicate string) []schema.Thing {
var matchedAnnotations []schema.Thing

for _, annotation := range annotations {
if annotation.Predicate == predicate && ids[annotation.ID] != nil {
matchedAnnotations = append(matchedAnnotations, annotation)
}
}
sort.Slice(matchedAnnotations, func(i, j int) bool {
return matchedAnnotations[i].PrefLabel < matchedAnnotations[j].PrefLabel
})
return matchedAnnotations
}

Expand Down

0 comments on commit 2adf62c

Please sign in to comment.