Introduction

I've been a Flickr registered user for a while, and since 2000, I'm very interested in the Semantic Web, and the FOAF for describing people.

One thing I'd like to do is search my Flickr stored pictures in a simple way, without having to remember the title used, or which tags the picture has, etc. Or a picture where a lot of people is depicted, at some place, in a specific hour. Flickr doesn't have a search interface like this, but they provide the information needed to develop it.

The examples present in this document are in Turtle, another syntax for RDF.

Describing people in the Semantic Web

My picture are mostly about people, so the first thing I need to have is a way to describe them. Luckily we already have FOAF. So I'll identify the people by their e-mail, but in order to avoid spammers, I'll use the encoded version of their addresses. There's plenty of information on how to do this, as you can find in the FOAF spec, or if you rather read in spanish, in my FOAF tutorial.

_:p1 a foaf:Person;
    foaf:mbox_sha1sum "7a9ac80b951378d4a82ed9eab2bb8fffd449b315"
    foaf:nick "inkel"
    .
    
_:p2 a foaf:Person;
    foaf:mbox_sha1sum "8702b4fa06455608159a8ada349f7924b9208386"
    foaf:nick "Peque"
    .
    
_:p3 a foaf:Person;
    foaf:mbox_sha1sum "556066e2c00f75e0703686b16949e150d710da14"
    foaf:nick "Mer"
    .

Describing pictures

FOAF gives us also the Image class, that allow us to indicate that a resource is an image (in this case, a picture). Flickr store the pictures with different sizes. With this we can construct the corresponding picture's URL and it's thumbnail. We can also know which tags where used in the image. These tags are that basis of the system.

<http://photos23.flickr.com/31214810_b9ab6ae39d_o.jpg> a foaf:Image ;
    foaf:thumbnail <http://photos23.flickr.com/31214810_b9ab6ae39d_o.jpg> ;
    flickr:tagged <http://flickr.com/photos/51722096@N00/tags/inkel/> ;
    flickr:tagged <http://flickr.com/photos/51722096@N00/tags/petos/> ;
    flickr:tagged <http://flickr.com/photos/51722096@N00/tags/2005/>
    .

<http://flickr.com/photos/51722096@N00/tags/inkel/> a flickr:Tag ;
    rdfs:comment "inkel" ;
    rdfs:label "inkel"
    .
    
<http://flickr.com/photos/51722096@N00/tags/2005/> a flickr:Tag ;
    rdfs:comment "Foto tomada en el aņo 2005" ;
    rdfs:label "2005"
    .
    
<http://flickr.com/photos/51722096@N00/tags/petos/> a flickr:Tag ;
    rdfs:comment "Foto tomada en la casa de Peto y Guada" ;
    rdfs:label "Peto's"
    .

This is enough to relate pictures and tags. Now we are at the most critical part of the system, where we relate people and tags:

_:p1 a foaf:Person;
    flickr:tag <http://flickr.com/photos/51722096@N00/tags/inkel/> ;
    foaf:nick "inkel" ;
    foaf:mbox_sha1sum "7a9ac80b951378d4a82ed9eab2bb8fffd449b315"
    .

Of course, you can also relate anything with a tag. In fact, the predicates that relates depiction and depicted object, foaf:depicts y foaf:depiction, has owl:Thing as their domain and range, so anything could be related.

More metadata

Now we add more metadate to the image, as it's title, description, date taken y date published, and it's tags as keywords:

<http://photos23.flickr.com/31214810_b9ab6ae39d_o.jpg> a foaf:Image ;
    foaf:thumbnail <http://photos23.flickr.com/31214810_b9ab6ae39d_t.jpg> ;
    flickr:tagged <http://flickr.com/photos/51722096@N00/tags/inkel/> ;
    flickr:tagged <http://flickr.com/photos/51722096@N00/tags/petos/> ;
    flickr:tagged <http://flickr.com/photos/51722096@N00/tags/2005/> ;
    dc:title "Tadaaaaaaa" ;
    dc:description "Con ustedes........ yo"@es ;
    dc:keyword "2005" ;
    dc:keyword "petos" ;
    dc:keyword "inkel" ;
    dcterms:issued "2004-08-22T00:12:57" ;
    dc:date "2004-42-23T21:09:25"
    .

Final result

Once we run the scripts the system add a few extra triples:

<http://photos23.flickr.com/31214810_b9ab6ae39d_o.jpg> a foaf:Image ;
    foaf:thumbnail <http://photos23.flickr.com/31214810_b9ab6ae39d_t.jpg> ;
    flickr:tagged <http://flickr.com/photos/51722096@N00/tags/inkel/> ;
    flickr:tagged <http://flickr.com/photos/51722096@N00/tags/petos/> ;
    flickr:tagged <http://flickr.com/photos/51722096@N00/tags/2005/> ;
    dc:title "Tadaaaaaaa" ;
    dc:description "Con ustedes........ yo"@es ;
    dc:keyword "2005" ;
    dc:keyword "petos" ;
    dc:keyword "inkel" ;
    foaf:depicts _:p1
    .

_:p1 a foaf:Person;
    flickr:tag <http://flickr.com/photos/51722096@N00/tags/inkel/> ;
    foaf:nick "inkel" ;
    foaf:mbox_sha1sum "7a9ac80b951378d4a82ed9eab2bb8fffd449b315" ;
    foaf:depiction <http://photos23.flickr.com/31214810_b9ab6ae39d_o.jpg>
    .

Done! All I need now is to query my RDF repository. But this exceeds the purpose of this document!

Scripts

My favorite programming language since a few years ago is Python, and you can use an excellent RDF library: RDFLib, developed by Daniel "eikeon" Krech. I'm using 2.2.2 version.

To connect to Flickr I've used James Clarke's flickr.py, but I needed to patch it. You'll need an API KEY to use it.

You need to download the following files, besides the libraries:

namespaces.py
Namespace definitions.
tags2rdf.py
Gets user's tags.
photo2rdf.py
Creates an RDF file for every picture.
smusher.py
Read and process all the .rdf files.

Conclusion

This simple tool shows some of the posibilities of the semantic web, and how we will benefit from it. You can add more metadata if you want to, it's up to your creativity. Please send your comments to inkel-rdf@f14web.com.ar, with subject [flickr2foaf.en]

TODO