diff --git a/dev/dev.js b/dev/dev.js index 8b7000a..fa93e34 100644 --- a/dev/dev.js +++ b/dev/dev.js @@ -111,8 +111,8 @@ async function devExtractRequirementProfileMedatada() { // devRunSparqlSelectQueryOnRdfString() // devRunSparqlConstructQueryOnRdfString() -// devValidateAll() +devValidateAll() // devValidateOne() // devValidateOneStrings() // devValidateUserProfile() -devExtractRequirementProfileMedatada() +// devExtractRequirementProfileMedatada() diff --git a/package.json b/package.json index 6b63f50..223a1f2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.js b/src/index.js index a8be2ef..d3b9ab1 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,6 @@ import { addRdfStringToStore, + extractRequirementProfilesMetadataFromStore, printDatasetAsTurtle, printStoreAsTurtle, runSparqlAskQueryOnStore, @@ -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]) { @@ -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) { @@ -91,7 +99,8 @@ export async function validateOne(userProfile, requirementProfile, datafieldsStr result: ValidationResult.INELIGIBLE, violations: violations, missingUserInput: [], - inMemoryMaterializedTriples: [] + inMemoryMaterializedTriples: [], + metadata: rqMetadata } } @@ -186,7 +195,8 @@ export async function validateOne(userProfile, requirementProfile, datafieldsStr result: ValidationResult.UNDETERMINABLE, violations: [], missingUserInput: askUserForDataPoints, - inMemoryMaterializedTriples: [] + inMemoryMaterializedTriples: [], + metadata: rqMetadata } } @@ -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 } } diff --git a/src/utils.js b/src/utils.js index e2c13c9..4e75620 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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: SELECT * WHERE {