Wednesday, June 27, 2007

Chemical RDFa with Operator in the Firefox toolbar

December last year I proposed the use of microformats and RDFa for simple semantic markup of molecular information. I linked that with the InChI extension for the software for Chemical blogspace and wrote these tools to work with the markup:
All using the new semantic markup.

Of the two, I think RDFa has the best future. Then I discovered Operator, written by Mike. While the Greasemonkey scripts already allow me to link to, for example, PubChem and eMolecules, the Operator Firefox Addon allowed me to open vCards incorporated in HTML pages directly to my address book client. Thus, I could open chemistry directly in Bioclipse too!

That was the idea, at least. I contacted Mike, and he asked me to wait until the first 0.8 releases, which he announced earlier this month. This version allows user scripts to be written, which define how RDFa should be handled. And with his patience and help, this was the result:

The HTML is almost as explained before, and looks like:

<html xmlns="">

<h1>Chemical RDFa with Operator</h1>

<div about="#chem_123" xmlns:chem="">
Methane has the following identifier: <span property="chem:inchi">InChI=1/CH4/h1H4</span>


It is important here to wrap the statement in a <div> element and to add the @about attribute to it, defining the Subject. Moreover, you need to use the @property attributes instead of @class. The content of this attribute defined the Predicate, and the content of the <span> element is the Object, completing the RDF triple.

Operator detects these RDFa statements from the HTML, and creates a new menu item Search in Pubchem using this piece of code:
var pubchem_inchi = {
description: "Search in PubChem",
short: "PubChem",
scope: {
semantic: {
"RDFa" : {
property : "",
defaultNS : ""
doAction: function(semanticObject, semanticObjectType) {
if (semanticObjectType == "RDFa") {
return "" + semanticObject.inchi + "%22[InChI]";

SemanticActions.add("pubchem_inchi", pubchem_inchi);

You can reproduce this by installing Operator 0.8a in Firefox, saving the script to a file in your home directory, and reading it via the Operator "Options" dialog. Make sure to also set the Display Style in the General tab of the dialog to Data formats. Only then will the RDFa magic kick in.

Adding support for eMolecules, ChemSpider and whatever else we like is easy now. What I still need to explore (or ask Mike), is how I can trigger the Open With/Save As dialog of Firefox.


  1. Cool ! I was looking for such a usage of RDFa ! Thanks ! your next step will be GRDDL ?

  2. Yes, GRDDL is very high on the list. But first I will write a plugin for Bioclipse that will be able to process the created RDF, so that I can easily visualize it.

    BTW, writing a Bioclipse/RCP plugin is easier than it sounds. At the workshop in May we had participants do it in less than two hours.

  3. You can use actions mode as well, but you have to explictly add "Search in PubChem" as an action. You can do this on Options->Actions.

    Also, you might want to add:

    as an icon to your action.

    Finally, we recognize rdfa:label to use as the label for the dropdown, so if you want to have something other than the RDFa subject as the dropdown, you can use add


    to whatever you want to use as the menu name.

  4. Your script will work in Operator 8.0+ if you change RDFa to RDF.

    Thanks for the script!

  5. Try