SPARQLPrefixResolver { public static String addMissingPrefixes(final String sparqlQuery) { PrefixMapping2 pmap = new TwoStagePrefixMapping(globalPrefixMapping); Query q1 = QueryFactory.create(); q1.setPrefixMapping(pmap); q1 = QueryFactory.parse(q1, sparqlQuery, null, null); q1.toString(); return q1.toString(); }  static PrefixMapping getGlobalPrefixMapping(); static String addMissingPrefixes(final String sparqlQuery);  }
@Test public void prefixResolverTest() { String prefixQuery = "SELECT DISTINCT ?uri WHERE { ?uri a dbo:Musical . ?uri dbo:musicBy <http: String realAnswer = "PREFIX dbo: <http: "PREFIX res: <http: "PREFIX rdf: <http: "\n" + "SELECT DISTINCT ?uri\n" + "WHERE\n" + " { ?uri rdf:type dbo:Musical ;\n" + " dbo:musicBy res:Elton_John\n" + " }\n"; String answer = SPARQLPrefixResolver.addMissingPrefixes(prefixQuery); Assert.assertTrue("Prefixes not correctly resolved.", realAnswer.equals(answer)); log.debug("Query with resolved Prefixes: \n" + answer); }