source: app/src/gue/guess.cc @ 2f8d6d8

Last change on this file since 2f8d6d8 was 2f8d6d8, checked in by to <to@…>, 15 years ago

Poprawki kodu w C++ (nazwy plikow naglowkowych, using ...).

modified: compiledic/aut2fsa.cc
modified: dgp/grammar.hh
modified: dgp/mgraph.hh
modified: dgp/sgraph.hh
modified: dgp/thesymbols.hh
modified: gue/guess.cc
modified: kor/corlist.cc
modified: lem/lem.cc
modified: lib/symtab.cc
modified: lib/tft.h
modified: lib/tfti.h
modified: lib/ttrans.h
modified: lib/word.cc
modified: lib/word.h

  • 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.