Skip to content

Instantly share code, notes, and snippets.

@samuell
Created September 15, 2010 11:22
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 samuell/580590 to your computer and use it in GitHub Desktop.
Save samuell/580590 to your computer and use it in GitHub Desktop.
/**
* @title: Testing the Semantic MediaWiki connector plugin
* @author: samuel.lampa@gmail.com
**/
// Get RDF Data from Wiki
var wikiURL = "http://drugmet.rilspace.org/wiki/";
var rdfXml = smw.getTriples( wikiURL, 0 );
// Write RDF to a local file
var now = getDateTimeString();
var rdfXmlFile = "My Test Project/output." + now + ".rdf.xml";
ui.newFile( rdfXmlFile, rdfXml );
// Query the local file with SPARQL
var tripleStore = rdf.createStore("rdfStore001");
rdf.importFile( tripleStore2, rdfXmlFile, "RDF/XML" )
var sparqlString = "SELECT ?s WHERE {?s ?p ?o}";
rdf.sparql( tripleStore, sparqlString );
/************** Utility functions ***************/
function getDateTimeString() {
var d = new Date();
var now = d.getFullYear() + "-" +
pad( d.getMonth(), 2 ) + "-" +
pad( d.getDate(), 2 ) + "." +
pad( d.getHours(), 2 ) + "." +
pad( d.getMinutes(), 2 ) + "." +
pad( d.getSeconds(), 2 );
return now;
}
function pad(number, length) {
var str = '' + number;
while (str.length < length) {
str = '0' + str;
}
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment