In SPARQL, the only way a variable can get a value is from a basic graph 
pattern match – everything builds up from there – and only RDF terms in the 
graph can be bound so only RDF terms that occur in the graph can be returned 
and then used in the CONSTRUCT.

In ARQ, in the extended syntax, there is assignment:

{
   …
   ?s ont:firstName ?firstName .
   ?s ont:lastName ?lastName .
   LET ( ?name = fn:concat(?firstName, “ “, ?lastName)  )
}

Where fn:concat [1][2] is the XQuery/XPath Function to concatenate strings.

There are other ways to achieve assignment; subqueries with SELECT expressions; 
property functions, that give an enhanced view of the data within strict SPARQL 
syntax.

A property function is custom code, made to fit into the SPARQl syntax, that 
called at query execution time

PREFIX apf:     <http://jena.hpl.hp.com/ARQ/property#>
prefix  ont:        <http://www.owl-ontologies.com/Ontology1200929459.owl>
SELECT *
{
   ?s ont:firstName ?firstName .
   ?s ont:lastName ?lastName .
    ?name apf:concat (?firstName “ “ ? lastName)
}

Will bind ?name to the result of concatenting str(?firstName) the space and 
str(?lastName)

                Andy

[1] http://www.w3.org/TR/xpath-functions/
[2] Only in SVN : in checking this reply, I found it was wrongly named and 
fixed that.

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ricardo Almeida
Sent: 09 September 2008 15:15
To: [email protected]
Subject: SPARQL query - Construct

I,

I’m using sparql with Jena, to make some queries. I have two ontologies (src1 
and tgt), and two rdf files were I have my instances, according to this 
ontologies.

[cid:[email protected]]src1:
[cid:[email protected]]         person: Set of
[cid:[email protected]]                          personId
[cid:[email protected]][cid:[EMAIL PROTECTED]                      
    name
 addressId
                          addressSrc: Set of
[cid:[email protected]]                                            
      adressIdSrc
[cid:[email protected]]street
[cid:[email protected]]                                            
      pobox

tgt:
employee: Set of
 employee:
 employeeId
 firstName
 lastName
 addressId
       addressTgt: Set of
          adressIdTgt
          address




I would like to use construct to obtain data from one ontology, according to 
the other. Is it possible to make a concatenation (or a split), with construct?
I made the query described above and I obtain all the first names, but what I 
really wanted was to obtain the concatenation of firstName and lastName, of tgt 
as the name of src1.

    private String QConstructSrcFromTgt =
        "CONSTRUCT { ?s rdf:type 
<http://www.owl-ontologies.com/Ontology1200929461.owl#Person> .." +
        "            ?s 
<http://www.owl-ontologies.com/Ontology1200929461.owl#name> ?firstName" +
        "} FROM <http://www.owl-ontologies.com/Ontology1200929459.owl> WHERE 
{?s rdf:type ?o ." +
         "               ?s 
<http://www.owl-ontologies.com/Ontology1200929459.owl#firstName> ?firstName} ";
        //"               ?s 
<http://www.owl-ontologies.com/Ontology1200929459.owl#lasttName> ?lastName. "+
        //"       FILTER regex(?lastName, \"Castro\")    } ";

Thanks,

Ricardo Gabriel Soares Fernandes de Almeida.

-------------------------------------------------------------------------------
Departamento de Engenharia Informática
Instituto Superior de Engenharia
Instituto Politécnico do Porto

Rua Dr. António Bernardino de Almeida, 431
4200-072 Porto
Portugal
Tel.:(+351) 228 340 500 / Fax.: (+351) 228 021 159

<<inline: image010.png>>

<<inline: image011.png>>

<<inline: image012.png>>

<<inline: image013.png>>

<<inline: image014.png>>

<<inline: image015.png>>

<<inline: image016.png>>

<<inline: image002.png>>

Reply via email to