PageRenderTime 84ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 1ms

/sandbox/semantic-interaction/trunk/lib/vie2/vie2-latest.debug.js

http://iks-project.googlecode.com/
JavaScript | 1711 lines | 1231 code | 202 blank | 278 comment | 163 complexity | 0bb3189b6f7aaf33834da171cccc5b99 MD5 | raw file
Possible License(s): CC-BY-3.0
  1. // VIE² - Vienna IKS Editable Entities
  2. // (c) 2011 Sebastian Germesin, IKS Consortium
  3. // VIE² may be freely distributed under the MIT license.
  4. // (see LICENSE.txt)
  5. // For all details and documentation:
  6. // http://wiki.iks-project.eu/index.php/VIE^2
  7. (function() {
  8. // Initial setup
  9. // -------------
  10. //
  11. // The VIE² library is fully contained inside a VIE2 namespace.
  12. var VIE2 = this.VIE2 = {};
  13. //VIE² is the semantic enrichment layer on top of VIE.
  14. //Its acronym stands for <b>V</b>ienna <b>I</b>KS <b>E</b>ditable <b>E</b>ntities.
  15. //With the help of VIE&sup2;, you can bring entites in your
  16. //content (aka. semantic lifting) and furthermore interact
  17. //with this knowledge in a MVC manner - using Backbone JS models
  18. //and collections. It is important to say that VIE&sup2; helps you to
  19. //automatically annotate data but also let's you enable users
  20. //to change/add/remove entities and their properties at the users
  21. //wish.
  22. //VIE&sup2; has two main principles:
  23. //* Connectors:
  24. // Connecting VIE&sup2; with **backend** services, that
  25. // can either analyse and enrich the content sent to them (e.g., using
  26. // Apache Stanbol or Zemanta), can act as knowledge databases (e.g., DBPedia)
  27. // or as serializer (e.g., RDFa).
  28. //* Mappings:
  29. // In a mapping, a web developer can specify a mapping from ontological entities
  30. // to backbone JS models. The developer can easily add types of entities and
  31. // also default attributes that are automatically filled with the help of the
  32. // available connectors.
  33. // File: util.js
  34. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  35. //
  36. VIE2.Util = {};
  37. // <strong>VIE2.Util.(haystack, needle)</strong>: Removes the *needle* from the *haystack* array.<br>
  38. // <code>return void</code>
  39. VIE2.Util.removeElement = function (haystack, needle) {
  40. //First we check if haystack is indeed an array.
  41. if (jQuery.isArray(haystack)) {
  42. //iterate over the array and check for equality.
  43. jQuery.each(haystack, function (index) {
  44. if (haystack[index] === needle) {
  45. //remove the one element and
  46. haystack.splice(index, 1);
  47. //break the iteration.
  48. return false;
  49. }
  50. });
  51. }
  52. };
  53. // <strong>VIE2.Util.isCurie(str)</strong>: Checks whether the given string is a curie.<br>
  54. // <code>return boolean</code>
  55. VIE2.Util.isCurie = function (str) {
  56. return !str.substring(0, 1).match(/^<$/) && !(str.substring(0, 7).match(/^http:\/\/$/));
  57. }
  58. // <strong>VIE2.Util.isLiteral(str)</strong>: Checks whether the given string is a literal.<br>
  59. // <code>return boolean</code>
  60. VIE2.Util.isLiteral = function (str) {
  61. try {
  62. jQuery.rdf.resource(str, {namespaces: VIE2.namespaces.toObj()});
  63. return false;
  64. } catch (e) {
  65. try {
  66. jQuery.rdf.blank(str, {namespaces: VIE2.namespaces.toObj()});
  67. return false;
  68. } catch (f) {
  69. try {
  70. jQuery.rdf.literal(str, {namespaces: VIE2.namespaces.toObj()});
  71. return true;
  72. } catch (g) {
  73. return false;
  74. }
  75. }
  76. }
  77. };
  78. // <strong>VIE2.Util.isLiteral(str)</strong>: Checks whether the given string is a blank.<br>
  79. // <code>return boolean</code>
  80. VIE2.Util.isBlank = function (str) {
  81. try {
  82. jQuery.rdf.resource(str, {namespaces: VIE2.namespaces.toObj()});
  83. return false;
  84. } catch (h) {
  85. try {
  86. jQuery.rdf.blank(str, {namespaces: VIE2.namespaces.toObj()});
  87. return true;
  88. } catch (i) {
  89. return false;
  90. }
  91. }
  92. };
  93. VIE2.Util.clone = function(src) {
  94. var newObj = {};
  95. for (k in src) {
  96. newObj[k] = src[k];
  97. }
  98. return newObj;
  99. }
  100. VIE2.Namespaces = function(namespaces) {
  101. this.namespaces = (namespaces)? namespaces : {};
  102. this.add = function (k, v) {
  103. //check if we overwrite existing mappings
  104. if (this.containsKey(k) && v !== this.namespaces[k]) {
  105. throw "ERROR: Trying to register namespace prefix mapping (" + k + "," + v + ")!" +
  106. "There is already a mapping existing: '(" + k + "," + this.get(k) + ")'!";
  107. } else {
  108. jQuery.each(this.namespaces, function (k1,v1) {
  109. if (v1 === v && k1 !== k) {
  110. throw "ERROR: Trying to register namespace prefix mapping (" + k + "," + v + ")!" +
  111. "There is already a mapping existing: '(" + k1 + "," + v + ")'!";
  112. }
  113. });
  114. }
  115. this.namespaces[k] = v;
  116. VIE2.globalCache.prefix(k, v);
  117. };
  118. this.get = function (k, v) {
  119. return this.namespaces[k];
  120. };
  121. this.containsKey = function (k) {
  122. return (k in this.namespaces);
  123. };
  124. this.containsValue = function (v) {
  125. jQuery.each(this.namespaces, function (k1,v1) {
  126. if (v1 === v) {
  127. return true;
  128. }
  129. });
  130. return false;
  131. };
  132. this.update = function (k, v) {
  133. this.namespaces[k] = v;
  134. VIE2.globalCache.prefix(k, v);
  135. };
  136. this.remove = function (k, v) {
  137. delete this.namespaces[k];
  138. delete VIE2.globalCache.databank.namespaces[k];
  139. };
  140. this.toObj = function () {
  141. return VIE2.Util.clone(this.namespaces);
  142. }
  143. };// File: core.js
  144. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  145. //
  146. (function($, undefined) {
  147. //VIE&sup2; is implmented as a [jQuery UI widget](http://semantic-interaction.org/blog/2011/03/01/jquery-ui-widget-factory/).
  148. $.widget('VIE2.vie2', {
  149. // default options
  150. options: {
  151. entities : []
  152. },
  153. //<strong>_create()</strong>: The private method **_create():** is called implicitly when
  154. //calling .vie2(); on any jQuery object.
  155. _create: function () {
  156. //automatically scans for xmlns attributes in the **html** element
  157. //and adds them to the global VIE2.namespaces object
  158. $.each(jQuery('html').xmlns(), function (k, v) {
  159. var vStr = v.toString();
  160. if (!VIE2.namespaces.containsKey(k) && !VIE2.namespaces.containsValue(vStr)) {
  161. VIE2.namespaces.add(k, vStr);
  162. }
  163. });
  164. //automatically scans for xmlns attributes in the **given** element
  165. //and adds them to the global VIE2.namespaces object
  166. try {
  167. $.each(this.element.xmlns(), function(k, v) {
  168. var vStr = v.toString();
  169. if (!VIE2.namespaces.containsKey(k) && !VIE2.namespaces.containsValue(vStr)) {
  170. VIE2.namespaces.add(k, vStr);
  171. }
  172. });
  173. } catch (ex) {
  174. //needs to be ignored when called on $(document);
  175. if (this.element.get(0) !== document) {
  176. VIE2.log("warn", "VIE2.core#create()", "Could not retrieve namespaces from element: '" + e + "'!");
  177. }
  178. }
  179. return this;
  180. },
  181. //<strong>analyze(callback,[options])</strong>: The analyze() method sends the element to all connectors and lets
  182. //them analyze the content. The connectors' methods are asynchronously called and once all connectors
  183. //returned the found enrichments in the form of **$.rdf objects**, the *callback* method is
  184. //executed (in the scope of the callback function, *this* refers to the given element).<br />
  185. //The returned enrichments are written into the global Cache of VIE&sup2; (VIE2.globalCache).<br />
  186. //Furthermore, each found subject in the returned knowledge is checked whether there is a type-mapping to
  187. //backbone JS available and if so, the entity is added to the corresponding backbone collection(s).
  188. //*options* can contain a 'connectors' field. If so, only these connectors will be used
  189. //for the analysis. If not specified, all connectors are used.
  190. analyze: function (callback, options) {
  191. if (!options) { options = {};}
  192. var that = this;
  193. //analyze() does not actually need a callback method, but it is usually good to use it
  194. if (callback === undefined) {
  195. VIE2.log("warn", "VIE2.core#analyze()", "No callback method specified!");
  196. }
  197. VIE2.log("info", "VIE2.core#analyze()", "Started.");
  198. //as the connectors work asynchronously, we need a queue to listen if all connectors are finished.
  199. var connectorQueue = [];
  200. $.each(VIE2.connectors, function () {
  201. //fill queue of connectors with 'id's to have an overview of running connectors.
  202. //this supports the asynchronous calls.
  203. if (options.connectors) {
  204. if (options.connectors.indexOf(this.id) !== -1) {
  205. connectorQueue.push(this.id);
  206. }
  207. } else {
  208. connectorQueue.push(this.id);
  209. }
  210. });
  211. //iterate over all connectors
  212. $.each(VIE2.connectors, function () {
  213. //the connector's success callback method
  214. var successCallback = function (elem) {
  215. return function (rdf) {
  216. VIE2.log("info", "VIE2.core#analyze()", "Received RDF annotation from connector '" + this.id + "'!");
  217. //we add all namespaces to the rdfQuery object.
  218. //Attention: this might override namespaces that were added by the connector!
  219. //but needed to keep consistency through VIE&sup2;.
  220. $.each(VIE2.namespaces.toObj(), function(k, v) {
  221. rdf.prefix(k, v);
  222. });
  223. rdf.databank.triples().each(function () {
  224. //add all triples to the global cache!
  225. VIE2.globalCache.add(this);
  226. });
  227. //register all subjects as backbone model
  228. $.each(rdf.databank.subjectIndex, function (subject, v) {
  229. var subjStr = subject.toString();
  230. if (that.options.entities.indexOf(subjStr) === -1) {
  231. that.options.entities.push(subjStr);
  232. }
  233. if (!VIE.EntityManager.getBySubject(subjStr)) {
  234. VIE2.log("info", "VIE2.core#analyze()", "Register new entity (" + subjStr + ")!");
  235. VIE2.createEntity({
  236. id : subjStr
  237. }, {backend: true});
  238. } else {
  239. //inform client(s) that new data is possibly available
  240. VIE.EntityManager.getBySubject(subjStr).change();
  241. }
  242. });
  243. VIE2.Util.removeElement(connectorQueue, this.id);
  244. //everytime we receive annotations from each connector, we remove the connector's id from the
  245. //queue and check whether the queue is empty.
  246. if (connectorQueue.length === 0) {
  247. //if the queue is empty, all connectors have successfully returned and we can execute the
  248. //callback function.
  249. VIE2.log("info", "VIE2.core#analyze()", "Finished! Global Cache holds now " + VIE2.globalCache.databank.triples().length + " triples!");
  250. VIE2.log("info", "VIE2.core#analyze()", "Finished! Local element holds now " + that.options.entities.length + " entities!");
  251. //provide a status field in the callback object: status = {'ok', 'error'};
  252. if (callback) {
  253. callback.call(elem);
  254. }
  255. }
  256. };
  257. } (that.element);
  258. //the connector's error callback method
  259. var errorCallback = function (reason) {
  260. VIE2.log("error", "VIE2.core#analyze()", "Connector (" + this.id + ") returned with the following error: '" + reason + "'!");
  261. VIE2.Util.removeElement(connectorQueue, this.id);
  262. };
  263. //check if we may need to filter for the connector
  264. if (options.connectors) {
  265. if (options.connectors.indexOf(this.id) !== -1) {
  266. //start analysis with the connector.
  267. VIE2.log("info", "VIE2.core#analyze()", "Starting analysis with connector: '" + this.id + "'!");
  268. this.analyze(that.element, {
  269. success: successCallback,
  270. error: errorCallback
  271. });
  272. }
  273. else {
  274. VIE2.log("info", "VIE2.core#analyze()", "Will not use connector " + this.id + " as it is filtered!");
  275. }
  276. } else {
  277. //start analysis with the connector.
  278. VIE2.log("info", "VIE2.core#analyze()", "Starting analysis with connector: '" + this.id + "'!");
  279. this.analyze(that.element, {
  280. success: successCallback,
  281. error: errorCallback
  282. });
  283. }
  284. });
  285. },
  286. //<strong>uris()</strong>: Returns a list of all uris, that are within the scope of the current element!
  287. uris: function () {
  288. return this.options.entities;
  289. },
  290. //<strong>addUri()</strong>: Manually adds a URI (string) to the list of entities within the scope of the current element!
  291. addUri: function (uri) {
  292. this.options.entities.push(uri);
  293. },
  294. //<strong>copy(tar)</strong>: Copies all local knowledge to the target element(s).
  295. //Basically calls: <pre>
  296. //$(tar).vie2().vie2('option', 'entities', this.options.entities);
  297. //</pre>
  298. copy: function (tar) {
  299. //copy all knowledge from src to target
  300. var that = this;
  301. if (!tar) {
  302. VIE2.log("warn", "VIE2.core#copy()", "Invoked 'copy()' without target element!");
  303. return;
  304. }
  305. VIE2.log("info", "VIE2.core#copy()", "Start.");
  306. VIE2.log("info", "VIE2.core#copy()", "Found " + this.options.entities.length + " entities for source.");
  307. jQuery(tar).vie2().vie2('option', 'entities', this.options.entities);
  308. VIE2.log("info", "VIE2.core#copy()", "Finished.");
  309. VIE2.log("info", "VIE2.core#copy()", "Target element has now " + jQuery(tar).vie2('option', 'entities') + " entities.");
  310. return this;
  311. },
  312. //<strong>clear()</strong>: Clears the local entities.
  313. clear: function () {
  314. this.options.entities = [];
  315. return this;
  316. }
  317. });
  318. }(jQuery));
  319. //The global <strong>VIE2 object</strong>. If VIE2 is already defined, the
  320. //existing VIE2 object will not be overwritten so that the
  321. //defined object is preserved.
  322. if (typeof VIE2 === 'undefined' || !VIE2) {
  323. VIE2 = {};
  324. }
  325. //<strong>VIE2.basename</strong>: The basis namespace of the VIE2 schema.
  326. VIE2.baseNamespace = 'http://schema.org/';
  327. //<strong>VIE2.namespaces</strong>: This object contains all namespaces known to VIE2.
  328. //There are currently *one* default namespace:
  329. // iks -> http://www.iks-ontology.net/
  330. // owl -> http://www.w3.org/2002/07/owl#
  331. //Namespaces can be overridden directly using VIE2.namespaces.update(k, v) but
  332. //are parsed from the &lt;html> tag's xmlns: attribute anyway during initialization.
  333. VIE2.namespaces = new VIE2.Namespaces({
  334. 'owl' : 'http://www.w3.org/2002/07/owl#',
  335. 'xsd' : 'http://www.w3.org/2001/XMLSchema#'
  336. });
  337. //<strong>VIE2.globalCache</strong>: The variable **globalCache** stores all knowledge in
  338. //triples that were retrieved and annotated so far in one *rdfQuery object*. Though it is
  339. //available via VIE2.globalCache, it is highly discouraged to access it directly.
  340. VIE2.globalCache = jQuery.rdf({namespaces: VIE2.namespaces.toObj()});
  341. VIE2.addToCache = function (uri, prop, val) {
  342. var triple = jQuery.rdf.triple(uri, prop, val, {namespaces: VIE2.namespaces.toObj()});
  343. VIE2.log("info", "VIE2.addToCache()", "Adding triple to cache!");
  344. VIE2.log("info", "VIE2.addToCache()", "Global Cache now holds " + VIE2.globalCache.databank.triples().length + " triples!");
  345. VIE2.globalCache.add(triple);
  346. VIE2.log("info", "VIE2.addToCache()", "Global Cache now holds " + VIE2.globalCache.databank.triples().length + " triples!");
  347. };
  348. //<strong>VIE2.getPropFromCache(parent, uri, prop)</strong>: Retrieve properties from the given
  349. // *uri* directly from the global Cache.
  350. VIE2.getPropFromCache = function (parent, uri, prop) {
  351. //initialize collection
  352. var Collection = VIE2.ObjectCollection.extend({
  353. uri : uri,
  354. property : prop,
  355. parent : parent
  356. });
  357. var ret = new Collection();
  358. VIE2.globalCache
  359. .where(jQuery.rdf.pattern(uri, prop, '?object', {namespaces: VIE2.namespaces.toObj()}))
  360. .each(function () {
  361. if (this.object.type) {
  362. if (this.object.type === 'literal') {
  363. var inst = VIE2.createLiteral(this.object.representation ? this.object.representation : this.object.value, {lang: this.object.lang, datatype: this.object.datatype, backend:true, silent:true});
  364. ret.add(inst, {backend:true, silent:true});
  365. } else if (this.object.type === 'uri' || this.object.type === 'bnode') {
  366. var entity = VIE.EntityManager.getBySubject(this.object.toString());
  367. if (entity) {
  368. ret.add(entity, {backend:true, silent:true});
  369. }
  370. else {
  371. var inst = VIE2.createResource(this.object.value.toString(), {backend:true, silent:true});
  372. ret.add(inst, {backend:true, silent:true});
  373. }
  374. }
  375. }
  376. });
  377. return ret;
  378. };
  379. VIE2.removeFromCache = function (uri, prop, val) {
  380. var pattern = jQuery.rdf.pattern(
  381. uri,
  382. (prop)? prop : '?x',
  383. (val)? val : '?y',
  384. {namespaces: VIE2.namespaces.toObj()});
  385. VIE2.log("info", "VIE2.removeFromCache()", "Removing triples that match: '" + pattern.toString() + "'!");
  386. VIE2.log("info", "VIE2.removeFromCache()", "Global Cache now holds " + VIE2.globalCache.databank.triples().length + " triples!");
  387. VIE2.globalCache
  388. .where(pattern)
  389. .remove(pattern);
  390. VIE2.log("info", "VIE2.removeFromCache()", "Global Cache now holds " + VIE2.globalCache.databank.triples().length + " triples!");
  391. };
  392. //<strong>VIE2.clearCache()</strong>: Static method to clear the global Cache.
  393. VIE2.clearCache = function () {
  394. VIE2.globalCache = jQuery.rdf({namespaces: VIE2.namespaces.toObj()});
  395. };
  396. //<strong>VIE2.lookup(uri, props, callback)</strong>: The query function supports querying for properties. The uri needs
  397. //to be of type <code>jQuery.rdf</code> object or a simple string and the property is either an array of strings
  398. //or a simple string. The function iterates over all connectors that have <code>query()</code>
  399. //implemented and collects data in an object.
  400. //The callback retrieves an object with the properties as keys and an array of results as their corresponding values.
  401. VIE2.lookup = function (uri, props, callback) {
  402. VIE2.log("info", "VIE2.lookup()", "Start ('" + uri + "', '" + props + "')!");
  403. if (uri === undefined || typeof uri !== 'string' || props === undefined) {
  404. VIE2.log("warn", "VIE2.lookup()", "Invoked 'lookup()' with wrong/undefined argument(s)!");
  405. if (callback) {
  406. callback.call(uri, ret);
  407. }
  408. return;
  409. }
  410. if (!jQuery.isArray(props)) {
  411. VIE2.lookup(uri, [ props ], callback);
  412. return;
  413. }
  414. //initialize the returning object
  415. var ret = {};
  416. for (var i=0; i < props.length; i++) {
  417. ret[props[i]] = [];
  418. }
  419. var connectorQueue = [];
  420. jQuery.each(VIE2.connectors, function () {
  421. //fill queue of connectors with 'id's to have an overview of running connectors.
  422. //this supports the asynchronous calls.
  423. connectorQueue.push(this.id);
  424. });
  425. //look up for properties in the connectors that
  426. //implement/overwrite the query() method
  427. jQuery.each(VIE2.connectors, function () {
  428. var c = function (uri, ret, callback) {
  429. return function (data) {
  430. try {
  431. VIE2.log("info", "VIE2.lookup()", "Received query information from connector '" + this.id + "' for uri '" + uri + "'!");
  432. jQuery.each(data, function (k, v) {
  433. for (var i = 0; i < v.length; i++) {
  434. var triple = jQuery.rdf.triple(uri, k, v[i], {namespaces: VIE2.namespaces.toObj()});
  435. VIE2.globalCache.add(triple);
  436. }
  437. });
  438. VIE2.Util.removeElement(connectorQueue, this.id);
  439. if (connectorQueue.length === 0) {
  440. //if the queue is empty, all connectors have successfully returned and we can call the
  441. //callback function.
  442. jQuery.each(ret, function(k){
  443. VIE2.globalCache.where(uri + ' ' + k + ' ?x').each(function(){
  444. var valStr = this.x.toString();
  445. if (ret[k].indexOf(valStr) === -1) {
  446. ret[k].push(valStr);
  447. }
  448. });
  449. });
  450. VIE2.log("info", "VIE2.lookup()", "Global Cache now holds " + VIE2.globalCache.databank.triples().length + " triples!");
  451. if (callback) {
  452. callback.call(uri, ret);
  453. }
  454. }
  455. } catch (e) {
  456. }
  457. };
  458. }(uri, ret, callback);
  459. this.query(uri, props, c);
  460. });
  461. };
  462. //<strong>VIE2.serialize</strong>: TODO document me
  463. VIE2.serialize = function (model, options) {
  464. if (!options)
  465. options = {};
  466. VIE2.log("info", "VIE2.Backbone#serialize(" + model.get('id') + ")", "Start serialization!");
  467. var connectorQueue = [];
  468. jQuery.each(VIE2.connectors, function(){
  469. //fill queue of connectors with 'id's to have an overview of running connectors.
  470. //this supports the asynchronous calls.
  471. if (options.connectors) {
  472. if (options.connectors.indexOf(this.id) !== -1) {
  473. connectorQueue.push(this.id);
  474. }
  475. }
  476. else {
  477. connectorQueue.push(this.id);
  478. }
  479. });
  480. //iterate over all connectors
  481. jQuery.each(VIE2.connectors, function() {
  482. //the connector's success callback method
  483. var successCallback = function(){
  484. VIE2.log("info", "VIE2.serialize(" + model.get('id') + ")", "Successfully serialized the annotation!");
  485. VIE2.Util.removeElement(connectorQueue, this.id);
  486. };
  487. var errorCallback = function(reason) {
  488. VIE2.log("error", "VIE2.serialize(" + model.get('id') + ")", "");
  489. VIE2.Util.removeElement(connectorQueue, this.id);
  490. };
  491. //check if we may need to filter for the connector
  492. if (options.connectors) {
  493. if (options.connectors.indexOf(this.id) !== -1) {
  494. //start analysis with the connector.
  495. VIE2.log("info", "VIE2.serialize(" + model.get('id') + ")", "Starting serialization with connector: '" + this.id + "'!");
  496. if (model instanceof VIE2.Entity) {
  497. var triple = model.get('a').at(0).tojQueryRdfTriple(); //TODO!
  498. } else {
  499. var triple = model.tojQueryRdfTriple(); //TODO!
  500. }
  501. this.serialize(triple, jQuery.extend(options, {
  502. success: successCallback,
  503. error: errorCallback
  504. }));
  505. }
  506. else {
  507. VIE2.log("info", "VIE2.serialize(" + model.get('id') + ")", "Will not use connector " + this.id + " as it is filtered!");
  508. }
  509. }
  510. else {
  511. //start analysis with the connector.
  512. VIE2.log("info", "VIE2.serialize(" + model.get('id') + ")", "Starting serialization with connector: '" + this.id + "'!");
  513. //TODO: toTriple(this);
  514. this.serialize(this, jQuery.extend(options, {
  515. success: successCallback,
  516. error: errorCallback
  517. }));
  518. }
  519. });
  520. };
  521. //<strong>VIE2.types</strong>: Contains for all registered types (type.id is the key), the
  522. //following items:<br/>
  523. //* VIE2.types[id].type -> the type object itself
  524. //* VIE2.types[id].collection -> the Backbone.js collection, that has the type registered.
  525. VIE2.types = {};
  526. //<strong>VIE2.registerType(type)</strong>: Static method to register a type (is automatically called
  527. //during construction of type class. This allocates an object in *VIE2.types[type.id]*.
  528. VIE2.registerType = function (type) {
  529. //first check if there is already
  530. //a type with 'type.id' registered
  531. if (!VIE2.types[type.id]) {
  532. var Collection = VIE2.EntityCollection.extend({model: VIE2.Entity});
  533. VIE2.types[type.id] = type;
  534. //Person -> VIE2.Persons
  535. VIE2[type.sid + "s"] = new Collection();
  536. //trigger filling of collections!
  537. for (var i = 0; i < VIE2.entities.length; i++) {
  538. VIE2.entities.at(i).searchCollections();
  539. }
  540. } else {
  541. VIE2.log("warn", "VIE2.registerType()", "Did not register type, as there is" +
  542. "already a type with the same id registered.");
  543. }
  544. };
  545. VIE2.getType = function (typeId) {
  546. if (typeId.indexOf('<') === 0) {
  547. return VIE2.types[typeId];
  548. }
  549. else if (typeId.indexOf(VIE2.baseNamespace) === 0) {
  550. return VIE2.getType('<' + typeId + '>');
  551. }
  552. else {
  553. return VIE2.getType('<' + VIE2.baseNamespace + typeId + '>');
  554. }
  555. return undefined;
  556. }
  557. //<strong>VIE2.unregisterType(typeId)</strong>: Unregistering of types.
  558. // There is currently no usecase for that, but it wasn't that hard to implement ;)
  559. VIE2.unregisterType = function (typeId) {
  560. delete VIE2.types[typeId];
  561. delete VIE2[typeId + "s"];
  562. };
  563. //<strong>VIE2.connectors</strong>: Static object of all registered connectors.
  564. VIE2.connectors = {};
  565. //<strong>VIE2.registerConnector(connector)</strong>: Static method to register a connector (is automatically called
  566. //during construction of connector class. If set, inserts connector-specific namespaces to the known Caches.
  567. VIE2.registerConnector = function (connector) {
  568. //first check if there is already
  569. //a connector with 'connector.id' registered
  570. if (!VIE2.connectors[connector.id]) {
  571. VIE2.connectors[connector.id] = connector;
  572. } else {
  573. VIE2.log("warn", "VIE2.registerConnector()", "Did not register connector, as there is" +
  574. "already a connector with the same id registered.");
  575. }
  576. };
  577. //<strong>VIE2.unregisterConnector(connectorId)</strong>: Unregistering of connectors. There is currently
  578. //no usecase for that, but it wasn't that hard to implement ;)
  579. VIE2.unregisterConnector = function (connectorId) {
  580. VIE2.connectors[connector.id] = undefined;
  581. };
  582. VIE2.logLevels = ["info", "warn", "error"];
  583. //<strong>VIE2.log(level, component, message)</strong>: Static convenience method for logging.
  584. VIE2.log = function (level, component, message) {
  585. if (VIE2.logLevels.indexOf(level) > -1) {
  586. switch (level) {
  587. case "info":
  588. console.info([component, message]);
  589. break;
  590. case "warn":
  591. console.warn([component, message]);
  592. break;
  593. case "error":
  594. console.error([component, message]);
  595. break;
  596. }
  597. }
  598. };
  599. // File: collection.js
  600. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  601. //
  602. //just for convenience, should be removed in a later revision
  603. VIE.EntityManager.initializeCollection();
  604. //<strong>VIE2.EntityCollection</strong>: TODO: document me
  605. VIE2.EntityCollection = VIE.RDFEntityCollection.extend({
  606. //overwrite the internal _add method
  607. _add: function (model, opts) {
  608. if (!opts) { opts = {};}
  609. if (this.get(model.get('id'))) {
  610. return;
  611. }
  612. if (!model.isEntity()) {
  613. return;
  614. }
  615. VIE.RDFEntityCollection.prototype._add.call(this, model, opts);
  616. //if the annotation does *not* come from the analyze() method
  617. //it comes from the user and hence,
  618. //we need to add the subject to the internal triple store.
  619. if (!opts.backend) {
  620. var type = model.get('a');
  621. if (type.length > 0) {
  622. type = type.at(0).value();
  623. } else {
  624. type = VIE2.getType('Thing').id //TODO: hack!
  625. }
  626. var triple = jQuery.rdf.triple(
  627. model.get('id'),
  628. 'a',
  629. type,
  630. {namespaces: VIE2.namespaces.toObj()}
  631. );
  632. VIE2.globalCache.add(triple);
  633. }
  634. },
  635. _remove: function (model, opts) {
  636. if (!opts) { opts = {};}
  637. if (model) {
  638. //when removing the model from this collection, that means
  639. //that we remove all corresponding data from the cache as well.
  640. if (VIE2.entities === this) {
  641. VIE2.removeFromCache(model.get('id'));
  642. delete VIE2.globalCache.databank.subjectIndex[model.get('id')]; //HACK: rdfQuery does not remove an entity from its internal DB when no other triples are present
  643. //also remove from all other collections!
  644. jQuery.each(VIE2.mappings, function(k, v){
  645. v.collection.remove(model);
  646. });
  647. VIE.EntityManager.entities.remove(model, opts);
  648. model.destroy();
  649. }
  650. VIE.RDFEntityCollection.prototype._remove.call(this, model, opts);
  651. }
  652. }
  653. });
  654. //<strong>VIE2.entities</strong>: Is a global Backbone JS Collection
  655. //which stores all models of all known entities.
  656. VIE2.entities = new VIE2.EntityCollection();
  657. //<strong>VIE2.ObjectCollection</strong>: TODO: document me
  658. VIE2.ObjectCollection = Backbone.Collection.extend({
  659. _add: function (model, opts) {
  660. //TODO: propagate event to parent model
  661. if (!opts) { opts = {};}
  662. //adding a back-reference to the model
  663. model.collection = this;
  664. Backbone.Collection.prototype._add.call(this, model, opts);
  665. if (!opts.backend) {
  666. var triple = jQuery.rdf.triple(
  667. this.uri,
  668. this.property,
  669. model.tojQueryRdf(),
  670. {namespaces: VIE2.namespaces.toObj()}
  671. );
  672. VIE2.globalCache.add(triple);
  673. if (this.parent) {
  674. this.parent.change();
  675. this.parent.trigger('change:' + this.property);
  676. }
  677. }
  678. },
  679. _remove: function (model, opts) {
  680. if (model) {
  681. //remove corresponding triples
  682. VIE2.removeFromCache(this.uri, this.property, model.tojQueryRdf());
  683. Backbone.Collection.prototype._remove.call(this, model, opts);
  684. //update parent entity
  685. this.parent.trigger('change:' + this.property);
  686. }
  687. },
  688. getByValue: function (value, opts) {
  689. if (!opts) { opts = {}; }
  690. var found;
  691. $.each(this.models, function (i, model) {
  692. if (model.get('value') === value) {
  693. if (opts.lang) {
  694. if (opts.lang === model.get('lang')) {
  695. found = model;
  696. return false;
  697. }
  698. } else if (opts.datatype) {
  699. if (opts.datatype === model.get('datatype')) {
  700. found = model;
  701. return false;
  702. }
  703. } else {
  704. found = model;
  705. return false;
  706. }
  707. }
  708. });
  709. return found;
  710. }
  711. });
  712. // File: model.js
  713. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  714. //
  715. //<strong>VIE2.Entity</strong>: The parent backbone entity class for all other entites.
  716. //Inherits from VIE.RDFEntity.
  717. VIE2.Entity = VIE.RDFEntity.extend({
  718. initialize: function (attrs, opts) {
  719. //if the type has changed, we need to search through the
  720. //types if the model needs to be inserted.
  721. this.bind('change:a', this.searchCollections);
  722. if (!opts) { opts = {};}
  723. if (!opts.backend) {
  724. for (var attr in attrs) {
  725. var val = attrs[attr];
  726. if (attr !== 'id') {
  727. var valArr;
  728. if (!jQuery.isArray(val)) {
  729. valArr = [ val ];
  730. } else {
  731. valArr = val;
  732. }
  733. for (var i = 0; i < valArr.length; i++) {
  734. var triple = jQuery.rdf.triple(this.get('id'), attr, valArr[i], {
  735. namespaces: VIE2.namespaces.toObj()
  736. });
  737. VIE2.globalCache.add(triple);
  738. }
  739. }
  740. }
  741. }
  742. //in any case, we query all connectors for the types of the entity.
  743. VIE2.lookup(this.get('id'), ['a', 'sameAs'], function (m) {
  744. return function () {
  745. m.trigger('change:a');
  746. m.trigger('change:sameAs');
  747. };
  748. }(this));
  749. },
  750. searchCollections: function () {
  751. var self = this;
  752. var types = VIE2.getPropFromCache(this, this.get('id'), 'a');
  753. for (var t = 0; t < types.length; t++) {
  754. var type = VIE2.getType(types.at(t).value());
  755. if (type) {
  756. if (!VIE2[type.sid + "s"].get(self.id)) {
  757. VIE2[type.sid + "s"].add(self, {backend: true});
  758. VIE2.log("info", "VIE2.Entity.searchCollections()", "Added entity '" + self.get('id') + "' to collection of type '" + type.id + "'!");
  759. }
  760. }
  761. }
  762. },
  763. //overwritten to directly access the global Cache
  764. get: function (attr) {
  765. if (attr === 'id') {
  766. return VIE.RDFEntity.prototype.get.call(this, attr);
  767. }
  768. return VIE2.getPropFromCache(this, this.get('id'), attr);
  769. },
  770. isEntity: function () {
  771. return true;
  772. }
  773. });
  774. VIE2.createEntity = function (type, attrs, opts) {
  775. if (!type) {
  776. type = VIE2.getType("Thing");
  777. } else if (typeof type === 'string') {
  778. type = VIE2.getType(type);
  779. }
  780. if (!attrs) {
  781. attrs = {};
  782. }
  783. if (!opts) {
  784. opts = {};
  785. }
  786. if (!('id' in attrs)) {
  787. attrs.id = $.rdf.blank('[]').toString();
  788. }
  789. //setting the type of the entity
  790. attrs.a = type.id;
  791. //create the model
  792. var model = new VIE2.Entity(attrs, opts);
  793. //automatically adds model to global VIE2.entities bucket
  794. VIE2.entities.add(model, opts);
  795. return model;
  796. };
  797. VIE2.Object = Backbone.Model.extend({
  798. initialize: function (attrs, opts) {
  799. if (!opts) { opts = {};}
  800. this.isLiteral = (opts.isLiteral)? opts.isLiteral : false;
  801. },
  802. set: function (attrs, opts) {
  803. if (!opts) { opts = {};}
  804. if (!attrs) return this;
  805. var oldValue = this.attributes['value'];
  806. var newValue = attrs['value'];
  807. if (oldValue !== undefined && oldValue !== newValue) {
  808. if (this.collection) {
  809. //remove old triple, add new triple!
  810. VIE2.removeFromCache(this.collection.uri,
  811. this.collection.property,
  812. oldValue);
  813. var triple = jQuery.rdf.triple(
  814. this.collection.uri,
  815. this.collection.property,
  816. this.tojQueryRdf(newValue),
  817. {namespaces: VIE2.namespaces.toObj()});
  818. VIE2.globalCache.add(triple);
  819. this.collection.parent.trigger('change:a');
  820. }
  821. }
  822. return Backbone.Model.prototype.set.call(this, attrs, opts);
  823. },
  824. tojQueryRdf: function (val) {
  825. if (this.isLiteral) {
  826. return this._tojQueryRdfLit(val);
  827. } else {
  828. return this._tojQueryRdfRes(val);
  829. }
  830. },
  831. _tojQueryRdfLit: function (val) {
  832. var lang = (this.get('lang')) ? this.get('lang') : undefined;
  833. var datatype = (this.get('datatype')) ? this.get('datatype') : undefined;
  834. if (lang !== undefined && datatype !== undefined) {
  835. datatype = undefined;
  836. }
  837. var val = (val)? val : this.get('value');
  838. var lit = jQuery.rdf.literal(
  839. val, {
  840. namespaces: VIE2.namespaces.toObj(),
  841. datatype: datatype,
  842. lang: lang
  843. });
  844. return lit;
  845. },
  846. _tojQueryRdfRes: function (val) {
  847. val = (val)? val : this.get('value');
  848. if (val.indexOf('_:') === 0) {
  849. return jQuery.rdf.blank(val);
  850. } else {
  851. return jQuery.rdf.resource(
  852. val, {
  853. namespaces: VIE2.namespaces.toObj()
  854. });
  855. }
  856. },
  857. tojQueryRdfTriple: function () {
  858. var triple = jQuery.rdf.triple(this.collection.uri + " " + this.collection.property + " " + this.tojQueryRdf().toString(), {
  859. namespaces: VIE2.namespaces.toObj()
  860. });
  861. return triple;
  862. },
  863. //for convenience
  864. value: function () {
  865. return this.get('value');
  866. },
  867. //for convenience
  868. datatype: function () {
  869. return this.get('datatype');
  870. },
  871. //for convenience
  872. lang: function () {
  873. return this.get('lang');
  874. },
  875. isResource: function () {
  876. return this.get('isResource');
  877. },
  878. isLiteral: function () {
  879. return this.get('isLiteral');
  880. },
  881. isEntity: function () {
  882. return false;
  883. }
  884. });
  885. VIE2.createLiteral = function (value, opts) {
  886. if (!opts) { opts = {};}
  887. return new VIE2.Object({
  888. 'value': value,
  889. isResource: false,
  890. lang: opts.lang,
  891. datatype: opts.datatype,
  892. }, jQuery.extend(opts, {isLiteral: true}));
  893. };
  894. VIE2.createResource = function (value, opts) {
  895. if (!opts) { opts = {};}
  896. return new VIE2.Object({
  897. 'value': (value.indexOf('<') === 0 || value.indexOf('_:') === 0)? value : '<' + value + '>',
  898. isLiteral: false,
  899. isResource: true
  900. }, jQuery.extend(opts, {isLiteral: false}));
  901. };
  902. // File: connector.js
  903. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  904. //
  905. //The Connector class.
  906. //So far, a connector has two main functionalities:
  907. //1. analyze: Applies semantic lifting of the passed object
  908. //2. query: Queries for properties of the given entity uri
  909. //A connector needs an **id** of type string and an optional
  910. //options object. The only option that is used in VIE&sup2; so far
  911. //is options['namespaces'], which adds connector-specific
  912. //namespaces to VIE&sup2;. However, you may add other options,
  913. //specific for this connector here.
  914. //After registration, they can be changed with:
  915. //<pre>
  916. // VIE2.connectors['<id>'].options({...});
  917. //</pre>
  918. VIE2.Connector = function(id, options) {
  919. //A connector needs an id of type string.
  920. if (id === undefined || typeof id !== 'string') {
  921. throw "The connector constructor needs an 'id' of type 'string'!";
  922. }
  923. this.id = id;
  924. this._options = (options)? options : {};
  925. if (this._options.namespaces) {
  926. jQuery.each(this._options.namespaces, function (k, v) {
  927. VIE2.namespaces.add(k, v);
  928. });
  929. }
  930. //registers the connector within VIE&sup2;. Also adds the given namespaces
  931. //to the global cache in VIE&sup2;.
  932. VIE2.registerConnector(this);
  933. };
  934. //setter and getter for options
  935. VIE2.Connector.prototype.options = function(values) {
  936. if (typeof values === 'string') {
  937. //return the values
  938. return this._options[values];
  939. }
  940. else if (typeof values === 'object') {
  941. //extend options
  942. jQuery.extend(true, this._options, values);
  943. } else {
  944. //get options
  945. return this._options;
  946. }
  947. };
  948. //TODO: document me
  949. VIE2.Connector.prototype.analyze = function (object, options) {
  950. //VIE2.log("info", "VIE2.Connector(" + this.id + ")#analyze()", "Not overwritten!");
  951. if (options && options.success) {
  952. options.success.call(this, jQuery.rdf());
  953. }
  954. };
  955. //TODO: document me
  956. VIE2.Connector.prototype.query = function (uri, properties, callback) {
  957. //VIE2.log("info", "VIE2.Connector(" + this.id + ")#query()", "Not overwritten!");
  958. callback.call(this, {});
  959. };
  960. VIE2.Connector.prototype.serialize = function (rdf, options) {
  961. //VIE2.log("info", "VIE2.Connector(" + this.id + ")#serialize()", "Not overwritten!");
  962. if (options && options.success) {
  963. options.success.call(this, {});
  964. }
  965. };// File: attribute.js
  966. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  967. //
  968. // An <code>Attribute</code> is a format to map ontological entity attributes into the
  969. // VIE&sup2; world - and hence, Backbone.js models.
  970. VIE2.Attribute = function(type, id, datatype, namespaces) {
  971. if (type && typeof type === 'string') {
  972. type = VIE2.getType(type);
  973. }
  974. if (type === undefined) {
  975. throw "The attribute constructor needs a 'type'!";
  976. }
  977. if (id === undefined) {
  978. throw "The attribute constructor needs an 'id'!";
  979. }
  980. if (typeof id !== 'string') {
  981. throw "The attribute constructor needs an 'id' of type 'string'!";
  982. }
  983. if (!datatype) {
  984. throw "The attribute constructor needs a 'datatype' of type 'string', e.g., 'Thing'!";
  985. }
  986. this.id = (VIE2.baseNamespace)? '<' + VIE2.baseNamespace + id + '>' : id;
  987. this.sid = id;
  988. this.type = type;
  989. this.datatype = datatype;
  990. //add given namespaces to VIE&sup2;'s namespaces
  991. this.namespaces = (namespaces)? namespaces : {};
  992. this.validateEntityType = function (type) {
  993. return type.id === this.id;
  994. };
  995. };// File: type.js
  996. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  997. //
  998. // A <code>Type</code> is a format to map ontological entity types into the VIE&sup2; world
  999. // - and hence, Backbone.js models.
  1000. VIE2.Type = function(id, parent, attrs, namespaces) {
  1001. if (id === undefined) {
  1002. throw "The type constructor needs an 'id'!";
  1003. }
  1004. if (typeof id !== 'string') {
  1005. throw "The type constructor needs an 'id' of type 'string'!";
  1006. }
  1007. if (parent !== undefined && typeof parent !== 'string') {
  1008. throw "The type constructor needs a 'parent' of type 'string', e.g., 'Thing'!";
  1009. }
  1010. if (attrs === undefined) {
  1011. throw "The type constructor needs 'attributes'!";
  1012. }
  1013. if (VIE2.getType(id)) {
  1014. // singleton!
  1015. return VIE2.getType(id);
  1016. }
  1017. this.id = (VIE2.baseNamespace)? '<' + VIE2.baseNamespace + id + '>' : id;
  1018. this.sid = id;
  1019. this._parent = parent;
  1020. this._children = [];
  1021. //add given namespaces to VIE&sup2;'s namespaces
  1022. this.namespaces = (namespaces)? namespaces : {};
  1023. jQuery.each(this.namespaces, function (k, v) {
  1024. VIE2.namespaces.add(k, v);
  1025. });
  1026. // allocate attributes
  1027. this._attrs = attrs;
  1028. this.listAttrs = function (targetType) {
  1029. var attrs = [];
  1030. for (var a = 0; a < this._attrs.length; a++) {
  1031. var aId = this._attrs[a].id;
  1032. var dt = (VIE2.getType(this._attrs[a].datatype))? VIE2.getType(this._attrs[a].datatype) : this._attrs[a].datatype;
  1033. if (!targetType || VIE2.getType(targetType).id === dt.id) {
  1034. attrs.push(new VIE2.Attribute(this, aId, dt, this.namespaces));
  1035. }
  1036. }
  1037. if (this.getParent()) {
  1038. var parentAttrs = this.getParent().listAttrs(targetType);
  1039. for (var i = 0; i < parentAttrs.length; i++) {
  1040. var contains = false;
  1041. for (var j = 0; j < attrs.length; j++) {
  1042. if (attrs[j].id === parentAttrs[i].id) {
  1043. contains = true;
  1044. }
  1045. }
  1046. if (!contains) {
  1047. attrs.push(parentAttrs[i]);
  1048. }
  1049. }
  1050. }
  1051. return attrs;
  1052. };
  1053. this.getAttr = function (aId) {
  1054. var attrs = this.listAttrs();
  1055. for (var a = 0; a < attrs.length; a++) {
  1056. if (attrs[a].id === aId || attrs[a].sid === aId) {
  1057. return attrs[a];
  1058. }
  1059. }
  1060. return undefined;
  1061. };
  1062. this.getParent = function () {
  1063. //in case the parent was not resolved during init
  1064. if (typeof this._parent === 'string') {
  1065. this._parent = VIE2.getType(this._parent);
  1066. }
  1067. return this._parent;
  1068. };
  1069. if (this.getParent()) {
  1070. this.getParent()._children.push(this);
  1071. };
  1072. this.isTypeOf = function (type) {
  1073. var searchFor = type;
  1074. if (typeof type === 'string') {
  1075. searchFor = VIE2.getType(type);
  1076. }
  1077. if (this.id === searchFor.id) {
  1078. return true;
  1079. }
  1080. if (this.getParent() !== undefined) {
  1081. return this.getParent().isTypeOf(searchFor);
  1082. }
  1083. return false;
  1084. };
  1085. this.getHierarchyObject = function () {
  1086. var obj = {id : this.id, children: []};
  1087. for (var c = 0; c < this._children.length; c++) {
  1088. obj.children.push(this._children[c].getHierarchyObject());
  1089. }
  1090. return obj;
  1091. }
  1092. //automatically registers the mapping in VIE^2.
  1093. VIE2.registerType(this);
  1094. return this;
  1095. };// File: person.js
  1096. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  1097. //
  1098. new VIE2.Type (
  1099. 'DataType', //the id of the mapping
  1100. undefined,
  1101. [
  1102. {'id' : 'value',
  1103. 'datatype' : 'xsd:anyType'
  1104. }
  1105. ],
  1106. { //the used namespaces, these can be given here, or placed directly into the HTML document's xmlns attribute.
  1107. 'xsd' : 'http://www.w3.org/2001/XMLSchema#'
  1108. }
  1109. );
  1110. // File: person.js
  1111. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  1112. //
  1113. new VIE2.Type (
  1114. 'Boolean', //the id of the mapping
  1115. 'DataType',
  1116. [
  1117. {'id' : 'value',
  1118. 'datatype' : 'xsd:boolean'
  1119. }
  1120. ],
  1121. { //the used namespaces, these can be given here, or placed directly into the HTML document's xmlns attribute.
  1122. 'xsd' : 'http://www.w3.org/2001/XMLSchema#'
  1123. }
  1124. );
  1125. // File: person.js
  1126. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  1127. //
  1128. new VIE2.Type (
  1129. 'Number', //the id of the mapping
  1130. 'DataType',
  1131. [
  1132. {'id' : 'value',
  1133. 'datatype' : 'xsd:anySimpleType'
  1134. }
  1135. ],
  1136. { //the used namespaces, these can be given here, or placed directly into the HTML document's xmlns attribute.
  1137. 'xsd' : 'http://www.w3.org/2001/XMLSchema#'
  1138. }
  1139. );
  1140. // File: person.js
  1141. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  1142. //
  1143. new VIE2.Type (
  1144. 'Date', //the id of the mapping
  1145. 'DataType',
  1146. [
  1147. {'id' : 'value',
  1148. 'datatype' : 'xsd:date'
  1149. }
  1150. ],
  1151. { //the used namespaces, these can be given here, or placed directly into the HTML document's xmlns attribute.
  1152. 'xsd' : 'http://www.w3.org/2001/XMLSchema#'
  1153. }
  1154. );
  1155. // File: person.js
  1156. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  1157. //
  1158. new VIE2.Type (
  1159. 'Text', //the id of the mapping
  1160. 'DataType',
  1161. [
  1162. {'id' : 'value',
  1163. 'datatype' : 'xsd:string'
  1164. }
  1165. ],
  1166. { //the used namespaces, these can be given here, or placed directly into the HTML document's xmlns attribute.
  1167. 'xsd' : 'http://www.w3.org/2001/XMLSchema#'
  1168. }
  1169. );
  1170. // File: person.js
  1171. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  1172. //
  1173. new VIE2.Type (
  1174. 'Float', //the id of the mapping
  1175. 'Number',
  1176. [
  1177. {'id' : 'value',
  1178. 'datatype' : 'xsd:float'
  1179. }
  1180. ],
  1181. { //the used namespaces, these can be given here, or placed directly into the HTML document's xmlns attribute.
  1182. 'xsd' : 'http://www.w3.org/2001/XMLSchema#'
  1183. }
  1184. );
  1185. // File: person.js
  1186. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  1187. //
  1188. new VIE2.Type (
  1189. 'Integer', //the id of the mapping
  1190. 'Number',
  1191. [
  1192. {'id' : 'value',
  1193. 'datatype' : 'xsd:decimal'
  1194. }
  1195. ],
  1196. { //the used namespaces, these can be given here, or placed directly into the HTML document's xmlns attribute.
  1197. 'xsd' : 'http://www.w3.org/2001/XMLSchema#'
  1198. }
  1199. );
  1200. // File: person.js
  1201. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  1202. //
  1203. new VIE2.Type (
  1204. 'URL', //the id of the mapping
  1205. 'Text',
  1206. [
  1207. {'id' : 'value',
  1208. 'datatype' : 'xsd:anyURI'
  1209. }
  1210. ],
  1211. { //the used namespaces, these can be given here, or placed directly into the HTML document's xmlns attribute.
  1212. 'xsd' : 'http://www.w3.org/2001/XMLSchema#'
  1213. }
  1214. );
  1215. // File: person.js
  1216. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  1217. //
  1218. new VIE2.Type (
  1219. 'Thing', //the id of the mapping
  1220. undefined,
  1221. [
  1222. {'id' : 'description',
  1223. 'datatype' : 'Text'
  1224. },
  1225. {'id' : 'image',
  1226. 'datatype' : 'URL'
  1227. },
  1228. {'id' : 'name',
  1229. 'datatype' : 'Text'
  1230. },
  1231. {'id' : 'url',
  1232. 'datatype' : 'URL'
  1233. },
  1234. {'id' : 'sameAs',
  1235. 'datatype' : 'URL'
  1236. }
  1237. ],
  1238. { //the used namespaces, these can be given here, or placed directly into the HTML document's xmlns attribute.
  1239. 'schema' : 'http://schema.org/',
  1240. 'xsd' : 'http://www.w3.org/2001/XMLSchema#',
  1241. 'owl' : 'http://www.w3.org/2002/07/owl#'
  1242. }
  1243. );
  1244. // File: person.js
  1245. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  1246. //
  1247. new VIE2.Type(
  1248. 'Person', //the id of the mapping
  1249. 'Thing', // the super type
  1250. [ // attributes
  1251. {'id' : 'address',
  1252. 'datatype' : 'PostalAddress'
  1253. },
  1254. {'id' : 'affiliation',
  1255. 'datatype' : 'Organization'
  1256. },
  1257. {'id' : 'alumniOf',
  1258. 'datatype' : 'EducationalOrganization'
  1259. },
  1260. {'id' : 'awards',
  1261. 'datatype' : 'Text'
  1262. },
  1263. {'id' : 'birthDate',
  1264. 'datatype' : 'Date'
  1265. },
  1266. {'id' : 'children',
  1267. 'datatype' : 'Person'
  1268. },
  1269. {'id' : 'colleagues',
  1270. 'datatype' : 'Person'
  1271. },
  1272. {'id' : 'contactPoints',
  1273. 'datatype' : 'ContactPoint'
  1274. },
  1275. {'id' : 'deathDate',
  1276. 'datatype' : 'Date'
  1277. },
  1278. {'id' : 'email',
  1279. 'datatype' : 'Text'
  1280. },
  1281. {'id' : 'faxNumber',
  1282. 'datatype' : 'Text'
  1283. },
  1284. {'id' : 'follows',
  1285. 'datatype' : 'Person'
  1286. },
  1287. {'id' : 'gender',
  1288. 'datatype' : 'Text'
  1289. },
  1290. {'id' : 'homeLocation',
  1291. 'datatype' : 'Place'
  1292. },
  1293. {'id' : 'interactionCount',
  1294. 'datatype' : 'Text'
  1295. },
  1296. {'id' : 'jobTitle',
  1297. 'datatype' : 'Text'
  1298. },
  1299. {'id' : 'knows',
  1300. 'datatype' : 'Person'
  1301. },
  1302. {'id' : 'interactionCount',
  1303. 'datatype' : 'Text'
  1304. },
  1305. {'id' : 'memberOf',
  1306. 'datatype' : 'Organization'
  1307. },
  1308. {'id' : 'nationality',
  1309. 'datatype' : 'Country'
  1310. },
  1311. {'id' : 'parents',
  1312. 'datatype' : 'Person'
  1313. },
  1314. {'id' : 'performerIn',
  1315. 'datatype' : 'Event'
  1316. },
  1317. {'id' : 'relatedTo',
  1318. 'datatype' : 'Person'
  1319. },
  1320. {'id' : 'siblings',
  1321. 'datatype' : 'Person'
  1322. },
  1323. {'id' : 'spouse',
  1324. 'datatype' : 'Person'
  1325. },
  1326. {'id' : 'telephone',
  1327. 'datatype' : 'Text'
  1328. },
  1329. {'id' : 'workLocation',
  1330. 'datatype' : 'Place'
  1331. },
  1332. {'id': 'worksFor',
  1333. 'datatype': 'Organization'
  1334. }
  1335. ],
  1336. { //the used namespaces, these can be given here, or placed directly into the HTML document's xmlns attribute.
  1337. 'schema' : 'http://schema.org/',
  1338. 'owl' : 'http://www.w3.org/2002/07/owl#'
  1339. }
  1340. );// File: person.js
  1341. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  1342. //
  1343. new VIE2.Type(
  1344. 'Intangible', //the id of the mapping
  1345. 'Thing', // the super type
  1346. [ // attributes
  1347. ],
  1348. { //the used namespaces, these can be given here, or placed directly into the HTML document's xmlns attribute.
  1349. }
  1350. );// File: person.js
  1351. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  1352. //
  1353. new VIE2.Type(
  1354. 'StructuredValue', //the id of the mapping
  1355. 'Intangible', // the super type
  1356. [ // attributes
  1357. ],
  1358. { //the used namespaces, these can be given here, or placed directly into the HTML document's xmlns attribute.
  1359. }
  1360. );// File: person.js
  1361. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  1362. //
  1363. new VIE2.Type(
  1364. 'ContactPoint', //the id of the mapping
  1365. 'StructuredValue', // the super type
  1366. [ // attributes
  1367. {'id' : 'contactType',
  1368. 'datatype' : 'Country'
  1369. },
  1370. {'id' : 'email',
  1371. 'datatype' : 'Text'
  1372. },
  1373. {'id' : 'faxNumber',
  1374. 'datatype' : 'Text'
  1375. },
  1376. {'id' : 'telephone',
  1377. 'datatype' : 'Text'
  1378. }
  1379. ],
  1380. { //the used namespaces, these can be given here, or placed directly into the HTML document's xmlns attribute.
  1381. }
  1382. );// File: person.js
  1383. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  1384. //
  1385. new VIE2.Type(
  1386. 'PostalAddress', //the id of the mapping
  1387. 'ContactPoint', // the super type
  1388. [ // attributes
  1389. {'id' : 'addressCountry',
  1390. 'datatype' : 'Country'
  1391. },
  1392. {'id' : 'addressLocality',
  1393. 'datatype' : 'Text'
  1394. },
  1395. {'id' : 'addressRegion',
  1396. 'datatype' : 'Text'
  1397. },
  1398. {'id' : 'postOfficeBoxNumber',
  1399. 'datatype' : 'Text'
  1400. },
  1401. {'id' : 'postalCode',
  1402. 'datatype' : 'Text'
  1403. },
  1404. {'id' : 'streetAddress',
  1405. 'datatype' : 'Text'
  1406. }
  1407. ],
  1408. { //the used namespaces, these can be given here, or placed directly into the HTML document's xmlns attribute.
  1409. }
  1410. );// File: person.js
  1411. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  1412. //
  1413. new VIE2.Type(
  1414. 'GeoCoordinates', //the id of the mapping
  1415. 'StructuredValue', // the super type
  1416. [ // attributes
  1417. {'id' : 'elevation',
  1418. 'datatype' : 'Float'
  1419. },
  1420. {'id' : 'latitude',
  1421. 'datatype' : 'Float'
  1422. },
  1423. {'id' : 'longitude',
  1424. 'datatype' : 'Float'
  1425. },
  1426. ],
  1427. { //the used namespaces, these can be given here, or placed directly into the HTML document's xmlns attribute.
  1428. }
  1429. );// File: person.js
  1430. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  1431. //
  1432. new VIE2.Type(
  1433. 'Place', //the id of the mapping
  1434. 'Thing', // the super type
  1435. [ // attributes
  1436. {'id' : 'address',
  1437. 'datatype' : 'PostalAddress'
  1438. },
  1439. {'id' : 'aggregateRating',
  1440. 'datatype' : 'AggregateRating' //TODO!
  1441. },
  1442. {'id' : 'containedIn',
  1443. 'datatype' : 'Place'
  1444. },
  1445. {'id' : 'events',
  1446. 'datatype' : 'Event' //TODO!
  1447. },
  1448. {'id' : 'faxNumber',
  1449. 'datatype' : 'Text'
  1450. },
  1451. {'id' : 'geo',
  1452. 'datatype' : 'GeoCoordinates'
  1453. },
  1454. {'id' : 'interactionCount',
  1455. 'datatype' : 'Text'
  1456. },
  1457. {'id' : 'maps',
  1458. 'datatype' : 'URL'
  1459. },
  1460. {'id' : 'photos',
  1461. 'datatype' : 'Photograph'
  1462. },
  1463. {'id' : 'reviews',
  1464. 'datatype' : 'Review' //TODO!
  1465. },
  1466. {'id' : 'telephone',
  1467. 'datatype' : 'Text'
  1468. }
  1469. ],
  1470. { //the used namespaces, these can be given here, or placed directly into the HTML document's xmlns attribute.
  1471. 'schema' : 'http://schema.org/',
  1472. 'owl' : 'http://www.w3.org/2002/07/owl#'
  1473. }
  1474. );// File: person.js
  1475. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  1476. //
  1477. new VIE2.Type(
  1478. 'AdministrativeArea', //the id of the mapping
  1479. 'Place', // the super type
  1480. [ // attributes
  1481. ],
  1482. { //the used namespaces, these can be given here, or placed directly into the HTML document's xmlns attribute.
  1483. }
  1484. );// File: person.js
  1485. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  1486. //
  1487. new VIE2.Type(
  1488. 'Country', //the id of the mapping
  1489. 'AdministrativeArea', // the super type
  1490. [ // attributes
  1491. ],
  1492. { //the used namespaces, these can be given here, or placed directly into the HTML document's xmlns attribute.
  1493. }
  1494. );// File: person.js
  1495. // Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
  1496. //
  1497. new VIE2.Type(
  1498. 'TouristAttraction', //the id of the mapping
  1499. 'Place', // the super type
  1500. [ // attributes
  1501. ],
  1502. { //the used namespaces, these can be given here, or placed directly into the HTML document's xmlns attribute.
  1503. 'schema' : 'http://schema.org/',
  1504. 'owl' : 'http://www.w3.org/2002/07/owl#'
  1505. }
  1506. );
  1507. //calling this once for convenience
  1508. jQuery(document).vie2();
  1509. }).call(this);