├── README.md ├── bin └── merge.sh ├── js3.js ├── js3.min.js ├── js3.node.js └── source ├── core.js ├── curiemap.js ├── node.exports.js └── propertymap.js /README.md: -------------------------------------------------------------------------------- 1 | # JS3 - An insane integration of RDF in ECMAScript-262 V5 (Javascript) # 2 | 3 | In short, with this library, all your javascript is also RDF, there are no special types or classes, 4 | each variable and value is also an RDF Node, List or Graph. 5 | 6 | All values are both the standard javascript values you expect (no extension or suchlike), and are the RDF types you expect 7 | 8 | ## Example ## 9 | 10 | This library doesn't inspect objects and then generate RDF, rather each value *is* RDF, and javascript: 11 | 12 | true.toNT(); // "true"^^ 13 | (12 * 1.4).toNT(); // "12.3"^^ 14 | 15 | Here's a complicated yet simple example to illustrate, this is just a standard Object in js: 16 | 17 | var me = { 18 | a: 'foaf:Person', // a String, a CURIE and a full IRI 19 | name: 'Nathan', // a String, and an RDF Plain Literal 20 | age: new Date().getFullYear() - 1981, // a Number, and a Typed Literal with the type xsd:integer 21 | homepage: 'http://webr3.org', // a String, and an IRI, 22 | holdsAccount: { // an Object, with a BlankNode reference for the .id 23 | label: "Nathan's twitter account".l('en'), // a String, and a Literal with a .language 24 | accountName: 'webr3', // noticed that you don't need the prefixes yet? 25 | homepage: 'http://twitter.com/webr3' 26 | }, 27 | knows: bob, // works with variables too of course 28 | nick: ['webr3','nath'] // an Array, also a list of values, like in turtle and n3 29 | }.ref(":me"); // still an Object, but also has a .id now, it's subject is set. 30 | 31 | If we now call *me.n3()* we'll get the following output: 32 | 33 | rdf:type foaf:Person; 34 | foaf:name "Nathan"; 35 | foaf:age 29; 36 | foaf:homepage ; 37 | foaf:holdsAccount [ 38 | rdfs:label "Nathan's twitter account"@en; 39 | foaf:accountName "webr3"; 40 | foaf:homepage ]; 41 | foaf:knows ; 42 | foaf:nick "webr3", "nath" . 43 | 44 | It's just that simple, your javascript is your RDF, it's just plain old javascript: 45 | 46 | me.gender = "male"; // .gender will resolve to foaf:gender to http://xmlns.com/foaf/0.1/gender 47 | if(me.age > 18) return true; // it's all native values, just use like normal! 48 | 49 | ### Implementation Notice ### 50 | 51 | This library requires ECMAScript-262 V5, specifically it makes heavy usage of Object.defineProperties. 52 | 53 | You can check the [compatibility chart](http://kangax.github.com/es5-compat-table/) to see if your platform / browser supports it. 54 | The short version is that chrome 5+, ff4, webkit (safari) and ie9 all support this script, and on the server side node.js, rhino and besen are all fine. 55 | 56 | Objects and values are not modified in the usual manner and they are not converted in to different types, rather this library automagically redefines 57 | the property descriptors on objects to allow each value to be both a native javascript value, and an RDF compatible value. 58 | 59 | ## Nodes & Values ## 60 | 61 | All values of type string, number, boolean and date are also RDF Nodes, and are fully aligned (and compatible) with the Interfaces 62 | from the RDFa API. 63 | 64 | ### Standard Methods #### 65 | All of the basic js types (string, number, boolean and date) are augmented with the following methods: 66 | 67 | * **.nodeType()** - returns one of PlainLiteral, TypedLiteral, BlankNode or IRI 68 | 69 | true.nodeType(); // TypedLiteral 70 | (12 * 1.4).nodeType(); // TypedLiteral 71 | new Date().nodeType(); // TypedLiteral 72 | "hello world".nodeType(); // PlainLiteral 73 | "_:b12".nodeType(); // BlankNode 74 | "foaf:name".nodeType(); // IRI 75 | "http://webr3.org/".nodeType(); // IRI 76 | 77 | * **.equals(other)** - returns boolean 78 | 79 | RDF type safe equality test. 80 | 81 | "hello" == "hello".l('en') // true 82 | "hello".equals( "hello".l('en') ) // false 83 | 84 | * **.toNT()** - returns string 85 | 86 | Does what it says on the tin, returns the N-Triples formatted value. 87 | 88 | true.toNT(); // "true"^^ 89 | (12 * 1.4).toNT(); // "12.3"^^ 90 | new Date().toNT(); // "2010-11-20T21:06:42Z"^^ 91 | "hello world".toNT(); // "hello world" 92 | "hello world".l('en').toNT(); // "hello world"@en 93 | "_:b12".toNT(); // _:b12 94 | "foaf:name".toNT(); // 95 | "http://webr3.org/".toNT(); // 96 | 97 | * **.toCanonical()** 98 | 99 | Alias of .toNT(), RDFa API compatibility method. 100 | 101 | * **.n3()** returns string 102 | 103 | Returns the value formatted for N3/Turtle. 104 | 105 | true.n3(); // true 106 | (12 * 1.4).n3(); // 12.3 107 | new Date().n3(); // "2010-11-20T21:06:42Z"^^ 108 | "hello world".n3(); // "hello world" 109 | "hello world".l('en').n3(); // "hello world"@en 110 | "_:b12".n3(); // _:b12 111 | "foaf:name".n3(); // foaf:name 112 | "http://webr3.org/".n3(); // 113 | 114 | 115 | ### String Methods #### 116 | A string can represent any of the RDF Node types, PlainLiteral (+language), TypedLiteral, BlankNode or IRI. 117 | In js3 string exposes the following methods (in addition to the standard methods outlined above): 118 | 119 | * **.l()** - returns this 120 | 121 | Set the language of a PlainLiteral - exposes the **.language** attribute after calling. (.language is non-enumerable, read-only) 122 | 123 | var s = "Hello World".l('en'); 124 | s.language // 'en' 125 | s.nodeType(); // PlainLiteral 126 | s.toNT(); // "Hello World"@en 127 | 128 | * **.tl()** - returns this 129 | 130 | Set the type of a TypedLiteral - exposes the **.type** attribute after calling. (.type is non-enumerable, read-only) 131 | 132 | var s = "0FB7".tl('xsd:hexBinary'); 133 | s.type // http://www.w3.org/2001/XMLSchema#hexBinary 134 | s.nodeType(); // TypedLiteral 135 | s.toNT(); // "0FB7"^^ 136 | 137 | Note: this method also caters for the situations when you want a PlainLiteral to be an xsd:string, or an IRI to be a PlainLiteral 138 | 139 | var u = "http://webr3.org/"; // 140 | u.tl("rdf:PlainLiteral); // "http://webr3.org/" 141 | 142 | var h = "hello"; // "hello" 143 | "hello".tl('xsd:string'); // "hello"^^ 144 | 145 | * **.resolve()** - returns string IRI 146 | 147 | Resolve a CURIE to a full IRI - note this is done automatically by .n3 and .toNT methods. 148 | 149 | "foaf:name".resolve() // returns string "http://xmlns.com/foaf/0.1/name" with nodeType IRI 150 | 151 | Remember, all javascript values and types remain unchanged, so it's entirely backwards compatible with all existing data, and will not modify any js values, 152 | "Hello World".l('en') is still a String, properties like .language and .type are non-enumerable, so they won't show up in for loops or when you JSON.stringify 153 | the values. You cannot implement this library in non v5 ecmascript by simply adding a .language property to the String object, that simply won't work. 154 | 155 | ### Numbers #### 156 | 157 | js3 is fully aware of number types, it knows when a number is an integer, a double or a decimal. 158 | 159 | 12 .toNT() // "12"^^ 160 | 12.1 .toNT() // "12.1"^^ 161 | 1267.43233E32 .toNT() // "1.26743233e+35"^^ 162 | 163 | **Gotcha:** do note that you need to add a space between the number and the .method, or wrap the number in braces *(12.1).toNT()*, 164 | since js expects any integer followed immediately by a period to be a decimal, like 12.145 - this only applies to hard coded in the source-code numbers, and not 165 | those in variables or returned from functions, so generally isn't noticable, in the same way that you don't normally write 12.toString()! 166 | 167 | 168 | ## Arrays and Lists ## 169 | 170 | JS3 uses arrays for both lists of objects in property-object chains { name: ['nathan','nath'] } and as rdf Lists. 171 | 172 | You can determine whether an array is a list or not by inspecting the boolean property **.list** on any array. To specify that an array is a list you simply call .toList() on it. 173 | 174 | ### Array Methods and Properties ### 175 | 176 | * **.list** - boolean 177 | 178 | Boolean flag indicating whether an array is an RDF list. 179 | 180 | * **.toList()** - returns this 181 | 182 | Specifies that an array is to be used as an RDF list, sets the .list property to true. 183 | 184 | * **.n3()** returns string 185 | 186 | Returns the value formatted for N3/Turtle. 187 | 188 | [1,2,3,4].n3() // 1, 2, 3, 4 189 | [1,2,3,4].toList().n3() // ( 1 2 3 4 ) 190 | 191 | Note that there are no .toNT or .nodeType methods, or related, arrays and lists are not RDF Nodes. 192 | 193 | ## Objects and Descriptions ## 194 | 195 | In js3 each Object is by default just an Object with a single additional method exposed **.ref()**. When you call this method the object is RDF enabled, 196 | whereby it is set to denote the description of something - identified by a blanknode or an IRI - the keys (properties) are mapped to RDF Properties, 197 | a **.id** attribute is exposed on the object, and four methods are also exposed: **.n3()**, **.toNT()**, **.using()** and **.graphify()**. 198 | 199 | ### The Basics ### 200 | It's all really simple tbh, the properties on each object can either be: 201 | 202 | - obj['http://xmlns.com/foaf/0.1/name'] - a full IRI 203 | - obj['foaf:name'] - a normal CURIE 204 | - obj.foaf$name - a more javascript friendly CURIE where the : is swapped for a $ 205 | - obj.name - a single property which maps up to a CURIE, which maps to an IRI 206 | 207 | Each value can be a single value (of any type covered), or an array of values (which might be a list), or an object (which can be named with an IRI or a blanknode identifier). 208 | 209 | And thus, just like normal javascript or JSON you can make an object structure as simple or as complicated as you like. 210 | 211 | Objects can also have methods on them, and these are stripped from any output, so any existing object whether dumb or a full class with properties can be used. 212 | 213 | They're just javascript objects with a .id set on them (non-enumerable and read-only), and where the properties are mapped to RDF properties. So, each object can be seen to describe one thing, one subject, the .id is the subject. 214 | To set the .id all you do is call **.ref()** on the object, if you pass in a CURIE or an IRI as a param then that is set as the subject/.id, if you call .ref() with no argument then it is given a blanknode identifier as the .id. 215 | 216 | The methods exposed after .ref'ing are also simple, .n3 dumps an n3 string of the object, .toNT dumps it out as ntriples, and .graphify gives you back an RDFGraph from the RDFa API, making it completely compatible and exposing all the functionality of my [rdfa-api](http://github.org/webr3/rdfa-api) library (and other compatible implementations of the RDFa API). 217 | 218 | **.using()** is a bit more subtle, you can throw in the names of ontologies which properties your using come from, in order to provide an unambiguous mapping, for instance: 219 | 220 | var article = { 221 | description: "A dc11:, not dc:, description", 222 | label: "An rdfs:label" 223 | }.ref(':me').using('dc11','rdfs'); 224 | 225 | If you don't pass in any names, then they are mapped up on a first-hit-first-used basis. This is covered more in the section about *propertymap* and *curiemap*. 226 | 227 | ### Syntax, Variables and References ### 228 | 229 | There is no special syntax, and variables + references are part of javascript, so they "just work". which means you can do things like this: 230 | 231 | article.maker = me; 232 | me.made = article; 233 | article.maker.knows = bob; // the same as me.knows 234 | article.created = new Date(); 235 | { a: 'foaf:Document', primaryTopicOf: article }.ref(':this').graphify().turtle(); 236 | 237 | Because we referenced article by value then it'll be in the output graph too, we could use article.id instead then it won't be included. 238 | 239 | You can also have X many Objects with the same .id, then when you .graphify them they all get smashed together as one - which is nice. 240 | 241 | As for migrating IRIs or renaming subjects, that's as simple as calling .ref(':newid') on any object, no complex rdf replace routines needed. 242 | 243 | ### Data Structures ### 244 | 245 | When Objects are nested, they are by default considered to be blanknodes, *however!*, you can of course call .ref() on them in place, and thus 246 | describe things in context, and name them there too. 247 | 248 | So in this case the object in holdsAccount will be a blanknode: 249 | 250 | var me = { 251 | name: 'Nathan', 252 | holdsAccount: { 253 | label: "Nathan's twitter account".l('en'), 254 | accountName: 'webr3', 255 | homepage: 'http://twitter.com/webr3' 256 | }, 257 | }.ref(":me"); 258 | 259 | But in this case it'll have it's own IRI: 260 | 261 | var me = { 262 | name: 'Nathan', 263 | holdsAccount: { 264 | label: "Nathan's twitter account".l('en'), 265 | accountName: 'webr3', 266 | homepage: 'http://twitter.com/webr3' 267 | }.ref(':twitter'), // here's where we named it 268 | }.ref(":me"); 269 | 270 | ... of course we can code this however we want to get the same results, for example: 271 | 272 | var me = { name: 'Nathan' }.ref(":me"); 273 | var account = { accountName: 'webr3' }; 274 | account.label = "Nathan's twitter account"; 275 | account.label.l('en'); 276 | me.holdsAccount = account; 277 | me.holdsAccount.foaf$homepage = "twitter:webr3".resolve(); 278 | me.holdsAccount.ref(':twitter'); 279 | 280 | ... or create structures just as complex as we like: 281 | 282 | { deep: [ 283 | "item1", 284 | [1, 2.745, [me,bob,"x:mary"].toList(), new Date(), bob].toList(), 285 | "something".substr(3,4).l('en'), 286 | [bob.id, me.id].toList(), { foo: "bar" } 287 | ]}; 288 | 289 | ... and interact with our data however we want: 290 | 291 | var somedata = { 292 | values: [1,10,25,50].toList(), 293 | created: new Date() 294 | }.ref(':results'); 295 | with(Math) { 296 | somedata.result = somedata.values.map(sqrt).reduce(function(p,c) { return max(p,c) }); 297 | } 298 | 299 | ... and then call .n3(): 300 | 301 | :results 302 | dc:created "2010-11-20T21:06:42Z"^^; 303 | seq:values ( 1 10 25 50 ); 304 | seq:result 7.0710678118654755 . 305 | 306 | It's all very flexible - as you can see as we just map reduced an RDF List and updated a graph in one line :) 307 | 308 | ### Object Methods and Properties - after .ref()'ing ### 309 | 310 | * **.id** - string (read-only, non-enumerable) 311 | 312 | BlankNode or IRI in a string, the subject / .id of this object. 313 | 314 | * **.n3()** returns string 315 | 316 | Returns the object as N3/Turtle. 317 | 318 | * **.toNT()** returns string 319 | 320 | Returns the object as NTriples. 321 | 322 | * **.graphify()** - returns RDFGraph 323 | 324 | Returns the structure as an RDFGraph of RDFTriples as per the RDFa API core interfaces - compat++. 325 | 326 | * **.using(arg1, arg2 ... argN)** - returns this 327 | 328 | Pass in string prefixes for ontologies to consider when mapping simple properties. 329 | 330 | Do see the [wiki page on .using() js3.propertymap](https://github.com/webr3/js3/wiki/using-and-propertymap) for more details. 331 | 332 | 333 | ## js3.curiemap and js3.propertymap ## 334 | 335 | **js3.curiemap** is a simple object which maps prefixes to IRIs. 336 | 337 | * to add a CURIE mapping: 338 | 339 | js3.curiemap.foaf = "http://xmlns.com/foaf/0.1/"; 340 | 341 | * to get an IRI for a prefix: 342 | 343 | var iri = js3.curiemap.foaf; 344 | 345 | * **.setDefault(iri)** - to set the default prefix "**:**" : 346 | 347 | js3.curiemap.setDefault('http://webr3.org/nathan#'); 348 | 349 | * **.getPrefix(iri)** - get the registered prefix for an IRI, returns null if no prefix is found: 350 | 351 | js3.curiemap.getPrefix('http://xmlns.com/foaf/0.1/'); // 'foaf' 352 | 353 | * **.shrink(iri)** - turn an IRI in to a CURIE : 354 | 355 | This method returns either a CURIE or the original IRI if no prefix is found. 356 | 357 | js3.curiemap.shrink('http://xmlns.com/foaf/0.1/name'); // 'foaf:name' 358 | 359 | 360 | **js3.propertymap** is a simple object which makes the lib aware of properties in ontologies. 361 | 362 | * to add the properties for an ontology: 363 | 364 | js3.propertymap.foaf = ['name','mbox','page', ...]; 365 | 366 | note: the value must always be an array. 367 | 368 | * to get the properties for an ontology: 369 | 370 | var properties = js3.propertymap.foaf; 371 | 372 | * **.ambiguities()** - returns an array of ambiguous properties: 373 | 374 | var gotchas = js3.propertymap.ambiguities(); 375 | 376 | Do see the [wiki page on .using() js3.propertymap](https://github.com/webr3/js3/wiki/using-and-propertymap) for more details. 377 | 378 | ## js3.graphify() ## 379 | 380 | A simple method which can accept any number of objects, or an array of objects, and will return back an RDFGraph. 381 | 382 | 383 | # Coming Soon # 384 | 385 | * **IRI.deref( callback )** 386 | 387 | A web aware function that will get the description of a subject from the web (negotiating formats) and return back a js3 object to work with: 388 | 389 | "http://webr3.org/nathan#me".deref( function(me) { 390 | print( me.name ); // etc 391 | }); 392 | 393 | * **Obj.save()** 394 | 395 | A web aware function that will PUT an updated description: 396 | 397 | "http://webr3.org/nathan#me".deref( function(me) { 398 | me.friends.push( "somebody:new ); 399 | me.save(); 400 | }); 401 | 402 | * **Full rdfa-api integration** 403 | 404 | From the other side, so you can do graph.describe(subject) and get back an object, and suchlike. 405 | 406 | Probably much more.. 407 | 408 | # Feedback # 409 | 410 | All feedback, bugs etc via issues here, or, well you can get all my details from my FOAF profile using this lib if you like ;) 411 | -------------------------------------------------------------------------------- /bin/merge.sh: -------------------------------------------------------------------------------- 1 | cat ../source/curiemap.js ../source/propertymap.js ../source/core.js > ../js3.js 2 | cat ../js3.js ../source/node.exports.js > ../js3.node.js 3 | java -jar ../../yui.jar ../js3.js > ../js3.min.js 4 | -------------------------------------------------------------------------------- /js3.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CURIE Map 3 | */ 4 | var curiemap = (function(map) { 5 | function oflip(o) { 6 | var out = {}; 7 | Object.keys(o).forEach(function(k) { out[o[k]] = k }); 8 | return out; 9 | }; 10 | return Object.defineProperties(map, { 11 | resolve: { 12 | writable: false, configurable : false, enumerable: false, 13 | value: function(o) { 14 | var index = o.indexOf(":"); 15 | if(index < 0 || o.indexOf("//") >= 0 ) { return o } 16 | var prefix = o.slice(0, index).toLowerCase(); 17 | if(!this[prefix]) return o; 18 | return this[prefix].concat( o.slice(++index) ); 19 | } 20 | }, 21 | setDefault: { 22 | writable: false, configurable : false, enumerable: false, 23 | value: function(o) { this[''] = o; return this; } 24 | }, 25 | getPrefix: { 26 | writable: false, configurable : false, enumerable: false, 27 | value: function(o) { return oflip(this)[o]; } 28 | }, 29 | shrink: { 30 | writable: false, configurable : false, enumerable: false, 31 | value: function(iri) { 32 | for(pref in this) 33 | if(iri.substr(0,this[pref].length) == this[pref]) 34 | return pref + ':' + iri.slice(this[pref].length); 35 | return iri; 36 | } 37 | }, 38 | }); 39 | })({ 40 | owl: "http://www.w3.org/2002/07/owl#", 41 | rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#", 42 | rdfs: "http://www.w3.org/2000/01/rdf-schema#", 43 | rdfa: "http://www.w3.org/ns/rdfa#", 44 | xhv: "http://www.w3.org/1999/xhtml/vocab#", 45 | xml: "http://www.w3.org/XML/1998/namespace", 46 | xsd: "http://www.w3.org/2001/XMLSchema#", 47 | grddl: "http://www.w3.org/2003/g/data-view#", 48 | powder: "http://www.w3.org/2007/05/powder#", 49 | powders: "http://www.w3.org/2007/05/powder-s#", 50 | rif: "http://www.w3.org/2007/rif#", 51 | atom: "http://www.w3.org/2005/Atom/", 52 | xhtml: "http://www.w3.org/1999/xhtml#", 53 | formats: "http://www.w3.org/ns/formats/", 54 | xforms: "http://www.w3.org/2002/xforms/", 55 | xhtmlvocab: "http://www.w3.org/1999/xhtml/vocab/", 56 | xpathfn: "http://www.w3.org/2005/xpath-functions#", 57 | http: "http://www.w3.org/2006/http#", 58 | link: "http://www.w3.org/2006/link#", 59 | time: "http://www.w3.org/2006/time#", 60 | acl: "http://www.w3.org/ns/auth/acl#", 61 | cert: "http://www.w3.org/ns/auth/cert#", 62 | rsa: "http://www.w3.org/ns/auth/rsa#", 63 | crypto: "http://www.w3.org/2000/10/swap/crypto#", 64 | list: "http://www.w3.org/2000/10/swap/list#", 65 | log: "http://www.w3.org/2000/10/swap/log#", 66 | math: "http://www.w3.org/2000/10/swap/math#", 67 | os: "http://www.w3.org/2000/10/swap/os#", 68 | string: "http://www.w3.org/2000/10/swap/string#", 69 | doc: "http://www.w3.org/2000/10/swap/pim/doc#", 70 | contact: "http://www.w3.org/2000/10/swap/pim/contact#", 71 | p3p: "http://www.w3.org/2002/01/p3prdfv1#", 72 | swrl: "http://www.w3.org/2003/11/swrl#", 73 | swrlb: "http://www.w3.org/2003/11/swrlb#", 74 | exif: "http://www.w3.org/2003/12/exif/ns#", 75 | earl: "http://www.w3.org/ns/earl#", 76 | ma: "http://www.w3.org/ns/ma-ont#", 77 | sawsdl: "http://www.w3.org/ns/sawsdl#", 78 | sd: "http://www.w3.org/ns/sparql-service-description#", 79 | skos: "http://www.w3.org/2004/02/skos/core#", 80 | fresnel: "http://www.w3.org/2004/09/fresnel#", 81 | gen: "http://www.w3.org/2006/gen/ont#", 82 | timezone: "http://www.w3.org/2006/timezone#", 83 | skosxl: "http://www.w3.org/2008/05/skos-xl#", 84 | org: "http://www.w3.org/ns/org#", 85 | ical: "http://www.w3.org/2002/12/cal/ical#", 86 | wgs84: "http://www.w3.org/2003/01/geo/wgs84_pos#", 87 | vcard: "http://www.w3.org/2006/vcard/ns#", 88 | turtle: "http://www.w3.org/2008/turtle#", 89 | pointers: "http://www.w3.org/2009/pointers#", 90 | dcat: "http://www.w3.org/ns/dcat#", 91 | imreg: "http://www.w3.org/2004/02/image-regions#", 92 | rdfg: "http://www.w3.org/2004/03/trix/rdfg-1/", 93 | swp: "http://www.w3.org/2004/03/trix/swp-2/", 94 | rei: "http://www.w3.org/2004/06/rei#", 95 | wairole: "http://www.w3.org/2005/01/wai-rdf/GUIRoleTaxonomy#", 96 | states: "http://www.w3.org/2005/07/aaa#", 97 | wn20schema: "http://www.w3.org/2006/03/wn/wn20/schema/", 98 | httph: "http://www.w3.org/2007/ont/httph#", 99 | act: "http://www.w3.org/2007/rif-builtin-action#", 100 | common: "http://www.w3.org/2007/uwa/context/common.owl#", 101 | dcn: "http://www.w3.org/2007/uwa/context/deliverycontext.owl#", 102 | hard: "http://www.w3.org/2007/uwa/context/hardware.owl#", 103 | java: "http://www.w3.org/2007/uwa/context/java.owl#", 104 | loc: "http://www.w3.org/2007/uwa/context/location.owl#", 105 | net: "http://www.w3.org/2007/uwa/context/network.owl#", 106 | push: "http://www.w3.org/2007/uwa/context/push.owl#", 107 | soft: "http://www.w3.org/2007/uwa/context/software.owl#", 108 | web: "http://www.w3.org/2007/uwa/context/web.owl#", 109 | content: "http://www.w3.org/2008/content#", 110 | vs: "http://www.w3.org/2003/06/sw-vocab-status/ns#", 111 | air: "http://dig.csail.mit.edu/TAMI/2007/amord/air#", 112 | ex: "http://example.org/", 113 | 114 | dc: "http://purl.org/dc/terms/", 115 | dc11: "http://purl.org/dc/elements/1.1/", 116 | dctype: "http://purl.org/dc/dcmitype/", 117 | foaf: "http://xmlns.com/foaf/0.1/", 118 | cc: "http://creativecommons.org/ns#", 119 | opensearch: "http://a9.com/-/spec/opensearch/1.1/", 120 | 'void': "http://rdfs.org/ns/void#", 121 | sioc: "http://rdfs.org/sioc/ns#", 122 | sioca: "http://rdfs.org/sioc/actions#", 123 | sioct: "http://rdfs.org/sioc/types#", 124 | lgd: "http://linkedgeodata.org/vocabulary#", 125 | moat: "http://moat-project.org/ns#", 126 | days: "http://ontologi.es/days#", 127 | giving: "http://ontologi.es/giving#", 128 | lang: "http://ontologi.es/lang/core#", 129 | like: "http://ontologi.es/like#", 130 | status: "http://ontologi.es/status#", 131 | og: "http://opengraphprotocol.org/schema/", 132 | protege: "http://protege.stanford.edu/system#", 133 | dady: "http://purl.org/NET/dady#", 134 | uri: "http://purl.org/NET/uri#", 135 | audio: "http://purl.org/media/audio#", 136 | video: "http://purl.org/media/video#", 137 | gridworks: "http://purl.org/net/opmv/types/gridworks#", 138 | hcterms: "http://purl.org/uF/hCard/terms/", 139 | bio: "http://purl.org/vocab/bio/0.1/", 140 | cs: "http://purl.org/vocab/changeset/schema#", 141 | geographis: "http://telegraphis.net/ontology/geography/geography#", 142 | doap: "http://usefulinc.com/ns/doap#", 143 | daml: "http://www.daml.org/2001/03/daml+oil#", 144 | geonames: "http://www.geonames.org/ontology#", 145 | sesame: "http://www.openrdf.org/schema/sesame#", 146 | cv: "http://rdfs.org/resume-rdf/", 147 | wot: "http://xmlns.com/wot/0.1/", 148 | media: "http://purl.org/microformat/hmedia/", 149 | ctag: "http://commontag.org/ns#" 150 | }); 151 | /** 152 | * Property Map 153 | */ 154 | var propertymap = (function(map) { 155 | return Object.defineProperties(map, { 156 | resolve: { 157 | writable: false, configurable : false, enumerable: false, 158 | value: function(t,l) { 159 | t = t.toString(); 160 | l = Array.isArray(l) && l.length > 0 ? l.concat(Object.keys(this)) : Object.keys(this); 161 | for(i in l) if(this[l[i]].indexOf(t) >= 0) return l[i] + ':' + t; 162 | return t; 163 | } 164 | }, 165 | ambiguities: { 166 | writable: false, configurable : false, enumerable: false, 167 | value: function() { 168 | var _ = this, map = {}, out = []; 169 | Object.keys(this).forEach(function(ont) { 170 | _[ont].forEach(function(prop) { if(!map[prop]) map[prop] = [ont + ':' + prop]; else map[prop].push(ont + ':' + prop) }) 171 | }); 172 | Object.keys(map).forEach(function(prop) { 173 | if(map[prop].length > 1) out = out.concat(map[prop]); 174 | }); 175 | return out; 176 | } 177 | } 178 | }); 179 | })({ 180 | owl: ['allValuesFrom','annotatedProperty','annotatedSource','annotatedTarget','assertionProperty','backwardCompatibleWith', 181 | 'bottomDataProperty','bottomObjectProperty','cardinality','complementOf','datatypeComplementOf','deprecated','differentFrom', 182 | 'disjointUnionOf','disjointWith','distinctMembers','equivalentClass','equivalentProperty','hasKey','hasSelf','hasValue', 183 | 'imports','incompatibleWith','intersectionOf','inverseOf','maxCardinality','maxQualifiedCardinality','members','minCardinality', 184 | 'minQualifiedCardinality','onClass','onDataRange','onDatatype','oneOf','onProperties','onProperty','priorVersion','propertyChainAxiom', 185 | 'propertyDisjointWith','qualifiedCardinality','sameAs','someValuesFrom','sourceIndividual','targetIndividual','targetValue', 186 | 'topDataProperty','topObjectProperty','unionOf','versionInfo','versionIRI','withRestrictions'], 187 | rdf: ['type','subject','predicate','object','value','first','rest'], 188 | rdfs: ['subClassOf','subPropertyOf','comment','label','domain','range','seeAlso','isDefinedBy','member'], 189 | grddl: ['namespaceTransformation','transformation','transformationProperty','result','profileTransformation'], 190 | wdrs: ['text','issuedby','matchesregex','notmatchesregex','hasIRI','tag','notknownto','describedby','authenticate', 191 | 'validfrom','validuntil','logo','sha1sum','certified','certifiedby','supportedby','data_error','proc_error','error_code'], 192 | 193 | dc: ['title','creator','subject','description','publisher','contributor','date','type','format','identifier','source', 194 | 'language','relation','coverage','rights','audience','alternative','tableOfContents','abstract','created','valid', 195 | 'available','issued','modified','extent','medium','isVersionOf','hasVersion','isReplacedBy','replaces','isRequiredBy', 196 | 'requires','isPartOf','hasPart','isReferencedBy','references','isFormatOf','hasFormat','conformsTo','spatial','temporal', 197 | 'mediator','dateAccepted','dateCopyrighted','dateSubmitted','educationLevel','accessRights','bibliographicCitation', 198 | 'license','rightsHolder','provenance','instructionalMethod','accrualMethod','accrualPeriodicity','accrualPolicy'], 199 | dc11: ['title','creator','subject','description','publisher','contributor','date','type','format','identifier','source', 200 | 'language','relation','coverage','rights'], 201 | foaf: ['mbox','mbox_sha1sum','gender','geekcode','dnaChecksum','sha1','based_near','title','nick','jabberID','aimChatID', 202 | 'skypeID','icqChatID','yahooChatID','msnChatID','name','firstName','lastName','givenName','givenname','surname', 203 | 'family_name','familyName','phone','homepage','weblog','openid','tipjar','plan','made','maker','img','depiction', 204 | 'depicts','thumbnail','myersBriggs','workplaceHomepage','workInfoHomepage','schoolHomepage','knows','interest', 205 | 'topic_interest','publications','currentProject','pastProject','fundedBy','logo','topic','primaryTopic','focus', 206 | 'isPrimaryTopicOf','page','theme','account','holdsAccount','accountServiceHomepage','accountName','member', 207 | 'membershipClass','birthday','age','status'], 208 | cc: ['requires','prohibits','jurisdiction','useGuidelines','deprecatedOn','attributionName','license','attributionURL', 209 | 'morePermissions','permits','legalcode'], 210 | 'void': ['statItem','feature','subset','target','sparqlEndpoint','linkPredicate','exampleResource','vocabulary', 211 | 'subjectsTarget','objectsTarget','dataDump','uriLookupEndpoint','uriRegexPattern'], 212 | sioc: ['about','account_of','addressed_to','administrator_of','attachment','avatar','container_of','content','creator_of', 213 | 'earlier_version','email','email_sha1','embeds_knowledge','feed','follows','function_of','has_administrator', 214 | 'has_container','has_creator','has_discussion','has_function','has_host','has_member','has_moderator','has_modifier', 215 | 'has_owner','has_parent','has_reply','has_scope','has_space','has_subscriber','has_usergroup','host_of','id', 216 | 'ip_address','last_activity_date','last_item_date','last_reply_date','later_version','latest_version','link', 217 | 'links_to','member_of','moderator_of','modifier_of','name','next_by_date','next_version','note','num_authors', 218 | 'num_items','num_replies','num_threads','num_views','owner_of','parent_of','previous_by_date','previous_version', 219 | 'related_to','reply_of','scope_of','sibling','space_of','subscriber_of','topic','usergroup_of'], 220 | sioca: ['byproduct','creates','deletes','modifies','object','product','source','uses'], // may remove.. 221 | link: ['listDocumentProperty','uri'], 222 | acl: ['accessControl','accessTo','accessToClass','agent','agentClass','defaultForNew','mode'], 223 | skos: ['inScheme','hasTopConcept','topConceptOf','prefLabel','altLabel','hiddenLabel','notation','note','changeNote', 224 | 'definition','editorialNote','example','historyNote','scopeNote','semanticRelation','broader','narrower','related', 225 | 'broaderTransitive','narrowerTransitive','member','memberList','mappingRelation','broadMatch','narrowMatch', 226 | 'relatedMatch','exactMatch','closeMatch'], 227 | wgs84: ['lat','location','long','alt','lat_long'], 228 | org: ['subOrganizationOf','transitiveSubOrganizationOf','hasSubOrganization ','purpose','hasUnit','unitOf','classification', 229 | 'identifier','linkedTo','memberOf','hasMember','reportsTo','member','organization','role','hasMembership','memberDuring', 230 | 'roleProperty','headOf','remuneration','siteAddress','hasSite','siteOf','hasPrimarySite','hasRegisteredSite','basedAt ', 231 | 'location','originalOrganization','changedBy','resultedFrom','resultingOrganization'], 232 | }); 233 | /** 234 | * JS3 Core 235 | */ 236 | js3 = (function( curiemap, propertymap, api ) { 237 | var bn = 0; 238 | function _(v) { return { writable: false, configurable : false, enumerable: false, value: v }} 239 | function pad(n){ return n<10 ? '0'+n : n } 240 | function prop(p,l) { 241 | if(p == 'a') return 'rdf:type'; 242 | p = p.replace('$',':'); 243 | if(p.indexOf(':') == -1) p = propertymap.resolve(p,l); 244 | return p; 245 | }; 246 | if(!api) { 247 | api = {}; 248 | // Temporary import of RDFa API RDFTriple and Graph for graphification. 249 | api.RDFTriple = function(s, p, o) { this.subject = s; this.property = p; this.object = o; }; 250 | api.RDFTriple.prototype = { 251 | object: null, property: null, subject: null, 252 | toString: function() { return this.subject.toNT() + " " + this.property.toNT() + " " + this.object.toNT() + " ." }, 253 | equals: function(t) { return this.subject.equals(t.subject) && this.property.equals(t.property) && this.object.equals(t.object) } 254 | }; 255 | api.Graph = function(a) { 256 | this.length = 0; 257 | this.graph = []; 258 | this.index = {}; 259 | if(Array.isArray(a)) this.importArray(a); 260 | }; 261 | api.Graph.prototype = { 262 | length: null, graph: null, 263 | importArray: function(a) { while( a.length > 0) { this.add(a.pop()) } }, 264 | get: function(index) { return this.graph[index] }, 265 | add: function(triple) { 266 | if(!this.index[triple.subject.value]) this.index[triple.subject.value] = {}; 267 | if(!this.index[triple.subject.value][triple.property.value]) this.index[triple.subject.value][triple.property.value] = []; 268 | if(this.index[triple.subject.value][triple.property.value].some(function(o){return o.equals(triple.object)})) return; 269 | this.length++; 270 | this.index[triple.subject.value][triple.property.value].push(triple.object); 271 | this.graph.push(triple); 272 | }, 273 | merge: function(s) { 274 | var _g1 = 0, _g = s.length; 275 | while(_g1 < _g) { 276 | var i = _g1++; 277 | this.add(s.get(i)) 278 | } 279 | }, 280 | every: function(filter) { return this.graph.every(filter) }, 281 | some: function(filter) { return this.graph.some(filter) }, 282 | forEach: function(callbck) { this.graph.forEach(callbck) }, 283 | filter: function(filter) { return new api.Graph(this.graph.filter(filter)); }, 284 | apply: function(filter) { this.graph = this.graph.filter(filter); this.length = this.graph.length; }, 285 | toArray: function() { return this.graph.slice() } 286 | }; 287 | } 288 | // N-Triples encoder 289 | function encodeString(s) { 290 | var out = ""; 291 | var skip = false; 292 | var _g1 = 0, _g = s.length; 293 | while(_g1 < _g) { 294 | var i = _g1++; 295 | if(!skip) { 296 | var code = s.charCodeAt(i); 297 | if(55296 <= code && code <= 56319) { 298 | var low = s.charCodeAt(i + 1); 299 | code = (code - 55296) * 1024 + (low - 56320) + 65536; 300 | skip = true 301 | } 302 | if(code > 1114111) { throw new Error("Char out of range"); } 303 | var hex = "00000000".concat((new Number(code)).toString(16).toUpperCase()); 304 | if(code >= 65536) { 305 | out += "\\U" + hex.slice(-8) 306 | } else { 307 | if(code >= 127 || code <= 31) { 308 | switch(code) { 309 | case 9: out += "\\t"; break; 310 | case 10: out += "\\n"; break; 311 | case 13: out += "\\r"; break; 312 | default: out += "\\u" + hex.slice(-4); break 313 | } 314 | } else { 315 | switch(code) { 316 | case 34: out += '\\"'; break; 317 | case 92: out += "\\\\"; break; 318 | default: out += s.charAt(i); break 319 | } 320 | } 321 | } 322 | } else { 323 | skip = !skip 324 | } 325 | } 326 | return out 327 | }; 328 | // Let the magic begin 329 | Object.defineProperties( Object.prototype, { 330 | equals: _(function(other) { 331 | if( this.nodeType() != other.nodeType() ) return false; 332 | switch(this.nodeType()) { 333 | case "IRI": case "BlankNode": 334 | return this == other; 335 | case "PlainLiteral": 336 | if((this.language && !other.language) || (!this.language && other.language)) return false; 337 | if(this.language && other.language) return this.language == other.language && this == other; 338 | return this == other; 339 | case "TypedLiteral": 340 | return this.type.equals(other.type) && this == other; 341 | } 342 | return this.n3() == other.n3() 343 | }), 344 | ref: _( function(id) { 345 | Object.defineProperties(this, { 346 | id: _( id ? id.resolve() : '_:b' +(++bn) ), 347 | n3: _( function(a) { 348 | var outs = [], o = this, map = o.aliasmap || a; 349 | Object.keys(this).forEach(function(p) { 350 | if(typeof o[p] == 'function') return; 351 | if(o[p].id && o[p].id.nodeType() == 'IRI') return outs.push( prop(p,map) + ' ' + o[p].id.n3() ); 352 | if(!o[p].nodeType && !o[p].id) o[p].ref(); 353 | outs.push( prop(p, map) + ' ' + o[p].n3(map) ); 354 | }); 355 | outs = outs.join(";\n "); 356 | return id ? this.id.n3() + ' ' + outs + ' .' : '[ ' + outs + ' ]'; 357 | }), 358 | toNT: _( function(a) { 359 | return this.graphify(a).toArray().join("\n"); 360 | }), 361 | graphify: _( function(a) { 362 | var graph = new api.Graph, o = this, map = o.aliasmap || a; 363 | function graphify(s1,p1,o1) { 364 | if(typeof o1 == 'function') return; 365 | if(!o1.nodeType && !o1.id) o1.ref(); 366 | if(o1.id) { 367 | graph.add( new api.RDFTriple(s1, prop(p1,map), o1.id ) ); 368 | graph.merge( o1.graphify() ); 369 | } else if(!Array.isArray(o1)) { 370 | graph.add( new api.RDFTriple(s1, prop(p1,map), o1 ) ); 371 | } else if(Array.isArray(o1)) { 372 | if(!o1.list) { 373 | o1.forEach( function(i) { graphify(s1,p1,i) }); 374 | } else { 375 | if(o1.length == 0) { 376 | graph.add( new api.RDFTriple(s1, prop(p1,map), "rdf:nil".resolve() ) ); 377 | } else { 378 | var b = {}.ref(); 379 | graph.add( new api.RDFTriple(s1, prop(p1,map), b.id ) ); 380 | o1.forEach( function(i,x) { 381 | graphify(b.id, 'rdf:first'.resolve(), i ); 382 | var n = {}.ref(); 383 | graph.add( new api.RDFTriple(b.id, 'rdf:rest'.resolve(), (x == o1.length-1) ? 'rdf:nil'.resolve() : n.id ) ); 384 | b = n; 385 | }); 386 | } 387 | } 388 | } 389 | } 390 | Object.keys(this).forEach(function(p) { graphify(o.id, p, o[p]) }); 391 | return graph; 392 | }), 393 | using: _( function() { 394 | Object.defineProperty(this,'aliasmap',_(Array.prototype.slice.call(arguments))); 395 | return this; 396 | }) 397 | }); 398 | return this; 399 | }), 400 | }); 401 | Object.defineProperties( String.prototype, { 402 | tl: _( function(t) { 403 | Object.defineProperty(this,'type', _(t.resolve()) ); 404 | Object.defineProperty(this,'language', _(null) ); 405 | return this; 406 | }), 407 | l: _( function(l) { 408 | Object.defineProperty(this,'type', _(null) ); 409 | Object.defineProperty(this,'language', _(l) ); 410 | return this; 411 | }), 412 | resolve: _( function() { 413 | return curiemap.resolve(this); 414 | }), 415 | value: _( function() { return this; }), 416 | nodeType: _( function() { 417 | if(this.type) return 'TypedLiteral'; 418 | if(this.language || this.indexOf(' ') >= 0 || this.indexOf(':') == -1 ) return 'PlainLiteral'; 419 | if(this.substr(0,2) == '_:') return 'BlankNode'; 420 | return 'IRI'; 421 | }), 422 | n3: _( function() { 423 | switch(this.nodeType()) { 424 | case 'PlainLiteral': return ('"' + encodeString(this) + '"' + ( this.language ? '@' + this.language : '')).toString(); 425 | case 'IRI': 426 | return (this.resolve() == this) ? "<" + encodeString(this.resolve()) + ">" : this.toString(); 427 | case 'BlankNode': return this.toString(); 428 | case 'TypedLiteral': 429 | if(this.type.resolve() == "rdf:PlainLiteral".resolve()) return '"' + encodeString(this) + '"'; 430 | return '"' + encodeString(this) + '"^^' + this.type.n3(); 431 | } 432 | }), 433 | toNT: _( function() { 434 | switch(this.nodeType()) { 435 | case 'PlainLiteral': return ('"' + encodeString(this) + '"' + ( this.language ? '@' + this.language : '')).toString(); 436 | case 'IRI': return "<" + encodeString(this.resolve()) + ">"; 437 | case 'BlankNode': return this.toString(); 438 | case 'TypedLiteral': 439 | if(this.type.resolve() == "rdf:PlainLiteral".resolve()) return '"' + encodeString(this) + '"'; 440 | return '"' + encodeString(this) + '"^^' + this.type.n3(); 441 | } 442 | }), 443 | toCanonical: _( function() { return this.n3() } ) 444 | }); 445 | Object.defineProperties( Array.prototype, { 446 | list: _(false), 447 | toList: _(function() { 448 | this.list = true; 449 | return this; 450 | }), 451 | nodeType: _("Collection"), 452 | n3: _( function(a) { 453 | var outs = []; 454 | this.forEach( function(i) { 455 | if(typeof i == 'function') return; 456 | if(i.id && i.id.nodeType() == 'IRI') return outs.push( i.id.n3() ); 457 | if(!i.nodeType) i.ref(); 458 | outs.push(i.n3(a)) 459 | }); 460 | return this.list ? "( " + outs.join(" ") + " )" : outs.join(", "); 461 | }) 462 | }); 463 | Object.defineProperties( Boolean.prototype, { 464 | type: _( "xsd:boolean".resolve() ), 465 | value: _( function() { return this; }), 466 | nodeType: _( function() { return "TypedLiteral"} ), 467 | n3: _( function() { return this.valueOf() } ), 468 | toNT: _( function() { return '"' + this.valueOf() + '"' + "^^<" + this.type + '>' } ), 469 | toCanonical: _( function() { return this.toNT() } ) 470 | }); 471 | Object.defineProperties( Date.prototype, { 472 | type: _( "xsd:dateTime".resolve() ), 473 | value: _( function() { return this; }), 474 | nodeType: _( function() { return "TypedLiteral"} ), 475 | n3: _( function() { 476 | return '"' + this.getUTCFullYear()+'-' + pad(this.getUTCMonth()+1)+'-' + pad(this.getUTCDate())+'T' 477 | + pad(this.getUTCHours())+':' + pad(this.getUTCMinutes())+':' + pad(this.getUTCSeconds())+'Z"^^<' + this.type + '>'; 478 | }), 479 | toNT: _( function() { return this.n3() } ), 480 | toCanonical: _( function() { return this.n3() } ) 481 | }); 482 | var INTEGER = new RegExp("^(-|\\+)?[0-9]+$", ""); 483 | var DOUBLE = new RegExp("^(-|\\+)?(([0-9]+\\.[0-9]*[eE]{1}(-|\\+)?[0-9]+)|(\\.[0-9]+[eE]{1}(-|\\+)?[0-9]+)|([0-9]+[eE]{1}(-|\\+)?[0-9]+))$", ""); 484 | var DECIMAL = new RegExp("^(-|\\+)?[0-9]*\\.[0-9]+?$", ""); 485 | Object.defineProperties( Number.prototype, { 486 | type: { 487 | configurable : false, enumerable: false, 488 | get: function() { 489 | if(this == Number.POSITIVE_INFINITY) return 'xsd:double'.resolve(); 490 | if(this == Number.NEGATIVE_INFINITY) return 'xsd:double'.resolve(); 491 | if(this == Number.NaN) return 'xsd:double'.resolve(); 492 | var n = this.toString(); 493 | if(INTEGER.test(n)) return 'xsd:integer'.resolve(); 494 | if(DECIMAL.test(n)) return 'xsd:decimal'.resolve(); 495 | if(DOUBLE.test(n)) return 'xsd:double'.resolve(); 496 | } 497 | }, 498 | value: _( function() { return this; }), 499 | nodeType: _( function() { return "TypedLiteral" } ), 500 | n3: _( function() { 501 | if(this == Number.POSITIVE_INFINITY) return '"INF"^^<' + 'xsd:double'.resolve() + '>'; 502 | if(this == Number.NEGATIVE_INFINITY) return '"-INF"^^<' + 'xsd:double'.resolve() + '>'; 503 | if(this == Number.NaN) return '"NaN"^^<' + 'xsd:double'.resolve() + '>'; 504 | return this.toString(); 505 | }), 506 | toNT: _( function() { 507 | if(this == Number.POSITIVE_INFINITY) return '"INF"^^<' + 'xsd:double'.resolve() + '>'; 508 | if(this == Number.NEGATIVE_INFINITY) return '"-INF"^^<' + 'xsd:double'.resolve() + '>'; 509 | if(this == Number.NaN) return '"NaN"^^<' + 'xsd:double'.resolve() + '>'; 510 | return '"' + this.toString() + '"' + "^^<" + this.type + '>'; 511 | }), 512 | toCanonical: _( function() { return this.nt() } ) 513 | }); 514 | return { 515 | curiemap: curiemap, propertymap: propertymap, 516 | graphify: function() { 517 | var a = Array.prototype.slice.call(arguments), gout = new api.Graph; 518 | function graphify(o) { 519 | if(typeof o == 'object' && !o.nodeType) { 520 | if(!o.id) o.ref(); 521 | gout.merge( o.graphify() ); 522 | } 523 | }; 524 | a.forEach( function(o) { 525 | if(Array.isArray(o)) o.forEach(function(x){graphify(x)}); 526 | else graphify(o); 527 | }); 528 | return gout; 529 | } 530 | }; 531 | })( curiemap, propertymap ); -------------------------------------------------------------------------------- /js3.min.js: -------------------------------------------------------------------------------- 1 | var curiemap=(function(b){function a(d){var c={};Object.keys(d).forEach(function(e){c[d[e]]=e});return c}return Object.defineProperties(b,{resolve:{writable:false,configurable:false,enumerable:false,value:function(e){var c=e.indexOf(":");if(c<0||e.indexOf("//")>=0){return e}var d=e.slice(0,c).toLowerCase();if(!this[d]){return e}return this[d].concat(e.slice(++c))}},setDefault:{writable:false,configurable:false,enumerable:false,value:function(c){this[""]=c;return this}},getPrefix:{writable:false,configurable:false,enumerable:false,value:function(c){return a(this)[c]}},shrink:{writable:false,configurable:false,enumerable:false,value:function(c){for(pref in this){if(c.substr(0,this[pref].length)==this[pref]){return pref+":"+c.slice(this[pref].length)}}return c}},})})({owl:"http://www.w3.org/2002/07/owl#",rdf:"http://www.w3.org/1999/02/22-rdf-syntax-ns#",rdfs:"http://www.w3.org/2000/01/rdf-schema#",rdfa:"http://www.w3.org/ns/rdfa#",xhv:"http://www.w3.org/1999/xhtml/vocab#",xml:"http://www.w3.org/XML/1998/namespace",xsd:"http://www.w3.org/2001/XMLSchema#",grddl:"http://www.w3.org/2003/g/data-view#",powder:"http://www.w3.org/2007/05/powder#",powders:"http://www.w3.org/2007/05/powder-s#",rif:"http://www.w3.org/2007/rif#",atom:"http://www.w3.org/2005/Atom/",xhtml:"http://www.w3.org/1999/xhtml#",formats:"http://www.w3.org/ns/formats/",xforms:"http://www.w3.org/2002/xforms/",xhtmlvocab:"http://www.w3.org/1999/xhtml/vocab/",xpathfn:"http://www.w3.org/2005/xpath-functions#",http:"http://www.w3.org/2006/http#",link:"http://www.w3.org/2006/link#",time:"http://www.w3.org/2006/time#",acl:"http://www.w3.org/ns/auth/acl#",cert:"http://www.w3.org/ns/auth/cert#",rsa:"http://www.w3.org/ns/auth/rsa#",crypto:"http://www.w3.org/2000/10/swap/crypto#",list:"http://www.w3.org/2000/10/swap/list#",log:"http://www.w3.org/2000/10/swap/log#",math:"http://www.w3.org/2000/10/swap/math#",os:"http://www.w3.org/2000/10/swap/os#",string:"http://www.w3.org/2000/10/swap/string#",doc:"http://www.w3.org/2000/10/swap/pim/doc#",contact:"http://www.w3.org/2000/10/swap/pim/contact#",p3p:"http://www.w3.org/2002/01/p3prdfv1#",swrl:"http://www.w3.org/2003/11/swrl#",swrlb:"http://www.w3.org/2003/11/swrlb#",exif:"http://www.w3.org/2003/12/exif/ns#",earl:"http://www.w3.org/ns/earl#",ma:"http://www.w3.org/ns/ma-ont#",sawsdl:"http://www.w3.org/ns/sawsdl#",sd:"http://www.w3.org/ns/sparql-service-description#",skos:"http://www.w3.org/2004/02/skos/core#",fresnel:"http://www.w3.org/2004/09/fresnel#",gen:"http://www.w3.org/2006/gen/ont#",timezone:"http://www.w3.org/2006/timezone#",skosxl:"http://www.w3.org/2008/05/skos-xl#",org:"http://www.w3.org/ns/org#",ical:"http://www.w3.org/2002/12/cal/ical#",wgs84:"http://www.w3.org/2003/01/geo/wgs84_pos#",vcard:"http://www.w3.org/2006/vcard/ns#",turtle:"http://www.w3.org/2008/turtle#",pointers:"http://www.w3.org/2009/pointers#",dcat:"http://www.w3.org/ns/dcat#",imreg:"http://www.w3.org/2004/02/image-regions#",rdfg:"http://www.w3.org/2004/03/trix/rdfg-1/",swp:"http://www.w3.org/2004/03/trix/swp-2/",rei:"http://www.w3.org/2004/06/rei#",wairole:"http://www.w3.org/2005/01/wai-rdf/GUIRoleTaxonomy#",states:"http://www.w3.org/2005/07/aaa#",wn20schema:"http://www.w3.org/2006/03/wn/wn20/schema/",httph:"http://www.w3.org/2007/ont/httph#",act:"http://www.w3.org/2007/rif-builtin-action#",common:"http://www.w3.org/2007/uwa/context/common.owl#",dcn:"http://www.w3.org/2007/uwa/context/deliverycontext.owl#",hard:"http://www.w3.org/2007/uwa/context/hardware.owl#",java:"http://www.w3.org/2007/uwa/context/java.owl#",loc:"http://www.w3.org/2007/uwa/context/location.owl#",net:"http://www.w3.org/2007/uwa/context/network.owl#",push:"http://www.w3.org/2007/uwa/context/push.owl#",soft:"http://www.w3.org/2007/uwa/context/software.owl#",web:"http://www.w3.org/2007/uwa/context/web.owl#",content:"http://www.w3.org/2008/content#",vs:"http://www.w3.org/2003/06/sw-vocab-status/ns#",air:"http://dig.csail.mit.edu/TAMI/2007/amord/air#",ex:"http://example.org/",dc:"http://purl.org/dc/terms/",dc11:"http://purl.org/dc/elements/1.1/",dctype:"http://purl.org/dc/dcmitype/",foaf:"http://xmlns.com/foaf/0.1/",cc:"http://creativecommons.org/ns#",opensearch:"http://a9.com/-/spec/opensearch/1.1/","void":"http://rdfs.org/ns/void#",sioc:"http://rdfs.org/sioc/ns#",sioca:"http://rdfs.org/sioc/actions#",sioct:"http://rdfs.org/sioc/types#",lgd:"http://linkedgeodata.org/vocabulary#",moat:"http://moat-project.org/ns#",days:"http://ontologi.es/days#",giving:"http://ontologi.es/giving#",lang:"http://ontologi.es/lang/core#",like:"http://ontologi.es/like#",status:"http://ontologi.es/status#",og:"http://opengraphprotocol.org/schema/",protege:"http://protege.stanford.edu/system#",dady:"http://purl.org/NET/dady#",uri:"http://purl.org/NET/uri#",audio:"http://purl.org/media/audio#",video:"http://purl.org/media/video#",gridworks:"http://purl.org/net/opmv/types/gridworks#",hcterms:"http://purl.org/uF/hCard/terms/",bio:"http://purl.org/vocab/bio/0.1/",cs:"http://purl.org/vocab/changeset/schema#",geographis:"http://telegraphis.net/ontology/geography/geography#",doap:"http://usefulinc.com/ns/doap#",daml:"http://www.daml.org/2001/03/daml+oil#",geonames:"http://www.geonames.org/ontology#",sesame:"http://www.openrdf.org/schema/sesame#",cv:"http://rdfs.org/resume-rdf/",wot:"http://xmlns.com/wot/0.1/",media:"http://purl.org/microformat/hmedia/",ctag:"http://commontag.org/ns#"});var propertymap=(function(a){return Object.defineProperties(a,{resolve:{writable:false,configurable:false,enumerable:false,value:function(c,b){c=c.toString();b=Array.isArray(b)&&b.length>0?b.concat(Object.keys(this)):Object.keys(this);for(i in b){if(this[b[i]].indexOf(c)>=0){return b[i]+":"+c}}return c}},ambiguities:{writable:false,configurable:false,enumerable:false,value:function(){var c=this,d={},b=[];Object.keys(this).forEach(function(e){c[e].forEach(function(f){if(!d[f]){d[f]=[e+":"+f]}else{d[f].push(e+":"+f)}})});Object.keys(d).forEach(function(e){if(d[e].length>1){b=b.concat(d[e])}});return b}}})})({owl:["allValuesFrom","annotatedProperty","annotatedSource","annotatedTarget","assertionProperty","backwardCompatibleWith","bottomDataProperty","bottomObjectProperty","cardinality","complementOf","datatypeComplementOf","deprecated","differentFrom","disjointUnionOf","disjointWith","distinctMembers","equivalentClass","equivalentProperty","hasKey","hasSelf","hasValue","imports","incompatibleWith","intersectionOf","inverseOf","maxCardinality","maxQualifiedCardinality","members","minCardinality","minQualifiedCardinality","onClass","onDataRange","onDatatype","oneOf","onProperties","onProperty","priorVersion","propertyChainAxiom","propertyDisjointWith","qualifiedCardinality","sameAs","someValuesFrom","sourceIndividual","targetIndividual","targetValue","topDataProperty","topObjectProperty","unionOf","versionInfo","versionIRI","withRestrictions"],rdf:["type","subject","predicate","object","value","first","rest"],rdfs:["subClassOf","subPropertyOf","comment","label","domain","range","seeAlso","isDefinedBy","member"],grddl:["namespaceTransformation","transformation","transformationProperty","result","profileTransformation"],wdrs:["text","issuedby","matchesregex","notmatchesregex","hasIRI","tag","notknownto","describedby","authenticate","validfrom","validuntil","logo","sha1sum","certified","certifiedby","supportedby","data_error","proc_error","error_code"],dc:["title","creator","subject","description","publisher","contributor","date","type","format","identifier","source","language","relation","coverage","rights","audience","alternative","tableOfContents","abstract","created","valid","available","issued","modified","extent","medium","isVersionOf","hasVersion","isReplacedBy","replaces","isRequiredBy","requires","isPartOf","hasPart","isReferencedBy","references","isFormatOf","hasFormat","conformsTo","spatial","temporal","mediator","dateAccepted","dateCopyrighted","dateSubmitted","educationLevel","accessRights","bibliographicCitation","license","rightsHolder","provenance","instructionalMethod","accrualMethod","accrualPeriodicity","accrualPolicy"],dc11:["title","creator","subject","description","publisher","contributor","date","type","format","identifier","source","language","relation","coverage","rights"],foaf:["mbox","mbox_sha1sum","gender","geekcode","dnaChecksum","sha1","based_near","title","nick","jabberID","aimChatID","skypeID","icqChatID","yahooChatID","msnChatID","name","firstName","lastName","givenName","givenname","surname","family_name","familyName","phone","homepage","weblog","openid","tipjar","plan","made","maker","img","depiction","depicts","thumbnail","myersBriggs","workplaceHomepage","workInfoHomepage","schoolHomepage","knows","interest","topic_interest","publications","currentProject","pastProject","fundedBy","logo","topic","primaryTopic","focus","isPrimaryTopicOf","page","theme","account","holdsAccount","accountServiceHomepage","accountName","member","membershipClass","birthday","age","status"],cc:["requires","prohibits","jurisdiction","useGuidelines","deprecatedOn","attributionName","license","attributionURL","morePermissions","permits","legalcode"],"void":["statItem","feature","subset","target","sparqlEndpoint","linkPredicate","exampleResource","vocabulary","subjectsTarget","objectsTarget","dataDump","uriLookupEndpoint","uriRegexPattern"],sioc:["about","account_of","addressed_to","administrator_of","attachment","avatar","container_of","content","creator_of","earlier_version","email","email_sha1","embeds_knowledge","feed","follows","function_of","has_administrator","has_container","has_creator","has_discussion","has_function","has_host","has_member","has_moderator","has_modifier","has_owner","has_parent","has_reply","has_scope","has_space","has_subscriber","has_usergroup","host_of","id","ip_address","last_activity_date","last_item_date","last_reply_date","later_version","latest_version","link","links_to","member_of","moderator_of","modifier_of","name","next_by_date","next_version","note","num_authors","num_items","num_replies","num_threads","num_views","owner_of","parent_of","previous_by_date","previous_version","related_to","reply_of","scope_of","sibling","space_of","subscriber_of","topic","usergroup_of"],sioca:["byproduct","creates","deletes","modifies","object","product","source","uses"],link:["listDocumentProperty","uri"],acl:["accessControl","accessTo","accessToClass","agent","agentClass","defaultForNew","mode"],skos:["inScheme","hasTopConcept","topConceptOf","prefLabel","altLabel","hiddenLabel","notation","note","changeNote","definition","editorialNote","example","historyNote","scopeNote","semanticRelation","broader","narrower","related","broaderTransitive","narrowerTransitive","member","memberList","mappingRelation","broadMatch","narrowMatch","relatedMatch","exactMatch","closeMatch"],wgs84:["lat","location","long","alt","lat_long"],org:["subOrganizationOf","transitiveSubOrganizationOf","hasSubOrganization ","purpose","hasUnit","unitOf","classification","identifier","linkedTo","memberOf","hasMember","reportsTo","member","organization","role","hasMembership","memberDuring","roleProperty","headOf","remuneration","siteAddress","hasSite","siteOf","hasPrimarySite","hasRegisteredSite","basedAt ","location","originalOrganization","changedBy","resultedFrom","resultingOrganization"],});js3=(function(f,j,h){var d=0;function l(m){return{writable:false,configurable:false,enumerable:false,value:m}}function e(m){return m<10?"0"+m:m}function b(n,m){if(n=="a"){return"rdf:type"}n=n.replace("$",":");if(n.indexOf(":")==-1){n=j.resolve(n,m)}return n}if(!h){h={};h.RDFTriple=function(m,n,q){this.subject=m;this.property=n;this.object=q};h.RDFTriple.prototype={object:null,property:null,subject:null,toString:function(){return this.subject.toNT()+" "+this.property.toNT()+" "+this.object.toNT()+" ."},equals:function(m){return this.subject.equals(m.subject)&&this.property.equals(m.property)&&this.object.equals(m.object)}};h.Graph=function(m){this.length=0;this.graph=[];this.index={};if(Array.isArray(m)){this.importArray(m)}};h.Graph.prototype={length:null,graph:null,importArray:function(m){while(m.length>0){this.add(m.pop())}},get:function(m){return this.graph[m]},add:function(m){if(!this.index[m.subject.value]){this.index[m.subject.value]={}}if(!this.index[m.subject.value][m.property.value]){this.index[m.subject.value][m.property.value]=[]}if(this.index[m.subject.value][m.property.value].some(function(n){return n.equals(m.object)})){return}this.length++;this.index[m.subject.value][m.property.value].push(m.object);this.graph.push(m)},merge:function(n){var o=0,p=n.length;while(o1114111){throw new Error("Char out of range")}var n="00000000".concat((new Number(m)).toString(16).toUpperCase());if(m>=65536){o+="\\U"+n.slice(-8)}else{if(m>=127||m<=31){switch(m){case 9:o+="\\t";break;case 10:o+="\\n";break;case 13:o+="\\r";break;default:o+="\\u"+n.slice(-4);break}}else{switch(m){case 34:o+='\\"';break;case 92:o+="\\\\";break;default:o+=v.charAt(p);break}}}}else{u=!u}}return o}Object.defineProperties(Object.prototype,{equals:l(function(m){if(this.nodeType()!=m.nodeType()){return false}switch(this.nodeType()){case"IRI":case"BlankNode":return this==m;case"PlainLiteral":if((this.language&&!m.language)||(!this.language&&m.language)){return false}if(this.language&&m.language){return this.language==m.language&&this==m}return this==m;case"TypedLiteral":return this.type.equals(m.type)&&this==m}return this.n3()==m.n3()}),ref:l(function(m){Object.defineProperties(this,{id:l(m?m.resolve():"_:b"+(++d)),n3:l(function(n){var q=[],r=this,p=r.aliasmap||n;Object.keys(this).forEach(function(o){if(typeof r[o]=="function"){return}if(r[o].id&&r[o].id.nodeType()=="IRI"){return q.push(b(o,p)+" "+r[o].id.n3())}if(!r[o].nodeType&&!r[o].id){r[o].ref()}q.push(b(o,p)+" "+r[o].n3(p))});q=q.join(";\n ");return m?this.id.n3()+" "+q+" .":"[ "+q+" ]"}),toNT:l(function(n){return this.graphify(n).toArray().join("\n")}),graphify:l(function(n){var q=new h.Graph,s=this,r=s.aliasmap||n;function p(t,v,u){if(typeof u=="function"){return}if(!u.nodeType&&!u.id){u.ref()}if(u.id){q.add(new h.RDFTriple(t,b(v,r),u.id));q.merge(u.graphify())}else{if(!Array.isArray(u)){q.add(new h.RDFTriple(t,b(v,r),u))}else{if(Array.isArray(u)){if(!u.list){u.forEach(function(w){p(t,v,w)})}else{if(u.length==0){q.add(new h.RDFTriple(t,b(v,r),"rdf:nil".resolve()))}else{var o={}.ref();q.add(new h.RDFTriple(t,b(v,r),o.id));u.forEach(function(y,w){p(o.id,"rdf:first".resolve(),y);var z={}.ref();q.add(new h.RDFTriple(o.id,"rdf:rest".resolve(),(w==u.length-1)?"rdf:nil".resolve():z.id));o=z})}}}}}}Object.keys(this).forEach(function(o){p(s.id,o,s[o])});return q}),using:l(function(){Object.defineProperty(this,"aliasmap",l(Array.prototype.slice.call(arguments)));return this})});return this}),});Object.defineProperties(String.prototype,{tl:l(function(m){Object.defineProperty(this,"type",l(m.resolve()));Object.defineProperty(this,"language",l(null));return this}),l:l(function(m){Object.defineProperty(this,"type",l(null));Object.defineProperty(this,"language",l(m));return this}),resolve:l(function(){return f.resolve(this)}),value:l(function(){return this}),nodeType:l(function(){if(this.type){return"TypedLiteral"}if(this.language||this.indexOf(" ")>=0||this.indexOf(":")==-1){return"PlainLiteral"}if(this.substr(0,2)=="_:"){return"BlankNode"}return"IRI"}),n3:l(function(){switch(this.nodeType()){case"PlainLiteral":return('"'+k(this)+'"'+(this.language?"@"+this.language:"")).toString();case"IRI":return(this.resolve()==this)?"<"+k(this.resolve())+">":this.toString();case"BlankNode":return this.toString();case"TypedLiteral":if(this.type.resolve()=="rdf:PlainLiteral".resolve()){return'"'+k(this)+'"'}return'"'+k(this)+'"^^'+this.type.n3()}}),toNT:l(function(){switch(this.nodeType()){case"PlainLiteral":return('"'+k(this)+'"'+(this.language?"@"+this.language:"")).toString();case"IRI":return"<"+k(this.resolve())+">";case"BlankNode":return this.toString();case"TypedLiteral":if(this.type.resolve()=="rdf:PlainLiteral".resolve()){return'"'+k(this)+'"'}return'"'+k(this)+'"^^'+this.type.n3()}}),toCanonical:l(function(){return this.n3()})});Object.defineProperties(Array.prototype,{list:l(false),toList:l(function(){this.list=true;return this}),nodeType:l("Collection"),n3:l(function(m){var n=[];this.forEach(function(o){if(typeof o=="function"){return}if(o.id&&o.id.nodeType()=="IRI"){return n.push(o.id.n3())}if(!o.nodeType){o.ref()}n.push(o.n3(m))});return this.list?"( "+n.join(" ")+" )":n.join(", ")})});Object.defineProperties(Boolean.prototype,{type:l("xsd:boolean".resolve()),value:l(function(){return this}),nodeType:l(function(){return"TypedLiteral"}),n3:l(function(){return this.valueOf()}),toNT:l(function(){return'"'+this.valueOf()+'"^^<'+this.type+">"}),toCanonical:l(function(){return this.toNT()})});Object.defineProperties(Date.prototype,{type:l("xsd:dateTime".resolve()),value:l(function(){return this}),nodeType:l(function(){return"TypedLiteral"}),n3:l(function(){return'"'+this.getUTCFullYear()+"-"+e(this.getUTCMonth()+1)+"-"+e(this.getUTCDate())+"T"+e(this.getUTCHours())+":"+e(this.getUTCMinutes())+":"+e(this.getUTCSeconds())+'Z"^^<'+this.type+">"}),toNT:l(function(){return this.n3()}),toCanonical:l(function(){return this.n3()})});var c=new RegExp("^(-|\\+)?[0-9]+$","");var g=new RegExp("^(-|\\+)?(([0-9]+\\.[0-9]*[eE]{1}(-|\\+)?[0-9]+)|(\\.[0-9]+[eE]{1}(-|\\+)?[0-9]+)|([0-9]+[eE]{1}(-|\\+)?[0-9]+))$","");var a=new RegExp("^(-|\\+)?[0-9]*\\.[0-9]+?$","");Object.defineProperties(Number.prototype,{type:{configurable:false,enumerable:false,get:function(){if(this==Number.POSITIVE_INFINITY){return"xsd:double".resolve()}if(this==Number.NEGATIVE_INFINITY){return"xsd:double".resolve()}if(this==Number.NaN){return"xsd:double".resolve()}var m=this.toString();if(c.test(m)){return"xsd:integer".resolve()}if(a.test(m)){return"xsd:decimal".resolve()}if(g.test(m)){return"xsd:double".resolve()}}},value:l(function(){return this}),nodeType:l(function(){return"TypedLiteral"}),n3:l(function(){if(this==Number.POSITIVE_INFINITY){return'"INF"^^<'+"xsd:double".resolve()+">"}if(this==Number.NEGATIVE_INFINITY){return'"-INF"^^<'+"xsd:double".resolve()+">"}if(this==Number.NaN){return'"NaN"^^<'+"xsd:double".resolve()+">"}return this.toString()}),toNT:l(function(){if(this==Number.POSITIVE_INFINITY){return'"INF"^^<'+"xsd:double".resolve()+">"}if(this==Number.NEGATIVE_INFINITY){return'"-INF"^^<'+"xsd:double".resolve()+">"}if(this==Number.NaN){return'"NaN"^^<'+"xsd:double".resolve()+">"}return'"'+this.toString()+'"^^<'+this.type+">"}),toCanonical:l(function(){return this.nt()})});return{curiemap:f,propertymap:j,graphify:function(){var m=Array.prototype.slice.call(arguments),o=new h.Graph;function n(p){if(typeof p=="object"&&!p.nodeType){if(!p.id){p.ref()}o.merge(p.graphify())}}m.forEach(function(p){if(Array.isArray(p)){p.forEach(function(q){n(q)})}else{n(p)}});return o}}})(curiemap,propertymap); -------------------------------------------------------------------------------- /js3.node.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CURIE Map 3 | */ 4 | var curiemap = (function(map) { 5 | function oflip(o) { 6 | var out = {}; 7 | Object.keys(o).forEach(function(k) { out[o[k]] = k }); 8 | return out; 9 | }; 10 | return Object.defineProperties(map, { 11 | resolve: { 12 | writable: false, configurable : false, enumerable: false, 13 | value: function(o) { 14 | var index = o.indexOf(":"); 15 | if(index < 0 || o.indexOf("//") >= 0 ) { return o } 16 | var prefix = o.slice(0, index).toLowerCase(); 17 | if(!this[prefix]) return o; 18 | return this[prefix].concat( o.slice(++index) ); 19 | } 20 | }, 21 | setDefault: { 22 | writable: false, configurable : false, enumerable: false, 23 | value: function(o) { this[''] = o; return this; } 24 | }, 25 | getPrefix: { 26 | writable: false, configurable : false, enumerable: false, 27 | value: function(o) { return oflip(this)[o]; } 28 | }, 29 | shrink: { 30 | writable: false, configurable : false, enumerable: false, 31 | value: function(iri) { 32 | for(pref in this) 33 | if(iri.substr(0,this[pref].length) == this[pref]) 34 | return pref + ':' + iri.slice(this[pref].length); 35 | return iri; 36 | } 37 | }, 38 | }); 39 | })({ 40 | owl: "http://www.w3.org/2002/07/owl#", 41 | rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#", 42 | rdfs: "http://www.w3.org/2000/01/rdf-schema#", 43 | rdfa: "http://www.w3.org/ns/rdfa#", 44 | xhv: "http://www.w3.org/1999/xhtml/vocab#", 45 | xml: "http://www.w3.org/XML/1998/namespace", 46 | xsd: "http://www.w3.org/2001/XMLSchema#", 47 | grddl: "http://www.w3.org/2003/g/data-view#", 48 | powder: "http://www.w3.org/2007/05/powder#", 49 | powders: "http://www.w3.org/2007/05/powder-s#", 50 | rif: "http://www.w3.org/2007/rif#", 51 | atom: "http://www.w3.org/2005/Atom/", 52 | xhtml: "http://www.w3.org/1999/xhtml#", 53 | formats: "http://www.w3.org/ns/formats/", 54 | xforms: "http://www.w3.org/2002/xforms/", 55 | xhtmlvocab: "http://www.w3.org/1999/xhtml/vocab/", 56 | xpathfn: "http://www.w3.org/2005/xpath-functions#", 57 | http: "http://www.w3.org/2006/http#", 58 | link: "http://www.w3.org/2006/link#", 59 | time: "http://www.w3.org/2006/time#", 60 | acl: "http://www.w3.org/ns/auth/acl#", 61 | cert: "http://www.w3.org/ns/auth/cert#", 62 | rsa: "http://www.w3.org/ns/auth/rsa#", 63 | crypto: "http://www.w3.org/2000/10/swap/crypto#", 64 | list: "http://www.w3.org/2000/10/swap/list#", 65 | log: "http://www.w3.org/2000/10/swap/log#", 66 | math: "http://www.w3.org/2000/10/swap/math#", 67 | os: "http://www.w3.org/2000/10/swap/os#", 68 | string: "http://www.w3.org/2000/10/swap/string#", 69 | doc: "http://www.w3.org/2000/10/swap/pim/doc#", 70 | contact: "http://www.w3.org/2000/10/swap/pim/contact#", 71 | p3p: "http://www.w3.org/2002/01/p3prdfv1#", 72 | swrl: "http://www.w3.org/2003/11/swrl#", 73 | swrlb: "http://www.w3.org/2003/11/swrlb#", 74 | exif: "http://www.w3.org/2003/12/exif/ns#", 75 | earl: "http://www.w3.org/ns/earl#", 76 | ma: "http://www.w3.org/ns/ma-ont#", 77 | sawsdl: "http://www.w3.org/ns/sawsdl#", 78 | sd: "http://www.w3.org/ns/sparql-service-description#", 79 | skos: "http://www.w3.org/2004/02/skos/core#", 80 | fresnel: "http://www.w3.org/2004/09/fresnel#", 81 | gen: "http://www.w3.org/2006/gen/ont#", 82 | timezone: "http://www.w3.org/2006/timezone#", 83 | skosxl: "http://www.w3.org/2008/05/skos-xl#", 84 | org: "http://www.w3.org/ns/org#", 85 | ical: "http://www.w3.org/2002/12/cal/ical#", 86 | wgs84: "http://www.w3.org/2003/01/geo/wgs84_pos#", 87 | vcard: "http://www.w3.org/2006/vcard/ns#", 88 | turtle: "http://www.w3.org/2008/turtle#", 89 | pointers: "http://www.w3.org/2009/pointers#", 90 | dcat: "http://www.w3.org/ns/dcat#", 91 | imreg: "http://www.w3.org/2004/02/image-regions#", 92 | rdfg: "http://www.w3.org/2004/03/trix/rdfg-1/", 93 | swp: "http://www.w3.org/2004/03/trix/swp-2/", 94 | rei: "http://www.w3.org/2004/06/rei#", 95 | wairole: "http://www.w3.org/2005/01/wai-rdf/GUIRoleTaxonomy#", 96 | states: "http://www.w3.org/2005/07/aaa#", 97 | wn20schema: "http://www.w3.org/2006/03/wn/wn20/schema/", 98 | httph: "http://www.w3.org/2007/ont/httph#", 99 | act: "http://www.w3.org/2007/rif-builtin-action#", 100 | common: "http://www.w3.org/2007/uwa/context/common.owl#", 101 | dcn: "http://www.w3.org/2007/uwa/context/deliverycontext.owl#", 102 | hard: "http://www.w3.org/2007/uwa/context/hardware.owl#", 103 | java: "http://www.w3.org/2007/uwa/context/java.owl#", 104 | loc: "http://www.w3.org/2007/uwa/context/location.owl#", 105 | net: "http://www.w3.org/2007/uwa/context/network.owl#", 106 | push: "http://www.w3.org/2007/uwa/context/push.owl#", 107 | soft: "http://www.w3.org/2007/uwa/context/software.owl#", 108 | web: "http://www.w3.org/2007/uwa/context/web.owl#", 109 | content: "http://www.w3.org/2008/content#", 110 | vs: "http://www.w3.org/2003/06/sw-vocab-status/ns#", 111 | air: "http://dig.csail.mit.edu/TAMI/2007/amord/air#", 112 | ex: "http://example.org/", 113 | 114 | dc: "http://purl.org/dc/terms/", 115 | dc11: "http://purl.org/dc/elements/1.1/", 116 | dctype: "http://purl.org/dc/dcmitype/", 117 | foaf: "http://xmlns.com/foaf/0.1/", 118 | cc: "http://creativecommons.org/ns#", 119 | opensearch: "http://a9.com/-/spec/opensearch/1.1/", 120 | 'void': "http://rdfs.org/ns/void#", 121 | sioc: "http://rdfs.org/sioc/ns#", 122 | sioca: "http://rdfs.org/sioc/actions#", 123 | sioct: "http://rdfs.org/sioc/types#", 124 | lgd: "http://linkedgeodata.org/vocabulary#", 125 | moat: "http://moat-project.org/ns#", 126 | days: "http://ontologi.es/days#", 127 | giving: "http://ontologi.es/giving#", 128 | lang: "http://ontologi.es/lang/core#", 129 | like: "http://ontologi.es/like#", 130 | status: "http://ontologi.es/status#", 131 | og: "http://opengraphprotocol.org/schema/", 132 | protege: "http://protege.stanford.edu/system#", 133 | dady: "http://purl.org/NET/dady#", 134 | uri: "http://purl.org/NET/uri#", 135 | audio: "http://purl.org/media/audio#", 136 | video: "http://purl.org/media/video#", 137 | gridworks: "http://purl.org/net/opmv/types/gridworks#", 138 | hcterms: "http://purl.org/uF/hCard/terms/", 139 | bio: "http://purl.org/vocab/bio/0.1/", 140 | cs: "http://purl.org/vocab/changeset/schema#", 141 | geographis: "http://telegraphis.net/ontology/geography/geography#", 142 | doap: "http://usefulinc.com/ns/doap#", 143 | daml: "http://www.daml.org/2001/03/daml+oil#", 144 | geonames: "http://www.geonames.org/ontology#", 145 | sesame: "http://www.openrdf.org/schema/sesame#", 146 | cv: "http://rdfs.org/resume-rdf/", 147 | wot: "http://xmlns.com/wot/0.1/", 148 | media: "http://purl.org/microformat/hmedia/", 149 | ctag: "http://commontag.org/ns#" 150 | }); 151 | /** 152 | * Property Map 153 | */ 154 | var propertymap = (function(map) { 155 | return Object.defineProperties(map, { 156 | resolve: { 157 | writable: false, configurable : false, enumerable: false, 158 | value: function(t,l) { 159 | t = t.toString(); 160 | l = Array.isArray(l) && l.length > 0 ? l.concat(Object.keys(this)) : Object.keys(this); 161 | for(i in l) if(this[l[i]].indexOf(t) >= 0) return l[i] + ':' + t; 162 | return t; 163 | } 164 | }, 165 | ambiguities: { 166 | writable: false, configurable : false, enumerable: false, 167 | value: function() { 168 | var _ = this, map = {}, out = []; 169 | Object.keys(this).forEach(function(ont) { 170 | _[ont].forEach(function(prop) { if(!map[prop]) map[prop] = [ont + ':' + prop]; else map[prop].push(ont + ':' + prop) }) 171 | }); 172 | Object.keys(map).forEach(function(prop) { 173 | if(map[prop].length > 1) out = out.concat(map[prop]); 174 | }); 175 | return out; 176 | } 177 | } 178 | }); 179 | })({ 180 | owl: ['allValuesFrom','annotatedProperty','annotatedSource','annotatedTarget','assertionProperty','backwardCompatibleWith', 181 | 'bottomDataProperty','bottomObjectProperty','cardinality','complementOf','datatypeComplementOf','deprecated','differentFrom', 182 | 'disjointUnionOf','disjointWith','distinctMembers','equivalentClass','equivalentProperty','hasKey','hasSelf','hasValue', 183 | 'imports','incompatibleWith','intersectionOf','inverseOf','maxCardinality','maxQualifiedCardinality','members','minCardinality', 184 | 'minQualifiedCardinality','onClass','onDataRange','onDatatype','oneOf','onProperties','onProperty','priorVersion','propertyChainAxiom', 185 | 'propertyDisjointWith','qualifiedCardinality','sameAs','someValuesFrom','sourceIndividual','targetIndividual','targetValue', 186 | 'topDataProperty','topObjectProperty','unionOf','versionInfo','versionIRI','withRestrictions'], 187 | rdf: ['type','subject','predicate','object','value','first','rest'], 188 | rdfs: ['subClassOf','subPropertyOf','comment','label','domain','range','seeAlso','isDefinedBy','member'], 189 | grddl: ['namespaceTransformation','transformation','transformationProperty','result','profileTransformation'], 190 | wdrs: ['text','issuedby','matchesregex','notmatchesregex','hasIRI','tag','notknownto','describedby','authenticate', 191 | 'validfrom','validuntil','logo','sha1sum','certified','certifiedby','supportedby','data_error','proc_error','error_code'], 192 | 193 | dc: ['title','creator','subject','description','publisher','contributor','date','type','format','identifier','source', 194 | 'language','relation','coverage','rights','audience','alternative','tableOfContents','abstract','created','valid', 195 | 'available','issued','modified','extent','medium','isVersionOf','hasVersion','isReplacedBy','replaces','isRequiredBy', 196 | 'requires','isPartOf','hasPart','isReferencedBy','references','isFormatOf','hasFormat','conformsTo','spatial','temporal', 197 | 'mediator','dateAccepted','dateCopyrighted','dateSubmitted','educationLevel','accessRights','bibliographicCitation', 198 | 'license','rightsHolder','provenance','instructionalMethod','accrualMethod','accrualPeriodicity','accrualPolicy'], 199 | dc11: ['title','creator','subject','description','publisher','contributor','date','type','format','identifier','source', 200 | 'language','relation','coverage','rights'], 201 | foaf: ['mbox','mbox_sha1sum','gender','geekcode','dnaChecksum','sha1','based_near','title','nick','jabberID','aimChatID', 202 | 'skypeID','icqChatID','yahooChatID','msnChatID','name','firstName','lastName','givenName','givenname','surname', 203 | 'family_name','familyName','phone','homepage','weblog','openid','tipjar','plan','made','maker','img','depiction', 204 | 'depicts','thumbnail','myersBriggs','workplaceHomepage','workInfoHomepage','schoolHomepage','knows','interest', 205 | 'topic_interest','publications','currentProject','pastProject','fundedBy','logo','topic','primaryTopic','focus', 206 | 'isPrimaryTopicOf','page','theme','account','holdsAccount','accountServiceHomepage','accountName','member', 207 | 'membershipClass','birthday','age','status'], 208 | cc: ['requires','prohibits','jurisdiction','useGuidelines','deprecatedOn','attributionName','license','attributionURL', 209 | 'morePermissions','permits','legalcode'], 210 | 'void': ['statItem','feature','subset','target','sparqlEndpoint','linkPredicate','exampleResource','vocabulary', 211 | 'subjectsTarget','objectsTarget','dataDump','uriLookupEndpoint','uriRegexPattern'], 212 | sioc: ['about','account_of','addressed_to','administrator_of','attachment','avatar','container_of','content','creator_of', 213 | 'earlier_version','email','email_sha1','embeds_knowledge','feed','follows','function_of','has_administrator', 214 | 'has_container','has_creator','has_discussion','has_function','has_host','has_member','has_moderator','has_modifier', 215 | 'has_owner','has_parent','has_reply','has_scope','has_space','has_subscriber','has_usergroup','host_of','id', 216 | 'ip_address','last_activity_date','last_item_date','last_reply_date','later_version','latest_version','link', 217 | 'links_to','member_of','moderator_of','modifier_of','name','next_by_date','next_version','note','num_authors', 218 | 'num_items','num_replies','num_threads','num_views','owner_of','parent_of','previous_by_date','previous_version', 219 | 'related_to','reply_of','scope_of','sibling','space_of','subscriber_of','topic','usergroup_of'], 220 | sioca: ['byproduct','creates','deletes','modifies','object','product','source','uses'], // may remove.. 221 | link: ['listDocumentProperty','uri'], 222 | acl: ['accessControl','accessTo','accessToClass','agent','agentClass','defaultForNew','mode'], 223 | skos: ['inScheme','hasTopConcept','topConceptOf','prefLabel','altLabel','hiddenLabel','notation','note','changeNote', 224 | 'definition','editorialNote','example','historyNote','scopeNote','semanticRelation','broader','narrower','related', 225 | 'broaderTransitive','narrowerTransitive','member','memberList','mappingRelation','broadMatch','narrowMatch', 226 | 'relatedMatch','exactMatch','closeMatch'], 227 | wgs84: ['lat','location','long','alt','lat_long'], 228 | org: ['subOrganizationOf','transitiveSubOrganizationOf','hasSubOrganization ','purpose','hasUnit','unitOf','classification', 229 | 'identifier','linkedTo','memberOf','hasMember','reportsTo','member','organization','role','hasMembership','memberDuring', 230 | 'roleProperty','headOf','remuneration','siteAddress','hasSite','siteOf','hasPrimarySite','hasRegisteredSite','basedAt ', 231 | 'location','originalOrganization','changedBy','resultedFrom','resultingOrganization'], 232 | }); 233 | /** 234 | * JS3 Core 235 | */ 236 | js3 = (function( curiemap, propertymap, api ) { 237 | var bn = 0; 238 | function _(v) { return { writable: false, configurable : false, enumerable: false, value: v }} 239 | function pad(n){ return n<10 ? '0'+n : n } 240 | function prop(p,l) { 241 | if(p == 'a') return 'rdf:type'; 242 | p = p.replace('$',':'); 243 | if(p.indexOf(':') == -1) p = propertymap.resolve(p,l); 244 | return p; 245 | }; 246 | if(!api) { 247 | api = {}; 248 | // Temporary import of RDFa API RDFTriple and Graph for graphification. 249 | api.RDFTriple = function(s, p, o) { this.subject = s; this.property = p; this.object = o; }; 250 | api.RDFTriple.prototype = { 251 | object: null, property: null, subject: null, 252 | toString: function() { return this.subject.toNT() + " " + this.property.toNT() + " " + this.object.toNT() + " ." }, 253 | equals: function(t) { return this.subject.equals(t.subject) && this.property.equals(t.property) && this.object.equals(t.object) } 254 | }; 255 | api.Graph = function(a) { 256 | this.length = 0; 257 | this.graph = []; 258 | this.index = {}; 259 | if(Array.isArray(a)) this.importArray(a); 260 | }; 261 | api.Graph.prototype = { 262 | length: null, graph: null, 263 | importArray: function(a) { while( a.length > 0) { this.add(a.pop()) } }, 264 | get: function(index) { return this.graph[index] }, 265 | add: function(triple) { 266 | if(!this.index[triple.subject.value]) this.index[triple.subject.value] = {}; 267 | if(!this.index[triple.subject.value][triple.property.value]) this.index[triple.subject.value][triple.property.value] = []; 268 | if(this.index[triple.subject.value][triple.property.value].some(function(o){return o.equals(triple.object)})) return; 269 | this.length++; 270 | this.index[triple.subject.value][triple.property.value].push(triple.object); 271 | this.graph.push(triple); 272 | }, 273 | merge: function(s) { 274 | var _g1 = 0, _g = s.length; 275 | while(_g1 < _g) { 276 | var i = _g1++; 277 | this.add(s.get(i)) 278 | } 279 | }, 280 | every: function(filter) { return this.graph.every(filter) }, 281 | some: function(filter) { return this.graph.some(filter) }, 282 | forEach: function(callbck) { this.graph.forEach(callbck) }, 283 | filter: function(filter) { return new api.Graph(this.graph.filter(filter)); }, 284 | apply: function(filter) { this.graph = this.graph.filter(filter); this.length = this.graph.length; }, 285 | toArray: function() { return this.graph.slice() } 286 | }; 287 | } 288 | // N-Triples encoder 289 | function encodeString(s) { 290 | var out = ""; 291 | var skip = false; 292 | var _g1 = 0, _g = s.length; 293 | while(_g1 < _g) { 294 | var i = _g1++; 295 | if(!skip) { 296 | var code = s.charCodeAt(i); 297 | if(55296 <= code && code <= 56319) { 298 | var low = s.charCodeAt(i + 1); 299 | code = (code - 55296) * 1024 + (low - 56320) + 65536; 300 | skip = true 301 | } 302 | if(code > 1114111) { throw new Error("Char out of range"); } 303 | var hex = "00000000".concat((new Number(code)).toString(16).toUpperCase()); 304 | if(code >= 65536) { 305 | out += "\\U" + hex.slice(-8) 306 | } else { 307 | if(code >= 127 || code <= 31) { 308 | switch(code) { 309 | case 9: out += "\\t"; break; 310 | case 10: out += "\\n"; break; 311 | case 13: out += "\\r"; break; 312 | default: out += "\\u" + hex.slice(-4); break 313 | } 314 | } else { 315 | switch(code) { 316 | case 34: out += '\\"'; break; 317 | case 92: out += "\\\\"; break; 318 | default: out += s.charAt(i); break 319 | } 320 | } 321 | } 322 | } else { 323 | skip = !skip 324 | } 325 | } 326 | return out 327 | }; 328 | // Let the magic begin 329 | Object.defineProperties( Object.prototype, { 330 | equals: _(function(other) { 331 | if( this.nodeType() != other.nodeType() ) return false; 332 | switch(this.nodeType()) { 333 | case "IRI": case "BlankNode": 334 | return this == other; 335 | case "PlainLiteral": 336 | if((this.language && !other.language) || (!this.language && other.language)) return false; 337 | if(this.language && other.language) return this.language == other.language && this == other; 338 | return this == other; 339 | case "TypedLiteral": 340 | return this.type.equals(other.type) && this == other; 341 | } 342 | return this.n3() == other.n3() 343 | }), 344 | ref: _( function(id) { 345 | Object.defineProperties(this, { 346 | id: _( id ? id.resolve() : '_:b' +(++bn) ), 347 | n3: _( function(a) { 348 | var outs = [], o = this, map = o.aliasmap || a; 349 | Object.keys(this).forEach(function(p) { 350 | if(typeof o[p] == 'function') return; 351 | if(o[p].id && o[p].id.nodeType() == 'IRI') return outs.push( prop(p,map) + ' ' + o[p].id.n3() ); 352 | if(!o[p].nodeType && !o[p].id) o[p].ref(); 353 | outs.push( prop(p, map) + ' ' + o[p].n3(map) ); 354 | }); 355 | outs = outs.join(";\n "); 356 | return id ? this.id.n3() + ' ' + outs + ' .' : '[ ' + outs + ' ]'; 357 | }), 358 | toNT: _( function(a) { 359 | return this.graphify(a).toArray().join("\n"); 360 | }), 361 | graphify: _( function(a) { 362 | var graph = new api.Graph, o = this, map = o.aliasmap || a; 363 | function graphify(s1,p1,o1) { 364 | if(typeof o1 == 'function') return; 365 | if(!o1.nodeType && !o1.id) o1.ref(); 366 | if(o1.id) { 367 | graph.add( new api.RDFTriple(s1, prop(p1,map), o1.id ) ); 368 | graph.merge( o1.graphify() ); 369 | } else if(!Array.isArray(o1)) { 370 | graph.add( new api.RDFTriple(s1, prop(p1,map), o1 ) ); 371 | } else if(Array.isArray(o1)) { 372 | if(!o1.list) { 373 | o1.forEach( function(i) { graphify(s1,p1,i) }); 374 | } else { 375 | if(o1.length == 0) { 376 | graph.add( new api.RDFTriple(s1, prop(p1,map), "rdf:nil".resolve() ) ); 377 | } else { 378 | var b = {}.ref(); 379 | graph.add( new api.RDFTriple(s1, prop(p1,map), b.id ) ); 380 | o1.forEach( function(i,x) { 381 | graphify(b.id, 'rdf:first'.resolve(), i ); 382 | var n = {}.ref(); 383 | graph.add( new api.RDFTriple(b.id, 'rdf:rest'.resolve(), (x == o1.length-1) ? 'rdf:nil'.resolve() : n.id ) ); 384 | b = n; 385 | }); 386 | } 387 | } 388 | } 389 | } 390 | Object.keys(this).forEach(function(p) { graphify(o.id, p, o[p]) }); 391 | return graph; 392 | }), 393 | using: _( function() { 394 | Object.defineProperty(this,'aliasmap',_(Array.prototype.slice.call(arguments))); 395 | return this; 396 | }) 397 | }); 398 | return this; 399 | }), 400 | }); 401 | Object.defineProperties( String.prototype, { 402 | tl: _( function(t) { 403 | Object.defineProperty(this,'type', _(t.resolve()) ); 404 | Object.defineProperty(this,'language', _(null) ); 405 | return this; 406 | }), 407 | l: _( function(l) { 408 | Object.defineProperty(this,'type', _(null) ); 409 | Object.defineProperty(this,'language', _(l) ); 410 | return this; 411 | }), 412 | resolve: _( function() { 413 | return curiemap.resolve(this); 414 | }), 415 | value: _( function() { return this; }), 416 | nodeType: _( function() { 417 | if(this.type) return 'TypedLiteral'; 418 | if(this.language || this.indexOf(' ') >= 0 || this.indexOf(':') == -1 ) return 'PlainLiteral'; 419 | if(this.substr(0,2) == '_:') return 'BlankNode'; 420 | return 'IRI'; 421 | }), 422 | n3: _( function() { 423 | switch(this.nodeType()) { 424 | case 'PlainLiteral': return ('"' + encodeString(this) + '"' + ( this.language ? '@' + this.language : '')).toString(); 425 | case 'IRI': 426 | return (this.resolve() == this) ? "<" + encodeString(this.resolve()) + ">" : this.toString(); 427 | case 'BlankNode': return this.toString(); 428 | case 'TypedLiteral': 429 | if(this.type.resolve() == "rdf:PlainLiteral".resolve()) return '"' + encodeString(this) + '"'; 430 | return '"' + encodeString(this) + '"^^' + this.type.n3(); 431 | } 432 | }), 433 | toNT: _( function() { 434 | switch(this.nodeType()) { 435 | case 'PlainLiteral': return ('"' + encodeString(this) + '"' + ( this.language ? '@' + this.language : '')).toString(); 436 | case 'IRI': return "<" + encodeString(this.resolve()) + ">"; 437 | case 'BlankNode': return this.toString(); 438 | case 'TypedLiteral': 439 | if(this.type.resolve() == "rdf:PlainLiteral".resolve()) return '"' + encodeString(this) + '"'; 440 | return '"' + encodeString(this) + '"^^' + this.type.n3(); 441 | } 442 | }), 443 | toCanonical: _( function() { return this.n3() } ) 444 | }); 445 | Object.defineProperties( Array.prototype, { 446 | list: _(false), 447 | toList: _(function() { 448 | this.list = true; 449 | return this; 450 | }), 451 | nodeType: _("Collection"), 452 | n3: _( function(a) { 453 | var outs = []; 454 | this.forEach( function(i) { 455 | if(typeof i == 'function') return; 456 | if(i.id && i.id.nodeType() == 'IRI') return outs.push( i.id.n3() ); 457 | if(!i.nodeType) i.ref(); 458 | outs.push(i.n3(a)) 459 | }); 460 | return this.list ? "( " + outs.join(" ") + " )" : outs.join(", "); 461 | }) 462 | }); 463 | Object.defineProperties( Boolean.prototype, { 464 | type: _( "xsd:boolean".resolve() ), 465 | value: _( function() { return this; }), 466 | nodeType: _( function() { return "TypedLiteral"} ), 467 | n3: _( function() { return this.valueOf() } ), 468 | toNT: _( function() { return '"' + this.valueOf() + '"' + "^^<" + this.type + '>' } ), 469 | toCanonical: _( function() { return this.toNT() } ) 470 | }); 471 | Object.defineProperties( Date.prototype, { 472 | type: _( "xsd:dateTime".resolve() ), 473 | value: _( function() { return this; }), 474 | nodeType: _( function() { return "TypedLiteral"} ), 475 | n3: _( function() { 476 | return '"' + this.getUTCFullYear()+'-' + pad(this.getUTCMonth()+1)+'-' + pad(this.getUTCDate())+'T' 477 | + pad(this.getUTCHours())+':' + pad(this.getUTCMinutes())+':' + pad(this.getUTCSeconds())+'Z"^^<' + this.type + '>'; 478 | }), 479 | toNT: _( function() { return this.n3() } ), 480 | toCanonical: _( function() { return this.n3() } ) 481 | }); 482 | var INTEGER = new RegExp("^(-|\\+)?[0-9]+$", ""); 483 | var DOUBLE = new RegExp("^(-|\\+)?(([0-9]+\\.[0-9]*[eE]{1}(-|\\+)?[0-9]+)|(\\.[0-9]+[eE]{1}(-|\\+)?[0-9]+)|([0-9]+[eE]{1}(-|\\+)?[0-9]+))$", ""); 484 | var DECIMAL = new RegExp("^(-|\\+)?[0-9]*\\.[0-9]+?$", ""); 485 | Object.defineProperties( Number.prototype, { 486 | type: { 487 | configurable : false, enumerable: false, 488 | get: function() { 489 | if(this == Number.POSITIVE_INFINITY) return 'xsd:double'.resolve(); 490 | if(this == Number.NEGATIVE_INFINITY) return 'xsd:double'.resolve(); 491 | if(this == Number.NaN) return 'xsd:double'.resolve(); 492 | var n = this.toString(); 493 | if(INTEGER.test(n)) return 'xsd:integer'.resolve(); 494 | if(DECIMAL.test(n)) return 'xsd:decimal'.resolve(); 495 | if(DOUBLE.test(n)) return 'xsd:double'.resolve(); 496 | } 497 | }, 498 | value: _( function() { return this; }), 499 | nodeType: _( function() { return "TypedLiteral" } ), 500 | n3: _( function() { 501 | if(this == Number.POSITIVE_INFINITY) return '"INF"^^<' + 'xsd:double'.resolve() + '>'; 502 | if(this == Number.NEGATIVE_INFINITY) return '"-INF"^^<' + 'xsd:double'.resolve() + '>'; 503 | if(this == Number.NaN) return '"NaN"^^<' + 'xsd:double'.resolve() + '>'; 504 | return this.toString(); 505 | }), 506 | toNT: _( function() { 507 | if(this == Number.POSITIVE_INFINITY) return '"INF"^^<' + 'xsd:double'.resolve() + '>'; 508 | if(this == Number.NEGATIVE_INFINITY) return '"-INF"^^<' + 'xsd:double'.resolve() + '>'; 509 | if(this == Number.NaN) return '"NaN"^^<' + 'xsd:double'.resolve() + '>'; 510 | return '"' + this.toString() + '"' + "^^<" + this.type + '>'; 511 | }), 512 | toCanonical: _( function() { return this.nt() } ) 513 | }); 514 | return { 515 | curiemap: curiemap, propertymap: propertymap, 516 | graphify: function() { 517 | var a = Array.prototype.slice.call(arguments), gout = new api.Graph; 518 | function graphify(o) { 519 | if(typeof o == 'object' && !o.nodeType) { 520 | if(!o.id) o.ref(); 521 | gout.merge( o.graphify() ); 522 | } 523 | }; 524 | a.forEach( function(o) { 525 | if(Array.isArray(o)) o.forEach(function(x){graphify(x)}); 526 | else graphify(o); 527 | }); 528 | return gout; 529 | } 530 | }; 531 | })( curiemap, propertymap );module.exports = js3; 532 | -------------------------------------------------------------------------------- /source/core.js: -------------------------------------------------------------------------------- 1 | /** 2 | * JS3 Core 3 | */ 4 | js3 = (function( curiemap, propertymap, api ) { 5 | var bn = 0; 6 | function _(v) { return { writable: false, configurable : false, enumerable: false, value: v }} 7 | function pad(n){ return n<10 ? '0'+n : n } 8 | function prop(p,l) { 9 | if(p == 'a') return 'rdf:type'; 10 | p = p.replace('$',':'); 11 | if(p.indexOf(':') == -1) p = propertymap.resolve(p,l); 12 | return p; 13 | }; 14 | if(!api) { 15 | api = {}; 16 | // Temporary import of RDFa API RDFTriple and Graph for graphification. 17 | api.RDFTriple = function(s, p, o) { this.subject = s; this.property = p; this.object = o; }; 18 | api.RDFTriple.prototype = { 19 | object: null, property: null, subject: null, 20 | toString: function() { return this.subject.toNT() + " " + this.property.toNT() + " " + this.object.toNT() + " ." }, 21 | equals: function(t) { return this.subject.equals(t.subject) && this.property.equals(t.property) && this.object.equals(t.object) } 22 | }; 23 | api.Graph = function(a) { 24 | this.length = 0; 25 | this.graph = []; 26 | this.index = {}; 27 | if(Array.isArray(a)) this.importArray(a); 28 | }; 29 | api.Graph.prototype = { 30 | length: null, graph: null, 31 | importArray: function(a) { while( a.length > 0) { this.add(a.pop()) } }, 32 | get: function(index) { return this.graph[index] }, 33 | add: function(triple) { 34 | if(!this.index[triple.subject.value]) this.index[triple.subject.value] = {}; 35 | if(!this.index[triple.subject.value][triple.property.value]) this.index[triple.subject.value][triple.property.value] = []; 36 | if(this.index[triple.subject.value][triple.property.value].some(function(o){return o.equals(triple.object)})) return; 37 | this.length++; 38 | this.index[triple.subject.value][triple.property.value].push(triple.object); 39 | this.graph.push(triple); 40 | }, 41 | merge: function(s) { 42 | var _g1 = 0, _g = s.length; 43 | while(_g1 < _g) { 44 | var i = _g1++; 45 | this.add(s.get(i)) 46 | } 47 | }, 48 | every: function(filter) { return this.graph.every(filter) }, 49 | some: function(filter) { return this.graph.some(filter) }, 50 | forEach: function(callbck) { this.graph.forEach(callbck) }, 51 | filter: function(filter) { return new api.Graph(this.graph.filter(filter)); }, 52 | apply: function(filter) { this.graph = this.graph.filter(filter); this.length = this.graph.length; }, 53 | toArray: function() { return this.graph.slice() } 54 | }; 55 | } 56 | // N-Triples encoder 57 | function encodeString(s) { 58 | var out = ""; 59 | var skip = false; 60 | var _g1 = 0, _g = s.length; 61 | while(_g1 < _g) { 62 | var i = _g1++; 63 | if(!skip) { 64 | var code = s.charCodeAt(i); 65 | if(55296 <= code && code <= 56319) { 66 | var low = s.charCodeAt(i + 1); 67 | code = (code - 55296) * 1024 + (low - 56320) + 65536; 68 | skip = true 69 | } 70 | if(code > 1114111) { throw new Error("Char out of range"); } 71 | var hex = "00000000".concat((new Number(code)).toString(16).toUpperCase()); 72 | if(code >= 65536) { 73 | out += "\\U" + hex.slice(-8) 74 | } else { 75 | if(code >= 127 || code <= 31) { 76 | switch(code) { 77 | case 9: out += "\\t"; break; 78 | case 10: out += "\\n"; break; 79 | case 13: out += "\\r"; break; 80 | default: out += "\\u" + hex.slice(-4); break 81 | } 82 | } else { 83 | switch(code) { 84 | case 34: out += '\\"'; break; 85 | case 92: out += "\\\\"; break; 86 | default: out += s.charAt(i); break 87 | } 88 | } 89 | } 90 | } else { 91 | skip = !skip 92 | } 93 | } 94 | return out 95 | }; 96 | // Let the magic begin 97 | Object.defineProperties( Object.prototype, { 98 | equals: _(function(other) { 99 | if( this.nodeType() != other.nodeType() ) return false; 100 | switch(this.nodeType()) { 101 | case "IRI": case "BlankNode": 102 | return this == other; 103 | case "PlainLiteral": 104 | if((this.language && !other.language) || (!this.language && other.language)) return false; 105 | if(this.language && other.language) return this.language == other.language && this == other; 106 | return this == other; 107 | case "TypedLiteral": 108 | return this.type.equals(other.type) && this == other; 109 | } 110 | return this.n3() == other.n3() 111 | }), 112 | ref: _( function(id) { 113 | Object.defineProperties(this, { 114 | id: _( id ? id.resolve() : '_:b' +(++bn) ), 115 | n3: _( function(a) { 116 | var outs = [], o = this, map = o.aliasmap || a; 117 | Object.keys(this).forEach(function(p) { 118 | if(typeof o[p] == 'function') return; 119 | if(o[p].id && o[p].id.nodeType() == 'IRI') return outs.push( prop(p,map) + ' ' + o[p].id.n3() ); 120 | if(!o[p].nodeType && !o[p].id) o[p].ref(); 121 | outs.push( prop(p, map) + ' ' + o[p].n3(map) ); 122 | }); 123 | outs = outs.join(";\n "); 124 | return id ? this.id.n3() + ' ' + outs + ' .' : '[ ' + outs + ' ]'; 125 | }), 126 | toNT: _( function(a) { 127 | return this.graphify(a).toArray().join("\n"); 128 | }), 129 | graphify: _( function(a) { 130 | var graph = new api.Graph, o = this, map = o.aliasmap || a; 131 | function graphify(s1,p1,o1) { 132 | if(typeof o1 == 'function') return; 133 | if(!o1.nodeType && !o1.id) o1.ref(); 134 | if(o1.id) { 135 | graph.add( new api.RDFTriple(s1, prop(p1,map), o1.id ) ); 136 | graph.merge( o1.graphify() ); 137 | } else if(!Array.isArray(o1)) { 138 | graph.add( new api.RDFTriple(s1, prop(p1,map), o1 ) ); 139 | } else if(Array.isArray(o1)) { 140 | if(!o1.list) { 141 | o1.forEach( function(i) { graphify(s1,p1,i) }); 142 | } else { 143 | if(o1.length == 0) { 144 | graph.add( new api.RDFTriple(s1, prop(p1,map), "rdf:nil".resolve() ) ); 145 | } else { 146 | var b = {}.ref(); 147 | graph.add( new api.RDFTriple(s1, prop(p1,map), b.id ) ); 148 | o1.forEach( function(i,x) { 149 | graphify(b.id, 'rdf:first'.resolve(), i ); 150 | var n = {}.ref(); 151 | graph.add( new api.RDFTriple(b.id, 'rdf:rest'.resolve(), (x == o1.length-1) ? 'rdf:nil'.resolve() : n.id ) ); 152 | b = n; 153 | }); 154 | } 155 | } 156 | } 157 | } 158 | Object.keys(this).forEach(function(p) { graphify(o.id, p, o[p]) }); 159 | return graph; 160 | }), 161 | using: _( function() { 162 | Object.defineProperty(this,'aliasmap',_(Array.prototype.slice.call(arguments))); 163 | return this; 164 | }) 165 | }); 166 | return this; 167 | }), 168 | }); 169 | Object.defineProperties( String.prototype, { 170 | tl: _( function(t) { 171 | Object.defineProperty(this,'type', _(t.resolve()) ); 172 | Object.defineProperty(this,'language', _(null) ); 173 | return this; 174 | }), 175 | l: _( function(l) { 176 | Object.defineProperty(this,'type', _(null) ); 177 | Object.defineProperty(this,'language', _(l) ); 178 | return this; 179 | }), 180 | resolve: _( function() { 181 | return curiemap.resolve(this); 182 | }), 183 | value: _( function() { return this; }), 184 | nodeType: _( function() { 185 | if(this.type) return 'TypedLiteral'; 186 | if(this.language || this.indexOf(' ') >= 0 || this.indexOf(':') == -1 ) return 'PlainLiteral'; 187 | if(this.substr(0,2) == '_:') return 'BlankNode'; 188 | return 'IRI'; 189 | }), 190 | n3: _( function() { 191 | switch(this.nodeType()) { 192 | case 'PlainLiteral': return ('"' + encodeString(this) + '"' + ( this.language ? '@' + this.language : '')).toString(); 193 | case 'IRI': 194 | return (this.resolve() == this) ? "<" + encodeString(this.resolve()) + ">" : this.toString(); 195 | case 'BlankNode': return this.toString(); 196 | case 'TypedLiteral': 197 | if(this.type.resolve() == "rdf:PlainLiteral".resolve()) return '"' + encodeString(this) + '"'; 198 | return '"' + encodeString(this) + '"^^' + this.type.n3(); 199 | } 200 | }), 201 | toNT: _( function() { 202 | switch(this.nodeType()) { 203 | case 'PlainLiteral': return ('"' + encodeString(this) + '"' + ( this.language ? '@' + this.language : '')).toString(); 204 | case 'IRI': return "<" + encodeString(this.resolve()) + ">"; 205 | case 'BlankNode': return this.toString(); 206 | case 'TypedLiteral': 207 | if(this.type.resolve() == "rdf:PlainLiteral".resolve()) return '"' + encodeString(this) + '"'; 208 | return '"' + encodeString(this) + '"^^' + this.type.n3(); 209 | } 210 | }), 211 | toCanonical: _( function() { return this.n3() } ) 212 | }); 213 | Object.defineProperties( Array.prototype, { 214 | list: _(false), 215 | toList: _(function() { 216 | this.list = true; 217 | return this; 218 | }), 219 | nodeType: _("Collection"), 220 | n3: _( function(a) { 221 | var outs = []; 222 | this.forEach( function(i) { 223 | if(typeof i == 'function') return; 224 | if(i.id && i.id.nodeType() == 'IRI') return outs.push( i.id.n3() ); 225 | if(!i.nodeType) i.ref(); 226 | outs.push(i.n3(a)) 227 | }); 228 | return this.list ? "( " + outs.join(" ") + " )" : outs.join(", "); 229 | }) 230 | }); 231 | Object.defineProperties( Boolean.prototype, { 232 | type: _( "xsd:boolean".resolve() ), 233 | value: _( function() { return this; }), 234 | nodeType: _( function() { return "TypedLiteral"} ), 235 | n3: _( function() { return this.valueOf() } ), 236 | toNT: _( function() { return '"' + this.valueOf() + '"' + "^^<" + this.type + '>' } ), 237 | toCanonical: _( function() { return this.toNT() } ) 238 | }); 239 | Object.defineProperties( Date.prototype, { 240 | type: _( "xsd:dateTime".resolve() ), 241 | value: _( function() { return this; }), 242 | nodeType: _( function() { return "TypedLiteral"} ), 243 | n3: _( function() { 244 | return '"' + this.getUTCFullYear()+'-' + pad(this.getUTCMonth()+1)+'-' + pad(this.getUTCDate())+'T' 245 | + pad(this.getUTCHours())+':' + pad(this.getUTCMinutes())+':' + pad(this.getUTCSeconds())+'Z"^^<' + this.type + '>'; 246 | }), 247 | toNT: _( function() { return this.n3() } ), 248 | toCanonical: _( function() { return this.n3() } ) 249 | }); 250 | var INTEGER = new RegExp("^(-|\\+)?[0-9]+$", ""); 251 | var DOUBLE = new RegExp("^(-|\\+)?(([0-9]+\\.[0-9]*[eE]{1}(-|\\+)?[0-9]+)|(\\.[0-9]+[eE]{1}(-|\\+)?[0-9]+)|([0-9]+[eE]{1}(-|\\+)?[0-9]+))$", ""); 252 | var DECIMAL = new RegExp("^(-|\\+)?[0-9]*\\.[0-9]+?$", ""); 253 | Object.defineProperties( Number.prototype, { 254 | type: { 255 | configurable : false, enumerable: false, 256 | get: function() { 257 | if(this == Number.POSITIVE_INFINITY) return 'xsd:double'.resolve(); 258 | if(this == Number.NEGATIVE_INFINITY) return 'xsd:double'.resolve(); 259 | if(this == Number.NaN) return 'xsd:double'.resolve(); 260 | var n = this.toString(); 261 | if(INTEGER.test(n)) return 'xsd:integer'.resolve(); 262 | if(DECIMAL.test(n)) return 'xsd:decimal'.resolve(); 263 | if(DOUBLE.test(n)) return 'xsd:double'.resolve(); 264 | } 265 | }, 266 | value: _( function() { return this; }), 267 | nodeType: _( function() { return "TypedLiteral" } ), 268 | n3: _( function() { 269 | if(this == Number.POSITIVE_INFINITY) return '"INF"^^<' + 'xsd:double'.resolve() + '>'; 270 | if(this == Number.NEGATIVE_INFINITY) return '"-INF"^^<' + 'xsd:double'.resolve() + '>'; 271 | if(this == Number.NaN) return '"NaN"^^<' + 'xsd:double'.resolve() + '>'; 272 | return this.toString(); 273 | }), 274 | toNT: _( function() { 275 | if(this == Number.POSITIVE_INFINITY) return '"INF"^^<' + 'xsd:double'.resolve() + '>'; 276 | if(this == Number.NEGATIVE_INFINITY) return '"-INF"^^<' + 'xsd:double'.resolve() + '>'; 277 | if(this == Number.NaN) return '"NaN"^^<' + 'xsd:double'.resolve() + '>'; 278 | return '"' + this.toString() + '"' + "^^<" + this.type + '>'; 279 | }), 280 | toCanonical: _( function() { return this.nt() } ) 281 | }); 282 | return { 283 | curiemap: curiemap, propertymap: propertymap, 284 | graphify: function() { 285 | var a = Array.prototype.slice.call(arguments), gout = new api.Graph; 286 | function graphify(o) { 287 | if(typeof o == 'object' && !o.nodeType) { 288 | if(!o.id) o.ref(); 289 | gout.merge( o.graphify() ); 290 | } 291 | }; 292 | a.forEach( function(o) { 293 | if(Array.isArray(o)) o.forEach(function(x){graphify(x)}); 294 | else graphify(o); 295 | }); 296 | return gout; 297 | } 298 | }; 299 | })( curiemap, propertymap ); -------------------------------------------------------------------------------- /source/curiemap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CURIE Map 3 | */ 4 | var curiemap = (function(map) { 5 | function oflip(o) { 6 | var out = {}; 7 | Object.keys(o).forEach(function(k) { out[o[k]] = k }); 8 | return out; 9 | }; 10 | return Object.defineProperties(map, { 11 | resolve: { 12 | writable: false, configurable : false, enumerable: false, 13 | value: function(o) { 14 | var index = o.indexOf(":"); 15 | if(index < 0 || o.indexOf("//") >= 0 ) { return o } 16 | var prefix = o.slice(0, index).toLowerCase(); 17 | if(!this[prefix]) return o; 18 | return this[prefix].concat( o.slice(++index) ); 19 | } 20 | }, 21 | setDefault: { 22 | writable: false, configurable : false, enumerable: false, 23 | value: function(o) { this[''] = o; return this; } 24 | }, 25 | getPrefix: { 26 | writable: false, configurable : false, enumerable: false, 27 | value: function(o) { return oflip(this)[o]; } 28 | }, 29 | shrink: { 30 | writable: false, configurable : false, enumerable: false, 31 | value: function(iri) { 32 | for(pref in this) 33 | if(iri.substr(0,this[pref].length) == this[pref]) 34 | return pref + ':' + iri.slice(this[pref].length); 35 | return iri; 36 | } 37 | }, 38 | }); 39 | })({ 40 | owl: "http://www.w3.org/2002/07/owl#", 41 | rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#", 42 | rdfs: "http://www.w3.org/2000/01/rdf-schema#", 43 | rdfa: "http://www.w3.org/ns/rdfa#", 44 | xhv: "http://www.w3.org/1999/xhtml/vocab#", 45 | xml: "http://www.w3.org/XML/1998/namespace", 46 | xsd: "http://www.w3.org/2001/XMLSchema#", 47 | grddl: "http://www.w3.org/2003/g/data-view#", 48 | powder: "http://www.w3.org/2007/05/powder#", 49 | powders: "http://www.w3.org/2007/05/powder-s#", 50 | rif: "http://www.w3.org/2007/rif#", 51 | atom: "http://www.w3.org/2005/Atom/", 52 | xhtml: "http://www.w3.org/1999/xhtml#", 53 | formats: "http://www.w3.org/ns/formats/", 54 | xforms: "http://www.w3.org/2002/xforms/", 55 | xhtmlvocab: "http://www.w3.org/1999/xhtml/vocab/", 56 | xpathfn: "http://www.w3.org/2005/xpath-functions#", 57 | http: "http://www.w3.org/2006/http#", 58 | link: "http://www.w3.org/2006/link#", 59 | time: "http://www.w3.org/2006/time#", 60 | acl: "http://www.w3.org/ns/auth/acl#", 61 | cert: "http://www.w3.org/ns/auth/cert#", 62 | rsa: "http://www.w3.org/ns/auth/rsa#", 63 | crypto: "http://www.w3.org/2000/10/swap/crypto#", 64 | list: "http://www.w3.org/2000/10/swap/list#", 65 | log: "http://www.w3.org/2000/10/swap/log#", 66 | math: "http://www.w3.org/2000/10/swap/math#", 67 | os: "http://www.w3.org/2000/10/swap/os#", 68 | string: "http://www.w3.org/2000/10/swap/string#", 69 | doc: "http://www.w3.org/2000/10/swap/pim/doc#", 70 | contact: "http://www.w3.org/2000/10/swap/pim/contact#", 71 | p3p: "http://www.w3.org/2002/01/p3prdfv1#", 72 | swrl: "http://www.w3.org/2003/11/swrl#", 73 | swrlb: "http://www.w3.org/2003/11/swrlb#", 74 | exif: "http://www.w3.org/2003/12/exif/ns#", 75 | earl: "http://www.w3.org/ns/earl#", 76 | ma: "http://www.w3.org/ns/ma-ont#", 77 | sawsdl: "http://www.w3.org/ns/sawsdl#", 78 | sd: "http://www.w3.org/ns/sparql-service-description#", 79 | skos: "http://www.w3.org/2004/02/skos/core#", 80 | fresnel: "http://www.w3.org/2004/09/fresnel#", 81 | gen: "http://www.w3.org/2006/gen/ont#", 82 | timezone: "http://www.w3.org/2006/timezone#", 83 | skosxl: "http://www.w3.org/2008/05/skos-xl#", 84 | org: "http://www.w3.org/ns/org#", 85 | ical: "http://www.w3.org/2002/12/cal/ical#", 86 | wgs84: "http://www.w3.org/2003/01/geo/wgs84_pos#", 87 | vcard: "http://www.w3.org/2006/vcard/ns#", 88 | turtle: "http://www.w3.org/2008/turtle#", 89 | pointers: "http://www.w3.org/2009/pointers#", 90 | dcat: "http://www.w3.org/ns/dcat#", 91 | imreg: "http://www.w3.org/2004/02/image-regions#", 92 | rdfg: "http://www.w3.org/2004/03/trix/rdfg-1/", 93 | swp: "http://www.w3.org/2004/03/trix/swp-2/", 94 | rei: "http://www.w3.org/2004/06/rei#", 95 | wairole: "http://www.w3.org/2005/01/wai-rdf/GUIRoleTaxonomy#", 96 | states: "http://www.w3.org/2005/07/aaa#", 97 | wn20schema: "http://www.w3.org/2006/03/wn/wn20/schema/", 98 | httph: "http://www.w3.org/2007/ont/httph#", 99 | act: "http://www.w3.org/2007/rif-builtin-action#", 100 | common: "http://www.w3.org/2007/uwa/context/common.owl#", 101 | dcn: "http://www.w3.org/2007/uwa/context/deliverycontext.owl#", 102 | hard: "http://www.w3.org/2007/uwa/context/hardware.owl#", 103 | java: "http://www.w3.org/2007/uwa/context/java.owl#", 104 | loc: "http://www.w3.org/2007/uwa/context/location.owl#", 105 | net: "http://www.w3.org/2007/uwa/context/network.owl#", 106 | push: "http://www.w3.org/2007/uwa/context/push.owl#", 107 | soft: "http://www.w3.org/2007/uwa/context/software.owl#", 108 | web: "http://www.w3.org/2007/uwa/context/web.owl#", 109 | content: "http://www.w3.org/2008/content#", 110 | vs: "http://www.w3.org/2003/06/sw-vocab-status/ns#", 111 | air: "http://dig.csail.mit.edu/TAMI/2007/amord/air#", 112 | ex: "http://example.org/", 113 | 114 | dc: "http://purl.org/dc/terms/", 115 | dc11: "http://purl.org/dc/elements/1.1/", 116 | dctype: "http://purl.org/dc/dcmitype/", 117 | foaf: "http://xmlns.com/foaf/0.1/", 118 | cc: "http://creativecommons.org/ns#", 119 | opensearch: "http://a9.com/-/spec/opensearch/1.1/", 120 | 'void': "http://rdfs.org/ns/void#", 121 | sioc: "http://rdfs.org/sioc/ns#", 122 | sioca: "http://rdfs.org/sioc/actions#", 123 | sioct: "http://rdfs.org/sioc/types#", 124 | lgd: "http://linkedgeodata.org/vocabulary#", 125 | moat: "http://moat-project.org/ns#", 126 | days: "http://ontologi.es/days#", 127 | giving: "http://ontologi.es/giving#", 128 | lang: "http://ontologi.es/lang/core#", 129 | like: "http://ontologi.es/like#", 130 | status: "http://ontologi.es/status#", 131 | og: "http://opengraphprotocol.org/schema/", 132 | protege: "http://protege.stanford.edu/system#", 133 | dady: "http://purl.org/NET/dady#", 134 | uri: "http://purl.org/NET/uri#", 135 | audio: "http://purl.org/media/audio#", 136 | video: "http://purl.org/media/video#", 137 | gridworks: "http://purl.org/net/opmv/types/gridworks#", 138 | hcterms: "http://purl.org/uF/hCard/terms/", 139 | bio: "http://purl.org/vocab/bio/0.1/", 140 | cs: "http://purl.org/vocab/changeset/schema#", 141 | geographis: "http://telegraphis.net/ontology/geography/geography#", 142 | doap: "http://usefulinc.com/ns/doap#", 143 | daml: "http://www.daml.org/2001/03/daml+oil#", 144 | geonames: "http://www.geonames.org/ontology#", 145 | sesame: "http://www.openrdf.org/schema/sesame#", 146 | cv: "http://rdfs.org/resume-rdf/", 147 | wot: "http://xmlns.com/wot/0.1/", 148 | media: "http://purl.org/microformat/hmedia/", 149 | ctag: "http://commontag.org/ns#" 150 | }); 151 | -------------------------------------------------------------------------------- /source/node.exports.js: -------------------------------------------------------------------------------- 1 | module.exports = js3; 2 | -------------------------------------------------------------------------------- /source/propertymap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Property Map 3 | */ 4 | var propertymap = (function(map) { 5 | return Object.defineProperties(map, { 6 | resolve: { 7 | writable: false, configurable : false, enumerable: false, 8 | value: function(t,l) { 9 | t = t.toString(); 10 | l = Array.isArray(l) && l.length > 0 ? l.concat(Object.keys(this)) : Object.keys(this); 11 | for(i in l) if(this[l[i]].indexOf(t) >= 0) return l[i] + ':' + t; 12 | return t; 13 | } 14 | }, 15 | ambiguities: { 16 | writable: false, configurable : false, enumerable: false, 17 | value: function() { 18 | var _ = this, map = {}, out = []; 19 | Object.keys(this).forEach(function(ont) { 20 | _[ont].forEach(function(prop) { if(!map[prop]) map[prop] = [ont + ':' + prop]; else map[prop].push(ont + ':' + prop) }) 21 | }); 22 | Object.keys(map).forEach(function(prop) { 23 | if(map[prop].length > 1) out = out.concat(map[prop]); 24 | }); 25 | return out; 26 | } 27 | } 28 | }); 29 | })({ 30 | owl: ['allValuesFrom','annotatedProperty','annotatedSource','annotatedTarget','assertionProperty','backwardCompatibleWith', 31 | 'bottomDataProperty','bottomObjectProperty','cardinality','complementOf','datatypeComplementOf','deprecated','differentFrom', 32 | 'disjointUnionOf','disjointWith','distinctMembers','equivalentClass','equivalentProperty','hasKey','hasSelf','hasValue', 33 | 'imports','incompatibleWith','intersectionOf','inverseOf','maxCardinality','maxQualifiedCardinality','members','minCardinality', 34 | 'minQualifiedCardinality','onClass','onDataRange','onDatatype','oneOf','onProperties','onProperty','priorVersion','propertyChainAxiom', 35 | 'propertyDisjointWith','qualifiedCardinality','sameAs','someValuesFrom','sourceIndividual','targetIndividual','targetValue', 36 | 'topDataProperty','topObjectProperty','unionOf','versionInfo','versionIRI','withRestrictions'], 37 | rdf: ['type','subject','predicate','object','value','first','rest'], 38 | rdfs: ['subClassOf','subPropertyOf','comment','label','domain','range','seeAlso','isDefinedBy','member'], 39 | grddl: ['namespaceTransformation','transformation','transformationProperty','result','profileTransformation'], 40 | wdrs: ['text','issuedby','matchesregex','notmatchesregex','hasIRI','tag','notknownto','describedby','authenticate', 41 | 'validfrom','validuntil','logo','sha1sum','certified','certifiedby','supportedby','data_error','proc_error','error_code'], 42 | 43 | dc: ['title','creator','subject','description','publisher','contributor','date','type','format','identifier','source', 44 | 'language','relation','coverage','rights','audience','alternative','tableOfContents','abstract','created','valid', 45 | 'available','issued','modified','extent','medium','isVersionOf','hasVersion','isReplacedBy','replaces','isRequiredBy', 46 | 'requires','isPartOf','hasPart','isReferencedBy','references','isFormatOf','hasFormat','conformsTo','spatial','temporal', 47 | 'mediator','dateAccepted','dateCopyrighted','dateSubmitted','educationLevel','accessRights','bibliographicCitation', 48 | 'license','rightsHolder','provenance','instructionalMethod','accrualMethod','accrualPeriodicity','accrualPolicy'], 49 | dc11: ['title','creator','subject','description','publisher','contributor','date','type','format','identifier','source', 50 | 'language','relation','coverage','rights'], 51 | foaf: ['mbox','mbox_sha1sum','gender','geekcode','dnaChecksum','sha1','based_near','title','nick','jabberID','aimChatID', 52 | 'skypeID','icqChatID','yahooChatID','msnChatID','name','firstName','lastName','givenName','givenname','surname', 53 | 'family_name','familyName','phone','homepage','weblog','openid','tipjar','plan','made','maker','img','depiction', 54 | 'depicts','thumbnail','myersBriggs','workplaceHomepage','workInfoHomepage','schoolHomepage','knows','interest', 55 | 'topic_interest','publications','currentProject','pastProject','fundedBy','logo','topic','primaryTopic','focus', 56 | 'isPrimaryTopicOf','page','theme','account','holdsAccount','accountServiceHomepage','accountName','member', 57 | 'membershipClass','birthday','age','status'], 58 | cc: ['requires','prohibits','jurisdiction','useGuidelines','deprecatedOn','attributionName','license','attributionURL', 59 | 'morePermissions','permits','legalcode'], 60 | 'void': ['statItem','feature','subset','target','sparqlEndpoint','linkPredicate','exampleResource','vocabulary', 61 | 'subjectsTarget','objectsTarget','dataDump','uriLookupEndpoint','uriRegexPattern'], 62 | sioc: ['about','account_of','addressed_to','administrator_of','attachment','avatar','container_of','content','creator_of', 63 | 'earlier_version','email','email_sha1','embeds_knowledge','feed','follows','function_of','has_administrator', 64 | 'has_container','has_creator','has_discussion','has_function','has_host','has_member','has_moderator','has_modifier', 65 | 'has_owner','has_parent','has_reply','has_scope','has_space','has_subscriber','has_usergroup','host_of','id', 66 | 'ip_address','last_activity_date','last_item_date','last_reply_date','later_version','latest_version','link', 67 | 'links_to','member_of','moderator_of','modifier_of','name','next_by_date','next_version','note','num_authors', 68 | 'num_items','num_replies','num_threads','num_views','owner_of','parent_of','previous_by_date','previous_version', 69 | 'related_to','reply_of','scope_of','sibling','space_of','subscriber_of','topic','usergroup_of'], 70 | sioca: ['byproduct','creates','deletes','modifies','object','product','source','uses'], // may remove.. 71 | link: ['listDocumentProperty','uri'], 72 | acl: ['accessControl','accessTo','accessToClass','agent','agentClass','defaultForNew','mode'], 73 | skos: ['inScheme','hasTopConcept','topConceptOf','prefLabel','altLabel','hiddenLabel','notation','note','changeNote', 74 | 'definition','editorialNote','example','historyNote','scopeNote','semanticRelation','broader','narrower','related', 75 | 'broaderTransitive','narrowerTransitive','member','memberList','mappingRelation','broadMatch','narrowMatch', 76 | 'relatedMatch','exactMatch','closeMatch'], 77 | wgs84: ['lat','location','long','alt','lat_long'], 78 | org: ['subOrganizationOf','transitiveSubOrganizationOf','hasSubOrganization ','purpose','hasUnit','unitOf','classification', 79 | 'identifier','linkedTo','memberOf','hasMember','reportsTo','member','organization','role','hasMembership','memberDuring', 80 | 'roleProperty','headOf','remuneration','siteAddress','hasSite','siteOf','hasPrimarySite','hasRegisteredSite','basedAt ', 81 | 'location','originalOrganization','changedBy','resultedFrom','resultingOrganization'], 82 | }); 83 | --------------------------------------------------------------------------------