Skip to content

Instantly share code, notes, and snippets.

@kwijibo
Created April 28, 2009 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwijibo/103269 to your computer and use it in GitHub Desktop.
Save kwijibo/103269 to your computer and use it in GitHub Desktop.
schemacache lookup ubiquity command
CmdUtils.CreateCommand({
name: "schemacache",
takes: {"term": noun_arb_text},
homepage: "http://schemacache.com/",
author: { name: "Keith Alexander", email: "keith.alexander@talis.com"},
license: "MPL",
description: "performs a lookup on SchemaCache (http://schemacache.com)",
preview: function(previewBlock, term) {
previewBlock.innerHTML = "Looking up " + term.text + " at SchemaCache ... ";
var baseURI = "http://schemacache.com/Search.json?q=" + term.text;
//displayMessage(sparams.q);
jQuery.ajax({
type: "GET",
url: baseURI,
datatype: "string",
error: function(responseData) {
previewBlock.innerHTML = "<em>Error:" + responseData+ "</em>";
},
success: function(responseData) {
var rdf = Utils.decodeJson(responseData);
var list = '<ol>';
jQuery.each(rdf, function(uri, props){
CmdUtils.log(uri);
try { label = props['http://www.w3.org/2000/01/rdf-schema#label'][0]['value']; } catch (e) { label = uri }
try {
types = '';
jQuery.each(props['http://www.w3.org/1999/02/22-rdf-syntax-ns#type'], function(){ types+=' '+this.value.match(/[^\/#]+$/)[0]});
} catch(e) { types = 'Resource'}
var description = ''
if(props['http://www.w3.org/2000/01/rdf-schema#comment']){
description = props['http://www.w3.org/2000/01/rdf-schema#comment'][0]['value'];
}
var linkType = 'Res';
if(types.match('Ontology')) linkType = 'Schema';
list+='<li><a href="'+uri+'">'+label+'</a> <strong>'+types.replace(' item ', ' ')+'</strong> <div><em>'+description+'</em></div> <div><a href="http://schemacache.test.talis.com/'+linkType+'/?uri='+encodeURIComponent(uri)+'">cache</a></div> </li>';
});
CmdUtils.log(rdf, list);
previewBlock.innerHTML = list;
}
});
},
execute: function(term) {
Utils.openUrlInBrowser("http://schemacache.com/Search?q=" + term.text);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment