Introduce corpusByMatch assistant object

Change-Id: Ia23b644e545f9e720de89704be1dc83a79957193
diff --git a/dev/js/runner/all.html b/dev/js/runner/all.html
index c58471c..d2d6f25 100644
--- a/dev/js/runner/all.html
+++ b/dev/js/runner/all.html
@@ -43,6 +43,7 @@
         'spec/panelSpec',
         'spec/pluginSpec',
         'spec/queryCreatorSpec',
+        'spec/corpusByMatchSpec',
         'spec/statSpec',
         'spec/vcSpec'
       ],
diff --git a/dev/js/spec/corpusByMatchSpec.js b/dev/js/spec/corpusByMatchSpec.js
new file mode 100644
index 0000000..d2588b0
--- /dev/null
+++ b/dev/js/spec/corpusByMatchSpec.js
@@ -0,0 +1,50 @@
+/**
+ * Specification for the corpusByMatch assistant.
+ */
+
+function metaTableFactory () {
+  var meta = document.createElement('div');
+  meta.className = 'view metaTable';
+  meta.innerHTML =
+    "    <dl class=\"flex\">" +
+    "      <div>" +
+    "        <dt title=\"author\">author</dt>" +
+    "        <dd>Sprachpfleger, u.a.</dd>" +
+    "      </div>" +
+    "      <div>" +
+    "        <dd class=\"metakeyvalues\">" +
+    "          <div>corenlp</div>" +
+    "          <div>corenlp/constituency</div>" +
+    "          <div>corenlp/morpho</div>" +
+    "          <div>corenlp/sentences</div>" +
+    "          <div>dereko</div>" +
+    "          <div>dereko/structure</div>" +
+    "          <div>dereko/structure/base-sentences-paragraphs-pagebreaks</div>" +
+    "          <div>opennlp</div>" +
+    "          <div>opennlp/morpho</div>" +
+    "          <div>opennlp/sentences</div>" +
+    "        </dd>" +
+    "      </div>" +
+    "    </dl>";
+  var parent = document.createElement("div");
+  parent.appendChild(meta);
+  return meta;
+};
+
+define(['match/corpusByMatch'], function (cbmClass) {  
+  describe('KorAP.CorpusByMatch', function () {
+    it('should be initializable', function () {
+      expect(function () {
+        cbmClass.create()
+      }).toThrow(new Error("Missing parameters"));
+
+      expect(
+	      function() {
+          cbmClass.create("Test")
+        }
+      ).toThrow(new Error("Requires element"));
+
+      expect(cbmClass.create(metaTableFactory()).toString()).toEqual("");
+    });
+  });
+});
diff --git a/dev/js/spec/queryCreatorSpec.js b/dev/js/spec/queryCreatorSpec.js
index 21fffac..5c5cddf 100644
--- a/dev/js/spec/queryCreatorSpec.js
+++ b/dev/js/spec/queryCreatorSpec.js
@@ -2,13 +2,13 @@
  * Specification for the query creator.
  */
 
+
+Element.prototype.innerString = function () {
+  return this.innerText.split("\n").join("");
+};
+
 function matchTableFactory () {
   var table = document.createElement('div');
-
-  Element.prototype.innerString = function () {
-    return this.innerText.split("\n").join("");
-  };
-
   
   table.className = 'matchtable';
   table.innerHTML = 
@@ -131,7 +131,7 @@
       expect(qc.shown()).toBe(false);
       qc.show();
       expect(qc.shown()).toBe(false);
-      expect(qc.element().className).toEqual("queryfragment");
+      expect(qc.element().className).toEqual("query fragment");
 
       // Click on cell 0:0 "Foundry"
       var cell = matchTable.querySelector("thead > tr > th:first-child");
@@ -292,7 +292,7 @@
       expect(qc.shown()).toBe(false);
       qc.show();
       expect(qc.shown()).toBe(false);
-      expect(qc.element().className).toEqual("queryfragment");
+      expect(qc.element().className).toEqual("query fragment");
 
       var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)");
       expect(cell.innerString()).toEqual("ADJA");
@@ -319,7 +319,7 @@
       expect(qc.shown()).toBe(false);
       qc.show();
       expect(qc.shown()).toBe(false);
-      expect(qc.element().className).toEqual("queryfragment");
+      expect(qc.element().className).toEqual("query fragment");
 
       var cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
       expect(cell.innerString()).toEqual("lebende");
@@ -352,7 +352,7 @@
       expect(qc.shown()).toBe(false);
       qc.show();
       expect(qc.shown()).toBe(false);
-      expect(qc.element().className).toEqual("queryfragment");
+      expect(qc.element().className).toEqual("query fragment");
 
       var corenlpRow = matchTable.querySelector("tbody > tr:nth-child(1)");
 
@@ -471,7 +471,7 @@
       expect(qc.shown()).toBe(false);
       qc.show();
       expect(qc.shown()).toBe(false);
-      expect(qc.element().className).toEqual("queryfragment");
+      expect(qc.element().className).toEqual("query fragment");
 
       var cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
       expect(cell.innerString()).toEqual("lebende");
diff --git a/dev/js/src/match/corpusByMatch.js b/dev/js/src/match/corpusByMatch.js
new file mode 100644
index 0000000..1c0bead
--- /dev/null
+++ b/dev/js/src/match/corpusByMatch.js
@@ -0,0 +1,37 @@
+define(['vc/fragment', 'util'], function (vcFragmentClass) {
+  "use strict";
+
+  return {
+    /**
+     * Constructor
+     */
+    create : function (meta) {
+      return Object.create(this)._init(meta);
+    },
+
+    // Initialize corpusByMatch
+    _init : function (meta) {
+      if (meta === undefined) {
+        throw new Error('Missing parameters');
+      }
+      else if (!(meta instanceof Node)) {
+        throw new Error("Requires element");
+      };
+
+      // Collect the meta constraints
+      this._vc = {};
+
+      // Remember the meta table
+      this._meta = meta;
+
+      this._fragment = vcFragmentClass.create();
+
+      return this;
+    },
+
+    // Stringify annotation
+    toString : function () {
+      return '';
+    }
+  };
+});
diff --git a/dev/js/src/match/meta.js b/dev/js/src/match/meta.js
index 8667953..d4b2d7f 100644
--- a/dev/js/src/match/meta.js
+++ b/dev/js/src/match/meta.js
@@ -1,4 +1,4 @@
-define(['util'], function () {
+define(['match/corpusByMatch','util'], function (cbmClass) {
 
   // Localization values
   const loc   = KorAP.Locale;
@@ -55,7 +55,7 @@
         var value = fields[i].value;      	
         metaInfo[fields[i].key] = value;	
       };
-    
+      
       // console.log(fields);   
       
       // TODO: Meta fields should be separated
@@ -63,13 +63,15 @@
       
       for (var i in keys.sort()) {
         var k = keys[i];
+
+        // Ignore internal IDs
         if (k !== "UID" &&
             k !== "corpusID" &&
             k !== "docID" &&
             k !== "textID" &&
             /*
-            k !== "corpusSigle" &&
-            k !== "docSigle" &&
+              k !== "corpusSigle" &&
+              k !== "docSigle" &&
             */
             k !== "layerInfos") {
 
@@ -83,18 +85,20 @@
           metaDD =  metaL.addE('dd');
           
           if(metaDescr instanceof Array){
-        	metaDD.classList.add("metakeyvalues");  
-        	for(i = 0; i < metaDescr.length; i++){
-        	metaDD.addE('div').addT(metaDescr[i]);
-        	} 
+        	  metaDD.classList.add("metakeyvalues");  
+        	  for(i = 0; i < metaDescr.length; i++){
+        	    metaDD.addE('div').addT(metaDescr[i]);
+        	  } 
           }
           else{
-          metaDD.addT(metaInfo[k]);
+            metaDD.addT(metaInfo[k]);
           }
-      
+          
           metaDL.appendChild(metaL);
         };
       };
+
+      this._corpusByMatch = cbmClass.create(this._element);
       return this._element;
     }
   };