Index: src/gue/Makefile
===================================================================
--- src/gue/Makefile	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
+++ src/gue/Makefile	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
@@ -0,0 +1,55 @@
+include ../../config.mak
+
+ifeq ($(BUILD_STATIC), yes)
+  LDFLAGS += -static
+endif
+
+LDFLAGS +=
+CXXFLAGS += -O2 -fpermissive
+
+LIB_PATH=../lib
+COMMON_PATH=../common
+CMDLINE_FILE='"../gue/cmdline.h"'
+
+
+gue: main.cc guess.o $(LIB_PATH)/auttools.o $(LIB_PATH)/word.o \
+      cmdline.c common_guess.o common.o
+	$(CXX) $(CXXFLAGS)  main.cc guess.o \
+	$(LIB_PATH)/auttools.o $(LIB_PATH)/word.o cmdline.c common.o common_guess.o \
+	-o gue $(LDFLAGS)
+
+guess.o: guess.h guess.cc
+	$(CXX) $(CXXFLAGS) -c guess.cc
+
+common_guess.o: cmdline.h  common_guess.cc common_guess.h
+	$(CXX) $(CXXFLAGS) -c common_guess.cc
+
+common.o: $(COMMON_PATH)/cmdline_common.ggo $(COMMON_PATH)/common.cc \
+	 $(COMMON_PATH)/common.h
+	$(CXX) $(CXXFLAGS) -c -D _CMDLINE_FILE=$(CMDLINE_FILE) $(COMMON_PATH)/common.cc
+
+cmdline.c cmdline.h: cmdline.ggo
+	$(GENGETOPT) -i cmdline.ggo --conf-parser
+
+cmdline.ggo: cmdline_guess.ggo $(COMMON_PATH)/cmdline_common.ggo
+	cat cmdline_guess.ggo $(COMMON_PATH)/cmdline_common.ggo > cmdline.ggo
+
+
+clean: clean.cmdline
+	rm *.o || true
+	rm gue || true
+
+clean.cmdline:
+	rm cmdline.* || true
+
+.PHONY: install
+install:
+ifdef BIN_DIR
+	install -m 0755 gue $(BIN_DIR)
+endif
+
+.PHONY: uninstall
+uninstall:
+ifdef BIN_DIR
+	rm $(BIN_DIR)/gue
+endif
Index: src/gue/cmdline_guess.ggo
===================================================================
--- src/gue/cmdline_guess.ggo	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
+++ src/gue/cmdline_guess.ggo	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
@@ -0,0 +1,12 @@
+package "guess"
+version "0.1"
+
+option "guess_count"		n	"Guess up to n descriptions" int default="0" no
+option "delta"			-	"Stop displaying answers after fall of weight" float default="0.2" no
+option "cut-off"		-	"Do not display answers with less weight than cut-off" int default="200" no
+option "dictionary-home"	-	"dh" string typestr="FILENAME" no hidden
+option "dictionary"		d	"File with dictionary information" string typestr="filename" default="gue.bin" no
+option "per-info"		v	"Display performance information" flag off
+option "weights"		w	"Print weights" flag off
+option "no-uppercase"		-	"Do not process form containing uppercase letters" flag off
+
Index: src/gue/common_guess.cc
===================================================================
--- src/gue/common_guess.cc	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
+++ src/gue/common_guess.cc	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
@@ -0,0 +1,60 @@
+#include <stdlib.h>
+#include <string.h>
+#include "common_guess.h"
+
+int guess_count=0;
+double delta=0.1;
+int cut_off=100;
+char dictionary[255];
+bool per_info=false;
+bool weights=false;
+
+void process_guess_options(gengetopt_args_info* args)
+{
+
+  if(args->dictionary_given)
+    {
+      expand_path(args->dictionary_arg,dictionary);
+      if(file_accessible(dictionary)!=0)
+	{
+	  fprintf(stderr,"Cannot open the dictionary file: %s\nAborting.\n",dictionary);
+	  exit(1);
+	}
+    }
+  else if (args->dictionary_home_given && args->language_given)
+    {
+      char buf[255];
+      expand_path(args->dictionary_home_arg, buf);
+      sprintf(dictionary,"%s/%s/gue.bin",buf,args->language_arg);
+      if(file_accessible(dictionary)!=0)
+	{
+	  fprintf(stderr,"Cannot open the dictionary file: %s\nAborting.\n",dictionary);
+	  exit(1);
+	}
+    }
+
+  if(args->guess_count_given)
+    guess_count=args->guess_count_arg;
+  else
+    guess_count=0;
+
+  if(guess_count==0)
+    guess_count=100;
+
+  if(args->delta_given)
+    delta=args->delta_arg;
+  else
+    delta=0.1;
+
+  if(args->cut_off_given)
+    cut_off=args->cut_off_arg;
+  else
+    cut_off=100;
+
+  if(args->per_info_given)
+    per_info=args->per_info_flag;
+
+  if(args->weights_given)
+    weights=true;
+
+}
Index: src/gue/common_guess.h
===================================================================
--- src/gue/common_guess.h	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
+++ src/gue/common_guess.h	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
@@ -0,0 +1,20 @@
+#ifndef __COMMON_GUESS_H
+#define __COMMON_GUESS_H
+
+#include <stdio.h>
+#define _CMDLINE_FILE "../gue/cmdline.h"
+#include "../common/common.h"
+#include "cmdline.h"
+
+#define DIC_FILE "gue.bin"
+
+extern int guess_count;
+extern double delta;
+extern int cut_off;
+extern char dictionary[];
+extern bool per_info;
+extern bool weights;
+
+void process_guess_options(gengetopt_args_info* args);
+
+#endif
Index: src/gue/guess.cc
===================================================================
--- src/gue/guess.cc	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
+++ src/gue/guess.cc	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
@@ -0,0 +1,138 @@
+
+#include "guess.h"
+
+#include <cstring>
+#include <iostream>
+#include <cstdlib>
+#include <cassert>
+#include <ctime>
+
+#define DICT 1
+#define COR 2
+#define DICT_P 3
+#define COR_P 4
+
+#define W_PRE 0.1
+#define W_SUF 0.9
+
+#define PREF_SIGN '_'
+
+Guess::Guess(const char* suf_file)
+  : _suf(suf_file) {
+  /*  _suf = NULL;
+  _pref = NULL;
+
+   if (strlen(suf_file) > 0)
+    _suf = new TFTiv<char, char>(suf_file);
+  if (strlen(pref_file) > 0)
+    _pref = new TFTiv<char, char>(corp_file);
+  */
+}
+
+
+  char buf[MAX_LINE];
+  char out[MAX_LINE];
+  char* buf0_s = buf;
+  char* word_t = NULL;
+  long state_s = 0;
+  unsigned length_s = buf0_s - buf;
+  long len = 0;
+  int i=0;
+
+int Guess::ana(const char* word, Words& result) {
+
+  assert(word && &result);
+
+  /* Word zawiera wyraz, ktory mamy zbadac.
+   * Nalezy przepisac go w odwrotnej kolejnosci do bufora,
+   * znalezc najdluzszy prefiks pasujacy do tego bufora
+   * separatorem jest '/' - za tym znakiem znajduje sie
+   * prawdopodobienstwo wystapienia danego opisu */
+
+  buf0_s = buf;
+  word_t = strdup(word);
+
+  if (reverse(word, buf) != 0)
+    return -1;
+
+ 
+
+  state_s = -1;
+  //  printf("#buf0_s=%s, ", buf0_s);
+  state_s = _suf.pref(buf0_s, PREF_SIGN);
+  //  printf("#word=%s, buf0_s=%s\t", word, buf0_s);
+  /* jezeli state_s != -1 to oznacza, ze w slowniku jest zawarta
+   * informacja o prefiksie tego slowa.
+   * nie jest ona odwrocona, wiec porownujemy do word a nie do buf
+   */
+  //  printf("state_s=%d\t", state_s);
+  if (state_s != -1) {
+    state_s = _suf.pref(word_t, '~', state_s);
+    //    printf("state_s(wp)=%d, word_t=%s, word=%s\n", state_s, word_t, word);
+  }
+  if (state_s == -1) {
+  //  if (_suf != NULL) 
+    buf0_s = buf;
+    state_s = _suf.pref(buf0_s, '~');
+    //    printf("state_s=%d\n", state_s);
+  }
+
+  length_s = buf0_s - buf;
+ 
+  /* state jest stanem, od ktorego zaczyna sie sciezka opisujaca
+   * prawdopodobienstwo przeciwienstwa wystapienia opisu
+   * znajdujacego sie dalej na tej sciezce.
+   * Im mniejsza wartosc liczby tym wieksze prawdopodobienstwo */
+
+  len = 0;
+  i=0;
+  
+  //  if (_suf != NULL)
+    len = _suf.cont(state_s, out);
+  while (len > 0) {
+    i++;
+    add_word_prob(result, word, out, length_s, DICT);
+    len = _suf.cont(-1, out);
+  }
+    
+  return i;
+
+}
+
+
+int Guess::add_word_prob(Words& tab, const char* word, const char* path, unsigned len, int source) {
+
+  /* Dodaje do tablicy tab wyraz word wraz
+   * z prawdopodobienstwem i opisem zawartym
+   * w sciezce path */
+
+  //  printf("add_word_prob(");
+  //  fflush(stdout);
+  char p[MAX_LINE];
+
+  strcpy(p, path);
+
+  int probLen = strcspn(p, ";");
+  char prob[probLen+1];
+  strncpy(prob, p, probLen);
+  prob[probLen] = '\0';
+
+  char* desc = p + probLen+1; // +2 bo pomijamy jeszcze znak ';'
+
+  int i = tab.add(word, desc);
+
+  if (source==DICT) {
+    tab[i].len_suf(len);
+    tab[i].w_suf(atof(prob)); // + W_PRE*tab[i].w_suf()));
+    //    tab[i].w_suf((float)(W_SUF*(1000-atof(prob)) + W_PRE*tab[i].w_suf()));
+  }
+//   if (source==COR) {
+//     tab[i].len_pref(len);
+//     tab[i].w_pref(W_SUF*(1000-atof(prob)) + W_PRE*tab[i].w_pref());
+//   }
+//   printf(")\n");
+//   fflush(stdout);
+
+  return i;
+
+}
Index: src/gue/guess.h
===================================================================
--- src/gue/guess.h	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
+++ src/gue/guess.h	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
@@ -0,0 +1,56 @@
+
+#include "../lib/tfti.h"
+#include "../lib/word.h"
+
+#include <sys/timeb.h>
+
+/**************************************************************
+ * Zawiera definicje klasy Guess.                              *
+ *                                                            *
+ * Klasa ta pozwala na okreslenie opisu slowa nie             *
+ * znajdujacego sie w slowniku wraz z prawdopodobienstwem     *
+ * jego wystapienia.                                          *
+ *************************************************************/
+
+class Guess {
+
+ public:
+
+  // nazawa pliku slownika w parametrze
+  Guess(const char* suf_file);
+
+  // zwraca tablice opisow slowa wraz z prawdopodobienstwem ich wystapienia
+  int ana(const char* word, Words& result);
+
+  long time_overall;
+
+ private:
+
+  // sufiksy
+  TFTiv<char, char> _suf;
+
+  // prefiksy
+  TFTiv<char, char> _pref;
+
+  //odwraca ciag znakow
+  int reverse(const char* src, char* dest) {
+ 
+  //  assert((src != NULL) && (dest != NULL));
+
+    const char* c = src;
+  
+    int len = strlen(src);
+
+    for (int i=1; i<=len; ++i) {
+      dest[i-1] = src[len-i];
+    }
+
+    dest[len] = '\0';
+
+    return 0;
+  }
+
+  //dodaje nowy element do tablicy WordsProb
+  int add_word_prob(Words& tab, const char* word, const char* path, unsigned len, int source);
+
+};
Index: src/gue/main.cc
===================================================================
--- src/gue/main.cc	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
+++ src/gue/main.cc	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
@@ -0,0 +1,237 @@
+#include <time.h>
+#include <stdlib.h>
+#include "../lib/iotools.h"
+#define _CMDLINE_FILE "../gue/cmdline.h"
+#define CONFIGFILE1 "/home/ynka/utt/utt-0.9/conf/gue.conf"
+#define CONFIGFILE2 "/home/ynka/utt/utt-0.9/conf/gue.conf"
+#include "../common/common.h"
+#include "common_guess.h"
+#include "guess.h"
+#include "cmdline.h"
+
+#define W_SUFF 0.6
+#define W_PREF 0.4
+
+
+int main(int argc, char** argv) {
+
+  //  int non_standard_config=0;
+
+  gengetopt_args_info args;
+
+  if(cmdline_parser(argc, argv, &args) != 0)
+    exit(1);
+
+  process_config_files(&args,argv[0]);
+  process_common_options(&args,argv[0]);
+  process_guess_options(&args);
+
+  char line[MAX_LINE];
+  char outline[MAX_LINE];
+  char parms[MAX_LINE], desc[MAX_LINE], lemma[MAX_LINE];
+  long line_count = 0;
+  
+  Guess guess(dictionary);
+  int words_count=0;
+  time_t start_time = time(NULL);
+  
+  //  Segment seg;
+  Words tab;
+  while (fgets(line, MAX_LINE, inputf))
+    {
+      line_count++;
+      int start, len;
+      
+      //      line[strlen(line)-1] = '\0';
+      
+      if (!process_seg(line, args))
+	fputs(line,outputf);
+      else
+	{
+	  char form[MAX_FORM];
+	  words_count++;
+	  tab.clear();
+	  getfield(line,input_field_prefix,form);
+	  if (form==NULL) continue;//BZDURA
+	  
+	  guess.ana(form, tab);
+	  
+	  if ((tab.count()==0) && (!args.no_fail_flag)) // no guesses - analysis was unsuccessful
+	    fputs(line, failedf);
+	  else
+	    {
+
+// 	      if (copy_processed)
+// 		fputs(line, stdout);
+// 	      continue;
+// 	    }
+	  // we've got some guesses. Do we want to print it?
+// 	      if (args.only_fail_flag)
+// 	    continue;
+
+	      float last_weight=0;
+	      int i=0;
+	      int count=0;
+	      unsigned first=1;
+	      char* parms_end = parms;
+	      char last_lemma[MAX_LINE];
+
+	      count = 1;
+
+	      	      tab.sort();
+	      
+	      while (count < tab.count() && count <= guess_count)
+		if (first || tab[count].w_suf() >= cut_off && tab[count].w_suf() >= delta * last_weight)
+		  {
+		    first=0;
+		    last_weight = tab[i].w_suf();
+		    count++;
+		  }
+		else
+		  break;
+	      
+	      // drukujemy count pierwszych z tab
+
+
+	      if(one_line)
+		{
+		  char* descp=desc;
+		  for (int i=0; i< count; ++i)
+		    {
+		      descp += sprintf(descp," %s%s,%s", output_field_prefix, tab[i].lemma(), tab[i].descr());
+		      if(weights) descp += sprintf(descp,":%d",(int)tab[i].w_suf());
+		    }
+		  strcpy(outline,line);
+		  outline[strlen(outline)-1]='\0';
+		  strcat(outline,desc);
+		  strcat(outline,"\n");
+		  fputs(outline, outputf);
+		  if (copy_processed)
+		    fputs(line,outputf);
+		}
+	      else if(one_field)
+		{
+		  char* descp=desc;
+		  for (int i=0; i< count; ++i)
+		    if(i==0)
+		      {
+			descp += sprintf(descp," %s%s,%s", output_field_prefix, tab[i].lemma(), tab[i].descr());
+			if(weights) descp += sprintf(descp,":%d",(int)tab[i].w_suf());
+		      }
+		    else
+		      {
+			if(strcmp(tab[i].lemma(),tab[i-1].lemma())==0)
+			  descp += sprintf(descp,",%s",tab[i].descr());
+			else
+			  descp += sprintf(descp,";%s,%s",tab[i].lemma(),tab[i].descr());
+			if(weights) descp += sprintf(descp,":%d",(int)tab[i].w_suf());
+		      }
+		  
+		  strcpy(outline,line);
+		  outline[strlen(outline)-1]='\0';
+		  strcat(outline,desc);
+		  strcat(outline,"\n");
+		  fputs(outline, outputf);
+		  if (copy_processed)
+		    fputs(line,outputf);
+		}
+	      else
+		{
+		  for (int i=0; i< count; ++i)
+		    {
+		      // kolejne opisy - kolejne linie.
+		      char* descp=desc;
+		      descp += sprintf(desc, " %s%s,%s", output_field_prefix, tab[i].lemma(), tab[i].descr());
+		      if(weights) descp += sprintf(descp,":%d",(int)tab[i].w_suf());
+		      descp += sprintf(descp,"\n");
+		      strcpy(outline,line);
+		      outline[strlen(outline)-1]='\0';
+		      strcat(outline,desc);
+		      fputs(outline, outputf);
+		    }
+		  if (copy_processed)
+		    fputs(line,outputf);
+		}
+	    }
+	}
+      if(args.interactive_flag) 
+	fflush(outputf), fflush(failedf);
+      
+    }
+  cmdline_parser_free(&args);
+}
+
+
+
+
+
+
+
+
+// 	      while ((i=tab.next()) != -1 && count++<guess_count) {
+// 		/* if we have "one-line" flag then everything goes in one segment as many fields,
+// 		 * if we have "one-field" flag everything goes in one segment as ONE field:
+// 		 * - diferent lemmas are separated with ';', sequent descriptions to one lemma
+// 		 *   are separated with ','
+// 		 */
+// 		if ((!first) && (tab[i].w_suf() < cut_off) || (tab[i].w_suf() < delta * last_weight)) {
+// 		  break;
+// 		}
+// 		if (first) {
+// 		  parms_end += sprintf(parms_end, "%s", output_field_prefix);
+// 		} else if (!args.one_field_flag)
+// 		  parms_end += sprintf(parms_end, "%s", output_field_prefix);
+		
+// 		if (!args.one_field_flag || strcmp(last_lemma, tab[i].lemma()) != 0) {
+// 		  if (args.one_field_flag && !first)
+// 		    parms_end += sprintf(parms_end, ";");
+// 		  parms_end += sprintf(parms_end, "%s", tab[i].lemma());
+// 		  strcpy(last_lemma, tab[i].lemma());
+// 		}
+		
+// 		first=0;
+		
+// 		last_weight = tab[i].w_suf();
+// 		if (!weights)
+// 		  parms_end += sprintf(parms_end, ",%s:%d",  tab[i].descr(), (int)tab[i].w_suf());
+// 		else
+// 		  parms_end += sprintf(parms_end, ",%s", tab[i].descr());
+		
+// 		if (!args.one_field_flag) {
+// 		  seg.addfield(parms);
+// 		  parms_end = parms;
+// 		}
+		
+// 		if (!(args.one_field_flag || args.one_line_flag)) {
+// 		  seg.print(outline);
+// 		  fputs(outline, outputf);
+// 		  --seg.auxn;
+// 		}
+// 		//if (copy_processed)
+// 		//  fputs(outline, stdout);
+// 	      } //while
+	      
+// 	      if (args.one_field_flag)
+// 		seg.addfield(parms);
+	      
+// 	      if (args.one_field_flag || args.one_line_flag){
+// 		seg.print(outline);
+// 		fputs(outline, outputf);
+// 	      }
+// 	    } else { // if (process_segment)
+// 	    // jak to nie jest wyraz - to przepisz token na wyjscie.
+// 	    //      printtok(line, start, len, cat, form);
+// 	    seg.print(outline);
+// 	    fputs(outline, outputf);
+// 	    if (copy_processed)
+// 	      fputs(outline, stdout);
+// 	  }
+// 	}
+//       time_t end_time = time(NULL);
+//       if (per_info) {
+// 	printf("Liczba sÂ³Ã³w: %d\n", words_count);
+// 	printf("Czas analizy: %d sekund\n", end_time-start_time);
+//       }
+//       cmdline_parser_free(&args);
+//     }
+  
