From: Rob V. <rv...@do...> - 2012-09-24 17:21:26
|
Off the top of my head it should look something like this, assuming you create the URIs as INode instances first: ISparqlAlgebra algebra = new Select( new Filter( new Join( new LeftJoin( new LeftJoin( new BGP(), new BGP(new TriplePattern(new VariablePattern("?item"), new NodeMatchPattern(rdfType), new NodeMatchPattern(someClass))) ), new BGP(new TriplePattern(new VariablePattern("?item"), new NodeMatchPattern(rdfType), new NodeMatchPattern(someOtherClass))) ), new BGP(new TriplePattern(new VariablePattern("?item"), new NodeMatchPattern(foafName), new VariablePattern("?itemName"))) ), new UnaryExpressionFilter(new LangMatchesFunction(new LangFunction(new VariableTerm("itemName")), new ConstantTerm(en))) ), new String[] { "item" }); Not the prettiest thing to build, see the QueryBuilder class [1] on the fluent-query [2] branch for an initial rough cut of a more user friendly fluent style API, see the unit tests in that commit for some examples of building queries Hopefully that style of API will be much more readable than the above and much more user friendly Rob [1] https://bitbucket.org/dotnetrdf/dotnetrdf/changeset/f0654d04f2612d6e215ff17 d166ba99c74e781af [2] https://bitbucket.org/dotnetrdf/dotnetrdf/changesets/tip/branch(%22fluent-q uery%22) On 9/24/12 5:40 AM, "Tomasz Pluskiewicz" <tom...@gm...> wrote: >Hello again > >I tried to build some algebra programmatically but I failed miserably :) > >Could you please as an example help me with expressing the below >SPARQL in Algebra API? > >SELECT ?item >{ > OPTIONAL { ?item a ex:someClass . } > OPTIONAL { ?item a ex:someOtherClass . } > ?item foaf:name ?itemName > FILTER( langMatches( lang(?itemName), "en" )) >} > >This should give me enough insight to get up to speed with the API. > >Thanks, >Tom > >On Sat, Sep 22, 2012 at 7:02 PM, Tomasz Pluskiewicz ><tom...@gm...> wrote: >> Also are there any introductory examples on creating SPARQL Algebra. >> It could be the way to go for my initially. Are there many scenarios >> when it would be impossible to convert it to a query? >> >> Tom >> >> On Sat, Sep 22, 2012 at 11:30 AM, Tomasz Pluskiewicz >> <tom...@gm...> wrote: >>> Thanks Rob >>> >>> I could look into it. Please point me int the right direction in the >>> code where the internal API is located. >>> >>> Tom >>> >>> On Fri, Sep 21, 2012 at 10:26 PM, Rob Vesse <rv...@do...> >>>wrote: >>>> Hey Tom >>>> >>>> Right now it's somewhat limited, you can build the algebra >>>> programmatically and try and convert it back to a query with the >>>>AsQuery() >>>> method but that isn't guaranteed to work (some algebras can't be >>>>converted >>>> back into queries). Otherwise you have to generate a string and then >>>> parse it. >>>> >>>> Most of the SparqlQuery API is protected internal/private, I have a >>>>To Do >>>> item to add a public fluent style API for building queries that I will >>>> likely do for the next release if that helps. I/you can start >>>>building >>>> that out in a feature branch if that would solve your issue? >>>> >>>> Rob >>>> >>>> On 9/21/12 11:39 AM, "Tomasz Pluskiewicz" >>>><tom...@gm...> >>>> wrote: >>>> >>>>>Hi >>>>> >>>>>Please tell me what are the options for building SPARQL >>>>>programatically with dotNetRDF? Is there any such API? >>>>> >>>>>Regards, >>>>>Tom >>>>> >>>>>---------------------------------------------------------------------- >>>>>---- >>>>>---- >>>>>Got visibility? >>>>>Most devs has no idea what their production app looks like. >>>>>Find out how fast your code is with AppDynamics Lite. >>>>>http://ad.doubleclick.net/clk;262219671;13503038;y? >>>>>http://info.appdynamics.com/FreeJavaPerformanceDownload.html >>>>>_______________________________________________ >>>>>dotNetRDF-develop mailing list >>>>>dot...@li... >>>>>https://lists.sourceforge.net/lists/listinfo/dotnetrdf-develop >>>> >>>> >>>> >>>> >>>> >>>> >>>>----------------------------------------------------------------------- >>>>------- >>>> Got visibility? >>>> Most devs has no idea what their production app looks like. >>>> Find out how fast your code is with AppDynamics Lite. >>>> http://ad.doubleclick.net/clk;262219671;13503038;y? >>>> http://info.appdynamics.com/FreeJavaPerformanceDownload.html >>>> _______________________________________________ >>>> dotNetRDF-develop mailing list >>>> dot...@li... >>>> https://lists.sourceforge.net/lists/listinfo/dotnetrdf-develop > >-------------------------------------------------------------------------- >---- >Live Security Virtual Conference >Exclusive live event will cover all the ways today's security and >threat landscape has changed and how IT managers can respond. Discussions >will include endpoint security, mobile security and the latest in malware >threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ >_______________________________________________ >dotNetRDF-develop mailing list >dot...@li... >https://lists.sourceforge.net/lists/listinfo/dotnetrdf-develop |