/
api.min.js
1 lines (1 loc) · 53.4 KB
/
api.min.js
1
rdfapi=function(){api={};api.Hash=function(a){this.empty()};api.Hash.prototype={h:null,get:function(a){return this.h[a]},set:function(b,a){this.h[b]=a},empty:function(){this.h={}},exists:function(a){return this.h.hasOwnProperty(a)},keys:function(c){var b=[];c=!c;for(var a in this.h){if(c&&Object.prototype[a]){continue}b.push(a)}return b},remove:function(a){var b=this.get(a);delete this.h[a];return b},toArray:function(){var b=new Array;var c=this;this.keys().forEach(function(a){b.push(c.get(a))});return b},toString:function(){return JSON.stringify(this.h)}};api.RDFNode=function(){};api.RDFNode.prototype={value:null,equals:function(a){if(this.nodeType()!=a.nodeType()){return false}switch(this.nodeType()){case"IRI":case"BlankNode":return this.value==a.value;case"PlainLiteral":return this.language==a.language&&this.value==a.value;case"TypedLiteral":return this.type.equals(a.type)&&this.value==a.value}return this.toNT()==a.toNT()},nodeType:function(){return"RDFNode"},toNT:function(){return""},toCanonical:function(){return this.toNT()},toString:function(){return this.value},encodeString:function(j){var c="";var h=false;var f=0,e=j.length;while(f<e){var d=f++;if(!h){var a=j.charCodeAt(d);if(55296<=a&&a<=56319){var g=j.charCodeAt(d+1);a=(a-55296)*1024+(g-56320)+65536;h=true}if(a>1114111){throw new Error("Char out of range")}var b="00000000".concat((new Number(a)).toString(16).toUpperCase());if(a>=65536){c+="\\U"+b.slice(-8)}else{if(a>=127||a<=31){switch(a){case 9:c+="\\t";break;case 10:c+="\\n";break;case 13:c+="\\r";break;default:c+="\\u"+b.slice(-4);break}}else{switch(a){case 34:c+='\\"';break;case 92:c+="\\\\";break;default:c+=j.charAt(d);break}}}}else{h=!h}}return c}};api.BlankNode=function(){this.value="_:b"+(new String(++api.BlankNode.NEXTID)).toString()};api.BlankNode.NEXTID=0;api.BlankNode.prototype={__proto__:api.RDFNode.prototype,nodeType:function(){return"BlankNode"},toNT:function(){return this.value}};api.PlainLiteral=function(a,b){if(typeof b=="string"&&b[0]=="@"){b=b.slice(1)}this.value=a;this.language=b};api.PlainLiteral.prototype={__proto__:api.RDFNode.prototype,language:null,nodeType:function(){return"PlainLiteral"},toNT:function(){var a='"'+this.encodeString(this.value)+'"';return !Boolean(this.language).valueOf()?a:a.concat("@"+this.language)}};api.TypedLiteral=function(b,a){this.value=b;this.type=a};api.TypedLiteral.prototype={__proto__:api.RDFNode.prototype,type:null,nodeType:function(){return"TypedLiteral"},toNT:function(){return'"'+this.encodeString(this.value)+'"^^<'+this.type+">"}};api.RDFTriple=function(a,b,c){this.subject=a;this.property=b;this.object=c};api.RDFTriple.prototype={object:null,property:null,subject:null,toString:function(){return this.subject.toNT()+" "+this.property.toNT()+" "+this.object.toNT()+" ."},equals:function(a){return this.subject.equals(a.subject)&&this.property.equals(a.property)&&this.object.equals(a.object)}};api.IRI=function(a){this.value=a};api.IRI.SCHEME_MATCH=new RegExp("^[a-z0-9-.+]+:","i");api.IRI.prototype={__proto__:api.RDFNode.prototype,nodeType:function(){return"IRI"},toNT:function(){return"<"+this.encodeString(this.value)+">"},defrag:function(){var a=this.value.indexOf("#");return(a<0)?this:new api.IRI(this.value.slice(0,a))},isAbsolute:function(){return this.scheme()!=null&&this.heirpart()!=null&&this.fragment()==null},toAbsolute:function(){if(this.scheme()==null&&this.heirpart()==null){throw new Error("IRI must have a scheme and a heirpart!")}return this.resolveReference(this.value).defrag()},authority:function(){var a=this.heirpart();if(a.substring(0,2)!="//"){return null}var c=a.slice(2);var b=c.indexOf("/");return b>=0?c.substring(0,b):c},fragment:function(){var a=this.value.indexOf("#");return(a<0)?null:this.value.slice(a)},heirpart:function(){var a=this.value;var b=a.indexOf("?");if(b>=0){a=a.substring(0,b)}else{b=a.indexOf("#");if(b>=0){a=a.substring(0,b)}}var c=this.scheme();if(c!=null){a=a.slice(1+c.length)}return a},host:function(){var a=this.authority();var b=a.indexOf("@");if(b>=0){a=a.slice(++b)}if(a.indexOf("[")==0){b=a.indexOf("]");if(b>0){return a.substring(0,b)}}b=a.lastIndexOf(":");return b>=0?a.substring(0,b):a},path:function(){var a=this.authority();if(a==null){return this.heirpart()}return this.heirpart().slice(a.length+2)},port:function(){var a=this.authority();var b=a.indexOf("@");if(b>=0){a=a.slice(++b)}if(a.indexOf("[")==0){b=a.indexOf("]");if(b>0){return a.substring(0,b)}}b=a.lastIndexOf(":");if(b<0){return null}a=a.slice(++b);return a.length==0?null:a},query:function(){var b=this.value.indexOf("?");if(b<0){return null}var a=this.value.indexOf("#");if(a<0){return this.value.slice(b)}return this.value.substring(b,a)},removeDotSegments:function(b){var a="";var c=0;while(b.length>0){if(b.substr(0,3)=="../"||b.substr(0,2)=="./"){b=b.slice(b.indexOf("/"))}else{if(b=="/."){b="/"}else{if(b.substr(0,3)=="/./"){b=b.slice(2)}else{if(b.substr(0,4)=="/../"||b=="/.."){(b=="/..")?b="/":b=b.slice(3);c=a.lastIndexOf("/");(c>=0)?a=a.substring(0,c):a=""}else{if(b.substr(0,2)==".."||b.substr(0,1)=="."){b=b.slice(b.indexOf("."));c=b.indexOf(".");if(c>=0){b=b.slice(c)}}else{if(b.substr(0,1)=="/"){a+="/";b=b.slice(1)}c=b.indexOf("/");if(c<0){a+=b;b=""}else{a+=b.substring(0,c);b=b.slice(c)}}}}}}}return a},resolveReference:function(c){var a;if(typeof c=="string"){a=new api.IRI(c)}else{if(c.nodeType&&c.nodeType()=="IRI"){a=c}else{throw new Error("Expected IRI or String")}}var b={scheme:"",authority:"",path:"",query:"",fragment:""};var d="";if(a.scheme()!=null){b.scheme=a.scheme();d=a.authority();b.authority+=d!=null?"//"+d:"";b.path=this.removeDotSegments(a.path());d=a.query();b.query+=d!=null?d:""}else{d=a.authority();if(d!=null){b.authority=d!=null?"//"+d:"";b.path=this.removeDotSegments(a.path());d=a.query();b.query+=d!=null?d:""}else{d=a.path();if(d==""||d==null){b.path=this.path();d=a.query();if(d!=null){b.query+=d}else{d=this.query();b.query+=d!=null?d:""}}else{if(d.substring(0,1)=="/"){b.path=this.removeDotSegments(d)}else{if(this.path()!=null){var e=this.path().lastIndexOf("/");if(e>=0){b.path=this.path().substring(0,++e)}b.path+=a.path()}else{b.path="/"+d}b.path=this.removeDotSegments(b.path)}d=a.query();b.query+=d!=null?d:""}d=this.authority();b.authority=d!=null?"//"+d:""}b.scheme=this.scheme()}d=a.fragment();b.fragment=d!=null?d:"";return new api.IRI(b.scheme+":"+b.authority+b.path+b.query+b.fragment)},scheme:function(){var a=this.value.match(api.IRI.SCHEME_MATCH);return(a==null)?null:a.shift().slice(0,-1)},userinfo:function(){var b=this.authority();var a=b.indexOf("@");return(a<0)?null:b.substring(0,a)}};api.Data=function(){this.graph=new api.Graph;this.context=new api.Context};api.Data.prototype={context:null,graph:null,createContext:function(){return new api.Context}};api.Graph=function(b){this.length=0;this.graph=[];this.index={};if(Array.isArray(b)){this.importArray(b)}};api.Graph.prototype={length:null,graph:null,importArray:function(b){while(b.length>0){this.add(b.pop())}},get:function(a){return this.graph[a]},add:function(a){if(!this.index[a.subject.value]){this.index[a.subject.value]={}}if(!this.index[a.subject.value][a.property.value]){this.index[a.subject.value][a.property.value]=[]}if(this.index[a.subject.value][a.property.value].some(function(b){return b.equals(a.object)})){return}this.length++;this.index[a.subject.value][a.property.value].push(a.object);this.graph.push(a)},merge:function(b){var c=0,d=b.length;while(c<d){var a=c++;this.add(b.get(a))}},every:function(a){return this.graph.every(a)},some:function(a){return this.graph.some(a)},forEach:function(a){this.graph.forEach(a)},filter:function(a){return new api.Graph(this.graph.filter(a))},apply:function(a){this.graph=this.graph.filter(a);this.length=this.graph.length},toArray:function(){return this.graph.slice()}};api.SlowGraph=function(b){this.length=0;this.graph=new Array;if(Array.isArray(b)){this.importArray(b)}};api.SlowGraph.prototype={length:null,graph:null,importArray:function(b){while(b.length>0){this.add(b.pop())}},get:function(a){return this.graph[a]},add:function(a){if(this.graph.some(function(b){return b.equals(a)})){return}this.length++;this.graph.push(a)},merge:function(b){var c=0,d=b.length;while(c<d){var a=c++;this.add(b.get(a))}},every:function(a){return this.graph.every(a)},some:function(a){return this.graph.some(a)},forEach:function(a){this.graph.forEach(a)},filter:function(a){return new api.SlowGraph(this.graph.filter(a))},apply:function(a){this.graph=this.graph.filter(a);this.length=this.graph.length},toArray:function(){return this.graph.slice()}};api.Context=function(){this.curieMap=new api.Hash;this.converterMap=new api.Hash;this._loadDefaultPrefixMap();this._loadDefaultTypeConverters()};api.Context.prototype={base:null,converterMap:null,curieMap:null,createBlankNode:function(){return new api.BlankNode},createIRI:function(b){var a=new api.IRI(b);if(a.scheme()==null&&this.base!=null){a=this.base.resolveReference(a)}return a},createPlainLiteral:function(a,b){return new api.PlainLiteral(a,b)},createTypedLiteral:function(b,a){a=this._resolveType(a);if(a==this._resolveType("rdf:PlainLiteral")){return this.createPlainLiteral(b)}return new api.TypedLiteral(b,this.createIRI(a))},createTriple:function(a,b,c){return new api.RDFTriple(a,b,c)},createGraph:function(b){return new api.Graph(b)},getMapping:function(){return this.curieMap},setMapping:function(b,c){if(b.slice(-1)==":"){b=b.slice(0,-1)}var a=new api.IRI(c);this.curieMap.set(b.toLowerCase(),a);return function(d){return new api.IRI(a.toString().concat(d))}},resolveCurie:function(c){var b=c.indexOf(":");if(b<0){return null}var d=c.slice(0,b).toLowerCase();var e=this.curieMap.get(d);if(e==null){return null}var a=new api.IRI(e.value.concat(c.slice(++b)));if(a.scheme()==null&&this.base!=null){a=this.base.resolveReference(a)}return a},convertTypedLiteral:function(a){var b=this.converterMap.get(a.type.toString());if(b!=null){try{return b(a.value,a.type)}catch(c){}}return a},registerTypeConversion:function(d,c){var b=this._resolveType(d);var a=this.converterMap.get(b);this.converterMap.remove(b);if(c!=null){this.converterMap.set(b,c)}return a?a:null},_resolveType:function(b){if(b.slice(0,2)=="^^"){b=b.slice(2)}var a=b.substring(0,3)=="xsd"?this.resolveCurie(b):this.createIRI(b);return a==null?b:a.value},_loadDefaultTypeConverters:function(){var d=function(f,e){return new String(f)};this.registerTypeConversion("xsd:string",d);var b=function(f,e){return(new Boolean(f)).valueOf()};this.registerTypeConversion("xsd:boolean",b);var c=function(f,e){return(new Number(f)).valueOf()};this.registerTypeConversion("xsd:float",c);this.registerTypeConversion("xsd:integer",c);this.registerTypeConversion("xsd:long",c);this.registerTypeConversion("xsd:double",c);this.registerTypeConversion("xsd:decimal",c);this.registerTypeConversion("xsd:nonPositiveInteger",c);this.registerTypeConversion("xsd:nonNegativeInteger",c);this.registerTypeConversion("xsd:negativeInteger",c);this.registerTypeConversion("xsd:int",c);this.registerTypeConversion("xsd:unsignedLong",c);this.registerTypeConversion("xsd:positiveInteger",c);this.registerTypeConversion("xsd:short",c);this.registerTypeConversion("xsd:unsignedInt",c);this.registerTypeConversion("xsd:byte",c);this.registerTypeConversion("xsd:unsignedShort",c);this.registerTypeConversion("xsd:unsignedByte",c);var a=function(f,e){return new Date(f)};this.registerTypeConversion("xsd:date",a);this.registerTypeConversion("xsd:time",a);this.registerTypeConversion("xsd:dateTime",a)},_loadDefaultPrefixMap:function(){this.setMapping("owl","http://www.w3.org/2002/07/owl#");this.setMapping("rdf","http://www.w3.org/1999/02/22-rdf-syntax-ns#");this.setMapping("rdfs","http://www.w3.org/2000/01/rdf-schema#");this.setMapping("rdfa","http://www.w3.org/ns/rdfa#");this.setMapping("xhv","http://www.w3.org/1999/xhtml/vocab#");this.setMapping("xml","http://www.w3.org/XML/1998/namespace");this.setMapping("xsd","http://www.w3.org/2001/XMLSchema#");this.setMapping("grddl","http://www.w3.org/2003/g/data-view#");this.setMapping("powder","http://www.w3.org/2007/05/powder#");this.setMapping("powders","http://www.w3.org/2007/05/powder-s#");this.setMapping("rif","http://www.w3.org/2007/rif#");this.setMapping("atom","http://www.w3.org/2005/Atom/");this.setMapping("xhtml","http://www.w3.org/1999/xhtml#");this.setMapping("formats","http://www.w3.org/ns/formats/");this.setMapping("xforms","http://www.w3.org/2002/xforms/");this.setMapping("xhtmlvocab","http://www.w3.org/1999/xhtml/vocab/");this.setMapping("xpathfn","http://www.w3.org/2005/xpath-functions#");this.setMapping("http","http://www.w3.org/2006/http#");this.setMapping("link","http://www.w3.org/2006/link#");this.setMapping("time","http://www.w3.org/2006/time#");this.setMapping("acl","http://www.w3.org/ns/auth/acl#");this.setMapping("cert","http://www.w3.org/ns/auth/cert#");this.setMapping("rsa","http://www.w3.org/ns/auth/rsa#");this.setMapping("crypto","http://www.w3.org/2000/10/swap/crypto#");this.setMapping("list","http://www.w3.org/2000/10/swap/list#");this.setMapping("log","http://www.w3.org/2000/10/swap/log#");this.setMapping("math","http://www.w3.org/2000/10/swap/math#");this.setMapping("os","http://www.w3.org/2000/10/swap/os#");this.setMapping("string","http://www.w3.org/2000/10/swap/string#");this.setMapping("doc","http://www.w3.org/2000/10/swap/pim/doc#");this.setMapping("contact","http://www.w3.org/2000/10/swap/pim/contact#");this.setMapping("p3p","http://www.w3.org/2002/01/p3prdfv1#");this.setMapping("swrl","http://www.w3.org/2003/11/swrl#");this.setMapping("swrlb","http://www.w3.org/2003/11/swrlb#");this.setMapping("exif","http://www.w3.org/2003/12/exif/ns#");this.setMapping("earl","http://www.w3.org/ns/earl#");this.setMapping("ma","http://www.w3.org/ns/ma-ont#");this.setMapping("sawsdl","http://www.w3.org/ns/sawsdl#");this.setMapping("sd","http://www.w3.org/ns/sparql-service-description#");this.setMapping("skos","http://www.w3.org/2004/02/skos/core#");this.setMapping("fresnel","http://www.w3.org/2004/09/fresnel#");this.setMapping("gen","http://www.w3.org/2006/gen/ont#");this.setMapping("timezone","http://www.w3.org/2006/timezone#");this.setMapping("skosxl","http://www.w3.org/2008/05/skos-xl#");this.setMapping("org","http://www.w3.org/ns/org#");this.setMapping("ical","http://www.w3.org/2002/12/cal/ical#");this.setMapping("wgs84","http://www.w3.org/2003/01/geo/wgs84_pos#");this.setMapping("vcard","http://www.w3.org/2006/vcard/ns#");this.setMapping("turtle","http://www.w3.org/2008/turtle#");this.setMapping("pointers","http://www.w3.org/2009/pointers#");this.setMapping("dcat","http://www.w3.org/ns/dcat#");this.setMapping("imreg","http://www.w3.org/2004/02/image-regions#");this.setMapping("rdfg","http://www.w3.org/2004/03/trix/rdfg-1/");this.setMapping("swp","http://www.w3.org/2004/03/trix/swp-2/");this.setMapping("rei","http://www.w3.org/2004/06/rei#");this.setMapping("wairole","http://www.w3.org/2005/01/wai-rdf/GUIRoleTaxonomy#");this.setMapping("states","http://www.w3.org/2005/07/aaa#");this.setMapping("wn20schema","http://www.w3.org/2006/03/wn/wn20/schema/");this.setMapping("httph","http://www.w3.org/2007/ont/httph#");this.setMapping("act","http://www.w3.org/2007/rif-builtin-action#");this.setMapping("common","http://www.w3.org/2007/uwa/context/common.owl#");this.setMapping("dcn","http://www.w3.org/2007/uwa/context/deliverycontext.owl#");this.setMapping("hard","http://www.w3.org/2007/uwa/context/hardware.owl#");this.setMapping("java","http://www.w3.org/2007/uwa/context/java.owl#");this.setMapping("loc","http://www.w3.org/2007/uwa/context/location.owl#");this.setMapping("net","http://www.w3.org/2007/uwa/context/network.owl#");this.setMapping("push","http://www.w3.org/2007/uwa/context/push.owl#");this.setMapping("soft","http://www.w3.org/2007/uwa/context/software.owl#");this.setMapping("web","http://www.w3.org/2007/uwa/context/web.owl#");this.setMapping("content","http://www.w3.org/2008/content#");this.setMapping("vs","http://www.w3.org/2003/06/sw-vocab-status/ns#");this.setMapping("air","http://dig.csail.mit.edu/TAMI/2007/amord/air#");this.setMapping("ex","http://example.org/");this.setMapping("dc","http://purl.org/dc/terms/");this.setMapping("dc11","http://purl.org/dc/elements/1.1/");this.setMapping("dctype","http://purl.org/dc/dcmitype/");this.setMapping("foaf","http://xmlns.com/foaf/0.1/");this.setMapping("cc","http://creativecommons.org/ns#");this.setMapping("opensearch","http://a9.com/-/spec/opensearch/1.1/");this.setMapping("void","http://rdfs.org/ns/void#");this.setMapping("sioc","http://rdfs.org/sioc/ns#");this.setMapping("sioca","http://rdfs.org/sioc/actions#");this.setMapping("sioct","http://rdfs.org/sioc/types#");this.setMapping("lgd","http://linkedgeodata.org/vocabulary#");this.setMapping("moat","http://moat-project.org/ns#");this.setMapping("days","http://ontologi.es/days#");this.setMapping("giving","http://ontologi.es/giving#");this.setMapping("lang","http://ontologi.es/lang/core#");this.setMapping("like","http://ontologi.es/like#");this.setMapping("status","http://ontologi.es/status#");this.setMapping("og","http://opengraphprotocol.org/schema/");this.setMapping("protege","http://protege.stanford.edu/system#");this.setMapping("dady","http://purl.org/NET/dady#");this.setMapping("uri","http://purl.org/NET/uri#");this.setMapping("audio","http://purl.org/media/audio#");this.setMapping("video","http://purl.org/media/video#");this.setMapping("gridworks","http://purl.org/net/opmv/types/gridworks#");this.setMapping("hcterms","http://purl.org/uF/hCard/terms/");this.setMapping("bio","http://purl.org/vocab/bio/0.1/");this.setMapping("cs","http://purl.org/vocab/changeset/schema#");this.setMapping("geographis","http://telegraphis.net/ontology/geography/geography#");this.setMapping("doap","http://usefulinc.com/ns/doap#");this.setMapping("daml","http://www.daml.org/2001/03/daml+oil#");this.setMapping("geonames","http://www.geonames.org/ontology#");this.setMapping("sesame","http://www.openrdf.org/schema/sesame#");this.setMapping("cv","http://rdfs.org/resume-rdf/");this.setMapping("wot","http://xmlns.com/wot/0.1/");this.setMapping("media","http://purl.org/microformat/hmedia/");this.setMapping("ctag","http://commontag.org/ns#")}};api.data=new api.Data;return api}();(function(a){if(!a.querylangs){a.querylangs={}}a.querylangs.RDFSelector=function(b){this.context=b};a.querylangs.RDFSelector.PATH_START=new RegExp("^[^!\\^]+","ig");a.querylangs.RDFSelector.PATH_PARTS=new RegExp("[!\\^][^!\\^]+","ig");a.querylangs.RDFSelector.prototype={context:null,select:function(g,l){var k=this;var h=g.match(a.querylangs.RDFSelector.PATH_START).map(function(p,n,m){return k.context.resolveCurie(p).toNT()});var f=g.match(a.querylangs.RDFSelector.PATH_PARTS);var c="";while(f.length>1){c=f.shift();var i=[[]];var b=[k.context.resolveCurie(c.slice(1))];switch(c.charAt(0)){case"!":h.forEach(function(m,n){return function(r,q,p){l.forEach(function(s,t){return function(u,w,v){if(u.subject.toNT()==r&&u.property.equals(t[0])&&!s[0].contains(u.object.toNT())){s[0].push(u.object.toNT())}}}(m,n))}}(i,b));break;case"^":h.forEach(function(m,n){return function(r,q,p){l.forEach(function(s,t){return function(u,w,v){if(u.object.toNT()==r&&u.property.equals(t[0])&&!s[0].contains(u.subject.toNT())){s[0].push(u.subject.toNT())}}}(m,n))}}(i,b));break}h=i[0]}c=f.pop();var d=new Object({});f=c.slice(1).split(",").map(function(p,n,m){var q=k.context.resolveCurie(p).toNT();d[q]=p;return q});var e=new Array;h.forEach(function(p,n,m){var q=new Object({});f.forEach(function(t,s,r){q[d[t]]=[]});q.uri=p;e.push(q)});var j=l;if(c.charAt(0)=="!"){j.filter(function(n,m,p){return h.contains(n.subject.toNT())}).forEach(function(n,m,p){if(f.contains(n.property.toNT())){e[h.indexOf(n.subject.toNT())][d[n.property.toNT()]].push(n.object)}})}else{j.filter(function(n,m,p){return h.contains(n.object.toNT())}).forEach(function(n,m,p){if(f.contains(n.property.toNT())){e[h.indexOf(n.object.toNT())][d[n.property.toNT()]].push(n.subject)}})}return e}};a.select=function(c,b){return new a.querylangs.RDFSelector(a.data.context).select(c,b)}})(rdfapi);(function(a){if(!a.parsers){a.parsers={}}a.parsers.u8=new RegExp("\\\\U([A-F0-9]{8})","g");a.parsers.u4=new RegExp("\\\\u([A-F0-9]{4})","g");a.parsers.hexToChar=function(c){var b="";var d=parseInt(c,16);if(d<=65535){b+=String.fromCharCode(d)}else{if(d<=1114111){d-=65536;b+=String.fromCharCode(55296+(d>>10),56320+(d&1023))}else{throw new Error("code point isn't known: "+d)}}return b};a.parsers.decodeString=function(b){b=b.replace(a.parsers.u8,function(c,d){return a.parsers.hexToChar(d)});b=b.replace(a.parsers.u4,function(c,d){return a.parsers.hexToChar(d)});b=b.replace(new RegExp("\\\\t","g"),"\t");b=b.replace(new RegExp("\\\\n","g"),"\n");b=b.replace(new RegExp("\\\\r","g"),"\r");b=b.replace(new RegExp('\\\\"',"g"),'"');b=b.replace(new RegExp("\\\\\\\\","g"),"\\");return b};a.parsers.NTriples=function(b){this.context=b;this.bnHash=new a.Hash};a.parsers.NTriples.isComment=new RegExp("^[ \t]*#","");a.parsers.NTriples.isEmptyLine=new RegExp("^[ \t]*$","");a.parsers.NTriples.initialWhitespace=new RegExp("^[ \t]+","");a.parsers.NTriples.trailingWhitespace=new RegExp("[. \t]+$","");a.parsers.NTriples.whitespace=new RegExp("[ \t]+","");a.parsers.NTriples.objectMatcher=new RegExp("^([^ \t]+)[ \t]+([^ \t]+)[ \t]+(.*)$","");a.parsers.NTriples.trailingLanguage=new RegExp("@([a-z]+[-a-z0-9]+)$","");a.parsers.NTriples.typedLiteralMatcher=new RegExp('^"(.*)"(.{2})<([^>]+)>$',"");a.parsers.NTriples.eolMatcher=new RegExp("\r\n|\n|\r","g");a.parsers.NTriples.prototype={context:null,quick:null,bnHash:null,graph:null,filter:null,processor:null,parse:function(e,b,c,d){this.graph=d==null?this.context.createGraph():d;this.filter=c;this.quick=false;this.internalParse(e);if(b!=null){b(this.graph)}return true},process:function(d,c,b){this.processor=c;this.filter=b;this.quick=true;return this.internalParse(d)},getBlankNode:function(c){if(this.bnHash.exists(c)){return this.bnHash.get(c)}var b=this.context.createBlankNode();this.bnHash.set(c,b);return b},internalParse:function(e){var d=new String(e);var b=d.split(a.parsers.NTriples.eolMatcher);var c=this;b.forEach(function(g,f,h){c.readLine(g,f,h)});return true},negotiateLiteral:function(b){if(b.slice(-1)=='"'){return this.context.createPlainLiteral(a.parsers.decodeString(b.slice(1,-1)))}var d=b.match(a.parsers.NTriples.trailingLanguage);if(d!=null){return this.context.createPlainLiteral(a.parsers.decodeString(b.slice(1,-1-d.shift().length)),d.pop())}var c=b.match(a.parsers.NTriples.typedLiteralMatcher);return this.context.createTypedLiteral(a.parsers.decodeString(c[1]),c.pop())},readLine:function(j,e,f){if(a.parsers.NTriples.isComment.test(j)||a.parsers.NTriples.isEmptyLine.test(j)){return}j=j.replace(a.parsers.NTriples.initialWhitespace,"").replace(a.parsers.NTriples.trailingWhitespace,"");var d=j.split(a.parsers.NTriples.whitespace,2);d.push(j.replace(a.parsers.NTriples.objectMatcher,"$3"));var i;if(d[0].charAt(0)=="<"){i=this.context.createIRI(a.parsers.decodeString(d[0].slice(1,-1)))}else{i=this.getBlankNode(d[0].slice(2))}d.shift();var b=this.context.createIRI(d.shift().slice(1,-1));var c;switch(d[0].charAt(0)){case"<":c=this.context.createIRI(a.parsers.decodeString(d[0].slice(1,-1)));break;case"_":c=this.getBlankNode(d[0].slice(2));break;default:c=this.negotiateLiteral(d[0]);break}var h=this.context.createTriple(i,b,c);var g=true;if(this.filter!=null){g=this.filter(h,null,null)}if(!g){return}this.quick?this.processor(h):this.graph.add(h)}};a.parsers.Turtle=function(b){this.context=b;this.bnHash=new a.Hash};a.parsers.Turtle.isWhitespace=new RegExp("^[ \t\r\n#]+","");a.parsers.Turtle.initialWhitespace=new RegExp("^[ \t\r\n]+","");a.parsers.Turtle.initialComment=new RegExp("^#[^\r\n]*","");a.parsers.Turtle.simpleToken=new RegExp("^[^ \t\r\n]+","");a.parsers.Turtle.simpleObjectToken=new RegExp("^[^ \t\r\n;,]+","");a.parsers.Turtle.tokenInteger=new RegExp("^(-|\\+)?[0-9]+$","");a.parsers.Turtle.tokenDouble=new RegExp("^(-|\\+)?(([0-9]+\\.[0-9]*[eE]{1}(-|\\+)?[0-9]+)|(\\.[0-9]+[eE]{1}(-|\\+)?[0-9]+)|([0-9]+[eE]{1}(-|\\+)?[0-9]+))$","");a.parsers.Turtle.tokenDecimal=new RegExp("^(-|\\+)?[0-9]*\\.[0-9]+?$","");a.parsers.Turtle.prototype={bnHash:null,context:null,filter:null,processor:null,quick:null,graph:null,parse:function(e,b,c,d){this.graph=d==null?this.context.createGraph():d;this.filter=c;this.quick=false;this.parseStatements(new String(e));if(b!=null){b(this.graph)}return true},process:function(d,c,b){this.processor=c;this.filter=b;this.quick=true;return this.parseStatements(new String(d))},t:function(){return{o:null}},parseStatements:function(b){b=b.toString();while(b.length>0){b=this.skipWS(b);if(b.length==0){return true}b.charAt(0)=="@"?b=this.consumeDirective(b):b=this.consumeStatement(b);this.expect(b,".");b=this.skipWS(b.slice(1))}return true},add:function(c){var b=true;if(this.filter!=null){b=this.filter(c,null,null)}if(!b){return}this.quick?this.processor(c):this.graph.add(c)},consumeBlankNode:function(c,b){b.o=this.context.createBlankNode();c=this.skipWS(c.slice(1));if(c.charAt(0)=="]"){return c.slice(1)}c=this.skipWS(this.consumePredicateObjectList(c,b));this.expect(c,"]");return this.skipWS(c.slice(1))},consumeCollection:function(f,e){e.o=this.context.createBlankNode();var c=this.t();c.o=e.o;f=this.skipWS(f.slice(1));var b=f.charAt(0)!=")";if(!b){e.o=this.context.resolveCurie("rdf:nil")}while(b){var g=this.t();switch(f.charAt(0)){case"[":f=this.consumeBlankNode(f,g);break;case"_":f=this.consumeKnownBlankNode(f,g);break;case"(":f=this.consumeCollection(f,g);break;case"<":f=this.consumeURI(f,g);break;case'"':f=this.consumeLiteral(f,g);break;default:var d=f.match(a.parsers.Turtle.simpleObjectToken).shift();if(d.charAt(d.length-1)==")"){d=d.substring(0,d.length-1)}if(d=="false"||d=="true"){g.o=this.context.createTypedLiteral(d,"xsd:boolean")}else{if(d.indexOf(":")>-1){g.o=this.context.resolveCurie(d)}else{if(a.parsers.Turtle.tokenInteger.test(d)){g.o=this.context.createTypedLiteral(d,"xsd:integer")}else{if(a.parsers.Turtle.tokenDouble.test(d)){g.o=this.context.createTypedLiteral(d,"xsd:double")}else{if(a.parsers.Turtle.tokenDecimal.test(d)){g.o=this.context.createTypedLiteral(d,"xsd:decimal")}else{throw new Error("unrecognised token: "+d)}}}}}f=f.slice(d.length);break}this.add(this.context.createTriple(c.o,this.context.resolveCurie("rdf:first"),g.o));f=this.skipWS(f);b=f.charAt(0)!=")";if(b){this.add(this.context.createTriple(c.o,this.context.resolveCurie("rdf:rest"),c.o=this.context.createBlankNode()))}else{this.add(this.context.createTriple(c.o,this.context.resolveCurie("rdf:rest"),this.context.resolveCurie("rdf:nil")))}}return this.skipWS(f.slice(1))},consumeDirective:function(b){var d=0;if(b.substring(1,7)=="prefix"){b=this.skipWS(b.slice(7));d=b.indexOf(":");var c=b.substring(0,d);b=this.skipWS(b.slice(++d));this.expect(b,"<");this.context.setMapping(c,a.parsers.decodeString(b.substring(1,d=b.indexOf(">"))));b=this.skipWS(b.slice(++d))}else{if(b.substring(1,5)=="base"){b=this.skipWS(b.slice(5));this.expect(b,"<");this.context.base=this.context.createIRI(a.parsers.decodeString(b.substring(1,d=b.indexOf(">"))));b=this.skipWS(b.slice(++d))}else{throw new Error("Unknown directive: "+b.substring(0,50))}}return b},consumeKnownBlankNode:function(c,b){this.expect(c,"_:");var d=c.slice(2).match(a.parsers.Turtle.simpleToken).shift();b.o=this.getBlankNode(d);return c.slice(d.length+2)},consumeLiteral:function(e,g){var f="";var d=true;var b=0;if(e.substring(0,3)=='"""'){b=3;while(d){b=e.indexOf('"""',b);if(d=e.charAt(b-1)=="\\"){b++}}f=e.substring(3,b);e=e.slice(f.length+6)}else{while(d){b=e.indexOf('"',b+1);d=e.charAt(b-1)=="\\"}f=e.substring(1,b);e=e.slice(f.length+2)}f=a.parsers.decodeString(f);switch(e.charAt(0)){case"@":var c=e.match(a.parsers.Turtle.simpleObjectToken).shift();g.o=this.context.createPlainLiteral(f,c.slice(1));e=e.slice(c.length);break;case"^":var c=e.match(a.parsers.Turtle.simpleObjectToken).shift().slice(2);if(c.charAt(0)=="<"){g.o=this.context.createTypedLiteral(f,c.substring(1,c.length-1))}else{g.o=this.context.createTypedLiteral(f,c)}e=e.slice(c.length+2);break;default:g.o=this.context.createPlainLiteral(f);break}return e},consumeObjectList:function(e,d,f){var b=true;while(b){var g=this.t();switch(e.charAt(0)){case"[":e=this.consumeBlankNode(e,g);break;case"_":e=this.consumeKnownBlankNode(e,g);break;case"(":e=this.consumeCollection(e,g);break;case"<":e=this.consumeURI(e,g);break;case'"':e=this.consumeLiteral(e,g);break;default:var c=e.match(a.parsers.Turtle.simpleObjectToken).shift();if(c.charAt(c.length-1)=="."){c=c.substring(0,c.length-1)}if(c=="false"||c=="true"){g.o=this.context.createTypedLiteral(c,"xsd:boolean")}else{if(c.indexOf(":")>-1){g.o=this.context.resolveCurie(c)}else{if(a.parsers.Turtle.tokenInteger.test(c)){g.o=this.context.createTypedLiteral(c,"xsd:integer")}else{if(a.parsers.Turtle.tokenDouble.test(c)){g.o=this.context.createTypedLiteral(c,"xsd:double")}else{if(a.parsers.Turtle.tokenDecimal.test(c)){g.o=this.context.createTypedLiteral(c,"xsd:decimal")}else{throw new Error("unrecognised token: "+c)}}}}}e=e.slice(c.length);break}this.add(this.context.createTriple(d.o,f,g.o));e=this.skipWS(e);b=e.charAt(0)==",";if(b){e=this.skipWS(e.slice(1))}}return e},consumePredicateObjectList:function(e,d){var c=true;while(c){var b=e.match(a.parsers.Turtle.simpleToken).shift();var f=null;if(b=="a"){f=this.context.resolveCurie("rdf:type")}else{switch(b.charAt(0)){case"<":f=this.context.createIRI(a.parsers.decodeString(b.substring(1,b.indexOf(">"))));break;default:f=this.context.resolveCurie(b);break}}e=this.skipWS(e.slice(b.length));e=this.consumeObjectList(e,d,f);c=e.charAt(0)==";";if(c){e=this.skipWS(e.slice(1))}}return e},consumeQName:function(c,b){var d=c.match(a.parsers.Turtle.simpleToken).shift();b.o=this.context.resolveCurie(d);return c.slice(d.length)},consumeStatement:function(c){var b=this.t();switch(c.charAt(0)){case"[":c=this.consumeBlankNode(c,b);if(c.charAt(0)=="."){return c}break;case"_":c=this.consumeKnownBlankNode(c,b);break;case"(":c=this.consumeCollection(c,b);break;case"<":c=this.consumeURI(c,b);break;default:c=this.consumeQName(c,b);break}c=this.consumePredicateObjectList(this.skipWS(c),b);return c},consumeURI:function(c,b){this.expect(c,"<");var d=0;b.o=this.context.createIRI(a.parsers.decodeString(c.substring(1,d=c.indexOf(">"))));return c.slice(++d)},expect:function(c,b){if(c.substring(0,b.length)==b){return}throw new Error("Expected token: "+b+" at "+c.substring(0,50))},getBlankNode:function(c){if(this.bnHash.exists(c)){return this.bnHash.get(c)}var b=this.context.createBlankNode();this.bnHash.set(c,b);return b},skipWS:function(b){while(a.parsers.Turtle.isWhitespace.test(b.charAt(0))){b=b.replace(a.parsers.Turtle.initialWhitespace,"");if(b.charAt(0)=="#"){b=b.replace(a.parsers.Turtle.initialComment,"")}}return b}};a.parsers.RDFXML=function(b){this.context=b;this.bnHash=new a.Hash};a.parsers.RDFXML.NS_RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#";a.parsers.RDFXML.NS_RDFS="http://www.w3.org/2000/01/rdf-schema#";a.parsers.RDFXML.RDF_TYPE=new a.IRI(a.parsers.RDFXML.NS_RDF+"type");a.parsers.RDFXML.RDF_RDF=new a.IRI(a.parsers.RDFXML.NS_RDF+"RDF");a.parsers.RDFXML.RDF_DESCRIPTION=new a.IRI(a.parsers.RDFXML.NS_RDF+"Description");a.parsers.RDFXML.RDF_STATEMENT=new a.IRI(a.parsers.RDFXML.NS_RDF+"Statement");a.parsers.RDFXML.RDF_SUBJECT=new a.IRI(a.parsers.RDFXML.NS_RDF+"subject");a.parsers.RDFXML.RDF_PREDICATE=new a.IRI(a.parsers.RDFXML.NS_RDF+"predicate");a.parsers.RDFXML.RDF_OBJECT=new a.IRI(a.parsers.RDFXML.NS_RDF+"object");a.parsers.RDFXML.RDF_LI=new a.IRI(a.parsers.RDFXML.NS_RDF+"li");a.parsers.RDFXML.RDF_FIRST=new a.IRI(a.parsers.RDFXML.NS_RDF+"first");a.parsers.RDFXML.RDF_REST=new a.IRI(a.parsers.RDFXML.NS_RDF+"rest");a.parsers.RDFXML.RDF_NIL=new a.IRI(a.parsers.RDFXML.NS_RDF+"nil");a.parsers.RDFXML.prototype={base:null,bnHash:null,context:null,filter:null,processor:null,quick:null,graph:null,parse:function(e,b,c,d){this.graph=d==null?new a.Graph:d;this.filter=c;this.quick=false;this.parseStatements(e);if(b!=null){b(this.graph)}return},process:function(d,c,b){this.processor=c;this.filter=b;this.quick=true;return this.parseStatements(d)},add:function(c){var b=true;if(this.filter!=null){b=this.filter(c,null,null)}if(!b){return}this.quick?this.processor(c):this.graph.add(c)},addArc:function(c,b){if(b.equals(a.parsers.RDFXML.RDF_LI)){b=this.context.resolveCurie("rdf:_"+c.parent.listIndex++)}this.addSymbol(c,2,b.toString())},addBNode:function(c,b){b!=null?c.node=this.getBlankNode(b):c.node=this.context.createBlankNode();c.nodeType=1;if(this.isTripleToLoad(c)){this.addFrame(c)}},addCollection:function(b){b.collection=true;this.addBNode(b)},addFrame:function(c){this.add(this.createTriple(c.parent.parent.node,c.parent.node,c.node));if(c.rdfid!=null||c.parent.rdfid!=null){if(c.parent.rdfid!=null&&c.rdfid==null){c.rdfid=c.parent.rdfid}var b=c.base.resolveReference("#".concat(c.rdfid));this.add(this.createTriple(b,a.parsers.RDFXML.RDF_TYPE,a.parsers.RDFXML.RDF_STATEMENT));this.add(this.createTriple(b,a.parsers.RDFXML.RDF_SUBJECT,c.parent.parent.node));this.add(this.createTriple(b,a.parsers.RDFXML.RDF_PREDICATE,c.parent.node));this.add(this.createTriple(b,a.parsers.RDFXML.RDF_OBJECT,c.node))}},addLiteral:function(c,b){c.nodeType=1;if(c.parent.datatype!=null){c.node=this.context.createTypedLiteral(b==null?c.element.nodeValue:b,c.parent.datatype)}else{c.node=this.context.createPlainLiteral(b==null?c.element.nodeValue:b,c.lang)}if(this.isTripleToLoad(c)){this.addFrame(c)}},addNode:function(c,b){this.addSymbol(c,1,b);if(this.isTripleToLoad(c)){this.addFrame(c)}},addSymbol:function(d,b,c){d.node=d.base.resolveReference(c);d.nodeType=b},buildFrame:function(g,f){var j={parent:g,element:f,lastChild:0,base:null,lang:null,node:null,nodeType:null,listIndex:1,rdfid:null,datatype:null,collection:false};if(g!=null){j.base=g.base;j.lang=g.lang}if(f==null||f.nodeType==3||f.nodeType==4){return j}var h=f.getAttributeNode("xml:base");if(h!=null){j.base=this.context.createIRI(h.nodeValue);f.removeAttribute("xml:base")}h=f.getAttributeNode("xml:lang");if(h!=null){j.lang=h.nodeValue;f.removeAttribute("xml:lang")}var b=f.attributes;var e=b.length-1;while(e>-1){if(b.item(e).nodeName.substring(0,3)=="xml"){if(b.item(e).name.substring(0,6)=="xmlns:"){var k=b.item(e).nodeValue;if(this.base!=null){k=this.base.resolveReference(k).toString()}this.context.setMapping(b.item(e).name.slice(6),k)}f.removeAttributeNode(b.item(e))}e--}return j},createTriple:function(b,c,d){return this.context.createTriple(b,c,d)},getBlankNode:function(c){if(this.bnHash.exists(c)){return this.bnHash.get(c)}var b=this.context.createBlankNode();this.bnHash.set(c,b);return b},isTripleToLoad:function(b){return b.parent!=null&&b.parent.parent!=null&&b.nodeType==1&&b.parent.nodeType==2&&b.parent.parent.nodeType==1},parseDOM:function(d){var t=true;while(d.parent!=null){var r=d.element;if(r.nodeType==3||r.nodeType==4){this.addLiteral(d)}else{if(!a.parsers.RDFXML.RDF_RDF.equals(this.resolveNamespaceURI(r))){if(d.parent!=null&&d.parent.collection){d.parent.listIndex++;this.addArc(d,a.parsers.RDFXML.RDF_FIRST);d=this.buildFrame(d,d.element);d.parent.element=null}if(d.parent==null||d.parent.nodeType==null||d.parent.nodeType==2){var j=r.getAttributeNodeNS(a.parsers.RDFXML.NS_RDF,"about");var h=r.getAttributeNodeNS(a.parsers.RDFXML.NS_RDF,"ID");if(j!=null&&h!=null){throw new Error("RDFParser: "+r.nodeName+" has both rdf:id and rdf:about, only one may be specified")}if(j==null&&h!=null){this.addNode(d,"#"+h.nodeValue);r.removeAttributeNode(h)}else{if(j==null&&h==null){if((j=r.getAttributeNodeNS(a.parsers.RDFXML.NS_RDF,"nodeID"))!=null){this.addBNode(d,j.nodeValue);r.removeAttributeNode(j)}else{this.addBNode(d)}}else{this.addNode(d,j.nodeValue);r.removeAttributeNode(j)}}j=r.getAttributeNodeNS(a.parsers.RDFXML.NS_RDF,"type");if(!this.resolveNamespaceURI(r).equals(a.parsers.RDFXML.RDF_DESCRIPTION)){j={nodeValue:this.resolveNamespaceURI(r)}}if(j!=null){this.add(this.createTriple(d.node,a.parsers.RDFXML.RDF_TYPE,d.base.resolveReference(j.nodeValue)));if(j.nodeName!=null){r.removeAttributeNode(j)}}var p=r.attributes.length-1;while(p>-1){this.add(this.createTriple(d.node,this.resolveNamespaceURI(r.attributes.item(p)),this.context.createPlainLiteral(r.attributes.item(p).nodeValue,d.lang)));p--}}else{this.addArc(d,this.resolveNamespaceURI(r));var h=r.getAttributeNodeNS(a.parsers.RDFXML.NS_RDF,"ID");if(h!=null){d.rdfid=h.nodeValue;r.removeAttributeNode(h)}var l=r.getAttributeNodeNS(a.parsers.RDFXML.NS_RDF,"datatype");if(l!=null){d.datatype=l.nodeValue;r.removeAttributeNode(l)}var s=r.getAttributeNodeNS(a.parsers.RDFXML.NS_RDF,"parseType");if(s!=null){switch(s.nodeValue){case"Literal":d.datatype=a.parsers.RDFXML.NS_RDF+"XMLLiteral";d=this.buildFrame(d);var m="";var u=0;while(u<r.childNodes.length){var v=r.childNodes.item(u++);if(v.nodeType==3){m+=v.nodeValue}else{m+=(new XMLSerializer).serializeToString(r.firstElementChild)}}this.addLiteral(d,m);t=false;break;case"Resource":d=this.buildFrame(d,d.element);d.parent.element=null;this.addBNode(d);break;case"Collection":d=this.buildFrame(d,d.element);d.parent.element=null;this.addCollection(d);break}r.removeAttributeNode(s)}if(r.attributes.length!=0){var p=r.getAttributeNodeNS(a.parsers.RDFXML.NS_RDF,"resource");s=r.getAttributeNodeNS(a.parsers.RDFXML.NS_RDF,"nodeID");d=this.buildFrame(d);if(p!=null){this.addNode(d,p.nodeValue);r.removeAttributeNode(p)}else{if(s!=null){this.addBNode(d,s.nodeValue);r.removeAttributeNode(s)}else{this.addBNode(d)}}var k=r.attributes.length-1;while(k>-1){var g=this.buildFrame(d);p=r.attributes.item(k);this.addArc(g,this.resolveNamespaceURI(p));if(this.resolveNamespaceURI(p).equals(a.parsers.RDFXML.RDF_TYPE)){this.addNode(this.buildFrame(g),p.nodeValue)}else{this.addLiteral(this.buildFrame(g),p.nodeValue)}k--}}else{if(r.childNodes.length==0){this.addLiteral(this.buildFrame(d),"")}}}}}r=d.element;while(d.parent!=null){var q=d;while(r==null){d=d.parent;r=d.element}var s=r.childNodes.item(d.lastChild);if(s==null||!t){if(d.collection){this.add(this.createTriple(d.node,a.parsers.RDFXML.RDF_REST,a.parsers.RDFXML.RDF_NIL))}if((d=d.parent)==null){break}r=d.element;t=true}else{if(s.nodeType!=1&&s.nodeType!=3&&s.nodeType!=4||(s.nodeType==3||s.nodeType==4)&&r.childNodes.length!=1){d.lastChild++}else{if(d.collection&&d.listIndex>1){var b=this.context.createBlankNode();this.add(this.createTriple(d.node,a.parsers.RDFXML.RDF_REST,b));q.node=b}d.lastChild++;d=this.buildFrame(q,r.childNodes.item(d.lastChild-1));break}}}}},parseStatements:function(c){this.base=this.context.base;var b=this.buildFrame(null,null);b.base=this.base;this.parseDOM(this.buildFrame(b,c.documentElement));return true},resolveNamespaceURI:function(b){if(b.namespaceURI==null){throw new Error("RDF/XML syntax error: No namespace for "+b.localName+" in "+this.base)}return this.context.createIRI(b.namespaceURI+b.localName)}}})(rdfapi);(function(a){if(!a.serializers){a.serializers={}}a.serializers.NTriples=function(b){};a.serializers.NTriples.prototype={serialize:function(b){return b.toArray().join("\n")}};a.serializers.Turtle=function(b){this.context=b;this.createPrefixMap()};a.serializers.Turtle.NS_RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#";a.serializers.Turtle.RDF_TYPE=new a.IRI(a.serializers.Turtle.NS_RDF+"type");a.serializers.Turtle.RDF_RDF=new a.IRI(a.serializers.Turtle.NS_RDF+"RDF");a.serializers.Turtle.RDF_FIRST=new a.IRI(a.serializers.Turtle.NS_RDF+"first");a.serializers.Turtle.RDF_REST=new a.IRI(a.serializers.Turtle.NS_RDF+"rest");a.serializers.Turtle.RDF_NIL=new a.IRI(a.serializers.Turtle.NS_RDF+"nil");a.serializers.Turtle.prototype={context:null,index:null,lists:null,prefixMap:null,usedPrefixes:null,nonAnonBNodes:null,skipSubjects:null,serialize:function(c){this.initiate();c=this.suckLists(c);var b=this;c.forEach(function(e,d,f){b.addTripleToIndex(e,d,f)});return this.render()},addTripleToIndex:function(d,c,e){if(d.object.nodeType()=="BlankNode"){this.nonAnonBNodes.set(d.object.toString(),this.nonAnonBNodes.exists(d.object.toString())?this.nonAnonBNodes.get(d.object.toString())+1:1)}var b=this.shrink(d.subject);var f=this.shrink(d.property,true);if(!this.index.exists(b)){this.index.set(b,new a.Hash)}if(!this.index.get(b).exists(f)){this.index.get(b).set(f,new Array)}this.index.get(b).get(f).push(d.object)},anonBNode:function(c,b){return this.propertyObjectChain(this.index.get(c),b)},createPrefixMap:function(){var b=this.context.getMapping();var c=this.prefixMap=new a.Hash;b.keys().forEach(function(e,f,d){c.set(b.get(e).toString(),e.concat(":"))})},initiate:function(){this.index=new a.Hash;this.usedPrefixes=new Array;this.nonAnonBNodes=new a.Hash;this.skipSubjects=new Array;this.lists=new a.Hash},output:function(b){if(b.nodeType()=="IRI"){return this.shrink(b)}if(b.nodeType()=="TypedLiteral"){if(b.type.equals(this.context.resolveCurie("xsd:integer"))){return b.value}if(b.type.equals(this.context.resolveCurie("xsd:double"))){return b.value}if(b.type.equals(this.context.resolveCurie("xsd:decimal"))){return b.value}if(b.type.equals(this.context.resolveCurie("xsd:boolean"))){return b.value}return'"'+b.value+'"^^'+this.shrink(b.type)}return b.toNT()},propertyObjectChain:function(c,b){if(!c){return}if(b==null){b=2}var e="";var d=this;var f=c.keys();f.sort();if(f.contains("a")){f.remove("a");f.unshift("a")}f.forEach(function(h,i,g){e=e+(i>0?(new Array(b+1)).join(" "):"")+h+" ";c.get(h).forEach(function(m,l,j){var k="";if(j.length>2){k="\n"+(new Array(b+2+1)).join(" ")}if(m.toString().charAt(0)=="_"&&!d.nonAnonBNodes.exists(m.toString())){if(d.lists.exists(m.toNT())){e=e+d.renderList(m.toNT(),b+3)}else{e=e+k+"[ "+d.anonBNode(m.toString(),b+2+2)+k+(j.length==1?" ":"")+"]"}}else{e=e+k+d.output(m)}if(j.length-1!=l){if(j.length>2){e=e+","+(new Array(b+2+2)).join(" ")}else{e=e+", "}}});e=e+(g.length-1==i?"":";\n")});return e},render:function(){var d=new Array;var c=this;this.skipSubjects=this.nonAnonBNodes.keys();this.nonAnonBNodes.keys().forEach(function(g,h,f){if(c.nonAnonBNodes.get(g)==1){c.nonAnonBNodes.remove(g)}});this.index.keys().forEach(function(g,h,f){var i="";if(g.charAt(0)=="_"){if(!c.nonAnonBNodes.exists(g)&&!c.skipSubjects.contains(g)){if(c.lists.exists(g)){i=c.renderList(g,2)+" "+c.propertyObjectChain(c.index.get(g))}else{i="[ "+c.anonBNode(g,2)+"\n]"}}}else{i=g+" "+c.propertyObjectChain(c.index.get(g))}if(i.length>0){d.push(i+" .\n")}});if(this.usedPrefixes.length>0){var b=new a.Hash;this.prefixMap.keys().forEach(function(f,g,j){if(c.usedPrefixes.contains(f)){b.set(c.prefixMap.get(f),f)}});var e=b.keys();e.sort();e.reverse();d.unshift("");e.forEach(function(h,g,f){d.unshift("@prefix "+h+" <"+b.get(h)+"> .")})}return d.join("\n")},renderList:function(i,c){var f=this;var h=new Array;f.lists.get(i).forEach(function(l,k,j){h.push(f.output(l))});var e=new Array;var g="";while(h.length>0){var b=h.shift();if(g.length+b.length<75){g=g.concat(b+" ")}else{e.push(g);g=b+" "}}e.push(g);var d=e.length==1?" ":"\n"+(new Array(c)).join(" ");return"("+d+e.join(d)+(e.length==1?"":"\n")+")"},shrink:function(f,d){if(d==null){d=false}if(d&&f.equals(a.serializers.Turtle.RDF_TYPE)){return"a"}if(f.equals(a.serializers.Turtle.RDF_NIL)){return"()"}var e=0,c=this.prefixMap.keys();while(e<c.length){var b=c[e];++e;if(f.toString().startsWith(b)){if(!this.usedPrefixes.contains(b)){this.usedPrefixes.push(b)}return f.toString().replace(b,this.prefixMap.get(b))}}return f.toNT()},suckLists:function(g){var h=function(j){return function(l,k,m){return l.subject.equals(j)}};var d=function(j){return function(l,k,m){return l.property.equals(j)}};var i=function(j,k){return function(m,l,n){return m.property.equals(j)&&m.object.equals(k)}};var b=function(j){return function(l,k,m){return !(l.subject.equals(j.subject)&&l.property.equals(j.property)&&l.object.equals(j.object))}};var e=g.filter(function(k,j,l){return k.property.equals(a.serializers.Turtle.RDF_FIRST)||k.property.equals(a.serializers.Turtle.RDF_REST)});e.forEach(function(k,j,l){g=g.filter(b(k))});var c=e.filter(function(k,j,l){return k.object.equals(a.serializers.Turtle.RDF_NIL)});var f=this;c.forEach(function(r,j,k){var m=new Array;var l=r;var p=null;while(l!=null){p=l.subject;m.unshift(e.filter(h(p)).filter(d(a.serializers.Turtle.RDF_FIRST)).toArray().pop().object);e=e.filter(function(q,s,n){return !q.subject.equals(p)});l=e.filter(i(a.serializers.Turtle.RDF_REST,p)).toArray().pop()}f.lists.set(p.toNT(),m)});return g}};a.nt=function(b){return new a.serializers.NTriples(a.data.context).serialize(b)};a.turtle=function(b){return new a.serializers.Turtle(a.data.context).serialize(b)}})(rdfapi);(function(a){a.filters={s:function(b){return function(c){return b.equals(c.subject)}},p:function(b){return function(c){return b.equals(c.property)}},o:function(b){return function(c){return b.equals(c.object)}},sp:function(b,c){return function(d){return b.equals(d.subject)&&c.equals(d.property)}},so:function(b,c){return function(d){return b.equals(d.subject)&&c.equals(d.object)}},po:function(b,c){return function(d){return b.equals(d.property)&&c.equals(d.object)}},spo:function(b,c,d){return function(e){return b.equals(e.subject)&&c.equals(e.property)&&d.equals(e.object)}},describes:function(b){return function(c){return b.equals(c.subject)||b.equals(c.object)}}}})(rdfapi);(function(a){a.Converter=function(){this.c=a.data.context};a.Converter.INTEGER=new RegExp("^(-|\\+)?[0-9]+$","");a.Converter.DOUBLE=new RegExp("^(-|\\+)?(([0-9]+\\.[0-9]*[eE]{1}(-|\\+)?[0-9]+)|(\\.[0-9]+[eE]{1}(-|\\+)?[0-9]+)|([0-9]+[eE]{1}(-|\\+)?[0-9]+))$","");a.Converter.DECIMAL=new RegExp("^(-|\\+)?[0-9]*\\.[0-9]+?$","");a.Converter.prototype={c:null,_string:function(c,b){if(!(Boolean(b).valueOf())||b.indexOf(":")<0){return this.c.createPlainLiteral(c,b)}return this.c.createTypedLiteral(c,b)},_boolean:function(c){return this.c.createTypedLiteral(c?"true":"false","xsd:boolean")},_date:function(f,b){function e(d){return d<10?"0"+d:d}var c=f.getUTCFullYear()+"-"+e(f.getUTCMonth()+1)+"-"+e(f.getUTCDate())+"T"+e(f.getUTCHours())+":"+e(f.getUTCMinutes())+":"+e(f.getUTCSeconds());if(Boolean(b)){c+=f.getUTCMilliseconds()>0?c+"."+f.getUTCMilliseconds():c}return this.c.createTypedLiteral(c+="Z","xsd:dateTime")},_number:function(b){if(b==Number.POSITIVE_INFINITY){return this.c.createTypedLiteral("INF","xsd:double")}if(b==Number.NEGATIVE_INFINITY){return this.c.createTypedLiteral("-INF","xsd:double")}if(b==Number.NaN){return this.c.createTypedLiteral("NaN","xsd:double")}b=b.toString();if(a.Converter.INTEGER.test(b)){return this.c.createTypedLiteral(b,"xsd:integer")}if(a.Converter.DECIMAL.test(b)){return this.c.createTypedLiteral(b,"xsd:decimal")}if(a.Converter.DOUBLE.test(b)){return this.c.createTypedLiteral(b,"xsd:double")}throw new TypeError("Can't convert weird number: "+b)},convert:function(b,c){switch(typeof b){case"string":return this._string(b,c);case"boolean":return this._boolean(b);case"number":return this._number(b);case"object":switch(b.constructor.name){case"Boolean":return this._boolean(b.valueOf());case"Date":return this._date(b);case"Number":return this._number(b)}}throw new TypeError("Cannot convert type: "+b.constructor.name)}};a.converter=new a.Converter;a.resolve=function(b){return a.data.context.resolveCurie(b)};a.iri=function(b){b=b.toString();if(b.startsWith("<")&&b.endsWith(">")){b=b.slice(1,b.length-1)}return a.data.context.createIRI(b)};a.reference=function(b){if(typeof b=="string"&&b.indexOf("//")>=0){return a.iri(b)}return a.iri(a.resolve(b))};a.blankNode=function(d){var c=a.data.context.createBlankNode();if(d){if(d.substring(0,2)=="_:"){c.value=o}else{c.value="_:"+o}}return c};a.blankNodeOrIRI=function(b){if(typeof b=="string"){if(b.substring(0,2)=="_:"){b=a.blankNode(b)}else{b=a.reference(b)}}return b};a.literal=function(c,b){return a.converter.convert(c,b)};a.node=function(c,b){if(!b&&typeof c=="string"&&c.indexOf(":")>=0){c=a.blankNodeOrIRI(c)}if(!c.nodeType){c=a.literal(c,b)}return c};a.link=function(b,c,d){b=a.blankNodeOrIRI(b);d=a.blankNodeOrIRI(d);return a.data.context.createTriple(b,a.iri(c),d)};a.t=a.triple=function(c,d,e,b){c=a.blankNodeOrIRI(c);d=a.resolve(d);e=a.node(e,b);return a.data.context.createTriple(c,d,e)}})(rdfapi);(function(a){a.proxy=null;a.log=function(b){console.log(b)};a.singlify=function(d){var c=d.filter(a.filters.p(a.resolve("owl:sameAs")));while(c.length>0){var b={};a.uniqueResources(c).forEach(function(e){b[e.toNT()]=a.filterCount(d,a.filters.describes(e))});c.forEach(function(e){if(e.subject.nodeType()=="BlankNode"&&e.object.nodeType()=="IRI"){a.replace(d,e.subject,e.object)}else{if(e.subject.nodeType()=="IRI"&&e.object.nodeType()=="BlankNode"){a.replace(d,e.object,e.subject)}else{if(b[e.subject.toNT()]<b[e.object.toNT()]){a.replace(d,e.subject,e.object)}else{if(b[e.subject.toNT()]>b[e.object.toNT()]){a.replace(d,e.object,e.subject)}else{if(e.subject.nodeType()=="IRI"&&e.object.nodeType()=="IRI"){if(e.subject.toString().length>e.object.toString().length){a.replace(d,e.subject,e.object)}else{a.replace(d,e.object,e.subject)}}}}}}});c=d.filter(a.filters.p(a.resolve("owl:sameAs")))}};a.replace=function(b,c,e){a.log("replacing "+c.toNT()+" with "+e.toNT());var d=a.filters.describes(c);b.filter(d).forEach(function(f){if(f.subject.equals(c)){b.add(a.t(e,f.property,f.object))}else{if(f.object.equals(c)){b.add(a.t(f.subject,f.property,e))}}});b.apply(function(f){return !d(f)&&!f.subject.equals(f.object)});if(c.nodeType()!="BlankNode"){b.add(a.t(e,a.resolve("link:uri"),c))}};a.filterCount=function(d,b){var c=0;d.forEach(function(e){if(b(e)){++c}});return c};a.uniqueResources=function(c){var d=[];c.forEach(function(f){d.push(f.subject);if(f.object.nodeType()=="IRI"||f.object.nodeType()=="BlankNode"){d.push(f.object)}});var b=[];while(d.length>0){var e=d.pop();if(!b.some(function(f){return e.equals(f)})){b.push(e)}}return b};a.errorHandler=null;a.save=function(f,d){var b=false;var c=f.toString();f=(new a.IRI(f.toString())).defrag().toString();var e=new XMLHttpRequest;e.onreadystatechange=function(h){var g=this;if(g.readyState==4){if(g.status==200){alert("stored at "+c)}}};e.open("PUT",f,b);e.withCredentials=true;e.timeout=40000;e.setRequestHeader("Content-Type","text/turtle");e.send(d);return};a.get=function(f,b,c){if(c==null){c=true}var d=f.toString();f=(new a.IRI(f.toString())).defrag().toString();var e=new XMLHttpRequest;e.onreadystatechange=function(h){var g=this;if(g.readyState==4){if(g.status==200){try{b(g)}catch(h){if(a.errorHandler!=null){a.errorHandler(h)}else{throw h}}}else{if(a.errorHandler!=null){a.errorHandler(new Error("Failed to load resource "+d+" the server responded with a status of "+g.status))}}}};if(a.proxy!=null){f=a.proxy+f}e.open("GET",f,c);e.followRedirects=true;e.timeout=40000;e.setRequestHeader("Accept","application/rdf+xml;q=0.9, application/x-turtle;q=0.9, application/turtle;q=0.9, text/rdf+n3;q=0.9, text/turtle;q=0.9, text/rdf;q=0.9, application/n3;q=0.8, text/n3;q=0.8, application/xml;q=0.7, text/*;q=0.6, */*;q=0");e.send();return};a.negotiate=function(f,b,h){var g=null;var e=f.responseText;var c=f.getResponseHeader("Content-Type");if(c!=null){var d=c.indexOf(";");if(d>-1){c=c.substring(0,d)}}else{c=""}switch(c){case"application/rdf+xml":case"application/xml":case"text/xml":g=new a.parsers.RDFXML(b);e=f.responseXML;break;case"text/turtle":case"application/x-turtle":case"application/turtle":case"text/rdf+n3":case"text/n3":case"application/n3":g=new a.parsers.Turtle(b);break;case"text/rdf":case"text/text":case"text/plain":case"text/html":case"":if(f.responseXML){g=new a.parsers.RDFXML(b);e=f.responseXML}else{if(e.indexOf("xmlns:rdf=")>-1){g=new a.parsers.RDFXML(b);e=new DOMParser().parseFromString(e,"text/xml")}else{g=new a.parsers.Turtle(b)}}break}if(g==null){throw new Error(h.toString()+" Unrecognized mediatype: '"+c+"'")}return[g,e,c]};a.mergeContext=function(b){a.data.context.curieMap=b.curieMap;a.data.context._loadDefaultPrefixMap()};a.parse=function(g,b,e,f){if(g instanceof Document||(g.indexOf&&g.indexOf(" ")>0)){return a.parseDoc(g,b,e,f)}var d=b!=null;var c=a.data.createContext();var h=a.iri(g.toString());c.base=h;this.get(h.toString(),function(k){var j=a.negotiate(k,c,h);try{j[0].parse(j[1],b,e,f);a.mergeContext(c)}catch(i){throw new Error(h.toString()+" [ "+j[2]+" ] - "+i.toString())}},d);return true};a.parseDoc=function(f,b,c,d){var e=f instanceof Document?new a.parsers.RDFXML(a.data.createContext()):new a.parsers.Turtle(a.data.createContext());return e.parse(f,b,c,d)};a.process=function(f,e,d){var c=true;f=a.data.context.createIRI(f.toString());var b=a.data.createContext();b.base=f;this.get(f.toString(),function(h){var g=a.negotiate(h,b,f);g[0].process(g[1],e,d);a.mergeContext(b)},c);return true}})(rdfapi);Array.isArray=Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"};Array.prototype.some=Array.prototype.some||function(b){if(this===void 0||this===null){throw new TypeError()}var e=Object(this);var a=e.length>>>0;if(typeof b!=="function"){throw new TypeError()}var d=arguments[1];for(var c=0;c<a;c++){if(c in e&&b.call(d,e[c],c,e)){return true}}return false};Array.prototype.every=Array.prototype.every||function(b){if(this===void 0||this===null){throw new TypeError()}var e=Object(this);var a=e.length>>>0;if(typeof b!=="function"){throw new TypeError()}var d=arguments[1];for(var c=0;c<a;c++){if(c in e&&!b.call(d,e[c],c,e)){return false}}return true};Array.prototype.forEach=Array.prototype.forEach||function(b){if(this===void 0||this===null){throw new TypeError()}var e=Object(this);var a=e.length>>>0;if(typeof b!=="function"){throw new TypeError()}var d=arguments[1];for(var c=0;c<a;c++){if(c in e){b.call(d,e[c],c,e)}}};Array.prototype.filter=Array.prototype.filter||function(b){if(this===void 0||this===null){throw new TypeError()}var f=Object(this);var a=f.length>>>0;if(typeof b!=="function"){throw new TypeError()}var e=[];var d=arguments[1];for(var c=0;c<a;c++){if(c in f){var g=f[c];if(b.call(d,g,c,f)){e.push(g)}}}return e};String.prototype.endsWith=function(b,a){if(a){return b.toLowerCase()==this.substring(this.length-b.length).toLowerCase()}return b==this.substring(this.length-b.length)};String.prototype.startsWith=function(b,a){if(a){return b.toLowerCase()==this.substring(0,b.length).toLowerCase()}return b==this.substring(0,b.length)};Array.prototype.remove=function(b){var a=this.indexOf(b);if(a==-1){return false}this.splice(a,1);return true};Array.prototype.contains=function(a){return this.indexOf(a)>=0};if(typeof exports!="undefined"){module.exports=rdfapi}else{if(typeof document=="object"){document.data=rdfapi.data}};