Re: SPARQL queries property or class from a schema

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