w2v-server: show merged vocabulary in with class "merged" (green)
diff --git a/css/derekovecs.css b/css/derekovecs.css
index d31bce1..5f4015e 100644
--- a/css/derekovecs.css
+++ b/css/derekovecs.css
@@ -77,8 +77,7 @@
}
a.target {
- color: red;
- fill: red;
+ font-weight: bold;
}
table.display {
diff --git a/templates/index.html.ep b/templates/index.html.ep
index 4745c90..32c8a07 100644
--- a/templates/index.html.ep
+++ b/templates/index.html.ep
@@ -123,7 +123,7 @@
nranks = nranks.concat(paraResults[i].map(function(a){return a.rank;}));
nmarked = nmarked.concat(paraResults[i].map(function(a){return a.marked;}));
}
- showMap({target: " "+urlParams.get('word')+" ", mergedEnd: 0, words: nwords, vecs: nvecs, ranks: nranks, marked: nmarked} );
+ showMap({target: " "+urlParams.get('word')+" ", mergedEnd: <%= $mergedEnd %>, words: nwords, vecs: nvecs, ranks: nranks, marked: nmarked} );
var t = $('#firsttable').DataTable({
data: paraResults[0],
"sScrollY": "780px",
@@ -139,7 +139,9 @@
"columns": [
{ "data": "rank", type: "allnumeric" },
{ "data": "dist", render: function ( data, type, row ) {return data.toFixed(3) }},
- { "data": "word", class: "paradigmator", render: function ( data, type, row ) {urlprefix.set("word", data); return '<a href="?' + urlprefix + '">' + data + '</a>' }}
+ { "data": "word", class: "paradigmator", render: function ( data, type, row ) {
+ urlprefix.set("word", data); return '<a class="' + getMergedClass(row.rank) + '" href="?' + urlprefix + '">' + data + '</a>'
+ }}
],
"columnDefs": [
{ className: "dt-right", "targets": [0,1] },
@@ -498,6 +500,26 @@
var anchor_array = [];
var text;
+ function getMergedClass(i) {
+ if(data.mergedEnd && i > data.mergedEnd) {
+ return " merged"
+ } else {
+ return "";
+ }
+ }
+
+ function getRankTooltip(i) {
+ if(data.mergedEnd) {
+ if(data.ranks[i] < data.mergedEnd) {
+ return "rank: "+i +" "+"freq. rank: "+(data.ranks[i]).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
+ } else {
+ return "rank: "+i +" "+"freq. rank: "+(data.ranks[i]-data.mergedEnd).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " (merged vocab)";
+ }
+ } else {
+ return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
+ }
+ }
+
function drawEmbedding() {
var urlprefix = new URLSearchParams(window.location.search);
urlprefix.delete("word");
@@ -527,23 +549,16 @@
res="marked ";
}
if(data.target.indexOf(" "+d+" ") >= 0) {
- return res+"target";
- } else if(data.ranks[i] < data.mergedEnd) {
- return res+"merged";
+ res += "target";
+ }
+ if(data.mergedEnd && data.ranks[i] >= data.mergedEnd) {
+ return res+" merged";
} else {
return res;
}
})
.attr("title", function(d, i) {
- if(data.mergedEnd > 0) {
- if(data.ranks[i] >= data.mergedEnd) {
- return "rank: "+i +" "+"freq. rank: "+(data.ranks[i]).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
- } else {
- return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " (merged vocab)";
- }
- } else {
- return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
- }
+ return getRankTooltip(i);
})
.append("text")
.attr("text-anchor", "top")
@@ -552,7 +567,7 @@
g.append("svg:title")
.text(function(d, i) {
- return "distance rank: "+ i +" "+"\nfrequency rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
+ return getRankTooltip(i);
});
var zoomListener = d3.behavior.zoom()
@@ -674,7 +689,7 @@
$.post('/derekovecs/getVecsByRanks',
JSON.stringify(nranks),
function(data, status){
- showMap({target: " "+urlParams.get('word')+" ", mergedEnd: 0, words: nwords, vecs: data, ranks: nranks, marked: Array(100).fill(false)} );
+ showMap({target: " "+urlParams.get('word')+" ", mergedEnd: <%= $mergedEnd %>, words: nwords, vecs: data, ranks: nranks, marked: Array(100).fill(false)} );
}, 'json');
}
}
diff --git a/w2v-server.pl b/w2v-server.pl
index f29a70a..d72aff8 100755
--- a/w2v-server.pl
+++ b/w2v-server.pl
@@ -731,22 +731,33 @@
while (1) {
st[cn][b] = st1[c];
+ if(merge_words > 0)
+ st[cn+1][b] = st1[c];
b++;
c++;
st[cn][b] = 0;
if (st1[c] == 0) break;
if (st1[c] == ' ' || st1[c] == '-') {
sep[cn++] = st1[c];
+ if(merge_words > 0)
+ sep[cn++] = st1[c];
b = 0;
c++;
}
}
cn++;
+ if(merge_words > 0)
+ cn++;
for (a = 0; a < cn; a++) {
if(search_backw) {
for (b = words - 1; b >= 0; b--) if (!strcmp(&vocab[b * max_w], st[a])) break;
} else {
- for (b = 0; b < words; b++) if (!strcmp(&vocab[b * max_w], st[a])) break;
+ for (b = 0; b < words; b++)
+ if (!strcmp(&vocab[b * max_w], st[a])) {
+ if(merge_words > 0)
+ search_backw^=1;
+ break;
+ }
}
if (b == words) b = -1;
wl->wordi[a] = b;