You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by sz...@apache.org on 2013/04/12 14:40:45 UTC

svn commit: r1467253 [1/8] - in /stanbol/trunk/demos/webvie: ./ src/license/ src/main/java/org/apache/stanbol/commons/web/vie/fragment/ src/main/resources/META-INF/resources/static/enhancervie/ src/main/resources/META-INF/resources/static/enhancervie/l...

Author: szabyg
Date: Fri Apr 12 12:40:44 2013
New Revision: 1467253

URL: http://svn.apache.org/r1467253
Log:
WebVIE: include a dropdown to select the enhancement chain. Fixes STANBOL-981

Added:
    stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/jquery/jquery-1.8.2.js
    stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/jqueryui/
    stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/jqueryui/jquery-ui.1.9.2.js
    stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/json/
    stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/json/README
    stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/json/json2.js
    stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/vie.entitypreview.js
    stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/vie/vie-2.1.0.debug.js
Removed:
    stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/annotate.coffee
    stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/jquery-1.7.1.js
    stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/jquery-ui.1.9m5.js
    stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/vie/vie-latest.debug.js
    stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/vie/vie-latest.js
Modified:
    stanbol/trunk/demos/webvie/pom.xml
    stanbol/trunk/demos/webvie/src/license/THIRD-PARTY.properties
    stanbol/trunk/demos/webvie/src/main/java/org/apache/stanbol/commons/web/vie/fragment/EnhancerVieWebFragment.java
    stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/annotate.css
    stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/Smoothness/jquery.ui.base.css
    stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/annotate.js
    stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/backbone-min.js
    stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/hallo/format.js
    stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/hallo/hallo.js
    stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/jquery.rdfquery.debug.js
    stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/jquery.rdfquery.min.js
    stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/underscore-min.js
    stanbol/trunk/demos/webvie/src/main/resources/templates/html/org/apache/stanbol/commons/web/vie/resource/EnhancerVieRootResource/index.ftl

Modified: stanbol/trunk/demos/webvie/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/demos/webvie/pom.xml?rev=1467253&r1=1467252&r2=1467253&view=diff
==============================================================================
--- stanbol/trunk/demos/webvie/pom.xml (original)
+++ stanbol/trunk/demos/webvie/pom.xml Fri Apr 12 12:40:44 2013
@@ -57,6 +57,7 @@
       <plugin>
         <groupId>org.apache.rat</groupId>
         <artifactId>apache-rat-plugin</artifactId>
+        <version>0.8</version>
         <configuration>
           <excludes>
             <exclude>.svnignore</exclude>
@@ -64,6 +65,7 @@
             <exclude>src/license/THIRD-PARTY.properties</exclude>
             <!-- rdfQuery has MIT licence -->
             <exclude>src/main/resources/org/apache/stanbol/commons/web/vie/static/lib/jquery.rdfquery.min.js</exclude>
+            <exclude>src/main/resources/META-INF/resources/static/enhancervie/annotate.css</exclude>
             <!--
                 Annotate.js: MIT License
                 underscore.js: MIT license
@@ -82,6 +84,16 @@
             <exclude>src/main/resources/org/apache/stanbol/commons/web/vie/static/test.js</exclude>
             -->
           </excludes>
+            <licenses>
+                <license implementation="org.apache.rat.analysis.license.SimplePatternBasedLicense">
+                    <licenseFamilyCategory>MIT</licenseFamilyCategory>
+                    <licenseFamilyName>The MIT License (MIT)</licenseFamilyName>
+                    <notes></notes>
+                    <patterns>
+                        <pattern>the MIT license</pattern>
+                    </patterns>
+                </license>
+            </licenses>
         </configuration>
       </plugin>
     </plugins>

Modified: stanbol/trunk/demos/webvie/src/license/THIRD-PARTY.properties
URL: http://svn.apache.org/viewvc/stanbol/trunk/demos/webvie/src/license/THIRD-PARTY.properties?rev=1467253&r1=1467252&r2=1467253&view=diff
==============================================================================
--- stanbol/trunk/demos/webvie/src/license/THIRD-PARTY.properties (original)
+++ stanbol/trunk/demos/webvie/src/license/THIRD-PARTY.properties Fri Apr 12 12:40:44 2013
@@ -1,23 +1,27 @@
 # Generated by org.codehaus.mojo.license.AddThirdPartyMojo
 #-------------------------------------------------------------------------------
 # Already used licenses in project :
-# - Apache License
-# - BSD
+# - Apache Software License
+# - Apache Software License, Version 2.0
 # - BSD License
-# - BSD-style license
-# - CDDL 1.1
-# - Common Development and Distribution License (CDDL) v1.0
-# - GPL2 w/ CPE
+# - Common Development And Distribution License (CDDL), Version 1.0
+# - Common Development And Distribution License (CDDL), Version 1.1
+# - Common Public License, Version 1.0
+# - Eclipse Public License, Version 1.0
+# - GNU General Public License (GPL), Version 2 with classpath exception
+# - GNU Lesser General Public License (LGPL)
+# - GNU Lesser General Public License (LGPL), Version 2.1
 # - ICU License
 # - MIT License
-# - The Apache Software License, Version 2.0
+# - New BSD License
+# - Public Domain License
+# - Similar to Apache License but with the acknowledgment clause removed
 #-------------------------------------------------------------------------------
 # Please fill the missing licenses for dependencies :
 #
 #
-#Tue Feb 21 15:51:07 CET 2012
-asm--asm--3.1=BSD License
-javax.servlet--servlet-api--2.4=Common Development And Distribution License (CDDL), Version 1.0
+#Mon Apr 08 19:47:07 CEST 2013
+javax.servlet--servlet-api--2.5=Common Development And Distribution License (CDDL), Version 1.0
 org.codehaus.jettison--jettison--1.3=The Apache Software License, Version 2.0
 org.osgi--org.osgi.compendium--4.1.0=The Apache Software License, Version 2.0
 org.osgi--org.osgi.core--4.1.0=The Apache Software License, Version 2.0

Modified: stanbol/trunk/demos/webvie/src/main/java/org/apache/stanbol/commons/web/vie/fragment/EnhancerVieWebFragment.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/demos/webvie/src/main/java/org/apache/stanbol/commons/web/vie/fragment/EnhancerVieWebFragment.java?rev=1467253&r1=1467252&r2=1467253&view=diff
==============================================================================
--- stanbol/trunk/demos/webvie/src/main/java/org/apache/stanbol/commons/web/vie/fragment/EnhancerVieWebFragment.java (original)
+++ stanbol/trunk/demos/webvie/src/main/java/org/apache/stanbol/commons/web/vie/fragment/EnhancerVieWebFragment.java Fri Apr 12 12:40:44 2013
@@ -82,17 +82,18 @@ public class EnhancerVieWebFragment impl
     @Override
     public List<ScriptResource> getScriptResources() {
         List<ScriptResource> resources = new ArrayList<ScriptResource>();
-        resources.add(new ScriptResource("text/javascript", "lib/jquery-1.7.1.js", this, 10));
-        resources.add(new ScriptResource("text/javascript", "lib/jquery-ui.1.9m5.js", this, 10));
+        resources.add(new ScriptResource("text/javascript", "lib/jquery/jquery-1.8.2.js", this, 10));
+        resources.add(new ScriptResource("text/javascript", "lib/jqueryui/jquery-ui.1.9.2.js", this, 10));
         resources.add(new ScriptResource("text/javascript", "lib/underscore-min.js", this, 10));
         resources.add(new ScriptResource("text/javascript", "lib/backbone.js", this, 10));
 
         resources.add(new ScriptResource("text/javascript", "lib/jquery.rdfquery.debug.js", this, 10));
-        resources.add(new ScriptResource("text/javascript", "lib/vie/vie-latest.debug.js", this, 10));
+        resources.add(new ScriptResource("text/javascript", "lib/vie/vie-2.1.0.debug.js", this, 10));
 
         resources.add(new ScriptResource("text/javascript", "lib/hallo/hallo.js", this, 10));
         resources.add(new ScriptResource("text/javascript", "lib/hallo/format.js", this, 10));
 
+        resources.add(new ScriptResource("text/javascript", "lib/vie.entitypreview.js", this, 10));
         resources.add(new ScriptResource("text/javascript", "lib/annotate.js", this, 10));
 
         return resources;
@@ -101,7 +102,7 @@ public class EnhancerVieWebFragment impl
     @Override
     public List<NavigationLink> getNavigationLinks() {
         List<NavigationLink> links = new ArrayList<NavigationLink>();
-        links.add(new NavigationLink("enhancervie", "/enhancer VIE", htmlDescription, 20));
+        links.add(new NavigationLink("enhancervie", "/enhancer VIE", htmlDescription, 21));
         return links;
     }
 

Modified: stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/annotate.css
URL: http://svn.apache.org/viewvc/stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/annotate.css?rev=1467253&r1=1467252&r2=1467253&view=diff
==============================================================================
--- stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/annotate.css (original)
+++ stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/annotate.css Fri Apr 12 12:40:44 2013
@@ -2,7 +2,7 @@
      (c) 2011 Szaby Gruenwald, IKS Consortium
      Annotate may be freely distributed under the MIT license
 */
-.entity, a[typeof][about] {
+.entity, a[resource] {
 	z-index: -1;
 	padding: 0 3px;
 	background-color: #E0E0E0;
@@ -11,7 +11,7 @@
 	white-space: nowrap;
 	border-width:1px;
 }
-a[typeof][about] {
+a[resource] {
     border-width: 1px 0;
     border-color: rgba(0, 0, 0, 0.8);
     border-style: solid;
@@ -20,13 +20,13 @@ a[typeof][about] {
 .entity.withSuggestions {border-color: rgba(0, 0, 0, 0.8);}
 
 .entity.person, 
-a[typeof][about].person       {background-color: #ffe;}
+a[resource].person       {background-color: #ffe;}
 
 .entity.place,
-a[typeof][about].place        {background-color: #fef;}
+a[resource].place        {background-color: #fef;}
 
 .entity.organisation,
-a[typeof][about].organisation {background-color: #eff;}
+a[resource].organisation {background-color: #eff;}
 
 #loadingDiv {
     position: absolute;

Modified: stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/Smoothness/jquery.ui.base.css
URL: http://svn.apache.org/viewvc/stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/Smoothness/jquery.ui.base.css?rev=1467253&r1=1467252&r2=1467253&view=diff
==============================================================================
--- stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/Smoothness/jquery.ui.base.css (original)
+++ stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/Smoothness/jquery.ui.base.css Fri Apr 12 12:40:44 2013
@@ -1,11 +1,3 @@
-/*
- * jQuery UI Accordion 1.8.13
- *
- * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
- * Dual licensed under the MIT or GPL Version 2 licenses.
- * http://jquery.org/license
- *
- */
 @import url("jquery.ui.core.css");
 @import url("jquery.ui.resizable.css");
 @import url("jquery.ui.selectable.css");
@@ -16,4 +8,4 @@
 @import url("jquery.ui.slider.css");
 @import url("jquery.ui.tabs.css");
 @import url("jquery.ui.datepicker.css");
-@import url("jquery.ui.progressbar.css");
+@import url("jquery.ui.progressbar.css");
\ No newline at end of file

Modified: stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/annotate.js
URL: http://svn.apache.org/viewvc/stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/annotate.js?rev=1467253&r1=1467252&r2=1467253&view=diff
==============================================================================
--- stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/annotate.js (original)
+++ stanbol/trunk/demos/webvie/src/main/resources/META-INF/resources/static/enhancervie/lib/annotate.js Fri Apr 12 12:40:44 2013
@@ -1,12 +1,14 @@
+// Generated by CoffeeScript 1.3.3
 
 /*   Annotate - a text enhancement interaction jQuery UI widget
 #     (c) 2011 Szaby Gruenwald, IKS Consortium
 #     Annotate may be freely distributed under the MIT license
 */
 
+
 (function() {
-  var Backbone, EntityCache, VIE, jQuery, ns, root, uriSuffix, vie, _, _base,
-    __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
+  var Backbone, EntityCache, Stanbol, VIE, delayThrottle, jQuery, ns, root, uriSuffix, vie, _, _base, _ref,
+    __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
 
   ns = {
     rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
@@ -29,13 +31,12 @@
   vie = new VIE();
 
   vie.use(new vie.StanbolService({
-    url: "http://dev.iks-project.eu:8080",
-    proxyDisabled: true
+    url: "http://dev.iks-project.eu:8080"
   }));
 
   vie.namespaces.add("skos", ns.skos);
 
-  if ((_base = String.prototype).trim == null) {
+  if ((_ref = (_base = String.prototype).trim) == null) {
     _base.trim = function() {
       return this.replace(/^\s+|\s+$/g, '');
     };
@@ -49,8 +50,8 @@
     }
 
     EntityCache.prototype._entities = function() {
-      var _ref;
-      return (_ref = window.entityCache) != null ? _ref : window.entityCache = {};
+      var _ref1;
+      return (_ref1 = window.entityCache) != null ? _ref1 : window.entityCache = {};
     };
 
     EntityCache.prototype.get = function(uri, scope, success, error) {
@@ -62,7 +63,9 @@
           success.apply(scope, [this._entities()[uri].entity]);
         }
       } else if (this._entities()[uri] && this._entities()[uri].status === "error") {
-        if (typeof error === "function") error.apply(scope, ["error"]);
+        if (typeof error === "function") {
+          error.apply(scope, ["error"]);
+        }
       } else if (!this._entities()[uri]) {
         this._entities()[uri] = {
           status: "pending",
@@ -76,7 +79,9 @@
             var cacheEntry, entity;
             cacheEntry = _this._entities()[uri];
             entity = _.detect(entityArr, function(e) {
-              if (e.getSubject() === ("<" + uri + ">")) return true;
+              if (e.getSubject() === ("<" + uri + ">")) {
+                return true;
+              }
             });
             if (entity) {
               cacheEntry.entity = entity;
@@ -99,9 +104,13 @@
       }
       if (this._entities()[uri] && this._entities()[uri].status === "pending") {
         return $(this._entities()[uri]).bind("done", function(event, entity) {
-          if (typeof success === "function") return success.apply(scope, [entity]);
+          if (typeof success === "function") {
+            return success.apply(scope, [entity]);
+          }
         }).bind("fail", function(event, error) {
-          if (typeof error === "function") return error.apply(scope, [error]);
+          if (typeof error === "function") {
+            return error.apply(scope, [error]);
+          }
         });
       }
     };
@@ -122,6 +131,8 @@
       vie: vie,
       vieServices: ["stanbol"],
       autoAnalyze: false,
+      continuousChecking: false,
+      throttleDistance: 5000,
       showTooltip: true,
       debug: false,
       depictionProperties: ["foaf:depiction", "schema:thumbnail"],
@@ -196,72 +207,135 @@
         vie: this.options.vie,
         logger: this._logger
       });
-      if (this.options.autoAnalyze) this.enable();
+      if (this.options.autoAnalyze) {
+        this.enable();
+      }
+      if (!jQuery().tooltip) {
+        this.options.showTooltip = false;
+        this._logger.warn("the used jQuery UI doesn't support tooltips, disabling.");
+      }
       return this._initExistingAnnotations();
     },
     _destroy: function() {
       this.disable();
-      $(':IKS-annotationSelector', this.element).each(function() {
+      $(':iks-annotationselector', this.element).each(function() {
         if ($(this).data().annotationSelector) {
           return $(this).annotationSelector('destroy');
         }
       });
       return this._destroyExistingAnnotationInteractionWidgets();
     },
-    enable: function(cb) {
-      var analyzedNode,
+    enable: function() {
+      var checkerFn,
+        _this = this;
+      if (this.options.continuousChecking) {
+        checkerFn = delayThrottle(function() {
+          return _this._checkForChanges();
+        }, this.options.throttleDistance);
+        $(this.element).bind('keyup', function() {
+          return checkerFn();
+        });
+      }
+      return this._checkForChanges();
+    },
+    _checkForChanges: function() {
+      var el, hash, _i, _len, _ref1, _results;
+      _ref1 = this._findElementsToAnalyze();
+      _results = [];
+      for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
+        el = _ref1[_i];
+        hash = this._elementHash(el);
+        if (!jQuery(el).data('hash')) {
+          console.info(el, "wasn't analized yet.");
+          this._analyze(el);
+        }
+        if (jQuery(el).data('hash') && jQuery(el).data('hash') !== hash) {
+          console.info(el, 'changed, try to get annotations for it.');
+          _results.push(this._analyze(el));
+        } else {
+          _results.push(void 0);
+        }
+      }
+      return _results;
+    },
+    _elementHash: function(el) {
+      return jQuery(el).text().hashCode();
+    },
+    _findElementsToAnalyze: function() {
+      return this._listNonblockElements(this.element);
+    },
+    _analyze: function(el) {
+      var hash,
         _this = this;
-      analyzedNode = this.element;
+      hash = this._elementHash(el);
       return this.options.vie.analyze({
-        element: this.element
+        element: jQuery(el)
       }).using(this.options.vieServices).execute().success(function(enhancements) {
-        return _.defer(function() {
-          var entAnn, entityAnnotations, textAnn, textAnnotations, textAnns, _i, _j, _len, _len2, _ref;
-          entityAnnotations = Stanbol.getEntityAnnotations(enhancements);
-          for (_i = 0, _len = entityAnnotations.length; _i < _len; _i++) {
-            entAnn = entityAnnotations[_i];
-            textAnns = entAnn.get("dcterms:relation");
-            if (!textAnns) {
-              _this._logger.error("For " + (entAnn.getSubject()) + " dcterms:relation is not set! This makes this EntityAnnotation unusable!", entAnn);
+        if (_this._elementHash(el) === hash) {
+          console.info('applying suggestions to', el, enhancements);
+          _this._applyEnhancements(el, enhancements);
+          jQuery(el).data('hash', hash);
+        } else {
+          console.info(el, 'changed in the meantime.');
+        }
+        return _this._trigger("success", true);
+      }).fail(function(msg) {
+        _this._trigger('error', msg, {
+          message: msg
+        });
+        return _this._logger.error("analyze failed", msg);
+      });
+    },
+    _applyEnhancements: function(el, enhancements) {
+      var _this = this;
+      return _.defer(function() {
+        var entAnn, entityAnnotations, textAnn, textAnnotations, textAnns, _i, _j, _len, _len1, _ref1;
+        entityAnnotations = Stanbol.getEntityAnnotations(enhancements);
+        for (_i = 0, _len = entityAnnotations.length; _i < _len; _i++) {
+          entAnn = entityAnnotations[_i];
+          textAnns = entAnn.get("dcterms:relation");
+          if (!textAnns) {
+            _this._logger.error("For " + (entAnn.getSubject()) + " dcterms:relation is not set! This makes this EntityAnnotation unusable!", entAnn);
+            continue;
+          }
+          _ref1 = _.flatten([textAnns]);
+          for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
+            textAnn = _ref1[_j];
+            if (!(textAnn instanceof Backbone.Model)) {
+              textAnn = entAnn.vie.entities.get(textAnn);
+            }
+            if (!textAnn) {
               continue;
             }
-            _ref = _.flatten([textAnns]);
-            for (_j = 0, _len2 = _ref.length; _j < _len2; _j++) {
-              textAnn = _ref[_j];
-              if (!(textAnn instanceof Backbone.Model)) {
-                textAnn = entAnn.vie.entities.get(textAnn);
-              }
-              if (!textAnn) continue;
-              _(_.flatten([textAnn])).each(function(ta) {
-                return ta.setOrAdd({
-                  "entityAnnotation": entAnn.getSubject()
-                });
+            _(_.flatten([textAnn])).each(function(ta) {
+              return ta.setOrAdd({
+                "entityAnnotation": entAnn.getSubject()
               });
-            }
+            });
           }
-          textAnnotations = Stanbol.getTextAnnotations(enhancements);
-          textAnnotations = _this._filterByType(textAnnotations);
-          textAnnotations = _(textAnnotations).filter(function(textEnh) {
-            if (textEnh.getSelectedText && textEnh.getSelectedText()) {
-              return true;
-            } else {
-              return false;
-            }
-          });
-          _(textAnnotations).each(function(s) {
-            _this._logger.info(s._enhancement, 'confidence', s.getConfidence(), 'selectedText', s.getSelectedText(), 'type', s.getType(), 'EntityEnhancements', s.getEntityEnhancements());
-            return _this._processTextEnhancement(s, analyzedNode);
-          });
-          _this._trigger("success", true);
-          if (typeof cb === "function") return cb(true);
+        }
+        textAnnotations = Stanbol.getTextAnnotations(enhancements);
+        textAnnotations = _this._filterByType(textAnnotations);
+        textAnnotations = _(textAnnotations).filter(function(textEnh) {
+          if (textEnh.getSelectedText && textEnh.getSelectedText()) {
+            return true;
+          } else {
+            return false;
+          }
+        });
+        return _(textAnnotations).each(function(s) {
+          _this._logger.info(s._enhancement, 'confidence', s.getConfidence(), 'selectedText', s.getSelectedText(), 'type', s.getType(), 'EntityEnhancements', s.getEntityEnhancements());
+          return _this._processTextEnhancement(s, el);
         });
-      }).fail(function(xhr) {
-        if (typeof cb === "function") cb(false, xhr);
-        _this._trigger('error', xhr);
-        return _this._logger.error("analyze failed", xhr.responseText, xhr);
       });
     },
     disable: function() {
+      var el, _i, _len, _ref1;
+      _ref1 = this._findElementsToAnalyze();
+      for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
+        el = _ref1[_i];
+        jQuery.removeData(el, 'hash');
+      }
       return $(':IKS-annotationSelector', this.element).each(function() {
         if ($(this).data().annotationSelector) {
           return $(this).annotationSelector('disable');
@@ -269,12 +343,13 @@
       });
     },
     _initExistingAnnotations: function() {
-      this.existingAnnotations = jQuery("a[about][typeof]", this.element);
-      console.info(this.existingAnnotations);
+      this.existingAnnotations = jQuery("a[resource]", this.element);
+      this._logger.info(this.existingAnnotations);
       return this.existingAnnotations[this.options.annotationInteractionWidget](this.options);
     },
     _destroyExistingAnnotationInteractionWidgets: function() {
-      return this.existingAnnotations[this.options.annotationInteractionWidget]("destroy");
+      this.existingAnnotations[this.options.annotationInteractionWidget]("destroy");
+      return this.existingAnnotations = [];
     },
     acceptAll: function(reportCallback) {
       var report;
@@ -294,14 +369,37 @@
       });
       return reportCallback(report);
     },
+    _listNonblockElements: function(el) {
+      var isDevidable, res,
+        _this = this;
+      isDevidable = function(el) {
+        var child, sum, _i, _len, _ref1;
+        sum = "";
+        _ref1 = jQuery(el).children();
+        for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
+          child = _ref1[_i];
+          sum += jQuery(child).text().replace(/\s\s*/g, "");
+        }
+        return jQuery(el).text().replace(/\s\s*/g, "") === sum;
+      };
+      res = jQuery([]);
+      if (isDevidable(el)) {
+        jQuery(el).children().each(function(i, ch) {
+          return res = res.add(_this._listNonblockElements(ch));
+        });
+      } else {
+        res = res.add(jQuery(el));
+      }
+      return res;
+    },
     _processTextEnhancement: function(textEnh, parentEl) {
-      var eEnh, eEnhUri, el, options, sType, type, widget, _i, _j, _len, _len2, _ref,
+      var eEnh, eEnhUri, el, options, sType, type, widget, _i, _j, _len, _len1, _ref1,
         _this = this;
       if (!textEnh.getSelectedText()) {
         this._logger.warn("textEnh", textEnh, "doesn't have selected-text!");
         return;
       }
-      el = $(this._getOrCreateDomElement(parentEl[0], textEnh.getSelectedText(), {
+      el = $(this._getOrCreateDomElement(parentEl, textEnh.getSelectedText(), {
         createElement: 'span',
         createMode: 'existing',
         context: textEnh.getContext(),
@@ -315,10 +413,12 @@
         type = sType[_i];
         el.addClass(uriSuffix(type).toLowerCase());
       }
-      if (textEnh.getEntityEnhancements().length) el.addClass("withSuggestions");
-      _ref = textEnh.getEntityEnhancements();
-      for (_j = 0, _len2 = _ref.length; _j < _len2; _j++) {
-        eEnh = _ref[_j];
+      if (textEnh.getEntityEnhancements().length) {
+        el.addClass("withSuggestions");
+      }
+      _ref1 = textEnh.getEntityEnhancements();
+      for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
+        eEnh = _ref1[_j];
         eEnhUri = eEnh.getUri();
         this.entityCache.get(eEnhUri, eEnh, function(entity) {
           if (("<" + eEnhUri + ">") === entity.getSubject()) {
@@ -335,22 +435,28 @@
     },
     _filterByType: function(textAnnotations) {
       var _this = this;
-      if (!this.options.typeFilter) return textAnnotations;
+      if (!this.options.typeFilter) {
+        return textAnnotations;
+      }
       return _.filter(textAnnotations, function(ta) {
-        var type, _i, _len, _ref, _ref2;
-        if (_ref = _this.options.typeFilter, __indexOf.call(ta.getType(), _ref) >= 0) {
+        var type, _i, _len, _ref1, _ref2;
+        if (_ref1 = _this.options.typeFilter, __indexOf.call(ta.getType(), _ref1) >= 0) {
           return true;
         }
         _ref2 = _this.options.typeFilter;
         for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
           type = _ref2[_i];
-          if (__indexOf.call(ta.getType(), type) >= 0) return true;
+          if (__indexOf.call(ta.getType(), type) >= 0) {
+            return true;
+          }
         }
       });
     },
     _getOrCreateDomElement: function(element, text, options) {
       var domEl, len, nearest, nearestPosition, newElement, occurrences, pos, start, textContentOf, textToCut;
-      if (options == null) options = {};
+      if (options == null) {
+        options = {};
+      }
       occurrences = function(str, s) {
         var last, next, res, _results;
         res = [];
@@ -390,7 +496,7 @@
         return $(element).text().replace(/\n/g, " ");
       };
       if (textContentOf(element).indexOf(text) === -1) {
-        console.error("'" + text + "' doesn't appear in the text block.");
+        this._logger.error("'" + text + "' doesn't appear in the text block.");
         return $();
       }
       start = options.start + textContentOf(element).indexOf(textContentOf(element).trim());
@@ -421,12 +527,42 @@
           $(domEl).parent()[0].replaceChild(newElement, domEl.splitText(pos));
           return $(newElement);
         } else {
-          return console.warn("dom element creation problem: " + textToCut + " isnt " + text);
+          return this._logger.warn("dom element creation problem: " + textToCut + " isnt " + text);
         }
       }
     }
   });
 
+  String.prototype.hashCode = function() {
+    var char, hash, i;
+    hash = 0;
+    if (this.length === 0) {
+      return hash;
+    }
+    i = 0;
+    while (i < this.length) {
+      char = this.charCodeAt(i);
+      hash = ((hash << 5) - hash) + char;
+      hash = hash & hash;
+      i++;
+    }
+    return hash;
+  };
+
+  delayThrottle = function(cb, timeout) {
+    var resFn, timeoutHandler;
+    timeoutHandler = null;
+    return resFn = function() {
+      if (timeoutHandler) {
+        clearTimeout(timeoutHandler);
+      }
+      return timeoutHandler = setTimeout(function() {
+        timeoutHandler = null;
+        return cb();
+      }, timeout);
+    };
+  };
+
   jQuery.widget("IKS.annotationInteraction", {
     __widgetName: "IKS.annotationInteraction",
     options: {
@@ -485,23 +621,25 @@
         _this = this;
       widget = this;
       this._logger.info("init tooltip for", this.element);
-      return jQuery(this.element).tooltip({
-        items: "[about]",
-        hide: {
-          effect: "hide",
-          delay: 50
-        },
-        show: {
-          effect: "show",
-          delay: 50
-        },
-        content: function(response) {
-          var uri;
-          uri = _this.element.attr("about");
-          _this._logger.info("tooltip uri:", uri);
-          return widget._createPreview(uri);
-        }
-      });
+      if (this.options.showTooltip) {
+        return jQuery(this.element).tooltip({
+          items: "[resource]",
+          hide: {
+            effect: "hide",
+            delay: 50
+          },
+          show: {
+            effect: "show",
+            delay: 50
+          },
+          content: function(response) {
+            var uri;
+            uri = _this.element.attr("resource");
+            _this._logger.info("tooltip uri:", uri);
+            return widget._createPreview(uri);
+          }
+        });
+      }
     },
     _createPreview: function(uri) {
       var depictionUrl, descr, html, picSize;
@@ -521,27 +659,19 @@
       return html;
     },
     _loadEntity: function(callback) {
-      var _this = this;
-      this.vie.use(new this.vie.RdfaService());
+      var uri,
+        _this = this;
+      uri = this.element.attr('resource');
       return this.vie.load({
-        element: this.element
-      }).using("rdfa").execute().success(function(res) {
-        _this._logger.info("found", res, _this.element, _this.vie);
-        return _(res).each(function(entity) {
-          return _this.vie.load({
-            entity: entity.getSubject()
-          }).using("stanbol").execute().success(function(res) {
-            var loadedEntity;
-            loadedEntity = _(res).detect(function(e) {
-              return entity.getSubject() === e.getSubject();
-            });
-            return callback(loadedEntity);
-          }).fail(function(err) {
-            return _this._logger.error("error getting entity from stanbol", err, entity.getSubject());
-          });
+        entity: uri
+      }).using("stanbol").execute().success(function(res) {
+        var loadedEntity;
+        loadedEntity = _(res).detect(function(e) {
+          return e.getSubject().replace(/^<|>$/g, '') === uri;
         });
-      }).fail(function(f) {
-        return _this._logger.error("error reading RDFa", f, _this.element);
+        return callback(loadedEntity);
+      }).fail(function(err) {
+        return _this._logger.error("error getting entity from stanbol", err, entity.getSubject());
       });
     },
     _getUserLang: function() {
@@ -553,12 +683,16 @@
       var depictionUrl, field, fieldValue, preferredFields;
       preferredFields = this.options.depictionProperties;
       field = _(preferredFields).detect(function(field) {
-        if (entity.get(field)) return true;
+        if (entity.get(field)) {
+          return true;
+        }
       });
       if (field && (fieldValue = _([entity.get(field)]).flatten())) {
         depictionUrl = _(fieldValue).detect(function(uri) {
           uri = (typeof uri.getSubject === "function" ? uri.getSubject() : void 0) || uri;
-          if (uri.indexOf("thumb") !== -1) return true;
+          if (uri.indexOf("thumb") !== -1) {
+            return true;
+          }
         }).replace(/[0-9]{2..3}px/, "" + picSize + "px");
         return depictionUrl;
       }
@@ -567,46 +701,13 @@
       var preferredFields, preferredLanguages;
       preferredFields = this.options.labelProperties;
       preferredLanguages = [this._getUserLang(), this.options.fallbackLanguage];
-      return this._getPreferredLangForPreferredProperty(entity, preferredFields, preferredLanguages);
+      return VIE.Util.getPreferredLangForPreferredProperty(entity, preferredFields, preferredLanguages);
     },
     _getDescription: function(entity) {
       var preferredFields, preferredLanguages;
       preferredFields = this.options.descriptionProperties;
       preferredLanguages = [this._getUserLang(), this.options.fallbackLanguage];
-      return this._getPreferredLangForPreferredProperty(entity, preferredFields, preferredLanguages);
-    },
-    _getPreferredLangForPreferredProperty: function(entity, preferredFields, preferredLanguages) {
-      var label, labelArr, lang, property, valueArr, _i, _j, _len, _len2,
-        _this = this;
-      for (_i = 0, _len = preferredLanguages.length; _i < _len; _i++) {
-        lang = preferredLanguages[_i];
-        for (_j = 0, _len2 = preferredFields.length; _j < _len2; _j++) {
-          property = preferredFields[_j];
-          if (typeof property === "string" && entity.get(property)) {
-            labelArr = _.flatten([entity.get(property)]);
-            label = _(labelArr).detect(function(label) {
-              if (typeof label === "string" && label.toString().indexOf("@" + lang) > -1) {
-                true;
-              }
-              if (typeof label === "object" && label["@language"] === lang) {
-                return true;
-              }
-            });
-            if (label) return label.toString().replace(/(^\"*|\"*@..$)/g, "");
-          } else if (typeof property === "object" && entity.get(property.property)) {
-            valueArr = _.flatten([entity.get(property.property)]);
-            valueArr = _(valueArr).map(function(termUri) {
-              if (termUri.isEntity) {
-                return termUri.getSubject();
-              } else {
-                return termUri;
-              }
-            });
-            return property.makeLabel(valueArr);
-          }
-        }
-      }
-      return "";
+      return VIE.Util.getPreferredLangForPreferredProperty(entity, preferredFields, preferredLanguages);
     }
   });
 
@@ -658,17 +759,13 @@
       if (this.isAnnotated()) {
         this._initTooltip();
         this.linkedEntity = {
-          uri: this.element.attr("about"),
-          type: this.element.attr("typeof")
+          uri: this.element.attr("resource")
         };
         return this.options.cache.get(this.linkedEntity.uri, this, function(cachedEntity) {
           var navigatorLanguage, userLang;
           navigatorLanguage = window.navigator.language || window.navigator.userLanguage;
           userLang = navigatorLanguage.split("-")[0];
-          _this.linkedEntity.label = _(cachedEntity.get("rdfs:label")).detect(function(label) {
-            if (label.indexOf("@" + userLang) > -1) return true;
-          }).replace(/(^\"*|\"*@..$)/g, "");
-          return _this._logger.info("did I figure out?", _this.linkedEntity.label);
+          return _this.linkedEntity.label = VIE.Util.getPreferredLangForPreferredProperty(cachedEntity, ["skos:prefLabel", "rdfs:label"], [userLang, "en"]);
         });
       }
     },
@@ -676,7 +773,7 @@
       var _this = this;
       return this.element.click(function(e) {
         _this._logger.log("click", e, e.isDefaultPrevented());
-        if (!_this.dialog) {
+        if (_this.dialog || !_this.dialog) {
           _this._createDialog();
           setTimeout((function() {
             return _this.dialog.open();
@@ -684,7 +781,7 @@
           _this.entityEnhancements = _this._getEntityEnhancements();
           _this._createSearchbox();
           if (_this.entityEnhancements.length > 0) {
-            if (_this.menu === void 0) return _this._createMenu();
+            return _this._createMenu();
           }
         } else {
           return _this.searchEntryField.find('.search').focus(100);
@@ -692,7 +789,7 @@
       });
     },
     disableEditing: function() {
-      return jQuery(this.element).off('click');
+      return jQuery(this.element).unbind('click');
     },
     _destroy: function() {
       this.disableEditing();
@@ -708,13 +805,17 @@
         delete this.dialog;
       }
       this._logger.info("destroy tooltip");
-      if (this.element.data().tooltip) return this.element.tooltip("destroy");
+      if (this.element.data().tooltip) {
+        return this.element.tooltip("destroy");
+      }
     },
     remove: function(event) {
       var el;
       el = this.element.parent();
       this._logger.info("destroy tooltip");
-      if (this.element.data().tooltip) this.element.tooltip("destroy");
+      if (this.element.data().tooltip) {
+        this.element.tooltip("destroy");
+      }
       if (!this.isAnnotated() && this.textEnhancements) {
         this._trigger('decline', event, {
           textEnhancements: this.textEnhancements
@@ -739,23 +840,34 @@
       }
     },
     isAnnotated: function() {
-      if (this.element.attr('about')) {
+      if (this.element.attr('resource')) {
         return true;
       } else {
         return false;
       }
     },
     annotate: function(entityEnhancement, options) {
-      var entityClass, entityHtml, entityType, entityUri, newElement, rel, sType, ui;
+      var entityClass, entityHtml, entityType, entityUri, newElement, rel, sType, type, ui, _i, _len, _ref1, _ref2;
       entityUri = entityEnhancement.getUri();
       entityType = entityEnhancement.getTextEnhancement().getType() || "";
       entityHtml = this.element.html();
       sType = entityEnhancement.getTextEnhancement().getType();
-      if (!sType.length) sType = ["Other"];
+      if (!sType.length) {
+        sType = ["Other"];
+      }
       this.element.attr('xmlns:skos', ns.skos);
       rel = options.rel || "skos:related";
       entityClass = 'entity ' + uriSuffix(sType[0]).toLowerCase();
-      newElement = $("<a href='" + entityUri + "'            about='" + entityUri + "'            typeof='" + entityType + "'            rel='" + rel + "'            class='" + entityClass + "'>" + entityHtml + "</a>");
+      _ref1 = ['Person', 'Place', 'Organisation'];
+      for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
+        type = _ref1[_i];
+        _(sType).each(function(t) {
+          if (t.indexOf(type) !== -1) {
+            return entityClass += " " + type;
+          }
+        });
+      }
+      newElement = $("<a href='" + entityUri + "'            resource='" + entityUri + "'            rel='" + rel + "'            class='" + entityClass + "'>" + entityHtml + "</a>");
       this._cloneCopyEvent(this.element[0], newElement[0]);
       this.linkedEntity = {
         uri: entityUri,
@@ -776,17 +888,25 @@
       };
       this.select(ui);
       this._initTooltip();
-      return jQuery(newElement).annotationSelector(this.options);
+      jQuery(newElement).annotationSelector(this.options);
+      return (_ref2 = this.dialog) != null ? _ref2.close() : void 0;
     },
     select: function(ui) {
-      this._trigger('select', null, ui);
+      var e;
+      e = new jQuery.Event("select");
+      e.ui = ui;
+      this._trigger('select', e, ui);
       return jQuery(this.options.annotateElement).trigger("annotateselect", ui);
     },
     acceptBestCandidate: function() {
       var eEnhancements;
       eEnhancements = this._getEntityEnhancements();
-      if (!eEnhancements.length) return;
-      if (this.isAnnotated()) return;
+      if (!eEnhancements.length) {
+        return;
+      }
+      if (this.isAnnotated()) {
+        return;
+      }
       this.annotate(eEnhancements[0], {
         styleClass: "acknowledged"
       });
@@ -798,9 +918,11 @@
       return this.textEnhancements = this.options.textEnhancements;
     },
     close: function() {
-      var _ref;
-      if ((_ref = this.dialog) != null) {
-        if (typeof _ref.close === "function") _ref.close();
+      var _ref1;
+      if ((_ref1 = this.dialog) != null) {
+        if (typeof _ref1.close === "function") {
+          _ref1.close();
+        }
       }
       return jQuery(".ui-tooltip").remove();
     },
@@ -811,7 +933,7 @@
       if (this.options.showTooltip) {
         this._logger.info("init tooltip for", this.element);
         return jQuery(this.element).tooltip({
-          items: "[about]",
+          items: "[resource]",
           hide: {
             effect: "hide",
             delay: 50
@@ -822,7 +944,7 @@
           },
           content: function(response) {
             var uri;
-            uri = _this.element.attr("about");
+            uri = _this.element.attr("resource");
             _this._logger.info("tooltip uri:", uri);
             widget._createPreview(uri, response);
             return "loading...";
@@ -831,13 +953,13 @@
       }
     },
     _getEntityEnhancements: function() {
-      var eEnhancements, enhancement, textEnh, _i, _j, _len, _len2, _ref, _ref2, _tempUris;
+      var eEnhancements, enhancement, textEnh, _i, _j, _len, _len1, _ref1, _ref2, _tempUris;
       eEnhancements = [];
-      _ref = this.textEnhancements;
-      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
-        textEnh = _ref[_i];
+      _ref1 = this.textEnhancements;
+      for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
+        textEnh = _ref1[_i];
         _ref2 = textEnh.getEntityEnhancements();
-        for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
+        for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
           enhancement = _ref2[_j];
           eEnhancements.push(enhancement);
         }
@@ -864,7 +986,7 @@
       allKnownPrefixes = _(knownMapping).map(function(x) {
         return x.uri;
       });
-      knownPrefixes = _.intersect(allKnownPrefixes, types);
+      knownPrefixes = _.intersection(allKnownPrefixes, types);
       return _(knownPrefixes).map(function(key) {
         var foundPrefix;
         foundPrefix = _(knownMapping).detect(function(x) {
@@ -875,8 +997,12 @@
     },
     _sourceLabel: function(src) {
       var sourceObj, sources;
-      if (!src) console.warn("No source");
-      if (!src) return "";
+      if (!src) {
+        this._logger.warn("No source");
+      }
+      if (!src) {
+        return "";
+      }
       sources = this.options.getSources();
       sourceObj = _(sources).detect(function(s) {
         return src.indexOf(s.uri) !== -1;
@@ -891,7 +1017,8 @@
       var dialogEl, label, widget,
         _this = this;
       label = this.element.text();
-      dialogEl = $("<div><span class='entity-link'></span></div>").attr("tabIndex", -1).addClass().keydown(function(event) {
+      jQuery(".annotateselector-dialog-content").dialog("destroy").remove();
+      dialogEl = $("<div class='annotateselector-dialog-content'><span class='entity-link'></span></div>").attr("tabIndex", -1).addClass().keydown(function(event) {
         if (!event.isDefaultPrevented() && event.keyCode && event.keyCode === $.ui.keyCode.ESCAPE) {
           _this.close(event);
           return event.preventDefault();
@@ -906,18 +1033,15 @@
       widget = this;
       dialogEl.dialog({
         width: 400,
+        dialogClass: 'annotation-selector-dialog',
         title: label,
-        close: function(event, ui) {
-          return _this.close(event);
-        },
         autoOpen: false,
-        open: function(e, ui) {
-          return $.data(this, 'dialog').uiDialog.position({
-            of: widget.element,
-            my: "left top",
-            at: "left bottom",
-            collision: "none"
-          });
+        open: function(e, ui) {},
+        position: {
+          of: this.element,
+          my: "left top",
+          at: "left bottom",
+          collision: "flip"
         }
       });
       this.dialog = dialogEl.data('dialog');
@@ -940,7 +1064,8 @@
         rem: {
           text: this.isAnnotated() ? 'Remove' : 'Decline',
           click: function(event) {
-            return _this.remove(event);
+            _this.remove(event);
+            return _this.close();
           }
         },
         Cancel: function() {
@@ -960,22 +1085,25 @@
       }
     },
     _createMenu: function() {
-      var ul, widget,
+      var selectHandler, ul, widget,
         _this = this;
       widget = this;
-      ul = $('<ul></ul>').appendTo(this.dialog.element);
+      ul = $('<ul class="suggestion-menu"></ul>').appendTo(this.dialog.element);
       this._renderMenu(ul, this.entityEnhancements);
+      selectHandler = function(event, ui) {
+        _this._logger.info("selected menu item", ui.item);
+        _this.annotate(ui.item.data('enhancement'), {
+          styleClass: 'acknowledged'
+        });
+        return _this.close(event);
+      };
       this.menu = ul.menu({
-        select: function(event, ui) {
-          _this._logger.info("selected menu item", ui.item);
-          _this.annotate(ui.item.data('enhancement'), {
-            styleClass: 'acknowledged'
-          });
-          return _this.close(event);
-        },
+        selected: selectHandler,
+        select: selectHandler,
         blur: function(event, ui) {
           return _this._logger.info('menu.blur()', ui.item);
-        }
+        },
+        styleClass: 'suggestion-menu'
       }).focus(150);
       if (this.options.showTooltip) {
         this.menu.tooltip({
@@ -1036,12 +1164,16 @@
       var depictionUrl, field, fieldValue, preferredFields;
       preferredFields = this.options.depictionProperties;
       field = _(preferredFields).detect(function(field) {
-        if (entity.get(field)) return true;
+        if (entity.get(field)) {
+          return true;
+        }
       });
       if (field && (fieldValue = _([entity.get(field)]).flatten())) {
         depictionUrl = _(fieldValue).detect(function(uri) {
           uri = (typeof uri.getSubject === "function" ? uri.getSubject() : void 0) || uri;
-          if (uri.indexOf("thumb") !== -1) return true;
+          if (uri.indexOf("thumb") !== -1) {
+            return true;
+          }
         }).replace(/[0-9]{2..3}px/, "" + picSize + "px");
         return depictionUrl;
       }
@@ -1050,46 +1182,13 @@
       var preferredFields, preferredLanguages;
       preferredFields = this.options.labelProperties;
       preferredLanguages = [this._getUserLang(), this.options.fallbackLanguage];
-      return this._getPreferredLangForPreferredProperty(entity, preferredFields, preferredLanguages);
+      return VIE.Util.getPreferredLangForPreferredProperty(entity, preferredFields, preferredLanguages);
     },
     _getDescription: function(entity) {
       var preferredFields, preferredLanguages;
       preferredFields = this.options.descriptionProperties;
       preferredLanguages = [this._getUserLang(), this.options.fallbackLanguage];
-      return this._getPreferredLangForPreferredProperty(entity, preferredFields, preferredLanguages);
-    },
-    _getPreferredLangForPreferredProperty: function(entity, preferredFields, preferredLanguages) {
-      var label, labelArr, lang, property, valueArr, _i, _j, _len, _len2,
-        _this = this;
-      for (_i = 0, _len = preferredLanguages.length; _i < _len; _i++) {
-        lang = preferredLanguages[_i];
-        for (_j = 0, _len2 = preferredFields.length; _j < _len2; _j++) {
-          property = preferredFields[_j];
-          if (typeof property === "string" && entity.get(property)) {
-            labelArr = _.flatten([entity.get(property)]);
-            label = _(labelArr).detect(function(label) {
-              if (typeof label === "string" && label.toString().indexOf("@" + lang) > -1) {
-                true;
-              }
-              if (typeof label === "object" && label["@language"] === lang) {
-                return true;
-              }
-            });
-            if (label) return label.toString().replace(/(^\"*|\"*@..$)/g, "");
-          } else if (typeof property === "object" && entity.get(property.property)) {
-            valueArr = _.flatten([entity.get(property.property)]);
-            valueArr = _(valueArr).map(function(termUri) {
-              if (termUri.isEntity) {
-                return termUri.getSubject();
-              } else {
-                return termUri;
-              }
-            });
-            return property.makeLabel(valueArr);
-          }
-        }
-      }
-      return "";
+      return VIE.Util.getPreferredLangForPreferredProperty(entity, preferredFields, preferredLanguages);
     },
     _renderMenu: function(ul, entityEnhancements) {
       var enhancement, _i, _len;
@@ -1108,7 +1207,7 @@
       type = this._typeLabels(eEnhancement.getTypes()).toString() || "Other";
       source = this._sourceLabel(eEnhancement.getUri());
       active = this.linkedEntity && eEnhancement.getUri() === this.linkedEntity.uri ? " class='ui-state-active'" : "";
-      return item = $("<li" + active + " entityuri='" + (eEnhancement.getUri()) + "' about='" + (eEnhancement.getUri()) + "'><a>" + label + " <small>(" + type + " from " + source + ")</small></a></li>").data('enhancement', eEnhancement).appendTo(ul);
+      return item = $("<li" + active + " entityuri='" + (eEnhancement.getUri()) + "' resource='" + (eEnhancement.getUri()) + "'><a>" + label + " <small>(" + type + " from " + source + ")</small></a></li>").data('enhancement', eEnhancement).appendTo(ul);
     },
     _createSearchbox: function() {
       var sugg, widget,
@@ -1116,77 +1215,29 @@
       this.searchEntryField = $('<span style="background: fff;"><label for="search">Search:</label> <input id="search" class="search"></span>').appendTo(this.dialog.element);
       sugg = this.textEnhancements[0];
       widget = this;
-      this.searchbox = $('.search', this.searchEntryField).autocomplete({
-        source: function(req, resp) {
-          widget._logger.info("req:", req);
-          return widget.options.vie.find({
-            term: "" + req.term + (req.term.length > 3 ? '*' : '')
-          }).using('stanbol').execute().fail(function(e) {
-            return widget._logger.error("Something wrong happened at stanbol find:", e);
-          }).success(function(entityList) {
-            var _this = this;
-            return _.defer(function() {
-              var limit, res;
-              widget._logger.info("resp:", _(entityList).map(function(ent) {
-                return ent.id;
-              }));
-              limit = 10;
-              entityList = _(entityList).filter(function(ent) {
-                if (ent.getSubject().replace(/^<|>$/g, "") === "http://www.iks-project.eu/ontology/rick/query/QueryResultSet") {
-                  return false;
-                }
-                return true;
-              });
-              res = _(entityList.slice(0, limit)).map(function(entity) {
-                return {
-                  key: entity.getSubject().replace(/^<|>$/g, ""),
-                  label: "" + (widget._getLabel(entity)) + " @ " + (widget._sourceLabel(entity.id)),
-                  _label: widget._getLabel(entity),
-                  getLabel: function() {
-                    return this._label;
-                  },
-                  getUri: function() {
-                    return this.key;
-                  },
-                  _tEnh: sugg,
-                  getTextEnhancement: function() {
-                    return this._tEnh;
-                  }
-                };
-              });
-              return resp(res);
-            });
-          });
-        },
-        open: function(e, ui) {
-          widget._logger.info("autocomplete.open", e, ui);
-          if (widget.options.showTooltip) {
-            return $(this).data().autocomplete.menu.activeMenu.tooltip({
-              items: ".ui-menu-item",
-              hide: {
-                effect: "hide",
-                delay: 50
-              },
-              show: {
-                effect: "show",
-                delay: 50
-              },
-              content: function(response) {
-                var uri;
-                uri = $(this).data()["item.autocomplete"].getUri();
-                widget._createPreview(uri, response);
-                return "loading...";
-              }
-            });
-          }
-        },
+      this.searchbox = $('.search', this.searchEntryField).vieAutocomplete({
+        vie: this.options.vie,
+        urifield: jQuery("#urifield"),
         select: function(e, ui) {
+          var item;
+          item = ui.item;
+          item.getUri = function() {
+            return this.key;
+          };
+          item._tEnh = sugg;
+          item.getTextEnhancement = function() {
+            return this._tEnh;
+          };
+          item.getLabel = function() {
+            return this.label;
+          };
           _this.annotate(ui.item, {
             styleClass: "acknowledged"
           });
           return _this._logger.info("autocomplete.select", e.target, ui);
         }
-      }).focus(200).blur(function(e, ui) {
+      });
+      this.searchEntryField.focus(200).blur(function(e, ui) {
         return _this._dialogCloseTimeout = setTimeout((function() {
           return _this.close();
         }), 200);
@@ -1202,7 +1253,7 @@
       return this._logger.info("show searchbox");
     },
     _cloneCopyEvent: function(src, dest) {
-      if (_(jQuery().jquery).contains("1.6")) {
+      if (jQuery().jquery.indexOf("1.6") === 0) {
         return this._cloneCopyEvent1_6(src, dest);
       } else {
         return this._cloneCopyEvent1_7(src, dest);
@@ -1210,7 +1261,9 @@
     },
     _cloneCopyEvent1_6: function(src, dest) {
       var curData, events, i, internalKey, l, oldData, type;
-      if (dest.nodeType !== 1 || !jQuery.hasData(src)) return;
+      if (dest.nodeType !== 1 || !jQuery.hasData(src)) {
+        return;
+      }
       internalKey = $.expando;
       oldData = $.data(src);
       curData = $.data(dest, oldData);
@@ -1234,7 +1287,9 @@
     },
     _cloneCopyEvent1_7: function(src, dest) {
       var curData, events, i, l, oldData, type;
-      if (dest.nodeType !== 1 || !jQuery.hasData(src)) return;
+      if (dest.nodeType !== 1 || !jQuery.hasData(src)) {
+        return;
+      }
       type = void 0;
       i = void 0;
       l = void 0;
@@ -1253,11 +1308,13 @@
           }
         }
       }
-      if (curData.data) return curData.data = jQuery.extend({}, curData.data);
+      if (curData.data) {
+        return curData.data = jQuery.extend({}, curData.data);
+      }
     }
   });
 
-  if (typeof Stanbol === "undefined" || Stanbol === null) Stanbol = {};
+  Stanbol = Stanbol != null ? Stanbol : {};
 
   Stanbol.getTextAnnotations = function(enhList) {
     var res;
@@ -1293,8 +1350,12 @@
     TextEnhancement.prototype.getSelectedText = function() {
       var res;
       res = this._vals("enhancer:selected-text");
-      if (typeof res === "string") return res;
-      if (typeof res === "object") return res.toString();
+      if (typeof res === "string") {
+        return res;
+      }
+      if (typeof res === "object") {
+        return res.toString();
+      }
     };
 
     TextEnhancement.prototype.getConfidence = function() {
@@ -1305,7 +1366,9 @@
       var rawList,
         _this = this;
       rawList = this._enhancement.get("entityAnnotation");
-      if (!rawList) return [];
+      if (!rawList) {
+        return [];
+      }
       rawList = _.flatten([rawList]);
       return _(rawList).map(function(ee) {
         return new Stanbol.EntityEnhancement(ee, _this);
@@ -1340,15 +1403,17 @@
 
     TextEnhancement.prototype._uriTrim = function(uriRef) {
       var bbColl, mod;
-      if (!uriRef) return [];
+      if (!uriRef) {
+        return [];
+      }
       if (uriRef instanceof Backbone.Model || uriRef instanceof Backbone.Collection) {
         bbColl = uriRef;
         return (function() {
-          var _i, _len, _ref, _results;
-          _ref = bbColl.models;
+          var _i, _len, _ref1, _results;
+          _ref1 = bbColl.models;
           _results = [];
-          for (_i = 0, _len = _ref.length; _i < _len; _i++) {
-            mod = _ref[_i];
+          for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
+            mod = _ref1[_i];
             _results.push(mod.get("@subject").replace(/^<|>$/g, ""));
           }
           return _results;
@@ -1371,6 +1436,7 @@
       this._enhancement = ee;
       this._textEnhancement = textEnh;
       this;
+
     }
 
     EntityEnhancement.prototype.getLabel = function() {
@@ -1396,7 +1462,9 @@
     EntityEnhancement.prototype._vals = function(key) {
       var res;
       res = this._enhancement.get(key);
-      if (!res) return [];
+      if (!res) {
+        return [];
+      }
       if (res.pluck) {
         return res.pluck("@subject");
       } else {
@@ -1406,15 +1474,17 @@
 
     EntityEnhancement.prototype._uriTrim = function(uriRef) {
       var bbColl, mod;
-      if (!uriRef) return [];
+      if (!uriRef) {
+        return [];
+      }
       if (uriRef instanceof Backbone.Collection) {
         bbColl = uriRef;
         return (function() {
-          var _i, _len, _ref, _results;
-          _ref = bbColl.models;
+          var _i, _len, _ref1, _results;
+          _ref1 = bbColl.models;
           _results = [];
-          for (_i = 0, _len = _ref.length; _i < _len; _i++) {
-            mod = _ref[_i];
+          for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
+            mod = _ref1[_i];
             _results.push(mod.getSubject().replace(/^<|>$/g, ""));
           }
           return _results;
@@ -1431,4 +1501,241 @@
 
   })();
 
+  vie = new VIE();
+
+  vie.use(new vie.StanbolService({
+    url: "http://dev.iks-project.eu:8080"
+  }));
+
+  jQuery.widget("IKS.vieAutocomplete", {
+    options: {
+      vie: vie,
+      select: function(e, ui) {},
+      urifield: null,
+      field: "rdfs:label",
+      services: "stanbol",
+      debug: false,
+      showTooltip: true,
+      depictionProperties: ["foaf:depiction", "schema:thumbnail"],
+      labelProperties: ["rdfs:label", "skos:prefLabel", "schema:name", "foaf:name"],
+      descriptionProperties: [
+        "rdfs:comment", "skos:note", "schema:description", "skos:definition", {
+          property: "skos:broader",
+          makeLabel: function(propertyValueArr) {
+            var labels;
+            labels = _(propertyValueArr).map(function(termUri) {
+              return termUri.replace(/<.*[\/#](.*)>/, "$1").replace(/_/g, "&nbsp;");
+            });
+            return "Subcategory of " + (labels.join(', ')) + ".";
+          }
+        }, {
+          property: "dcterms:subject",
+          makeLabel: function(propertyValueArr) {
+            var labels;
+            labels = _(propertyValueArr).map(function(termUri) {
+              return termUri.replace(/<.*[\/#](.*)>/, "$1").replace(/_/g, "&nbsp;");
+            });
+            return "Subject(s): " + (labels.join(', ')) + ".";
+          }
+        }
+      ],
+      stanbolIncludeLocalSite: false,
+      fallbackLanguage: "en",
+      styleClass: "vie-autocomplete",
+      getTypes: function() {
+        return [
+          {
+            uri: "" + this.ns.dbpedia + "Place",
+            label: 'Place'
+          }, {
+            uri: "" + this.ns.dbpedia + "Person",
+            label: 'Person'
+          }, {
+            uri: "" + this.ns.dbpedia + "Organisation",
+            label: 'Organisation'
+          }, {
+            uri: "" + this.ns.skos + "Concept",
+            label: 'Concept'
+          }
+        ];
+      },
+      getSources: function() {
+        return [
+          {
+            uri: "http://dbpedia.org/resource/",
+            label: "dbpedia"
+          }, {
+            uri: "http://sws.geonames.org/",
+            label: "geonames"
+          }
+        ];
+      },
+      source: function(req, resp) {
+        var mergedEntityList, properties, success, waitingfor,
+          _this = this;
+        this._logger.info("req:", req);
+        properties = _.flatten([this.options.labelProperties, this.options.descriptionProperties, this.options.depictionProperties]);
+        properties = _(properties).map(function(prop) {
+          if (typeof prop === "object") {
+            return prop.property;
+          } else {
+            return prop;
+          }
+        });
+        waitingfor = 0;
+        mergedEntityList = [];
+        success = function(entityList) {
+          return _.defer(function() {
+            var limit, res;
+            waitingfor--;
+            _this._logger.info("resp:", _(entityList).map(function(ent) {
+              return ent.id;
+            }));
+            limit = 10;
+            entityList = _(entityList).filter(function(ent) {
+              if (ent.getSubject().replace(/^<|>$/g, "") === "http://www.iks-project.eu/ontology/rick/query/QueryResultSet") {
+                return false;
+              }
+              return true;
+            });
+            mergedEntityList = mergedEntityList.concat(entityList);
+            if (waitingfor === 0) {
+              mergedEntityList = _.sortBy(mergedEntityList, function(e) {
+                var s;
+                s = e.get('<http://stanbol.apache.org/ontology/entityhub/query#score>');
+                if (typeof s === "object") {
+                  s = _.max(s);
+                }
+                return 0 - s;
+              });
+              _this._logger.info(_(mergedEntityList).map(function(e) {
+                var s, uri;
+                uri = e.getSubject();
+                s = e.get('<http://stanbol.apache.org/ontology/entityhub/query#score>');
+                return "" + uri + ": " + s;
+              }));
+              res = _(mergedEntityList.slice(0, limit)).map(function(entity) {
+                return {
+                  key: entity.getSubject().replace(/^<|>$/g, ""),
+                  label: "" + (_this._getLabel(entity)) + " @ " + (_this._sourceLabel(entity.id)),
+                  value: _this._getLabel(entity),
+                  getUri: function() {
+                    return this.key;
+                  }
+                };
+              });
+              return resp(res);
+            }
+          });
+        };
+        waitingfor++;
+        this.options.vie.find({
+          term: "" + req.term + (req.term.length > 3 ? '*' : ''),
+          field: this.options.field,
+          properties: properties
+        }).using(this.options.services).execute().fail(function(e) {
+          return _this._logger.error("Something wrong happened at stanbol find:", e);
+        }).success(success);
+        if (this.options.stanbolIncludeLocalSite) {
+          this._logger.log("stanbolIncludeLocalSite");
+          waitingfor++;
+          return this.options.vie.find({
+            term: "" + req.term + (req.term.length > 3 ? '*' : ''),
+            field: this.options.field,
+            properties: properties,
+            local: true
+          }).using(this.options.services).execute().fail(function(e) {
+            return _this._logger.error("Something wrong happened at stanbol find:", e);
+          }).success(success);
+        }
+      }
+    },
+    _create: function() {
+      this._logger = this.options.debug ? console : {
+        info: function() {},
+        warn: function() {},
+        error: function() {},
+        log: function() {}
+      };
+      this.menuContainer = jQuery("<span class='" + this.options.styleClass + "'/>");
+      this.menuContainer.appendTo('body');
+      return this._instantiateAutocomplete();
+    },
+    _destroy: function() {
+      return this.menuContainer.remove();
+    },
+    _instantiateAutocomplete: function() {
+      var widget,
+        _this = this;
+      widget = this;
+      return this.element.autocomplete({
+        source: function(req, resp) {
+          return _this.options.source.apply(_this, [req, resp]);
+        },
+        open: function(e, ui) {
+          var _this = this;
+          widget._logger.info("autocomplete.open", e, ui);
+          if (widget.options.showTooltip) {
+            return $('.ui-menu-item', $(this).data().autocomplete.menu.activeMenu).each(function() {
+              var item, uri;
+              item = $(this).data()["item.autocomplete"] || $(this).data()["uiAutocompleteItem"] || $(this).data()["ui-autocomplete-item"];
+              uri = item.getUri();
+              return $(this).entitypreview({
+                vie: widget.options.vie,
+                uri: uri
+              });
+            }).first().parent().bind('menufocus', function(e, ui) {
+              console.info('fire focusin');
+              return ui.item.trigger('focusin', ui);
+            });
+          }
+        },
+        focus: function(e, ui) {
+          return console.info("focus", ui);
+        },
+        select: function(e, ui) {
+          $('.ui-menu-item', $(e.target).data().autocomplete.menu.activeMenu).each(function() {
+            return $(this).entitypreview('destroy');
+          });
+          _.defer(function() {
+            _this.options.select(e, ui);
+            _this._logger.info("autocomplete.select", e.target, ui);
+            if (widget.options.urifield) {
+              return widget.options.urifield.val(ui.item.key);
+            }
+          });
+          return true;
+        },
+        appendTo: this.menuContainer
+      });
+    },
+    _getUserLang: function() {
+      return window.navigator.language.split("-")[0];
+    },
+    _getLabel: function(entity) {
+      var preferredFields, preferredLanguages;
+      preferredFields = this.options.labelProperties;
+      preferredLanguages = [this._getUserLang(), this.options.fallbackLanguage];
+      return VIE.Util.getPreferredLangForPreferredProperty(entity, preferredFields, preferredLanguages);
+    },
+    _sourceLabel: function(src) {
+      var sourceObj, sources;
+      if (!src) {
+        this._logger.warn("No source");
+      }
+      if (!src) {
+        return "";
+      }
+      sources = this.options.getSources();
+      sourceObj = _(sources).detect(function(s) {
+        return src.indexOf(s.uri) !== -1;
+      });
+      if (sourceObj) {
+        return sourceObj.label;
+      } else {
+        return src.split("/")[2];
+      }
+    }
+  });
+
 }).call(this);