Add rewrite test as method to vc

Change-Id: I87ac48fdbf9d4c75ce09c4456460d1ede56b9034
diff --git a/dev/js/spec/vcSpec.js b/dev/js/spec/vcSpec.js
index 81e3f8a..87442bd 100644
--- a/dev/js/spec/vcSpec.js
+++ b/dev/js/spec/vcSpec.js
@@ -1594,6 +1594,61 @@
       vc = vcClass.create().fromJson({"@type" : "koral:doc", "key" : "author", "value" : "Peter"});
       expect(vc.getName()).toEqual(KorAP.Locale.VC_oneCollection);
     });
+
+    it('should check for rewrites', function () {
+
+      var vc = vcClass.create().fromJson({
+        "@type" : "koral:doc",
+        "key" : "author",
+        "value" : "Goethe",
+        "rewrites" : [{
+          "@type" : "koral:rewrite",
+          "operation" : "operation:modification",
+          "src" : "querySerializer",
+          "scope" : "value"
+        }]
+      });
+      expect(vc.wasRewritten()).toBeTruthy();
+
+      var nested = {
+        "@type" : "koral:docGroup",
+        "operation" : "operation:or",
+        "operands" : [
+          {
+            "@type" : "koral:doc",
+            "key" : "author",
+            "value" : "Goethe"
+          },
+          {
+            "@type" : "koral:docGroup",
+            "operation" : "operation:and",
+            "operands" : [
+              {
+                "@type": "koral:doc",
+                "key" : "author",
+                "value" : "Schiller"
+              },
+              {
+                "@type": "koral:doc",
+                "key" : "author",
+                "value" : "Fontane"
+              }
+            ]
+          }
+        ]
+      };
+      vc = vcClass.create().fromJson(nested);
+      expect(vc.wasRewritten()).toBe(false);
+
+      nested["operands"][1]["operands"][1]["rewrites"] = [{
+        "@type" : "koral:rewrite",
+        "operation" : "operation:modification",
+        "src" : "querySerializer",
+        "scope" : "tree"
+      }];
+      vc = vcClass.create().fromJson(nested);
+      expect(vc.wasRewritten()).toBeTruthy();
+    });
   });
 
 
@@ -2318,7 +2373,9 @@
   });
 
   // Check class method
-  describe('KorAP.VC.checkRewrite', function () {
+  xdescribe('KorAP.VC.checkRewrite', function () {
+
+    // Class method is deprecated!
     
     it('should check for simple rewrites', function () {
       expect(vcClass.checkRewrite(
diff --git a/dev/js/src/vc.js b/dev/js/src/vc.js
index 5d2b498..3259083 100644
--- a/dev/js/src/vc.js
+++ b/dev/js/src/vc.js
@@ -207,6 +207,35 @@
 
       return this;
     },
+
+
+    // Check if the virtual corpus contains a rerite
+    wasRewritten : function (obj) {
+
+      var obj;
+      if (arguments.length === 1) {
+        obj = arguments[0];
+      }
+      else {
+        obj = this._root;
+      };
+
+      // Check for rewrite
+      if (obj.rewrites() && obj.rewrites().length() > 0) {
+        return true;
+      }
+
+      // Check recursively
+      else if (obj.ldType() === 'docGroup') {
+        for (var i in obj.operands()) {
+          if (this.wasRewritten(obj.getOperand(i))) {
+            return true;
+          }
+        };
+      };
+
+      return false;
+    },
     
     // Check if the virtual corpus contains a rewrite
     // This is a class method
diff --git a/dev/js/src/vc/doc.js b/dev/js/src/vc/doc.js
index 7c4f98a..2d38b56 100644
--- a/dev/js/src/vc/doc.js
+++ b/dev/js/src/vc/doc.js
@@ -42,6 +42,7 @@
 
       if (obj === undefined) {
         console.log(json);
+        return;
       };
 
       // Bind the parent
diff --git a/dev/js/src/vc/docgroupref.js b/dev/js/src/vc/docgroupref.js
index f1c1851..905faf8 100644
--- a/dev/js/src/vc/docgroupref.js
+++ b/dev/js/src/vc/docgroupref.js
@@ -9,6 +9,9 @@
   'util'
 ], function (jsonldClass, rewriteListClass, stringValClass) {
 
+  // TODO:
+  //   Does not support rewrites currently
+  
   const loc = KorAP.Locale;
   loc.EMPTY = loc.EMPTY || '⋯';
 
diff --git a/dev/js/src/vc/jsonld.js b/dev/js/src/vc/jsonld.js
index 545652b..600a5bb 100644
--- a/dev/js/src/vc/jsonld.js
+++ b/dev/js/src/vc/jsonld.js
@@ -95,6 +95,10 @@
       };
     },
 
+    rewrites : function () {
+      return null;
+    },
+
     toQuery : function () {
       return '';
     }
diff --git a/dev/js/src/vc/rewritelist.js b/dev/js/src/vc/rewritelist.js
index 8e68fa0..9a87e4e 100644
--- a/dev/js/src/vc/rewritelist.js
+++ b/dev/js/src/vc/rewritelist.js
@@ -23,6 +23,10 @@
       return this;
     },
 
+    length : function () {
+      return this._list.length;
+    },
+
     /**
      * Get element.
      */