Author: szabyg
Date: Tue Mar  6 08:56:24 2012
New Revision: 1297389

URL: http://svn.apache.org/viewvc?rev=1297389&view=rev
Log:
Updateing VIE and Annotate.js. Resolves STANBOL-523

Modified:
    
incubator/stanbol/trunk/demos/webvie/src/main/resources/org/apache/stanbol/commons/web/vie/static/lib/annotate.js
    
incubator/stanbol/trunk/demos/webvie/src/main/resources/org/apache/stanbol/commons/web/vie/static/lib/jquery.rdfquery.debug.js
    
incubator/stanbol/trunk/demos/webvie/src/main/resources/org/apache/stanbol/commons/web/vie/static/lib/jquery.rdfquery.min.js
    
incubator/stanbol/trunk/demos/webvie/src/main/resources/org/apache/stanbol/commons/web/vie/static/lib/vie/vie-latest.debug.js
    
incubator/stanbol/trunk/demos/webvie/src/main/resources/org/apache/stanbol/commons/web/vie/static/lib/vie/vie-latest.js

Modified: 
incubator/stanbol/trunk/demos/webvie/src/main/resources/org/apache/stanbol/commons/web/vie/static/lib/annotate.js
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/demos/webvie/src/main/resources/org/apache/stanbol/commons/web/vie/static/lib/annotate.js?rev=1297389&r1=1297388&r2=1297389&view=diff
==============================================================================
--- 
incubator/stanbol/trunk/demos/webvie/src/main/resources/org/apache/stanbol/commons/web/vie/static/lib/annotate.js
 (original)
+++ 
incubator/stanbol/trunk/demos/webvie/src/main/resources/org/apache/stanbol/commons/web/vie/static/lib/annotate.js
 Tue Mar  6 08:56:24 2012
@@ -1063,9 +1063,14 @@
           if (typeof property === "string" && entity.get(property)) {
             labelArr = _.flatten([entity.get(property)]);
             label = _(labelArr).detect(function(label) {
-              if (label.indexOf("@" + lang) > -1) return true;
+              if (typeof label === "string" && label.indexOf("@" + lang) > -1) 
{
+                true;
+              }
+              if (typeof label === "object" && label["@lang"] === lang) {
+                return true;
+              }
             });
-            if (label) return label.replace(/(^\"*|\"*@..$)/g, "");
+            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) {
@@ -1281,7 +1286,10 @@
     }
 
     TextEnhancement.prototype.getSelectedText = function() {
-      return this._vals("enhancer:selected-text");
+      var res;
+      res = this._vals("enhancer:selected-text");
+      if (typeof res === "string") return res;
+      if (typeof res === "object") return res.toString();
     };
 
     TextEnhancement.prototype.getConfidence = function() {
@@ -1361,7 +1369,7 @@
     }
 
     EntityEnhancement.prototype.getLabel = function() {
-      return this._vals("enhancer:entity-label").replace(/(^\"*|\"*@..$)/g, 
"");
+      return 
this._vals("enhancer:entity-label").toString().replace(/(^\"*|\"*@..$)/g, "");
     };
 
     EntityEnhancement.prototype.getUri = function() {

Modified: 
incubator/stanbol/trunk/demos/webvie/src/main/resources/org/apache/stanbol/commons/web/vie/static/lib/jquery.rdfquery.debug.js
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/demos/webvie/src/main/resources/org/apache/stanbol/commons/web/vie/static/lib/jquery.rdfquery.debug.js?rev=1297389&r1=1297388&r2=1297389&view=diff
==============================================================================
--- 
incubator/stanbol/trunk/demos/webvie/src/main/resources/org/apache/stanbol/commons/web/vie/static/lib/jquery.rdfquery.debug.js
 (original)
+++ 
incubator/stanbol/trunk/demos/webvie/src/main/resources/org/apache/stanbol/commons/web/vie/static/lib/jquery.rdfquery.debug.js
 Tue Mar  6 08:56:24 2012
@@ -1299,7 +1299,7 @@
         return bindings === null ? null : { bindings: bindings, triples: 
[triple] };
       });
     },
-
+    
     mergeMatches = function (existingMs, newMs, optional) {
       return $.map(existingMs, function (existingM, i) {
         var compatibleMs = $.map(newMs, function (newM) {
@@ -1654,21 +1654,20 @@
       }
       documentQueue[databank.id][url] = undefined;
     },
-
+    
     unique = function( b ) {
-      var a = [];
-      var l = b.length;
-      for(var i=0; i<l; i++) {
-        for(var j=i+1; j<l; j++) {
-          // If b[i] is found later in the array
-          if (b[i] === b[j])
-            j = ++i;
-        }
-        a.push(b[i]);
-      }
-      return a;
-     };
-
+       var a = [];
+       var l = b.length;
+       for(var i=0; i<l; i++) {
+         for(var j=i+1; j<l; j++) {
+           // If b[i] is found later in the array
+           if (b[i] === b[j])
+             j = ++i;
+         }
+         a.push(b[i]);
+     }
+     return a;
+   };
 
   $.typedValue.types['http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral'] 
= {
     regex: /^.*$/m,
@@ -2280,6 +2279,7 @@
      *   });
      */
     sources: function () {
+         
       return $($.map(this.matches, function (match) {
         // return an array-of-an-array because arrays automatically get 
expanded by $.map()
         return [match.triples];
@@ -2446,8 +2446,8 @@
       return $(this).children('*').rdf(callback);
     } else if ($(this).length > 0) {
       triples = $(this).map(function (i, elem) {
-        return $.map($.rdf.gleaners, function (gleaner) {
-          return gleaner.call($(elem), { callback: callback });
+        return $.map($.rdf.gleaners, function (g) {
+          return g.gleaner.call($(elem), { callback: callback });
         });
       });
       return $.rdf({ triples: triples, namespaces: $(this).xmlns() });
@@ -2462,11 +2462,8 @@
       var j = $(a),
         resource = m[3] ? j.safeCurie(m[3]) : null,
         isAbout = false;
-      $.each($.rdf.gleaners, function (i, gleaner) {
-        isAbout = gleaner.call(j, { about: resource });
-        if (isAbout) {
-          return null;
-        }
+      $.each($.rdf.gleaners, function (i, g) {
+        isAbout |= g.gleaner.call(j, { about: resource });
       });
       return isAbout;
     },
@@ -2475,15 +2472,31 @@
       var j = $(a),
         type = m[3] ? j.curie(m[3]) : null,
         isType = false;
-      $.each($.rdf.gleaners, function (i, gleaner) {
-        if (gleaner.call(j, { type: type })) {
-          isType = true;
-          return null;
-        }
+      $.each($.rdf.gleaners, function (i, g) {
+          isType |= g.gleaner.call(j, {  type: type });
       });
       return isType;
-    }
+    },
 
+       itemid: function (a, i, m) {
+      var j = $(a),
+        resource = m[3] ? j.safeCurie(m[3]) : null,
+        isItemid = false;
+      $.each($.rdf.gleaners, function (i, g) {
+        isItemid |= g.gleaner.call(j, { itemid: resource });
+      });
+      return isItemid;
+    },
+       
+       itemtype: function (a, i, m) {
+      var j = $(a),
+        type = m[3] ? j.curie(m[3]) : null,
+        isType = false;
+      $.each($.rdf.gleaners, function (i, g) {
+          isType |= g.gleaner.call(j, {  itemtype: type });
+      });
+      return isType;
+    }
   });
 
   /**
@@ -2674,22 +2687,22 @@
         striples.splice($.inArray(triple, striples), 1);
         if($(striples).size() === 0) {
             delete this.subjectIndex[triple.subject];
-        }
+        }              
       }
       ptriples = this.propertyIndex[triple.property];
       if (ptriples !== undefined) {
         ptriples.splice($.inArray(triple, ptriples), 1);
         if($(ptriples).size() === 0) {
             delete this.propertyIndex[triple.property];
-        }
+        }              
       }
       if (triple.object.type === 'uri' || triple.object.type === 'bnode') {
         otriples = this.objectIndex[triple.object];
         if (otriples !== undefined) {
           otriples.splice($.inArray(triple, otriples), 1);
-          if($(ptriples).size() === 0) {
-            delete this.objectIndex[triple.object];
-          }
+          if($(otriples).size() === 0) {
+              delete this.objectIndex[triple.object];
+          }              
         }
       }
       removeFromDatabankQueries(this, triple);
@@ -3546,8 +3559,7 @@
                  !/^\s*([\-\+]?INF|NaN)\s*$/.test(value)) {  // INF, -INF and 
NaN aren't valid literals in Turtle
         $.extend(this, $.typedValue(value, xsdNs + 'double'));
       } else {
-          var newValue = value.replace(/(.)"(.)/g, "$1\\\"$2");
-        m = literalRegex.exec(newValue);
+        m = literalRegex.exec(value);
         if (m !== null) {
           this.value = (m[2] || m[4]).replace(/\\"/g, '"').replace(/\\n/g, 
'\n').replace(/\\t/g, '\t').replace(/\\r/g, '\r');
           if (m[9]) {
@@ -3658,7 +3670,8 @@
                 if (o.lang !== undefined) {
                   opts.lang = o.lang;
                 }
-                object = $.rdf.literal('"' + o.value + '"', opts);
+                var escapedValue = typeof o.value === "string" ? 
o.value.replace(/\"/g,'\\"') : o.value;
+                object = $.rdf.literal('"' + escapedValue + '"', opts);
               }
             }
             triples.push($.rdf.triple(subject, property, object));
@@ -3703,6 +3716,641 @@
  *  jquery.rdf.xml.js
  */
 /**
+ * @fileOverview jQuery Turtle parser
+ * @author <a href="mailto:[email protected]";>Jeni Tennison</a>
+ * @copyright (c) 2008,2009 Jeni Tennison
+ * @license MIT license (MIT-LICENSE.txt)
+ * @version 1.0
+ */
+/**
+ * @exports $ as jQuery
+ */
+/**
+ * @ignore
+ */
+(function ($) {
+  var
+    wsRegex = /^(\u0009|\u000A|\u000D|\u0020|#([^\u000A\u000D])*)+/,
+    nameStartChars = 
'A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD',
 // can't include \u10000-\uEFFFF
+    nameChars = '-' + nameStartChars + '0-9\u00B7\u0300-\u036F\u203F-\u2040',
+    nameRegex = new RegExp('^[' + nameStartChars + '][' + nameChars + ']*'),
+    uriRegex = 
/^(\\u[0-9A-F]{4}|\\U[0-9A-F]{8}|\\\\|\\>|[\u0020-\u003D\u003F-\u005B\u005D-\u10FFFF])*/,
+    booleanRegex = /^(true|false)[\s\.;,)\]]/,
+    doubleRegex = 
/^(-|\+)?([0-9]+\.[0-9]*[eE](-|\+)?[0-9]+|\.[0-9]+[eE](-|\+)?[0-9]+|[0-9]+[eE](-|\+)?[0-9]+)/,
+    decimalRegex = /^(-|\+)?(([0-9]+\.[0-9]*)|(\.[0-9]))+/,
+    integerRegex = /^(-|\+)?[0-9]+/,
+    stringRegex = 
/^(\\u[0-9A-F]{4}|\\U[0-9A-F]{8}|\\\\|[\u0020-\u0021\u0023-\u005B]|[\u005D-\u10FFFF]|\\t|\\n|\\r|\\")*/,
+    longStringRegex = 
/^(\\u[0-9A-F]{4}|\\U[0-9A-F]{8}|\\\\|[\u0020-\u0021\u0023-\u005B]|[\u005D-\u10FFFF]|\\t|\\n|\\r|\\"|\u0009|\u000A|\u000D|"[^"]|""[^"])*/,
+    languageRegex = /^[a-z]+(-[a-z0-9]+)*/,
+  
+    log = function (message) {
+      //console.log(message);
+    },
+  
+    unescape = function (string) {
+      return 
string.replace(/(\\u([0-9A-F]{4}))|(\\U([0-9A-F]{4})([0-9A-F]{4}))/g, function 
(m, u4, u4h, u8, u8h1, u8h2) {
+        if (u4 !== undefined) {
+          return String.fromCharCode(parseInt(u4h, 16));
+        } else {
+          return String.fromCharCode(parseInt(u8h1, 16)) + 
String.fromCharCode(parseInt(u8h2, 16));
+        }
+      });
+    },
+  
+    require = function (data, str) {
+      if (data.substring(0, str.length) === str) {
+        return data.substring(str.length);
+      } else {
+        throw "Invalid Turtle: Expecting '" + str + "', found '" + 
data.substring(0, 20) + "...'";
+      }
+    },
+  
+    ws = function (data, opts) {
+      var required;
+      opts = opts || {};
+      required = opts.required || false;
+      if (required && !wsRegex.test(data)) {
+        throw("Invalid Turtle: Required whitespace is missing!");
+      }
+      return data.replace(wsRegex, '');
+    },
+
+    uriref = function (data, opts) {
+      var uri;
+      log('uriref: ' + data);
+      data = require(data, '<');
+      uri = uriRegex.exec(data)[0];
+      data = data.substring(uri.length);
+      data = require(data, '>');
+      return {
+        remainder: data,
+        uri: $.uri.resolve(uri, opts.base)
+      };
+    },
+
+    name = function (data, opts) {
+      var result;
+      log('name: ' + data);
+      if (nameRegex.test(data)) {
+        result = nameRegex.exec(data);
+        return {
+          name: result[0],
+          remainder: data.substring(result[0].length)
+        };
+      } else {
+        return {
+          name: '',
+          remainder: data
+        }
+      }
+    },
+
+    prefixName = function (data, opts) {
+      var n = name(data, opts);
+      log('prefixName: ' + data);
+      if (n.name.substring(0, 1) === '_') {
+        throw "Invalid Turtle: Prefix must not start with an underscore: " + 
name;
+      } else {
+        return {
+          prefix: n.name,
+          remainder: n.remainder
+        };
+      }
+    },
+
+    directive = function (data, opts) {
+      var parsed, prefix, uri;
+      log('directive: ' + data);
+      if (data.substring(0, 7) === '@prefix') {
+        data = data.substring(7);
+        data = ws(data, { required: true });
+        parsed = prefixName(data, opts);
+        prefix = parsed.prefix;
+        data = parsed.remainder;
+        data = ws(data);
+        data = require(data, ':');
+        data = ws(data);
+        parsed = uriref(data, opts);
+        opts.namespaces[prefix] = parsed.uri;
+        data = parsed.remainder;
+      } else if (data.substring(0, 5) === '@base') {
+        data = require(data, '@base');
+        data = ws(data, { required: true });
+        parsed = uriref(data, opts);
+        opts.base = parsed.uri;
+        data = parsed.remainder;
+      } else {
+        throw ("Invalid Turtle: Unrecognised directive: " + data);
+      }
+      data = ws(data);
+      data = require(data, '.');
+      return {
+        remainder: data,
+        opts: opts,
+        triples: []
+      };
+    },
+
+    itemList = function (data, opts) {
+      var parsed, items = [], triples = [], first = data.substring(0, 1);
+      log('itemList: ' + data);
+      while (first !== ')') {
+        parsed = object(data, opts);
+        data = parsed.remainder;
+        items.push(parsed.object);
+        triples = triples.concat(parsed.triples);
+        data = ws(data);
+        first = data.substring(0, 1);
+      }
+      return {
+        remainder: data,
+        items: items,
+        triples: triples
+      };
+    },
+
+    collection = function (data, opts) {
+      var parsed, i, items, triples, list, rest = $.rdf.nil;
+      log('collection: ' + data);
+      data = require(data, '(');
+      data = ws(data);
+      parsed = itemList(data, opts);
+      data = parsed.remainder;
+      items = parsed.items;
+      triples = parsed.triples;
+      for (i = items.length - 1; i >= 0; i -= 1) {
+        list = $.rdf.blank('[]');
+        triples.push($.rdf.triple(list, $.rdf.first, items[i]));
+        triples.push($.rdf.triple(list, $.rdf.rest, rest));
+        rest = list;
+      }
+      data = ws(data);
+      data = require(data, ')');
+      return {
+        remainder: data,
+        collection: rest,
+        triples: triples
+      };
+    },
+
+    blank = function (data, opts) {
+      var parsed, bnode, first = data.substring(0, 1);
+      log('blank: ' + data);
+      if (first === '_') {
+        data = require(data, '_:');
+        parsed = name(data, opts);
+        return {
+          remainder: parsed.remainder,
+          blank: $.rdf.blank('_:' + parsed.name),
+          triples: []
+        }
+      } else if (first === '(') {
+        parsed = collection(data, opts);
+        return {
+          remainder: parsed.remainder,
+          blank: parsed.collection,
+          triples: parsed.triples
+        };
+      } else if (data.substring(0, 2) === '[]') {
+        return {
+          remainder: data.substring(2),
+          blank: $.rdf.blank('[]'),
+          triples: []
+        };
+      } else {
+        bnode = $.rdf.blank('[]');
+        opts.subject.unshift(bnode);
+        data = require(data, '[');
+        data = ws(data);
+        parsed = predicateObjectList(data, opts);
+        data = parsed.remainder;
+        data = ws(data);
+        data = require(data, ']');
+        opts.subject.shift();
+        return {
+          remainder: data,
+          blank: bnode,
+          triples: parsed.triples
+        };
+      }
+    },
+
+    subject = function (data, opts) {
+      var parsed, first = data.substring(0, 1);
+      log('subject: ' + data);
+      if (first === '[' || first === '_' || first === '(') {
+        parsed = blank(data, opts);
+        return {
+          remainder: parsed.remainder,
+          subject: parsed.blank,
+          triples: parsed.triples
+        };
+      } else {
+        parsed = resource(data, opts);
+        return {
+          remainder: parsed.remainder,
+          subject: parsed.resource,
+          triples: []
+        };
+      }
+    },
+
+    resource = function (data, opts) {
+      var parsed, prefix, local, first = data.substring(0, 1);
+      log('resource: ' + data);
+      if (first === '<') {
+        parsed = uriref(data, opts);
+        return {
+          remainder: parsed.remainder,
+          resource: $.rdf.resource(parsed.uri, opts.base)
+        };
+      } else {
+        try {
+          parsed = prefixName(data, opts);
+          prefix = parsed.prefix;
+          data = parsed.remainder;
+        } catch (e) {
+          prefix = '';
+        }
+        data = require(data, ':');
+        parsed = name(data, opts);
+        local = parsed.name;
+        return {
+          remainder: parsed.remainder,
+          resource: $.rdf.resource(prefix + ':' + local, { namespaces: 
opts.namespaces, base: opts.base })
+        };
+      }
+    },
+
+    quotedString = function (data, opts) {
+      var str;
+      log('quotedString: ' + data);
+      if (data.substring(0, 3) === '"""') {
+        data = require(data, '"""');
+        str = longStringRegex.exec(data)[0];
+        data = data.substring(str.length);
+        str = str
+          .replace(/\n/g, '\\n')
+          .replace(/\t/g, '\\t')
+          .replace(/\r/g, '\\r')
+          .replace(/\\"/g, '"');
+        str = unescape(str);
+        data = require(data, '"""');
+        return {
+          remainder: data,
+          string: str
+        };
+      } else {
+        data = require(data, '"');
+        str = stringRegex.exec(data)[0];
+        data = data.substring(str.length);
+        str = str.replace(/\\"/g, '"');
+        str = unescape(str);
+        data = require(data, '"');
+        return {
+          remainder: data,
+          string: str
+        };
+      }
+    },
+
+    language = function (data, opts) {
+      var lang;
+      log('language: ' + data);
+      lang = languageRegex.exec(data)[0];
+      return {
+        remainder: data.substring(lang.length),
+        language: lang
+      }
+    },
+
+    literal = function (data, opts) {
+      var first, str;
+      log('literal: ' + data);
+      if (booleanRegex.test(data)) {
+        str = booleanRegex.exec(data)[1];
+        return {
+          remainder: data.substring(str.length),
+          literal: $.rdf.literal(str, { datatype: 
'http://www.w3.org/2001/XMLSchema#boolean' })
+        }
+      } else if (doubleRegex.test(data)) {
+        str = doubleRegex.exec(data)[0];
+        return {
+          remainder: data.substring(str.length),
+          literal: $.rdf.literal(str, { datatype: 
'http://www.w3.org/2001/XMLSchema#double' })
+        };
+      } else if (decimalRegex.test(data)) {
+        str = decimalRegex.exec(data)[0];
+        return {
+          remainder: data.substring(str.length),
+          literal: $.rdf.literal(str, { datatype: 
'http://www.w3.org/2001/XMLSchema#decimal' })
+        };
+      } else if (integerRegex.test(data)) {
+        str = integerRegex.exec(data)[0];
+        return {
+          remainder: data.substring(str.length),
+          literal: $.rdf.literal(str, { datatype: 
'http://www.w3.org/2001/XMLSchema#integer' })
+        };
+      } else {
+        parsed = quotedString(data, opts);
+        data = parsed.remainder;
+        str = parsed.string;
+        data = ws(data);
+        first = data.substring(0, 1);
+        if (first === '^') {
+          data = require(data, '^^');
+          data = ws(data);
+          parsed = resource(data, opts);
+          return {
+            remainder: parsed.remainder,
+            literal: $.rdf.literal(str, { datatype: parsed.resource.value })
+          };
+        } else if (first === '@') {
+          data = require(data, '@');
+          data = ws(data);
+          parsed = language(data, opts);
+          return {
+            remainder: parsed.remainder,
+            literal: $.rdf.literal(str, { lang: parsed.language })
+          };
+        } else {
+          return {
+            remainder: data,
+            literal: $.rdf.literal('"' + str.replace(/"/g, '\\"') + '"')
+          };
+        }
+      }
+    },
+
+    verb = function (data, opts) {
+      var parsed, first = data.substring(0, 1);
+      log('verb: ' + data);
+      try {
+        parsed = resource(data, opts);
+        return {
+          remainder: parsed.remainder,
+          verb: parsed.resource
+        };
+      } catch (e) {
+        if (first === 'a') {
+          data = ws(data.substring(1), { required: true });
+          return {
+            remainder: data,
+            verb: $.rdf.type
+          };
+        } else {
+          throw e;
+        }
+      }
+    },
+
+    object = function (data, opts) {
+      var parsed, o, first = data.substring(0, 1);
+      log('object: ' + data);
+      if (first === '[' || first === '_' || first === '(') {
+        parsed = blank(data, opts);
+        return {
+          remainder: parsed.remainder,
+          object: parsed.blank,
+          triples: parsed.triples
+        };
+      } else {
+        try {
+          parsed = literal(data, opts);
+          return {
+            remainder: parsed.remainder,
+            object: parsed.literal,
+            triples: []
+          };
+        } catch (e) {
+          parsed = resource(data, opts);
+          return {
+            remainder: parsed.remainder,
+            object: parsed.resource,
+            triples: []
+          };
+        }
+      }
+    },
+
+    objectList = function (data, opts) {
+      var parsed, obj, triple, triples = [], first = data.substring(0, 1);
+      log('objectList: ' + data);
+      do {
+        parsed = object(data, opts);
+        data = parsed.remainder;
+        triples = triples.concat(parsed.triples);
+        triple = $.rdf.triple(opts.subject[0], opts.verb[0], parsed.object);
+        triples.push(triple);
+        data = ws(data);
+        first = data.substring(0, 1);
+        if (first === ',') {
+          data = require(data, ',');
+          data = ws(data);
+          first = data.substring(0, 1);
+        } else {
+          break;
+        }
+      } while (first !== ']' && first !== ';' && first !== '.');
+      return {
+        remainder: data,
+        triples: triples
+      };
+    },
+
+    predicateObjectList = function (data, opts) {
+      var parsed, property, objects, triples = [], first = data.substring(0, 
1);
+      log('predicateObjectList: ' + data);
+      do {
+        parsed = verb(data, opts);
+        data = parsed.remainder;
+        property = parsed.verb;
+        data = ws(data);
+        opts.verb.unshift(property);
+        parsed = objectList(data, opts);
+        data = parsed.remainder;
+        triples = triples.concat(parsed.triples);
+        opts.verb.shift();
+        data = ws(data);
+        first = data.substring(0, 1);
+        if (first === ';') {
+          data = require(data, ';');
+          data = ws(data);
+          first = data.substring(0, 1);
+        } else {
+          break;
+        }
+      } while (first !== ']' && first !== '.');
+      return {
+        remainder: data,
+        triples: triples
+      };
+    },
+
+    triples = function (data, opts) {
+      var parsed, triples = [];
+      log('triples: ' + data);
+      parsed = subject(data, opts);
+      data = parsed.remainder;
+      opts.subject.unshift(parsed.subject);
+      triples = parsed.triples;
+      data = ws(data);
+      parsed = predicateObjectList(data, opts);
+      opts.subject.shift();
+      data = ws(parsed.remainder);
+      data = require(data, '.');
+      return {
+        remainder: data,
+        opts: opts,
+        triples: triples.concat(parsed.triples)
+      };
+    },
+  
+    statement = function (data, opts) {
+      var first, parsed;
+      log('statement: ' + data);
+      data = ws(data);
+      if (data.length === 0) {
+        return { remainder: '', opts: opts, triples: [] };
+      } else {
+        first = data.substring(0, 1);
+        if (first === '@') {
+          return directive(data, opts);
+        } else {
+          return triples(data, opts);
+        }
+      }
+    },
+  
+    parseTurtle = function (data, opts) {
+      var base, ns = {}, parsed = {}, triples = [];
+      opts = opts || {};
+      opts.namespaces = {};
+      opts.base = opts.base || $.uri.base();
+      opts.subject = [];
+      opts.verb = [];
+      while (data !== '') {
+        log('parseTurtle: ' + data);
+        parsed = statement(data, opts);
+        data = parsed.remainder;
+        opts = parsed.opts;
+        triples = triples.concat(parsed.triples);
+      } 
+      return triples;
+    },
+  
+    createTurtle = function (triples, options) {
+      var dump = $.rdf.parsers['application/json'].dump(triples),
+        namespaces = options.namespaces || {},
+        indent = options.indent || false,
+        firstP, prefix,
+        s, p, v, i,
+        result = '';
+      for (prefix in namespaces) {
+        result += '@prefix ' + prefix + ': <' + namespaces[prefix] + '> . ';
+        if (indent) {
+          result += '\n';
+        }
+      }
+      for (s in dump) {
+        if (indent) {
+          result += '\n';
+        }
+        if (s.substring(0, 2) === '_:') {
+          result += s;
+        } else {
+          try {
+            result += $.createCurie(s, { namespaces: namespaces });
+          } catch (e) {
+            result += '<' + s + '>';
+          }
+        }
+        result += ' ';
+        firstP = true;
+        for (p in dump[s]) {
+          if (indent) {
+            result += '\n  ';
+          }
+          firstP = false;
+          if (p === $.rdf.type.value.toString()) {
+            result += 'a';
+          } else {
+            try {
+              result += $.createCurie(p, { namespaces: namespaces });
+            } catch (f) {
+              result += '<' + p + '>';
+            }
+          }
+          result += ' ';
+          for (i = 0; i < dump[s][p].length; i += 1) {
+            if (i > 0 && indent) {
+              result += '\n    ';
+            }
+            v = dump[s][p][i];
+            if (v.type === 'uri') {
+              try {
+                result += $.createCurie(v.value, { namespaces: namespaces });
+              } catch (g) {
+                result += '<' + v.value + '>';
+              }
+            } else if (v.type === 'bnode') {
+              result += v.value;
+            } else {
+              result += '"' + v.value + '"';
+              if (v.lang) {
+                result += '@' + v.lang;
+              }
+              if (v.datatype) {
+                result += '^^';
+                try {
+                  result += $.createCurie(v.datatype, { namespaces: namespaces 
});
+                } catch (h) {
+                  result += '<' + v.datatype + '>';
+                }
+              }
+            }
+            result += ' , ';
+          }
+          result = result.substring(0, result.length - 3);
+          result += ' ; ';
+        }
+        result = result.substring(0, result.length - 3);
+        result += ' . ';
+        if (indent) {
+          result += '\n';
+        }
+      }
+      return result;
+    };
+
+  $.rdf.parsers['text/turtle'] = {
+    parse: function (data) {
+      return data;
+    },
+    serialize: function (dump) {
+      return dump;
+    },
+    triples: parseTurtle,
+    dump: createTurtle
+  };
+
+})(jQuery);
+/*
+ * jQuery RDF @VERSION
+ *
+ * Copyright (c) 2008,2009 Jeni Tennison
+ * Licensed under the MIT (MIT-LICENSE.txt)
+ *
+ * Depends:
+ *  jquery.uri.js
+ *  jquery.xmlns.js
+ *  jquery.datatype.js
+ *  jquery.curie.js
+ *  jquery.rdf.js
+ *  jquery.rdf.json.js
+ *  jquery.rdf.xml.js
+ */
+/**
  * @fileOverview jQuery RDF/XML parser
  * @author <a href="mailto:[email protected]";>Jeni Tennison</a>
  * @copyright (c) 2008,2009 Jeni Tennison
@@ -3992,7 +4640,7 @@
             p.prefix !== 'xml') {
           if (p.namespaceURI !== rdfNs) {
             property = $.rdf.resource('<' + p.namespaceURI + getLocalName(p) + 
'>');
-            object = $.rdf.literal(literalOpts.lang ? p.nodeValue : '"' + 
p.nodeValue + '"', literalOpts);
+            object = $.rdf.literal(literalOpts.lang ? p.nodeValue : '"' + 
p.nodeValue.replace(/"/g, '\\"') + '"', literalOpts);
             triples.push($.rdf.triple(subject, property, object));
           } else if (getLocalName(p) === 'type') {
             property = $.rdf.type;
@@ -4012,8 +4660,8 @@
             property = $.rdf.resource('<' + p.namespaceURI + getLocalName(p) + 
'>');
           }
           lang = getAttributeNS(p, 'http://www.w3.org/XML/1998/namespace', 
'lang') || parentLang;
-           if (lang !== null && lang !== undefined && lang !== '') {
-             literalOpts = { lang: lang };
+          if (lang !== null && lang !== undefined && lang !== '') {
+            literalOpts = { lang: lang };
           } else {
             literalOpts = {};
           }
@@ -4077,7 +4725,7 @@
               }
             }
           } else if (hasAttributeNS(p, rdfNs, 'datatype')) {
-            o = p.childNodes[0].nodeValue;
+            o = p.childNodes[0].nodeValue ? p.childNodes[0].nodeValue : "";
             object = $.rdf.literal(o, { datatype: getAttributeNS(p, rdfNs, 
'datatype') });
           } else if (p.getElementsByTagName('*').length > 0) {
             for (j = 0; j < p.childNodes.length; j += 1) {
@@ -4094,7 +4742,7 @@
             }
           } else if (p.childNodes.length > 0) {
             o = p.childNodes[0].nodeValue;
-            object = $.rdf.literal(literalOpts.lang ? o : '"' + o + '"', 
literalOpts);
+            object = $.rdf.literal(literalOpts.lang ? o : '"' + 
o.replace(/"/g, '\\"') + '"', literalOpts);
           } else {
             oTriples = parseRdfXmlDescription(p, false, base, lang);
             if (oTriples.length > 0) {
@@ -4718,13 +5366,13 @@
       return elem;
     },
 
-    addRDFa = function (triple, namespaces) {
+    addRDFa = function (triple) {
       var hasContent, hasRelation, hasRDFa, overridableObject, span,
         subject, sameSubject,
         object, sameObject,
         lang, content,
-        i, atts;
-      var ns = (namespaces)? namespaces : this.xmlns();
+        i, atts,
+        ns = this.xmlns();
       span = this;
       atts = getAttributes(this).atts;
       if (typeof triple === 'string') {
@@ -4959,7 +5607,7 @@
    *  var span = $('#main > p > span');
    *  span.rdfa('&lt;> dc:date "2008-10-19"^^xsd:date .');
    */
-  $.fn.rdfa = function (triple, ns) {
+  $.fn.rdfa = function (triple) {
     if (triple === undefined) {
       var triples = $.map($(this), function (elem) {
         return rdfa.call($(elem));
@@ -4967,7 +5615,7 @@
       return $.rdf({ triples: triples });
     } else {
       $(this).each(function () {
-        addRDFa.call($(this), triple, ns);
+        addRDFa.call($(this), triple);
       });
       return this;
     }
@@ -4997,7 +5645,311 @@
     return this;
   };
 
-  $.rdf.gleaners.push(gleaner);
+  $.rdf.gleaners.push({
+      name: "rdfa",
+      gleaner: gleaner
+  });
+
+})(jQuery);
+/*
+ * jQuery Microdata @VERSION
+ *
+ * Copyright (c) 2011 Sebastian Germesin
+ * Licensed under the MIT (MIT-LICENSE.txt)
+ *
+ * Depends:
+ *  jquery.uri.js
+ *  jquery.xmlns.js
+ *  jquery.curie.js
+ *  jquery.datatype.js
+ *  jquery.rdf.js
+ */
+/**
+ * @fileOverview jQuery Microdata processing
+ * @author <a href="mailto:[email protected]";>Sebastian Germesin</a>
+ * @copyright (c) 2008,2009 Sebastian Germesin
+ * @license MIT license (MIT-LICENSE.txt)
+ * @version 1.0
+ * @requires jquery.uri.js
+ * @requires jquery.xmlns.js
+ * @requires jquery.curie.js
+ * @requires jquery.datatype.js
+ * @requires jquery.rdf.js
+ */
+(function ($) {
+
+  var
+    ns = {
+        schema: "http://schema.org/";
+    },
+    
+    getSubjectFromElement = function () {
+        if (this.attr('itemid')) {
+            return $.rdf.resource('<' + this.attr('itemid') + '>');
+        } else {
+            return $.rdf.blank('[]');
+        }
+    },
+    
+    getTypeFromElement = function () {
+        var type = this.attr('itemtype');
+        if (type) {
+            return $.rdf.resource('<' + type + '>');
+        } else {
+      //TODO: implement me
+            return $.rdf.resource('<' + ns.schema + 'Thing>');
+        }
+    },
+    
+    getPropertyFromElement = function () {
+        var prop = this.attr('itemprop');
+        if (prop) {
+      //TODO: implement me
+            return $.rdf.resource('<' + ns.schema + prop + '>');
+        } 
+        return undefined;
+    },
+    
+    resolveURL = function (str) {
+      //TODO: implement me
+      return '<' + str + '>';  
+    },
+    
+    getValueFromElement = function () {
+        var tag = this.get(0).nodeName.toLowerCase();
+        var value;
+        if (tag === 'meta') {
+            return $.rdf.literal(this.attr('content') === undefined ? '""' : 
this.attr('content'));
+        } else if (tag === 'audio' || 
+            tag === 'embed' || 
+            tag === 'iframe' || 
+            tag === 'img' || 
+            tag === 'source' || 
+            tag === 'track' || 
+            tag === 'video') {
+                if (this.attr('src')) {
+                    return $.rdf.resource(resolveURL(this.attr('src')));
+                } else {
+                   return $.rdf.resource('<>');
+                }
+        } else if (tag === 'a' || 
+            tag === 'area' || 
+            tag === 'link') {
+                if (this.attr('href')) {
+                    return $.rdf.resource(resolveURL(this.attr('href')));
+                } else {
+                   return $.rdf.resource('<>');
+                }
+        } else if (tag === 'object') {
+                if (this.attr('data')) {
+                    return $.rdf.resource(resolveURL(this.attr('data')));
+                } else {
+                   return $.rdf.resource('<>');
+                }
+        } else if (tag === 'time' && this.attr('datetime') !== undefined) {
+           if (this.attr('datetime')) {
+                return $.rdf.literal('"' + this.attr('datetime') + '"');
+            } else {
+               return $.rdf.literal('""');
+            }
+        } else {
+            return $.rdf.literal('"' + this.text() + '"');
+        }
+    },
+    
+    extractProperties = function (context) {
+        var triples = [];
+                
+        //there are two types of properties
+        // (1 - the easy ones): literals
+        var property = getPropertyFromElement.call(this);
+        if (property !== undefined) {
+            if (this.attr('itemscope') === undefined) {
+                var value = getValueFromElement.call(this);
+                
+                var triple = $.rdf.triple(
+                    context.subject,
+                    property,
+                    value, {namespaces: ns});
+                
+                triples.push(triple);
+            }
+            else {
+                // (2 - the more complex ones): resources
+                //recursively call extractResource to parse the triples
+                                
+                var res = extractResource.call(this, {
+                    subject: context.subject,
+                    property: property
+                });
+                triples = triples.concat(res.triples);
+                return triples;
+            }
+        }
+        
+        //search for children with properties
+        var propertyTriples = $.map(this.children(), function (elem) {
+            return extractProperties.call($(elem), context);
+        });
+        triples = triples.concat(propertyTriples);
+        return triples;
+    },
+    
+    extractResource = function (context) {
+        var triples = [];
+        
+        if (!context) {
+            context =  {};
+        }
+        
+        var subject = getSubjectFromElement.call(this);
+        //add possible back-reference
+        if (context.subject && context.property) {
+            triples.push(
+                $.rdf.triple(
+                    context.subject, 
+                    context.property, 
+                    subject, {namespaces: ns}));
+        }
+       
+
+        //get type of element
+        var type = getTypeFromElement.call(this);
+        triples.push(
+                $.rdf.triple(
+                    subject, 
+                    $.rdf.type, 
+                    type, {namespaces: ns}));
+       
+       //query for referenced items and add triples recursively
+        if (this.attr('itemref') !== undefined) {
+            var selector = $.map(this.attr('itemref').split(" "), 
+            function (n, i) {
+                return "#" + n;
+            })
+            .join(", ");
+            var referencedProperties = extractProperties.call($(selector), {
+                subject: subject
+            });
+            triples = triples.concat(referencedProperties);
+        }
+               
+        //parse children for properties (recursively)!
+        var propertyTriples = $.map(this.children(), function (elem) {
+            return extractProperties.call($(elem), {subject: subject});
+        });
+        triples = triples.concat(propertyTriples);
+        
+        return {
+            triples: triples
+        };
+    },
+    
+    microdata = function (context) {
+        //only call .microdata on an element with 'itemscope' attribute
+        if (this.attr('itemscope') === undefined) {
+            console.log("[DEBUG]", "No itemscope attribute found!");
+            return [];
+        }
+        else {
+            var triples = extractResource.call($(this)).triples;
+            console.log("[DEBUG]", "Extracted ", triples.length, " 
triple(s)!", triples);
+            return triples;
+        }
+    },
+    
+    gleaner = function (options) {
+      if (options && options.about !== undefined) {
+          if (options.about === null) {
+              return this.attr('itemprop') !== undefined ||
+                     this.attr('itemref') !== undefined ||
+                     this.attr('itemtype') !== undefined;
+          } else {
+              return getSubjectFromElement.call(this) === options.about;
+          }
+      } else if (options && options.type !== undefined) {
+          var type = getTypeFromElement.call(this);
+          if (type !== undefined) {
+              return options.type === null ? true : (type === options.type);
+          }
+          return false;
+      } else {
+          return microdata.call(this, options);
+      }
+    },
+
+    addMicrodata = function (triple) {
+      //TODO: implement me!
+      return this;
+    },
+
+    removeMicrodata = function (what) {
+      //TODO: implement me!
+      return this;
+    };
+
+  /**
+   * Creates a {@link jQuery.rdf} object containing the RDF triples parsed 
from the microdata found in the current 
+   * jQuery selection or adds the specified triple as microdata markup on each 
member of the current jQuery selection.
+   * To create an {@link jQuery.rdf} object, you will usually want to use 
{@link jQuery#rdf} instead, as this may 
+   * perform other useful processing (such as of microformats used within the 
page).
+   * @methodOf jQuery#
+   * @name jQuery#microdata
+   * @param {jQuery.rdf.triple} [triple] The RDF triple to be added to each 
item in the jQuery selection.
+   * @returns {jQuery.rdf}
+   * @example
+   * // Extract microdata markup from all span elements contained inside #main
+   * rdf = $('#main > span').microdata();
+   * @example
+   * // Add microdata markup to a particular element
+   *  var span = $('#main > p > span');
+   *  span.microdata('&lt;> name "Test Name" .');
+   */
+  $.fn.microdata = function (triple, ns) {
+    if (triple === undefined) {
+      var triples = $.map($(this), function (elem) {
+        return microdata.call($(elem));
+      });
+      return $.rdf({ triples: triples });
+    } else {
+      $(this).each(function () {
+        addMicrodata.call($(this), triple, ns);
+      });
+      return this;
+    }
+  };
+
+  /**
+   * Removes the specified microdata markup from each of the items in the 
current jQuery selection. The input parameter
+   * can be either an object or an array of objects. The objects can either 
have a <code>type</code> property, in which 
+   * case the specified type is removed from the microdata provided on the 
selected elements, or a <code>property</code> property,
+   * in which case the specified property is removed from the microdata 
provided on the selected elements.
+   * @methodOf jQuery#
+   * @name jQuery#removeMicrodata
+   * @param {Object|Object[]} triple The microdata markup items to be removed
+   * from the items in the jQuery selection.
+   * @returns {jQuery} The original jQuery object.
+   * @example 
+   * // To remove a property resource or relation from an element 
+   * $('#main > p > a').removeMicrodata({ itemprop: "creator" });
+   * @example
+   * // To remove a type from an element
+   * $('#main >p > a').removeMicrodata({ itemtype: "http://schema.org/Person"; 
});
+   * @example
+   * // To remove multiple triples from an element
+   * $('#main > p > a').removeMicrodata([{ itemprop: "depicts" }, { itemprop: 
"creator" }]);
+   */
+  $.fn.removeMicrodata = function (triple) {
+    $(this).each(function () {
+      removeMicrodata.call($(this), triple);
+    });
+    return this;
+  };
+
+  $.rdf.gleaners.push({
+      name: "microdata",
+      gleaner: gleaner
+  });
 
 })(jQuery);
 /*
@@ -5335,7 +6287,12 @@
               }
               blankNodeNum += 1;
             } else if ($.isFunction(this.rhs)) {
-              q.map(this.rhs);
+                               var results = q.map(this.rhs);
+                               for (var t = 0; t < results.length; t++) {
+                    if ((results[t]) instanceof $.rdf.triple) {
+                        query.add(results[t]);
+                    }
+                }
             } else {
               for (j = 0; j < this.rhs.length; j += 1) {
                 q.add(this.rhs[j]);


Reply via email to