1

I just started working with Fuseki and Jena. I have an ontology and I want to allow HTTP clients to send SPARQL requests and get the result. Here is the code I have in order to achieve that:

        // testing Fuseki
        Dataset dataset = RDFDataMgr.loadDataset("src/main/resources/files/test.owl");

        FusekiEmbeddedServer server = FusekiEmbeddedServer.create()
                .setPort(3332)
                .add("/ds", dataset, true)
                .build() ;
        server.start() ;

The Fuseki web server is working fine and I can send queries and get their results using a web browser.
The problem is whenever I try to use a prefix defined in the .owl file I get an error. Basically here is a simple request I want to send: http://localhost:3332/ds?query=SELECT ?test WHERE {?test ssn:observes ?o}
At the moment I get this error:

Error 400: Parse error: 
SELECT ?test WHERE {?test ssn:observes ?o}

Line 1, column 27: Unresolved prefixed name: ssn:observes

I know for sure the ssn prefix does exist in the .owl file. Is there a way I can get this request to work, knowing that I don't have access to Fuseki configuration file as I'm only using it through Java?

UninformedUser
  • 8,397
  • 1
  • 14
  • 23
Yotm
  • 45
  • 4
  • A prefix in any serialization format doesn't necessarily mean that it is available in the SPARQL engine. Why can't you simply add the PREFIX declaration to the SPARQL query? – UninformedUser Jul 19 '17 at 17:51
  • Well I can, I just wanted to know if a feature existed to automatically resolve prefix when the server handle the request. It would have been better because the client would just need to know the prefix and not the full URI and define a prefix. – Yotm Jul 19 '17 at 19:06
  • 1
    Automatically resolve from the file I don't know - but you could add the prefixes in the Java code by `dataset.getDefaultModel().setNsPrefixes( prefix2NamespaceMap)` where `prefix2NamespaceMap` is a `Map` – UninformedUser Jul 20 '17 at 07:23
  • @AKSW your solution does work and allow the client to directly use prefixes. You can post it as an answer. – Yotm Jul 20 '17 at 14:46

0 Answers0