Hi Greg,
query.getValuesVariables() applies specifically to the case of a
trailing VALUES block.
SELECT *
WHERE {}
VALUES ?var { ... }
(I'll add some javadoc)
To get an inner VALUES block which can be anywhere in the graph pattern,
the code has to walk the query or to walk into the WHERE pattern looking
for the specific case of interest. Here, it is the fist syntax element
in the ElementGroup which is the query pattern. (query.getQueryPattern().
Andy
On 07/11/2018 18:26, Greg Albiston wrote:
Hello,
I'm trying to retrieve the VALUES variable names of a Query parsed from
a string.
When I run the below test the result is false when I was expecting true.
The query is from the SPARQL 1.1 standard.
Can the VALUES variable names be retrieved from another method?
Apologies if I've missed something,
Greg
@Test
public void testValues_block() {
System.out.println("values_block");
String queryString = "PREFIX dc:
<http://purl.org/dc/elements/1.1/> \n"
+ "PREFIX : <http://example.org/book/> \n"
+ "PREFIX ns: <http://example.org/ns#> \n"
+ "\n"
+ "SELECT ?book ?title ?price\n"
+ "{\n"
+ " VALUES ?book { :book1 :book3 }\n"
+ " ?book dc:title ?title ;\n"
+ " ns:price ?price .\n"
+ "}";
Query query = QueryFactory.create(queryString);
boolean result = query.hasValues();
boolean expResult = true;
System.out.println(query.toString());
System.out.println("Vars: " + query.getValuesVariables());
System.out.println("Exp: " + expResult);
System.out.println("Res: " + result);
assertEquals(expResult, result);
}