Pages

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 Postgenomic.com 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="http://www.w3.org/2002/06/xhtml2/">

<h1>Chemical RDFa with Operator</h1>

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

</html>

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 : "http://www.blueobelisk.org/chemistryblogs/inchi",
defaultNS : "http://www.blueobelisk.org/chemistryblogs/"
}
}
},
doAction: function(semanticObject, semanticObjectType) {
if (semanticObjectType == "RDFa") {
return "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?CMD=search&DB=pccompound&term=%22" + 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.