Added VC.checkRewrite() class method
Change-Id: If8a557a37a59eb850f936bcfd1a591b789f3a933
diff --git a/dev/js/src/init.js b/dev/js/src/init.js
index 16a58ff..81ed093 100644
--- a/dev/js/src/init.js
+++ b/dev/js/src/init.js
@@ -330,10 +330,16 @@
show['collection'] = true;
};
};
+
vcname.onclick = vcclick;
if (show['collection']) {
vcclick.apply();
};
+
+ // Check
+ if (_checkVCrewrite(vcClass)) {
+ console.log("Rewrite!");
+ };
};
@@ -417,3 +423,10 @@
};
return vc;
};
+
+function _checkVCrewrite (vcClass) {
+ if (KorAP.koralQuery !== undefined && KorAP.koralQuery["collection"]) {
+ return vcClass.checkRewrite(KorAP.koralQuery["collection"]);
+ };
+ return false;
+}
diff --git a/dev/js/src/vc.js b/dev/js/src/vc.js
index 3e9f16e..5ba68d1 100644
--- a/dev/js/src/vc.js
+++ b/dev/js/src/vc.js
@@ -176,13 +176,39 @@
},
+ // Check if the virtual corpus contains a rewrite
+ // This is a class method
+ checkRewrite : function (json) {
+
+ // There is a rewrite attribute
+ if (json['rewrites'] !== undefined) {
+ return true;
+ }
+
+ // There is a group to check for rewrites
+ else if (json['@type'] === 'koral:docGroup') {
+ var ops = json['operands'];
+ if (ops === undefined)
+ return false;
+
+ for (var i in ops) {
+
+ // "this" is the class
+ if (this.checkRewrite(ops[i])) {
+ return true;
+ };
+ };
+ };
+ return false;
+ },
+
/**
* Clean the virtual document to uspecified doc.
*/
clean : function () {
if (this._root.ldType() !== "non") {
- this._root.destroy();
- this.root(unspecDocClass.create(this));
+ this._root.destroy();
+ this.root(unspecDocClass.create(this));
};
return this;
},