Question

I am trying to model a SPARQL query with the SparqlQuery class.

It looks like I can use the RootGraphPattern property property to specify the triple patterns to adhere to in the results to my query.

Unfortunately, I have so far failed to create an instance of the SparqlQuery class, as its constructors are not publicly accessible and the class is sealed. Likewise, the query type can only be retrieved, but not set. Is there any factory method with an obscure name that creates instances of that class?

Forum postings, just as the documentation on the topic exclusively generate their SparqlQuery instances based on query strings with the SparqlQueryParser class. However, I don't have a query string yet, and I'm trying to avoid concatenating strings to build my query when there's an object-oriented API available that lets me construct my query in an OO way rather than starting out with a string.

Hence, my question is: How can I instantiate the SparqlQuery class without using an initial query string and a SPARQL parser?

Was it helpful?

Solution

Right now you can't, most of SparqlQuery is intentionally sealed because a lot of the properties and related classes like GraphPattern represent the AST and when we originally designed the class we didn't want people to intentionally/accidentally modify the AST in ways that created broken queries.

There is a fluent-query branch in the works which will eventually provide a Fluent API for building queries but the developer behind that is currently on a month long vacation and I haven't seen any activity on it for a while. You can take a look at the Fluent Query wiki for some examples of what this API is going to look like.

If this is an important feature to you we can push this up the priorities but as an open source project we are heavily constrained by the limited resources of our small developer team.

We could likely integrate what we have so far into our 1.0.0 release but our recent release focus has been on bug fixes and stability to make the 1.0.0 a stable production ready release, introducing a new and relatively untested feature goes somewhat against this. Also the API does not yet cover all of SPARQL so would be incomplete and potentially unstable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top