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 09:47:07 -0400
Message-ID: <CAOaHUMkqe5sTuBJGo3xguPyXP+wiN+tN1m3r0P5crA3BZbAuaA@mail.gmail.com>
To: Jitao Yang <jitao.yang@gmail.com>
Cc: Mischa Tuffield <mischa.tuffield@garlik.com>, Andy Seaborne <andy.seaborne@epimorphics.com>, "semantic-web@w3.org" <semantic-web@w3.org>
Hi Jitao,

If working with property labels instead of names will work for you,
the query below might be worth considering.

When I run the query below with ARQ 2.8.8, I feed ARQ with two data
files, like thus:

arq --data jitao.ttl --data index.rdf --query jitao2.rq

jitao.ttl is your data, index.rdf contains the FOAF ontology.

The result is:
-----------------
| propertyLabel |
=================
| "name"        |
-----------------

It's a coincidence that, in this case,  the property label is the same
as the property name.

Not all ontologies have such useful labels for properties,
but if the work to add needed labels yourself is not too much,
this approach might be worth considering ...

Here is the query:
PREFIX foaf:   <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?propertyLabel

WHERE{
    ?x ?p  "Peter Goodguy".
    ?p rdfs:label ?propertyLabel
}

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:36 UTC

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