1
1
import {
2
- addRdfStringToStore ,
3
- extractRequirementProfilesMetadataFromStore ,
2
+ addRdfStringToStore , extractRpUriFromRpString ,
4
3
printDatasetAsTurtle ,
5
4
printStoreAsTurtle ,
6
5
runSparqlAskQueryOnStore ,
@@ -40,31 +39,24 @@ export async function validateUserProfile(userProfile, datafieldsStr, debug = fa
40
39
export async function validateAll ( userProfileStr , requirementProfiles , datafieldsStr , materializationStr , debug = false ) {
41
40
let map = {
42
41
reports : [ ] ,
43
- missingUserInputsAggregated : { } ,
44
- metadata : { }
42
+ missingUserInputsAggregated : { }
45
43
}
46
44
for ( let [ filename , reqProfileStr ] of Object . entries ( requirementProfiles ) ) {
45
+ let rpUri = await extractRpUriFromRpString ( reqProfileStr )
47
46
let report = await validateOne ( userProfileStr , reqProfileStr , datafieldsStr , materializationStr , debug )
47
+ report . rpUri = rpUri
48
48
map . reports . push ( report )
49
- map . metadata = { ...map . metadata , ...report . metadata }
50
- let rpId = Object . keys ( report . metadata ) [ 0 ]
51
- report . metadata = {
52
- ...report . metadata [ rpId ] ,
53
- id : rpId ,
54
- filename : filename
55
- }
56
49
for ( let userInput of report . missingUserInput ) {
57
- let key = userInput . subject + "_" + userInput . predicate
50
+ let key = userInput . subject + "_" + userInput . dfUri
58
51
if ( ! map . missingUserInputsAggregated [ key ] ) {
59
52
map . missingUserInputsAggregated [ key ] = {
60
53
subject : userInput . subject ,
61
- predicate : userInput . predicate ,
62
- label : userInput . label ,
54
+ dfUri : userInput . dfUri ,
63
55
usedIn : [ ]
64
56
}
65
57
}
66
58
map . missingUserInputsAggregated [ key ] . usedIn . push ( {
67
- id : rpId ,
59
+ rpUri : rpUri ,
68
60
optional : userInput . optional ,
69
61
isLastMissingUserInput : report . missingUserInput . length === 1
70
62
} )
@@ -82,9 +74,6 @@ export async function validateOne(userProfile, requirementProfile, datafieldsStr
82
74
await addRdfStringToStore ( materializationStr , store )
83
75
await addRdfStringToStore ( datafieldsStr , store )
84
76
85
- // ----- extract metadata from the requirement profile -----`
86
- let rpMetadata = await extractRequirementProfilesMetadataFromStore ( store )
87
-
88
77
// ----- first validation to identify missing data points -----
89
78
let firstReport = await runValidationOnStore ( store )
90
79
if ( debug ) {
@@ -100,8 +89,7 @@ export async function validateOne(userProfile, requirementProfile, datafieldsStr
100
89
result : ValidationResult . INELIGIBLE ,
101
90
violations : violations ,
102
91
missingUserInput : [ ] ,
103
- inMemoryMaterializedTriples : [ ] ,
104
- metadata : rpMetadata
92
+ inMemoryMaterializedTriples : [ ]
105
93
}
106
94
}
107
95
@@ -114,7 +102,7 @@ export async function validateOne(userProfile, requirementProfile, datafieldsStr
114
102
let message = result . message [ 0 ] . value // can the arrays be bigger than 1?
115
103
missingList . push ( {
116
104
subject : fromSubject ,
117
- predicate : missingPredicate ,
105
+ dfUri : missingPredicate , // predicate
118
106
optional : message . toLowerCase ( ) . includes ( "[optional]" ) // a better way to check for this?
119
107
} )
120
108
}
@@ -130,7 +118,7 @@ export async function validateOne(userProfile, requirementProfile, datafieldsStr
130
118
PREFIX ff: <https://foerderfunke.org/default#>
131
119
SELECT * WHERE {
132
120
?rule ff:output ?output .
133
- FILTER(?output = <${ missing . predicate } >) .
121
+ FILTER(?output = <${ missing . dfUri } >) .
134
122
?rule ff:sparqlConstructQuery ?query .
135
123
OPTIONAL { ?rule ff:input ?input . }
136
124
}
@@ -155,7 +143,7 @@ export async function validateOne(userProfile, requirementProfile, datafieldsStr
155
143
let existingMainPersonPredicates = result . map ( n => n . predicate )
156
144
157
145
for ( let missing of missingList ) {
158
- let matchingRule = materializableDataPoints . find ( n => n . output === missing . predicate )
146
+ let matchingRule = materializableDataPoints . find ( n => n . output === missing . dfUri )
159
147
let otherRuleWithThatInputAsOutput = undefined
160
148
if ( matchingRule && matchingRule . input ) {
161
149
otherRuleWithThatInputAsOutput = materializableDataPoints . find ( n => n . output === matchingRule . input )
@@ -166,22 +154,6 @@ export async function validateOne(userProfile, requirementProfile, datafieldsStr
166
154
askUserForDataPoints . push ( missing )
167
155
}
168
156
169
- // ----- enrich the ones we'll ask for with labels -----
170
- // should we send more along than then the label?
171
- for ( let dataPoint of askUserForDataPoints ) {
172
- let query = `
173
- PREFIX ff: <https://foerderfunke.org/default#>
174
- PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
175
- SELECT * WHERE {
176
- ?predicate a ff:DataField .
177
- FILTER(?predicate = <${ dataPoint . predicate } >) .
178
- ?predicate rdfs:label ?label .
179
- }
180
- `
181
- let resultLine = ( await runSparqlSelectQueryOnStore ( query , store ) ) [ 0 ]
182
- if ( resultLine ) dataPoint . label = resultLine . label
183
- }
184
-
185
157
let optionals = askUserForDataPoints . filter ( missing => missing . optional )
186
158
let blockers = askUserForDataPoints . filter ( missing => ! missing . optional )
187
159
@@ -196,8 +168,7 @@ export async function validateOne(userProfile, requirementProfile, datafieldsStr
196
168
result : ValidationResult . UNDETERMINABLE ,
197
169
violations : [ ] ,
198
170
missingUserInput : askUserForDataPoints ,
199
- inMemoryMaterializedTriples : [ ] ,
200
- metadata : rpMetadata
171
+ inMemoryMaterializedTriples : [ ]
201
172
}
202
173
}
203
174
@@ -241,7 +212,7 @@ export async function validateOne(userProfile, requirementProfile, datafieldsStr
241
212
?shape a sh:NodeShape .
242
213
FILTER(?shape = ff:MainPersonShape) .
243
214
?shape sh:property ?propertyShape .
244
- ?propertyShape sh:path <${ optional . predicate } > .
215
+ ?propertyShape sh:path <${ optional . dfUri } > .
245
216
?propertyShape ?pred ?obj .
246
217
}
247
218
` // can this query be simplified?
@@ -275,8 +246,7 @@ export async function validateOne(userProfile, requirementProfile, datafieldsStr
275
246
result : secondReport . conforms ? ValidationResult . ELIGIBLE : ValidationResult . INELIGIBLE ,
276
247
violations : collectViolations ( secondReport , false ) ,
277
248
missingUserInput : askUserForDataPoints ,
278
- inMemoryMaterializedTriples : materializedTriples ,
279
- metadata : rpMetadata
249
+ inMemoryMaterializedTriples : materializedTriples
280
250
}
281
251
}
282
252
0 commit comments