Tuesday, January 31, 2017

Links working with D3

 D3 seems to be a functional programming interfact to the document object model.

https://d3js.org/

https://github.com/d3/d3/blob/master/API.md

https://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-textContent

https://www.dashingd3js.com/svg-text-element

https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Getting_Started

notes from exporting a library with browserify so that it can be used with require.js

Exporting a library with browserify, so that it can be used by require.js

http://dontkry.com/posts/code/browserify-and-the-universal-module-definition.html

based on:

http://ifandelse.com/its-not-hard-making-your-library-support-amd-and-commonjs/ 

edit: also see:

https://www.leanpanda.com/blog/2015/06/28/amd-requirejs-commonjs-browserify/

or try:

http://webpack.github.io/docs/usage.html

edit: target:
https://github.com/RubenVerborgh/N3.js

edit: notes from interactions with Dr. Verborgh :

 "The generated n3-browser.js is standalone and not for usage with require.

To obtain a library for usage with require, you have to use a utility such as browserify (http://browserify.org/).
N3.js is designed for compatibility with browserify. Then you can continue your exact use case.
(See https://github.com/RubenVerborgh/N3.js#installation.)"

"This gives in the browser:
> Util,Lexer,Parser,Writer,Store....

Indeed, that's how n3-browser.js works:
it exposes a global N3 object."

Saturday, January 28, 2017

Bookmarks for getting a callback to work with node

https://www.youtube.com/watch?v=nwXwoibiuGI
(OK Coders Express Intro)

http://stackoverflow.com/questions/6847697/how-to-return-value-from-an-asynchronous-callback-function
(How to return value from an asynchronous callback function? [duplicate])



Bookmarks for getting a node library working in the browser

https://github.com/RubenVerborgh/N3.js
(Lightning fast, spec-compatible, streaming RDF for JavaScript)

 https://davidwalsh.name/upgrade-nodejs
 (Upgrade Node.js via NPM)

https://docs.npmjs.com/getting-started/installing-node
(Installing Node.js and updating npm)

https://scotch.io/tutorials/getting-started-with-browserify
(Getting Started with Browserify) --- this last link is not needed if the "
$ cd N3.js
$ npm install
$ npm run browser
"  is followed with updgrated nodejs and npm

Friday, January 27, 2017

More experiments with rdflib.js

This code:
 
var store = $rdf.graph()
var timeout = 5000 // 5000 ms timeout
var fetcher = new $rdf.Fetcher(store, timeout)
var url = 'http://localhost/node-arc-p5/data/Food-Growing-Methods.ttl';

fetcher.nowOrWhenFetched(url, function(ok, body, xhr) {
    if (!ok) {
        console.log("Oops, something happened and couldn't fetch data");
    } else {
         document.write(store);
    }
})
 

https://github.com/bshambaugh/node-arc-p5/blob/master/js/tests/test2-rdflib.js
 

produces this output:
{_:n1 <http://www.w3.org/2000/01/rdf-schema#label> "[17:18:6]  Request for http://localhost/node-arc-p5/data/Food-Growing-Methods.ttl" .
_:n1 <http://www.w3.org/2007/ont/link#requestedURI> "http://localhost/node-arc-p5/data/Food-Growing-Methods.ttl" .
_:n1 <http://www.w3.org/2007/ont/link#status> _:n2 .
_:n1 <http://www.w3.org/2007/ont/link#response> _:n3 .
_:n3 <http://www.w3.org/2007/ont/http#status> "200" .
_:n3 <http://www.w3.org/2007/ont/http#statusText> "OK" .
_:n3 <http://www.w3.org/2007/ont/httph#date> "Fri, 27 Jan 2017 23:10:32 GMT" .
_:n3 <http://www.w3.org/2007/ont/httph#server> "Apache/2.4.7 (Ubuntu)" .
_:n3 <http://www.w3.org/2007/ont/httph#last-modified> "Fri, 27 Jan 2017 21:20:24 GMT" .
_:n3 <http://www.w3.org/2007/ont/httph#etag> "\"456-5471a08b84856\"" .
_:n3 <http://www.w3.org/2007/ont/httph#accept-ranges> "bytes" .
_:n3 <http://www.w3.org/2007/ont/httph#content-length> "1110" .
_:n3 <http://www.w3.org/2007/ont/httph#content-type> "text/turtle" .
<http://localhost/node-arc-p5/data/Food-Growing-Methods.ttl> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/iana/media-types/text/turtle#Resource> .
<http://localhost/node-arc-p5/data/Food-Growing-Methods.ttl> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2007/ont/link#Document> .
<http://localhost/node-arc-p5/data/Food-Growing-Methods.ttl> <http://purl.org/dc/terms/title> "Food Growing Methods" .
<http://localhost/node-arc-p5/data/Food-Growing-Methods.ttl> <http://www.w3.org/2000/01/rdf-schema#comment> "For independence and resource optimization, some or all of the astronauts' diet must be grown in-situ. Various forms have been proposed, from greenhouses to hydroponics, but there must also be optimization in the types of food grown to maximize caloric and nutrient output compared to water and energy input." .
<http://localhost/node-arc-p5/data/Food-Growing-Methods.ttl> <http://data.thespaceplan.com/ontologies/lsi#averageEstInvestmentCost> "0.0(investment cost pulled from children pages)" .
<http://localhost/node-arc-p5/data/Food-Growing-Methods.ttl> <http://data.thespaceplan.com/ontologies/lsi#averageEstTimetoMaturity> "0.0 (time to maturity pulled from children pages)" .
<http://localhost/node-arc-p5/data/Food-Growing-Methods.ttl> <http://data.thespaceplan.com/ontologies/lsi#commercialStatus> "Research" .
<http://localhost/node-arc-p5/data/Food-Growing-Methods.ttl> <http://data.thespaceplan.com/ontologies/lsi#relatedIndustriesFields> "Health and Medicine" .
<http://localhost/node-arc-p5/data/Food-Growing-Methods.ttl> <http://data.thespaceplan.com/ontologies/lsi#label> <http://investors.ddns.net:8080/marmotta/ldp/waypaver-lsi/biological-support> .
<http://localhost/node-arc-p5/data/Food-Growing-Methods.ttl> <http://data.thespaceplan.com/ontologies/lsi#label> <http://investors.ddns.net:8080/marmotta/ldp/waypaver-lsi/habitation-infrastructure> .
<http://localhost/node-arc-p5/data/Food-Growing-Methods.ttl> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2007/ont/link#RDFDocument> .}

 
I'm not sure how to extract on the elements of the object that contain 
<http://localhost/node-arc-p5/data/Food-Growing-Methods.ttl> .

Comparison of JavaScript libraries for RDF -- trying N3.js

See a comparison of rdfjs-libraries:

https://www.w3.org/community/rdfjs/wiki/Comparison_of_RDFJS_libraries

At this point, I may be inexperienced with JavaScript. I'm going to try N3.js, which provides more examples:

https://github.com/RubenVerborgh/N3.js

Experiments with rdflib.js

https://github.com/linkeddata/rdflib.js

https://github.com/solid/solid-tutorial-rdflib.js

-------------------------------------

// requirejs closure that imports the rdflib.js script into the $rdf variable
define(['rdflib'], function($rdf) {

// Namespaces
var RDF = $rdf.Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#");
var RDFS = $rdf.Namespace("http://www.w3.org/2000/01/rdf-schema#");
var FOAF = $rdf.Namespace("http://xmlns.com/foaf/0.1/");
var OWL = $rdf.Namespace("http://www.w3.org/2002/07/owl#");
var SPACE = $rdf.Namespace("http://www.w3.org/ns/pim/space#");
var UI = $rdf.Namespace("http://www.w3.org/ns/ui#");
var DCT = $rdf.Namespace("http://purl.org/dc/terms/");
var CERT = $rdf.Namespace("http://www.w3.org/ns/auth/cert#");
var ACL = $rdf.Namespace("http://www.w3.org/ns/auth/acl#");

// method to create a store for rdf graph
var store = $rdf.graph()
var timeout = 5000 // 5000 ms timeout

// creates a new fetcher object
var fetcher = new $rdf.Fetcher(store, timeout)

// Loading this url requires in browser webid verification
var url = 'https://bshambaugh.databox.me/profile/card#me';
//var url = 'http://data.thespaceplan.com/isp.rdf';

fetcher.nowOrWhenFetched(url, function(ok, body, xhr) {
    if (!ok) {
        console.log("Oops, something happened and couldn't fetch data");
    } else {
        // do something with the data in the store (see below)
        document.write(store);
    }
})

var me = $rdf.sym('https://www.w3.org/People/Berners-Lee/card#i');
store.add(me, FOAF('knows'), $rdf.sym('https://fred.me/profile#me'));

//store.add(me, FOAF('knows'), $rdf.sym('https://fred.me/profile#me'));
//store.add(me, FOAF('name'), "Albert Bloggs");
//document.write(store);
});

---------------------------------

using

document.write('name  :' + '   typeof');
document.write('<br><br>');
var properties = Object.getOwnPropertyNames($rdf);
for(var i = 0; i < properties.length; i++) {
  var g = (properties[i]);
  var p = typeof $rdf[g];
  document.write(properties[i] + '   :   ' + p);
  document.write('<br>');
}


(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames_ )

gives:

name : typeof

BlankNode : function
Collection : function
convert : object
DataFactory : object
Empty : function
Fetcher : function
Formula : function
IndexedFormula : function
jsonParser : object
Literal : function
log : object
N3Parser : function
NamedNode : function
Namespace : function
Node : function
parse : function
Query : function
queryToSPARQL : function
RDFaProcessor : function
RDFParser : function
serialize : function
Serializer : function
SPARQLToQuery : function
sparqlUpdateParser : function
Statement : function
term : function
UpdateManager : function
UpdatesSocket : function
UpdatesVia : function
uri : object
Util : object
Variable : function
NextId : number
fromNT : function
fetcher : function
graph : function
lit : function
st : function
sym : function
variable : function
blankNode : function
defaultGraph : function
literal : function
namedNode : function
quad : function
triple : function

// console.log(Object.getOwnPropertyNames($rdf.graph()));


document.write('name  :' + '   typeof');
document.write('<br><br>');
var properties = Object.getOwnPropertyNames($rdf.graph());
for(var i = 0; i < properties.length; i++) {
  var g = (properties[i]);
  var p = typeof $rdf[g];
  document.write(properties[i] + '   :   ' + p);
  document.write('<br>');
}

gives:


termType : undefined
statements : undefined
constraints : undefined
initBindings : undefined
optional : undefined
propertyActions : undefined
classActions : undefined
redirections : undefined
aliases : undefined
HTTPRedirects : undefined
subjectIndex : undefined
predicateIndex : undefined
objectIndex : undefined
whyIndex : undefined
index : undefined
namespaces : undefined
features : undefined


document.write('name  :' + '   typeof');
document.write('<br><br>');
var properties = Object.getOwnPropertyNames($rdf.convert);
for(var i = 0; i < properties.length; i++) {
  var g = (properties[i]);
  var p = typeof $rdf[g];
  document.write(properties[i] + '   :   ' + p);
  document.write('<br>');
}

gives:

name : typeof

convertToJson : undefined
convertToNQuads : undefined






document.write('name  :' + '   typeof');
document.write('<br><br>');
var properties = Object.getOwnPropertyNames($rdf.DataFactory);
for(var i = 0; i < properties.length; i++) {
  var g = (properties[i]);
  var p = typeof $rdf[g];
  document.write(properties[i] + '   :   ' + p);
  document.write('<br>');
}




gives:



name : typeof

blankNode : function
defaultGraph : function
graph : function
literal : function
namedNode : function
quad : function
triple : function
variable : function
collection : undefined
fetcher : function
lit : function
st : function

document.write('name  :' + '   typeof');
document.write('<br><br>');
var properties = Object.getOwnPropertyNames($rdf.jsonParser);
for(var i = 0; i < properties.length; i++) {
  var g = (properties[i]);
  var p = typeof $rdf[g];
  document.write(properties[i] + '   :   ' + p);
  document.write('<br>');
}




gives:

name : typeof

parseJSON : undefined







 document.write('name  :' + '   typeof');
document.write('<br><br>');
var properties = Object.getOwnPropertyNames($rdf.log);
for(var i = 0; i < properties.length; i++) {
  var g = (properties[i]);
  var p = typeof $rdf[g];
  document.write(properties[i] + '   :   ' + p);
  document.write('<br>');
}

gives:

name : typeof

debug : undefined
warn : undefined
info : undefined
error : undefined
success : undefined
msg : undefined

document.write('name  :' + '   typeof');
document.write('<br><br>');
var properties = Object.getOwnPropertyNames($rdf.uri);
for(var i = 0; i < properties.length; i++) {
  var g = (properties[i]);
  var p = typeof $rdf[g];
  document.write(properties[i] + '   :   ' + p);
  document.write('<br>');
}

gives:

name : typeof

docpart : undefined
document : undefined
hostpart : undefined
join : undefined
protocol : undefined
refTo : undefined

document.write('name  :' + '   typeof');
document.write('<br><br>');
var properties = Object.getOwnPropertyNames($rdf.Util);
for(var i = 0; i < properties.length; i++) {
  var g = (properties[i]);
  var p = typeof $rdf[g];
  document.write(properties[i] + '   :   ' + p);
  document.write('<br>');
}

gives:

name : typeof

AJAR_handleNewTerm : undefined
ArrayIndexOf : undefined
callbackify : undefined
dtstamp : undefined
DOMParserFactory : undefined
domToString : undefined
dumpNode : undefined
getHTTPHeaders : undefined
heavyCompare : undefined
heavyCompareSPO : undefined
output : undefined
parseXML : undefined
RDFArrayRemove : undefined
stackString : undefined
string_startswith : undefined
string : undefined
uri : object
XMLHTTPFactory : undefined
log : object
mediaTypeClass : undefined

------------------------------
var properties = Object.getOwnPropertyNames($rdf);
for(var i = 0; i < properties.length; i++) {
  var g = (properties[i]);
  var p = typeof $rdf[g];
  if(p === 'function') {
    document.write(g);
    document.write('<br>');
    document.write($rdf[g]);
    document.write('<br><br><br>');
  }
//  document.write(properties[i] + '   :   ' + p);
//  document.write('<br>');
}



gives:


name : typeof

BlankNode
function t(e){ "use strict"; _classCallCheck(this,t);var r=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return r.termType=t.termType,r.id=t.nextId++,r.value=e||r.id.toString(),r}


Collection
function t(e){ "use strict"; _classCallCheck(this,t);var n=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return n.termType=t.termType,n.id=BlankNode.nextId++,n.elements=[],n.closed=!1,e&&e.length>0&&e.forEach(function(e){n.elements.push(Node.fromValue(e))}),n}


Empty
function t(){ "use strict"; _classCallCheck(this,t);var e=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return e.termType=t.termType,e}


Fetcher
function e(t,r,a){ "use strict"; this.store=t,this.thisURI="http://dig.csail.mit.edu/2005/ajar/ajaw/rdf/sources.js#SourceFetcher",this.timeout=r||3e4,this.async=null==a||a,this.appNode=this.store.bnode(),this.store.fetcher=this,this.requested={},this.redirectedTo={},this.fetchCallbacks={},this.nonexistant={},this.lookedUp={},this.handlers=[],this.mediatypes={};var i=this,n=this.store,s={};s.link=Namespace("http://www.w3.org/2007/ont/link#"),s.http=Namespace("http://www.w3.org/2007/ont/http#"),s.httph=Namespace("http://www.w3.org/2007/ont/httph#"),s.rdf=Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#"),s.rdfs=Namespace("http://www.w3.org/2000/01/rdf-schema#"),s.dc=Namespace("http://purl.org/dc/elements/1.1/"),i.mediatypes["image/*"]={q:.9},i.mediatypes["*/*"]={q:.1},e.crossSiteProxy=function(t){return e.crossSiteProxyTemplate?e.crossSiteProxyTemplate.replace("{uri}",encodeURIComponent(t)):void 0},e.RDFXMLHandler=function(e){e&&(this.dom=e[0]),this.handlerFactory=function(e){e.handle=function(t){var r=i.store;this.dom||(this.dom=Util.parseXML(e.responseText));var a=this.dom.documentElement;if("parsererror"===a.nodeName)throw i.failFetch(e,"Badly formed XML in "+e.resource.uri),new Error("Badly formed XML in "+e.resource.uri);var n=new RDFParser(r);try{n.parse(this.dom,e.original.uri,e.original)}catch(t){i.addStatus(e.req,"Syntax error parsing RDF/XML! "+t),console.log("Syntax error parsing RDF/XML! "+t)}e.options.noMeta||r.add(e.original,s.rdf("type"),s.link("RDFDocument"),i.appNode),t()}}},e.RDFXMLHandler.toString=function(){return"RDFXMLHandler"},e.RDFXMLHandler.register=function(e){e.mediatypes["application/rdf+xml"]={q:.9}},e.RDFXMLHandler.pattern=new RegExp("application/rdf\\+xml"),e.XHTMLHandler=function(e){e&&(this.dom=e[0]),this.handlerFactory=function(e){e.handle=function(t){var r,a;this.dom||(this.dom=Util.parseXML(e.responseText));var n=i.store,o=this.dom.getElementsByTagName("title");o.length>0&&n.add(e.resource,s.dc("title"),n.literal(o[0].textContent),e.resource);for(var d=this.dom.getElementsByTagName("link"),l=d.length-1;l>=0;l--)r=d[l].getAttribute("rel"),a=!1,r||(r=d[l].getAttribute("rev"),a=!0),r&&i.linkData(e,r,d[l].getAttribute("href"),e.resource,a);for(var c=this.dom.getElementsByTagName("script"),u=0;u]+\?>/))return i.addStatus(e.req,"Has an XML declaration. We'll assume it's XHTML as the content-type was text/html.\n"),void i.switchHandler("XHTMLHandler",e,t);if(r.match(/.*/))return i.addStatus(e.req,"Has XHTML DOCTYPE. Switching to XHTMLHandler.\n"),void i.switchHandler("XHTMLHandler",e,t);if(r.match(/[^(/))return i.addStatus(e.req,"Has default namespace for XHTML, so switching to XHTMLHandler.\n"),void i.switchHandler("XHTMLHandler",e,t);var a=new RegExp("","im").exec(r);if(a){var n=i.store;return n.add(e.resource,s.dc("title"),n.literal(a[1]),e.resource),n.add(e.resource,s.rdf("type"),s.link("WebPage"),i.appNode),void t()}i.addStatus(e.req,"non-XML HTML document, not parsed for data."),i.doneFetch(e)}}},e.HTMLHandler.toString=function(){return"HTMLHandler"},e.HTMLHandler.register=function(e){e.mediatypes["text/html"]={q:.9}},e.HTMLHandler.pattern=new RegExp("text/html"),e.TextHandler=function(){this.handlerFactory=function(e){e.handle=function(t){var r=e.responseText;return r.match(/\s*<\?xml\s+version\s*=[^<>]+\?>/)?(i.addStatus(e.req,"Warning: "+e.resource+" has an XML declaration. We'll assume it's XML but its content-type wasn't XML.\n"),void i.switchHandler("XMLHandler",e,t)):r.slice(0,500).match(/xmlns:/)?(i.addStatus(e.req,"May have an XML namespace. We'll assume it's XML but its content-type wasn't XML.\n"),void i.switchHandler("XMLHandler",e,t)):(i.addStatus(e.req,"Plain text document, no known RDF semantics."),void i.doneFetch(e))}}},e.TextHandler.toString=function(){return"TextHandler"},e.TextHandler.register=function(e){e.mediatypes["text/plain"]={q:.5}},e.TextHandler.pattern=new RegExp("text/plain"),e.N3Handler=function(){this.handlerFactory=function(e){e.handle=function(t){var r=N3Parser(n,n,e.original.uri,e.original.uri,null,null,"",null);try{r.loadBuf(e.responseText)}catch(t){var a="Error trying to parse "+e.resource+" as Notation3:\n"+t+":\n"+t.stack;return void i.failFetch(e,a)}i.addStatus(e.req,"N3 parsed: "+r.statementCount+" triples in "+r.lines+" lines."),i.store.add(e.original,s.rdf("type"),s.link("RDFDocument"),i.appNode),i.doneFetch(e)}}},e.N3Handler.toString=function(){return"N3Handler"},e.N3Handler.register=function(e){e.mediatypes["text/n3"]={q:"1.0"},e.mediatypes["text/turtle"]={q:1}},e.N3Handler.pattern=new RegExp("(application|text)/(x-)?(rdf\\+)?(n3|turtle)"),Util.callbackify(this,["request","recv","headers","load","fail","refresh","retract","done"]),this.addHandler=function(e){i.handlers.push(e),e.register(i)},this.switchHandler=function(t,r,a,n){for(var s=null,o=0;o failed: "+t,e);return delete this.fetchCallbacks[e.original.uri],this.fireCallbacks("fail",[e.original.uri,t]),e.abort(),e},this.linkData=function(e,t,r,a,i){if(r){var o,d=n.sym(Uri.join(r,e.original.uri));if("alternate"===t||"seeAlso"===t||"meta"===t||"describedby"===t){if(d.uri===e.original.uri)return;o=s.rdfs("seeAlso")}else o="type"===t?n.sym("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"):n.sym(Uri.join(t,"http://www.iana.org/assignments/link-relations/"));i?n.add(d,o,e.original,a):n.add(e.original,o,d,a)}},this.parseLinkHeader=function(e,t){var r;try{r=e.getResponseHeader("link")}catch(e){}if(r)for(var a=/<[^>]*>\s*(\s*;\s*[^\(\)<>@,;:"\/\[\]\?={} \t]+=(([^\(\)<>@,;:"\/\[\]\?={} \t]+)|("[^"]*")))*(,|$)/g,i=/[^\(\)<>@,;:"\/\[\]\?={} \t]+=(([^\(\)<>@,;:"\/\[\]\?={} \t]+)|("[^"]*"))/g,n=r.match(a),s=0;s"),d=o[0].substring(1),l=o[1],c=l.match(i),u=0;u=200&&s.status<300;r.noMeta||"undefined"==typeof tabulator||a.saveResponseMetadata(s,a.store),e?i(s):n(s.status+" "+s.statusText)}},s.open(e,t,!0),s.setRequestHeader("Content-type",r.contentType||"text/turtle"),s.send(r.data?r.data:void 0)})},this.webCopy=function(e,t,r){var a=this;return e=e.uri||e,new Promise(function(i,n){a.webOperation("GET",e).then(function(e){a.webOperation("PUT",t,{data:e.responseText,contentType:r}).then(function(e){i(e)}).catch(function(e){n(e)})}).catch(function(e){n(e)})})},this.lookUpThing=function(e,t,r,a,i){var s,o=n.uris(e),d=!0,l="",c={};if(r===!1||r===!0?(s=r,r={force:s}):(void 0===r&&(r={}),s=!!r.force),"undefined"!=typeof o)for(var u=0;u0||i&&i(d,l)})};f(h)}return o.length},this.load=function(e,t){var r=this;if(e instanceof Array){var a=e.map(function(e){return r.load(e)});return Promise.all(a)}return e=e.uri||e,new Promise(function(a,i){r.nowOrWhenFetched(e,t,function(e,t,r){e?a(r):i(t)})})},this.nowOrWhenFetched=function(e,t,r,a){e=e.uri||e,"function"==typeof t?(a={},r=t):"undefined"==typeof t||(a=t instanceof NamedNode?{referingTerm:t}:t),this.requestURI(e,t,a||{},r)},this.get=this.nowOrWhenFetched,this.getHeader=function(e,t){for(var r=this.store,a=r.each(void 0,s.link("requestedURI"),e.uri),i=0;i Cross-site Proxy to <"+o+">"),t.aborted)return;var d=m.store,l=t.req;t.options.noMeta||d.add(l,s.http("redirectedTo"),d.sym(o),l),t.abort(),t.aborted=!0,m.addStatus(l,"redirected to new request"),m.requested[t.resource.uri]="redirected",m.redirectedTo[t.resource.uri]=o,m.fetchCallbacks[t.resource.uri]&&(m.fetchCallbacks[o]||(m.fetchCallbacks[o]=[]),m.fetchCallbacks[o]===m.fetchCallbacks[o].concat(m.fetchCallbacks[t.resource.uri]),delete m.fetchCallbacks[t.resource.uri]);var c=m.requestURI(o,t.resource,t.options,t.userCallback);if(c&&(c.proxyUsed=!0,c.original=t.original,console.log("Proxying but original still "+c.original)),c&&c.req)return void(t.options.noMeta||d.add(t.req,d.sym("http://www.w3.org/2007/ont/link#redirectedRequest"),c.req,m.appNode))}t.CORS_status=999}}},b=function(e){return function(){var r=function(){if(!e.handleResponseDone){e.handleResponseDone=!0;var r=null,i=e.req;m.fireCallbacks("recv",d);var o=m.store;if(m.saveResponseMetadata(e,o),m.fireCallbacks("headers",[{uri:t,headers:e.headers}]),0===e.status){if(console.log("Masked error - status 0 for "+e.resource.uri),v(e))return;return void(e.CORS_status=900)}if(e.status>=400){if(404===e.status&&(o.fetcher.nonexistant[e.resource.uri]=!0),e.responseText.length>10){var l=o.bnode();o.add(l,s.http("content"),o.literal(e.responseText),l),e.statusText&&o.add(l,s.http("statusText"),o.literal(e.statusText),l)}return void m.failFetch(e,"HTTP error for "+e.resource+": "+e.status+" "+e.statusText)}var c,u=e.headers["content-location"],h=function(e){var t=i;if(u){var r=o.any(t,s.link("requestedURI"));r!==u&&o.add(o.sym(u),s.rdf("type"),e,m.appNode)}for(;;){var a=o.any(t,s.link("requestedURI"));if(a&&a.value&&o.add(o.sym(a.value),s.rdf("type"),e,m.appNode),t=o.any(void 0,o.sym("http://www.w3.org/2007/ont/link#redirectedRequest"),t),!t)break;var n=o.any(t,o.sym("http://www.w3.org/2007/ont/link#response"));if(!n)break;var d=o.any(n,o.sym("http://www.w3.org/2007/ont/http#status"));if(!d)break;if("301"!==d&&"302"!==d)break}},p={rdf:"application/rdf+xml",owl:"application/rdf+xml",n3:"text/n3",ttl:"text/turtle",nt:"text/n3",acl:"text/n3",html:"text/html",xml:"text/xml"};if(200===e.status){h(s.link("Document"));var f=e.headers["content-type"];a.forceContentType&&(e.headers["content-type"]=a.forceContentType),(!f||f.indexOf("application/octet-stream")>=0)&&(c=p[e.resource.uri.split(".").pop()],c&&(e.headers["content-type"]=c)),f&&(0!==f.indexOf("image/")&&0!==f.indexOf("application/pdf")||h(o.sym("http://purl.org/dc/terms/Image"))),a.clearPreviousData&&o.removeDocument(e.resource)}if("file"!==Uri.protocol(e.resource.uri)&&"chrome"!==Uri.protocol(e.resource.uri)||(a.forceContentType?e.headers["content-type"]=a.forceContentType:(c=p[e.resource.uri.split(".").pop()],c?e.headers["content-type"]=c:e.headers["content-type"]="text/xml")),u){var g=Uri.join(e.resource.uri,u);if(!n&&g!==e.resource.uri&&m.requested[g]&&"done"===m.requested[g])return m.doneFetch(e),void e.abort();m.requested[g]=!0}for(var y=0;y Cross-site Proxy to <"+i+">"),e.aborted)return;var u=m.store,h=e.req;u.add(h,s.http("redirectedTo"),u.sym(i),h);var p=e.req=u.bnode();u.add(h,s.http("redirectedRequest"),p,e.req);var f=new Date,g="["+f.getHours()+":"+f.getMinutes()+":"+f.getSeconds()+"] ";u.add(p,s.rdfs("label"),u.literal(g+" Request for "+i),this.appNode),u.add(p,s.link("status"),u.collection(),this.appNode),u.add(p,s.link("requestedURI"),u.literal(i),this.appNode);var y=u.bnode();u.add(h,s.link("response"),y),e.abort(),e.aborted=!0,e.redirected=!0,m.addStatus(h,"redirected XHR"),m.fetchCallbacks[e.resource.uri]&&(m.fetchCallbacks[i]||(m.fetchCallbacks[i]=[]),m.fetchCallbacks[i]===m.fetchCallbacks[i].concat(m.fetchCallbacks[e.resource.uri]),delete m.fetchCallbacks[e.resource.uri]),m.fireCallbacks("redirected",d),m.requested[e.resource.uri]="redirected";var w=m.requestURI(i,e.resource,e.options||{},e.userCallback);if(w&&w.req)return void u.add(e.req,u.sym("http://www.w3.org/2007/ont/link#redirectedRequest"),w.req,m.appNode)}}m.failFetch(e,"HTTP Blocked. (ReadyState 0) Cross-site violation for <"+t+">");break;case 3:break;case 4:if(r(),e.handle&&void 0!==e.responseText){if("redirected"===m.requested[e.resource.uri])break;m.fireCallbacks("load",d),e.handle(function(){m.doneFetch(e)})}else e.redirected?m.addStatus(e.req,"Aborted and redirected to new request."):m.addStatus(e.req,"Fetch over. No data handled. Aborted = "+e.aborted)}}},q=t;"undefined"!=typeof tabulator&&tabulator.preferences.get("offlineModeUsingLocalhost")&&"http://"===q.slice(0,7)&&"localhost/"!==q.slice(7,17)&&(q="http://localhost/"+q.slice(7),log.warn("Localhost kludge for offline use: actually getting <"+q+">"));var T="https:"===q.slice(0,6);void 0!==a.withCredentials&&(T=a.withCredentials);var k=this.proxyIfNecessary(q);p.onerror=w(p),p.onreadystatechange=b(p),p.timeout=m.timeout,p.withCredentials=T,p.actualProxyURI=k,p.req=f,p.options=a,p.options=a,p.resource=u,p.requestedURI=q,p.ontimeout=function(){m.failFetch(p,"requestTimeout")};try{p.open("GET",k,this.async)}catch(e){return this.failFetch(p,"XHR open for GET failed for <"+q+">:\n\t"+e)}if(n&&p.setRequestHeader("Cache-control","no-cache"),"undefined"!=typeof tabulator&&tabulator.isExtension&&p.channel&&("http"===Uri.protocol(p.resource.uri)||"https"===Uri.protocol(p.resource.uri)))try{p.channel.notificationCallbacks={getInterface:function(e){return e.equals(Components.interfaces.nsIChannelEventSink)?{onChannelRedirect:function(e,t,i){if(!p.aborted){var n=m.store,o=t.URI.spec,l=p.req;if(!p.options.noMeta){m.addStatus(p.req,"Redirected: "+p.status+" to <"+o+">"),n.add(l,s.http("redirectedTo"),n.sym(o),p.req);var c=p.req=n.bnode();n.add(l,s.http("redirectedRequest"),c,this.appNode);var u=new Date,h="["+u.getHours()+":"+u.getMinutes()+":"+u.getSeconds()+"] ";n.add(c,s.rdfs("label"),n.literal(h+" Request for "+o),this.appNode),n.add(c,s.link("status"),n.collection(),this.appNode),n.add(c,s.link("requestedURI"),n.literal(o),this.appNode);var f=n.bnode();n.add(l,s.link("response"),f),n.add(f,s.http("status"),n.literal(p.status),f),p.statusText&&n.add(f,s.http("statusText"),n.literal(p.statusText),f)}if(p.status-0!==303&&(n.HTTPRedirects[p.resource.uri]=o),p.status-0===301&&r){var g=Uri.docpart(r.uri),y="Warning: "+p.resource+" has moved to <"+o+">.";r&&(y+=" Link in <"+g+" >should be changed",n.add(g,n.sym("http://www.w3.org/2007/ont/link#warning"),y,m.appNode))}p.abort(),p.aborted=!0,m.fetchCallbacks[p.resource.uri]&&(m.fetchCallbacks[o]||(m.fetchCallbacks[o]=[]),m.fetchCallbacks[o]===m.fetchCallbacks[o].concat(m.fetchCallbacks[p.resource.uri]),delete m.fetchCallbacks[p.resource.uri]),m.addStatus(l,"redirected"),m.fireCallbacks("redirected",d),m.requested[p.resource.uri]="redirected",m.redirectedTo[p.resource.uri]=o;var v=o.indexOf("#");v>=0&&(p.options.noMeta||n.add(p.resource,n.sym("http://www.w3.org/2007/ont/link#warning"),"Warning: "+p.resource+" HTTP redirects to"+o+' which should not contain a "#" sign'),o=o.slice(0,v));var w=m.requestURI(o,p.resource,p.options,p.userCallback);w&&w.req&&!a.noMeta&&n.add(p.req,n.sym("http://www.w3.org/2007/ont/link#redirectedRequest"),w.req,m.appNode)}},asyncOnChannelRedirect:function(e,t,a,i){if(!p.aborted){var n=m.store,o=t.URI.spec,d=p.req;m.addStatus(p.req,"Redirected: "+p.status+" to <"+o+">"),n.add(d,s.http("redirectedTo"),n.sym(o),p.req);var l=p.req=n.bnode();n.add(d,s.http("redirectedRequest"),l,p.req);var c=new Date,u="["+c.getHours()+":"+c.getMinutes()+":"+c.getSeconds()+"] ";n.add(l,s.rdfs("label"),n.literal(u+" Request for "+o),this.appNode),n.add(l,s.link("status"),n.collection(),this.appNode),n.add(l,s.link("requestedURI"),n.literal(o),this.appNode);var h=n.bnode();if(n.add(d,s.link("response"),h),n.add(h,s.http("status"),n.literal(p.status),h),p.statusText&&n.add(h,s.http("statusText"),n.literal(p.statusText),h),p.status-0!==303&&(n.HTTPRedirects[p.resource.uri]=o),p.status-0===301&&r){var f=Uri.docpart(r.uri),g="Warning: "+p.resource+" has moved to <"+o+">.";r&&(g+=" Link in <"+f+" >should be changed",n.add(f,n.sym("http://www.w3.org/2007/ont/link#warning"),g,m.appNode))}p.abort(),p.aborted=!0;var y=o.indexOf("#");if(y>=0){var v="Warning: "+p.resource+" HTTP redirects to"+o+' which do not normally contain a "#" sign';n.add(p.resource,n.sym("http://www.w3.org/2007/ont/link#warning"),v),o=o.slice(0,y)}m.requested[p.resource.uri]="redirected",m.redirectedTo[p.resource.uri]=o;var w=m.requestURI(o,p.resource,p.options,p.userCallback);w&&(w.original=p.original,w.req&&n.add(p.req,n.sym("http://www.w3.org/2007/ont/link#redirectedRequest"),w.req,m.appNode))}}}:Components.results.NS_NOINTERFACE}}}catch(e){return m.failFetch(p,"@@ Couldn't set callback for redirects: "+e)}try{var H="";for(var x in this.mediatypes){""!==H&&(H+=", "),H+=x;for(var M in this.mediatypes[x])H+=";"+M+"="+this.mediatypes[x][M]}p.setRequestHeader("Accept",H),this.addStatus(p.req,"Accept: "+H)}catch(e){throw new Error("Can't set Accept header: "+e)}try{p.send(null)}catch(e){return this.failFetch(p,"XHR send failed:"+e)}return setTimeout(function(){4!==p.readyState&&m.isPending(p.resource.uri)&&m.failFetch(p,"requestTimeout")},this.timeout),this.addStatus(p.req,"HTTP Request sent."),p}},this.objectRefresh=function(e){var t=n.uris(e);if("undefined"!=typeof t)for(var r=0;r

Formula
function t(e,r,n,s){ "use strict"; _classCallCheck(this,t);var i=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return i.termType=t.termType,i.statements=e||[],i.constraints=r||[],i.initBindings=n||[],i.optional=s||[],i}


IndexedFormula
function t(e){ "use strict"; _classCallCheck(this,t);var n=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return n.propertyActions=[],n.classActions=[],n.redirections=[],n.aliases=[],n.HTTPRedirects=[],n.subjectIndex=[],n.predicateIndex=[],n.objectIndex=[],n.whyIndex=[],n.index=[n.subjectIndex,n.predicateIndex,n.objectIndex,n.whyIndex],n.namespaces={},n.features=e||["sameAs","InverseFunctionalProperty","FunctionalProperty"],n.initPropertyActions(n.features),n}


Literal
function t(e,r,n){ "use strict"; _classCallCheck(this,t);var o=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return o.termType=t.termType,o.value=e,r&&(o.lang=r,n=XSD.langString),n&&(o.datatype=NamedNode.fromValue(n)),o}


N3Parser
function e(t,e,r,s,n,o,h,a){ "use strict"; return new i(t,e,r,s,n,o,h,a)}


NamedNode
function t(e){ "use strict"; _classCallCheck(this,t);var r=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return r.termType=t.termType,e.indexOf(":")<0&&console.log('Warning: NamedNode IRI "'+e+'" must be absolute. Relative URIs will fail in future versions'),r.value=e,r}


Namespace
function Namespace(e){ "use strict"; return function(n){return new NamedNode(e+(n||""))}}


Node
function e(){ "use strict"; _classCallCheck(this,e)}


parse
function parse(e,r,a,t,l){ "use strict"; function n(){l&&l(null,r)}function i(e){if("application/ld+json"!==t||"application/nquads"!==t||"application/n-quads"!==t){if(!l)throw new Error("Error trying to parse <"+a+"> as "+t+":\n"+e+":\n"+e.stack);l(e,r)}}function s(e,a){e&&l(e,r);try{f.parse(a,p)}catch(e){l(e,r)}}function p(e,a,t){if(e&&l(e,r),a)N.push(a);else{for(var n=0;n

Query
function t(n,e){ "use strict"; _classCallCheck(this,t),this.pat=new _indexedFormula2.default,this.vars=[],this.name=n,this.id=e}


queryToSPARQL
function queryToSPARQL(n){ "use strict"; function r(n){for(var r=a()+"SELECT ",t=0;t

RDFaProcessor
function e(t,a){ "use strict"; _classCallCheck(this,e),this.options=a||{},this.kb=t,this.target=a.target||{graph:{subjects:{},prefixes:{},terms:{}}},this.blankNodes=[],this.htmlOptions={selfClosing:"br img input area base basefont col colgroup source wbr isindex link meta param hr"},this.theOne="_:"+(new Date).getTime(),this.language=null,this.vocabulary=null,this.blankCounter=0,this.langAttributes=[{namespaceURI:"http://www.w3.org/XML/1998/namespace",localName:"lang"}],this.inXHTMLMode=!1,this.absURIRE=/[\w\_\-]+:\S+/,this.finishedHandlers=[],this.init()}


RDFParser
function e(t){ "use strict"; var e={};e.ns={RDF:"http://www.w3.org/1999/02/22-rdf-syntax-ns#",RDFS:"http://www.w3.org/2000/01/rdf-schema#"},e.nodeType={ELEMENT:1,ATTRIBUTE:2,TEXT:3,CDATA_SECTION:4,ENTITY_REFERENCE:5,ENTITY:6,PROCESSING_INSTRUCTION:7,COMMENT:8,DOCUMENT:9,DOCUMENT_TYPE:10,DOCUMENT_FRAGMENT:11,NOTATION:12},this.frameFactory=function(t,i,n){return{NODE:1,ARC:2,parent:i,parser:t,store:t.store,element:n,lastChild:0,base:null,lang:null,node:null,nodeType:null,listIndex:1,rdfid:null,datatype:null,collection:!1,terminateFrame:function(){this.collection&&this.node.close()},addSymbol:function(e,t){t=uriUtil.join(t,this.base),this.node=this.store.sym(t),this.nodeType=e},loadTriple:function(){if(this.parent.parent.collection?this.parent.parent.node.append(this.node):this.store.add(this.parent.parent.node,this.parent.node,this.node,this.parser.why),null!=this.parent.rdfid){var t=this.store.sym(uriUtil.join("#"+this.parent.rdfid,this.base));this.store.add(t,this.store.sym(e.ns.RDF+"type"),this.store.sym(e.ns.RDF+"Statement"),this.parser.why),this.store.add(t,this.store.sym(e.ns.RDF+"subject"),this.parent.parent.node,this.parser.why),this.store.add(t,this.store.sym(e.ns.RDF+"predicate"),this.parent.node,this.parser.why),this.store.add(t,this.store.sym(e.ns.RDF+"object"),this.node,this.parser.why)}},isTripleToLoad:function(){return null!=this.parent&&null!=this.parent.parent&&this.nodeType===this.NODE&&this.parent.nodeType===this.ARC&&this.parent.parent.nodeType===this.NODE},addNode:function(e){this.addSymbol(this.NODE,e),this.isTripleToLoad()&&this.loadTriple()},addCollection:function(){this.nodeType=this.NODE,this.node=this.store.collection(),this.collection=!0,this.isTripleToLoad()&&this.loadTriple()},addCollectionArc:function(){this.nodeType=this.ARC},addBNode:function(e){null!=e?null!=this.parser.bnodes[e]?this.node=this.parser.bnodes[e]:this.node=this.parser.bnodes[e]=this.store.bnode():this.node=this.store.bnode(),this.nodeType=this.NODE,this.isTripleToLoad()&&this.loadTriple()},addArc:function(t){t===e.ns.RDF+"li"&&(t=e.ns.RDF+"_"+this.parent.listIndex,this.parent.listIndex++),this.addSymbol(this.ARC,t)},addLiteral:function(e){this.parent.datatype?this.node=this.store.literal(e,"",this.store.sym(this.parent.datatype)):this.node=this.store.literal(e,this.lang),this.nodeType=this.NODE,this.isTripleToLoad()&&this.loadTriple()}}},this.getAttributeNodeNS=function(e,t,i){var n=null;if(e.getAttributeNodeNS)n=e.getAttributeNodeNS(t,i);else for(var s,r,o=e.attributes,a=0;a=0?e.nodeName.split(":")[1]:e.nodeName),t}.bind(this),s=!0;t.parent;){var r=t.element,o=r.attributes;if(r.nodeType===e.nodeType.TEXT||r.nodeType===e.nodeType.CDATA_SECTION)t.parent.nodeType===t.NODE&&(t.addArc(e.ns.RDF+"value"),t=this.buildFrame(t)),t.addLiteral(r.nodeValue);else if(n(r)!==e.ns.RDF+"RDF")if(t.parent&&t.parent.collection&&(t.addCollectionArc(),t=this.buildFrame(t,t.element),t.parent.element=null),t.parent&&t.parent.nodeType&&t.parent.nodeType!==t.ARC){t.addArc(n(r)),this.reify&&(i=this.getAttributeNodeNS(r,e.ns.RDF,"ID"),i&&(t.rdfid=i.nodeValue,r.removeAttributeNode(i)));var a=this.getAttributeNodeNS(r,e.ns.RDF,"parseType"),d=this.getAttributeNodeNS(r,e.ns.RDF,"datatype");if(d&&(t.datatype=d.nodeValue,r.removeAttributeNode(d)),a){var l=a.nodeValue;"Literal"===l?(t.datatype=e.ns.RDF+"XMLLiteral",t=this.buildFrame(t),t.addLiteral(r),s=!1):"Resource"===l?(t=this.buildFrame(t,t.element),t.parent.element=null,t.addBNode()):"Collection"===l&&(t=this.buildFrame(t,t.element),t.parent.element=null,t.addCollection()),r.removeAttributeNode(a)}if(0!==o.length){var h=this.getAttributeNodeNS(r,e.ns.RDF,"resource"),p=this.getAttributeNodeNS(r,e.ns.RDF,"nodeID");t=this.buildFrame(t),h?(t.addNode(h.nodeValue),r.removeAttributeNode(h)):p?(t.addBNode(p.nodeValue),r.removeAttributeNode(p)):t.addBNode();for(var u=o.length-1;u>=0;u--){var N=this.buildFrame(t);N.addArc(n(o[u])),n(o[u])===e.ns.RDF+"type"?this.buildFrame(N).addNode(o[u].nodeValue):this.buildFrame(N).addLiteral(o[u].nodeValue)}}else 0===r.childNodes.length&&this.buildFrame(t).addLiteral("")}else{var T=this.getAttributeNodeNS(r,e.ns.RDF,"about");if(i=this.getAttributeNodeNS(r,e.ns.RDF,"ID"),T&&i)throw new Error("RDFParser: "+r.nodeName+" has both rdf:id and rdf:about. Halting. Only one of these properties may be specified on a node.");if(!T&&i)t.addNode("#"+i.nodeValue),r.removeAttributeNode(i);else if(null==T&&null==i){var m=this.getAttributeNodeNS(r,e.ns.RDF,"nodeID");m?(t.addBNode(m.nodeValue),r.removeAttributeNode(m)):t.addBNode()}else t.addNode(T.nodeValue),r.removeAttributeNode(T);var y=this.getAttributeNodeNS(r,e.ns.RDF,"type");e.ns.RDF+"Description"!==n(r)&&(y={nodeValue:n(r)}),null!=y&&(this.store.add(t.node,this.store.sym(e.ns.RDF+"type"),this.store.sym(uriUtil.join(y.nodeValue,t.base)),this.why),y.nodeName&&r.removeAttributeNode(y));for(var b=o.length-1;b>=0;b--)this.store.add(t.node,this.store.sym(n(o[b])),this.store.literal(o[b].nodeValue,t.lang),this.why)}for(r=t.element;t.parent;){for(var c=t;null==r;)t=t.parent,r=t.element;var f=r.childNodes&&r.childNodes[t.lastChild];if(f&&s){if((f.nodeType===e.nodeType.ELEMENT||f.nodeType===e.nodeType.TEXT||f.nodeType===e.nodeType.CDATA_SECTION)&&(f.nodeType!==e.nodeType.TEXT&&f.nodeType!==e.nodeType.CDATA_SECTION||1===r.childNodes.length)){t.lastChild++,t=this.buildFrame(c,r.childNodes[t.lastChild-1]);break}t.lastChild++}else{if(t.terminateFrame(),!(t=t.parent))break;r=t.element,s=!0}}}},this.cleanParser=function(){this.bnodes={},this.why=null},this.buildFrame=function(t,i){var n=this.frameFactory(this,t,i);if(t&&(n.base=t.base,n.lang=t.lang),!i||i.nodeType===e.nodeType.TEXT||i.nodeType===e.nodeType.CDATA_SECTION)return n;var s=i.attributes,r=i.getAttributeNode("xml:base");null!=r&&(n.base=r.nodeValue,i.removeAttribute("xml:base"));var o=i.getAttributeNode("xml:lang");null!=o&&(n.lang=o.nodeValue,i.removeAttribute("xml:lang"));for(var a=s.length-1;a>=0;a--)if("xml"===s[a].nodeName.substr(0,3)){if("xmlns:"===s[a].name.slice(0,6)){var d=s[a].nodeValue;this.base&&(d=uriUtil.join(d,this.base)),this.store.setPrefixForURI(s[a].name.slice(6),d)}i.removeAttributeNode(s[a])}return n}}


serialize
function serialize(e,t,s,r,a){ "use strict"; function n(e,t){return a?void a(e,t):t}s=s||e.uri,r=r||"text/turtle";var i=null;try{var l,o=Serializer(t),u=t.statementsMatching(void 0,void 0,void 0,e);switch(o.suggestNamespaces(t.namespaces),o.setBase(s),r){case"application/rdf+xml":return i=o.statementsToXML(u),n(null,i);case"text/n3":case"application/n3":return i=o.statementsToN3(u),n(null,i);case"text/turtle":case"application/x-turtle":return o.setFlags("si"),i=o.statementsToN3(u),n(null,i);case"application/n-triples":return o.setFlags("deinprstux"),i=o.statementsToNTriples(u),n(null,i);case"application/ld+json":o.setFlags("deinprstux"),l=o.statementsToNTriples(u),convert.convertToJson(l,a);break;case"application/n-quads":case"application/nquads":return o.setFlags("deinprstux q"),i=o.statementsToNTriples(u),n(null,i);default:throw new Error("Serialize: Content-type "+r+" not supported for data write.")}}catch(e){if(a)return a(e);throw e}}


Serializer
function (e){ "use strict"; return new r(e)}


SPARQLToQuery
function SPARQLToQuery(e,r,n){ "use strict"; function t(e){if(O[e])return O[e];var r=n.variable(e);return O[e]=r,r}function o(e){return"string"==typeof e&&e.match(/[^ \n\t]/)}function i(e){return"string"==typeof e&&e.match(/^[\?\$]/)}function a(e){return"string"==typeof e?e.replace(/^</,"<").replace(/>$/,">"):e}function l(e){return"string"==typeof e&&e.match(/^<[^>]*>$/)}function c(e){return"string"==typeof e&&(e.match(/^_:/)||e.match(/^$/))}function s(e){return"string"==typeof e&&e.match(/:$/)}function f(e){return"string"==typeof e&&e.match(/^:|^[^_][^:]*:/)}function u(e){var r=e.split(":");return r[0]}function g(e){var r=e.split(":");return r[1]}function p(e){return l(e)?e.slice(1,e.length-1):e}function d(e){var r=e.indexOf("'")===-1?null:e.indexOf("'"),t=e.indexOf('"')===-1?null:e.indexOf('"');if(!r&&!t){var o=new Array(1);return o[0]=e,o}var i,a,l=new Array(2);if(!r||t&&t/g,"> ").replace(/{/g," { ").replace(/}/g," } ").replace(/[\t\n\r]/g," ").replace(/; /g," ; ").replace(/\. /g," . ").replace(/, /g," , "),log.info("New str into spaceDelimit: \n"+e);var r=[],n=e.split(" ");for(var t in n)o(n[t])&&(r=r.concat(n[t]));return r}function h(e){for(var r=e,n=0;n"),"is"===r[n]&&"of"===r[n+2]){r.splice(n,1),r.splice(n+1,1);var t=r[n-1];r[n-1]=r[n+1],r[n+1]=t}return r}function y(e){for(var r=[],o=0;o "+i);var a=u(o),c=p(i);n[a]=c}else log.error("Invalid SPARQL symbol: "+i);else log.error("Invalid SPARQL prefix: "+o)}return n}function E(e,r,n){log.info("Looking for a close bracket of type "+n+" in "+e);for(var t=0,o=0;o"===e[1]?(log.debug("Constraint added: "+e),r.constraints[e[0]]=new T(e[2])):"<"===e[1]?(log.debug("Constraint added: "+e),r.constraints[e[0]]=new T(e[2])):log.warn("I don't know how to handle the constraint: "+e)}function Q(e,r){log.debug("Optional query: "+e+" not yet implemented.");var t=n.formula();S(e,t),r.optional.push(t)}function S(e,r){var n,t=y(e);log.debug("WHERE: "+t);for(var o;m("OPTIONAL",t);)o=m("OPTIONAL",t),log.debug("OPT: "+o+" "+t[o]+" in "+t),"{"!==t[o+1]&&log.warn("Bad optional opening bracket in word "+o),n=E(t.slice(o+2),"{","}"),n===-1?log.error("No matching bracket in word "+o):(Q(t.slice(o+2,o+2+n),r),o=m("OPTIONAL",t),n=E(t.slice(o+2),"{","}"),t.splice(o,n+3));for(log.debug("WHERE after optionals: "+t);m("FILTER",t);){var i=m("FILTER",t);"("!==t[i+1]&&log.warn("Bad filter opening bracket in word "+i),n=E(t.slice(i+2),"(",")"),n===-1?log.error("No matching bracket in word "+i):(A(t.slice(i+2,i+2+n),r),i=m("FILTER",t),n=E(t.slice(i+2),"(",")"),t.splice(i,n+3))}log.debug("WHERE after filters and optionals: "+t),x(t,r)}function x(e,r){var n=new Array(1);n[0]=-1;for(var t=n.concat(b(".",e)),o=[],i=0;iq)return log.error("Invalid or nonexistent SELECT and WHERE tags in SPARQL query"),!1;if(L(C.slice(k+1,q),N),S(C.slice(q+2,C.length-1),N.pat),r)return N;for(var j in N.pat.statements){var H=N.pat.statements[j];"NamedNode"===H.subject.termType&&n.fetcher&&n.fetcher.lookUpThing(H.subject,"sparql:"+H.subject),"NamedNode"===H.object.termType&&n.fetcher&&n.fetcher.lookUpThing(H.object,"sparql:"+H.object)}return N}


sparqlUpdateParser
function sparqlUpdateParser(e,r,t){ "use strict"; var a,i,s,n=["INSERT","DELETE","WHERE"],o=Namespace("http://www.w3.org/ns/pim/patch#"),c=N3Parser(r,r,t,t,null,null,"",null),f={},l=function(e,r,t,a,i){return"Line "+(r+1)+" of <"+e+">: Bad syntax:\n "+i+'\n at: "'+t.slice(a,a+30)+'"'};a=0;var p=r.sym(t+"#query");for(f.query=p;;){if(i=c.skipSpace(e,a),i<0)return f;if(";"===e[i]){if(a=c.skipSpace(e,i+1),a<0)return f;i=a}var h=!1;for(s=0;s

Statement
function t(e,i,n,s){ "use strict"; _classCallCheck(this,t),this.subject=Node.fromValue(e),this.predicate=Node.fromValue(i),this.object=Node.fromValue(n),this.why=s}


term
function (e){ "use strict"; var t=require("./collection"),r=require("./literal");require("./named-node");if("undefined"==typeof e||null===e)return e;var n=e&&e.termType;return n?e:Array.isArray(e)?new t(e):r.fromValue(e)}


UpdateManager
function (e){ "use strict"; if(this.store=e,e.updater)throw new Error("You can't have two UpdateManagers for the same store");e.fetcher||new Fetcher(e),e.updater=this,this.ifps={},this.fps={},this.ns={},this.ns.link=Namespace("http://www.w3.org/2007/ont/link#"),this.ns.http=Namespace("http://www.w3.org/2007/ont/http#"),this.ns.httph=Namespace("http://www.w3.org/2007/ont/httph#"),this.ns.ldp=Namespace("http://www.w3.org/ns/ldp#"),this.ns.rdf=Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#"),this.ns.rdfs=Namespace("http://www.w3.org/2000/01/rdf-schema#"),this.ns.rdf=Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#"),this.ns.owl=Namespace("http://www.w3.org/2002/07/owl#"),this.patchControl=[]}


UpdatesSocket
function e(t,n){ "use strict"; _classCallCheck(this,e),this.parent=t,this.via=n,this.connected=!1,this.pending={},this.subscribed={},this.socket={};try{this.socket=new WebSocket(n),this.socket.onopen=this.onOpen,this.socket.onclose=this.onClose,this.socket.onmessage=this.onMessage,this.socket.onerror=this.onError}catch(e){this.onError(e)}}


UpdatesVia
function e(t){ "use strict"; _classCallCheck(this,e),this.fetcher=t,this.graph={},this.via={},this.fetcher.addCallback("headers",this.onHeaders)}


Variable
function t(){ "use strict"; var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";_classCallCheck(this,t);var r=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return r.termType=t.termType,r.value=e,r.base="varid:",r.uri=Uri.join(e,r.base),r}


fromNT
function (e){ "use strict"; var t,r,n,s;switch(e[0]){case"<":return this.sym(e.slice(1,-1));case'"':if(n=void 0,t=void 0,r=e.lastIndexOf('"'),r

fetcher
function fetcher(e,r,t){ "use strict"; return new Fetcher(e,r,t)}


graph
function graph(){ "use strict"; return new _indexedFormula2.default}


lit
function lit(e,r,t){ "use strict"; return new Literal(""+e,r,t)}


st
function st(e,r,t,n){ "use strict"; return new Statement(e,r,t,n)}


sym
function namedNode(e){ "use strict"; return new NamedNode(e)}


variable
function variable(e){ "use strict"; return new Variable(e)}


blankNode
function blankNode(e){ "use strict"; return new BlankNode(e)}


defaultGraph
function defaultGraph(){ "use strict"; return new DefaultGraph}


literal
function literal(e,r){ "use strict"; return"string"==typeof r?r.indexOf(":")===-1?new Literal(e,r):new Literal(e,null,namedNode(r)):new Literal(e,null,r)}


namedNode
function namedNode(e){ "use strict"; return new NamedNode(e)}


quad
function quad(e,r,t,n){ "use strict"; return n=n||new DefaultGraph,new Statement(e,r,t,n)}


triple
function triple(e,r,t){ "use strict"; return quad(e,r,t)}



Monday, January 23, 2017

JavaScript that works with both client side and server side

See the StackOverflow Article:
http://stackoverflow.com/questions/24685154/write-javascript-code-that-works-with-client-side-javascript-and-server-side-nod

http://stackoverflow.com/questions/27561252/how-to-correctly-include-lodash-underscore-on-website-with-conflicting-libs

Require.js Tutorial playlist:

https://www.youtube.com/watch?v=j588XXF4f2Y&list=PLYxzS__5yYQmDD-0A0Jvy27lUnrGIsq9o


Meh. I had this lodash script working in node, and now it does not want to work in the browser. Instead of the script src="". I'm trying require.js . It might help. Look at the load time of lodash verses example.js (my custom code) .

Edit: yes using require.js solves the issue and the file loads.


Requirejs doc:
http://requirejs.org/docs/start.html
http://requirejs.org/docs/api.html

Requirejs module YouTube:
https://www.youtube.com/watch?v=vWGuaZOTR4U

AMD (Asynchronous Module Definition) :
https://github.com/amdjs/amdjs-api/wiki/AMD



Also see in common with common.js and require.js : WebPack (https://webpack.github.io/docs/)

Module Exports in Node Links

Module Patterns:
https://darrenderidder.github.io/talks/ModulePatterns/#/

Passing arguments into Node.js modules:
http://stackoverflow.com/questions/28380561/how-to-pass-variables-into-nodejs-modules

The Node.js documentation:
https://nodejs.org/api/modules.html#modules_module_exports

Saturday, January 21, 2017

Convert triples to random x,y

Code (for a unit area of one):

var triples = [["<subject>", "<predicate>", "<object>"],["<subject-one>", "<predicate-two>", "<object-two>"]];
var accumulator = [];

for(var i = 0; i < triples.length; i++) {
 var pointstwo = triples[i].map(function(elem) {
    return [Math.random(), Math.random()];
 });
 Array.prototype.push.apply(accumulator, pointstwo);
}

console.log("The accumulator is");
console.log(accumulator);


Output:

The accumulator is
[ [ 0.27492627189257113, 0.9965854825881204 ],
  [ 0.9587315529457798, 0.005962501576601609 ],
  [ 0.8799835293320759, 0.041557371975880164 ],
  [ 0.2877037483279361, 0.7579722486957656 ],
  [ 0.4981034461408851, 0.6805552990524384 ],
  [ 0.2785271855960343, 0.4624418653391791 ] ]


Also, here is code considering an area with a specified width and height:

var triples = [["<subject>", "<predicate>", "<object>"],["<subject-one>", "<predicate-two>", "<object-two>"]];
var accumulator = [];
var width = 400;
var height = 400;

for(var i = 0; i < triples.length; i++) {
 var pointstwo = triples[i].map(function(elem) {
    return [Math.random() * width, Math.random() * height];
 });
 Array.prototype.push.apply(accumulator, pointstwo);
}

console.log("The accumulator is");
console.log(accumulator);

Output:

The accumulator is
[ [ 275.6366907510565, 164.99802199836947 ],
  [ 137.25395893793467, 248.2564004659154 ],
  [ 168.47855923177502, 189.31625113698917 ],
  [ 208.77813503610395, 240.8037786584658 ],
  [ 156.17979915445898, 6.730482159676576 ],
  [ 370.5337310559533, 333.75239835510445 ] ]



Thursday, January 19, 2017

p5 drawing continued


Code:

var nums = [[56, 45],[185, 175],[185, 45],[255,145]];
var radius = 55;
var tw = 10;
var titles = ["Hello","World","!","hola"];

function setup() {
  createCanvas(400, 400);
}

function draw() {

  for(var i = 0; i < nums.length - 1; i++) {
    line(nums[i][0], nums[i][1], nums[i+1][0], nums[i+1][1]);
  }


 for(var i = 0; i < nums.length; i++) {
   ellipse(nums[i][0], nums[i][1],radius, radius);
   text(titles[i], nums[i][0] - titles[i].length - tw, nums[i][1] + 0.5*tw, tw);
 }


}

Try: https://danmartensen.svbtle.com/javascripts-map-reduce-and-filter ,
http://jcla1.com/blog/javascript-mapreduce/

For mapping: <?s> <?p> <?o> , <?s1> <?p1> <?o1>

<?s>     , <?o>       ;  <?s1>    ,  <?o1>
 [56,45] , [185,175] ; [185, 45] , [255,145]


 [56,45] , [185,175] ; [185,175] , [255,145]

If this does not work, try mapping functions in the php scripts : https://github.com/bshambaugh

Wednesday, January 18, 2017

p5 drawing

Two primatives: a line object and a circle object. The line goes from the center of one circle to the next. a line goes from one point to the next.

p5.js provides these primatives..

https://p5js.org/reference/#/p5/ellipse, https://p5js.org/reference/#/p5/line

Also add text:
https://p5js.org/reference/#/p5/text
Code:

function setup() {
  createCanvas(200, 200);
}

function draw() {
  ellipse(56, 45, 55, 55);
  line(30, 20, 85, 75);
  text("Hello", 40, 50, 10);
}
~

Code:

function setup() {
  createCanvas(400, 400);
}

function draw() {
 line(56, 45, 185, 175);
  ellipse(56, 45, 55, 55);
  text("Hello", 40, 50, 10);
  ellipse(185, 175, 55, 55);
  text("World", 170, 180, 10);
}

With variables:
var x = 56;
var y = 45;
var z = 185;
var q = 175;
var radius = 55;

function setup() {
  createCanvas(400, 400);
}

function draw() {
 line(x, y, z, q);
  ellipse(x , y, radius, radius);
  text("Hello", 40, 50, 10);
  ellipse(z, q, radius, radius);
  text("World", 170, 180, 10);
}

With arrays:

var nums = [[56, 45],[185, 175]];
var radius = 55;

function setup() {
  createCanvas(400, 400);
}

function draw() {
 line(nums[0][0], nums[0][1], nums[1][0], nums[1][1]);
  ellipse(nums[0][0], nums[0][1],radius, radius);
  text("Hello", 40, 50, 10);
  ellipse(nums[1][0], nums[1][1], radius, radius);
  text("World", 170, 180, 10);
}

With more arrays:

var nums = [[56, 45],[185, 175]];
var radius = 55;
var tw = 10;
var titles = ["Hello","World"];

function setup() {
  createCanvas(400, 400);
}

function draw() {
 line(nums[0][0], nums[0][1], nums[1][0], nums[1][1]);
  ellipse(nums[0][0], nums[0][1],radius, radius);
  text(titles[0], nums[0][0] - titles[0].length - tw, nums[0][1] + 0.5*tw, tw);
  ellipse(nums[1][0], nums[1][1], radius, radius);
  text(titles[1], nums[1][0] - titles[1].length - tw, nums[1][1] + 0.5*tw, tw);
}
~         

Code:

var nums = [[56, 45],[185, 175],[185, 45]];
var radius = 55;
var tw = 10;
var titles = ["Hello","World","!"];

function setup() {
  createCanvas(400, 400);
}

function draw() {
 line(nums[0][0], nums[0][1], nums[1][0], nums[1][1]);
  ellipse(nums[0][0], nums[0][1],radius, radius);
  text(titles[0], nums[0][0] - titles[0].length - tw, nums[0][1] + 0.5*tw, tw);
 
  line(nums[1][0],nums[1][1], nums[2][0], nums[2][1]);
  ellipse(nums[1][0], nums[1][1], radius, radius);
  text(titles[1], nums[1][0] - titles[1].length - tw, nums[1][1] + 0.5*tw, tw);

  ellipse(nums[2][0],nums[2][1], radius, radius);
  text(titles[2],nums[2][0] - titles[2].length - tw, nums[2][1] + 0.5*tw, tw);

//  line(nums[1][0],nums[1][1], nums[2][0], nums[2][1]);
}

or modify the code to draw the lines first:

var nums = [[56, 45],[185, 175],[185, 45]];
var radius = 55;
var tw = 10;
var titles = ["Hello","World","!"];

function setup() {
  createCanvas(400, 400);
}

function draw() {
 line(nums[0][0], nums[0][1], nums[1][0], nums[1][1]);
 line(nums[1][0],nums[1][1], nums[2][0], nums[2][1]);

  ellipse(nums[0][0], nums[0][1],radius, radius);
  text(titles[0], nums[0][0] - titles[0].length - tw, nums[0][1] + 0.5*tw, tw);
 
//  line(nums[1][0],nums[1][1], nums[2][0], nums[2][1]);
  ellipse(nums[1][0], nums[1][1], radius, radius);
  text(titles[1], nums[1][0] - titles[1].length - tw, nums[1][1] + 0.5*tw, tw);

  ellipse(nums[2][0],nums[2][1], radius, radius);
  text(titles[2],nums[2][0] - titles[2].length - tw, nums[2][1] + 0.5*tw, tw);

//  line(nums[1][0],nums[1][1], nums[2][0], nums[2][1]);
}


Tuesday, January 17, 2017

Present Happenings

I'm looking at EISPP from a data side and a presentation side. It has a lot of dialog boxes, so I searched for a ton of them (I don't really like the default jQuery box). It also has directed graph diagrams, amongst a few other things. I find p5.js and daniel shiffman's videos (https://www.youtube.com/watch?v=8j0UDiN7my4&list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA , https://github.com/CodingTrain/Rainbow-Code) useful for prototyping directed graphs. d3.js might be useful for some more serious stuff. I'd like to do things with layers with CSS? Perhaps this gives me the same feel as my wireframes On the data side, I've done some work with node-solid-server, I've also worked with easyrdf.php and requests.php, but would like to work with rdflib.js and express.js or hapi.js.

JavaScript pop-up window resources:

http://www.javascriptf1.com/tutorial/javascript-popup-window.html#
https://www.youtube.com/watch?v=VnHvVz_bFKo
https://www.youtube.com/watch?v=wiAm2YkF5Bo
https://www.youtube.com/watch?v=B0_M1y4aFAQ

also https://jqueryui.com/

---------------
https://guides.emberjs.com/v2.10.0/tutorial/acceptance-test/
https://docs.angularjs.org/tutorial
avoid messiness: http://backbonejs.org/#Getting-started
Inspiration: https://github.com/FreeCodeCampOKC/AngularApp
https://github.com/codenorman/solitaire/tree/development
------------

Other:

https://github.com/shiffman/A2Z-F16
http://shiffman.net/a2z/

This is a hard problem: "We (edit: I?) need a system that encourages learning and creates business and research opportunities through self-organization. The traditional model is failing us (edit: failed me?). We (edit: I) must go beyond the traditional model and personalize education, business, and research with self-organization, so that individuals can contribute their own ideas (edit: have creativity/dreams appreciated and find a path) and work together toward common goals."

It leads to a difficult solution.
"Ideally, the peer-to-peer economic platform will allow for the creation of virtual teams / "companies" that will be connected to other virtual teams by means of their value networks"

Its also unique, so I you have to learn a lot of it on your own. It takes you weird places. Nearly no one gets it. But I identify with it, and want to see the problem solved. But at the same time the weight of the world comes and you struggle to put aside frustration and make money.