RE: SPARQL query - Construct

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: public-sparql-dev-request@w3.org [mailto:public-sparql-dev-request@w3.org] On Behalf Of Ricardo Almeida
Sent: 09 September 2008 15:15
To: public-sparql-dev@w3.org
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:image002.png@01C91396.45092860]src1:
[cid:image010.png@01C91390.DB875E70]         person: Set of
[cid:image011.png@01C91390.DB875E70]                          personId
[cid:image012.png@01C91390.DB875E70][cid:image013.png@01C91390.DB875E70]                          name
 addressId
                          addressSrc: Set of
[cid:image014.png@01C91390.DB875E70]                                                  adressIdSrc
[cid:image015.png@01C91390.DB875E70]street
[cid:image016.png@01C91390.DB875E70]                                                  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

Received on Wednesday, 10 September 2008 21:42:57 UTC