source: _old/app/src/gue/guess.cc @ 5f4d9c3

Last change on this file since 5f4d9c3 was a6e708f, checked in by tom <tom@…>, 13 years ago

ANULOWANIE POPRZEDNIEGO COMMITU

Revert "Replacing old implementation with working implementation"

This reverts commit 1e121f45e2d091fcd34a893291b8453e350d5884.

Please enter the commit message for your changes. Lines starting
with '#' will be ignored, and an empty message aborts the commit.

Committer: tom <tom@lim.(none)>

On branch master
Changes to be committed:

(use "git reset HEAD <file>..." to unstage)

modified: _old/app/Makefile
deleted: _old/app/conf/Makefile
deleted: _old/app/conf/compiledic.conf
deleted: _old/app/conf/cor.conf
deleted: _old/app/conf/dgc.conf
deleted: _old/app/conf/dgp.conf
deleted: _old/app/conf/gph.conf
deleted: _old/app/conf/grp.conf
deleted: _old/app/conf/gue.conf
deleted: _old/app/conf/kor.conf
deleted: _old/app/conf/lem.conf
deleted: _old/app/conf/mar.conf
deleted: _old/app/conf/ser.conf
deleted: _old/app/conf/utt.conf
modified: _old/app/src/common/Makefile
modified: _old/app/src/compiledic/Makefile
modified: _old/app/src/compiledic/aut2fsa.cc
modified: _old/app/src/cor/Makefile
modified: _old/app/src/dgp/Makefile
new file: _old/app/src/dgp/canonize
new file: _old/app/src/dgp/dgc
modified: _old/app/src/dgp/grammar.hh
modified: _old/app/src/dgp/mgraph.hh
modified: _old/app/src/dgp/sgraph.hh
modified: _old/app/src/dgp/thesymbols.hh
new file: _old/app/src/dgp/tre
modified: _old/app/src/gue/Makefile
modified: _old/app/src/gue/guess.cc
modified: _old/app/src/kor/Makefile
modified: _old/app/src/kor/corlist.cc
modified: _old/app/src/kor/corr.cc
new file: _old/app/src/kor/corr.hh
modified: _old/app/src/kor/main.cc
modified: _old/app/src/lem/Makefile
modified: _old/app/src/lem/lem.cc
modified: _old/app/src/lib/Makefile
modified: _old/app/src/lib/auttools.cc
modified: _old/app/src/lib/symtab.cc
modified: _old/app/src/lib/tft.h
modified: _old/app/src/lib/tfti.h
modified: _old/app/src/lib/ttrans.h
modified: _old/app/src/lib/word.cc
modified: _old/app/src/lib/word.h
modified: _old/app/src/tok.c/Makefile
modified: _old/app/src/tok.c/cmdline_tok.ggo
modified: _old/app/src/tok.c/common_tok.cc
modified: _old/app/src/tok/Makefile
modified: _old/nawszelkiwypadek/tools/aut2fsa
modified: _old/nawszelkiwypadek/tools/cor_dic/makeLabels.pl
modified: _old/nawszelkiwypadek/tools/cor_dic/prep.pl
modified: _old/nawszelkiwypadek/tools/fsm2aut
modified: _old/nawszelkiwypadek/tools/gue_dic/canon.pl
modified: _old/nawszelkiwypadek/tools/gue_dic/compile_user_dict.pl
modified: _old/nawszelkiwypadek/tools/gue_dic/count_prefs.pl
modified: _old/nawszelkiwypadek/tools/gue_dic/cut_prefs.pl
modified: _old/nawszelkiwypadek/tools/gue_dic/makeLabels.pl
modified: _old/nawszelkiwypadek/tools/gue_dic/prep.pl
modified: _old/nawszelkiwypadek/tools/gue_dic/prep_user_dict.pl
modified: _old/nawszelkiwypadek/tools/gue_dic/rmDup.pl
modified: _old/nawszelkiwypadek/tools/gue_dic/stat.pl
modified: _old/nawszelkiwypadek/tools/gue_dic/stat_pre.pl
modified: _old/nawszelkiwypadek/tools/lem_dic/makeLabels.pl
modified: _old/nawszelkiwypadek/tools/lem_dic/prep.pl
modified: auto/defaults
modified: auto/options
modified: auto/output/Makefile
modified: auto/output/config_h
modified: auto/summary
modified: configure

  • Property mode set to 100644
File size: 3.1 KB
Line 
1
2#include "guess.h"
3
4#include <string.h>
5#include <iostream>
6#include <stdlib.h>
7#include <assert.h>
8#include <time.h>
9
10#define DICT 1
11#define COR 2
12#define DICT_P 3
13#define COR_P 4
14
15#define W_PRE 0.1
16#define W_SUF 0.9
17
18#define PREF_SIGN '_'
19
20
21using namespace std;
22
23
24Guess::Guess(const char* suf_file)
25  : _suf(suf_file) {
26  /*  _suf = NULL;
27  _pref = NULL;
28
29   if (strlen(suf_file) > 0)
30    _suf = new TFTiv<char, char>(suf_file);
31  if (strlen(pref_file) > 0)
32    _pref = new TFTiv<char, char>(corp_file);
33  */
34}
35
36
37  char buf[MAX_LINE];
38  char out[MAX_LINE];
39  char* buf0_s = buf;
40  char* word_t = NULL;
41  long state_s = 0;
42  unsigned length_s = buf0_s - buf;
43  long len = 0;
44  int i=0;
45
46int Guess::ana(const char* word, Words& result) {
47
48  assert(word && &result);
49
50  /* Word zawiera wyraz, ktory mamy zbadac.
51   * Nalezy przepisac go w odwrotnej kolejnosci do bufora,
52   * znalezc najdluzszy prefiks pasujacy do tego bufora
53   * separatorem jest '/' - za tym znakiem znajduje sie
54   * prawdopodobienstwo wystapienia danego opisu */
55
56  buf0_s = buf;
57  word_t = strdup(word);
58
59  if (reverse(word, buf) != 0)
60    return -1;
61
62 
63
64  state_s = -1;
65  //  printf("#buf0_s=%s, ", buf0_s);
66  state_s = _suf.pref(buf0_s, PREF_SIGN);
67  //  printf("#word=%s, buf0_s=%s\t", word, buf0_s);
68  /* jezeli state_s != -1 to oznacza, ze w slowniku jest zawarta
69   * informacja o prefiksie tego slowa.
70   * nie jest ona odwrocona, wiec porownujemy do word a nie do buf
71   */
72  //  printf("state_s=%d\t", state_s);
73  if (state_s != -1) {
74    state_s = _suf.pref(word_t, '~', state_s);
75    //    printf("state_s(wp)=%d, word_t=%s, word=%s\n", state_s, word_t, word);
76  }
77  if (state_s == -1) {
78  //  if (_suf != NULL)
79    buf0_s = buf;
80    state_s = _suf.pref(buf0_s, '~');
81    //    printf("state_s=%d\n", state_s);
82  }
83
84  length_s = buf0_s - buf;
85 
86  /* state jest stanem, od ktorego zaczyna sie sciezka opisujaca
87   * prawdopodobienstwo przeciwienstwa wystapienia opisu
88   * znajdujacego sie dalej na tej sciezce.
89   * Im mniejsza wartosc liczby tym wieksze prawdopodobienstwo */
90
91  len = 0;
92  i=0;
93 
94  //  if (_suf != NULL)
95    len = _suf.cont(state_s, out);
96  while (len > 0) {
97    i++;
98    add_word_prob(result, word, out, length_s, DICT);
99    len = _suf.cont(-1, out);
100  }
101   
102  return i;
103
104}
105
106
107int Guess::add_word_prob(Words& tab, const char* word, const char* path, unsigned len, int source) {
108
109  /* Dodaje do tablicy tab wyraz word wraz
110   * z prawdopodobienstwem i opisem zawartym
111   * w sciezce path */
112
113  //  printf("add_word_prob(");
114  //  fflush(stdout);
115  char p[MAX_LINE];
116
117  strcpy(p, path);
118
119  int probLen = strcspn(p, ";");
120  char prob[probLen+1];
121  strncpy(prob, p, probLen);
122  prob[probLen] = '\0';
123
124  char* desc = p + probLen+1; // +2 bo pomijamy jeszcze znak ';'
125
126  int i = tab.add(word, desc);
127
128  if (source==DICT) {
129    tab[i].len_suf(len);
130    tab[i].w_suf(atof(prob)); // + W_PRE*tab[i].w_suf()));
131    //    tab[i].w_suf((float)(W_SUF*(1000-atof(prob)) + W_PRE*tab[i].w_suf()));
132  }
133//   if (source==COR) {
134//     tab[i].len_pref(len);
135//     tab[i].w_pref(W_SUF*(1000-atof(prob)) + W_PRE*tab[i].w_pref());
136//   }
137//   printf(")\n");
138//   fflush(stdout);
139
140  return i;
141
142}
Note: See TracBrowser for help on using the repository browser.