I am using Jena to query an owl file through Eclipse. I want to do some successive queries and every new query will use the results of the previous query. I want to do it in different ?SELECT and save every time the result of a query in order to use it again in a new query. I dont want to insert the values of the variables by myself but automatically occur from the queries. Any ideas whats a suitable way to achieve this? Thanks in advance
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
I think that there are two primary options here:
initialBindings
argument for the QueryExecution, and the values of the variables in the QuerySolution will be used in the second query. This probably only works for local queries (since some the values in the ResultSet could be blank nodes whose values wouldn't make sense in a remote context), and it's only useful if you have a single QuerySolution of interest.b. The single QuerySolution could also be used to set some values in a ParameterizedSparqlString. In this case, the values are substituted in before you create the actual Query or QueryExecution object, and you could do some other manipulation if you needed as well. You might not be able to reliably run remote queries if some of the results are blank nodes, but you will be able to use this approach with remote endpoints, which you can't do with the
initialBindings
approach.The more general solution uses SPARQL 1.1's VALUES to provide the content of the ResultSet in a VALUES block. This is more portable, because any endpoint should be able to handle the VALUES block, and it's more general, because it can handle a bunch of bindings, not just one.
Here's the output that's generated. In the first case, the fact that Alice's address gets selected shows that the value of
?alice
carried from the first ResultSet to theinitialBindings
. In the second case, I've printed the query before and after adding the VALUES clause so that the difference is clear. Note that this will work even if the ResultSet binds multiple variables. The syntax in the case of multiple variables would beVALUES (?v1 ... ?vN) { (value11 ... value1N) ... (valueM1 ... valueMN) }
.may work for you.
refer: http://www.w3.org/TR/sparql11-query/