Hi Andy, 

&n is illegal SPARQL, ok, but that does not means that can be used to refer a 
outer variable? The symbol “&” can appear in a SPARQL command (excepting in a 
String)? 

and the symbol “$”?

BTW, I almost finished the development of an engine to evaluate rules that 
combines rules terms with sparql commands. To finish, I only need to define the 
special char to make reference to outer variables (for now, and to develop the 
engine, I'm using a non-valid char).

Miguel




On 27 Aug 2014, at 18:51, Miguel Bento Alves <mbentoal...@gmail.com> wrote:

> Hi Andy, 
> 
>> &n is illegal SPARQL.  Use ?n if you want to use the more robust rewiring of 
>> the AST (abstract syntax tree) or algebra.
>> 
> 
> I think that should be defined a special char (or char sequence) to make 
> reference to outer variables, variables from rule terms for instance, in a 
> Sparql command declared in a rule. In this way, it will be clear when we want 
> to make reference to outer variables. If we use the same char as variables 
> (?), inadvertently  can be made reference to a outer variable and the system 
> undesirably replace the variable by a value. 
> 
> Furthermore, and in the best of my knowledge (correct me if I’m wrong), in 
> SPARQL command, a subquery cannot make reference to outer variables in the 
> query pattern. If I use the same symbol of variables to make reference to 
> outer variables, seems that my sparql command has a "special behaviour". In 
> my point of view, a command SPARQL in a rule should have the same behaviour 
> as a subquery in a sparql command, except that we can introduce a way to make 
> reference to outer variables. 
> 
> I hope that I have clearly exposed my idea. Otherwise, I will try to explain 
> better. 
> 
> have you any suggestion for the special char (or char sequence)? 
> 
> 
> 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
>>>> 
>>> 
>> 
> 

Reply via email to