Modified: incubator/stanbol/trunk/demos/webvie/src/main/resources/org/apache/stanbol/commons/web/vie/static/lib/vie/vie-latest.js URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/demos/webvie/src/main/resources/org/apache/stanbol/commons/web/vie/static/lib/vie/vie-latest.js?rev=1294730&r1=1294729&r2=1294730&view=diff ============================================================================== --- incubator/stanbol/trunk/demos/webvie/src/main/resources/org/apache/stanbol/commons/web/vie/static/lib/vie/vie-latest.js (original) +++ incubator/stanbol/trunk/demos/webvie/src/main/resources/org/apache/stanbol/commons/web/vie/static/lib/vie/vie-latest.js Tue Feb 28 16:56:02 2012 @@ -1 +1 @@ -var _=this._;if(!_&&(typeof require!=="undefined")){_=require("underscore")._}if(!_){throw"VIE requires underscore.js to be available"}var Backbone=this.Backbone;if(!Backbone&&(typeof require!=="undefined")){Backbone=require("backbone")}if(!Backbone){throw"VIE requires Backbone.js to be available"}var jQuery=this.jQuery;if(!jQuery&&(typeof require!=="undefined")){jQuery=require("jquery")}if(!jQuery){throw"VIE requires jQuery to be available"}var VIE;VIE=function(a){this.config=(a)?a:{};this.services={};this.entities=new this.Collection();this.Entity.prototype.entities=this.entities;this.entities.vie=this;this.Entity.prototype.entityCollection=this.Collection;this.Entity.prototype.vie=this;this.defaultProxyUrl=(this.config.defaultProxyUrl)?this.config.defaultProxyUrl:"../utils/proxy/proxy.php";this.Namespaces.prototype.vie=this;this.namespaces=new this.Namespaces((this.config.defaultNamespace)?this.config.defaultNamespace:"http://ontology.vie.js/");this.Type.prototype.vie=thi s;this.Types.prototype.vie=this;this.Attribute.prototype.vie=this;this.Attributes.prototype.vie=this;this.types=new this.Types();this.types.add("Thing");if(this.config.classic!==false){this.RDFa=new this.ClassicRDFa(this);this.RDFaEntities=new this.ClassicRDFaEntities(this);this.EntityManager=new this.ClassicEntityManager(this);this.cleanup=function(){this.entities.reset()}}};VIE.prototype.use=function(a,b){if(!b){b=a.name}a.vie=this;a.name=b;if(a.init){a.init()}this.services[b]=a};VIE.prototype.service=function(a){if(!this.services[a]){throw"Undefined service "+a}return this.services[a]};VIE.prototype.getServicesArray=function(){var a=[];_(this.services).each(function(b,c){a.push(b)});return a};VIE.prototype.load=function(a){if(!a){a={}}a.vie=this;return new this.Loadable(a)};VIE.prototype.save=function(a){if(!a){a={}}a.vie=this;return new this.Savable(a)};VIE.prototype.remove=function(a){if(!a){a={}}a.vie=this;return new this.Removable(a)};VIE.prototype.analyze=function(a) {if(!a){a={}}a.vie=this;return new this.Analyzable(a)};VIE.prototype.find=function(a){if(!a){a={}}a.vie=this;return new this.Findable(a)};if(typeof(exports)!=="undefined"&&exports!==null){exports.VIE=VIE}VIE.prototype.Able=function(){};VIE.prototype.Able.prototype={using:function(b){var a=this;if(b instanceof Array){_(b).each(function(d){a._using(d)})}else{var c=b;a._using(c)}return this},_using:function(a){var b=typeof a==="string"?this.vie.service(a):a;this.services.push(b);return this},init:function(b,a){this.methodName=a;this.options=b;this.services=b.from||b.using||b.to||[];this.vie=b.vie;this.deferred=jQuery.Deferred();this.resolve=this.deferred.resolve;this.resolveWith=this.deferred.resolveWith;this.reject=this.deferred.reject;this.rejectWith=this.deferred.rejectWith;this.success=this.done=this.deferred.done;this.fail=this.deferred.fail;this.then=this.deferred.then;this.always=this.deferred.always;this.from=this.using;this.to=this.using},execute:function(){var a=this; _(this.services).each(function(b){b[a.methodName](a)});return this}};VIE.prototype.Loadable=function(a){this.init(a,"load")};VIE.prototype.Loadable.prototype=new VIE.prototype.Able();VIE.prototype.Savable=function(a){this.init(a,"save")};VIE.prototype.Savable.prototype=new VIE.prototype.Able();VIE.prototype.Removable=function(a){this.init(a,"remove")};VIE.prototype.Removable.prototype=new VIE.prototype.Able();VIE.prototype.Analyzable=function(a){this.init(a,"analyze")};VIE.prototype.Analyzable.prototype=new VIE.prototype.Able();VIE.prototype.Findable=function(a){this.init(a,"find")};VIE.prototype.Findable.prototype=new VIE.prototype.Able();jQuery.fn.compare=function(f){if(this.length!=f.length){return false}var d=this.sort(),c=f.sort();for(var e=0;f[e];e++){if(d[e]!==c[e]){return false}}return true};if(!Array.prototype.remove){Array.prototype.remove=function(){var d=this.remove.arguments;if(d[0]&&d[0] instanceof Array){var b=d[0];for(var e=0;e<b.length;e++){this.remove(b[e]) }}else{for(var e=0;e<d.length;e++){while(true){var c=this.indexOf(d[e]);if(c!==-1){this.splice(c,1)}else{break}}}}return this}}if(!Array.prototype.unduplicate){Array.prototype.unduplicate=function(){var a=this.sort();var c=[];for(var b=0;b<a.length;b++){if(b===a.length-1||a[b]!=a[b+1]){c.push(a[b])}}return c}}VIE.Util={toCurie:function(b,e,d){if(VIE.Util.isCurie(b,d)){return b}var f=":";for(var a in d.toObj()){if(b.indexOf(d.get(a))===1){var c=new RegExp("^<"+d.get(a));if(a===""){f=""}return((e)?"[":"")+b.replace(c,a+f).replace(/>$/,"")+((e)?"]":"")}}throw new Error("No prefix found for URI '"+b+"'!")},isCurie:function(a,b){try{VIE.Util.toUri(a,b);return true}catch(c){return false}},toUri:function(b,d){var e=":";for(var a in d.toObj()){if(a!==""&&(b.indexOf(a)===0||b.indexOf(a)===1)){var c=new RegExp("^\\[{0,1}"+a+e);return"<"+b.replace(c,d.get(a)).replace(/\]{0,1}$/,"")+">"}}if(b.indexOf(e)===-1&&d.base()){return"<"+d.base()+b+">"}throw new Error("No prefix found for CURIE '"+b+"'!")},isUri:function(a){return(typeof a==="string"&&a.search(/^<.+:.+>$/)===0)},_blankNodeSeed:new Date().getTime()%1000,blankNodeID:function(){this._blankNodeSeed+=1;return"_:bnode"+this._blankNodeSeed.toString(16)}};VIE.prototype.Entity=function(c,d){var b=this;var a=function(f,h){var g=f;if(h.isUri(f)||f.indexOf("@")===0){}else{if(h.isCurie(f)){g=h.uri(f)}else{if(!h.isUri(f)){if(f.indexOf(":")===-1){g="<"+h.base()+f+">"}else{g="<"+f+">"}}}}return g};if("@type" in c){if(_.isArray(c["@type"])){c["@type"]=_.map(c["@type"],function(f){if(this.types.get(f)){return this.types.get(f).id}else{return f}},b.vie)}else{if(typeof c["@type"]==="string"){if(b.vie.types.get(c["@type"])){c["@type"]=b.vie.types.get(c["@type"]).id}}}}else{c["@type"]=b.vie.types.get("Thing").id}c=(c)?c:{};_.each(c,function(g,f){var h=a(f,this.namespaces);if(f!==h){delete c[f];c[h]=g}},b.vie);var e=Backbone.Model.extend({idAttribute:"@subject",initialize:function(f,g){if(f["@subject"]){this.id=this["@su bject"]=this.toReference(f["@subject"])}return this},get:function(f){f=a(f,b.vie.namespaces);var g=Backbone.Model.prototype.get.call(this,f);if(_.isArray(g)){g=_.map(g,function(h){if(b.vie.entities.get(h)){return b.vie.entities.get(h)}else{if(f==="@type"&&b.vie.types.get(h)){return b.vie.types.get(h)}else{return h}}},this)}else{if(b.vie.entities.get(g)){g=b.vie.entities.get(g)}else{if(f==="@type"&&b.vie.types.get(g)){g=b.vie.types.get(g)}}}return g},has:function(f){f=a(f,b.vie.namespaces);return Backbone.Model.prototype.has.call(this,f)},set:function(g,f){if(!g){return this}if(g.attributes){g=g.attributes}_.each(g,function(i,h){var j=a(h,b.vie.namespaces);if(h!==j){delete g[h];g[j]=i}},this);_.each(g,function(i,h){if(h.indexOf("@")===-1){if(typeof i==="object"&&!jQuery.isArray(i)&&!i.isCollection){var j=new b.vie.Entity(i,f);b.vie.entities.add(j);g[h]=j.getSubject()}else{if(i.isCollection){g[h]=[];i.each(function(k){b.vie.entities.add(k);g[h].push(k.getSubject())})}}}},this) ;return Backbone.Model.prototype.set.call(this,g,f)},unset:function(f,g){f=a(f,b.vie.namespaces);return Backbone.Model.prototype.unset.call(this,f,g)},getSubject:function(){if(typeof this.id==="undefined"){this.id=this.get(this.idAttribute)}if(typeof this.id==="string"){if(this.id.substr(0,7)==="http://"||this.id.substr(0,4)==="urn:"){return this.toReference(this.id)}return this.id}return this.cid.replace("c","_:bnode")},getSubjectUri:function(){return this.fromReference(this.getSubject())},isReference:function(f){var g=new RegExp("^\\<([^\\>]*)\\>$");if(g.exec(f)){return true}return false},toReference:function(f){if(typeof f!=="string"){return f}if(this.isReference(f)){return f}return"<"+f+">"},fromReference:function(f){if(typeof f!=="string"){return f}if(!this.isReference(f)){return f}return f.substring(1,f.length-1)},as:function(f){if(f==="JSON"){return this.toJSON()}if(f==="JSONLD"){return this.toJSONLD()}throw"Unknown encoding "+f},toJSONLD:function(){var g={};var f=thi s;_.each(f.attributes,function(j,i){var h=f.get(i);if(i==="@type"&&h){h=h.id}if(j instanceof f.vie.Collection){h=j.map(function(k){return k.getSubject()})}g[i]=h});g["@subject"]=f.getSubject();return g},setOrAdd:function(h,g){var f=this;if(typeof h==="string"&&g){f._setOrAddOne(h,g)}else{if(typeof h==="object"){_(h).each(function(j,i){f._setOrAddOne(i,j)})}}return this},_setOrAddOne:function(f,g){f=a(f,b.vie.namespaces);var i=Backbone.Model.prototype.get.call(this,f);if(!i){var h={};h[f]=g;this.set(h)}else{if(i!==g&&(!(i instanceof Array)&&i.indexOf(g)===-1)){if(!(i instanceof Array)){i=[i]}i.push(g);var h={};h[f]=i;this.set(h)}}},hasType:function(f){f=b.vie.types.get(f);return this.hasPropertyValue("@type",f)},hasPropertyValue:function(h,g){var f=this.get(h);if(!(g instanceof Object)){g=b.vie.entities.get(g)}if(f instanceof Array){return f.indexOf(g)!==-1}else{return f===g}},isof:function(h){var g=this.get("@type");g=(_.isArray(g))?g:[g];for(var f=0;f<g.length;f++){if(b.vie .types.get(g[f])&&b.vie.types.get(g[f]).isof(h)){return true}}return false},isEntity:true,vie:b.vie});return new e(c,d)};VIE.prototype.Collection=Backbone.Collection.extend({model:VIE.prototype.Entity,get:function(a){if(a==null){return null}a=(a.getSubject)?a.getSubject():a;if(typeof a==="string"&&a.indexOf("_:")===0){a=a.replace("_:bnode","c");return this._byCid[a]}else{a=this.toReference(a);return this._byId[a]}},addOrUpdate:function(a){var d=this;if(_.isArray(a)){var c=[];_.each(a,function(e){c.push(d.addOrUpdate(e))});return c}if(!a.isEntity){a=new this.model(a)}if(!a.id){this.add(a);return a}if(this.get(a.id)){var b=this.get(a.id);if(a.attributes){return b.set(a.attributes)}return b.set(a)}this.add(a);return a},isReference:function(a){var b=new RegExp("^\\<([^\\>]*)\\>$");if(b.exec(a)){return true}return false},toReference:function(a){if(this.isReference(a)){return a}return"<"+a+">"},fromReference:function(a){if(!this.isReference(a)){return a}return a.substring(1,a.leng th-1)},isCollection:true});if(VIE.prototype.Type){throw"ERROR: VIE.Type is already defined. Please check your installation!"}if(VIE.prototype.Types){throw"ERROR: VIE.Types is already defined. Please check your installation!"}VIE.prototype.Type=function(b,a){if(b===undefined||typeof b!=="string"){throw"The type constructor needs an 'id' of type string! E.g., 'Person'"}this.id=this.vie.namespaces.isUri(b)?b:this.vie.namespaces.uri(b);if(this.vie.types.get(this.id)){throw"The type "+this.id+" is already defined!"}this.supertypes=new this.vie.Types();this.subtypes=new this.vie.Types();this.attributes=new this.vie.Attributes(this,(a)?a:[]);this.isof=function(c){c=this.vie.types.get(c);if(c){return c.subsumes(this.id)}else{throw"No valid type given"}};this.subsumes=function(d){d=this.vie.types.get(d);if(d){if(this.id===d.id){return true}var e=this.subtypes.list();for(var g=0;g<e.length;g++){var f=e[g];if(f){if(f.id===d.id||f.subsumes(d)){return true}}}return false}else{throw"No va lid type given"}};this.inherit=function(c){if(typeof c==="string"){this.inherit(this.vie.types.get(c))}else{if(c instanceof this.vie.Type){c.subtypes.addOrOverwrite(this);this.supertypes.addOrOverwrite(c);try{this.attributes.list()}catch(f){c.subtypes.remove(this);this.supertypes.remove(c);throw f}}else{if(jQuery.isArray(c)){for(var d=0;d<c.length;d++){this.inherit(c[d])}}else{throw"Wrong argument in VIE.Type.inherit()"}}}return this};this.hierarchy=function(){var e={id:this.id,subtypes:[]};var d=this.subtypes.list();for(var g=0;g<d.length;g++){var f=this.vie.types.get(d[g]);e.subtypes.push(f.hierarchy())}return e};this.instance=function(d,e){d=(d)?d:{};for(var c in d){if(c.indexOf("@")!==0&&!this.attributes.get(c)){throw new Error("Cannot create an instance of "+this.id+" as the type does not allow an attribute '"+c+"'!")}}d["@type"]=this.id;return new this.vie.Entity(d,e)};this.toString=function(){return this.id}};VIE.prototype.Types=function(){this._types={};this.add=func tion(c,a){if(this.get(c)){throw"Type '"+c+"' already registered."}else{if(typeof c==="string"){var b=new this.vie.Type(c,a);this._types[b.id]=b;return b}else{if(c instanceof this.vie.Type){this._types[c.id]=c;return c}else{throw"Wrong argument to VIE.Types.add()!"}}}};this.addOrOverwrite=function(b,a){if(this.get(b)){this.remove(b)}return this.add(b,a)};this.get=function(b){if(!b){return undefined}if(typeof b==="string"){var a=this.vie.namespaces.isUri(b)?b:this.vie.namespaces.uri(b);return this._types[a]}else{if(b instanceof this.vie.Type){return this.get(b.id)}}return undefined};this.remove=function(f){var a=this.get(f);if(!a){return this}delete this._types[a.id];var b=a.subtypes.list();for(var e=0;e<b.length;e++){var d=b[e];if(d.supertypes.list().length===1){this.remove(d)}else{d.supertypes.remove(a.id)}}return a};this.toArray=this.list=function(){var a=[];for(var b in this._types){a.push(this._types[b])}return a};this.sort=function(e,d){var k=this;var c=$.merge([],($.isA rray(e))?e:[e]);d=(d)?true:false;for(var i=0;i<c.length;i++){var h=c.shift();var j=0;for(var g=0;g<c.length;g++){var f=k.vie.types.get(c[g]);if(f.subsumes(h)){j=g}}c.splice(j+1,0,h)}if(!d){c.reverse()}return c}};if(VIE.prototype.Attribute){throw"ERROR: VIE.Attribute is already defined. Please check your installation!"}if(VIE.prototype.Attributes){throw"ERROR: VIE.Attributes is already defined. Please check your installation!"}VIE.prototype.Attribute=function(c,a,b){if(c===undefined||typeof c!=="string"){throw"The attribute constructor needs an 'id' of type string! E.g., 'Person'"}if(a===undefined){throw"The attribute constructor needs 'range'."}if(b===undefined){throw"The attribute constructor needs a 'domain'."}this._domain=b;this.range=(jQuery.isArray(a))?a:[a];this.id=this.vie.namespaces.isUri(c)?c:this.vie.namespaces.uri(c);this.applies=function(e){if(this.vie.types.get(e)){e=this.vie.types.get(e)}for(var f=0;f<this.range.length;f++){var d=this.vie.types.get(this.range[f ]);if(d===undefined&&typeof e==="string"){if(e===this.range[f]){return true}}else{if(e.isof(this.range[f])){return true}}}return false}};VIE.prototype.Attributes=function(d,c){this.domain=d;this._local={};this._attributes={};this.add=function(g,f){if(this.get(g)){throw"Attribute '"+g+"' already registered for domain "+this.domain.id+"!"}else{if(typeof g==="string"){var e=new this.vie.Attribute(g,f,this.domain);this._local[e.id]=e;return e}else{if(g instanceof this.vie.Type){g.domain=this.domain;g.vie=this.vie;this._local[g.id]=g;return g}else{throw"Wrong argument to VIE.Types.add()!"}}}};this.remove=function(f){var e=this.get(f);if(e.id in this._local){delete this._local[e.id];return e}throw"The attribute "+f+" is inherited and cannot be removed from the domain "+this.domain.id+"!"};this.get=function(e){if(typeof e==="string"){var a=this.vie.namespaces.isUri(e)?e:this.vie.namespaces.uri(e);return this._inherit()._attributes[a]}else{if(e instanceof this.vie.Attribute){return this.get(e.id)}else{throw"Wrong argument in VIE.Attributes.get()"}}};this._inherit=function(){var j=jQuery.extend(true,{},this._local);var k=this.domain.supertypes.list().map(function(a){return a.attributes});var t={};var m={};for(var n=0;n<k.length;n++){var s=k[n].list();for(var o=0;o<s.length;o++){var h=s[o].id;if(!(h in j)){if(!(h in t)&&!(h in m)){t[h]=s[o]}else{if(!m[h]){m[h]=[]}if(h in t){m[h]=jQuery.merge(m[h],t[h].range);delete t[h]}m[h]=jQuery.merge(m[h],s[o].range);m[h]=m[h].unduplicate()}}}}jQuery.extend(j,t);for(var h in m){var q=m[h];var f=[];for(var e=0;e<q.length;e++){var g=this.vie.types.get(q[e]);var i=false;if(g){for(var o=0;o<q.length;o++){if(o===e){continue}var l=this.vie.types.get(q[o]);if(l&&l.isof(g)){i=true;break}}}if(!i){f.push(q[e])}}j[h]=new this.vie.Attribute(h,f,this)}this._attributes=j;return this};this.toArray=this.list=function(g){var h=[];var f=this._inherit()._attributes;for(var e in f){if(!g||f[e].applies(g)){h.push(f[e])}}return h};if(!jQu ery.isArray(c)){c=[c]}for(var b=0;b<c.length;b++){this.add(c[b].id,c[b].range)}};if(VIE.prototype.Namespaces){throw"ERROR: VIE.Namespaces is already defined. Please check your installation!"}VIE.prototype.Namespaces=function(b,a){if(!b){throw"Please provide a base namespace!"}this._base=b;this.base=function(c){if(!c){return this._base}else{if(typeof c==="string"){this._base=c}else{throw"Please provide a valid namespace!"}}return this};this._namespaces=(a)?a:{};this.add=function(d,c){if(typeof d==="object"){for(var e in d){this.add(e,d[e])}return this}if(d===""){this.base(c)}else{if(this.containsPrefix(d)&&c!==this._namespaces[d]){throw"ERROR: Trying to register namespace prefix mapping ("+d+","+c+")!There is already a mapping existing: '("+d+","+this.get(d)+")'!"}else{jQuery.each(this._namespaces,function(g,f){if(f===c&&g!==d){throw"ERROR: Trying to register namespace prefix mapping ("+d+","+c+")!There is already a mapping existing: '("+g+","+c+")'!"}})}}this._namespaces[d]= c;return this};this.addOrReplace=function(e,d){if(typeof e==="object"){for(var f in e){this.addOrReplace(f,e[f])}return this}var c=this;if(this.containsPrefix(e)&&d!==this._namespaces[e]){this.remove(e)}else{jQuery.each(this._namespaces,function(h,g){if(g===d&&h!==e){c.remove(h)}})}return this.add(e,d)};this.get=function(c){if(c===""){return this.base()}return this._namespaces[c]};this.getPrefix=function(c){jQuery.each(this._namespaces,function(e,d){if(d===c){return e}});return undefined};this.containsPrefix=function(c){return(c in this._namespaces)};this.containsNamespace=function(c){return this.getPrefix(c)!==undefined};this.update=function(c,d){this._namespaces[c]=d;return this};this.remove=function(c){delete this._namespaces[c];return this};this.toObj=function(){return jQuery.extend({"":this._base},this._namespaces)};this.curie=function(c,d){return VIE.Util.toCurie(c,d,this)};this.isCurie=function(c){return VIE.Util.isCurie(c,this)};this.uri=function(c){return VIE.Util.t oUri(c,this)};this.isUri=VIE.Util.isUri};VIE.prototype.ClassicRDFa=function(a){this.vie=a};VIE.prototype.ClassicRDFa.prototype={readEntities:function(a){var b=[];var c=this.vie.RDFaEntities.getInstances(a);_.each(c,function(d){b.push(d.toJSONLD())});return b}};VIE.prototype.ClassicRDFaEntities=function(a){this.vie=a};VIE.prototype.ClassicRDFaEntities.prototype={getInstances:function(a){if(!this.vie.services.rdfa){this.vie.use(new this.vie.RdfaService())}var b=null;var c=false;this.vie.load({element:a}).from("rdfa").execute().done(function(d){b=d;c=true});while(!c){}return b},getInstance:function(a){var b=this.getInstances(a);if(b&&b.length){return b[0]}return null}};VIE.prototype.ClassicEntityManager=function(a){this.vie=a;this.entities=this.vie.entities};VIE.prototype.ClassicEntityManager.prototype={getBySubject:function(a){return this.vie.entities.get(a)},getByJSONLD:function(a){return this.vie.entities.addOrUpdate(a)},initializeCollection:function(){return}};(function(){V IE.prototype.DBPediaService=function(b){var c={name:"dbpedia",namespaces:{owl:"http://www.w3.org/2002/07/owl#",yago:"http://dbpedia.org/class/yago/",dbonto:"http://dbpedia.org/ontology/"}};this.options=jQuery.extend(c,b?b:{});this.vie=null;this.name=this.options.name;this.connector=new a(this.options);jQuery.ajaxSetup({converters:{"text application/rdf+json":function(d){return JSON.parse(d)}}})};VIE.prototype.DBPediaService.prototype={init:function(){for(var b in this.options.namespaces){try{var d=this.options.namespaces[b];this.vie.namespaces.add(b,d)}catch(c){}}this.namespaces=new this.vie.Namespaces(this.options.namespaces);this.rules=[{left:["?subject a <http://dbpedia.org/ontology/Person>",],right:function(e){return function(){return jQuery.rdf.triple(this.subject.toString()+" a <http://schema.org/Person>",{namespaces:e})}}(this.namespaces.toObj())}]},load:function(g){var e=g instanceof this.vie.Loadable;if(!e){throw"Invalid Loadable passed"}var b=this;var c=g.options.e ntity;if(!c){console.warn("DBPediaConnector: No entity to look for!");g.resolve([])}var f=function(i){var k=c.replace(/^</,"").replace(/>$/,"");if(i[k]){var j=b.vie.entities.get(c);if(!j){var h={"@subject":c,"@type":i[k]["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"]};delete i[k]["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"];jQuery.extend(h,i[k]);b.vie.entities.add(h);j=b.vie.entities.get(c)}g.resolve([j])}else{g.reject(undefined)}};var d=function(h){g.reject(h)};this.connector.load(c,f,d)}};var a=function(b){this.options=b};a.prototype={load:function(e,g,d,c){if(!c){c={}}var b=e.replace(/^</,"").replace(/>$/,"").replace("resource","data")+".jrdf";var f=c.format||"application/rdf+json";if(typeof exports!=="undefined"&&typeof process!=="undefined"){return this.loadNode(b,g,d,c,f)}jQuery.ajax({success:function(h){g(h)},error:d,type:"GET",url:b,dataType:"jsonp"})},loadNode:function(f,h,c,b,g){var e=require("request");var d=e({method:"GET",uri:f,headers:{Accept:g}},func tion(k,j,i){h({results:JSON.parse(i)})});d.end()}}})();VIE.prototype.RdfaService=function(a){if(!a){a={}}this.vie=null;this.name="rdfa";this.subjectSelector=a.subjectSelector?a.subjectSelector:"[about],[typeof],[src],[href],html";this.predicateSelector=a.predicateSelector?a.predicateSelector:"[property],[rel]";this.views=[]};VIE.prototype.RdfaService.prototype={analyze:function(c){var a=this;var b=c instanceof this.vie.Analyzable;if(!b){throw"Invalid Analyzable passed"}return this.load(new this.vie.Loadable({element:c.options.element}))},load:function(g){var a=this;var b=g instanceof this.vie.Loadable;if(!b){throw"Invalid Loadable passed"}var c;if(!g.options.element){if(typeof document==="undefined"){return g.resolve([])}c=jQuery(document)}else{c=g.options.element}var d=this.xmlns(c);for(var e in d){this.vie.namespaces.addOrReplace(e,d[e])}var f=[];jQuery(this.subjectSelector,c).add(jQuery(c).filter(this.subjectSelector)).each(function(){var h=a._readEntity(jQuery(this));if( h){f.push(h)}});g.resolve(f)},save:function(b){var a=b instanceof this.vie.Savable;if(!a){throw"Invalid Savable passed"}if(!b.options.element){throw"Unable to write entity to RDFa, no element given"}if(!b.options.entity){throw"Unable to write to RDFa, no entity given"}this._writeEntity(b.options.entity,b.options.element);b.resolve()},_readEntity:function(f){var e=this.getElementSubject(f);var g=this._getElementType(f);var b,h,a;var c=this._readEntityPredicates(e,f,false);for(b in c){h=c[b];if(typeof h!=="object"||toString.call(h)!=="[object Array]"){continue}a=new this.vie.Collection();_.each(h,function(i){a.addOrUpdate({"@subject":i})});c[b]=a}c["@subject"]=e;if(g){c["@type"]=g}var d=new this.vie.Entity(c);d=this.vie.entities.addOrUpdate(d);this._registerEntityView(d,f);return d},_writeEntity:function(b,c){var a=this;this._findPredicateElements(this.getElementSubject(c),c,true).each(function(){var e=jQuery(this);var d=a.getElementPredicate(e);if(!b.has(d)){return true}var f =b.get(d);if(f===a.readElementValue(d,e)){return true}a.writeElementValue(d,e,f)});return true},_getViewForElement:function(c,a){var b;jQuery.each(this.views,function(){if(this.el.get(0)===c.get(0)){if(a&&!this.template){return true}b=this;return false}});return b},_registerEntityView:function(c,d){var a=this;var b=this._getViewForElement(d);if(b){return b}b=new this.vie.view.Entity({model:c,el:d,tagName:d.get(0).nodeName,vie:this.vie,service:this.name});this.views.push(b);_.each(c.attributes,function(g,e){var f=c.fromReference(c.get(e));if(f instanceof a.vie.Collection){jQuery.each(a.getElementByPredicate(e,d),function(){a._registerCollectionView(f,jQuery(this))})}});return b},_registerCollectionView:function(d,b){var a=this._getViewForElement(b,true);if(a){return a}var c=b.children(":first-child");a=new this.vie.view.Collection({collection:d,model:d.model,el:b,template:c,service:this,tagName:b.get(0).nodeName});this.views.push(a);return a},_getElementType:function(a){var b ;if(jQuery(a).attr("typeof")){b=jQuery(a).attr("typeof");if(b.indexOf("://")!==-1){return"<"+b+">"}else{return b}}return null},getElementSubject:function(c){var a=this;if(typeof document!=="undefined"){if(c===document){return document.baseURI}}var b=undefined;jQuery(c).closest(this.subjectSelector).each(function(){if(jQuery(this).attr("about")){b=jQuery(this).attr("about");return true}if(jQuery(this).attr("src")){b=jQuery(this).attr("src");return true}if(jQuery(this).attr("typeof")){b=VIE.Util.blankNodeID();return true}if(jQuery(this).get(0).nodeName==="HTML"){jQuery(this).find("base").each(function(){b=jQuery(this).attr("href")})}});if(!b){return undefined}if(typeof b==="object"){return b}return(b.indexOf("_:")===0)?b:"<"+b+">"},setElementSubject:function(b,a){if(jQuery(a).attr("src")){return jQuery(a).attr("src",b)}return jQuery(a).attr("about",b)},getElementPredicate:function(b){var a;a=b.attr("property");if(!a){a=b.attr("rel")}return a},getElementBySubject:function(c,b){ var a=this;return jQuery(b).find(this.subjectSelector).add(jQuery(b).filter(this.subjectSelector)).filter(function(){if(a.getElementSubject(jQuery(this))!==c){return false}return true})},getElementByPredicate:function(b,d){var a=this;var c=this.getElementSubject(d);return jQuery(d).find(this.predicateSelector).add(jQuery(d).filter(this.predicateSelector)).filter(function(){var e=a.getElementPredicate(jQuery(this));if(a.vie.namespaces.curie(e)!==a.vie.namespaces.curie(b)){return false}if(a.getElementSubject(jQuery(this))!==c){return false}return true})},_readEntityPredicates:function(c,b,e){var a=this;var d={};this._findPredicateElements(c,b,true).each(function(){var g=jQuery(this);var f=a.getElementPredicate(g);var h=a.readElementValue(f,g);if(h===null&&!e){return}d[f]=h});if(jQuery(b).get(0).tagName!=="HTML"){jQuery(b).parent("[rev]").each(function(){d[jQuery(this).attr("rev")]=a.getElementSubject(this)})}return d},_findPredicateElements:function(d,c,b){var a=this;return jQ uery(c).find(this.predicateSelector).add(jQuery(c).filter(this.predicateSelector)).filter(function(){if(a.getElementSubject(this)!==d){return false}if(!b){if(!jQuery(this).parents("[property]").length){return true}return false}return true})},readElementValue:function(b,d){var e=d.attr("content");if(e){return e}var g=d.attr("resource");if(g){return"<"+g+">"}var c=d.attr("href");if(c&&d.attr("rel")===b){return"<"+c+">"}if(d.attr("rel")){var f=[];var a=this;jQuery(d).children(this.subjectSelector).each(function(){f.push(a.getElementSubject(this))});return f}return d.html()},writeElementValue:function(a,b,e){if(e instanceof Array&&e.length>0){e=e[0]}var c=b.attr("content");if(c){b.attr("content",e);return}var d=b.attr("resource");if(d){b.attr("resource",e)}b.html(e)},xmlns:function(b){var a;if(!b){if(typeof document==="undefined"){return{}}a=jQuery(document)}else{a=jQuery(b)}var c={};a.each(function(f,g){if(g.attributes&&g.attributes.getNamedItemNS){for(f=0;f<g.attributes.length ;f+=1){var d=g.attributes[f];if(/^xmlns(:(.+))?$/.test(d.nodeName)){prefix=/^xmlns(:(.+))?$/.exec(d.nodeName)[2]||"";value=d.nodeValue;if(prefix===""||value!==""){c[prefix]=d.nodeValue}}}}});return c}};(function(){VIE.prototype.StanbolService=function(b){var c={name:"stanbol",url:"http://dev.iks-project.eu:8080/",defaultProxyUrl:"../utils/proxy/proxy.php",namespaces:{semdeski:"http://www.semanticdesktop.org/ontologies/2007/01/19/nie#",semdeskf:"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#",skos:"http://www.w3.org/2004/02/skos/core#",foaf:"http://xmlns.com/foaf/0.1/",opengis:"http://www.opengis.net/gml/",dbpedia:"http://dbpedia.org/ontology/",owl:"http://www.w3.org/2002/07/owl#",geonames:"http://www.geonames.org/ontology#",enhancer:"http://fise.iks-project.eu/ontology/",entityhub:"http://www.iks-project.eu/ontology/rick/model/",entityhub2:"http://www.iks-project.eu/ontology/rick/query/",rdf:"http://www.w3.org/1999/02/22-rdf-syntax-ns#",rdfs:"http://www.w3.org/200 0/01/rdf-schema#",dc:"http://purl.org/dc/terms/",foaf:"http://xmlns.com/foaf/0.1/",schema:"http://schema.org/",geo:"http://www.w3.org/2003/01/geo/wgs84_pos#"}};this.options=jQuery.extend(true,c,b?b:{});this.vie=null;this.name=this.options.name;this.connector=new a(this.options);jQuery.ajaxSetup({converters:{"text application/rdf+json":function(d){return JSON.parse(d)}}})};VIE.prototype.StanbolService.prototype={init:function(){for(var b in this.options.namespaces){try{var d=this.options.namespaces[b];this.vie.namespaces.add(b,d)}catch(c){}}this.namespaces=new this.vie.Namespaces(this.vie.namespaces.base(),this.options.namespaces);this.rules=[{left:["?subject a <http://fise.iks-project.eu/ontology/EntityAnnotation>","?subject enhancer:entity-type ?type","?subject enhancer:confidence ?confidence","?subject enhancer:entity-reference ?entity","?subject dc:relation ?relation","?relation a <http://fise.iks-project.eu/ontology/TextAnnotation>","?relation enhancer:selected-text ?sel ected-text","?relation enhancer:selection-context ?selection-context","?relation enhancer:start ?start","?relation enhancer:end ?end"],right:["?entity a ?type","?entity enhancer:hasTextAnnotation ?relation","?entity enhancer:hasEntityAnnotation ?subject"]},{left:["?subject a dbpedia:Person","?subject rdfs:label ?label"],right:function(e){return function(){return[jQuery.rdf.triple(this.subject.toString(),"a","<"+e.base()+"Person>",{namespaces:e.toObj()}),jQuery.rdf.triple(this.subject.toString(),"<"+e.base()+"name>",this.label,{namespaces:e.toObj()})]}}(this.namespaces)},{left:["?subject a dbpedia:Place","?subject rdfs:label ?label"],right:function(e){return function(){return[jQuery.rdf.triple(this.subject.toString(),"a","<"+e.base()+"Place>",{namespaces:e.toObj()}),jQuery.rdf.triple(this.subject.toString(),"<"+e.base()+"name>",this.label.toString(),{namespaces:e.toObj()})]}}(this.namespaces)},];this.vie.types.addOrOverwrite("enhancer:EntityAnnotation",[]).inherit("Thing");th is.vie.types.addOrOverwrite("enhancer:TextAnnotation",[]).inherit("Thing");this.vie.types.addOrOverwrite("enhancer:Enhancement",[]).inherit("Thing")},analyze:function(h){var b=this;var d=h instanceof this.vie.Analyzable;if(!d){throw"Invalid Analyzable passed"}var e=h.options.element?h.options.element:jQuery("body");var g=b._extractText(e);if(g.length>0){var b=this;var f=function(i){var j=b._enhancer2Entities(b,i);h.resolve(j)};var c=function(i){h.reject(i)};this.connector.analyze(g,f,c)}else{console.warn("No text found in element.");h.resolve([])}},find:function(g){var e=g instanceof this.vie.Findable;if(!e){throw"Invalid Findable passed"}var b=this;var f=escape(g.options.term);if(!f){console.warn("StanbolConnector: No term to look for!");g.resolve([])}var c=(typeof g.options.limit==="undefined")?20:g.options.limit;var i=(typeof g.options.offset==="undefined")?0:g.options.offset;var h=function(j){var k=_(j).map(function(m,l){m.id=l;return m});g.resolve(k)};var d=function(j){ g.reject(j)};this.connector.find(f,c,i,h,d)},load:function(g){var e=g instanceof this.vie.Loadable;if(!e){throw"Invalid Loadable passed"}var b=this;var c=g.options.entity;if(!c){console.warn("StanbolConnector: No entity to look for!");g.resolve([])}var f=function(h){var i=b._enhancer2Entities(b,h);g.resolve(i)};var d=function(h){g.reject(h)};this.connector.load(c,f,d)},_extractText:function(b){if(b.get(0)&&b.get(0).tagName&&(b.get(0).tagName=="TEXTAREA"||b.get(0).tagName=="INPUT"&&b.attr("type","text"))){return b.get(0).val()}else{return b.text().replace(/\s+/g," ").replace(/\0\b\n\r\f\t/g,"").trim()}},_enhancer2Entities:function(c,f){if(typeof jQuery.rdf!=="function"){return this._enhancer2EntitiesNoRdfQuery(c,f)}var e=jQuery.rdf().load(f,{});if(c.rules){var j=jQuery.rdf.ruleset();for(var g in c.namespaces.toObj()){if(g!==""){j.prefix(g,c.namespaces.get(g))}}for(var d=0;d<c.rules.length;d++){j.add(c.rules[d]["left"],c.rules[d]["right"])}e=e.reason(j,10)}var h={};e.where("?s ubject ?property ?object").each(function(){var k=this.subject.toString();if(!h[k]){h[k]={"@subject":k,"@context":c.namespaces.toObj(),"@type":[]}}var m=this.property.toString();var n;m=m.substring(1,m.length-1);try{property=jQuery.createCurie(m,{namespaces:c.namespaces.toObj()})}catch(l){property=m;console.warn(m+" doesn't have a namespace definition in '",c.namespaces.toObj())}h[k][property]=h[k][property]||[];function i(o){if(typeof o.value==="string"){if(o.lang){return o.toString()}else{return o.value}return o.value.toString()}else{if(o.type==="uri"){return o.toString()}else{return o.value}}}h[k][property].push(i(this.object))});_(h).each(function(i){i["@type"]=i["@type"].concat(i["rdf:type"]);delete i["rdf:type"];_(i).each(function(l,k){if(l.length===1){i[k]=l[0]}})});var b=[];jQuery.each(h,function(){var i=new c.vie.Entity(this);i=c.vie.entities.addOrUpdate(i);b.push(i)});return b},_enhancer2EntitiesNoRdfQuery:function(b,c){jsonLD=[];_.forEach(c.results,function(f,e){va r d={};d["@subject"]="<"+e+">";_.forEach(f,function(h,g){g="<"+g+">";_.forEach(h,function(i){if(i.type==="uri"){i.value="<"+i.value+">"}if(d[g]&&!_.isArray(d[g])){d[g]=[d[g]]}if(_.isArray(d[g])){d[g].push(i.value);return}d[g]=i.value})});jsonLD.push(d)});return jsonLD}};var a=function(b){this.options=b;this.baseUrl=b.url.replace(/\/$/,"");this.enhancerUrlPrefix="/engines";this.entityhubUrlPrefix="/entityhub"};a.prototype={analyze:function(g,f,d,c){if(!c){c={}}var b=this.baseUrl+this.enhancerUrlPrefix;var h=this._proxyUrl();var e=c.format||"application/rdf+json";if(typeof exports!=="undefined"&&typeof process!=="undefined"){return this.analyzeNode(b,g,f,d,c,e)}jQuery.ajax({success:function(i){f(i)},error:d,type:"POST",url:h||b,data:(h)?{proxy_url:b,content:g,verb:"POST",format:e}:g,dataType:e,contentType:h?undefined:"text/plain",accepts:{"application/rdf+json":"application/rdf+json"}})},analyzeNode:function(d,i,h,c,b,g){var f=require("request");var e=f({method:"POST",uri:d,bo dy:i,headers:{Accept:g}},function(l,k,j){h({results:JSON.parse(j)})});e.end()},load:function(e,g,d,c){if(!c){c={}}e=e.replace(/^</,"").replace(/>$/,"");var b=this.baseUrl+this.entityhubUrlPrefix+"/sites/entity?id="+escape(e);var h=this._proxyUrl();var f=c.format||"application/rdf+json";jQuery.ajax({success:function(i){g(i)},error:d,type:(h)?"POST":"GET",url:h||b,data:(h)?{proxy_url:b,content:"",verb:"GET",format:f}:null,dataType:f,contentType:h?undefined:"text/plain",accepts:{"application/rdf+json":"application/rdf+json"}})},find:function(c,d,e,i,f,j){if(!j){j={}}if(e==null){e=0}if(d==null){d=10}var b=this.baseUrl+this.entityhubUrlPrefix+"/sites/find";var h=this._proxyUrl();var g=j.format||"application/rdf+json";jQuery.ajax({success:function(k){i(k)},error:f,type:"POST",url:h||b,data:(h)?{proxy_url:b,content:{name:c,limit:d,offset:e},verb:"POST",format:g,type:"text/plain"}:"name="+c+"&limit="+d+"&offset="+e,dataType:g,accepts:{"application/rdf+json":"application/rdf+json"}}) },_proxyUrl:function(){this.proxyUrl="";if(this.baseUrl.indexOf(":")!==-1&&!this.options.proxyDisabled){return this.options.proxyUrl||this.options.defaultProxyUrl}else{return""}}}})();if(!VIE.prototype.view){VIE.prototype.view={}}VIE.prototype.view.Collection=Backbone.View.extend({initialize:function(){this.template=this.options.template;this.service=this.options.service;if(!this.service){throw"No RDFa service provided to the Collection View"}this.entityViews={};_.bindAll(this,"addItem","removeItem","refreshItems");this.collection.bind("add",this.addItem);this.collection.bind("remove",this.removeItem);var a=this;this.collection.forEach(function(b){a.registerItem(b,a.collection)})},addItem:function(b,d){if(d!=this.collection){return}if(!this.template||this.template.length===0){return}var a=this.service._registerEntityView(b,this.cloneElement(this.template));var c=a.render().el;if(b.id){this.service.setElementSubject(b.getSubjectUri(),c)}this.el.append(c);this.trigger("add",a) ;this.entityViews[b.cid]=a;c.show()},registerItem:function(b,d){var c=this.service.getElementBySubject(b.id,this.el);if(!c){return}var a=this.service._registerEntityView(b,c);this.entityViews[b.cid]=a},removeItem:function(a){if(!this.entityViews[a.cid]){return}this.entityViews[a.cid].el.remove();delete (this.entityViews[a.cid])},refreshItems:function(b){var a=this;jQuery(this.el).empty();b.forEach(function(c){a.addItem(c,b)})},cloneElement:function(c){var d=jQuery(c).clone(false);var a=this.service;if(typeof d.attr("about")!=="undefined"){d.attr("about","")}d.find("[about]").attr("about","");var b=this.service.getElementSubject(d);a._findPredicateElements(b,d,false).each(function(){a.writeElementValue(null,jQuery(this),"")});return d}});if(!VIE.prototype.view){VIE.prototype.view={}}VIE.prototype.view.Entity=Backbone.View.extend({initialize:function(a){this.service=a.service?a.service:"rdfa";this.vie=a.vie;_.bindAll(this,"render");this.model.bind("change",this.render)},render :function(){this.vie.save({element:this.el,entity:this.model}).to(this.service).execute();return this}}); \ No newline at end of file
[... 3 lines stripped ...] Modified: incubator/stanbol/trunk/demos/webvie/src/main/resources/org/apache/stanbol/commons/web/vie/templates/org/apache/stanbol/commons/web/vie/resource/EnhancerVieRootResource/index.ftl URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/demos/webvie/src/main/resources/org/apache/stanbol/commons/web/vie/templates/org/apache/stanbol/commons/web/vie/resource/EnhancerVieRootResource/index.ftl?rev=1294730&r1=1294729&r2=1294730&view=diff ============================================================================== --- incubator/stanbol/trunk/demos/webvie/src/main/resources/org/apache/stanbol/commons/web/vie/templates/org/apache/stanbol/commons/web/vie/resource/EnhancerVieRootResource/index.ftl (original) +++ incubator/stanbol/trunk/demos/webvie/src/main/resources/org/apache/stanbol/commons/web/vie/templates/org/apache/stanbol/commons/web/vie/resource/EnhancerVieRootResource/index.ftl Tue Feb 28 16:56:02 2012 @@ -64,7 +64,7 @@ article { $('#content').annotate({ vie: z, vieServices: ["stanbol"], - showTooltip: false, + showTooltip: true, debug: true, decline: function(event, ui){ console.info('decline event', event, ui); Modified: incubator/stanbol/trunk/parent/pom.xml URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/parent/pom.xml?rev=1294730&r1=1294729&r2=1294730&view=diff ============================================================================== --- incubator/stanbol/trunk/parent/pom.xml (original) +++ incubator/stanbol/trunk/parent/pom.xml Tue Feb 28 16:56:02 2012 @@ -1885,6 +1885,45 @@ </execution> </executions> <configuration> + <licenses> + <license implementation="org.apache.rat.analysis.license.SimplePatternBasedLicense"> + <licenseFamilyCategory>PublicDomain</licenseFamilyCategory> + <licenseFamilyName>Public Domain License</licenseFamilyName> + <notes></notes> + <patterns> + <pattern>Public Domain.</pattern> + </patterns> + </license> + <license implementation="org.apache.rat.analysis.license.SimplePatternBasedLicense"> + <licenseFamilyCategory>DualMIT</licenseFamilyCategory> + <licenseFamilyName>Dual License</licenseFamilyName> + <notes>jQuery uses this.</notes> + <patterns> + <pattern>Dual licensed under the MIT</pattern> + </patterns> + </license> + <license implementation="org.apache.rat.analysis.license.SimplePatternBasedLicense"> + <licenseFamilyCategory>MIT</licenseFamilyCategory> + <licenseFamilyName>MIT License</licenseFamilyName> + <notes>RDFQuery uses this.</notes> + <patterns> + <pattern>Licensed under the MIT</pattern> + <pattern>MIT license</pattern> + </patterns> + </license> + </licenses> + <licenseFamilies> + <licenseFamily implementation="org.apache.rat.license.Apache20LicenseFamily" /> + <licenseFamily implementation="org.apache.rat.license.SimpleLicenseFamily"> + <familyName>Public Domain License</familyName> + </licenseFamily> + <licenseFamily implementation="org.apache.rat.license.SimpleLicenseFamily"> + <familyName>Dual License</familyName> + </licenseFamily> + <licenseFamily implementation="org.apache.rat.license.SimpleLicenseFamily"> + <familyName>MIT License</familyName> + </licenseFamily> + </licenseFamilies> <excludes> <exclude>src/license/THIRD-PARTY.properties</exclude> </excludes>
