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
24 stars 4 forks source link

Question: Form display when multiple class types accepted #4

Closed calummackervoy closed 1 year ago

calummackervoy commented 1 year ago

For an ontology for games characters, I've written a shape to accept a character which has a species of type mud:Species (for fictive species, e.g. Vampire), or using WikiData's Taxonomy class:

mudcharshapes:SpeciesProperty
    sh:path mud:species ;
    sh:name "Species" ;
    sh:description "A Character is not obliged to have a species" ;
    sh:maxCount 1 ;
    sh:class ( mud:Species wd:Q16521 ) .

Using this shape, I'm presented with a text-box which lets me submit string input. This will always be considered invalid, however, because the string isn't of type mud:Species or of Taxonomy

I'd like to be able to accept multiple class types for the field. I'm wondering if the automatic form could ask the user which form they would like to complete from a set of options. This could possibly be done based on the NodeShapes provided (as it is when there's only one value)

I think I could probably work around this client-side

s-tittel commented 1 year ago

Thanks for reporting and giving this library a try. A feature like this is on my list, but will take some time and probably will work a bit differently. According to https://www.w3.org/TR/shacl/#ClassConstraintComponent, the values of sh:class in a shape are IRIs, so I will go for supporting something like this:

mudcharshapes:SpeciesProperty
    sh:path mud:species ;
    sh:name "Species" ;
    sh:description "A Character is not obliged to have a species" ;
    sh:maxCount 1 ;
    sh:or (
        [ sh:class mud:Species ; ]
        [ sh:class wd:Q16521  ; ]
    ) .
s-tittel commented 1 year ago

This is now actually possible. Here's an exmaple of the form adapting to previous choices using sh:or:

@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix mud: <https://raw.githubusercontent.com/Multi-User-Domain/vocab/main/mud.ttl#> .
@prefix mudchar: <https://raw.githubusercontent.com/Multi-User-Domain/vocab/main/mudchar.ttl#> .
@prefix mudcharshapes: <https://raw.githubusercontent.com/Multi-User-Domain/vocab/main/shapes/core/mudchar.ttl#> .
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix wd: <http://www.wikidata.org/entity/> .

mudcharshapes:Character a sh:NodeShape ;
    sh:targetClass mudchar:Character ;
    sh:property mudcharshapes:SpeciesProperty .

mudcharshapes:SpeciesProperty
    sh:path mud:species ;
    sh:name "Species" ;
    sh:description "A Character is not obliged to have a species" ;
    sh:maxCount 1 ;
    sh:or ( [ sh:node mudcharshapes:Species ; rdfs:label "MUD Species" ;] [ sh:node mudcharshapes:Q16521 ; rdfs:label "Wikidata Species" ;] ).

mudcharshapes:Species a sh:NodeShape ;
    sh:targetClass mud:Species ;
    sh:property [
        sh:name "@id" ;
        sh:path <mud:id> ;
        sh:description "Enter the urlid of the desired species" ;
        sh:defaultValue "https://raw.githubusercontent.com/Multi-User-Domain/vocab/main/mud.ttl#Human" ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
    ] .

mudcharshapes:Q16521 a sh:NodeShape ;
    sh:targetClass wd:Q16521 ;
    sh:property [
        sh:name "Wikidata page" ;
        sh:path <mud:id> ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
    ] .