Adopt API for meta data
Change-Id: I1615261a765325516a1b838bd87075de480556f3
diff --git a/dev/demo/matchdemo.js b/dev/demo/matchdemo.js
index 8f99e6c..185d28b 100644
--- a/dev/demo/matchdemo.js
+++ b/dev/demo/matchdemo.js
@@ -157,6 +157,11 @@
"</span>"+
"<span class=\"context-right\"></span>";
+ var meta = {"messages":[["Response format is temporary"]],"@context":"http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld","meta":{},"document":{"@type":"koral:document","fields":[{"@type":"koral:field","type":"type:store","key":"ref","value":"My reference"},{"@type":"koral:field","type":"type:text","key":"title","value":"Der Name der Rose"},{"@type":"koral:field","type":"type:string","key":"textSigle","value":"a/b/c"},{"@type":"koral:field","type":"type:string","key":"keyword","value":["baum","wald"]},{"@type":"koral:field","type":"type:number","key":"zahl1","value":56},{"@type":"koral:field","type":"type:string","key":"name","value":"Peter"}]}};
+
+ meta = {"messages":[["Response format is temporary"]],"@context":"http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld","meta":{},"document":{"@type":"koral:document","fields":[{"@type":"koral:field","type":"type:number","key":"pubDate","value":20170701},{"@type":"koral:field","type":"type:string","key":"textSigle","value":"WDD17/982/72848"},{"@type":"koral:field","type":"type:string","key":"foundries","value":"dereko dereko/structure dereko/structure/base-sentences-paragraphs-pagebreaks lwc lwc/dependency treetagger treetagger/morpho"},{"@type":"koral:field","type":"type:string","key":"corpusSigle","value":"WDD17"},{"@type":"koral:field","type":"type:string","key":"docSigle","value":"WDD17/982"},{"@type":"koral:field","type":"type:store","key":"reference","value":"Diskussion:99 Namen Allahs/Archiv/1, In: Wikipedia - URL:http://de.wikipedia.org/wiki/Diskussion:99_Namen_Allahs/Archiv/1: Wikipedia, 2017"},{"@type":"koral:field","type":"type:text","key":"author","value":"ArchivBot, u.a."},{"@type":"koral:field","type":"type:number","key":"creationDate","value":20140609},{"@type":"koral:field","type":"type:string","key":"textTypeArt","value":"Diskussion"},{"@type":"koral:field","type":"type:store","key":"editor","value":"wikipedia.org"},{"@type":"koral:field","type":"type:text","key":"title","value":"Diskussion:99 Namen Allahs/Archiv/1"},{"@type":"koral:field","type":"type:store","key":"tokenSource","value":"base#tokens"},{"@type":"koral:field","type":"type:store","key":"layerInfos","value":"dereko/s=spans lwc/d=rels tt/l=tokens tt/p=tokens"},{"@type":"koral:field","type":"type:string","key":"textClass","value":"staat-gesellschaft biographien-interviews"},{"@type":"koral:field","type":"type:string","key":"availability","value":"CC-BY-SA"}]}}
+
+
// var treeSnippet = "<span class=\"context-left\"><\/span><span class=\"match\">In diesem <span title=\"cnx\/c:np\">Sinne<\/span> schrieb <span title=\"cnx\/c:np\">Brunschwicg<\/span>:"In <span title=\"cnx\/c:np\">Euklids<\/span> <span title=\"cnx\/c:np\">Elementen<\/span> <span title=\"cnx\/c:np\">spiegel<\/span> sich die <span title=\"cnx\/c:np\">Resultate<\/span> der <span title=\"cnx\/c:np\">Arbeit von Generationen vor Aristoteles<\/span> wider, nicht nur die <span title=\"cnx\/c:np\">technische Arbeit<\/span> der <span title=\"cnx\/c:np\">Entdecklung<\/span>, sondern auch die <span title=\"cnx\/c:np\">methodologische Arbeit<\/span> der <span title=\"cnx\/c:np\">Verbindung<\/span> und des <span title=\"cnx\/c:np\">Beweises<\/span>, die, in der <span title=\"cnx\/c:np\">Schule<\/span> des <span title=\"cnx\/c:np\">Phythagoras<\/span> begonnen, ihre <span title=\"cnx\/c:np\">Vollendung in den Schulen von Eudoxos von Cnidus<\/span> und <span title=\"cnx\/c:np\">Platon<\/span> gefunden hat"(5<\/span><span class=\"context-right\"><\/span>";
KorAP.API.getMatchInfo = function(match, callObj, cb) {
@@ -173,4 +178,8 @@
return cb({ "snippet": snippet });
}
};
+
+ KorAP.API.getTextInfo = function(doc, callObj, cb) {
+ return cb(meta);
+ };
});
diff --git a/dev/js/src/api.js b/dev/js/src/api.js
index 89534be..b87eb1f 100644
--- a/dev/js/src/api.js
+++ b/dev/js/src/api.js
@@ -57,6 +57,25 @@
/**
+ * Retrieve information about a document.
+ */
+ KorAP.API.getTextInfo = function (doc, param, cb) {
+
+ // doc is a KorAP.Match object
+ var url = KorAP.URL;
+ url += '/' + match.textSigle;
+
+ if (param['fields'] !== undefined) {
+ url += '?fields='; // TODO!
+ }
+ else {
+ url += '?fields=@all';
+ }
+ KorAP.API.getJSON(url, cb);
+ };
+
+
+ /**
* Retrieve information about collections
*/
KorAP.API.getCollections = function (cb) {
diff --git a/dev/js/src/match.js b/dev/js/src/match.js
index 63fa55a..bca7f09 100644
--- a/dev/js/src/match.js
+++ b/dev/js/src/match.js
@@ -190,19 +190,23 @@
var ops = d.createElement('div');
ops.classList.add('action', 'bottom', 'button-group');
-
+
+ /*
+ Temporarily disabled
var meta = ops.addE('span');
meta.addT('Meta');
meta.setAttribute('title', loc.SHOW_META);
meta.classList.add('meta');
+ */
+ // TODO: Rename anno
var info = ops.addE('span');
- info.addT('Anno');
+ info.addT(loc.SHOWINFO);
info.setAttribute('title', loc.SHOWINFO);
info.classList.add('info');
var tree = ops.addE('span');
- tree.addT('+ Tree');
+ tree.addT(loc.ADDTREE);
tree.setAttribute('title', loc.ADDTREE);
tree.classList.add('tree');
@@ -213,12 +217,14 @@
);
// Click on meta - add meta (unless already there)
+ /*
meta.addEventListener(
'click', function (e) {
e.halt();
that.info().showMeta();
}
);
+ */
// Click on token annotations - add token annotations (unless already there)
info.addEventListener(
diff --git a/dev/js/src/match/info.js b/dev/js/src/match/info.js
index a72b66f..ba7214e 100644
--- a/dev/js/src/match/info.js
+++ b/dev/js/src/match/info.js
@@ -141,8 +141,35 @@
},
- getMetaData : function (metaInfo, cb) {
- // ...
+ getMetaData : function (cb) {
+ KorAP.API.getTextInfo(
+ this._match, {}, function (textResponse) {
+
+ if (textResponse === undefined) {
+ cb(null);
+ return;
+ };
+
+ var doc = textResponse["document"];
+
+
+ if (doc === undefined) {
+ cb(null);
+ return;
+ };
+
+ var fields = doc["fields"];
+ if (fields === undefined) {
+ cb(null);
+ return;
+ };
+
+ // Add metainfo to matchview
+ cb(matchMetaClass.create(
+ this._match, fields
+ ));
+ }
+ );
},
@@ -160,6 +187,11 @@
'layer' : layer
},
function (matchResponse) {
+ if (matchResponse === undefined) {
+ cb(null);
+ return;
+ };
+
// Get snippet from match info
if (matchResponse["snippet"] !== undefined) {
// Todo: This should be cached somehow
@@ -284,33 +316,29 @@
metaTable.classList.add('metatable', 'loading');
this.element().appendChild(metaTable);
- // TODO: This is part of the getMeta!
+ /*
+ * This was temporary
var metaInfo = this._match.element().getAttribute('data-info');
-
if (metaInfo)
metaInfo = JSON.parse(metaInfo);
-
+ */
var that = this;
- // There is metainfo
- if (metaInfo) {
-
+ this.getMetaData(function (meta) {
// Load data
metaTable.classList.remove('loading');
- // Add metainfo to matchview
- var metaElem = matchMetaClass.create(this._match).element(metaInfo);
- metaTable.appendChild(metaElem);
+ metaTable.appendChild(meta.element());
// Add button
- this._addButton('close', metaTable, function (e) {
+ that._addButton('close', metaTable, function (e) {
this.parentNode.removeChild(this);
that._visibleMeta = false;
e.halt();
});
- };
+ });
- // Load data
+ // Do not load any longer
metaTable.classList.remove('loading');
},
diff --git a/dev/js/src/match/meta.js b/dev/js/src/match/meta.js
index 8237935..05e1f3b 100644
--- a/dev/js/src/match/meta.js
+++ b/dev/js/src/match/meta.js
@@ -27,23 +27,24 @@
// Localization values
const loc = KorAP.Locale;
- loc.METADATA = loc.METADATA || 'Metadata';
+ loc.METADATA = loc.METADATA || 'Metadata';
return {
/**
* Create new match object
*/
- create : function (match) {
- return Object.create(this)._init(match);
+ create : function (match, fields) {
+ return Object.create(this)._init(match, fields);
},
/**
* Initialize object
*/
- _init : function (match) {
+ _init : function (match, fields) {
this._match = match;
- this.opened = false;
+ this._fields = fields;
+ // this.opened = false;
return this;
},
@@ -57,26 +58,35 @@
/**
* Create match reference view.
*/
- element : function (metaInfo) {
+ element : function () {
if (this._element !== undefined)
return this._element;
-
- /*
- var header = metaTable.appendChild(
- document.createElement('h6')
- );
- header.appendChild(
- document.createElement('div')
- ).appendChild(
- document.createTextNode(loc.METADATA)
- );
- */
+ if (this._fields === null)
+ return;
var metaDL = document.createElement('dl');
this._element = metaDL;
+ var fields = this._fields;
+
+ // TODO:
+ // This should only remember array positions by index
+ // and keep all other field information intact
+ var metaInfo = {};
+ for (var i in fields) {
+ var value = fields[i].value;
+ if (value instanceof Array) {
+ metaInfo[fields[i].key] = value.join(", ");
+ }
+ else {
+ metaInfo[fields[i].key] = value;
+ };
+ };
+
+ // console.log(fields);
+
// TODO: Meta fields should be separated
var keys = Object.keys(metaInfo);
for (var i in keys.sort()) {