Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sparnatural config src could take an ontology string #552

Closed
PyHahiro opened this issue Jan 24, 2024 · 3 comments
Closed

Sparnatural config src could take an ontology string #552

PyHahiro opened this issue Jan 24, 2024 · 3 comments

Comments

@PyHahiro
Copy link

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
Copy link
Contributor

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

image

@PyHahiro
Copy link
Author

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
Copy link
Contributor

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants