Skip to content

Commit

Permalink
Fix issue with co-occurrences (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesu committed Oct 17, 2023
1 parent 3820408 commit e3d806e
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,25 @@ export class OccurrencesService {
const { schemes, links, database } = this

return result.map(({ freq, concept, voc, notation }) => {
// We can't override `otherScheme` here because if it's not given in the request,
// it will stay the same even if there are concepts of multiple schemes in the result set.
let targetScheme = otherScheme
if (concept) { // backend returns full JSKOS concept
if (!otherScheme) {
otherScheme = schemes.findByUri(concept.inScheme[0].uri)
if (!targetScheme) {
targetScheme = schemes.findByUri(concept.inScheme[0].uri)
}
notation = otherScheme.notationFromUri(concept.uri)
notation = targetScheme.notationFromUri(concept.uri)
} else { // backend returns voc and notation to build concept from
if (!otherScheme) {
otherScheme = schemes.findByVOC(voc)
if (!targetScheme) {
targetScheme = schemes.findByVOC(voc)
}
const uri = otherScheme?.uriFromNotation(notation)
const uri = targetScheme?.uriFromNotation(notation)
if (!uri) {
return null
}
concept = {
uri,
inScheme: [{ uri: otherScheme.uri }],
inScheme: [{ uri: targetScheme.uri }],
}
}

Expand All @@ -165,8 +168,8 @@ export class OccurrencesService {
modified,
count: parseInt(freq) || 0,
}
if (links.templateCoOccurrences && memberScheme.IKT && otherScheme?.IKT) {
entry.url = links.templateCoOccurrences.replace("{notation1}",encodeURI(notation)).replace("{notation2}",encodeURI(notation)).replace("{ikt1}", memberScheme.IKT).replace("{ikt2}", otherScheme.IKT)
if (links.templateCoOccurrences && memberScheme.IKT && targetScheme?.IKT) {
entry.url = links.templateCoOccurrences.replace("{notation1}", encodeURI(notation)).replace("{notation2}", encodeURI(notation)).replace("{ikt1}", memberScheme.IKT).replace("{ikt2}", targetScheme.IKT)
}
return entry
}).filter(Boolean)
Expand Down

0 comments on commit e3d806e

Please sign in to comment.