📜 ⬆️ ⬇️

FOAF for dummies

You had a chance to find out what RDF is.
Have you ever read in my blog for some terrible FOAF, SIOC, SKOS, DOAP ...
It's time to find out what it is and why I talked about RDF.

Let's start?


Foaf
F riend O f A F riend is the ontology of describing a person (roughly speaking), more precisely, of a person. In short, the usual profile that you fill out on sites a million times. It contains information about the name, date of birth, work, contacts, dating. It is the starting point in the Social Graph. Let's see in more detail? For greater comprehension, we will think of it with you, again, so that you would understand all the logic and see how everything is thought out and why it is so, and not that way. In addition, it will be convenient for people who do not read XML.
')
We have a man (in this case, I gave myself to experiment, for the sake of science)
So who am I?

Name : Nikolai Korobko
Email : admin@futuri.us
Homepage : futuri.us
Nick : Nicholass
Photo : img-fotki.yandex.ru/get/9/w88lf.8/0_9266_a7b0b5d8_L.jpg
Interests :
  1. Web 3.0
  2. Semantic network

Dating :

This is far but not a complete list, of course, but enough for intelligence.
Remember the N3? let's try to apply?
@prefix < xmlns.com/foaf/0.1/>
Nikolay Korobko A: person
Nikolai Korobko: hasMail <admin@futuri.us>
Nikolai Korobko: hasHomepage < futuri.us>
Nikolai Korobko: hasNik "Nicholass"
Nikolai Korobko "hasPhoto < img-fotki.yandex.ru/get/9/w88lf.8/0_9266_a7b0b5d8_L.jpg>
Nikolai Korobko: hasInterest Web 3.0
Nikolai Korobko: hasInterest "Semantic Network"
Nikolay Korobko: knows: people

(in fact, this scheme does not work!)

In a good way, I must create a similar list for my acquaintances. But it is a bit complicated, better readable for humans, but worse for a car.
FOAF was developed for this purpose.
Interlude : Namespaces
Namespace (in XML) definition of tags, attributes and their location relative to each other in the document.
For example, take HTML. Lists. The namespace clearly states that <ul> may contain one or more <li>, as well as other elements. Or in the same namespace it is clearly stated that <head> is a descendant of <body> and that <head> cannot contain <img>.

Without going into the details of the namespace, we write down the information about me (so far only about me) in the form of FOAF:
 <rdf: RDF
   xmlns: rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns: foaf = "http://xmlns.com/foaf/0.1/"
   xmlns: rdfs = "http://www.w3.org/2000/01/rdf-schema#">
   <foaf: Person rdf: about = "# JW">
     <foaf: name> Korobko Nikolay </ foaf: name>
     <foaf: mbox rdf: resource = "mailto: admin@futuri.us" />
     <foaf: homepage rdf: resource = "http://futuri.us/" />
     <foaf: nick> Niholass </ foaf: nick>
     <foaf: depiction rdf: resource = "http://img-fotki.yandex.ru/get/9/w88lf.8/0_9266_a7b0b5d8_L.jpg" /> 

Disassemble line by line?
 <rdf: RDF
   xmlns: rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns: foaf = "http://xmlns.com/foaf/0.1/"
   xmlns: rdfs = "http://www.w3.org/2000/01/rdf-schema#">
   <foaf: Person rdf: about = "# JW"> 

This is where the namespaces are connected. xmlns is nothing more than an XML Name Space (XML Namespace). We connected RDF, FOAF and RDF-schema.

RDF to create an RDF document.
FOAF is understandable for what :)
RDF-schema is the format of the RDF format. Since FOAF is also an RDF document, the machine must check its design according to the RDF dictionary.
   <foaf: Person rdf: about = "# JW"> 

This line indicates that we are describing a person. It is equivalent to “Nikolay Korobko A: person“. This is a personality description container. “Why is it needed, because we use FOAF, this is the description of a person !?” You will angrily comment, but everything is ahead, everything is thought out. look further.
   <foaf: name> Korobko Nikolay </ foaf: name> 

By the way, I forgot to say, the prefix in the tag (foaf :) indicates what namespace we take it from, because there are coincidences, for example, in the Dublin Core (about it later) and in HTML there is a title element.

it seems all clear. Name: Nikolai Korobko.
     <foaf: mbox rdf: resource = "mailto: admin@futuri.us" />
     <foaf: homepage rdf: resource = "http://futuri.us/" />
     <foaf: nick> Niholass </ foaf: nick>
     <foaf: depiction rdf: resource = "http://img-fotki.yandex.ru/get/9/w88lf.8/0_9266_a7b0b5d8_L.jpg" /> 

General structure understood?

First, we declared foaf: Person, this is in N3 we have a subject, the name of the tag will be a predicate, and the content will be an object. For example. foaf: Person foaf: name „Korobko Nikolai“. rdf: resource is used to transfer the URI as an object not as a string.

So, now we have assigned the person a name, mail (for spam protection, it is sometimes encoded in sha1), a homepage, a nickname, and some description (foaf: depiction This field can contain any information about you, in this case, the address of the photo).

Remember that RDF is nesting? That is, the object may be another triple of values. In XML, this is shown simply by tagging.

So, we will create interests for a person, for this we use the foaf: interest tag and invest my interests in it. Now the triples will be such foaf: interest df: Description (rdf: about rdfs: label). I mean, Persons. There are interests: Interest: (URI and description of interest). We look:
     <foaf: interest>
       <rdf: Description rdf: about = "http://futuri.us" rdfs: label = "Web 3.0" />
     </ foaf: interest>
     <foaf: interest>
       <rdf: Description rdf: about = "http://futuri.us" rdfs: label = "Semantic Web" />
     </ foaf: interest> 

Like that. The same nesting and dating, but here we remember why we declare foaf: Person. After all, we are familiar with people, that is, the object will contain an embedded person. Another foaf: Person. I think many have guessed how it would look:
      <foaf: knows>
      <foaf: Person>
        <foaf: name> Misha Kvakin </ foaf: name>
        <foaf: homepage rdf: resource = "http://design-freak.com/" />
        <rdf: Description rdf: about = "http://www.google.com.ua/search?q=design" rdfs: label = "Design" />
        <rdf: Description rdf: about = "http://www.google.com.ua/search?q=Uzability" rdfs: label = "Usability" />
     </ foaf: Person>
     <foaf: Person>
        <foaf: name> Roman Rybalchenko </ foaf: name>
        <foaf: homepage rdf: resource = "http://cooluck.kiev.ua" />
       <foaf: nick> Cooluck </ foaf: nick>
        <rdf: Description rdf: about = "http://www.google.com.ua/search?q=SEO" rdfs: label = "SEO" />
     </ foaf: Person>
    </ foaf: knows> 

It remains to put together the entire document.
 <rdf: RDF
   xmlns: rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns: foaf = "http://xmlns.com/foaf/0.1/"
   xmlns: rdfs = "http://www.w3.org/2000/01/rdf-schema#">
   <foaf: Person rdf: about = "# JW">
     <foaf: name> Korobko Nikolay </ foaf: name>
     <foaf: mbox rdf: resource = "mailto: admin@futuri.us" />
     <foaf: homepage rdf: resource = "http://futuri.us/" />
     <foaf: nick> Niholass </ foaf: nick>
     <foaf: depiction rdf: resource = "http://img-fotki.yandex.ru/get/9/w88lf.8/0_9266_a7b0b5d8_L.jpg" />
     <foaf: interest>
       <rdf: Description rdf: about = "http://futuri.us" rdfs: label = "Web 3.0" />
     </ foaf: interest>
      <foaf: knows>
      <foaf: Person>
        <foaf: name> Misha Kvakin </ foaf: name>
        <foaf: homepage rdf: resource = "http://design-freak.com/" />
        <rdf: Description rdf: about = "http://www.google.com.ua/search?q=design" rdfs: label = "Design" />
     </ foaf: Person>
     <foaf: Person>
        <foaf: name> Roman Rybalchenko </ foaf: name>
        <foaf: homepage rdf: resource = "http://cooluck.kiev.ua" />
        <rdf: Description rdf: about = "http://www.google.com.ua/search?q=SEO" rdfs: label = "SEO" />
     </ foaf: Person>
    </ foaf: knows>
   </ foaf: Person>
 </ rdf: RDF> 

Voila! now, I hope everyone understood not only FOAF, but also the logic of writing RDF documents in XML format.

D / C
Try to create your FOAF, and then check what happened. Below in the links is foaf-a-matic, he will help you with this.


Materials taken from my blog .
Write about what else you will be interested to hear in the „for dummies“ section and I will try to write.

Source: https://habr.com/ru/post/18263/


All Articles