Skip to content

Commit

Permalink
Include req profile metadata in return value
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminaaron committed May 3, 2024
1 parent 900f24c commit 2aa8782
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
4 changes: 2 additions & 2 deletions dev/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ async function devExtractRequirementProfileMedatada() {

// devRunSparqlSelectQueryOnRdfString()
// devRunSparqlConstructQueryOnRdfString()
// devValidateAll()
devValidateAll()
// devValidateOne()
// devValidateOneStrings()
// devValidateUserProfile()
devExtractRequirementProfileMedatada()
// devExtractRequirementProfileMedatada()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@foerderfunke/matching-engine",
"version": "0.3.7",
"version": "0.3.8",
"description": "Checks eligibilities by validating a user profile against requirement profiles",
"author": "@foerderfunke",
"license": "MIT",
Expand Down
27 changes: 19 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
addRdfStringToStore,
extractRequirementProfilesMetadataFromStore,
printDatasetAsTurtle,
printStoreAsTurtle,
runSparqlAskQueryOnStore,
Expand Down Expand Up @@ -39,15 +40,19 @@ export async function validateUserProfile(userProfile, datafieldsStr, debug = fa
export async function validateAll(userProfileStr, requirementProfiles, datafieldsStr, materializationStr, debug = false) {
let map = {
reports: [],
missingUserInputsAggregated: {}
missingUserInputsAggregated: {},
metadata: {}
}
for (let [filename, reqProfileStr] of Object.entries(requirementProfiles)) {
let report = await validateOne(userProfileStr, reqProfileStr, datafieldsStr, materializationStr, debug)
report.filename = filename
let regex = /ff:title\s+"([^"]+)"/; // use grapoi instead?
let match = reqProfileStr.match(regex)
if (match) report.title = match[1]
map.reports.push(report)
map.metadata = { ...map.metadata, ...report.metadata }
let rqId = Object.keys(report.metadata)[0]
report.metadata = {
...report.metadata[rqId],
id: rqId,
filename: filename
}
for (let userInput of report.missingUserInput) {
let key = userInput.subject + "_" + userInput.predicate
if (!map.missingUserInputsAggregated[key]) {
Expand Down Expand Up @@ -76,6 +81,9 @@ export async function validateOne(userProfile, requirementProfile, datafieldsStr
await addRdfStringToStore(materializationStr, store)
await addRdfStringToStore(datafieldsStr, store)

// ----- extract metadata from the requirement profile -----`
let rqMetadata = await extractRequirementProfilesMetadataFromStore(store)

// ----- first validation to identify missing data points -----
let firstReport = await runValidationOnStore(store)
if (debug) {
Expand All @@ -91,7 +99,8 @@ export async function validateOne(userProfile, requirementProfile, datafieldsStr
result: ValidationResult.INELIGIBLE,
violations: violations,
missingUserInput: [],
inMemoryMaterializedTriples: []
inMemoryMaterializedTriples: [],
metadata: rqMetadata
}
}

Expand Down Expand Up @@ -186,7 +195,8 @@ export async function validateOne(userProfile, requirementProfile, datafieldsStr
result: ValidationResult.UNDETERMINABLE,
violations: [],
missingUserInput: askUserForDataPoints,
inMemoryMaterializedTriples: []
inMemoryMaterializedTriples: [],
metadata: rqMetadata
}
}

Expand Down Expand Up @@ -264,7 +274,8 @@ export async function validateOne(userProfile, requirementProfile, datafieldsStr
result: secondReport.conforms ? ValidationResult.ELIGIBLE : ValidationResult.INELIGIBLE,
violations: collectViolations(secondReport, false),
missingUserInput: askUserForDataPoints,
inMemoryMaterializedTriples: materializedTriples
inMemoryMaterializedTriples: materializedTriples,
metadata: rqMetadata
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ export async function runSparqlDeleteQueryOnStore(query, store) {

export async function extractRequirementProfilesMetadata(shaclFileContents) {
let store = await rdfStringsToStore(shaclFileContents)
return await extractRequirementProfilesMetadataFromStore(store)
}

export async function extractRequirementProfilesMetadataFromStore(store) {
let query = `
PREFIX ff: <https://foerderfunke.org/default#>
SELECT * WHERE {
Expand Down

0 comments on commit 2aa8782

Please sign in to comment.