ULB-Darmstadt / shacl-form

HTML5 web component for editing/viewing RDF data that conform to SHACL shapes
https://ulb-darmstadt.github.io/shacl-form/
MIT License
28 stars 5 forks source link

<shacl-form> Component doesn't auto populate data-values with RDF Data in certain formats #27

Closed dmap1514 closed 1 week ago

dmap1514 commented 2 weeks ago

When trying to autopopulate data-values for the editor, I noticed that data-values are not automatically entered if the data-shapes follow a specific format, such as:

<http://example.org/PersonShape> <http://www.w3.org/ns/shacl#property> _:bc_0_n3-0 .
<http://example.org/PersonShape> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/shacl#NodeShape> .
_:bc_0_n3-0 <http://www.w3.org/ns/shacl#path> <http://xmlns.com/foaf/0.1/forname> .

or

<http://example.org/PersonShape> <http://www.w3.org/ns/shacl#property> <http://example.org/shacl/Property0>;
a <http://www.w3.org/ns/shacl#NodeShape>.
<http://example.org/shacl/Property0> <http://www.w3.org/ns/shacl#path> <http://xmlns.com/foaf/0.1/forname>.

Result without data-values-subject: image

Result with data-values-subject: image

However, it works, when using a format, such as:

@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix ex: <http://example.org/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

ex:PersonShape a sh:NodeShape ;
  sh:targetClass foaf:Person ;

  sh:property [
    sh:path foaf:forname ;
  ] .

Result without data-values-subject: image

Result with data-values-subject: image

shacl-form element of the above:

<shacl-form 
      data-values-subject="http://example.org/Natanael"
      data-shapes='@prefix foaf: <http://xmlns.com/foaf/0.1/> .
      @prefix ex: <http://example.org/> .
      @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
      @prefix sh: <http://www.w3.org/ns/shacl#> .
      @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

      ex:PersonShape a sh:NodeShape ;
        sh:targetClass foaf:Person ;

        sh:property [
          sh:path foaf:forname ;
        ] .
    '      
    data-values="
    <http://example.org/Natanael> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> <http://example.org/> .
    <http://example.org/Natanael> <http://xmlns.com/foaf/0.1/forname> 'Natanael' <http://example.org/> .
    "
></shacl-form>

Is it possible to fix this error, without changing the data-shapes format?

s-tittel commented 1 week ago

Hi and thanks for the feedback. When binding a data graph to the form, <shacl-form> only has some basic logic to determine the shacl shape to use for the values, one of which is using sh:targetClass. In your case, the triple

<http://example.org/Natanael> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person>

results in using ex:PersonShape, because of its corresponding sh:targetClass definition. When this triple is missing (I guess this is the case in your first example), shacl-form doesn't know what shacl shape the data conforms to.

BTW, you can always manually set the shacl shape on the HTML element like so:

<shacl-form data-shape-subject="http://example.org/PersonShape" ...></shacl-form>
dmap1514 commented 1 week ago

Thank you very much, that helped!