diff options
author | Patrick Simianer <p@simianer.de> | 2015-09-01 10:48:13 +0200 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2015-09-01 10:48:13 +0200 |
commit | 0a665d1b790e203347479bc798df45114b6e43e0 (patch) | |
tree | 8aeb58ec8f0b42716356747375190de4e10d0094 | |
parent | 7fa4a3574c40da4289196a0aaf8a11cd9ba4a1ae (diff) |
data
-rw-r--r-- | edit.html | 4 | ||||
-rw-r--r-- | r.js | 41 |
2 files changed, 44 insertions, 1 deletions
@@ -11,10 +11,12 @@ <body> <div id='holder'></div> <input type='button' value='+' onClick='add_obj()' /> + <input type='button' value='D' onClick='extract_data()' onClick='extract_data()' /> <p id='debug'></p> + <pre id='data'></pre> <h3>TODO</h3> <ul> - <li>extract data</li> + <li>integrate into MT system</li> </ul> </body> </html> @@ -368,6 +368,47 @@ make_objs = function (a, type) } }; +/* + * data + * + */ +var extract_data = function () +{ + el = document.getElementById("data"); + d = {}; + d["source"] = []; + d["target"] = []; + d["align"] = []; + // target + var ids = []; + target_shapes.sort(function(a, b) { + return a["grid_"]-b["grid_"]; + }); + for (var i=0; i<target_shapes.length; i++) { + d["target"].push(target_shapes[i].pair.attr("text")); + ids.push(target_shapes[i]["id_"]); + } + // alignment + for (key in connections) { + var a = key.split('-'); + var src = a[0], tgt = ids.indexOf(parseInt(a[1])); + d["align"].push(src+'-'+tgt); + } + // source + for (var i=0; i<shapes.length; i++) { + if (shapes[i]["type_"] == "source") { + d["source"].push(shapes[i].pair.attr("text")); + } else { + break; + } + } + // output + s = JSON.stringify(d); + el.innerHTML = s; + + return s; +} + /////////////////////////////////////////////////////////////////////////////// |