If you just want to restrict a variable to a specific value for local queries, you can do this by overloading the QueryFactory.create() method, which takes a QuerySolutionMap value to set value limits. Please note that this does not change your query, it simply limits the final results, so this is not really a parameterization.
If you really want to have true parameterized queries (i.e. replace variables for constants), there are several ways to do this depending on your version of ARQ.
Using any current version (up to 2.9.0), the only way to do this is to concatenate strings, i.e. instead of having? name in your query, you simply enter the desired value, for example. "Bean"
Using the last trunk (hereinafter 2.9.1-SNAPSHOT), a new ParameterizedSparqlString class has appeared, which makes it much more user-friendly, for example.
ParameterizedSparqlString queryStr = new ParameterizedSparqlString(comNameQuery); queryStr.setLiteral("name", "Bob"); Query query = QueryFactory.create(queryStr.toString());
And in fact, you can simplify your code, as ParameterizedSparqlString has a StringBuffer style interface and can be used to build a query in stages and includes useful functions, such as prefixes of prefixes to your query.
The advantage of this new method is that it provides a more general way to execute parameterized queries, which can also be used with updates, and can be used to prepare remote queries that existing methods do not cover.
Robv
source share