Pages

Wednesday, October 12, 2011

Tricks I learned today #2: importing ontologies into a Semantic MediaWiki

I learned a second trick today (see also this first); this one is about the Semantic MediaWiki (SMW). I was using a trick I learned from RDFIO before, setting Equivalent and Original URIs (though the difference between those, I lost). But I ran into the problem that these equivalent URIs cannot contain hashes (#), or not always it seems.

After some googling, I did not find an answer, and turned to the SMW IRC channel. Saruman was helping out and pointed me to the Equivalant URI wiki page. I had looked at that earlier, but now turned to the Import vocabulary page. While this was not what Saruman wanted me to look at, it did turn out a nice workaround. The wiki page shows how to import external ontologies. This trick requires you to craft a wiki page with a special name, starting with MediaWiki:Smw_import_ followed by a namespace. It exemplifies this with the FOAF ontology, which is in fact an ontology I was also using equivalent URIs for.

So, I created a new MediaWiki:Smw_import_foaf page, with this content:

  http://xmlns.com/foaf/0.1/|
  [http://www.foaf-project.org/ Friend Of A Friend]
    name|Type:String
    homepage|Type:URL
    depiction|Type:URL
    phone|Type:String
    knows|Type:Page
    member|Type:Page

And another page, MediaWiki:Smw_import_rdfs, with this:

  http://www.w3.org/2000/01/rdf-schema#|
  [http://www.w3.org/TR/rdf-schema/ RDF Schema]
    seeAlso|Type:URL

Then, in a Property page, which I want to make equivalent with a property in FOAF or RDF Schema, I can now simply use [[imported from::foaf:homepage]] or [[imported from::rdfs:seeAlso]], in Property:Has_homepage and Property:See_also respectively.

That's a neat trick, /me thinks!