#!/usr/local/bin/perl
use Inline C;
use Mojolicious::Lite;
use Mojo::JSON qw(decode_json encode_json to_json);
use Encode qw(decode encode);
use Mojo::Server::Daemon;

print STDERR $ARGV[0];
# -cbow 1 -size 200 -window 8 -negative 25 -hs 0 -sample 1e-4 -threads 40 -binary 1 -iter 15
init_net("vectors15.bin");

get '/' => sub {
  my $c    = shift;
	my $word=$c->param('word');
  my $no_nbs=$c->param('n') || 100;
  my $no_iterations=$c->param('N') || 2000;
	my @lists;
	if(defined($word) && $word !~ /^\s*$/) {
		$c->inactivity_timeout(300);
		$word =~ s/\s+/ /g;
    for my $w (split(' *\| *', $word)) {
			$c->app->log->debug('Looking for neighbours of '.$w);
			push(@lists, get_neighbours(encode("iso-8859-1", $w), $no_nbs));
		}
	}
  $c->render(template=>"index", word=>$word, no_nbs=>$no_nbs, no_iterations => $no_iterations, lists=> \@lists);
};

app->start;

exit;

__END__

__C__
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <malloc.h>
#include <stdlib.h>    //strlen

#define max_size 2000
#define max_w 50
#define MAX_NEIGHBOURS 1000
#define MAX_WORDS -1

//the thread function
void *connection_handler(void *);
 
char *bestw[MAX_NEIGHBOURS];
char file_name[max_size], st[100][max_size];
float dist, len, bestd[MAX_NEIGHBOURS], vec[max_size];
long long words, size, a, b, c, d, cn, bi[100], besti[MAX_NEIGHBOURS];
char ch;
float *M;
char *vocab;
char *stringBuffer;

int init_net(char *file_name) {
  FILE *f, *binvecs, *binwords;
	char binvecs_fname[256], binwords_fname[256];
	strcpy(binwords_fname, file_name);
	strcat(binwords_fname, ".words");
	strcpy(binvecs_fname, file_name);
	strcat(binvecs_fname, ".vecs");

	stringBuffer = malloc(64000);
  f = fopen(file_name, "rb");
  if (f == NULL) {
    printf("Input file %s not found\n", file_name);
    return -1;
  }
  fscanf(f, "%lld", &words);
	if(MAX_WORDS > 0 && words > MAX_WORDS) words = MAX_WORDS;
  fscanf(f, "%lld", &size);
  vocab = (char *)malloc((long long)words * max_w * sizeof(char));
  for (a = 0; a < MAX_NEIGHBOURS; a++) bestw[a] = (char *)malloc(max_size * sizeof(char));
  M = (float *)malloc((long long)words * (long long)size * sizeof(float));
  if (M == NULL) {
    printf("Cannot allocate memory: %lld MB    %lld  %lld\n", (long long)words * size * sizeof(float) / 1048576, words, size);
    return -1;
  }
	if( (binvecs = fopen(binvecs_fname, "rb")) != NULL && (binwords = fopen(binwords_fname, "rb")) != NULL) {
		fread(M, sizeof(float), (long long)words * (long long)size, binvecs);
		fclose(binvecs);
		fread(vocab, sizeof(char), (long long)words * max_w, binwords);
		fclose(binwords);
	} else {
		for (b = 0; b < words; b++) {
			a = 0;
			while (1) {
				vocab[b * max_w + a] = fgetc(f);
				if (feof(f) || (vocab[b * max_w + a] == ' ')) break;
				if ((a < max_w) && (vocab[b * max_w + a] != '\n')) a++;
			}
			vocab[b * max_w + a] = 0;
			fread(&M[b * size], sizeof(float), size, f);
			len = 0;
			for (a = 0; a < size; a++) len += M[a + b * size] * M[a + b * size];
			len = sqrt(len);
			for (a = 0; a < size; a++) M[a + b * size] /= len;
		}
		if( (binvecs = fopen(binvecs_fname, "wb")) != NULL && (binwords = fopen(binwords_fname, "wb")) != NULL) {
			fwrite(M, sizeof(float), (long long)words * (long long)size, binvecs);
			fclose(binvecs);
			fwrite(vocab, sizeof(char), (long long)words * max_w, binwords);
			fclose(binwords);
		}
	}
  fclose(f);
	return 0;
}

SV *get_neighbours(char *st1, int N) {
  if(N>MAX_NEIGHBOURS) N=MAX_NEIGHBOURS;

	FILE *out=stdout;
	*stringBuffer=0;

	for (a = 0; a < N; a++) bestd[a] = 0;
	for (a = 0; a < N; a++) bestw[a][0] = 0;
	a = 0;
	cn = 0;
	b = 0;
	c = 0;
	while (1) {
		st[cn][b] = st1[c];
		b++;
		c++;
		st[cn][b] = 0;
		if (st1[c] == 0) break;
		if (st1[c] == ' ') {
			cn++;
			b = 0;
			c++;
		}
	}
	cn++;
	for (a = 0; a < cn; a++) {
		for (b = 0; b < words; b++) if (!strcmp(&vocab[b * max_w], st[a])) break;
		if (b == words) b = -1;
		bi[a] = b;
		fprintf(stderr, "Word: \"%s\"  Position in vocabulary: %lld\n", st[a], bi[a]);
		if (b == -1) {
			fprintf(stderr, "Out of dictionary word!\n");
			cn--;
			break;
		}
	}
	if (b == -1 && cn <= 0) {
    N = 0;
	  goto end;
  }
	for (a = 0; a < size; a++) vec[a] = 0;
	for (b = 0; b < cn; b++) {
		if (bi[b] == -1) continue;
		for (a = 0; a < size; a++) vec[a] += M[a + bi[b] * size];
	}
	len = 0;
	for (a = 0; a < size; a++) len += vec[a] * vec[a];
	len = sqrt(len);
	for (a = 0; a < size; a++) vec[a] /= len;
	for (a = 0; a < N; a++) bestd[a] = -1;
	for (a = 0; a < N; a++) bestw[a][0] = 0;
	for (c = 0; c < words; c++) {
		a = 0;
// do not skip taget word
//		for (b = 0; b < cn; b++) if (bi[b] == c) a = 1;
//		if (a == 1) continue;
		dist = 0;
		for (a = 0; a < size; a++) dist += vec[a] * M[a + c * size];
		for (a = 0; a < N; a++) {
			if (dist > bestd[a]) {
				for (d = N - 1; d > a; d--) {
					bestd[d] = bestd[d - 1];
					besti[d] = besti[d - 1];
				}
				bestd[a] = dist;
				besti[a] = c;
				break;
			}
		}
	}

end:
	a=0;
	AV* array = newAV();
	for (a = 0; a < N; a++) {
		strcpy(bestw[a], &vocab[besti[a] * max_w]);
		HV* hash = newHV();
		hv_store(hash, "word", strlen("word"), newSVpvf(bestw[a], 0), 0);
		hv_store(hash, "dist", strlen("dist"), newSVnv(bestd[a]), 0);
		hv_store(hash, "rank", strlen("rank"), newSVuv(besti[a]), 0);
		AV *vector = newAV();
		for (b = 0; b < size; b++) {
			av_push(vector, newSVnv(M[b + besti[a] * size]));
		}
		hv_store(hash, "vector", strlen("vector"), newRV_noinc((SV*)vector), 0);
		av_push(array, newRV_noinc((SV*)hash));
	}
	return newRV_noinc((SV*)array);
}


__DATA__

@@ index.html.ep
<!DOCTYPE html>
<html>
<head>
	<title>DeReKo-Word-Vector-Distances</title>
	<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
	<script src="http://code.jquery.com/jquery-latest.min.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
	<script>
 $(function() {
    $( document ).tooltip({
			content: function() {
				return $(this).attr('title');
			}}
		)
	 })
  </script>
	<script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
	<script src="http://klinux10/word2vec/tsne.js"></script>
	<script src="http://klinux10/word2vec/labeler.js"></script>
<style>
body, input {
	font-family: Arial, sans-serif;
	font-size: 11pt;
}

.ui-tooltip-content {
	font-size: 9pt;
	colour: #222222;
}

svg > .ui-tooltip-content {
	font-size: 7pt;
	colour: #222222;
}

svg {
//  border: 1px solid #333;
  margin-right: 10px;
  margin-bottom:10px;
}
#wrapper {
    width: 100%;
//   border: 1px solid red; 
    overflow: hidden; /* will contain if #first is longer than #second */
}
#first {
 margin-right: 20px;
    float:left; /* add this */
//    border: 1px solid green;
}
#second {
    border: 1px solid #333;
	  height: 850px;
    overflow: hidden; /* if you don't want #second to wrap below #first */
}
#cost {
	z-index: 1;
	position: fixed;
	font-size: 10px;
	color: #222222;
  margin-bottom: 10px;
}
</style>
<script>

var opt = {epsilon: 1, perplexity: 20};
var T = new tsnejs.tSNE(opt); // create a tSNE instance

var Y;

var data;
var labeler;


function applyJitter() {
  svg.selectAll('.u')
    .data(labels)
    .transition()
    .duration(50)
    .attr("transform", function(d, i) {
      T.Y[i][0] = (d.x - 400 - tx)/ss/20;
      T.Y[i][1] = (d.y - 400 - ty)/ss/20;
      return "translate(" +
        (d.x) + "," +
        (d.y) + ")";
    });
}
    
function updateEmbedding() {
  var Y = T.getSolution();
  svg.selectAll('.u')
    .data(data.words)
    .attr("transform", function(d, i) { 
			return "translate(" +
        ((Y[i][0]*20*ss + tx) + 400) + "," +
        ((Y[i][1]*20*ss + ty) + 400) + ")"; });
}

var svg;
var labels = [];
var anchor_array = [];
var text;

function drawEmbedding() {
   $("#embed").empty();
   var div = d3.select("#embed");
	 
   // get min and max in each column of Y
   var Y = T.Y;
   
   svg = div.append("svg") // svg is global
						.attr("width", 800)
						.attr("height", 800);
	 
   var g = svg.selectAll(".b")
							.data(data.words)
							.enter().append("g")
							.attr("class", "u");
	 
   g.append("a")
		.attr("xlink:href", function(word) {return "/?word="+word;})
	  .attr("title", function(d, i) {
			return "rank: "+i +"  "+"freq. rank: "+data.ranks[i];
		})
		.append("text")
    .attr("text-anchor", "top")
    .attr("font-size", 12)
    .attr("fill", function(d) {
			if(data.target.indexOf(" "+d+" ") >= 0) {
				return "red";
			} else {
				return "#333"
			}
		})
    .text(function(d) { return d; });
	 
   var zoomListener = d3.behavior.zoom()
												.scaleExtent([0.1, 10])
												.center([0,0])
												.on("zoom", zoomHandler);
   zoomListener(svg);
 }
 
 var tx=0, ty=0;
 var ss=1;
 var iter_id=-1;
 
 function zoomHandler() {
   tx = d3.event.translate[0];
   ty = d3.event.translate[1];
   ss = d3.event.scale;
   updateEmbedding();
 }
 
 var stepnum = 0;

 function stopStep() {
   clearInterval(iter_id);
	 text = svg.selectAll("text");
	 
	 labels = d3.range(data.words.length).map(function(i) {
     var x = (T.Y[i][0]*20*ss + tx) + 400;
     var y = (T.Y[i][1]*20*ss + ty) + 400;
		 anchor_array.push({x: x, y: y, r: 5});
		 return {
         x: x,
         y: y,
			   name: data.words[i]
		 };
	 });

	 var index = 0;
	 text.each(function() {
		 labels[index].width = this.getBBox().width;
		 labels[index].height = this.getBBox().height;
		 index += 1;
	 });

	 
//	 setTimeout(updateEmbedding, 1);
//	 setTimeout(
	   labeler =	 d3.labeler()
			 .label(labels)
			 .anchor(anchor_array)
			 .width(800)
			 .height(800)
			   .update(applyJitter);
//         .start(1000);

     iter_id = setInterval(jitterStep, 1);

 }

var jitter_i=0;;

function jitterStep() {
    if(jitter_i++ > 100) {
        clearInterval(iter_id);
    } else {
     labeler.start2(10);
	      applyJitter();
    }
}
 
 function step() {
   var i = T.iter;
   if(i > <%= $no_iterations %>) {
		 stopStep();
   } else {
     var cost = Math.round(T.step() *1000) / 1000; // do a few steps
     $("#cost").html("tsne iteration " + i + ", cost: " + cost.toFixed(3));
     updateEmbedding();
   }
 }

 function showMap(j) {
	 data=j;
   T.iter=0;
   T.initDataRaw(data.vecs); // init embedding
   drawEmbedding(); // draw initial embedding
	 
	 if(iter_id >= 0) {
		 clearInterval(iter_id);
	 }
   //T.debugGrad();
   iter_id = setInterval(step, 1);
   //step();
 }
 
 function update() {
          
   text.transition().duration(800)
       .attr("transform", transform);
 }


</script>
</head>
<body>
	<form action="<%=url_for('/')->to_abs%>" method="GET">
		word(s): 
    <input type="text" name="word" size="20"  value="<%= $word %>" title="When looking for multiple words use spaces as separators to search around the average vector and | as separator to get the neighbours for each word."> 
		max. neighbours: <input type="text" size="8" name="n" value="<%= $no_nbs %>">
		iterations: <input type="text" name="N" size="8" value="<%= $no_iterations %>">
		<input type="submit" value="Show">
	</form>
	<br>
	% if($lists) {
	<div id="wrapper">
		<table id="first">
			<tr>
				<th align="right">Pos.</th><th align="left">Word</th><th align="right">Cosine dist.</th><th>Freq. rank</th>
			</tr>
			% my $j=0; my @words; my @vecs; my @ranks; for my $list (@$lists) {
			% my $i=1; for my $item (@$list) {
			% if(!grep{$_ eq $item->{word}} @words) {
      %   push @vecs, $item->{vector};
			%   push @words, $item->{word};
			%   push @ranks, $item->{rank};
      % }
			<tr>
				<td align="right">
  				<%= $i++ %>.
				</td>
				<td>
  				<a href="/?word=<%= $item->{word} %>">
						<%= $item->{word} %>
					</a>
				</td>
				<td align="right">
  				<%= sprintf("%.3f", $item->{dist}) %>
				</td>
				<td align="right">
  				<%= $item->{rank} %>
				</td>
			</tr>
			% }
			% }
		</table>
		<script>
		 % use Mojo::ByteStream 'b';
		 $(window).load(function() {
			 showMap(<%= b(Mojo::JSON::to_json({target => " $word ", words => \@words, vecs => \@vecs, ranks => \@ranks})); %>);
		 });
    </script>
		% }
		<div id="second" style="width:800px; height:800px; font-family: arial;">
			<div id="embed">
			</div>
			<div id="cost"></div>
		</div>
  </div>
	<p>
		Word vector model based on  DeReKo-2015-II. Trained with <a href="https://code.google.com/p/word2vec/">word2vec</a> using the following parameters:</p>
  <pre>
-cbow 1 -size 300 -window 7 -negative 5 -hs 0 -sample 1e-5 -threads 44 -binary 1 -iter 5
	</pre>
	</p>
</body>
</html>

