sparna-git / Sparnatural

Sparnatural : Typescript visual SPARQL query builder for knowledge graphs, configurable with SHACL
http://sparnatural.eu
GNU Lesser General Public License v3.0
206 stars 34 forks source link

Sparnatural config src could take an ontology string #552

Closed PyHahiro closed 4 months ago

PyHahiro commented 5 months ago

The official documentation https://docs.sparnatural.eu/Javascript-integration.html specifies the following :

src

Provides the configuration that specifies the classes and properties to be displayed, and how they are mapped to SPARQL. This can be 
either the URL of an OWL Turtle or RDF/XML file, or a URL to a JSON file. Example : sparnatural-config.ttl another option is to provide a 
serialized JSON obj as a string. For example: JSON.stringify(configAsJsonObj)

It would be nice to enable this config to directly take a string of an OWL Turtle or RDF/XML file content, such as we don't have to have a path/to/file but simply get a configuration from a whole ontology string

tfrancart commented 5 months ago

Although not documented, this is actually possible. See SparnaturalSpecificationFactory, line 14

image

PyHahiro commented 5 months ago

It in fact seems like my minified .js is going through the right builder, though I don't have the same result while getting the config as a ttl string or getting the config via an API call that gives me that same ttl

I tested with a simple ontology implemented one class and got the following error message :

Error: No value received on "classTypeValueSelected" Sparnatural version 8.6.0

Example log from the builder

Attempt to parse determining format from path https://sparnatural.eu../. [sparnatural.js:2:1743001](webpack://_N_E/node_modules/sparnatural/dist/sparnatural.js?4a1c)
Attempt to parse in Turtle... [sparnatural.js:2:1743109](webpack://_N_E/node_modules/sparnatural/dist/sparnatural.js?4a1c)
NodeShapes with at least one property [sparnatural.js:2:1769720](webpack://_N_E/node_modules/sparnatural/dist/sparnatural.js?4a1c)
Found languages in configuration :

Example ontology ttl string working from API but not from Direct insertion :

@prefix : <http://example.org/> .
    @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://example.org/> .

    <http://example.org/> rdf:type owl:Ontology .

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

    :hasBooks rdfs:subPropertyOf sparna:AutocompleteProperty ;
            rdfs:domain :Library ;
            rdfs:range :Book .

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

    ###  http://example.org/Book
    :Book rdf:type owl:Class ;
        rdfs:subClassOf sparna:SparnaturalClass .

    ###  http://example.org/Library
    :Library rdf:type owl:Class ;
             rdfs:subClassOf sparna:SparnaturalClass ;
             rdfs:subClassOf [ rdf:type owl:Restriction ;
                               owl:onProperty :has_books ;
                               owl:allValuesFrom [ rdf:type owl:Restriction ;
                                                   owl:onProperty :contains ;
                                                   owl:allValuesFrom :Book
                                                 ]
                             ] .
    `;
tfrancart commented 4 months ago

This is fixed. Passing the string was OK, but the config was always parsed as SHACL, and not OWL. Note that you should provide the config with a call to setAttribute:

      let configString=`
@prefix : <http://example.org/> .
...
    `;

sparnatural.setAttribute("src",configString);