Archive for the ‘SemanticWeb’ Category

NQUADS -> TRIG … A Noddy Perl Script

Friday, October 22nd, 2010

I keep coming across nquads files, and libraptor doesn’t support this serialisation, it only supports quad-based TriG format. I knocked together a dirty perl file which will parse a nquads file to TriG if ever need be.

You can find the perl file on my site :

http://mmt.me.uk/examples/perl/nquads_to_trig.pl


#!/usr/bin/perl
use strict;

my $files = scalar(@ARGV);
if ($files != 1) {
  print "NQuads importer. ./nquads_importer nquads_file\n";
  exit();
}

my $input_filename = @ARGV[0];

open (INPUT,$input_filename) || die { print "Input file does not exist\n"};
open (OUTPUT,">$input_filename.trig") || die { print "Failed to open output file\n"};

my $line = "";
my $model_uri = "";
my $triple = "";
my $count = 0;
my %quads = ();

while (<INPUT>) {
  $line = $_;
  if ($line =~ m/^(.*?)(<[^>]+>?)\s*\.$/) {
   $model_uri = $2;
   $triple = $1.".\n";

   $quads{$model_uri} .= $triple;

  } else {
   print ERROR "boo this nquad doesn't pass regex\n$line\n*************\n";
   }
  $count++;
}

foreach my $forth (keys %quads) {
  print OUTPUT "$forth { ".$quads{$forth}." }\n";
}

print "Finished\n";
close(INPUT);
close(OUTPUT);

# vi:set ts=8 sts=4 sw=4 et:

FOAF Inverse Functional Properties

Monday, September 7th, 2009

These are the Inverse Functional Properties of the FOAF ontology, as per 07/09/2009 :

4store>select * where { graph <http://xmlns.com/foaf/0.1/> {?a <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#InverseFunctionalProperty>}}#EOQ


?a
<http://xmlns.com/foaf/0.1/homepage>
<http://xmlns.com/foaf/0.1/mbox_sha1sum>
<http://xmlns.com/foaf/0.1/jabberID>
<http://xmlns.com/foaf/0.1/isPrimaryTopicOf>
<http://xmlns.com/foaf/0.1/icqChatID>
<http://xmlns.com/foaf/0.1/weblog>
<http://xmlns.com/foaf/0.1/mbox>
<http://xmlns.com/foaf/0.1/aimChatID>
<http://xmlns.com/foaf/0.1/msnChatID>
<http://xmlns.com/foaf/0.1/yahooChatID>

I was wondering what happen to foaf:openId ? Does anyone know ?

Grabbing LOD clouds

Tuesday, August 18th, 2009

I have been looking for a set of links for all of the (Linked Open Data) LOD clouds so that I could have a pictorial description of how the LOD cloud has evolved since it was first assembled. Sadly there are no links to the old LOD clouds on from the LOD cloud’s home on the web.

So I hacked together a dirty perl script to see if I could guess the URLs for the old clouds, the code looks like so :

#!/usr/bin/perl

$rootUrl = ‘http://richard.cyganiak.de/2007/10/lod/’;

#now to brute force the URL mangling to grab all of the pictures

for ($i = 2007 ; $i < 2010; $i++) {
for ($j = 1 ; $j < 13; $j++) {
for ($k = 1; $k < 32; $k++) {
$stringToFetch = $rootUrl.”lod-datasets_$i-”.make_big($j).”-”.make_big($k).”.png”;

`wget $stringToFetch`;

}
}
}

#padding out string …
sub make_big($) {
my $string = shift;
if (length($string) == 1) {
$string = “0″.$string;
}
return $string;
}

After running the script I have found the following old instances of the LOD cloud :

Finally, I still don’t think I have the first LOD cloud, would love to know its URL if anyone out there knows it!

meh to owl:equivalentClass

Monday, August 10th, 2009

Meh,

So we now have more links from dbpedia to other RDF resources on the web. Dbpedia now links from dbpedia classes to freebase ones, this example SPARQL query gives some examples of the described linkage. None of these make any sense to me. Why have people decided to use owl:equivalentClass and not owl:sameAs (ducks behind computer screen). Neither of the two seem correct to me, am guessing there is a skos:broader relationship (or something similar) which would be more appropriate, but at least we have come to accept that owl:sameAs tends to get abused, do we really need to loose faith in the semantics of the other OWL classes. Does anyone know why dbpedia decided to go this way?

The OWL spec defines owl:equivalentClass to be :

“A class axiom may contain (multiple) owl:equivalentClass statements. owl:equivalentClass is a built-in property that links a class description to another class description. The meaning of such a class axiom is that the two class descriptions involved have the same class extension (i.e., both class extensions contain exactly the same set of individuals).”

I really don’t think these links are suitable for the knowledge at hand. Perhaps even rdfs:subClassOf would be more fitting.

Determining the Level of Trust of a Digitally Signed Document

Wednesday, July 8th, 2009

In order to determine how trustworthy a digital signature of a file is, you need to grab the file, the digital signature, and you will need to import the user’s public key. This wikipedia fragment describes what is meant by a “trustworthy signature” in terms of the Web of Trust.

This is the command I run to determine the level of trust of my signed foaf file.

gpg --verify --no-tty --status-fd 2 --command-fd 0 foaf.rdf.asc foaf.rdf

Which results in the folowing output :

gpg: Signature made Wed 3 Jun 23:19:52 2009 BST using RSA key ID 51F2F7EF
[GNUPG:] SIG_ID foL1PiWCT+546VnE17UG2QvWJeE 2009-06-03 1244067592
[GNUPG:] GOODSIG 9ED0B04E51F2F7EF Mischa Tuffield (Mischa@Garlik) <mischa.tuffield@garlik.com>
gpg: Good signature from "Mischa Tuffield (Mischa@Garlik) <mischa.tuffield@garlik.com>"
gpg: aka "Mischa Tuffield (http://id.ecs.soton.ac.uk/person/6914) <mmt04r@ecs.soton.ac.uk>"
[GNUPG:] VALIDSIG 18A2AF280CA59E77AE512BB39ED0B04E51F2F7EF 2009-06-03 1244067592 0 4 0 1 2 00 18A2AF280CA59E77AE512BB39ED0B04E51F2F7EF
[GNUPG:] TRUST_ULTIMATE

This is an automatic way of evaluating how trust worthy statement at the end of a URI are.

Firefox 3.5 and W3C Geo API

Wednesday, July 8th, 2009

I have made a simple webpage which makes use of the W3C Geo API. The page will prompt you for your location, given you are using FF3.5, and will subsequently ask you for a WebID and some text to describe what you are up to.

The service then generates a call to another endpoint I bashed together, that takes the following cgi arguements.

webid - lat - long with an OPTIONAL alt - datetime - doing(what I am doing now field)

e.g.,

http://mmt.me.uk/services/FOAFEvent?lat=51.4583494&long=-0.1186444&webid=http://foo.com/foaf.rdf%23bar&datetime=2009-07-08T13:02:46+01:00&doing=writing+a+blog+article


That in turn generates a FOAF person scrobble, or a FOAF Event. I have made us of the Event, Timeline, FOAF, dc, and the Geo ontologies.

So this service can be found on my site, http://mmt.me.uk/geo. It should be noted that I DO NOT store any of the information which I output on this site. I will make it HTTPS at some point, and then I will replace using Plazes.com with my own service. I would rather a world where I was running all of my own social networking from my own machine.

The code to do this is so simple. In order to do the W3C geo stuff all you need to do is write some html and javascript, like so (sorry about the indentation)

<script src="http://maps.google.com/maps?file=api&v=2&key=YOUR_API_KEY_HERE" type="text/javascript"></script>
<script type="text/javascript">
function load() {
navigator.geolocation.getCurrentPosition(showMap);
}
function showMap(position.coords) {
// (position.coords.latitude, position.coords.longitude).
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(position.coords.latitude, position.coords.longitude), 13);
var point = new GLatLng(position.coords.latitude, position.coords.longitude);
map.addOverlay(new GMarker(point));
}
}
</script>
<div id="map" style="width: 620px; height: 310px"></div>

and this :

<body onload="load()" onunload="GUnload()">

Here are a bunch of links which I used to find out how to do this :

Enabling Trust in a FOAF Document

Wednesday, July 8th, 2009

This blog post follows on from my previous one signing and verifying files with GnuPG, whereby I showed (he says), in its simplest form, how one can digitally sign and verify a document. This in turn allows anyone reading the document to verify whether or not it has been tampered with since it was signed.

In this post I will describe two methods of linking to a digital signature from a RDF document. The RDF document I will be describing in this post is a FOAF document, but is is needless to say that this approach can be used from any RDF file.

The method described below makes use of the Web of Trust ontology (WOT). WOT allows for RDF documents to be signed using Digital Signatures and Public Key Cryptography.

Whilst putting together the foaf validator, which checks the semantics of a RDF document to ensure that it is a well formed foaf:PersonalProfileDocument, I came across these two different methods of using the Web of Trust ontology.

Linking to an armored digital signature using the WOT ontology from your FOAF file:

Step 0: Declare the wot namespace in the FOAF file



@prefix wot: <http://xmlns.com/wot/0.1/> .

Step 1

Add a triple from the Document pointing to the digital signature like so:



<> wot:assurance <http://foo.com/foaf.rdf.asc> .

Step 2

Add a triples associating the public key used to sign the FOAF document to the FOAF person. This can be done in one of two ways, like so:

Style 1



_:bnode0 a <http://xmlns.com/wot/0.1/PubKey> .
_:bnode0 dc:title "Public Key Bnode" .
_:bnode0 wot:fingerprint "FW89F7WF78SD8F7SD7FG21JL213192" .
_:bnode0 wot:hex_id "12A75E9B" .
_:bnode0 wot:identity <#me> .
_:bnode0 wot:pubkeyAddress <http://foo.com/me.pubkey.asc>

This is how I sign my FOAF file

Style 2



<#me> wot:hasKey _:bnode0 .
_:bnode0 a <http://xmlns.com/wot/0.1/PubKey> .
_:bnode0 wot:pubkeyAddress <http://foo.com/me.pubkey.asc>
_:bnode0 dc:title "Public Key Bnode" .
_:bnode0 wot:fingerprint "FW89F7WF78SD8F7SD7FG21JL213192" .
_:bnode0 wot:hex_id "12A75E9B" .

This is how Kjetil signs his FOAF file

These two methods of associating a publicKey to a FOAF WebID, which is in turn can be used to digitally sign a FOAF file are both supported by Garlik's FOAF validator.

Enabling a Writable WebID with WebDAV

Wednesday, July 8th, 2009

In this post I will describe how you can enable write access to a file, specially a RDF one, via Apache’s HTTP server and the Web Distributed Authoring and Versioning protocol (WebDAV) extension to the HTTP protocol.

So, why would you want to do this?

I use WebDAV on my FOAF file to enable write access via Tim Berners-Lee’s Tabulator and Garlik’s foafbuilder. This technology allows me to write updates straight through the HTTP protocol, so that I don’t have to save the file to my local machine, and scp it over.

These are the configuration settings needed in your httpd.conf file:

Setting up WebDAV on a whole directory:



<VirtualHost *:80>

ServerName www.foo.com

ServerAlias foo.com

Alias / /var/www/foo/public_html/

<Location />

DAV On

AuthType Basic

AuthName "webdav"

Header set MS-Author-Via DAV

AuthUserFile /var/www/foo/passwd.dav

<LimitExcept GET HEAD OPTIONS POST>

Require user bar

</LimitExcept>

</Location>

</VirtualHost>

Enabling WebDAV for all files ending in .rdf:



<VirtualHost *:80>

ServerName www.foo.com

ServerAlias foo.com

Alias / /var/www/foo/public_html/

<Files ~ ".*\.rdf">

DAV On

AuthType Basic

AuthName "webdav"

AuthUserFile /var/www/foo/passwd.dav

Header set MS-Author-Via DAV

ForceType application/rdf+xml

<LimitExcept GET HEAD OPTIONS POST>

Require user bar

</LimitExcept>

</Files>

</VirtualHost>

It should be noted that the methods presented above allow for the files to be read normally via HTTP, as well as catering for writing via WebDAV.

WebDAV related HTTP Headers:

The correct HTTP header used to tell a client that a file is WebDAV enabled is:

MS-Author-via: DAV

Some of this information was taken from the ESW wiki’s article “EditingData”, and I should thank everyone who helped put it together.

Making FOAF useful ?

Wednesday, July 8th, 2009

FOAF files in isolation only give you information about a person, and who they know – i.e. who they claim to know in their FOAF file.

At Garlik we have implemented a reverse search facility for FOAF, whereby given an API request one can get back triples containing a list of people who claim to know the FOAF URI/IFP used to generate the API request. This list of people is taken from our knowledge base of harvested FOAF files, which currently holds around 10 millions individual FOAF files.

By including an API request to our reverse search in your FOAF file, you can have a FOAF file with both links out and links in :) Wow (he says)…

This API call – http://foaf.qdos.com/reverse/?path=http://mmt.me.uk/foaf.rdf%23mischa – returns an RDF fragment listing foaf:People that claim to know me.

All you need to do is add one triple that requests RDF from our reverse search API to your FOAF file. The triple will look something like this:

<#me> rdfs:seeAlso <http://foaf.qdos.com/reverse/?path=http://foo.com/foaf.rdf%23me> .

You can find examples of this API call in Danbri’s, Steve Harris’s, and my FOAF files.

There is some information regarding how to use the API on the reverse search HTML page.

Ah, good work tobyink …

Tuesday, July 7th, 2009

I have just read tobyink’s article on how one could cater for 3rd parties wanting to contribute triples to an RDF file you own. Firstly, great stuff, this follows on from some things I have been thinking about recently, which include, that of how best to inform RDF documents of when they have been mentioned elsewhere.

tobyink and various other people have been talking about such things recently you can find them of the irc://irc.freenode.net/swig chatlogs here (thanks phenny…). I first started thinking about this when I read this email and when I was thinking about how technologies like linkback, inc. trackback and pingback changed blogging for the better.

I like tobyink’s approach, but I think I would prefer to use a SPARQL endpoint for updating any RDF I own. And I would definitely protected this behind some sort of security mechanism, from .htaccess rules to techniques such as OAuth or FOAF+SSL or similar, I would stress that I would be very careful who I allowed access to any data I owned.

I guess I come from a world of triple-stores, and do enjoy being able to SPARQL quads efficiently as apposed to coming to this from a linked data standpoint. In JXT the SPARQL Endpoint implements a HTTP DELETE and HTTP PUT to allow for graph’s to be updated in the quad store. Give the following SPARQL endpoint :

http://example.com/sparql

We would delete a graph like so :

'curl -X DELETE http://example.com/sparql/http://mmt.me.uk/foaf.rdf'

and similarly for adding triples we use PUT to add triples into the quad store, in the form of a string of RDF and its graph URI. There is work underway to get a SPARUL implementation working so that we can update individual triples in future quad stores.

I was more envisaging the mechanism that would pingback to my FOAF file (or any RDF document I own) as soon as it has been used elsewhere. So for example if Alice befriends Bob, in the form of I know this chap with some URI, then the Alice should somehow ping Bob, like bloggers do, with a simple request, something like what tobyink describes in the section 2.2 POST of the aforementioned post. I would definately not let other people add triples to my FOAF file, and would rather have the triple which mentioned my FOAF URI and have the graph URI where the statement was made, so that I can decide on any future action I may take. If Alice doesn’t know Bob’s FOAF URI, but knows another identifier for him, they could always use a service like the QDOS FOAF search to find a URI for Bob before befriending him.

So something like 2.2 sounds good, but I would prefer if they simply sent me the triple(s) authored that mentioned me, along with the graph URI, than triples they would like to insert into one of my graphs.

I understand how the approach tobyink mentions could be beneficial in a linked data world, and do kind of like the idea of have some sort of “RDF scrap book” which my FOAF friends could write to, but I still think I prefer to not let anyone but me author triples on my domain. If I where to implement an “RDF scrap book” which my foaf:friends could add triples to, whatever they may be ? dbtune scrobbles, their dbpedia interests, I would much rather that information be hosted on one of their sites, which in turn I would store in my quad store for future SPARQL goodness.

Finally, tobyink, why did you decide to use charset="us-ascii" ?