Hi Andy, I was working around decompose a SPARQL command and seems more easy to work with string processing (at least, I want to try with string processing). Is there any place where is defined the valid/invalid chars for a SPARQL variable?
Miguel On 19 Aug 2014, at 16:15, Andy Seaborne <a...@apache.org> wrote: > On 19/08/14 16:03, Miguel Bento Alves wrote: >> Andy, >> >> "Another approach is to use a named variable, parse the SPARQL query, which >> identifies variables, then rewrite the parsed structure to replace >> occurrences of variable 'n' by a specific value.” >> >> in a first glance, it's what I expect to do. If I have a variable ?n >> instantiated, I will lookup for &n and replace. > > That's string processing. > > &n is illegal SPARQL. Use ?n if you want to use the more robust rewiring of > the AST (abstract syntax tree) or algebra. > > Andy > >> >> I read carefully your suggestions but I need to start to have a well founded >> opinion. I will start only in next week. >> >> Miguel >> >> >> On 19 Aug 2014, at 14:36, Andy Seaborne <a...@apache.org> wrote: >> >>> On 18/08/14 12:17, Miguel Bento Alves wrote: >>>> Dear all, >>>> >>>> I will start to develop an engine to evaluate rules that combines SPARQL >>>> commands with rule terms. The purpose is to be possible to define rules >>>> like: >>>> >>>> ex:SportsMan ex:minimumSportsPlayed 1 . >>>> ex:IronMan ex:minimumSportsPlayed 3 . >>>> >>>> >>>> (?x rdf:type ?t) <- >>>> ?t ex:minimumSportsPlayed ?n . >>>> (\\\SPARQL >>>> (Select ?x >>>> Where { >>>> ?x ex:playSport ?y . >>>> } >>>> group by ?x >>>> having (count(1) >=&n) >>>> \\\SPARQL). >>>> >>>> Note: in a first approach syntax "&n" is to make reference to ?n . >>>> >>>> my question is: how we should make reference to external variables in a >>>> Sparql command? >>>> >>>> To start the discussion, I have two proposals: >>>> the symbol "&"; >>>> keep the symbol "?", where some variables must be instantiated before >>>> the execution of the sparql command. Something like: >>>> (?x rdf:type ?t) <- >>>> ?t ex:minimumSportsPlayed ?n . >>>> (\\\SPARQL >>>> (Select ?x >>>> Where { >>>> ?x ex:playSport ?y . >>>> } >>>> group by ?x >>>> having (count(1) >=?n) >>>> \\\SPARQL). >>>> >>>> >>>> Miguel >>>> >>> >>> Using & means you need to process the query string and so need to be >>> careful of & used elsewhere (e.g. in a string, in the '&&' operator). >>> >>> Another approach is to use a named variable, parse the SPARQL query, which >>> identifies variables, then rewrite the parsed structure to replace >>> occurrences of variable 'n' by a specific value. >>> >>> If "?t ex:minimumSportsPlayed ?n" has multiple matches, it would need to >>> loop on ?n. >>> >>> I do have some code that rewrites the abstract syntax tree: >>> >>> https://github.com/afs/AFS-Dev/tree/master/src/main/java/element >>> >>> which you're free to copy and use. >>> >>> Or you can do it on the Algebra -- see >>> com.hp.hpl.jena.sparql.core.Substitute(Op, Binding) >>> >>> If you know "?t ex:minimumSportsPlayed ?n" is from the data, you may be >>> able to convert that part and the SPARQL query into a single algebra >>> expression bu joining the two parts, and execute the whole right-hand side >>> as SPARQL. >>> >>> Andy >>> >> >