Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

bits

  • Loading branch information...
commit c7d5923db6ff2f14d026789102319bf719a34498 1 parent cdc2775
@danja authored
View
15 baked/bookmarks/b1.ttl
@@ -0,0 +1,15 @@
+# Baked by Seki
+
+<http://hyperdata.org/bookmarks/b1>
+ <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
+ <x:Bookmark> ;
+ <http://purl.org/dc/terms/date>
+ "2012-04-17T16:06:30.413Z" ;
+ <http://purl.org/dc/terms/title>
+ "bookmark1" ;
+ <http://rdfs.org/sioc/ns#content>
+ "test" ;
+ <http://xmlns.com/foaf/0.1/maker>
+ [ <http://xmlns.com/foaf/0.1/nick>
+ "danja"
+ ] .
View
58 baked/meta.ttl
@@ -1,15 +1,43 @@
-# Graphs baked by Seki
-
-@prefix stuff: <http://purl.org/stuff> .
-
-<http://hyperdata.org/seki/Hello> a stuff:Graph .
-<http://hyperdata.org/seki/HelloAgain> a stuff:Graph .
-<http://hyperdata.org/seki/HelloThree> a stuff:Graph .
-<http://hyperdata.org/seki/Hello5> a stuff:Graph .
-<http://hyperdata.org/seki/Hello4> a stuff:Graph .
-<http://hyperdata.org/seki/Q> a stuff:Graph .
-<http://hyperdata.org/seki/Hello9> a stuff:Graph .
-<http://hyperdata.org/A> a stuff:Graph .
-<http://hyperdata.org/D> a stuff:Graph .
-<http://hyperdata.org/E> a stuff:Graph .
-<http://hyperdata.org/Hello> a stuff:Graph .
+# Graphs baked by <http://hyperdata.org/E>
+ <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
+ <http://purl.org/stuffGraph> .
+
+<http://hyperdata.org/seki/HelloAgain>
+ <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
+ <http://purl.org/stuffGraph> .
+
+<http://hyperdata.org/D>
+ <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
+ <http://purl.org/stuffGraph> .
+
+<http://hyperdata.org/seki/Q>
+ <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
+ <http://purl.org/stuffGraph> .
+
+<http://hyperdata.org/A>
+ <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
+ <http://purl.org/stuffGraph> .
+
+<http://hyperdata.org/seki/Hello5>
+ <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
+ <http://purl.org/stuffGraph> .
+
+<http://hyperdata.org/seki/HelloThree>
+ <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
+ <http://purl.org/stuffGraph> .
+
+<http://hyperdata.org/seki/Hello>
+ <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
+ <http://purl.org/stuffGraph> .
+
+<http://hyperdata.org/Hello>
+ <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
+ <http://purl.org/stuffGraph> .
+
+<http://hyperdata.org/seki/Hello9>
+ <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
+ <http://purl.org/stuffGraph> .
+
+<http://hyperdata.org/seki/Hello4>
+ <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
+ <http://purl.org/stuffGraph> .
View
4 src/Constants.js
@@ -4,6 +4,10 @@ var constants = {
".rdf" : "application/rdf+xml",
".html" : "text/html"
// ".json" : "text/json" ??
+ },
+ rdfsTypes : {
+ "bookmark" : "x:Bookmark",
+ "post" : "sioc:Post"
}
};
View
12 src/SpecialPages.js
@@ -0,0 +1,12 @@
+var sparqlTemplates = require('./sparqlTemplates');
+var htmlTemplates = require('./htmlTemplates');
+
+var special = {
+ "/graphs" : {
+ sparqlTemplate : sparqlTemplates.listGraphURIs,
+ htmlTemplate : htmlTemplates.uriList
+ }
+
+};
+
+module.exports = special;
View
8 src/Utils.js
@@ -0,0 +1,8 @@
+var utils = {
+ mintURI : function(seedURI){
+ return "http://hyperdata.org/X";
+ }
+
+};
+
+module.exports = utils;
View
8 src/admin/Admin.js
@@ -1,9 +1,11 @@
var fs = require('fs');
+var Constants = require('../Constants');
+
var TurtleHandler = require('../TurtleHandler');
var config = require('../ConfigDefault').config;
var FileReader = require('./FileReader');
-var Constants = require('../Constants');
+
// Constructor
function Admin(sekiRequest, sekiResponse) {
@@ -48,8 +50,8 @@ Admin.prototype = {
var dir = "";
for ( var i = 0; i < dirs.length - 1; i++) {
dir += dirs[i];
- // console.log("trying to create dir " + dir);
- fs.mkdir(dir);
+ console.log("trying to create dir " + dir);
+ fs.mkdir(dir); // NEED OPTIONS HERE??
dir += "/";
}
View
21 src/htmlTemplates.js
@@ -5,7 +5,22 @@
var htmlTemplates = {
- viewTemplate : "<!DOCTYPE html> \
+ uriList : "<!DOCTYPE html> \
+ <html> \
+ <head> \
+ <meta charset=\"utf-8\"> \
+ <title>%title%</title> \
+ </head> \
+ <body> \
+ <h1>%title%</h1> \
+ <ul> \
+ <li><a href=\"%uri%\">%uri%</a></li> \
+ </ul>\
+ </body> \
+ </html> \
+ ",
+
+ postViewTemplate : "<!DOCTYPE html> \
<html> \
<head> \
<meta charset=\"utf-8\"> \
@@ -17,9 +32,9 @@ var htmlTemplates = {
<p>By : %nick%, %date%</p> \
</body> \
</html> \
-",
+",
-creativeTemplate : "<!DOCTYPE html> \
+ creativeTemplate : "<!DOCTYPE html> \
<html> \
<head><meta charset='utf-8'> \
<title>Create new page</title> \
View
89 src/seki.js
@@ -6,7 +6,11 @@
*/
/* TODO
- * change to using http.request
+ * change to using http.request (have done?)
+ *
+ *
+ * figure out wat bindings
+ * mustache - foreach templates
*/
/*
@@ -22,6 +26,10 @@ var verbose = true;
/*
* Seki support scripts imports
*/
+
+var Constants = require('./Constants');
+var Utils = require('./Utils');
+
var templater = require('./templater');
var sparqlTemplates = require('./sparqlTemplates');
var htmlTemplates = require('./htmlTemplates');
@@ -30,6 +38,7 @@ var TurtleHandler = require('./TurtleHandler');
var JSONHandler = require('./JSONHandler');
var Admin = require('./admin/Admin');
var config = require('./ConfigDefault').config;
+var special = require('./SpecialPages');
var sekiHeaders = {
"Content-type" : "text/html; charset=utf-8",
@@ -133,13 +142,26 @@ function onRequest(sekiRequest, sekiResponse) {
var handler = new JSONHandler();
return handler[sekiRequest.method]();
}
+
// verbosity("Accept header =" + accept
// + accept.indexOf("application/rdf+xml" == 0));
// TODO pull these out into separate per-media type handlers
// use pattern as for JSONHandler
if (sekiRequest.method == "GET") {
-
+ var queryTemplate;
+ var viewTemplate;
+ //= templater(htmlTemplates.viewTemplate);
+
+ if(special[sekiRequest.url]) {
+ queryTemplate = special[sekiRequest.url].sparqlTemplate;
+ viewTemplate = special[sekiRequest.url].htmlTemplate;
+ }
+
+// console.log("special[sekiRequest.url] = "+special[sekiRequest.url]);
+// console.log("queryTemplate = "+queryTemplate);
+// console.log("viewTemplate = "+viewTemplate);
+
if (accept && accept.indexOf("text/turtle") == 0) {
verbosity("text/turtle requested");
var handler = new TurtleHandler();
@@ -148,9 +170,16 @@ function onRequest(sekiRequest, sekiResponse) {
}
// Assume HTML is acceptable
+
+ if(!queryTemplate) { // need smarter switching/lookup here
+ queryTemplate = sparqlTemplates.itemTemplate;
+ }
+ if(!viewTemplate) { // need smarter switching/lookup here
+ viewTemplate = htmlTemplates.itemTemplate;
+ }
// build the query
- var queryTemplater = templater(sparqlTemplates.itemTemplate);
+ var queryTemplater = templater(queryTemplate);
var replaceMap = {
"uri" : resource
};
@@ -166,7 +195,7 @@ function onRequest(sekiRequest, sekiResponse) {
// handle the response from the SPARQL server
clientRequest.on('response', function(queryResponse) {
- serveHTML(resource, sekiResponse, queryResponse);
+ serveHTML(resource, viewTemplate, sekiResponse, queryResponse);
});
// finish up
@@ -180,11 +209,10 @@ function onRequest(sekiRequest, sekiResponse) {
if (sekiRequest.method == "POST") {
// verbosity("Start of POST");
- /*
- * start building query - but it needs the data supplied in the body of
- * the request by the browser
- */
- var queryTemplater = templater(sparqlTemplates.insertTemplate);
+// check media type of data
+
+
+
var post_body = '';
// request body may come in chunks, join them together
@@ -197,8 +225,29 @@ function onRequest(sekiRequest, sekiResponse) {
// turn the POST parameters into JSON
var replaceMap = qs.parse(post_body);
+
+ var queryTemplater;
+ if(replaceMap.target) { // if a target URI is specified, it's an annotation
+ queryTemplater = templater(sparqlTemplates.insertAnnotationTemplate);
+ } else {
+ queryTemplater = templater(sparqlTemplates.insertTemplate);
+ }
+
replaceMap["date"] = new Date().toJSON();
-
+ var resourceType = replaceMap["type"];
+
+ // URI wasn't specified so generate one (if a target URI has been specified
+ // use that as a seed)
+ if(!replaceMap["uri"] || replaceMap["uri"] == ""){
+ replaceMap["uri"] = Utils.mintURI(replaceMap["target"]);
+ }
+
+ // graph wasn't specified so create named graph
+ if(!replaceMap["graph"] || replaceMap["graph"] == ""){
+ replaceMap["graph"] = replaceMap["uri"];
+ }
+ replaceMap["type"] = Constants.rdfsTypes[resourceType];
+
// verbosity("ReplaceMap = "+JSON.stringify(replaceMap));
// can now make the query
@@ -241,11 +290,16 @@ function onRequest(sekiRequest, sekiResponse) {
/*
* Handles GET requests (typically from a browser)
*/
-function serveHTML(resource, sekiResponse, queryResponse) {
+function serveHTML(resource, viewTemplate, sekiResponse, queryResponse) {
+ if(!viewTemplate){
+ viewTemplate = htmlTemplates.postViewTemplate;
+ }
// set up HTML builder
- var viewTemplater = templater(htmlTemplates.viewTemplate);
- // verbosity("GOT RESPONSE ");
+ var viewTemplater = templater(viewTemplate);
+
+
+ // verbosity("GOT RESPONSE viewTemplate "+viewTemplate);
var saxer = require('./srx2map');
var stream = saxer.createStream();
@@ -261,13 +315,16 @@ function serveHTML(resource, sekiResponse, queryResponse) {
stream.end();
var bindings = stream.bindings;
- if (bindings.title) { // // this is ugly
- verbosity("GOT: " + JSON.stringify(bindings));
+
+ verbosity("bindings " + JSON.stringify(bindings));
+ verbosity("bindings.uri " + bindings.uri);
+
+ if (bindings != {}) { // // this is shite
+ verbosity("here GOT: " + JSON.stringify(bindings));
// verbosity("TITLE: " + bindings.title);
verbosity("WRITING HEADERS " + JSON.stringify(sekiHeaders));
sekiResponse.writeHead(200, sekiHeaders);
var html = viewTemplater.fillTemplate(bindings);
- } else {
verbosity("404");
sekiResponse.writeHead(404, sekiHeaders);
// /////////////////////////////// refactor
View
39 src/sparqlTemplates.js
@@ -3,10 +3,10 @@
* parts like %this% will be replaced
*/
var sparqlTemplates = {
- // used to retrieve an item from the store for display
- // http://purl.org/dc/terms/
-
- itemTemplate : "PREFIX dcterms: <http://purl.org/dc/terms/> \
+ // used to retrieve an item from the store for display
+ // http://purl.org/dc/terms/
+
+ itemTemplate : "PREFIX dcterms: <http://purl.org/dc/terms/> \
PREFIX foaf: <http://xmlns.com/foaf/0.1/> \
PREFIX sioc: <http://rdfs.org/sioc/ns#> \
\
@@ -21,23 +21,40 @@ var sparqlTemplates = {
?maker foaf:nick ?nick . \
}",
- // used to insert a new item into the store
- insertTemplate : "PREFIX dcterms: <http://purl.org/dc/terms/> \
+ // used to insert a new item into the store
+ insertTemplate : "PREFIX dcterms: <http://purl.org/dc/terms/> \
PREFIX foaf: <http://xmlns.com/foaf/0.1/> \
PREFIX sioc: <http://rdfs.org/sioc/ns#> \
+ PREFIX x: <http://purl.org/stuff/> \
\
INSERT DATA { \
- GRAPH <%uri%>{\
+ GRAPH <%graph%>{\
\
- <%uri%> a sioc:Post ;\
+ <%uri%> a <%type%> ;\
dcterms:title \"%title%\";\
sioc:content \"%content%\" ;\
foaf:maker [ foaf:nick \"%nick%\" ] ;\
dcterms:date \"%date%\" .\
}}",
- listGraphURIs : "SELECT DISTINCT ?graph WHERE { GRAPH ?graph {} }"
-};
+ insertAnnotationTemplate : "PREFIX dcterms: <http://purl.org/dc/terms/> \
+ PREFIX foaf: <http://xmlns.com/foaf/0.1/> \
+ PREFIX sioc: <http://rdfs.org/sioc/ns#> \
+ PREFIX x: <http://purl.org/stuff/> \
+ \
+ INSERT DATA { \
+ GRAPH <%graph%>{\
+ \
+ <%uri%> a <%type%> ;\
+ x:target <%target%> ;\
+ dcterms:title \"%title%\";\
+ sioc:content \"%content%\" ;\
+ foaf:maker [ foaf:nick \"%nick%\" ] ;\
+ dcterms:date \"%date%\" .\
+ }}",
+
+ listGraphURIs : "SELECT DISTINCT ?graph WHERE { GRAPH ?graph {} }"
+}; // sioc:Post
-//make it visible to other scripts
+// make it visible to other scripts
module.exports = sparqlTemplates;
View
9 src/wat.js
@@ -0,0 +1,9 @@
+var wat = {};
+
+if( wat == {} ){
+ console.log("wat == {} is true");
+} else {
+ console.log("wat == {} is false");
+}
+
+console.log("wat = " +wat);
View
7 www/miniform.html
@@ -13,10 +13,11 @@
<p>
<form action="/post" method="post">
-<input type="hidden" value="bookmark" name="type" />
+<input type="hidden" value="annotation" name="type" />
+<input type="hidden" name="graph" value="http://hyperdata.org/danja/bookmarks" />
- <label for="uri">Item URI</label>
- <input type="text" name="uri" id="uri" />
+ <label for="target">Target URI</label>
+ <input type="text" name="target" id="target" />
<label for="title">Title</label>
<input type="text" name="title" id="title" />
View
1  www/sparql/graphs.rq
@@ -0,0 +1 @@
+SELECT DISTINCT ?graph WHERE { GRAPH ?graph {} }
Please sign in to comment.
Something went wrong with that request. Please try again.