简体   繁体   中英

SPARQL query to get all the individuals with a specific property

I have an ontology with two types of relations, the amigo_de and the amigo_de_amigo_de .

The domain and range of these relations is the same: pessoa .

The file containing this ontology is a.nt file.

What I need is a query to get all the lines that a object has a amigo_de_amigo_de predicate.

I am new with SPARQL and I am having trouble learning it.

Useful information:

  • amigo_de_amigo_de URI: file://ontologiaTeste.ntriples#amigo_de_amigo_de
  • pessoa URI: file://ontologiaTeste.ntriples#pessoa
  • file name: ontologiaTeste.ntriples

(I know the file extension is wrong, I will correct it later.)

I didn't try many things, but I am studying SPARQL to try resolve this.

What you need is something like this:

SELECT ?obj
WHERE {
  _:a <file://ontologiaTeste.ntriples#amigo_de_amigo_de> ?obj
}

Here we are stating a graph pattern which triples must satisfy in order to be returned as part of a query result.

So all objects ?obj that have a predicate amigo_de_amigo_de , and for subject a blank node _:a , as that information does not interest you.

If you also need a subject then you go with this query:

SELECT ?sub ?obj
WHERE {
  ?sub <file://ontologiaTeste.ntriples#amigo_de_amigo_de> ?obj
}

As Stefan had pointed out, these are some elementary queries. You can find useful examples for each semantic web concept in W3C documents that define them. Feel free to ask questions here, but go through examples first in order to steep up your learning curve: :))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM