sparna-git / Sparnatural

Sparnatural : visual knowledge graph explorer with SPARQL, in the browser, configurable with SHACL
http://sparnatural.eu
GNU Lesser General Public License v3.0
225 stars 41 forks source link

Selecting a literal from a list does not format the sparql query correctly #539

Closed LucasRembert closed 9 months ago

LucasRembert commented 11 months ago

I use the following sparnatural configuration:

@prefix : <http://example.com/ontology/test#> .
@prefix test: <http://example.com/ontology/test#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sparna: <http://data.sparna.fr/ontologies/sparnatural-config-core#> .
@prefix ds: <http://data.sparna.fr/ontologies/sparnatural-config-datasources#> .

@base <http://data.sparna.fr/ontologies/sparnatural-demo-dbpedia> .

<http://data.sparna.fr/ontologies/sparnatural-demo-dbpedia> rdf:type owl:Ontology ;
                                                             owl:imports <http://data.sparna.fr/ontologies/sparnatural-config-core> ,
                                                                         <http://data.sparna.fr/ontologies/sparnatural-config-datasources> .

:Objet rdfs:subClassOf sparna:SparnaturalClass ;
        rdfs:subClassOf :Concept;
        sparna:defaultLabelProperty rdfs:label ;
        sparna:faIcon "fa fa-object-group" ;
        sparna:tooltip "un objet"@fr ;
        rdfs:label "Objet"@fr .

:Literal rdfs:subClassOf rdfs:Literal ;
      sparna:faIcon "fa fa-italic" ;
      sparna:tooltip "Un attribut qui caractérise l'objet, comme un nom ou une description. <br/><br/>Choisissez ceci pour sélectionner le nom de l'objet"@fr ;
      rdfs:label "Literal"@fr .

:aPourLiteral rdfs:subPropertyOf sparna:ListProperty ;
        rdfs:domain :Objet ;
        rdfs:range :Literal ;
        sparna:enableOptional "true"^^xsd:boolean ;
        sparna:enableNegation "true"^^xsd:boolean ;
        ds:datasource ds:list_URI_or_literal_alpha ;
        rdfs:label "a pour literal"@fr .

When it came to making my choice with sparnatural : Screenshot from 2023-12-01 14-20-22

The SPARQL query is formatted as follows:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?Objet_1 ?Objet_1_label ?Literal_2 WHERE {
  ?Objet_1 rdf:type <http://example.com/ontology/test#Objet>.
  ?Objet_1 rdfs:label ?Objet_1_label.
  ?Objet_1 <http://example.com/ontology/test#aPourLiteral> ?Literal_2.
  VALUES ?Literal_2 {
    "Literal1"@http://www.w3.org/2001/xmlschema#string
    "Literal2"@http://www.w3.org/2001/xmlschema#string
    "Literal3"@http://www.w3.org/2001/xmlschema#string
  }
}

This way, the query cannot be executed due to the incorrect formatting of the XSD:string uri (@http://www.w3.org/2001/xmlschema#string). Instead, the query should be :

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?Objet_1 ?Objet_1_label ?Literal_2 WHERE {
  ?Objet_1 rdf:type <http://example.com/ontology/test#Objet>.
  ?Objet_1 rdfs:label ?Objet_1_label.
  ?Objet_1 <http://example.com/ontology/test#aPourLiteral> ?Literal_2.
  VALUES ?Literal_2 {
    "Literal1"^^xsd:string
    "Literal2"^^xsd:string
    "Literal3"^^xsd:string
  }
}
tfrancart commented 11 months ago

This may come from your data: can you make an export of your data ? maybe the datatype was inserted as a language in your data. Can you also confirm the version of Sparnatural you are using ?

LucasRembert commented 11 months ago
Data: sub pred obj
http://example.com/ontology/test#Concept http://mytest.com/ontologies/common/annotation#hasAnnotation http-//example.com/ontology/test-Concept_9A9ZKFgUUK3PTfg1kc_dng
http://example.com/ontology/test#Concept http://mytest.com/ontologies/common/annotation#hasAnnotation http-//example.com/ontology/test-Concept_zi9F3o0PaMvPdCNrlhx7Kw
http://example.com/ontology/test#Concept http://www.w3.org/2000/01/rdf-schema#label Concept
http-//example.com/ontology/test-Concept_9A9ZKFgUUK3PTfg1kc_dng http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://mytest.com/ontologies/common/annotation#property
http-//example.com/ontology/test-Concept_9A9ZKFgUUK3PTfg1kc_dng http://mytest.com/ontologies/common/annotation#Arg0 http://www.w3.org/2000/01/rdf-schema#label
http-//example.com/ontology/test-Concept_9A9ZKFgUUK3PTfg1kc_dng http://mytest.com/ontologies/common/annotation#Arg1 Concept
http-//example.com/ontology/test-Concept_zi9F3o0PaMvPdCNrlhx7Kw http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://www.w3.org/2000/01/rdf-schema#label
http-//example.com/ontology/test-Concept_zi9F3o0PaMvPdCNrlhx7Kw http://mytest.com/ontologies/common/annotation#Arg0 Concept
http://example.com/ontology/test#Objet http://mytest.com/ontologies/common/annotation#hasAnnotation http-//example.com/ontology/test-Objet_EKtskELVGS1t2RylRuOETQ
http://example.com/ontology/test#Objet http://mytest.com/ontologies/common/annotation#hasAnnotation http-//example.com/ontology/test-Objet_yvJvfQU5z1k3ay_qa3mk9Q
http://example.com/ontology/test#Objet http://mytest.com/ontologies/common/annotation#hasAnnotation http-//example.com/ontology/test-Objet_bl3oIdgK4By31w-lb7Ub8Q
http://example.com/ontology/test#Objet http://mytest.com/ontologies/common/annotation#hasAnnotation http-//example.com/ontology/test-Objet_zMkFmPMnnxSvO63AkuZ2vA
http://example.com/ontology/test#Objet http://www.w3.org/2000/01/rdf-schema#label Objet
http://example.com/ontology/test#Objet http://www.w3.org/2000/01/rdf-schema#comment Ceci est un objet
http-//example.com/ontology/test-Objet_EKtskELVGS1t2RylRuOETQ http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://mytest.com/ontologies/common/annotation#property
http-//example.com/ontology/test-Objet_EKtskELVGS1t2RylRuOETQ http://mytest.com/ontologies/common/annotation#Arg0 http://www.w3.org/2000/01/rdf-schema#label
http-//example.com/ontology/test-Objet_EKtskELVGS1t2RylRuOETQ http://mytest.com/ontologies/common/annotation#Arg1 Objet
http-//example.com/ontology/test-Objet_yvJvfQU5z1k3ay_qa3mk9Q http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://mytest.com/ontologies/common/annotation#property
http-//example.com/ontology/test-Objet_yvJvfQU5z1k3ay_qa3mk9Q http://mytest.com/ontologies/common/annotation#Arg0 http://www.w3.org/2000/01/rdf-schema#comment
http-//example.com/ontology/test-Objet_yvJvfQU5z1k3ay_qa3mk9Q http://mytest.com/ontologies/common/annotation#Arg1 Ceci est un objet
http-//example.com/ontology/test-Objet_bl3oIdgK4By31w-lb7Ub8Q http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://www.w3.org/2000/01/rdf-schema#label
http-//example.com/ontology/test-Objet_bl3oIdgK4By31w-lb7Ub8Q http://mytest.com/ontologies/common/annotation#Arg0 Objet
http-//example.com/ontology/test-Objet_zMkFmPMnnxSvO63AkuZ2vA http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://www.w3.org/2000/01/rdf-schema#comment
http-//example.com/ontology/test-Objet_zMkFmPMnnxSvO63AkuZ2vA http://mytest.com/ontologies/common/annotation#Arg0 Ceci est un objet
http://example.com/ontology/test#aPourLiteral http://www.w3.org/2000/01/rdf-schema#label literal
http://example.com/ontology/test#objet_un http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://example.com/ontology/test#Objet
http://example.com/ontology/test#objet_un http://www.w3.org/2000/01/rdf-schema#label Objet un
http://example.com/ontology/test#objet_un http://example.com/ontology/test#aPourLiteral Literal1
http://example.com/ontology/test#objet_un http://example.com/ontology/test#aPourLiteral Literal2
http://example.com/ontology/test#objet_un http://example.com/ontology/test#aPourLiteral Literal3
http://example.com/ontology/test#objet_un http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://example.com/ontology/test#Concept

I use sparnatural version 8.4.0

tfrancart commented 11 months ago

This is not precise enough wrt to the language and datatypes of literals. Can you please provide a ttl or RDF/XML file ?

PyHahiro commented 9 months ago

I run into the same issue with the following .ttl

@prefix ma: <http://anabasis-assets.com/ontologies/modelisationLycee/Matiere#> .
@prefix pr: <http://anabasis-assets.com/ontologies/modelisationLycee/Professeur#> .
@prefix ly: <http://anabasis-assets.com/ontologies/modelisationLycee/Lyceen> .
@prefix lycee: <http://anabasis-assets.com/ontologies/lycee#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . 
@prefix sparna: <http://data.sparna.fr/ontologies/sparnatural-config-core#> .
@prefix ds: <http://data.sparna.fr/ontologies/sparnatural-config-datasources#> .

#################################################################
#    Classes
#################################################################

pr:Professeur rdfs:subClassOf sparna:SparnaturalClass ;
    sparna:defaultLabelProperty rdfs:label ;
    sparna:faIcon "fa fa-person-chalkboard" ;
    sparna:tooltip "un professeur"@fr ;
    rdfs:label "Professeur"@fr .

ma:Matiere rdfs:subClassOf sparna:SparnaturalClass ;
    sparna:defaultLabelProperty rdfs:label ;
    sparna:faIcon "fa fa-book" ;
    sparna:tooltip "une matiere"@fr ;
    rdfs:label "Matiere"@fr .

ly:Lyceen rdfs:subClassOf sparna:SparnaturalClass ;
    sparna:defaultLabelProperty rdfs:label ;
    sparna:faIcon "fa fa-person" ;
    sparna:tooltip "un Lycéen"@fr ;
    rdfs:label "Lycéen"@fr .

###  http://ontologies.sparna.fr/sparnatural-demo-dbpedia#Text
lycee:Text rdf:type owl:Class ;
      rdfs:subClassOf rdfs:Literal ;
      sparna:faIcon "fa-solid fa-font" ;
      sparna:tooltip "An attribute, a property that describes the object, like a name or a description. <br/><br/>Use this to select the name of the object."@en ,
                                                                         "Un attribut qui caractérise l'objet, comme un nom ou une description. <br/><br/>Choisissez ceci pour sélectionner le nom de l'objet"@fr ;
      rdfs:label "Text"@en ,
                 "Texte"@fr .

#################################################################
#    Object Properties
#################################################################

# specialise: Professeur
pr:specialise rdfs:subPropertyOf sparna:AutocompleteProperty ;
        rdfs:domain pr:Professeur ;
        rdfs:range ma:Matiere ;
        sparna:enableOptional "false"^^xsd:boolean ;
        sparna:enableNegation "false"^^xsd:boolean ;
        ds:datasource ds:literal_list_alpha ;
        rdfs:label "se spécialise dans"@fr ,
                "specialize himself in"@en .

# enseigne: Professeur
pr:enseigne rdfs:subPropertyOf sparna:ListProperty ;
        rdfs:domain pr:Professeur ;
        rdfs:range ly:Lyceen ;
        sparna:enableOptional "false"^^xsd:boolean ;
        sparna:enableNegation "false"^^xsd:boolean ;
        ds:datasource ds:search_rdfslabel_contains ;
        rdfs:label "enseigne à l'élève"@fr ,
                "teach student"@en .

# nom du prof
pr:nom rdfs:subPropertyOf sparna:AutocompleteProperty ;
        rdfs:domain pr:Professeur ;
        rdfs:range lycee:Text ;
        sparna:enableOptional "true"^^xsd:boolean ;
        sparna:enableNegation "true"^^xsd:boolean ;
        rdfs:label "a comme nom"@fr ,
                "has name"@en .

It seems like having an AutocompleteProperty with rdfs:range a Literal uses the : ds:datasource ds:search_literal_contains ; which does the right search and returns the following data list :

image

But when I click on a result, for example, Livaitom, I get the following sparql query :

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?Professeur_1 ?Professeur_1_label WHERE {
  ?Professeur_1 rdf:type <http://anabasis-assets.com/ontologies/modelisationLycee/Professeur#Professeur>.
  ?Professeur_1 rdfs:label ?Professeur_1_label.
  ?Professeur_1 <http://anabasis-assets.com/ontologies/modelisationLycee/Professeur#nom> "Livaitom"@xsd:string.
}

As you can see "Livaitom" is transformed into "Livaitom"@xsd:string

I expect literal to be transform the following way : ?literal^^?datatype and not ?literal@?datatype

In most similar example, you are not using autocompleteProperty but SearchProperty, and it works but it doesn't achieve the same need, for example, if I use SearchProperty and click on a result, for example, Livaitom, I get the following sparql query :

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?Professeur_1 ?Professeur_1_label WHERE {
  ?Professeur_1 rdf:type <http://anabasis-assets.com/ontologies/modelisationLycee/Professeur#Professeur>.
  ?Professeur_1 rdfs:label ?Professeur_1_label.
  ?Professeur_1 <http://anabasis-assets.com/ontologies/modelisationLycee/Professeur#nom> ?Text_2.
  FILTER(REGEX(STR(?Text_2), "tom", "i"))
}

Both widgets have different purposes so I expect them to work differently, but I think this highlight where may the issue comes from to help your debugging the issue (if that is one)

I would also add that we should add the xsd prefix in the sparql query if it not already in yet

tfrancart commented 9 months ago

This is fixed. Let me know if it works for you if you can test on the latest master branch. Otherwise you need to wait for the next release. Thanks