0

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 .
}
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
Dihya
  • 19
  • 2
  • You run the query on which knowledge base? The FOAF ontology itself is just the schema. – UninformedUser May 03 '16 at 11:21
  • I used the Virtuoso SPARQL Query Editor and I put http://xmlns.com/foaf/0.1/ in the Default Data Set. Am I wrong ? @AKSW – Dihya May 03 '16 at 11:47
  • From my point of view, you loaded just the FOAF vocabulary, but not any instance data. – UninformedUser May 03 '16 at 13:14
  • Worth noting, even given a data set with such instance data -- your query will deliver the `?name` and `?mbox` of person `?x`, and these only if both statements are in the store you're querying against. You'll need a very different query for what you've described as your goal. [These tutorials](http://virtuoso.openlinksw.com/sparql-tutorials/) may be helpful to you. (ObDisclaimer: I work for [OpenLink Software](http://www.openlinksw.com/), source of those tutorials and the [Virtuoso Universal Server](http://virtuoso.openlinksw.com/).) – TallTed May 03 '16 at 15:34
  • you are right, @AKSW . It's because FOAF is just a vocabulary, it doesn't contains any instance – Dihya May 03 '16 at 17:49

1 Answers1

2

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.

TallTed
  • 9,069
  • 2
  • 22
  • 37
Grégoire G.
  • 719
  • 4
  • 11
  • 1
    A couple more useful tools for learning... the [OpenLink Structured Data Editor (OSDE)](http://osde.openlinksw.com/) (use a [live instance on URIBurner.com](http://linkeddata.uriburner.com/rdf-editor/)) is good for creating and editing RDF data documents. Also, [iSPARQL, the Interactive SPARQL Query Builder](http://oat.openlinksw.com/index.html?isparql), live at [http://dbpedia.org/isparql/](http://dbpedia.org/isparql/), among other places. – TallTed May 03 '16 at 15:41
  • Is there any knowledge base which contains instances according to FOAF ontology ? I used for exemple dbpedia to get a "depiction" of a person. And if I want to get people that one person "knows" I don't know if there is a knowledge base that can answer this query ? @TallTed – Dihya May 05 '16 at 10:58
  • There is no FOAF knowledgebase, per se. Still, many data sets and sources include FOAF-based data; for instance, you can [query the LOD Cloud Cache](http://lod.openlinksw.com/sparql?default-graph-uri=&query=PREFIX++foaf%3A++%3Chttp%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2F%3E%0D%0ASELECT+DISTINCT+*+%0D%0AWHERE%0D%0A++{+%3Fs++foaf%3Aknows++%3Fo+}+%0D%0AORDER+BY+%3Fs+%3Fo%0D%0ALIMIT+1000&should-sponge=&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=30000&debug=on) provided by my employer, [OpenLink Software](http://www.openlinksw.com/). – TallTed May 05 '16 at 14:58