3

When I start a Fuseki server, I use this command :

fuseki-server --config=config-orphadata.ttl

In this ttl file, I can writte some prefix rules :

@prefix orphanet: <http://www.orpha.net/ORDO/Orphanet_#> .
@prefix ORDO: <http://www.orpha.net/ORDO/> .

In SPARQL queries, I have to write all prefix values, like that :

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX obo: <http://purl.obolibrary.org/obo/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX oboInOwl: <http://www.geneontology.org/formats/oboInOwl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX Orphanet_: <http://www.orpha.net/ORDO/Orphanet_#>
PREFIX ORDO: <http://www.orpha.net/ORDO/>
select ?s ?p ?o ?m ?v ?e WHERE {
?s ?p ?o.
optional {?o ?m ?v. 
?v rdfs:label ?e}.
filter (?s = ORDO:Orphanet_2004)
}
ORDER BY ?o

If I do not write the prefixes, the query does not work... It seems that the rules prefix defined in the configuration file may not be available in queries.

All elements written in SPARQL query go to GET information URL.

Is it possible to reduce the string length of this query by putting prefix in config files to reuse it after launching my fuseki server ?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Matthieu
  • 221
  • 1
  • 11
  • This doesn't really address the question, but in SPARQL queries, the prefix syntax is, e.g., `prefix ex: `. What you're showing, `@prefix ex: .` is used in Turtle and N3. – Joshua Taylor Apr 09 '14 at 20:40
  • Yeah of course, i have edit my post to be precise. – Matthieu Apr 10 '14 at 11:20

1 Answers1

0

As far as I know, there is no support to do this directly.

Hacking a Generic Solution

I have yet to find a location where I can modify the prefixes used by ARQ while parsing queries, but that does not mean that it does not exist. My suggestion, if you wanted to pursue this, would be to dig around GrepCode until you find a place where you can replace a default factory / resolver, and then write the code that is used to do that into the static initializer of some custom class of yours. This could potentially be epic-dirty, so it may not be nearly worth it to you to do this.

Start Fuseki with your new class (org.ididhax.ChangePrefixes) on the classpath somewhere, and place [] ja:loadClass "org.ididhax.ChangePrefixes" within your Fuseki assembler file. This will cause Fuseki to load up your class, which will modify the available prefixes.

Web Workaround / Hack

If you are using Fuseki from the web interface, update the templates that Fuseki uses for the web forms in order to attach some set of default prefixes to any query that you submit. Then the SPARQL that Fuseki parses will be valid.

Java Workaround / Hack #1

This is a workaround I sometimes use. I construct 99% of my queries programmatically, anyway. What you do is build a PrefixMappingImpl and load it up with your favorite prefixes. Make some code that will take your desired SPARQL String and prepend it with those prefixes in the proper format. The rest of your code, then, doesn't care.

/* 'MyQueryFactory' hides the appending of your prefixes and the call to
 * the actual Jena 'QueryFactory'
 */
final String mySparqlString = "SELECT * WHERE { ?bob rdf:type vocab:Cat }";
final Query query = MyQueryFactory.create(mySparqlString);

Java Workaround / Hack #2

This is often my personal preference. If you have Jena Schemagen Java Class vocabularies for your terms, then don't use prefixes at all. Statically substitute in the fields from those vocabularies and construct the SPARQL using the exact terms. You'll never personally see a single URI, and it can be handy if you are potentially changing your vocabulary (can give you handy compilation errors wherever you are using a term that no longer exists). An example follows:

final Query query = QueryFactory.create(
  "SELECT * WHERE {\n"+
  " ?bob <"+RDF.type+"> <"+MyVocab.Cat+"> .\n"+
  "}");
Rob Hall
  • 2,693
  • 16
  • 22
  • If you front fuseki with apache httpd, you could do some sort of hackery with the URL in a proxypass. Something like `proxypass /foo /fuseki/blah/query=ENCODED_VERSION_OF_PREFIXES` – Dan Pritts Jun 14 '18 at 16:33