I've set up some namespaces in virtuoso, but when I used jena to do sparql queries in virtuoso, some namespaces were not abbreviated:
- @prefix sio: http://semanticscience.org/resource/SIO_ .
- @prefix cheminf: http://semanticscience.org/resource/CHEMINF_ .
- @prefix snomedct: http://purl.bioontology.org/ontology/SNOMEDCT/ .
What I want to do: SPARQL queries automatically read namespaces for abbreviations, rather than collecting all namespaces locally.
Do jena and virtuoso support this?
I know a way to do this, but it requires collecting all namespaces locally:
- SPARQL query
- Create map stores namespaces and abbreviations locally
- Replace uri's prefix with abbreviations from map
Information for reference
Virtuoso version 07.20.3235 (64e6ecd39) on Win64 (x86_64-generic-win-64) Single Server Edition
Data:
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix sio: <http://semanticscience.org/resource/SIO_> .
@prefix cheminf: <http://semanticscience.org/resource/CHEMINF_> .
@prefix snomedct: <http://purl.bioontology.org/ontology/SNOMEDCT/> .
@prefix example: <http://example.org/resource/> .
example:7732-18-5 rdf:type snomedct:101782006 .
example:7732-18-5 sio:SIO_000008 example:Descriptor_water_boiling_point_15039 .
example:Descriptor_water_boiling_point_15039 rdf:type sio:CHEMINF_000257 .
Jena code & SPARQL:
RDFConnection conn = RDFConnectionRemote.service("http://localhost:8890/sparql").build();
Model model = conn.queryConstruct("CONSTRUCT { ?s ?p ?o . } WHERE { ?s ?p ?o . FILTER ( ?s = <http://example.org/resource/7732-18-5> ) }");
// SPARQL Result
model.write(System.out, "ttl");
// model.listNameSpaces
Iterator iterator = model.listNameSpaces();
while (iterator.hasNext()) {
System.out.println(iterator.next().toString());
}
SPARQL Result:
@prefix example: <http://example.org/resource/> .
@prefix ns1: <http://semanticscience.org/resource/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
example:7732-18-5 rdf:type <http://purl.bioontology.org/ontology/SNOMEDCT/101782006> ;
ns1:SIO_SIO_000008 example:Descriptor_water_boiling_point_15039 .
(Jena)model.listNameSpaces:
http://www.w3.org/1999/02/22-rdf-syntax-ns#
http://purl.bioontology.org/ontology/SNOMEDCT/101782006
http://semanticscience.org/resource/
Best regards