-
-
Save kwijibo/103269 to your computer and use it in GitHub Desktop.
schemacache lookup ubiquity command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CmdUtils.CreateCommand({ | |
name: "schemacache", | |
takes: {"term": noun_arb_text}, | |
homepage: "http://schemacache.com/", | |
author: { name: "Keith Alexander", email: "[email protected]"}, | |
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