-
Notifications
You must be signed in to change notification settings - Fork 0
/
n3-browser.min.js
2 lines (2 loc) · 27.6 KB
/
n3-browser.min.js
1
2
/** @license MIT - N3.js 0.5.0 (browser build) - ©Ruben Verborgh */
!function(e){!function(){function t(e,t){for(var i in f)t?e.prototype[i]=r(f[i]):e[i]=f[i];return e}function r(e){return function(t){return e(this,t)}}var i="http://www.w3.org/2001/XMLSchema#",s=i+"string",n=i+"integer",a=i+"decimal",u=i+"boolean",c="http://www.w3.org/1999/02/22-rdf-syntax-ns#langString",f={isIRI:function(e){if(!e)return e;var t=e[0];return'"'!==t&&"_"!==t},isLiteral:function(e){return e&&'"'===e[0]},isBlank:function(e){return e&&"_:"===e.substr(0,2)},getLiteralValue:function(e){var t=/^"([^]*)"/.exec(e);if(!t)throw new Error(e+" is not a literal");return t[1]},getLiteralType:function(e){var t=/^"[^]*"(?:\^\^([^"]+)|(@)[^@"]+)?$/.exec(e);if(!t)throw new Error(e+" is not a literal");return t[1]||(t[2]?c:s)},getLiteralLanguage:function(e){var t=/^"[^]*"(?:@([^@"]+)|\^\^[^"]+)?$/.exec(e);if(!t)throw new Error(e+" is not a literal");return t[1]?t[1].toLowerCase():""},isPrefixedName:function(e){return e&&/^[^:\/"']*:[^:\/"']+$/.test(e)},expandPrefixedName:function(e,t){var r,i,s,n=/(?:^|"\^\^)([^:\/#"'\^_]*):[^\/]*$/.exec(e);return n&&(r=n[1],i=t[r],s=n.index),void 0===i?e:0===s?i+e.substr(r.length+1):e.substr(0,s+3)+i+e.substr(s+r.length+4)},createIRI:function(e){return e&&'"'===e[0]?f.getLiteralValue(e):e},createLiteral:function(e,t){if(!t)switch(typeof e){case"boolean":t=u;break;case"number":if(isFinite(e)){t=e%1===0?n:a;break}default:return'"'+e+'"'}return'"'+e+(/^[a-z]+(-[a-z0-9]+)*$/i.test(t)?'"@'+t.toLowerCase():'"^^'+t)},prefix:function(e){return f.prefixes({"":e})("")},prefixes:function(e){function t(e,t){if(t||!(e in r)){var i=Object.create(null);t=t||"",r[e]=function(e){return i[e]||(i[e]=t+e)}}return r[e]}var r=Object.create(null);for(var i in e)t(i,e[i]);return t}};e.Util=t(t)}(),function(){function t(e){if(!(this instanceof t))return new t(e);if(e&&e.lineMode){this._tripleQuotedString=this._number=this._boolean=/$0^/;var r=this;this._tokenize=this.tokenize,this.tokenize=function(e,t){this._tokenize(e,function(e,i){!e&&/^(?:IRI|prefixed|literal|langcode|type|\.|eof)$/.test(i.type)?t&&t(e,i):t&&t(e||r._syntaxError(i.type,t=null))})}}}var r=String.fromCharCode,i="function"==typeof setImmediate?setImmediate:function(e){setTimeout(e,0)},s=/\\u([a-fA-F0-9]{4})|\\U([a-fA-F0-9]{8})|\\[uU]|\\(.)/g,n={"\\":"\\","'":"'",'"':'"',n:"\n",r:"\r",t:" ",f:"\f",b:"\b",_:"_","~":"~",".":".","-":"-","!":"!",$:"$","&":"&","(":"(",")":")","*":"*","+":"+",",":",",";":";","=":"=","/":"/","?":"?","#":"#","@":"@","%":"%"},a=/[\x00-\x20<>\\"\{\}\|\^\`]/;t.prototype={_iri:/^<((?:[^>\\]|\\[uU])+)>/,_unescapedIri:/^<([^\x00-\x20<>\\"\{\}\|\^\`]*)>/,_unescapedString:/^"[^"\\]+"(?=[^"\\])/,_singleQuotedString:/^"[^"\\]*(?:\\.[^"\\]*)*"(?=[^"\\])|^'[^'\\]*(?:\\.[^'\\]*)*'(?=[^'\\])/,_tripleQuotedString:/^""("[^"\\]*(?:(?:\\.|"(?!""))[^"\\]*)*")""|^''('[^'\\]*(?:(?:\\.|'(?!''))[^'\\]*)*')''/,_langcode:/^@([a-z]+(?:-[a-z0-9]+)*)(?=[^a-z0-9\-])/i,_prefix:/^((?:[A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:\.?[\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)?:(?=[#\s<])/,_prefixed:/^((?:[A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:\.?[\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)?:((?:(?:[0-:A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~])(?:(?:[\.\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~])*(?:[\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~]))?)?)(?=\.?[,;\s#()\[\]\{\}"'<])/,_blank:/^_:((?:[0-9A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:\.?[\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)(?=\.?[,;:\s#()\[\]\{\}"'<])/,_number:/^[\-+]?(?:\d+\.?\d*([eE](?:[\-\+])?\d+)|\d*\.?\d+)(?=[.,;:\s#()\[\]\{\}"'<])/,_boolean:/^(?:true|false)(?=[.,;:\s#()\[\]\{\}"'<])/,_keyword:/^@[a-z]+(?=[\s#<:])/,_sparqlKeyword:/^(?:PREFIX|BASE|GRAPH)(?=[\s#<:])/i,_shortPredicates:/^a(?=\s+|<)/,_newline:/^[ \t]*(?:#[^\n\r]*)?(?:\r\n|\n|\r)[ \t]*/,_whitespace:/^[ \t]+/,_endOfFile:/^(?:#[^\n\r]*)?$/,_tokenizeToEnd:function(e,t){function r(t){e(t._syntaxError(/^\S*/.exec(i)[0]))}for(var i=this._input;;){for(var s;s=this._newline.exec(i);)i=i.substr(s[0].length,i.length),this._line++;if((s=this._whitespace.exec(i))&&(i=i.substr(s[0].length,i.length)),this._endOfFile.test(i))return t&&e(i=null,{line:this._line,type:"eof",value:"",prefix:""}),this._input=i;var n,u=this._line,c="",f="",d="",h=i[0],l=null,o=0,_=!1;switch(h){case"^":if(1===i.length)break;if("^"!==i[1])return r(this);if(this._prevTokenType="^",i=i.substr(2),"<"!==i[0]){_=!0;break}case"<":if(l=this._unescapedIri.exec(i))c="IRI",f=l[1];else if(l=this._iri.exec(i)){if(n=this._unescape(l[1]),null===n||a.test(n))return r(this);c="IRI",f=n}break;case"_":((l=this._blank.exec(i))||t&&(l=this._blank.exec(i+" ")))&&(c="prefixed",d="_",f=l[1]);break;case'"':case"'":if(l=this._unescapedString.exec(i))c="literal",f=l[0];else if(l=this._singleQuotedString.exec(i)){if(n=this._unescape(l[0]),null===n)return r(this);c="literal",f=n.replace(/^'|'$/g,'"')}else if(l=this._tripleQuotedString.exec(i)){if(n=l[1]||l[2],this._line+=n.split(/\r\n|\r|\n/).length-1,n=this._unescape(n),null===n)return r(this);c="literal",f=n.replace(/^'|'$/g,'"')}break;case"@":"literal"===this._prevTokenType&&(l=this._langcode.exec(i))?(c="langcode",f=l[1]):(l=this._keyword.exec(i))&&(c=l[0]);break;case".":if(1===i.length?t:i[1]<"0"||i[1]>"9"){c=".",o=1;break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":case"+":case"-":(l=this._number.exec(i))&&(c="literal",f='"'+l[0]+'"^^http://www.w3.org/2001/XMLSchema#'+(l[1]?"double":/^[+\-]?\d+$/.test(l[0])?"integer":"decimal"));break;case"B":case"b":case"p":case"P":case"G":case"g":(l=this._sparqlKeyword.exec(i))?c=l[0].toUpperCase():_=!0;break;case"f":case"t":(l=this._boolean.exec(i))?(c="literal",f='"'+l[0]+'"^^http://www.w3.org/2001/XMLSchema#boolean'):_=!0;break;case"a":(l=this._shortPredicates.exec(i))?(c="abbreviation",f="http://www.w3.org/1999/02/22-rdf-syntax-ns#type"):_=!0;break;case",":case";":case"[":case"]":case"(":case")":case"{":case"}":o=1,c=h;break;default:_=!0}if(_&&("@prefix"!==this._prevTokenType&&"PREFIX"!==this._prevTokenType||!(l=this._prefix.exec(i))?((l=this._prefixed.exec(i))||t&&(l=this._prefixed.exec(i+" ")))&&(c="prefixed",d=l[1]||"",f=this._unescape(l[2])):(c="prefix",f=l[1]||"")),"^"===this._prevTokenType&&(c="IRI"===c||"prefixed"===c?"type":""),!c)return t||!/^'''|^"""/.test(i)&&/\n|\r/.test(i)?r(this):this._input=i;e(null,{line:u,type:c,value:f,prefix:d}),this._prevTokenType=c,i=i.substr(o||l[0].length,i.length)}},_unescape:function(e){try{return e.replace(s,function(e,t,i,s){var a;if(t){if(a=parseInt(t,16),isNaN(a))throw new Error;return r(a)}if(i){if(a=parseInt(i,16),isNaN(a))throw new Error;return 65535>=a?r(a):r(55296+(a-=65536)/1024,56320+(1023&a))}var u=n[s];if(!u)throw new Error;return u})}catch(t){return null}},_syntaxError:function(e){return this._input=null,new Error('Syntax error: unexpected "'+e+'" on line '+this._line+".")},tokenize:function(e,t){function r(e){null!==n._input&&(n._input+=e,n._tokenizeToEnd(t,!1))}function s(){null!==n._input&&n._tokenizeToEnd(t,!0)}var n=this;this._line=1,"string"==typeof e?(this._input=e,i(function(){n._tokenizeToEnd(t,!0)})):(this._input="",e&&"function"!=typeof e?("function"==typeof e.setEncoding&&e.setEncoding("utf8"),e.on("data",r),e.on("end",s)):(this.addChunk=r,this.end=s,t||(t=e)))}},e.Lexer=t}(),function(){function t(e){if(!(this instanceof t))return new t(e);this._tripleStack=[],this._graph=null,e=e||{},this._setBase(e.documentIRI);var s="string"==typeof e.format&&e.format.match(/\w*$/)[0].toLowerCase(),n="turtle"===s,a="trig"===s,u=/triple/.test(s),c=/quad/.test(s),f=u||c;(this._supportsNamedGraphs=!n)||(this._readPredicateOrNamedGraph=this._readPredicate),this._supportsQuads=!(n||a||u),f&&(this._base="",this._resolveIRI=function(e){return this._error("Disallowed relative IRI",e),this._callback=r,this._subject=null}),this._blankNodePrefix="string"!=typeof e.blankNodePrefix?"":"_:"+e.blankNodePrefix.replace(/^_:/,""),this._lexer=e.lexer||new i({lineMode:f})}function r(){}var i=e.Lexer,s="http://www.w3.org/1999/02/22-rdf-syntax-ns#",n=s+"nil",a=s+"first",u=s+"rest",c=/^[a-z][a-z0-9+.-]*:/i,f=/^(?:([a-z][a-z0-9+.-]*:))?(?:\/\/[^\/]*)?/i,d=/(?:^|\/)\.\.?(?:$|[\/#?])/,h=0,l=0;t._resetBlankNodeIds=function(){h=l=0},t.prototype={_setBase:function(e){if(e){if(e.indexOf("#")>=0)throw new Error("Invalid base IRI "+e)}else e=null;(this._base=e)&&(this._basePath=e.replace(/[^\/?]*(?:\?.*)?$/,""),e=e.match(f),this._baseRoot=e[0],this._baseScheme=e[1])},_readInTopContext:function(e){switch(e.type){case"eof":return null!==this._graph?this._error("Unclosed graph",e):(delete this._prefixes._,this._callback(null,null,this._prefixes));case"@prefix":return this._sparqlStyle=!1,this._readPrefix;case"PREFIX":return this._sparqlStyle=!0,this._readPrefix;case"@base":return this._sparqlStyle=!1,this._readBaseIRI;case"BASE":return this._sparqlStyle=!0,this._readBaseIRI;case"{":if(this._supportsNamedGraphs)return this._graph="",this._subject=null,this._readSubject;case"GRAPH":if(this._supportsNamedGraphs)return this._readNamedGraphLabel;default:return this._readSubject(e)}},_readSubject:function(e){switch(this._predicate=null,e.type){case"IRI":null===this._base||c.test(e.value)?this._subject=e.value:this._subject=this._resolveIRI(e);break;case"prefixed":var t=this._prefixes[e.prefix];if(void 0===t)return this._error('Undefined prefix "'+e.prefix+':"',e);this._subject=t+e.value;break;case"[":return this._subject="_:b"+l++,this._tripleStack.push({subject:this._subject,predicate:null,object:null,type:"blank"}),this._readBlankNodeHead;case"(":return this._tripleStack.push({subject:n,predicate:null,object:null,type:"list"}),this._subject=null,this._readListItem;case"}":return this._readPunctuation(e);default:return this._error("Expected subject but got "+e.type,e)}return this._readPredicateOrNamedGraph},_readPredicate:function(e){var t=e.type;switch(t){case"IRI":case"abbreviation":null===this._base||c.test(e.value)?this._predicate=e.value:this._predicate=this._resolveIRI(e);break;case"prefixed":if("_"===e.prefix)return this._error("Disallowed blank node as predicate",e);var r=this._prefixes[e.prefix];if(void 0===r)return this._error('Undefined prefix "'+e.prefix+':"',e);this._predicate=r+e.value;break;case".":case"]":case"}":return null===this._predicate?this._error("Unexpected "+t,e):(this._subject=null,"]"===t?this._readBlankNodeTail(e):this._readPunctuation(e));case";":return this._readPredicate;default:return this._error('Expected predicate to follow "'+this._subject+'"',e)}return this._readObject},_readObject:function(e){switch(e.type){case"IRI":null===this._base||c.test(e.value)?this._object=e.value:this._object=this._resolveIRI(e);break;case"prefixed":var t=this._prefixes[e.prefix];if(void 0===t)return this._error('Undefined prefix "'+e.prefix+':"',e);this._object=t+e.value;break;case"literal":return this._object=e.value,this._readDataTypeOrLang;case"[":var r="_:b"+l++;return this._tripleStack.push({subject:this._subject,predicate:this._predicate,object:r,type:"blank"}),this._subject=r,this._readBlankNodeHead;case"(":return this._tripleStack.push({subject:this._subject,predicate:this._predicate,object:n,type:"list"}),this._subject=null,this._readListItem;default:return this._error('Expected object to follow "'+this._predicate+'"',e)}return this._getTripleEndReader()},_readPredicateOrNamedGraph:function(e){return"{"===e.type?this._readGraph(e):this._readPredicate(e)},_readGraph:function(e){return"{"!==e.type?this._error("Expected graph but got "+e.type,e):(this._graph=this._subject,this._subject=null,this._readSubject)},_readBlankNodeHead:function(e){return"]"===e.type?(this._subject=null,this._readBlankNodeTail(e)):(this._predicate=null,this._readPredicate(e))},_readBlankNodeTail:function(e){if("]"!==e.type)return this._readBlankNodePunctuation(e);null!==this._subject&&this._callback(null,{subject:this._subject,predicate:this._predicate,object:this._object,graph:this._graph||""});var t=this._tripleStack.pop();return this._subject=t.subject,null!==t.object?(this._predicate=t.predicate,this._object=t.object,this._getTripleEndReader()):null!==this._predicate?this._readPredicate:this._readPredicateOrNamedGraph},_readDataTypeOrLang:function(e){switch(e.type){case"type":var t;if(""===e.prefix)t=null===this._base||c.test(e.value)?e.value:this._resolveIRI(e);else{var r=this._prefixes[e.prefix];if(void 0===r)return this._error('Undefined prefix "'+e.prefix+':"',e);t=r+e.value}return this._object+="^^"+t,this._getTripleEndReader();case"langcode":return this._object+="@"+e.value.toLowerCase(),this._getTripleEndReader();default:return this._getTripleEndReader().call(this,e)}},_readListItem:function(e){var t=null,r=null,i=this._subject,s=this._tripleStack,f=s[s.length-1],d=this._readListItem;switch(e.type){case"IRI":t=null===this._base||c.test(e.value)?e.value:this._resolveIRI(e);break;case"prefixed":var h=this._prefixes[e.prefix];if(void 0===h)return this._error('Undefined prefix "'+e.prefix+':"',e);t=h+e.value;break;case"literal":t=e.value,d=this._readDataTypeOrLang;break;case"[":r="_:b"+l++,t="_:b"+l++,s.push({subject:r,predicate:a,object:t,type:"blank"}),this._subject=t,d=this._readBlankNodeHead;break;case"(":r="_:b"+l++,s.push({subject:r,predicate:a,object:n,type:"list"}),this._subject=null,d=this._readListItem;break;case")":if(s.pop(),0!==s.length&&"list"===s[s.length-1].type&&this._callback(null,{subject:f.subject,predicate:f.predicate,object:f.object,graph:this._graph||""}),this._subject=f.subject,null===f.predicate){if(d=this._readPredicate,f.subject===n)return d}else if(this._predicate=f.predicate,this._object=f.object,d=this._getTripleEndReader(),f.object===n)return d;r=n;break;default:return this._error('Expected list item instead of "'+e.type+'"',e)}return null===r&&(this._subject=r="_:b"+l++),null===i?f.object===n?f.object=r:f.subject=r:this._callback(null,{subject:i,predicate:u,object:r,graph:this._graph||""}),null!==t&&this._callback(null,{subject:r,predicate:a,object:t,graph:this._graph||""}),d},_readPunctuation:function(e){var t,r=this._subject,i=this._graph;switch(e.type){case"}":if(null===this._graph)return this._error("Unexpected graph closing",e);this._graph=null;case".":this._subject=null,t=this._readInTopContext;break;case";":t=this._readPredicate;break;case",":t=this._readObject;break;case"IRI":if(this._supportsQuads&&null===this._graph){i=null===this._base||c.test(e.value)?e.value:this._resolveIRI(e),r=this._subject,t=this._readQuadPunctuation;break}case"prefixed":if(this._supportsQuads&&null===this._graph){var s=this._prefixes[e.prefix];if(void 0===s)return this._error('Undefined prefix "'+e.prefix+':"',e);i=s+e.value,t=this._readQuadPunctuation;break}default:return this._error('Expected punctuation to follow "'+this._object+'"',e)}return null!==r&&this._callback(null,{subject:r,predicate:this._predicate,object:this._object,graph:i||""}),t},_readBlankNodePunctuation:function(e){var t;switch(e.type){case";":t=this._readPredicate;break;case",":t=this._readObject;break;default:return this._error('Expected punctuation to follow "'+this._object+'"',e)}return this._callback(null,{subject:this._subject,predicate:this._predicate,object:this._object,graph:this._graph||""}),t},_readQuadPunctuation:function(e){return"."!==e.type?this._error("Expected dot to follow quad",e):this._readInTopContext},_readPrefix:function(e){return"prefix"!==e.type?this._error("Expected prefix to follow @prefix",e):(this._prefix=e.value,this._readPrefixIRI)},_readPrefixIRI:function(e){if("IRI"!==e.type)return this._error('Expected IRI to follow prefix "'+this._prefix+':"',e);var t;return t=null===this._base||c.test(e.value)?e.value:this._resolveIRI(e),this._prefixes[this._prefix]=t,this._prefixCallback(this._prefix,t),this._readDeclarationPunctuation},_readBaseIRI:function(e){if("IRI"!==e.type)return this._error("Expected IRI to follow base declaration",e);try{this._setBase(null===this._base||c.test(e.value)?e.value:this._resolveIRI(e))}catch(t){this._error(t.message,e)}return this._readDeclarationPunctuation},_readNamedGraphLabel:function(e){switch(e.type){case"IRI":case"prefixed":return this._readSubject(e),this._readGraph;case"[":return this._readNamedGraphBlankLabel;default:return this._error("Invalid graph label",e)}},_readNamedGraphBlankLabel:function(e){return"]"!==e.type?this._error("Invalid graph label",e):(this._subject="_:b"+l++,this._readGraph)},_readDeclarationPunctuation:function(e){return this._sparqlStyle?this._readInTopContext(e):"."!==e.type?this._error("Expected declaration to end with a dot",e):this._readInTopContext},_getTripleEndReader:function(){var e=this._tripleStack;if(0===e.length)return this._readPunctuation;switch(e[e.length-1].type){case"blank":return this._readBlankNodeTail;case"list":return this._readListItem}},_error:function(e,t){this._callback(new Error(e+" at line "+t.line+"."))},_resolveIRI:function(e){var t=e.value;switch(t[0]){case void 0:return this._base;case"#":return this._base+t;case"?":return this._base.replace(/(?:\?.*)?$/,t);case"/":return("/"===t[1]?this._baseScheme:this._baseRoot)+this._removeDotSegments(t);default:return this._removeDotSegments(this._basePath+t)}},_removeDotSegments:function(e){if(!d.test(e))return e;for(var t="",r=e.length,i=-1,s=-1,n=0,a="/";r>i;){switch(a){case":":if(0>s&&"/"===e[++i]&&"/"===e[++i])for(;(s=i+1)<r&&"/"!==e[s];)i=s;break;case"?":case"#":i=r;break;case"/":if("."===e[i+1])switch(a=e[++i+1]){case"/":t+=e.substring(n,i-1),n=i+1;break;case void 0:case"?":case"#":return t+e.substring(n,i)+e.substr(i+1);case".":if(a=e[++i+1],void 0===a||"/"===a||"?"===a||"#"===a){if(t+=e.substring(n,i-2),(n=t.lastIndexOf("/"))>=s&&(t=t.substr(0,n)),"/"!==a)return t+"/"+e.substr(i+1);n=i+1}}}a=e[++i]}return t+e.substring(n)},parse:function(e,t,i){this._readCallback=this._readInTopContext,this._prefixes=Object.create(null),this._prefixes._=this._blankNodePrefix||"_:b"+h++ +"_","function"==typeof e&&(i=t,t=e,e=null),this._callback=t||r,this._prefixCallback=i||r;var s=this;this._lexer.tokenize(e,function(e,t){null!==e?(s._callback(e),s._callback=r):void 0!==s._readCallback&&(s._readCallback=s._readCallback(t))}),e||(this.addChunk=this._lexer.addChunk,this.end=this._lexer.end)}},e.Parser=t}(),function(){function t(e,r){if(!(this instanceof t))return new t(e,r);if(e&&"function"!=typeof e.write&&(r=e,e=null),r=r||{},e)this._outputStream=e,this._endStream=void 0===r.end?!0:!!r.end;else{var i="";this._outputStream={write:function(e,t,r){i+=e,r&&r()},end:function(e){e&&e(null,i)}},this._endStream=!0}this._subject=null,/triple|quad/i.test(r.format)?this._writeTriple=this._writeTripleLine:(this._graph="",this._prefixIRIs=Object.create(null),r.prefixes&&this.addPrefixes(r.prefixes))}function r(e){var t=c[e];return void 0===t&&(1===e.length?(t=e.charCodeAt(0).toString(16),t="\\u0000".substr(0,6-t.length)+t):(t=(1024*(e.charCodeAt(0)-55296)+e.charCodeAt(1)+9216).toString(16),t="\\U00000000".substr(0,10-t.length)+t)),t}var i=/^"([^]*)"(?:\^\^(.+)|@([\-a-z]+))?$/i,s="http://www.w3.org/1999/02/22-rdf-syntax-ns#",n=s+"type",a=/["\\\t\n\r\b\f\u0000-\u0019\ud800-\udbff]/,u=/["\\\t\n\r\b\f\u0000-\u0019]|[\ud800-\udbff][\udc00-\udfff]/g,c={"\\":"\\\\",'"':'\\"'," ":"\\t","\n":"\\n","\r":"\\r","\b":"\\b","\f":"\\f"};t.prototype={_write:function(e,t){this._outputStream.write(e,"utf8",t)},_writeTriple:function(e,t,r,i,s){try{this._graph!==i&&(this._write((null===this._subject?"":this._graph?"\n}\n":".\n")+(i?this._encodeIriOrBlankNode(i)+" {\n":"")),this._subject=null,this._graph="["!==i[0]?i:"]"),this._subject===e?this._predicate===t?this._write(", "+this._encodeObject(r),s):this._write(";\n "+this._encodePredicate(this._predicate=t)+" "+this._encodeObject(r),s):this._write((null===this._subject?"":".\n")+this._encodeSubject(this._subject=e)+" "+this._encodePredicate(this._predicate=t)+" "+this._encodeObject(r),s)}catch(n){s&&s(n)}},_writeTripleLine:function(e,t,r,i,s){delete this._prefixMatch;try{this._write(this._encodeIriOrBlankNode(e)+" "+this._encodeIriOrBlankNode(t)+" "+this._encodeObject(r)+(i?" "+this._encodeIriOrBlankNode(i)+".\n":".\n"),s)}catch(n){s&&s(n)}},_encodeIriOrBlankNode:function(e){var t=e[0];if("["===t||"("===t||"_"===t&&":"===e[1])return e;a.test(e)&&(e=e.replace(u,r));var i=this._prefixRegex.exec(e);return i?i[1]?this._prefixIRIs[i[1]]+i[2]:e:"<"+e+">"},_encodeLiteral:function(e,t,i){return a.test(e)&&(e=e.replace(u,r)),i?'"'+e+'"@'+i:t?'"'+e+'"^^'+this._encodeIriOrBlankNode(t):'"'+e+'"'},_encodeSubject:function(e){if('"'===e[0])throw new Error("A literal as subject is not allowed: "+e);return"["===e[0]&&(this._subject="]"),this._encodeIriOrBlankNode(e)},_encodePredicate:function(e){if('"'===e[0])throw new Error("A literal as predicate is not allowed: "+e);return e===n?"a":this._encodeIriOrBlankNode(e)},_encodeObject:function(e){if('"'!==e[0])return this._encodeIriOrBlankNode(e);var t=i.exec(e);if(!t)throw new Error("Invalid literal: "+e);return this._encodeLiteral(t[1],t[2],t[3])},_blockedWrite:function(){throw new Error("Cannot write because the writer has been closed.")},addTriple:function(e,t,r,i,s){void 0===r?this._writeTriple(e.subject,e.predicate,e.object,e.graph||"",t):"string"!=typeof i?this._writeTriple(e,t,r,"",i):this._writeTriple(e,t,r,i,s)},addTriples:function(e){for(var t=0;t<e.length;t++)this.addTriple(e[t])},addPrefix:function(e,t,r){var i={};i[e]=t,this.addPrefixes(i,r)},addPrefixes:function(e,t){var r=this._prefixIRIs,i=!1;for(var s in e){var n=e[s];/[#\/]$/.test(n)&&r[n]!==(s+=":")&&(i=!0,r[n]=s,null!==this._subject&&(this._write(this._graph?"\n}\n":".\n"),this._subject=null,this._graph=""),this._write("@prefix "+s+" <"+n+">.\n"))}if(i){var a="",u="";for(var c in r)a+=a?"|"+c:c,u+=(u?"|":"")+r[c];a=a.replace(/[\]\/\(\)\*\+\?\.\\\$]/g,"\\$&"),this._prefixRegex=new RegExp("^(?:"+u+")[^/]*$|^("+a+")([a-zA-Z][\\-_a-zA-Z0-9]*)$")}this._write(i?"\n":"",t)},blank:function(e,t){var r,i,s=e;switch(void 0===e?s=[]:"string"==typeof e?s=[{predicate:e,object:t}]:"length"in e||(s=[e]),i=s.length){case 0:return"[]";case 1:if(r=s[0],"["!==r.object[0])return"[ "+this._encodePredicate(r.predicate)+" "+this._encodeObject(r.object)+" ]";default:for(var n="[",a=0;i>a;a++)r=s[a],r.predicate===e?n+=", "+this._encodeObject(r.object):(n+=(a?";\n ":"\n ")+this._encodePredicate(r.predicate)+" "+this._encodeObject(r.object),e=r.predicate);return n+"\n]"}},list:function(e){for(var t=e&&e.length||0,r=new Array(t),i=0;t>i;i++)r[i]=this._encodeObject(e[i]);return"("+r.join(" ")+")"},_prefixRegex:/$0^/,end:function(e){null!==this._subject&&(this._write(this._graph?"\n}\n":".\n"),this._subject=null),this._write=this._blockedWrite;var t=e&&function(r,i){t=null,e(r,i)};if(this._endStream)try{return this._outputStream.end(t)}catch(r){}t&&t()}},e.Writer=t}(),function(){function t(e,r){return this instanceof t?(this._size=0,this._graphs=Object.create(null),this._id=0,this._ids=Object.create(null),this._ids["><"]=0,this._entities=Object.create(null),this._blankNodeIndex=0,r||!e||e[0]||(r=e,e=null),r=r||{},this._prefixes=Object.create(null),r.prefixes&&this.addPrefixes(r.prefixes),this.defaultGraph=r.defaultGraph||"http://example.org/#defaultGraph",void(e&&this.addTriples(e))):new t(e,r)}var r=e.Util.expandPrefixedName;t.prototype={get size(){var e=this._size;if(null!==e)return e;var t,r,i=this._graphs;for(var s in i)for(var n in t=i[s].subjects)for(var a in r=t[n])e+=Object.keys(r[a]).length;return this._size=e},_addToIndex:function(e,t,r,i){var s=e[t]||(e[t]={}),n=s[r]||(s[r]={}),a=i in n;return a||(n[i]=null),!a},_removeFromIndex:function(e,t,r,i){var s,n=e[t],a=n[r];delete a[i];for(s in a)return;delete n[r];for(s in n)return;delete e[t]},_findInIndex:function(e,t,r,i,s,n,a,u){var c,f,d,h=[],l=!t+!r+!i,o=l>1?Object.keys(this._ids):this._entities;t&&((c=e,e={})[t]=c[t]);for(var _ in e){var p=o[_];if(f=e[_]){r&&((c=f,f={})[r]=c[r]);for(var b in f){var x=o[b];if(d=f[b])for(var j=(i?i in d?[i]:[]:Object.keys(d)),v=j.length-1;v>=0;v--){var g={subject:"",predicate:"",object:"",graph:u};g[s]=p,g[n]=x,g[a]=o[j[v]],h.push(g)}}}}return h},_countInIndex:function(e,t,r,i){var s,n,a,u=0;t&&((s=e,e={})[t]=s[t]);for(var c in e)if(n=e[c]){r&&((s=n,n={})[r]=s[r]);for(var f in n)(a=n[f])&&(i?i in a&&u++:u+=Object.keys(a).length)}return u},addTriple:function(e,t,r,i){t||(i=e.graph,r=e.object,t=e.predicate,e=e.subject),i=i||this.defaultGraph;var s=this._graphs[i];s||(s=this._graphs[i]={subjects:{},predicates:{},objects:{}},Object.freeze(s));var n=this._ids,a=this._entities;e=n[e]||(n[a[++this._id]=e]=this._id),t=n[t]||(n[a[++this._id]=t]=this._id),r=n[r]||(n[a[++this._id]=r]=this._id);var u=this._addToIndex(s.subjects,e,t,r);return this._addToIndex(s.predicates,t,r,e),this._addToIndex(s.objects,r,e,t),this._size=null,u},addTriples:function(e){for(var t=e.length-1;t>=0;t--)this.addTriple(e[t])},addPrefix:function(e,t){this._prefixes[e]=t},addPrefixes:function(e){for(var t in e)this.addPrefix(t,e[t])},removeTriple:function(e,t,r,i){t||(i=e.graph,r=e.object,t=e.predicate,e=e.subject),i=i||this.defaultGraph;var s,n=this._ids,a=this._graphs;if(!(e=n[e]))return!1;if(!(t=n[t]))return!1;if(!(r=n[r]))return!1;if(!(s=a[i]))return!1;var u,c;if(!(u=s.subjects[e]))return!1;if(!(c=u[t]))return!1;if(!(r in c))return!1;this._removeFromIndex(s.subjects,e,t,r),this._removeFromIndex(s.predicates,t,r,e),this._removeFromIndex(s.objects,r,e,t),null!==this._size&&this._size--;for(e in s.subjects)return!0;return delete a[i],!0},removeTriples:function(e){for(var t=e.length-1;t>=0;t--)this.removeTriple(e[t])},find:function(e,t,i,s){var n=this._prefixes;return this.findByIRI(r(e,n),r(t,n),r(i,n),r(s,n))},findByIRI:function(e,t,r,i){var s,n,a,u,c=[],f={},d=this._ids;i?f[i]=this._graphs[i]:f=this._graphs;for(var h in f)if(s=f[h]){if(e&&!(n=d[e]))return c;if(t&&!(a=d[t]))return c;if(r&&!(u=d[r]))return c;n?u?c.push(this._findInIndex(s.objects,u,n,a,"object","subject","predicate",h)):c.push(this._findInIndex(s.subjects,n,a,null,"subject","predicate","object",h)):a?c.push(this._findInIndex(s.predicates,a,u,null,"predicate","object","subject",h)):u?c.push(this._findInIndex(s.objects,u,null,null,"object","subject","predicate",h)):c.push(this._findInIndex(s.subjects,null,null,null,"subject","predicate","object",h))}return 1===c.length?c[0]:c.concat.apply([],c)},count:function(e,t,i,s){var n=this._prefixes;return this.countByIRI(r(e,n),r(t,n),r(i,n),r(s,n))},countByIRI:function(e,t,r,i){i=i||this.defaultGraph;var s=this._graphs[i],n=this._ids;return s?e&&!(e=n[e])?0:t&&!(t=n[t])?0:r&&!(r=n[r])?0:e?r?this._countInIndex(s.objects,r,e,t):this._countInIndex(s.subjects,e,t,r):t?this._countInIndex(s.predicates,t,r,e):this._countInIndex(s.objects,r,e,t):0},createBlankNode:function(e){var t,r;if(e)for(t=e="_:"+e,r=1;this._ids[t];)t=e+r++;else do t="_:b"+this._blankNodeIndex++;while(this._ids[t]);return this._ids[t]=++this._id,t}},e.Store=t}()}("undefined"!=typeof exports?exports:this.N3={});