LokiNkc
LokiNkc

Reputation: 55

Select property from an Individual SPARQL

I need to get a property value from an individual in an ontology.

How can I do it?

I have this code, but I have to filter because I need an certain individual.

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX oc: <http://localhost:8080/OntoSakaiWS/OntoCompetence.owl#> 
SELECT distinct ?x ?value
    WHERE { 
    ?x a oc:Asignatura.
    ?x oc:nombre ?value.

}

Upvotes: 0

Views: 1424

Answers (1)

Artemis
Artemis

Reputation: 3301

Your query should work perfectly. I'll give you an example of how you can extract a certain individual in the family tree ontology.

Imagine you want to get all the information about a specific person, let's say herbert_vincent_jessop_1871. There are two ways, first to retrieve all the information and then filter it based on your individual:

prefix : <http://www.co-ode.org/roberts/family-tree.owl#>
SELECT distinct *
WHERE { 
?s a ?o.
?s ?p ?x.
filter (?s=:herbert_vincent_jessop_1871)
}

Or, just define the instance in the query:

prefix : <http://www.co-ode.org/roberts/family-tree.owl#>
SELECT distinct *
WHERE { 
:herbert_vincent_jessop_1871 a ?o.
:herbert_vincent_jessop_1871 ?p ?x.
}

They will both produce the same result.

Upvotes: 1

Related Questions