Skip to content

Commit

Permalink
Fix shacl-form
Browse files Browse the repository at this point in the history
Form is working now
Add "data-values-subject" as an missing argument
  • Loading branch information
splattater committed Nov 14, 2024
1 parent ea8ad32 commit 613ec1c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
13 changes: 12 additions & 1 deletion src/helpers/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function getShapeQuery4Target (targetClassIri) {
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
CONSTRUCT {
?node_s ?node_p ?node_o ;
sh:targetClass <${targetClassIri}> ;
a sh:NodeShape .
?prop_s ?prop_p ?prop_o .
?prop_s sh:in ?list .
Expand Down Expand Up @@ -52,6 +53,7 @@ function getShapeQuery4Instance (instanceIri) {
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
CONSTRUCT {
?node_s ?node_p ?node_o ;
sh:targetClass ?class ;
a sh:NodeShape .
?prop_s ?prop_p ?prop_o .
#?node_s ?p ?o .
Expand Down Expand Up @@ -81,6 +83,15 @@ function getShapeQuery4Instance (instanceIri) {
}`
}

function getResourceQuery (resourceIri) {
return `
CONSTRUCT {
<${resourceIri}> ?p ?o .
} WHERE {
<${resourceIri}> ?p ?o .
}`
}

function injectDefaultGraph(query, defaultGraph) {
console.log(query)
let altQuery = "select distinct ?instance from <http://default.com/> { ?instance a <http://example.org/Resource> } order by ?instance"
Expand All @@ -102,4 +113,4 @@ function injectDefaultGraph(query, defaultGraph) {
return query
}

export { getShapeQuery4Target, getShapeQuery4Instance, injectDefaultGraph }
export { getShapeQuery4Target, getShapeQuery4Instance, getResourceQuery, injectDefaultGraph }
27 changes: 21 additions & 6 deletions src/views/FormDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SHACL shapes can be defined on the attribute 'data-shapes'
or can be loaded by setting attribute 'data-shapes-url'
-->
<shacl-form @change="getFormTurtle" ref="myform" data-submit-button data-generate-node-shape-reference data-show-node-ids v-bind:data-values="dataTurtle" v-bind:data-shapes="shapeTurtle"></shacl-form>
<shacl-form @change="getFormTurtle" ref="myform" data-submit-button data-generate-node-shape-reference data-show-node-ids v-bind:data-values="dataTurtle" v-bind:data-shapes="shapeTurtle" v-bind:data-values-subject="dataSubject"></shacl-form>
</div>
</pane>
<pane size="30">
Expand All @@ -31,7 +31,7 @@ import { useRdfStore } from '../stores/rdf'
import { useSelectionStore } from '../stores/selection'
import { Store, StreamParser, Parser, Writer } from 'n3'
import { registerPlugin } from '@ulb-darmstadt/shacl-form'
import { getShapeQuery4Target, getShapeQuery4Instance } from '../helpers/queries'
import { getShapeQuery4Target, getShapeQuery4Instance, getResourceQuery } from '../helpers/queries'
import { defaultShape, defaultData } from '../helpers/rdf-data'
import { quadStreamToString } from '../helpers/rdf-parse'
import { streamToStore } from 'rdf-dereference-store';
Expand Down Expand Up @@ -69,6 +69,7 @@ export default {
return {
dataModel: {},
dataTurtle: defaultData,
dataSubject: "",
shapeTurtle: defaultShape,
subject: rdf.namedNode(''),
}
Expand Down Expand Up @@ -96,25 +97,36 @@ export default {
async getResource () {
this.subject = rdf.namedNode(this.resource_iri)
const resourceData = await this.store.getResource(this.resource_iri)
const originalData = (await streamToStore(resourceData)).store
const originalData = (await quadStreamToStore(resourceData)).store
return await quadStreamToString(originalData.match(), { format: 'application/n-triples', prefixes: this.prefixes_flat })
},
async getInstance () {
var result = await this.store.sendQuery({query: await getResourceQuery(this.resource_iri)})
if (result.resultType === 'quads') {
const quadStream = await result.execute()
var instanceData = await quadStream.toArray()
}
var instance_string = await this.serialize(instanceData, { format: 'application/n-triples', prefixes: this.prefixes })
return instance_string.replaceAll("\"", "'")
},
async getFormData () {
console.log('Form: Get form data')
let shapeData = []
let result = ""
let dataSubject = ""
if (this.is_class) {
result = await this.store.sendQuery({query: await getShapeQuery4Target(this.resource_iri)})
} else {
result = await this.store.sendQuery({query: await getShapeQuery4Instance(this.resource_iri)})
dataSubject = this.resource_iri
}
if (result.resultType === 'quads') {
const quadStream = await result.execute()
shapeData = await quadStream.toArray()
}
let shapeTurtle = ""
let shapeTurtle = ""
let dataTurtle = ""
if (shapeData.length < 1) {
Expand All @@ -125,7 +137,7 @@ export default {
let data_string = ""
if (this.is_class == false) {
let instance_data = await this.getResource()
let instance_data = await this.getInstance()
dataTurtle = instance_data.replaceAll("\"", "'")
}
Expand All @@ -137,7 +149,10 @@ export default {
console.log(shapeTurtle)
console.log('Form: Instance as n-triples')
console.log(dataTurtle)
console.log('Form: dataSubject')
console.log(dataSubject)
this.shapeTurtle = shapeTurtle
this.dataSubject = dataSubject
this.dataTurtle = dataTurtle
},
selectResource (resourceIri) {
Expand All @@ -160,4 +175,4 @@ export default {
}
}
</script>
</script>

0 comments on commit 613ec1c

Please sign in to comment.