Skip to content

Commit

Permalink
Allow recursive blank node resolution for submission
Browse files Browse the repository at this point in the history
This has been a long time coming. In the end it needed a simple adjustment to
the utils/getSubjectTriples function to allow recursion. This was after much
time went into the design, with thoughts written in https://hub.datalad.org/datalink/annotate-trr379-demo/issues/45
  • Loading branch information
jsheunis committed Feb 14, 2025
1 parent 6878f85 commit 7974783
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/components/SubmitComp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
const submitDialog = inject('submitDialog')
const tokenExists = ref(false)
const nodeShapes = inject('nodeShapes')
const graphData = inject('graphData')
const ID_IRI = inject('ID_IRI')
const config = inject('config')
const allPrefixes = inject('allPrefixes');
Expand Down Expand Up @@ -88,7 +89,7 @@
setToken(tokenval.value)
}
awaitingResponse.value = true
var submit_result = await submitFormData(nodeShapes.value, ID_IRI.value, allPrefixes, config)
var submit_result = await submitFormData(nodeShapes.value, ID_IRI.value, allPrefixes, config, graphData)
console.log("submit_result")
console.log(submit_result)
Expand Down
25 changes: 18 additions & 7 deletions src/composables/formdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export function useFormData() {
}
}

async function submitFormData(nodeShapes, id_iri, prefixes, config) {
async function submitFormData(nodeShapes, id_iri, prefixes, config, graphData) {
console.log("inside submitFormData function")
console.log(toRaw(formData))
if (Object.keys(formData).length == 0) {
Expand All @@ -210,16 +210,12 @@ export function useFormData() {
return
}
const { token } = useToken();
// Send a POST to a service for every record in formData
// Some exploration:
// - we need to send a POST request for every NAMED NODE record,
// with blank nodes resolved

var headers = {}
if (token.value !== null && token.value !== "null") {
headers['X-DumpThings-Token'] = token.value;
}


try {
// collect all POST requests as Promises
let postPromises = [];
Expand All @@ -228,10 +224,25 @@ export function useFormData() {
// Get shapes for reference
var nodeShape = nodeShapes[class_uri]
var propertyShapes = nodeShape.properties
// if the nodeshape does NOT have a propertyshape with sh:path being equal to ID_IRI,
// it means the class's records will be blank nodes and we can skip the whole class
var ps = propertyShapes.find((prop) => prop[SHACL.path.value] == id_iri)
if(!ps) {
console.log(`Class '${class_uri}' shape does not have an id field, i.e. it will have blank node records, i.e. skipping.`)
continue;
}
for (var record_id of Object.keys(formData[class_uri])) {
console.log(`formData for node: ${record_id}`)
console.log(toRaw(formData[class_uri][record_id]))
// Turn the record/node into quads
//
var quads = formNodeToQuads(class_uri, record_id, nodeShapes, propertyShapes, id_iri, prefixes)
// Ne need to resolve blank nodes recursively, and add all to the dataset
quads.forEach(quad => {
if (quad.object.termType === "BlankNode") {
var moreQuads = getSubjectTriples(graphData, quad.object, true)
quads = quads.concat(Array.from(moreQuads))
}
});
// Create an rdf dataset per record
var ds = rdf.dataset()
quads.forEach(quad => {
Expand Down
4 changes: 0 additions & 4 deletions src/modules/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,3 @@ export async function postRDF(endpoint, dataset, format = 'text/turtle', headers
throw error;
}
}




13 changes: 11 additions & 2 deletions src/modules/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,22 @@ export function getLiteralAndNamedNodes(graphData, predicate, propertyClass, pre
}


export function getSubjectTriples(graphData, someTerm) {
export function getSubjectTriples(graphData, someTerm, blankNodesResolved=false) {
// console.log(`Getting all triples with subject: ${someTerm.value}`)
const quads = rdf.grapoi({ dataset: graphData, term: someTerm }).out().quads();
// Array.from(quads).forEach(quad => {
// console.log(`\t${quad.subject.value} - ${quad.predicate.value} - ${quad.object.value}`)
// })
return Array.from(quads)
var quadArray = Array.from(quads)
if (blankNodesResolved) {
quads.forEach(q => {
if (q.object.termType === "BlankNode") {
var moreQuads = getSubjectTriples(graphData, q, true)
quadArray = quadArray.concat(Array.from(moreQuads))
}
})
}
return quadArray
}


Expand Down

0 comments on commit 7974783

Please sign in to comment.