#!/usr/local/bin/perl
use Inline C;
use Inline C => Config => CLEAN_AFTER_BUILD => 0, ccflags => $Config{ccflags}." -O4";
#use Inline C => Config => BUILD_NOISY => 1, CFLAGS => $Config{cflags}." -O4 -mtune k9";
#use Inline C => Config => CLEAN_AFTER_BUILD => 0, ccflags => $Config{ccflags}." -Ofast -march k8 -mtune k8 ";
use Mojolicious::Lite;
use Mojo::JSON qw(decode_json encode_json to_json);
use base 'Mojolicious::Plugin';

use Encode qw(decode encode);
use Getopt::Std;
use Mojo::Server::Daemon;
use Cwd;
app->static->paths->[0] = getcwd;

plugin 'Log::Access';
plugin "RequestBase";

our $opt_i = 0; # latin1-input?
our $opt_l = undef;
our $opt_p = 5676;
our $opt_m;
our $opt_M;
our $opt_n = '';
our $opt_d;
our $opt_G;

my %marked;
my $training_args="";
my $mergedEnd=0;
my %cache;

getopts('d:Gil:p:m:n:M:');

if($opt_M) {
  open my $handle, '<:encoding(UTF-8)', $opt_M
    or die "Can't open '$opt_M' for reading: $!";
  while(<$handle>) {
    foreach my $mw (split /\s+/) {
      $marked{$mw}=1
    }
  }
  close($handle);
}

# -cbow 1 -size 200 -window 8 -negative 25 -hs 0 -sample 1e-4 -threads 40 -binary 1 -iter 15
if(!$ARGV[0]) {
  init_net("vectors15.bin", $opt_n, ($opt_i? 1 : 0));
} else {
  init_net($ARGV[0], $opt_n, ($opt_i? 1 : 0));
  if(open(FILE, "$ARGV[0].args")) {
    $training_args = <FILE>;
  }
  close(FILE);
}

if($opt_m) {
  $mergedEnd = mergeVectors($opt_m);
}


if($opt_d) { # -d: dump  vecs and exit
	dump_vecs($opt_d);
	exit;
}

my $daemon = Mojo::Server::Daemon->new(
    app    => app,
    listen => ['http://'.($opt_l ? $opt_l : '*').":$opt_p"]
);

if($opt_G) {
  print "Filtering garbage\n";
  filter_garbage();
}

get '*/js/*' => sub {
	my $c = shift;
	my $url = $c->req->url;
	$url =~ s@/derekovecs@@g;
  $c->app->log->info("GET: " . $url);
	$c->reply->static($url);
};

get '/' => sub {
  my $c    = shift;
  $c->app->log->info("get: ".$c->req->url->to_abs);
	my $word=$c->param('word');
  my $no_nbs=$c->param('n') || 100;
  my $no_iterations=$c->param('N') || 2000;
  my $perplexity=$c->param('perplexity') || 20;
  my $epsilon=$c->param('epsilon') || 5;
  my $som=$c->param('som') || 0;
	my $searchBaseVocabFirst=$c->param('sbf') || 0;
  my $sort=$c->param('sort') || 0;
  my $csv=$c->param('csv') || 0;
  my $json=$c->param('json') || 0;
  my $cutoff=$c->param('cutoff') || 1000000;
  my $dedupe=$c->param('dedupe') || 0;
  my $res;
	my @lists;
	my @collocations;
	if(defined($word) && $word !~ /^\s*$/) {
		$c->inactivity_timeout(300);
		$word =~ s/\s+/ /g;
    for my $w (split(' *\| *', $word)) {
      if ($cache{$w.$cutoff.$no_nbs.$sort.$dedupe}) {
        $c->app->log->info("Getting $w results from cache");
        $res = $cache{$w.$cutoff.$no_nbs.$sort.$dedupe}
      } else {
        $c->app->log->info('Looking for neighbours of '.$w);
        if($opt_i) {
          $res = get_neighbours(encode("iso-8859-1", $w), $no_nbs, $sort, $searchBaseVocabFirst, $cutoff, $dedupe);
        } else {
          $res = get_neighbours($w, $no_nbs, $sort, $searchBaseVocabFirst, $cutoff, $dedupe);
        }
        $cache{$w} = $res;
      }
      push(@lists, $res->{paradigmatic});
    }
  }
	$word =~ s/ *\| */ | /g;
  if($json) {
    return $c->render(json => {word => $word, list => \@lists, collocators=>$res->{syntagmatic}});
  } elsif($csv) {
    my $csv_data="";
    for (my $i=0; $i <= $no_nbs; $i++) {
      $csv_data .= $res->{paradigmatic}->[$i]->{word} . ", ";
    }
    for (my $i=0; $i < $no_nbs; $i++) {
      $csv_data .= $res->{syntagmatic}->[$i]->{word} . ", ";
    }
    chop $csv_data;
    chop $csv_data;
    $csv_data .= "\n";
    return $c->render(text=>$csv_data);
  } else {
    $c->render(template=>"index", word=>$word, cutoff=>$cutoff, no_nbs=>$no_nbs, no_iterations => $no_iterations, epsilon=> $epsilon, perplexity=> $perplexity, show_som=>$som, searchBaseVocabFirst=>$searchBaseVocabFirst, sort=>$sort, training_args=>$training_args, mergedEnd=> $mergedEnd, dedupe=> $dedupe, marked=>\%marked, lists=> \@lists, collocators=> $res->{syntagmatic});
  }
};

helper(bitvec2window => sub {
         my ($self, $n) = @_;
         my $str = unpack("B32", pack("N", $n));
         $str =~ s/^\d{22}//;
         $str =~ s/^(\d{5})/$1x/;
         $str =~ s/0/·/g;
         $str =~ s/1/+/g;
         return $str;
      });

$daemon->run; # app->start;

exit;

__END__

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

#define max_size 2000
#define max_w 50
#define MAX_NEIGHBOURS 1000
#define MAX_WORDS -1
#define MAX_THREADS 100
#define MAX_CC 50
#define EXP_TABLE_SIZE 1000
#define MAX_EXP 6
#define MIN_RESP 0.50

//the thread function
void *connection_handler(void *);

typedef struct {
	long long *index;
	float *dist;
	float *norm;
  long long *pos;
	int length;
} knn;
  
typedef struct {
  long long wordi[MAX_NEIGHBOURS];
  char sep[MAX_NEIGHBOURS];
  int length;
} wordlist;

typedef struct {
  long cutoff;
  wordlist *wl;
	char *token;
	int N;
	long from;
	unsigned long upto;
  float *target_sums;
  float *window_sums;
} knnpars;

float *M, *M2=0L, *syn1neg_window, *expTable;
float *window_sums;
char *vocab;
char *garbage = NULL;

long long words, size, merged_end;
long long merge_words = 0;
int num_threads=20;
int latin_enc=0;
int window;

int init_net(char *file_name, char *net_name, int latin) {
  FILE *f, *binvecs, *binwords;
	int binwords_fd, binvecs_fd, net_fd, i;
	long long a, b, c, d, cn;
	float len;
  double val;

	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");

  latin_enc = latin;
  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);
	if( (binvecs_fd = open(binvecs_fname, O_RDONLY)) < 0  || (binwords_fd = open(binwords_fname, O_RDONLY)) < 0) {
    printf("Converting %s to memory mappable structures\n", file_name);
		vocab = (char *)malloc((long long)words * max_w * 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(strstr(file_name, ".txt")) {
      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;
        len = 0;
        for (a = 0; a < size; a++) {
          fscanf(f, "%lf", &val);
          M[a + b * size] = val;
          len += val * val;
        } 
        len = sqrt(len);
        for (a = 0; a < size; a++) M[a + b * size] /= len;
      }
    } 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);
		}
  }
	if( (binvecs_fd = open(binvecs_fname, O_RDONLY)) >= 0 && (binwords_fd = open(binwords_fname, O_RDONLY)) >= 0) {
		M = mmap(0, sizeof(float) * (long long)words * (long long)size, PROT_READ, MAP_SHARED, binvecs_fd, 0);
		vocab = mmap(0,  sizeof(char) * (long long)words * max_w, PROT_READ, MAP_SHARED, binwords_fd, 0);
    if (M == MAP_FAILED || vocab == MAP_FAILED) {
			close(binvecs_fd);
			close(binwords_fd);
			fprintf(stderr, "Cannot mmap %s or %s\n", binwords_fname, binvecs_fname);
			exit(-1);
    }
	} else {
    fprintf(stderr, "Cannot open %s or %s\n", binwords_fname, binvecs_fname);
    exit(-1);
	}
  fclose(f);

  if(net_name && strlen(net_name) > 0) {
    if( (net_fd = open(net_name, O_RDONLY)) >= 0) {
      window = (lseek(net_fd, 0, SEEK_END) -  sizeof(float) * words * size) / words / size / sizeof(float) / 2;
      //      lseek(net_fd, sizeof(float) * words * size, SEEK_SET);
      // munmap(M,  sizeof(float) * words * size);
      M2 = mmap(0, sizeof(float) * words * size + sizeof(float) * 2 * window * size * words, PROT_READ, MAP_SHARED, net_fd, 0);
      if (M2 == MAP_FAILED) {
        close(net_fd);
        fprintf(stderr, "Cannot mmap %s\n", net_name);
        exit(-1);
      }
      syn1neg_window =  M2 + words * size;
    } else {
      fprintf(stderr, "Cannot open %s\n", net_name);
      exit(-1);
    }
    fprintf(stderr, "Successfully memmaped %s. Determined window size: %d\n", net_name, window);
  }    

	expTable = (float *) malloc((EXP_TABLE_SIZE + 1) * sizeof(float));
	for (i = 0; i < EXP_TABLE_SIZE; i++) {
		expTable[i] = exp((i / (float) EXP_TABLE_SIZE * 2 - 1) * MAX_EXP); // Precompute the exp() table
		expTable[i] = expTable[i] / (expTable[i] + 1); // Precompute f(x) = x / (x + 1)
	}
	window_sums = malloc(sizeof(float) * (window+1) * 2);
	return 0;
}

long mergeVectors(char *file_name){
  FILE *f, *binvecs, *binwords;
	int binwords_fd, binvecs_fd, net_fd, i;
	long long a, b, c, d, cn;
	float len;
  float *merge_vecs;
  char *merge_vocab;
 /*  long long merge_words, merge_size; */
  long long merge_size;

	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");

  f = fopen(file_name, "rb");
  if (f == NULL) {
    printf("Input file %s not found\n", file_name);
    exit -1;
  }
  fscanf(f, "%lld", &merge_words);
  fscanf(f, "%lld", &merge_size);
  if(merge_size != size){
		fprintf(stderr, "vectors must have the same length\n");
		exit(-1);
	}
	if( (binvecs_fd = open(binvecs_fname, O_RDONLY)) >= 0 && (binwords_fd = open(binwords_fname, O_RDONLY)) >= 0) {
		merge_vecs = malloc(sizeof(float) * (words + merge_words) * size);
		merge_vocab = malloc(sizeof(char) * (words + merge_words) * max_w);
    if (merge_vecs == NULL || merge_vocab == NULL) {
			close(binvecs_fd);
			close(binwords_fd);
			fprintf(stderr, "Cannot reserve memory for %s or %s\n", binwords_fname, binvecs_fname);
			exit(-1);
    }
    read(binvecs_fd, merge_vecs, merge_words * size * sizeof(float));
    read(binwords_fd, merge_vocab, merge_words * max_w);
	} else {
    fprintf(stderr, "Cannot open %s or %s\n", binwords_fname, binvecs_fname);
    exit(-1);
	}
	printf("Successfully reallocated memory\nMerging...\n");
	fflush(stdout);
  memcpy(merge_vecs + merge_words * size, M, words * size * sizeof(float));
  memcpy(merge_vocab + merge_words * max_w, vocab, words * max_w);
  munmap(M, words * size * sizeof(float));
  munmap(vocab, words * max_w);
  M = merge_vecs;
  vocab = merge_vocab;
  merged_end = merge_words;
  words += merge_words;
  fclose(f);
	printf("merged_end: %lld, words: %lld\n", merged_end, words);
  return((long) merged_end);
}

void filter_garbage() {
  long i;
  unsigned char *w, previous, c;
  garbage = malloc(words);
  memset(garbage, 0, words);
  for (i = 0; i < words; i++) {
    w = vocab + i * max_w;
    previous = 0;
    while((c = *w++) && !garbage[i]) {
      if( ((c <= 90 && c >= 65) && (previous >= 97 && previous <= 122)) || 
          (previous == '-' && (c & 32)) ||
          (previous == 0xc2 && (c == 0xa4 || c == 0xb6 )) ||
          c == '<'
        ) {
        garbage[i]=1;
        continue;
      }
      previous = c;
    }
  }
  return;
}

void *getCollocators(knnpars *pars) {
	int N = pars->N;
  int cc = pars->wl->wordi[0];
	knn *nbs = NULL;
  long window_layer_size = size * window * 2;
	long a, b, c, d, e, window_offset, target, max_target=0, maxmax_target;
	float f, max_f, maxmax_f;
	float *target_sums, *bestf, *bestn, worstbest, wpos_sum;
	long long *besti, *bestp;

  if(M2 == NULL || cc == -1)
    return NULL;

	a = posix_memalign((void **) &target_sums, 128, pars->cutoff * sizeof(float));
	besti = malloc(N * sizeof(long long));
	bestp = malloc(N * sizeof(long long));
	bestf = malloc(N * sizeof(float));
	bestn = malloc(N * sizeof(float));

  worstbest = MIN_RESP;

  for (b = 0; b < pars->cutoff; b++)
			target_sums[b]=0;
  for (b = 0; b < N; b++) {
      besti[b] = -1;
      bestn[b] = 1;
      bestf[b] = worstbest;
  }

  d = cc;
  maxmax_f = -1;
  maxmax_target = 0;

  for (a = pars->from; a < pars->upto; a++) {
    if(a >= window)
      a++;
    wpos_sum = 0;
    printf("window pos: %ld\n", a);
    if (a != window) {
      max_f = -1;
      window_offset = a * size;
      if (a > window)
        window_offset -= size;
      for(target = 0; target < pars->cutoff; target ++) {
				if(garbage && garbage[target]) continue;
        if(target == d)
          continue;
        f = 0;
        for (c = 0; c < size; c++)
          f += M2[d* size + c]	* syn1neg_window[target * window_layer_size	+ window_offset + c];
        if (f < -MAX_EXP)
          continue;
        else if (f > MAX_EXP)
          continue;
        else
          f = expTable[(int) ((f + MAX_EXP)	* (EXP_TABLE_SIZE / MAX_EXP / 2))];
        wpos_sum += f;

        target_sums[target] += f;
        if(f > worstbest) {
          for (b = 0; b < N; b++) {
            if (f > bestf[b]) {
							memmove(bestf + b + 1, bestf + b, (N - b -1) * sizeof(float));
							memmove(besti + b + 1, besti + b, (N - b -1) * sizeof(long long));
							memmove(bestp + b + 1, bestp + b, (N - b -1) * sizeof(long long));
							bestf[b] = f;
							besti[b] = target;
							bestp[b] = window-a;
							break;
            }
          }
          if(b == N - 1)
            worstbest = bestf[N-1];
        }
      }
      printf("%d %.2f\n", max_target, max_f);
      printf("%s (%.2f) ", &vocab[max_target * max_w], max_f);
      if(max_f > maxmax_f) {
        maxmax_f = max_f;
        maxmax_target = max_target;
      }
      for (b = 0; b < N; b++)
        if(bestp[b] == window-a)
          bestn[b] = bestf[b] / wpos_sum;
    } else {
      printf("\x1b[1m%s\x1b[0m ", &vocab[d*max_w]);
    }
    pars->window_sums[a] = wpos_sum;
  }
  for (b = 0; b < pars->cutoff; b++)
      pars->target_sums[b] += (target_sums[b] / wpos_sum ) / (window * 2);
  free(target_sums);
  for(b=0; b<N && besti[b] >= 0; b++);; // THIS LOOP IS NEEDED (b...)
//		printf("%d: best syn: %s %.2f %.5f\n", b, &vocab[besti[b]*max_w], bestf[b], bestn[b]);
//	printf("\n");
  nbs = malloc(sizeof(knn));
	nbs->index = besti;
	nbs->dist = bestf;
	nbs->norm = bestn;
	nbs->pos = bestp;
	nbs->length = b-1;
  pthread_exit(nbs);
}


wordlist *getTargetWords(char *st1, int search_backw) {
  wordlist *wl = malloc(sizeof(wordlist));
  char st[100][max_size], sep[100];
	long a, b=0, c=0, cn=0;
  int unmerged;

	while (1) {
		st[cn][b] = st1[c];
		b++;
		c++;
		st[cn][b] = 0;
		if (st1[c] == 0) break;
		if (st1[c] == ' ' || st1[c] == '-') {
      sep[cn++] = st1[c];
			b = 0;
			c++;
		}
	}
	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;
		}
		if (b == words) b = -1;
		wl->wordi[a] = b;
		fprintf(stderr, "Word: \"%s\"  Position in vocabulary: %lld\n", st[a], wl->wordi[a]);
		if (b == -1) {
			fprintf(stderr, "Out of dictionary word!\n");
			cn--;
			free(wl);
			return NULL;
		}
	}
  wl->length=cn;
  return(wl);
}
 
void *_get_neighbours(knnpars *pars) {
	char *st1 = pars->token;
	int N = pars->N;
	long from = pars -> from;
	unsigned long upto = pars -> upto;
	char file_name[max_size], st[100][max_size], *sep;
	float dist, len, *bestd, vec[max_size];
	long long a, b, c, d, cn, *bi, *besti;
	char ch;
	knn *nbs = NULL;
  wordlist *wl = pars->wl;
  
	besti = malloc(N * sizeof(long long));
	bestd = malloc(N * sizeof(float));

	float worstbest=-1;

	for (a = 0; a < N; a++) bestd[a] = 0;
	a = 0;
  bi = wl->wordi;
	cn = wl->length;
  sep = wl->sep;
	b = bi[0];
	c = 0;
	if (b == -1) {
    N = 0;
	  goto end;
  }
	for (a = 0; a < size; a++) vec[a] = 0;
	for (b = 0; b < cn; b++) {
		if (bi[b] == -1) continue;
    if(b>0 && sep[b-1] == '-')
      for (a = 0; a < size; a++) vec[a] -= M[a + bi[b] * size];
    else
      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 (c = from; c < upto; c++) {
    if(garbage && garbage[c]) continue;
		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];
		if(dist > worstbest) {
			for (a = 0; a < N; a++) {
				if (dist > bestd[a]) {
					memmove(bestd + a + 1, bestd + a, (N - a -1) * sizeof(float));
					memmove(besti + a + 1, besti + a, (N - a -1) * sizeof(long long));
					bestd[a] = dist;
					besti[a] = c;
					break;
				}
			}
			worstbest = bestd[N-1];
		}
	}

	nbs = malloc(sizeof(knn));
	nbs->index = besti;
	nbs->dist = bestd;
	nbs->length = N;
end:
	pthread_exit(nbs);
}


SV *get_neighbours(char *st1, int N, int sort_by, int search_backw, long cutoff, int dedupe) {
  HV *result = newHV();
	float *target_sums, bestd[MAX_NEIGHBOURS], bestn[MAX_NEIGHBOURS], bests[MAX_NEIGHBOURS], vec[max_size];
	long long old_words;
	long besti[MAX_NEIGHBOURS], bestp[MAX_NEIGHBOURS], a, b, c, d, slice;
	knn *para_nbs[MAX_THREADS];
	knn *syn_nbs[MAX_THREADS];
	knnpars pars[MAX_THREADS];
  pthread_t *pt = (pthread_t *)malloc((num_threads+1) * sizeof(pthread_t));
  wordlist *wl;
  int syn_threads = (M2? window * 2 : 0);
  int para_threads = num_threads - syn_threads;
  
  if(N>MAX_NEIGHBOURS) N=MAX_NEIGHBOURS;
	
  if(cutoff < 1)
    cutoff=words;

  wl = getTargetWords(st1, search_backw);
  if(wl == NULL || wl->length < 1)
    goto end;

	old_words = cutoff;
  if(merge_words > 0)
		cutoff = merge_words * 1.25;  /* HACK */
	slice = cutoff / para_threads;

	a = posix_memalign((void **) &target_sums, 128, cutoff * sizeof(float));
  for(a = 0; a < cutoff; a++)
    target_sums[a] = 0;

  printf("Starting %d threads\n", para_threads);
  fflush(stdout);
	for(a=0; a < para_threads; a++) {
		pars[a].cutoff = cutoff;
		pars[a].token = st1;
		pars[a].wl = wl;
		pars[a].N = N;
		pars[a].from = a*slice;
		pars[a].upto = ((a+1)*slice > cutoff? cutoff:(a+1)*slice);
		pthread_create(&pt[a], NULL, _get_neighbours, (void *) &pars[a]);
	}
  if(M2) {
    for(a=0; a < syn_threads; a++) {
			pars[a + para_threads].cutoff = cutoff;
      pars[a + para_threads].target_sums = target_sums;
      pars[a + para_threads].window_sums = window_sums;
      pars[a + para_threads].wl = wl;
      pars[a + para_threads].N = N;
      pars[a + para_threads].from = a;
      pars[a + para_threads].upto = a+1;
      pthread_create(&pt[a + para_threads], NULL, getCollocators, (void *) &pars[a + para_threads]);
    }
  }
  printf("Waiting for para threads to join\n");
  fflush(stdout);
  for (a = 0; a < para_threads; a++) pthread_join(pt[a], &para_nbs[a]);
  printf("Para threads joint\n");
  fflush(stdout);

	/* if(!syn_nbs[0]) */
	/* 	goto end; */

	for(b=0; b < N; b++) {
		besti[b] = para_nbs[0]->index[b];
		bestd[b] = para_nbs[0]->dist[b];
	}

	for(a=1; a < para_threads; a++) {
		for(b=0; b < para_nbs[a]->length && para_nbs[a]->index[b] >= 0; b++) {
			for(c=0; c < N * para_threads; c++) {
				if(para_nbs[a]->dist[b] > bestd[c]) {
					for(d=N-1; d>c; d--) {
						bestd[d] = bestd[d-1];
						besti[d] = besti[d-1];
					}
					besti[c] = para_nbs[a]->index[b];
					bestd[c] = para_nbs[a]->dist[b];
					break;
				}
			}
		}
	}

  char *chosen[600];
  AV* array = newAV();
  int i, j;
  int l1_words=0, l2_words=0;
  for (a = 0, i = 0; i < N && a < 600; a++) {
    int filtered=0;
    long long c = besti[a];
    if (dedupe && i > 0) {
      for (j=0; j<i; j++)
        if (strcasestr(&vocab[c * max_w], chosen[j]) ||
            strcasestr(chosen[j], &vocab[c * max_w])) {
              printf("filtering %s %s\n", chosen[j], &vocab[c * max_w]);
              filtered = 1;
        }
      if(filtered)
        continue;
    }
    if(merge_words > 0) {
        if(c >= merge_words) {
            if(l1_words > N / 2)
                continue;
            else
                l1_words++;
        } else {
            if(l2_words > N / 2)
                continue;
            else
                l2_words++;
        }
    }
    fflush(stdout);
    printf("%s l1:%d l2:%d i:%d a:%ld\n", &vocab[c * max_w], l1_words, l2_words, i, a);
 
    HV* hash = newHV();
    SV* word = newSVpvf(&vocab[c * max_w], 0);
		chosen[i] = &vocab[c * max_w];
    if(latin_enc == 0) SvUTF8_on(word);
    fflush(stdout);
    hv_store(hash, "word", strlen("word"), word , 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));
    i++;
  }
  hv_store(result, "paradigmatic", strlen("paradigmatic"), newRV_noinc((SV*)array), 0);
  
  for(b=0; b < MAX_NEIGHBOURS; b++) {
    besti[b] = -1L;
    bestd[b] = 0;
    bestn[b] = 0;
    bestp[b] = 0;
    bests[b] = 0;
  }

  if (M2) {
    printf("Waiting for syn threads to join\n");
    fflush(stdout);
    for (a = 0; a < syn_threads; a++) pthread_join(pt[a+para_threads], &syn_nbs[a]);
 for (a = 0; a <= syn_threads; a++)			printf("window pos: %d, sum: %f\n", a, window_sums[a]);
    printf("syn threads joint\n");
    fflush(stdout);

    for(b=0; b < syn_nbs[0]->length; b++) {
      besti[b] = syn_nbs[0]->index[b];
      bestd[b] = syn_nbs[0]->dist[b];
      bestn[b] = syn_nbs[0]->norm[b];
      bestp[b] = -1; //  syn_nbs[0]->pos[b];
      bests[b] = target_sums[syn_nbs[0]->index[b]];
    }
		
		float best_window_sum[MAX_NEIGHBOURS];
    int found_index=0, i=0, j, w;
    if(sort_by != 1 && sort_by != 2) { // sort by auto focus mean
      for(a=0; a < syn_threads; a++) {
        for(b=0; b < syn_nbs[a]->length; b++) {
					for(i=0; i < found_index; i++)
						if(besti[i] == syn_nbs[a]->index[b])
							break;
					if(i >= found_index) {
						besti[found_index++] = syn_nbs[a]->index[b];
//						printf("found: %s\n", &vocab[syn_nbs[a]->index[b] * max_w]);
					}
				}
			}
			printf("window: %d  -  syn_threads: %d, %d\n", window, syn_threads, (1 << syn_threads) -1);
			int wpos;
			for(i=0; i < found_index; i++) {
				bestd[i] = 0; bestn[i] = 0;
				for(w=1; w <  (1 << syn_threads); w++) { // loop through all possible windows
					float word_window_sum = 0, word_activation_sum = 0, total_window_sum = 0;
					int bits_set = 0;
					for(a=0; a < syn_threads; a++) {
						if((1 << a) & w) {
							wpos = (a >= window? a+1 : a);
							total_window_sum += window_sums[wpos];
						}
					}
//					printf("%d window-sum %f\n", w, total_window_sum);
					for(a=0; a < syn_threads; a++) {
						if((1 << a) & w) {
							wpos = (a >= window? a+1 : a);
 						  bits_set++;
						  for(b=0; b < syn_nbs[a]->length; b++)
							  if(besti[i] == syn_nbs[a]->index[b]) {
//                  word_window_sum += syn_nbs[a]->dist[b] *  syn_nbs[a]->norm[b]; // / window_sums[wpos];  // syn_nbs[a]->norm[b];
//                    word_window_sum += syn_nbs[a]->dist[b]; // / window_sums[wpos];  // syn_nbs[a]->norm[b];
//                    word_window_sum += syn_nbs[a]->norm[b]; // / window_sums[wpos];  // syn_nbs[a]->norm[b];
//                  word_window_sum = (word_window_sum + syn_nbs[a]->norm[b]) - (word_window_sum * syn_nbs[a]->norm[b]);  // syn_nbs[a]->norm[b];
                  word_window_sum += syn_nbs[a]->dist[b] - word_window_sum * syn_nbs[a]->dist[b];  // conormalied activation sum
									word_activation_sum += syn_nbs[a]->dist[b];
								}
						}
					}
//          if(bits_set) {
//						word_activation_sum /= bits_set;
//						word_window_sum /= bits_set;
//          }
//          word_window_sum /= total_window_sum;

          if(word_window_sum > bestn[i]) {
						bestn[i] = word_window_sum;
						bestd[i] = word_activation_sum;
						bestp[i] = w;
					}
			  }
			}
      for(i=0; i<found_index;i++) {
        for(j=0;j<found_index-1;j++) {
          if(bestn[j]<bestn[j+1]) {
            float tempd=bestn[j];
            bestn[j]=bestn[j+1];
            bestn[j+1]=tempd;
            tempd=bestd[j];
            bestd[j]=bestd[j+1];
            bestd[j+1]=tempd;
            int tempi=besti[j];
            besti[j]=besti[j+1];
            besti[j+1]=tempi;
            int tempp=bestp[j];
            bestp[j]=bestp[j+1];
            bestp[j+1]=tempp;
          }
        }
      }
//      for(i=0; i < found_index; i++) {
//				printf("found: %s - sum: %f - window: %d\n", &vocab[besti[i] * max_w], bestd[i], bestp[i]);
//			}

    } else if(sort_by ==1) { // single window position
       for(a=1; a < syn_threads; a++) {
        for(b=0; b < syn_nbs[a]->length; b++) {
          for(c=0; c < MAX_NEIGHBOURS; c++) {
            if(syn_nbs[a]->dist[b] > bestd[c]) {
              for(d=MAX_NEIGHBOURS-1; d>c; d--) {
                bestd[d] = bestd[d-1];
                besti[d] = besti[d-1];
                bestn[d] = bestn[d-1];
                bestp[d] = bestp[d-1];
              }
              besti[c] = syn_nbs[a]->index[b];
              bestd[c] = syn_nbs[a]->dist[b];
              bestn[c] = syn_nbs[a]->norm[b];
              bestp[c] = 1 << (-syn_nbs[a]->pos[b]+window - (syn_nbs[a]->pos[b] < 0 ? 1:0));
              break;
            }
          }
        }
      }
    } else { // sort by mean p
      for(a=1; a < syn_threads; a++) {
        for(b=0; b < syn_nbs[a]->length; b++) {
          for(c=0; c < MAX_NEIGHBOURS; c++) {
            if(target_sums[syn_nbs[a]->index[b]] > bests[c]) {
              for(d=MAX_NEIGHBOURS-1; d>c; d--) {
                bestd[d] = bestd[d-1];
                besti[d] = besti[d-1];
                bestn[d] = bestn[d-1];
                bestp[d] = bestp[d-1];
                bests[d] = bests[d-1];
              }
              besti[c] = syn_nbs[a]->index[b];
              bestd[c] = syn_nbs[a]->dist[b];
              bestn[c] = syn_nbs[a]->norm[b];
              bestp[c] = (1 << 2*window) - 1; // syn_nbs[a]->pos[b];
              bests[c] = target_sums[syn_nbs[a]->index[b]];
              break;
            }
          }
        }
      }
    }
    array = newAV();
    for (a = 0, i=0; a < MAX_NEIGHBOURS && besti[a] >= 0; a++) {
      long long c = besti[a];
      if (dedupe) {
	  		int filtered=0;
        for (j=0; j<i; j++)
          if (strcasestr(&vocab[c * max_w], chosen[j]) ||
              strcasestr(chosen[j], &vocab[c * max_w])) {
                printf("filtering %s %s\n", chosen[j], &vocab[c * max_w]);
								filtered = 1;
							}
				if(filtered)
					continue;
			}
			chosen[i++]=&vocab[c * max_w];
      HV* hash = newHV();
      SV* word = newSVpvf(&vocab[besti[a] * max_w], 0);
      if(latin_enc == 0) SvUTF8_on(word);
      hv_store(hash, "word", strlen("word"), word , 0);
      hv_store(hash, "rank", strlen("rank"), newSVuv(besti[a]), 0);
      hv_store(hash, "dist", strlen("dist"), newSVnv(bestd[a]), 0);
      hv_store(hash, "norm", strlen("norm"), newSVnv(bestn[a]), 0);
      hv_store(hash, "sum", strlen("sum"), newSVnv(target_sums[besti[a]]), 0);
      hv_store(hash, "pos", strlen("pos"), newSVnv(bestp[a]), 0);
      av_push(array, newRV_noinc((SV*)hash));
    }
    hv_store(result, "syntagmatic", strlen("syntagmatic"), newRV_noinc((SV*)array), 0);
  }
end:
	words = old_words;
	return newRV_noinc((SV*)result);
}

int dump_vecs(char *fname) {
	long i, j;
	FILE *f;
	/* if(words>200000) */
	/* 	words=200000; */

	if((f=fopen(fname, "w")) == NULL) {
			fprintf(stderr, "cannot open %s for writing\n", fname);
			return(-1);
	}
	fprintf(f, "%lld %lld\n", words, size);
	for (i=0; i < words; i++) {
		fprintf(f, "%s ", &vocab[i * max_w]);
		for(j=0; j < size - 1; j++)
			fprintf(f, "%f ", M[i*size + j]);
		fprintf(f, "%f\n", M[i*size + j]);
	}
	fclose(f);
	return(0);
}

