Gustavo Salvador
Gustavo Salvador

Reputation: 15

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:

(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.

Upvotes: 1

Views: 269

Answers (1)

RedCrusaderJr
RedCrusaderJr

Reputation: 372

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! :))

Upvotes: 0

Related Questions