I have troubles figuring out how to represent the following query in dotnetrdf using fluent query. The SPARQL Query:
PREFIX a: <http://www.example.com/ex1#>
PREFIX rdf: < http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?object
WHERE {
a:Branch1 rdf:type ?object
FILTER(!STRSTARTS(STR(?object), "http://www.w3.org/2002/07/owl#"))
}
This is what I achieved so far, I couldn't figure the filter predicate.
var prefixes = new NamespaceMapper(true);
prefixes.AddNamespace("rdf", new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#"));
prefixes.AddNamespace("a", new Uri("http://www.example.com/ex1#"));
var objVar = "object";
var queryBuilder =
QueryBuilder
.Select(new string[] { objVar })
.Where(
(triplePatternBuilder) =>
{
triplePatternBuilder
.Subject(element)
.PredicateUri("rdf:type")
.Object(objVar);
})
.Filter(f =>
// What should be added here?
);
queryBuilder.Prefixes = prefixes;
Thanks,
Unfortunately the STRSTARTS
function hasn't been mapped to the fluent interface yet, but there is a way around that. You can build a regular ISparqlExpression
in the Filter action and wrap it in a new BooleanExpression
:
var queryBuilder =
QueryBuilder
.Select(new string[] { objVar })
.Where(
(triplePatternBuilder) =>
{
triplePatternBuilder
.Subject(element)
.PredicateUri("rdf:type")
.Object(objVar);
})
.Filter(f =>
new BooleanExpression(
new StrStartsFunction(
new StrFunction(new VariableTerm(objVar)),
f.Constant("http://www.w3.org/2002/07/owl#").Expression
))
);
NOTE: You may need to add VDS.RDF.Query.Builder.Expressions
and VDS.RDF.Nodes
to your imports for the above to compile.