@@ -262,22 +262,20 @@ public void test235Issue()
262262
263263 @ Test
264264 public void testDistanceFunction ()
265- throws Exception
265+ throws Exception
266266 {
267267 String queryStr = "prefix geo: <" + GEO .NAMESPACE + ">" + "prefix geof: <" + GEOF .NAMESPACE + ">"
268268 + "prefix search: <" + LuceneSailSchema .NAMESPACE + ">"
269269 + "select ?toUri ?fromUri ?dist where {(?from ?range ?units geo:asWKT search:distance)"
270270 + "search:withinDistance (?toUri ?to ?dist) ."
271271 + "?toUri a <urn:geo/Landmark>. ?fromUri geo:asWKT ?from; <urn:geo/maxDistance> ?range.}" ;
272- try
273- {
272+ try {
274273 connection .begin ();
275274 TupleQuery query = connection .prepareTupleQuery (QueryLanguage .SPARQL , queryStr );
276275 query .setBinding ("units" , GEOF .UOM_METRE );
277-
276+
278277 printTupleResult (query );
279- try (TupleQueryResult result = query .evaluate ())
280- {
278+ try (TupleQueryResult result = query .evaluate ()) {
281279 int count = countTupleResults (result );
282280 Assert .assertThat (count , is (2 ));
283281 }
@@ -291,6 +289,42 @@ public void testDistanceFunction()
291289 }
292290 }
293291
292+ /**
293+ * Complex query: <code>
294+ *
295+ * </code>
296+ *
297+ * @throws Exception
298+ */
299+ @ Test
300+ public void complexQuery ()
301+ throws Exception
302+ {
303+ StringBuilder sb = new StringBuilder ();
304+ sb .append ("prefix t: <urn:test.org/onto#> \n " );
305+ sb .append ("prefix kw: <urn:test.org/key-words/> \n \n " );
306+ sb .append ("select ?term_string ?sub ?score where { \n " );
307+ sb .append (" ?pred_map rdfs:label \" keyWord\" ; \n " );
308+ sb .append (" t:column ?pred . \n " );
309+ sb .append (" [] ?pred ?term . \n " );
310+ sb .append (" bind(str(?term) as ?term_string) . \n " );
311+ sb .append (
312+ " (?term_string <" + ALL_MATCHES + "> <" + SCORE + ">) <" + SEARCH + "> (?sub ?score) . \n " );
313+ sb .append (" ?sub a t:Data ." );
314+ sb .append ("}" );
315+
316+ log .debug ("SPARQL query:\n =======\n {}\n =======\n " , sb .toString ());
317+
318+ TupleQuery query = connection .prepareTupleQuery (sb .toString ());
319+ try {
320+ printTupleResult (query );
321+ }
322+ catch (Exception e ) {
323+ e .printStackTrace ();
324+ throw new RuntimeException (e );
325+ }
326+ }
327+
294328 public int countStatements (RepositoryConnection con )
295329 throws Exception
296330 {
@@ -317,7 +351,9 @@ protected void printGraphResult(GraphQuery query) {
317351 log .info ("\n =============\n " + new String (resultoutput .toByteArray ()) + "\n =============" );
318352 }
319353
320- protected void printTupleResult (TupleQuery query ) {
354+ protected void printTupleResult (TupleQuery query )
355+ throws Exception
356+ {
321357 ByteArrayOutputStream resultoutput = new ByteArrayOutputStream ();
322358 query .evaluate (new SPARQLResultsCSVWriter (resultoutput ));
323359 log .info ("tuple result:" );
0 commit comments