-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexiconparameters.cpp
105 lines (87 loc) · 2.27 KB
/
lexiconparameters.cpp
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
/*
* Quackle -- Crossword game artificial intelligence and analysis tool
* Copyright (C) 2005-2006 Jason Katz-Brown and John O'Laughlin.
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include <iostream>
#include <fstream>
#include "datamanager.h"
#include "lexiconparameters.h"
#include "uv.h"
using namespace Quackle;
LexiconParameters::LexiconParameters()
: m_dawg(0), m_gaddag(0)
{
}
LexiconParameters::~LexiconParameters()
{
unloadAll();
}
void LexiconParameters::unloadAll()
{
unloadDawg();
unloadGaddag();
}
void LexiconParameters::unloadDawg()
{
delete[] m_dawg;
m_dawg = 0;
}
void LexiconParameters::unloadGaddag()
{
delete[] m_gaddag;
m_gaddag = 0;
}
void LexiconParameters::loadDawg(const string &filename)
{
unloadDawg();
ifstream file(filename.c_str(), ios::in | ios::binary);
if (!file.is_open())
{
UVcout << "couldn't open dawg " << filename.c_str() << endl;
return;
}
m_dawg = new unsigned char[7000000];
int i = 0;
while (!file.eof())
{
file.read((char*)(m_dawg) + i, 7);
i += 7;
}
}
void LexiconParameters::loadGaddag(const string &filename)
{
unloadGaddag();
ifstream file(filename.c_str(), ios::in | ios::binary);
if (!file.is_open())
{
UVcout << "couldn't open gaddag " << filename.c_str() << endl;
UVcout << "Performance without gaddag won't be quite so awesome." << endl;
return;
}
m_gaddag = new unsigned char[40000000];
int i = 0;
while (!file.eof())
{
file.read((char*)(m_gaddag) + i, 4);
i += 4;
}
}
string LexiconParameters::findDictionaryFile(const string &lexicon)
{
return DataManager::self()->findDataFile("lexica", lexicon);
}