sparna-git / Sparnatural

Sparnatural : visual SPARQL query builder for knowledge graphs in the browser, configurable with SHACL
http://sparnatural.eu
GNU Lesser General Public License v3.0
219 stars 41 forks source link

Making use of Data Properties #486

Closed prashydee closed 1 year ago

prashydee commented 1 year ago

Hi @tfrancart,

In my knowledge graph I also have saved actual data about individual entities as data properties with datatypes, e.g. the dog "Rufus" makes a "sound" "Woof", where "Woof" is a literal and not an IRI.

How can this be configured in the config file? I couldn't find the right solution so far. Is this supported?

Cheers, Prashant

prashydee commented 1 year ago

prash-pets.zip

I attach the zip file again for your reference, where you will see the data properties in pets_graph.ttl

Thank you!

prashydee commented 1 year ago

Apologies, I just realized now how it can be achieved by making the domain of my data property a named rdfs:Literal subclass in the config file.

tfrancart commented 1 year ago

.. and use a LiteralListWidget instead of just a ListWidget.

Also, this is something I am currently working on : that the lists widgets and autocomplete widgets work seamlessly with URIs as well as Literals. It would simply be a question of what the datasource selects (either URIs or Literals) but the UI widget and SPARQL generation logic would remain completely the same;

estathop commented 1 year ago

can you please elaborate how someone could make such a configuration to search for a datatype property ? Can you provide a concrete example please ? Is it possible through xls 2 rdf converter from sparna ?

this is an example of how I have defined all datatype Properties in my ontology:

chr:anger rdf:type owl:DatatypeProperty ; rdfs:domain chr:Score ; rdfs:range xsd:decimal .

chr:attire rdf:type owl:DatatypeProperty ; rdfs:domain chr:Dance ; rdfs:range xsd:string .

chr:beatValue rdf:type owl:DatatypeProperty ; rdfs:domain chr:RhythmicInstruction ; rdfs:range xsd:string .

chr:beatsPerMinute rdf:type owl:DatatypeProperty ; rdfs:domain chr:RhythmicInstruction ; rdfs:range xsd:integer .

chr:Dance rdf:type owl:Class . chr:RhythmicInstruction rdf:type owl:Class . chr:Score rdf:type owl:Class .

estathop commented 1 year ago

@tfrancart

tfrancart commented 1 year ago
  1. Create a owl:Class and make it rdfs:subClassOf rdfs:Literal image
  2. Define an ObjectProperty subPropertyOf one of the property types that are useful for literals, like TimeProperty-Date for dates, SearchProperty to express a regex search, or AutocompleteProperty that can work with literals. Yes, this is an ObjectProperty, not a DatatypeProperty. Use the URI of your DatatypeProperty, or another URI that you then remap to your property URI using the sparqlString annotation.
  3. Use the class you have defined as subClassOf literal as the range of the property
  4. Have a look at how things are configured in the config file at https://github.com/sparna-git/sparnatural.eu/blob/main/demos/demo-dbpedia-v2/sparnatural-config.ttl for e.g. :birthDate or :description
estathop commented 1 year ago

@tfrancart can you give an example how the RDF triples should look like taking into consideration the initial RDF triples I provided above ?

estathop commented 1 year ago

is this correct RDF ? Why is it not displaying in the demo UI?

this:Anger a owl:Class; rdfs:subClassOf rdfs:Literal; rdfs:label "anger score"@en; core:faIcon "fa-duotone fa-input-text"; core:tooltip "Represents the anger score of a particular Score instance"@en; core:order "1"^^xsd:integer .

this:hasAnger a owl:ObjectProperty; rdfs:label "has anger"@en; rdfs:subPropertyOf core:SearchProperty; rdfs:range this:anger; core:sparqlString "< https://chromata-project.gr/anger >"; core:enableOptional "true"^^xsd:boolean .

tfrancart commented 1 year ago

because you are missing an rdfs:domain