W3C home > Mailing lists > Public > semantic-web@w3.org > August 2011

Re: SPARQL queries property or class from a schema

From: evan chua-yap <semwebfan@gmail.com>
Date: Sun, 14 Aug 2011 20:37:25 -0400
Message-ID: <CAOaHUM=An7fzsxi5G0y42tyoJnfSfhU4dRwn27-dV3SRWznK=Q@mail.gmail.com>
To: Jitao Yang <jitao.yang@gmail.com>
Cc: "semantic-web@w3.org" <semantic-web@w3.org>
The following query also works in ARQ 2.8.8:

#filename: jitao3.rq

PREFIX foaf:   <http://xmlns.com/foaf/0.1/>
PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>

SELECT ?property

WHERE{
    ?x ?p  "Peter Goodguy".
    BIND (afn:localname(?p) as ?property)
}

arq --data jitao.ttl --query jitao3.rq
------------
| property |
============
| "name"   |
------------

if you're not using ARQ, check if your SPARQL processor offers something
similar to Jena's /ARQ's afn:localname() function.

Hope this helps!

Evan Chua-Yap

On Fri, Aug 12, 2011 at 2:58 PM, Jitao Yang <jitao.yang@gmail.com> wrote:

> Thank you Mischa,
>
> but in this way, how to decompose ?Property out? Could you please write a
> full query?
>
> Jitao
>
>
> On Fri, Aug 12, 2011 at 19:20, Mischa Tuffield <mischa.tuffield@garlik.com
> > wrote:
>
>> Excuse the top-post.
>>
>> You can brutal about it in SPARQL 1.0 and use filter regex. Something like
>> :
>>
>> . FILTER ( regex( str(?p), "/http:\/\/xmlns\.com\/foaf/") )
>>
>> It is kinda nasty, but will do the trick!
>>
>> Mischa
>>
>> Sent on the move
>>
>> On Aug 12, 2011, at 5:55 PM, Andy Seaborne <andy.seaborne@epimorphics.com>
>> wrote:
>>
>> >
>> >
>> > On 12/08/11 17:36, Jitao Yang wrote:
>> >> Dear all,
>> >>
>> >> suppose we have DATA:
>> >>
>> >> @prefix foaf: <http://xmlns.com/foaf/0.1/> .
>> >>
>> >> _:a  foaf:name "Johnny Lee Outlaw" .
>> >> _:a  foaf:mbox <mailto:jlow@example.com <mailto:jlow@example.com>> .
>> >> _:b  foaf:name "Peter Goodguy" .
>> >> _:b  foaf:mbox <mailto:peter@example.org <mailto:peter@example.org>> .
>> >> _:c  foaf:mbox <mailto:carol@example.org <mailto:carol@example.org>> .
>> >>
>> >>
>> >> can we write a SPARQL query like:
>> >>
>> >> PREFIX foaf: <http://xmlns.com/foaf/0.1/>
>> >> SELECT *?property*
>> >>
>> >> WHERE{
>> >>             ?x  foaf:*?property* "Peter Goodguy".
>> >> }
>> >>
>> >> if we can not, can we write an equivalent SPARQL query? Namely, can we
>> >> decompose schema and Class(or Property) in SPARQL query?
>> >>
>> >> Thanks,
>> >> Jitao
>> >
>> > SPARQL 1.1:
>> >
>> > PREFIX foaf:   <http://xmlns.com/foaf/0.1/>
>> > SELECT ( substr( str(?p), strlen(str(foaf:))+1 )
>> >          AS ?property)
>> >
>> > WHERE{
>> >    ?x ?p  "Peter Goodguy".
>> > }
>> >
>> >
>> >
>> > In SPARQL 1.0, you can't return anything not already in the graph : in
>> SPARQL 1.1 you can do some manipulation of RDF terms.
>> >
>> > Because SUBSTR is fn:substring, indexes are 1-based.
>> >
>> >   Andy
>> >
>>
>>
>>
>
Received on Monday, 15 August 2011 17:45:34 UTC

This archive was generated by hypermail 2.4.0 : Tuesday, 5 July 2022 08:45:25 UTC