mdesalvo / RDFSharp

Lightweight and friendly .NET library for realizing Semantic Web applications
Apache License 2.0
118 stars 26 forks source link

[ENHANCEMENT] More support for unary operators when constructing queries #339

Open DarthStem opened 1 week ago

DarthStem commented 1 week ago

I have need to craft queries using unary operators other than Inverse; specifically the + operator.

This need is two fold.

First, using RDFPropertyPathStep, only Inverse is supported.

.AddPropertyPath(new RDFPropertyPath(varUri, varId) .AddAlternativeSteps(new List { new RDFPropertyPathStep(new RDFResource("brick:hasPart")), << Needs + new RDFPropertyPathStep(new RDFResource("brick:isPartOf")),).Inverse() << Needs + })) Desired SPARQL: ?VARURI (https://brickschema.org/schema/Brick#hasPart+|^https://brickschema.org/schema/Brick#isPartOf+) ?VARID .

Second, there is no apparent way to insert unary operators when constructing filters

patternGroup.AddFilter(new RDFNotExistsFilter(new RDFPattern( varType, RDFVocabulary.RDFS.SUB_CLASS_OF, << Needs + "brick:Wing")));

Desired SPARQL: FILTER ( NOT EXISTS { ?VARTYPE http://www.w3.org/2000/01/rdf-schema#subClassOf+ https://brickschema.org/schema/Brick#Wing } )

mdesalvo commented 5 days ago

Requires an algebra for traversal of graphs and generic path evaluation, which we dont have currently. We support property paths by transforming them in a finite and deterministic sequence of equivalent patterns (accepting sequential, alternative, inverse syntaxes). Support for non-deterministic paths (unary operators like "+", "*" and "?" which are all variants of "{MIN,MAX}" operator) is an epic for a major v4 release of the library.

Sorry to not have a workaround to propose for this. If you deal with ontologies I suggest you to try OWLSharp, which is our project specifically suited for working at OWL level: it integrates reasoning in many forms, like rdfs:subClassOf subsumption or owl:TransitiveObjectProperty inferencing which you are trying to do at lower RDF/SPARQL level.

Best regards, Marco