From 282a85e5225c1a8028ea53e272587f8424f53c18 Mon Sep 17 00:00:00 2001 From: Henri Bergius Date: Thu, 3 Nov 2011 17:07:00 +0200 Subject: [PATCH] New upstream VIE --- deps/vie-min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/vie-min.js b/deps/vie-min.js index 19291ca..4a06fc7 100644 --- a/deps/vie-min.js +++ b/deps/vie-min.js @@ -1 +1 @@ -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=this;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=[];_.each(this.services,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==="object"){exports.VIE=VIE;var root=this;var jQuery=this.jQuery;if(!jQuery){jQuery=require("jquery")}var Backbone=root.Backbone;if(!Backbone){Backbone=require("backbone")}var _=this._;if(!_){_=require("underscore")._}}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;var e;if(d[0]&&d[0] instanceof Array){var b=d[0];for(e=0;e$/,"")+((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["@subject"]=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(f==="@type"&&b.vie.types.get(h)){return b.vie.types.get(h)}else{if(b.vie.entities.get(h)){return b.vie.entities.get(h)}else{return h}}},this)}else{if(typeof g!=="string"){return g}if(f==="@type"&&b.vie.types.get(g)){g=b.vie.types.get(g)}else{if(b.vie.entities.get(g)){g=b.vie.entities.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.addOrUpdate(j);g[h]=j.getSubject()}else{if(i.isCollection){i.each(function(k){b.vie.entities.addOrUpdate(k)})}}}},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.attributes[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=this;_.each(f.attributes,function(j,i){var h=j;if(i==="@type"&&typeof h==="object"){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){var h;f=a(f,b.vie.namespaces);var i=Backbone.Model.prototype.get.call(this,f);if(!i){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);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]*)\\>$");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.length-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"],right:function(e){return function(){return jQuery.rdf.triple(this.subject.toString()+" a ",{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.entity;if(!c){g.resolve([])}var f=function(i){var k=c.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("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}},function(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(!_.isArray(h)){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")!==undefined){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 jQuery(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,j){if(j.attributes&&j.attributes.getNamedItemNS){for(f=0;f","?subject enhancer:entity-type ?type","?subject enhancer:confidence ?confidence","?subject enhancer:entity-reference ?entity","?subject dc:relation ?relation","?relation a ","?relation enhancer:selected-text ?selected-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");this.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=b._enhancer2Entities(b,j);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";_.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,body: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(/^$/,"");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(c,e){if(e!==this.collection){return}if(!this.template||this.template.length===0){return}var b=this.service._registerEntityView(c,this.cloneElement(this.template));var d=b.render().el;if(c.id){this.service.setElementSubject(c.getSubjectUri(),d)}this.el.append(d);var a=this.service;jQuery(d).parent("[rev]").each(function(){var f=jQuery(this).attr("rev");var g={};g[f]=new a.vie.Collection();g[f].addOrUpdate(a.vie.entities.get(a.getElementSubject(this)));c.set(g)});this.trigger("add",b);this.entityViews[c.cid]=b;d.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 +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=this;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=[];_.each(this.services,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==="object"){exports.VIE=VIE;var root=this;var jQuery=this.jQuery;if(!jQuery){jQuery=require("jquery")}var Backbone=root.Backbone;if(!Backbone){Backbone=require("backbone")}var _=this._;if(!_){_=require("underscore")._}}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;var e;if(d[0]&&d[0] instanceof Array){var b=d[0];for(e=0;e$/,"")+((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["@subject"]=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(f==="@type"&&b.vie.types.get(h)){return b.vie.types.get(h)}else{if(b.vie.entities.get(h)){return b.vie.entities.get(h)}else{return h}}},this)}else{if(typeof g!=="string"){return g}if(f==="@type"&&b.vie.types.get(g)){g=b.vie.types.get(g)}else{if(b.vie.entities.get(g)){g=b.vie.entities.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.addOrUpdate(j);g[h]=j.getSubject()}else{if(i.isCollection){i.each(function(k){b.vie.entities.addOrUpdate(k)})}}}},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.attributes[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=this;_.each(f.attributes,function(j,i){var h=j;if(i==="@type"&&typeof h==="object"){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){var h;f=a(f,b.vie.namespaces);var i=Backbone.Model.prototype.get.call(this,f);if(!i){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);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]*)\\>$");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.length-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"],right:function(e){return function(){return jQuery.rdf.triple(this.subject.toString()+" a ",{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.entity;if(!c){g.resolve([])}var f=function(i){var k=c.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("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}},function(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(!_.isArray(h)){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")!==undefined){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 jQuery(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,j){if(j.attributes&&j.attributes.getNamedItemNS){for(f=0;f","?subject enhancer:entity-type ?type","?subject enhancer:confidence ?confidence","?subject enhancer:entity-reference ?entity","?subject dc:relation ?relation","?relation a ","?relation enhancer:selected-text ?selected-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");this.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=b._enhancer2Entities(b,j);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";_.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,body: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(/^$/,"");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(c,e){if(e!==this.collection){return}if(!this.template||this.template.length===0){return}var b=this.service._registerEntityView(c,this.cloneElement(this.template));var d=b.render().el;if(c.id){this.service.setElementSubject(c.getSubjectUri(),d)}this.el.append(d);var a=this.service;jQuery(d).parent("[rev]").each(function(){var f=jQuery(this).attr("rev");var g={};g[f]=new a.vie.Collection();g[f].addOrUpdate(a.vie.entities.get(a.getElementSubject(this)));c.set(g)});this.trigger("add",b);this.entityViews[c.cid]=b;d.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