RE: SPARQL query - Construct



> -----Original Message-----
> From: Andreas Langegger [mailto:al@jku.at]
> Sent: 10 September 2008 23:37
> To: Seaborne, Andy
> Cc: Ricardo Almeida; public-sparql-dev@w3.org
> Subject: Re: SPARQL query - Construct
>
> or better LET ( ?var := ... ) right? ;-)
>                      ^^

Yes - plain text is safer!  I promise the cut-and-paste original did work and had := (and the right quotes as well).

>
> This is great, so I can use
>
> SELECT DISTINCT(?dt) WHERE { ?s ?p ?o . LET (?dt := datatype(?o)) }
>
> to get a simple list of all datatypes used for typed literals, at least
> when using ARQ Syntax.


Yes - it's any expression that can appear in a FILTER so built-ins are OK.

You have to declare you want extended SPARQL when the query string is parsed - strict SPARQL is the default.

        Andy
>
>
> good hint, thanks
>
>
> AndyL
>
> On Sep 10, 2008, at 11:41 PM, Seaborne, Andy wrote:
>
>
> 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.
>
> <image002.png>src1:
> <image010.png>         person: Set of
> <image011.png>                          personId
> <image012.png><image013.png>                          name
>  addressId
>                           addressSrc: Set of
> <image014.png>
> adressIdSrc
> <image015.png>street
> <image016.png>                                                  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
>
>
>
>
> Web of Data Practitioners Days / Oct 22-23 / Vienna
> http://www.webofdata.info

> ----------------------------------------------------------------------
> Dipl.-Ing.(FH) Andreas Langegger
> Institute for Applied Knowledge Processing
> Johannes Kepler University Linz
> A-4040 Linz, Altenberger Straße 69
> http://www.langegger.at

>
>
>

Received on Thursday, 11 September 2008 09:12:08 UTC