简体   繁体   中英

SPARQL Query of FOAF doesn't return any result

I want to get some information from the FOAF ontology. I tried the following SPARQL query, but it returns no results. I tried this query to get familiar with FOAF, but what I really want to do is to find all the people that a particular person ?x knows (using the property foaf:knows ). How do I do this?

PREFIX foaf:<http://xmlns.com/foaf/0.1/>
SELECT ?name ?mbox
WHERE { ?x foaf:name ?name .
        ?x foaf:mbox ?mbox .
}

Semantic web is made of different components.

Knowledge is represented as RDF triples. These triples describes Resources based on a Subject - Predicate - Object syntax. For example, "John is a Male" may be represented as a RDF triple.

On top of RDF, we may use RDFS and OWL to specify restrictions and other information on these data. Thanks to RDFS, I can specify that "Male is a subclass of Person" and it is therefore possible to infer that "John is a Person" . RDFS and OWL helps to define ontologies. An ontology is a vocabulary (that can be general or specific to a domain) to represents data. For example, I may want to create an ontology CAT to represent data on cats.

In that case, I would create my CAT vocabulary defining that "Cat is a subclass of Animal" and "hasOwner is a property that links a cat to a Person" and some other properties. Then, I am able to instantiate some individuals to create data on cats. For example by saying that "Baccara is a Cat" and "Baccara hasOwner John" .

FOAF is basically a vocabulary to represent data on people and especially links between these people. FOAF vocabulary gives some properties and classes to handle easily information on people. But it doesn't provide any piece of information, only the "structure"/"model"/"schema" to organize information. There are no individuals in the FOAF dataset. That is why your query returns no result. Since there's no people in the FOAF dataset, it is normal that the query returns nothing.

You may want to build your own RDF dataset based on FOAF vocabulary. To do so, you can try a tool like Protégé, or more easily with a text editor if you're familiar with RDF/XML or Turtle.

Otherwise, if you only need to get familiar with FOAF, you can query the model. For example, you may want to get all the subclasses of Agent :

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT distinct ?c 
WHERE { ?c rdfs:subClassOf foaf:Agent }

I recommend you to read a bit on the semantic web components (especially RDF and RDFS, and differences between them) before going any further in FOAF. Plus, a nice exercise to learn SPARQL consists in querying DBpedia: http://dbpedia.org/sparql .

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