Add corpusByMatch fragment to VC builder (Issue #27)
Change-Id: I3c7ecb434572412203bb6055b4ce8f2947975306
diff --git a/dev/js/src/vc/fragment.js b/dev/js/src/vc/fragment.js
index a03e845..2d2504d 100644
--- a/dev/js/src/vc/fragment.js
+++ b/dev/js/src/vc/fragment.js
@@ -6,7 +6,7 @@
* @author Nils Diewald
*/
-define(['util'], function () {
+define(['vc/doc', 'util'], function (docClass) {
"use strict";
const loc = KorAP.Locale;
@@ -72,6 +72,7 @@
return;
},
+
/**
* Check, if the fragment contains any constraints
*/
@@ -79,12 +80,6 @@
return this._operands.length > 0 ? false : true;
},
- /**
- * Add fragment constraints to VC.
- */
- mergeWithVC : function () {
- },
-
/**
* Get the element associated with the virtual corpus
@@ -107,6 +102,27 @@
/**
+ * Return operands as document objects
+ */
+ documents : function () {
+ return this._operands.map(
+ function (item) {
+ let doc = docClass.create();
+ doc.key(item[0]);
+ doc.matchop("eq");
+ doc.value(item[1]);
+ if (item[2] === "date") {
+ doc.type("date");
+ }
+ else {
+ doc.type("string");
+ };
+ return doc;
+ }
+ );
+ },
+
+ /**
* Update the whole object based on the underlying data structure
*/
update : function() {
@@ -147,17 +163,22 @@
return this;
},
+
+ /**
+ * Stringification
+ */
toQuery : function () {
if (this._operands.length === 0)
return '';
- let str = '(' + this._operands.map(
+ return this._operands.map(
function (item) {
+ if (item[2] === "date") {
+ return item[0] + ' in ' + item[1];
+ };
return item[0] + ' = "' + new String(item[1]).quote() + '"';
}
).join(" & ");
-
- return str + ')';
}
}
});