-
Notifications
You must be signed in to change notification settings - Fork 8
/
lexicon.h
112 lines (94 loc) · 3.12 KB
/
lexicon.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**************************************************************************
* copyright : (C) 2004-2006 by Petr Schwarz & Pavel Matejka *
* UPGM,FIT,VUT,Brno *
* email : {schwarzp,matejkap}@fit.vutbr.cz *
**************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
**************************************************************************/
#ifndef _LEXICON_H
#define _LEXICON_H
#include <string>
#include <list>
#include <map>
#include <set>
#include <climits>
// error codes
#define LEX_OK 0
#define LEX_INPUTFILE 101
#define LEX_OUTPUTFILE 102
#define LEX_SYNTAX 103
#define LEX_MISSINGWORD 104
#define LEX_TRANSC 105
#define LEX_ALREDYEXISTS 106
#define LEX_NOTINIT 107
#define LEX_ALLPARTS INT_MAX
#define LEX_KEY 1000
#define LEX_XOR '0'
class Lexicon
{
public:
typedef struct TE
{
std::string trans;
float prob;
bool operator < (const TE &v) const
{
if(prob < v.prob)
return true;
else if(prob > v.prob)
return false;
return trans < v.trans;
}
} trans_entry;
protected:
class LexEntry
{
public:
std::string word;
std::string trans;
int pronVariant;
int part;
float prob;
bool operator < (const LexEntry &de) const
{
if(word < de.word)
return true;
else if(word > de.word)
return false;
else if(pronVariant < de.pronVariant)
return true;
else
return false;
}
};
std::multiset<LexEntry> words;
typedef struct
{
std::string fileName;
bool saveBinary;
} part_info;
std::map<int, part_info> parts;
char *strtok_buff;
char *StrTok(char *str, char *delims);
void Chomp(char *str);
int actPart;
public:
Lexicon();
~Lexicon();
void Clear() {words.clear(); parts.clear();};
int AddWord(char *word, char *trans, float prob, int part = 0, char *retErrWord = 0);
bool RemoveWord(char *word, int part = LEX_ALLPARTS);
int Load(char *file, int part = 0, bool saveBin = false, char *retErrWord = 0);
int Save(int part = 0, char *file = 0, bool saveBin = false);
int LoadBin(char *file, int part = 0, char *retErrWord = 0);
int SaveBin(int part, char *file);
bool WordExists(char *word);
bool GetTranscs(char *word, std::list<trans_entry> *list);
void SetActPart(int v) {actPart = v;}
};
#endif