Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Search recursively to attach entry to correct subject
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminaaron committed May 21, 2024
1 parent 888e2c3 commit edf96f1
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ <h3>Report</h3>
}
}

for (let key of Object.keys(missingData)) {
let datafield = missingData[key]
for (let datafield of Object.values(missingData)) {

let usedInRpUris = datafield.usedIn.map(usedInRP => usedInRP.rpUri)
if (focusRPs.length > 0 && !usedInRpUris.some(rpUri => focusRPs.includes(rpUri))) {
Expand All @@ -233,6 +232,7 @@ <h3>Report</h3>
if (usedInRP.isLastMissingUserInput) lastMissingCounter += 1
}
prioritizedList.push({
subject: datafield.subject,
dfUri: datafield.dfUri,
objectHasClass: metadata.df[datafield.dfUri]?.objectHasClass,
label: metadata.df[datafield.dfUri]?.label ?? datafield.dfUri.split("#")[1],
Expand All @@ -241,7 +241,7 @@ <h3>Report</h3>
})
}
prioritizedList.sort((a, b) => b.score - a.score)
prioritizedList.forEach((entry) => {
prioritizedList.forEach((entry) => { // entry = wrapped datafield
let spanEl = document.createElement("span")
spanEl.title = entry.usedInTitles.join("\n")
spanEl.style.color = "gray"
Expand All @@ -256,14 +256,14 @@ <h3>Report</h3>
if (entry.objectHasClass) {
if (confirm("Do you want to add a " + metadata.df[entry.objectHasClass].label + "?")) {
console.log("Adding an object class instantiation for " + entry.dfUri)
await addProfileEntry(entry.dfUri, [{}])
// await addProfileEntry(entry.dfUri, [{}])
}
return
}
let input = prompt("What is your value for: " + entry.label)
if (input !== null) {
console.log(entry.dfUri, "-->", input)
await addProfileEntry(entry.dfUri, input)
console.log(entry.subject, entry.dfUri, "-->", input)
await addProfileEntry(entry.subject, entry.dfUri, input)
}
})
div.appendChild(a)
Expand All @@ -274,18 +274,35 @@ <h3>Report</h3>
}
}

async function addProfileEntry(dfUri, value) {
let key = "ff:" + dfUri.split("#")[1]
let result = await MatchingEngine.validateSingleDatafieldValue({ [key]: value }, turtleMap.datafields)
function searchSubjectNodeRecursively(node, sKey, action) {
for (let objectOrArray of Object.values(node)) {
if (objectOrArray === sKey) {
action(node)
break
}
if (Array.isArray(objectOrArray)) {
for (let arrayEl of objectOrArray) {
searchSubjectNodeRecursively(arrayEl, sKey, action)
}
}
}
}

async function addProfileEntry(subject, dfUri, value) {
let sKey = "ff:" + subject.split("#")[1]
let pKey = "ff:" + dfUri.split("#")[1]
searchSubjectNodeRecursively(userProfile, sKey, (node) => {
node[pKey] = value
})
/*let result = await MatchingEngine.validateSingleDatafieldValue({ [pKey]: value }, turtleMap.datafields)
if (!result.conforms) {
let msgs = "\n"
for (let violation of result.violations) {
msgs += violation.message + "\n"
}
alert(value + " is an invalid input for " + metadata.df[dfUri].label + ": " + msgs)
return
}
userProfile[key] = value
}*/
console.log("userProfile", userProfile)
localStorage.setItem("userProfile", JSON.stringify(userProfile))
await update()
Expand Down

0 comments on commit edf96f1

Please sign in to comment.