Questions specific to Jena and ARQ are usually answered on the mailing list 
[EMAIL PROTECTED]

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:public-sparql-dev-
> [EMAIL PROTECTED] On Behalf Of Ahmad Iqbal
> Sent: 09 May 2008 11:44
> To: [email protected]
> Subject: SPARQL query modification with ARQ API
>
>
> Hi All,
>
> I have the following question on working with ARQ API:
>
> If I have an object of com.hp.hpl.jena.sparql.syntax.Element class,
> containing four triple pattren as follows;
> { ?artical   <http://swrc.ontoware.org/ontology#author>  ?person .
>   ?person  <http://data.semanticweb.org/ns/swc/ontology#affiliation>  ?org ;
>            <http://www.w3.org/2000/01/rdf-schema#label>  ?name .
>   ?artical   <http://purl.org/dc/elements/1.1/title>  ?title .
> }
>
> code displays above graph pattren:
> System.out.println(element); // where element is an object of Element class.

(Context: Elements are the root class for patterns in the abstract syntax tree)

>
> I have the following questions. Please write a small piece of code.
> Question 1: How can I replace 2nd triple with
> ?person  <http://data.semanticweb.org/ns/swc/ontology#worksIn>  ?org

You can either use the visitor pattern supported by Element or check and 
directly cast to an ElementGroup.  Then you can access the BGP (it's a group of 
one BGP) and manipulate the triples.  Good design is to build a new structure, 
leaving the original untouched.

But it is better to work on the algebra form anyway because "Element" etc are 
just the surface syntax.

Completely different solution: use the rules engine to assert 
<http://data.semanticweb.org/ns/swc/ontology#affiliation>
for every
<http://data.semanticweb.org/ns/swc/ontology#worksIn>
If they mean the same for the purpose of the application.  Then the query is 
fine as is.

>
> Question 2: How can I remove 3rd triple pattren?

As before - cast to ElementGroup, get the first element (the BGP) and 
manipulate.

In the algebra expression below you seem to have aquery that starts with

SELECT ?name ?org ?title

So removing the 3rd triple will leave ?name unbound.

>
>
> Question 3: If I have algebra expression as given below (in an object of
> class com.hp.hpl.jena.sparql.algebra.Op), how can I add and remove a triple
> pattren in this algebra expression? Please mention a short code.
> (project (?name ?org ?title)
>   (order (?org)(BGP
>       (triple ?artical <http://swrc.ontoware.org/ontology#author> ?writer)
>       (triple ?writer
> <http://data.semanticweb.org/ns/swc/ontology#affiliation> ?org)
>       (triple ?writer <http://www.w3.org/2000/01/rdf-schema#label> ?name)
>       (triple ?artical <http://purl.org/dc/elements/1.1/title> ?title)
>     )))

The algebra part of ARQ also supports the visitor pattern but also a transform 
pattern for rewriting one algebra expression into another (transform actually 
builds on visitor).  Subclass TransformCopy and add your manipulation of BGPs; 
use class Tranformer to apply your transform.  It's a bottom-up rewrite of the 
algebra form.  This is the better way to manipulate queries - ARQ uses itself 
for some optimizations, and uses the visitor pattern for reference evaluation 
and serialization into SSE as in your example.

(ARQ supports turning most algebra expressions back into SPARQL syntax, where 
the algebra expression has a SPARQL syntax form that would generate the algebra 
expression.  Some algebra expression do not lead to a direct SPARQL query 
string.)

        Andy

>
> Thanks in advance,
>
> --
> Ahmad Ali Iqbal
> Visiting Scholar (Februry 15 to July 22, 2008)
> Semantic Information Systems and Language Engineering Group
> Digital Enterprise Research Institute (DERI)
> Galway, Ireland.
> Email: ahmad.iqbal at deri.org
> Tel: +353 8782 11402
>
> Ph.D. Research Scholar
> School of Electrical Engineering and Telecommunications
> University of New South Wales (UNSW)
> National ICT Australia Ltd
> Bay 15, Locomotive Workshop, Australian Technology Park
> Eveleigh, NSW 1430
> Email: ahmad.iqbal at {student.unsw.edu.au, nicta.com.au}
> Tel: +61 2 8374 5543, Fax: +61 2 8374 5531
>
>
>

Reply via email to