Skip to content

Commit

Permalink
Duplicate entries: Return analysis, but mark as invalid with null m…
Browse files Browse the repository at this point in the history
…ember
  • Loading branch information
stefandesu committed Dec 8, 2023
1 parent f09a032 commit e194e28
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,16 @@ function checkConcept(concept) {
return
}

// allow elements two appear twice (could be error) bot not more (is probably error)
// allow elements to appear twice (could be error) but not more (is probably error)
const count = {}
for(let i=0; i<memberList.length; i++) {
const id = memberList[i].notation.join(" = ")
for (const member of memberList.filter(Boolean)) {
const id = member.notation.join(" = ")
count[id] = count[id] || 0
if (count[id]++ >= 2) {
config.log(`Error: Unexpected duplicate ${id} in analysis of ${notation})`)
return
// Add `null` member to indicate an error in the analysis
if (!memberList.includes(null)) {
memberList.push(null)
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ export async function decomposeDDC(ddc, notation) {
}
}
const memberList = ((result && result.memberList) || []).map(concept => {
if (!concept) {
return concept
}
if (concept.uri) {
// Do not convert if URI already exists
return concept
Expand Down
6 changes: 6 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ export async function createServer(
// Check if it's necessary to swap some lines
// TODO: Verify and test this check.
for (let i = 1; i < memberList.length; i += 1) {
if (!memberList[i] || !memberList[i - 1]) {
continue
}
if (memberList[i].notation[1] === memberList[i - 1].notation[1] && memberList[i].notation[0].length > memberList[i - 1].notation[0].length) {
[memberList[i], memberList[i - 1]] = [memberList[i - 1], memberList[i]]
}
Expand All @@ -84,6 +87,9 @@ export async function createServer(
// Add broader fields to members
const member1 = memberList[i - 1]
const member2 = memberList[i]
if (!member1 || !member2) {
continue
}
if (isMemberParentOf(member1, member2)) {
member2.broader = [{ uri: member1.uri }]
} else {
Expand Down

0 comments on commit e194e28

Please sign in to comment.