WordPress Plugin: Semantic Visits

When I came back from Madrid, after the Image Decription workshop, a few days in the city, and a hefty party in Getafe, I realised I could add another country to my list of visits.

The nice folks at World66 have created a nice interface for generating an image with visited countries highlighted, but while it would be easy to check a few boxes and copy the code to somewhere on my blog pages, that wouldn’t make it possible for the semantic web to figure out where I’ve been. For that reason, I decided to mint a set of vocabulary terms for visits according to Norm Walsh’s country counting rules, collected in the visit vocabulary, and have WordPress output the information in my FOAF profile – thanks to the extensibility of my FOAF Output Plugin. Of course, the FOAF Explorer now also understands these terms, displaying maps of the world, Canada and USA when appropriate — see for yourself!

Thus, here is a new plugin, the Semantic Visits Plugin (view source).

The current version is 1.1.

Changes since 1.0:
  • Added visits to Canadian regions.
  • Fixed “wrong” code/name/etc. properties.
  • The URIs for US states are now correct, pointing at the http://www.daml.ri.cmu.edu/ont/USRegionState.daml ontology containing state definitions instead of http://www.daml.ri.cmu.edu/ont/State.daml which only contains classes and properties.

Features:
  • Extends the FOAF profile document with statements about visited countries and US states (example).
  • Extends the author profile page with images from World66 (example).
  • List of visited countries, Canadian regions, and US states based on links in special categories.
Requirements:
  • WordPress 1.2 (later versions not tested but might work).
  • A working installation of the FOAF Output Plugin version 1.7 or later.
Installation:
  1. Download the Semantic Visits Plugin, rename to semantic-visits.php and place it in the plugins directory.
  2. Activate it in the administration interface under Plugins.
  3. Create three link categories in the administration interface under Links > Link Categories, one named “Countries”, one named “CA Regions”, and one named “US States” (case matters). Remember to enter “0” in the Limit field unless you also want the list of countries and regions/states to be displayed alongside the other links in the side bar. Once created, the list of link categories should look something like this (larger version): WordPress administration interface, list of link categories
Managing visits:
The lists of visits are managed as links (possibly without a link!) in categories named “Countries”, “CA Regions”, and “US States”, created as described above. The fields in the link manager must be used as follows for the plugin to work correctly:
  • The URI field can be empty, but if you do enter a URI, make sure it’s for a page about the country or US state, e.g. “http://www.denmark.dk/“.
  • The Link Name field must contain the ISO3166 code for the country — or the two-letter state code for the Canadian region or US state, e.g. “DK”, “AL” or “CA” (case matters). The list of ISO3166 Country Codes is available elsewhere, as is a list of US State Codes.
  • The Short description field can be empty, but must contain the name of the country, region, or state if not left blank, e.g. “Denmark”.
API extensions, functions:
get_semantic_visits_countries_image():
This function returns, if on a page with with one post/author, a string with an img element pointing to a map with visited countries highlighted.
get_semantic_visits_usstates_image():
This function returns, if on a page with with one post/author, a string with an img element pointing to a map with visited US states highlighted.
get_semantic_visits_caregions_image():
This function returns, if on a page with with one post/author, a string with an img element pointing to a map with visited Canadian regions highlighted.
get_semantic_visits_countries():
This function returns, if on a page with with one post/author, an array with each element being an associative array, representing a country, with the fields code, name, uri and country, where the first three correspond to the fields in the link administration interface and the last is the URI identifying the country, e.g. http://www.daml.org/2001/09/countries/iso#DK.
get_semantic_visits_usstates():
This function returns, if on a page with with one post/author, an array with each element being an associative array, representing a state, with the fields code, name, uri and usstate, where the first three correspond to the fields in the link administration interface and the last is the URI identifying the state, e.g. http://www.daml.ri.cmu.edu/ont/USRegionState.daml#DC.
get_semantic_visits_caregions():
This function returns, if on a page with with one post/author, an array with each element being an associative array, representing a region, with the fields code, name, uri and caregion, where the first three correspond to the fields in the link administration interface and the last is the URI identifying the region, e.g. http://www.daml.ri.cmu.edu/ont/CanadianState.daml#AL.

Of course, all of this hacking wouldn’t be necessary if we had the right inference rules in place and tools to handle them with. With images depicting me, taken at various points around the globe, it seems like it should be possible at some point to automatically infer which countries I have visited, much like Dan Connolly has done with his Travel Tools.

With existing data we could get close by using information on the nearest airport, but it might be prone to errors for small and closeby countries where the nearest airport is actually located in another country.

17 thoughts on “WordPress Plugin: Semantic Visits

  1. Hey morten, do any ideas exist to relate visited countries to time of visit. From my point of view there is a huge difference in visiting a country as a child or as a business traveller

  2. Pingback: erdGeschoss
  3. Me again,
    I have looked at kanzaki’s whois vocabulary, and I think that using this is the right way of expressing “I have been to this and that country and did things like…”. Travelling to a country is never without any purpose, so I think the whois:stage must contain a visit:country. Some example is at http://B4mad.Net/FOAF/goern-visits.rdf. Actually FoaF Explorer is not capable of rendering this.

    PS: Is defining the way I use a vocabulary by making such a statement acceptable or is there a more general way defining the coexistence of whois: and visit: ?

  4. Hey,

    I think your example looks fine, but the visit:country should not be placed in the whois:Stage, as visit:country has a domain of foaf:Person, and places and people are almost certainly disjoint.

    Aside from that it seems the FOAF Explorer renders it fine? It doesn’t include the Germany visit, but that is due to the reason mentioned above, the visit:country isn’t a property of the person.

    Regarding interoperability of whois and visit, I’m not sure how it should be done. It seems like it won’t be possible without rules, e.g. one that says that if a person has a stage with a whois:where, with some sort of location, and covering a time span of at least to days, it can be infered that the person has visited the country that the location is located in…

  5. Absolutely marvellous!
    Both this and your updated FOAF Output worked perfectly.
    One little question – is there an easy way of including/seeAlso’ing my handwritten FOAF? I presume there’s a PHP [include this.file] but maybe there’s a less in-the-engine way?

  6. PS. Is there an easy way of hidding selected categories from the front page? WP’s link hiding seems to hide it from the FOAF too.

    I guess adding something like [div style=”display: none;”] to the markup associated with each link should do it – but any easier way?

  7. Danny,

    Regarding the hiding of categories (I’m assuming you mean link categories), make sure you put “0” in the Limit field for the category (see instructions above), that’ll stop them from showing on the HTML pages, and will still keep them in the FOAF file for the countries/states.

    As for the other-foaf-file inclusion, it’d have to be by seeAlso — I think it’d be impossible to keep it well-formed otherwise. Watch this space or beat me to it by coding up the plugin. :)

  8. Thanks.

    btw, while you’re on this roll, have you thought about any WP coolness relating to topics/subjects (and maybe foaf:project)? I just came across MS’s OPML stuff, it could surely be a lot more fun in RDF…

  9. Hey morten, I just played arround with your set of plugins on WordPress 1.5. Seems to work ok, only the URI field of the country links seems to be handled differently by wp1.5: it always contains a http:// when left blank.

Comments are closed.