Skip to content

Commit d39b93c

Browse files
committed
rename hfst_ol namespace to hfst_ospell to avoid conflicts
also HFST_THROW → HFSTOSPELL_THROW etc. since macro-replacement happens before namespacing fixes #34 - duplicated code from hfst shares namespace with hfst
1 parent eccbd6f commit d39b93c

18 files changed

+140
-140
lines changed

README

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,36 @@ and link with:
3333

3434
## Programming examples
3535

36-
The library lives in a namespace called hfst_ol. Pass (weighted!) Transducer
36+
The library lives in a namespace called hfst_ospell. Pass (weighted!) Transducer
3737
pointers to the Speller constructor, eg.:
3838

3939
FILE * error_source = fopen(error_filename, "r");
4040
FILE * lexicon_file = fopen(lexicon_filename, "r");
41-
hfst_ol::Transducer * error;
42-
hfst_ol::Transducer * lexicon;
41+
hfst_ospell::Transducer * error;
42+
hfst_ospell::Transducer * lexicon;
4343
try {
44-
error = new hfst_ol::Transducer(error_source);
45-
lexicon = new hfst_ol::Transducer(lexicon_file);
46-
} catch (hfst_ol::TransducerParsingException& e) {
44+
error = new hfst_ospell::Transducer(error_source);
45+
lexicon = new hfst_ospell::Transducer(lexicon_file);
46+
} catch (hfst_ospell::TransducerParsingException& e) {
4747
/* problem with transducer file, usually completely
4848
different type of file - there's no magic number
4949
in the header to check for this */
5050
}
51-
hfst_ol::Speller * speller;
51+
hfst_ospell::Speller * speller;
5252
try {
53-
speller = new hfst_ol::Speller(error, lexicon);
54-
} catch (hfst_ol::AlphabetTranslationException& e) {
53+
speller = new hfst_ospell::Speller(error, lexicon);
54+
} catch (hfst_ospell::AlphabetTranslationException& e) {
5555
/* problem with translating between the two alphabets */
5656
}
5757

5858

5959
And use the functions:
6060

6161
// returns true if line is found in lexicon
62-
bool hfst_ol::Speller::check(char * line);
62+
bool hfst_ospell::Speller::check(char * line);
6363

6464
// CorrectionQueue is a priority queue, sorted by weight
65-
hfst_ol::CorrectionQueue hfst_ol::Speller::correct(char * line);
65+
hfst_ospell::CorrectionQueue hfst_ospell::Speller::correct(char * line);
6666

6767

6868
to communicate with it. See main.cc for a concrete usage example.

ZHfstOspeller.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ using std::map;
3737
#include "hfst-ol.h"
3838
#include "ZHfstOspeller.h"
3939

40-
namespace hfst_ol
40+
namespace hfst_ospell
4141
{
4242

4343
#if HAVE_LIBARCHIVE
@@ -475,4 +475,4 @@ ZHfstOspeller::metadata_dump() const
475475
return metadata_.debug_dump();
476476

477477
}
478-
} // namespace hfst_ol
478+
} // namespace hfst_ospell

ZHfstOspeller.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#include "hfst-ol.h"
4242
#include "ZHfstOspellerXmlMetadata.h"
4343

44-
namespace hfst_ol
44+
namespace hfst_ospell
4545
{
4646
//! @brief ZHfstOspeller class holds one speller contained in one
4747
//! zhfst file.
@@ -195,7 +195,7 @@ namespace hfst_ol
195195
explicit ZHfstTemporaryWritingError(const std::string& message) : ZHfstException(message) {}
196196
};
197197

198-
} // namespace hfst_ol
198+
} // namespace hfst_ospell
199199

200200

201201
#endif // HFST_OSPELL_OSPELLER_SET_H_

ZHfstOspellerXmlMetadata.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ using std::map;
4242
#include "ZHfstOspeller.h"
4343
#include "ZHfstOspellerXmlMetadata.h"
4444

45-
namespace hfst_ol
45+
namespace hfst_ospell
4646
{
4747

4848
ZHfstOspellerXmlMetadata::ZHfstOspellerXmlMetadata()
@@ -1034,6 +1034,6 @@ ZHfstOspellerXmlMetadata::debug_dump() const
10341034
return retval;
10351035
}
10361036

1037-
} // namespace hfst_ol
1037+
} // namespace hfst_ospell
10381038

10391039

ZHfstOspellerXmlMetadata.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ using std::map;
3535
#include "ospell.h"
3636
#include "hfst-ol.h"
3737

38-
namespace hfst_ol
38+
namespace hfst_ospell
3939
{
4040
//! @brief data type for associating set of translations to languages.
4141
typedef std::map<std::string,std::string> LanguageVersions;

hfst-ol.cc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# include <config.h>
1919
#endif
2020

21-
namespace hfst_ol {
21+
namespace hfst_ospell {
2222

2323
template <typename T>
2424
inline T hfst_deref(T* ptr)
@@ -121,7 +121,7 @@ TransducerHeader::read_property(bool& property, FILE* f)
121121
} else {
122122
unsigned int prop;
123123
if (fread(&prop,sizeof(uint32_t),1,f) != 1) {
124-
HFST_THROW_MESSAGE(HeaderParsingException,
124+
HFSTOSPELL_THROW_MESSAGE(HeaderParsingException,
125125
"Header ended unexpectedly\n");
126126
}
127127
if (prop == 0)
@@ -168,23 +168,23 @@ void TransducerHeader::skip_hfst3_header(FILE * f)
168168
} else {
169169
if (fread(&remaining_header_len,
170170
sizeof(remaining_header_len), 1, f) != 1) {
171-
HFST_THROW_MESSAGE(HeaderParsingException,
171+
HFSTOSPELL_THROW_MESSAGE(HeaderParsingException,
172172
"Found broken HFST3 header\n");
173173
}
174174
}
175175
//std::cerr << "remaining_header_len " << remaining_header_len << std::endl;
176176
if (getc(f) != '\0') {
177-
HFST_THROW_MESSAGE(HeaderParsingException,
177+
HFSTOSPELL_THROW_MESSAGE(HeaderParsingException,
178178
"Found broken HFST3 header\n");
179179
}
180180
char * headervalue = new char[remaining_header_len];
181181
if (fread(headervalue, remaining_header_len, 1, f) != 1)
182182
{
183-
HFST_THROW_MESSAGE(HeaderParsingException,
183+
HFSTOSPELL_THROW_MESSAGE(HeaderParsingException,
184184
"HFST3 header ended unexpectedly\n");
185185
}
186186
if (headervalue[remaining_header_len - 1] != '\0') {
187-
HFST_THROW_MESSAGE(HeaderParsingException,
187+
HFSTOSPELL_THROW_MESSAGE(HeaderParsingException,
188188
"Found broken HFST3 header\n");
189189
}
190190
std::string header_tail(headervalue, remaining_header_len);
@@ -193,7 +193,7 @@ void TransducerHeader::skip_hfst3_header(FILE * f)
193193
if (header_tail.find("HFST_OL") != type_field + 5 &&
194194
header_tail.find("HFST_OLW") != type_field + 5) {
195195
delete[] headervalue;
196-
HFST_THROW_MESSAGE(
196+
HFSTOSPELL_THROW_MESSAGE(
197197
TransducerTypeException,
198198
"Transducer has incorrect type, should be "
199199
"hfst-optimized-lookup\n");
@@ -268,7 +268,7 @@ TransducerHeader::TransducerHeader(FILE* f)
268268
sizeof(TransitionTableIndex),1,f) != 1||
269269
fread(&number_of_transitions,
270270
sizeof(TransitionTableIndex),1,f) != 1) {
271-
HFST_THROW_MESSAGE(HeaderParsingException,
271+
HFSTOSPELL_THROW_MESSAGE(HeaderParsingException,
272272
"Header ended unexpectedly\n");
273273
}
274274
}
@@ -429,15 +429,15 @@ void TransducerAlphabet::read(FILE * f, SymbolNumber number_of_symbols)
429429
while ( (byte = fgetc(f)) != 0 ) {
430430
/* pass over epsilon */
431431
if (byte == EOF) {
432-
HFST_THROW(AlphabetParsingException);
432+
HFSTOSPELL_THROW(AlphabetParsingException);
433433
}
434434
}
435435

436436
for (SymbolNumber k = 1; k < number_of_symbols; ++k) {
437437
char * sym = line;
438438
while ( (byte = fgetc(f)) != 0 ) {
439439
if (byte == EOF) {
440-
HFST_THROW(AlphabetParsingException);
440+
HFSTOSPELL_THROW(AlphabetParsingException);
441441
}
442442
*sym = static_cast<char>(byte);
443443
++sym;
@@ -667,7 +667,7 @@ void IndexTable::read(FILE * f,
667667
size_t table_size = number_of_table_entries*TransitionIndex::SIZE;
668668
indices = (char*)(malloc(table_size));
669669
if (fread(indices,table_size, 1, f) != 1) {
670-
HFST_THROW(IndexTableReadingException);
670+
HFSTOSPELL_THROW(IndexTableReadingException);
671671
}
672672
if (is_big_endian()) {
673673
convert_to_big_endian();
@@ -706,7 +706,7 @@ void TransitionTable::read(FILE * f,
706706
size_t table_size = number_of_table_entries*Transition::SIZE;
707707
transitions = (char*)(malloc(table_size));
708708
if (fread(transitions, table_size, 1, f) != 1) {
709-
HFST_THROW(TransitionTableReadingException);
709+
HFSTOSPELL_THROW(TransitionTableReadingException);
710710
}
711711
if (is_big_endian()) {
712712
convert_to_big_endian();
@@ -1032,4 +1032,4 @@ SymbolNumber Encoder::find_key(char ** p)
10321032
return s;
10331033
}
10341034

1035-
} // namespace hfst_ol
1035+
} // namespace hfst_ospell

hfst-ol.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include <utility>
3535
#include "ol-exceptions.h"
3636

37-
namespace hfst_ol {
37+
namespace hfst_ospell {
3838

3939
typedef uint16_t SymbolNumber;
4040
typedef uint32_t TransitionTableIndex;
@@ -457,6 +457,6 @@ void debug_print(printable p)
457457
}
458458
}
459459

460-
} // namespace hfst_ol
460+
} // namespace hfst_ospell
461461

462462
#endif // HFST_OSPELL_HFST_OL_H_

main-cicling.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,24 +140,24 @@ int main(int argc, char **argv)
140140
return 1;
141141
}
142142
}
143-
hfst_ol::Transducer * mutator;
144-
hfst_ol::Transducer * lexicon;
145-
mutator = new hfst_ol::Transducer(mutator_file);
143+
hfst_ospell::Transducer * mutator;
144+
hfst_ospell::Transducer * lexicon;
145+
mutator = new hfst_ospell::Transducer(mutator_file);
146146
if (!mutator->is_weighted()) {
147147
std::cerr << "Error source was unweighted, exiting\n\n";
148148
return EXIT_FAILURE;
149149
}
150-
lexicon = new hfst_ol::Transducer(lexicon_file);
150+
lexicon = new hfst_ospell::Transducer(lexicon_file);
151151
if (!lexicon->is_weighted()) {
152152
std::cerr << "Lexicon was unweighted, exiting\n\n";
153153
return EXIT_FAILURE;
154154
}
155155

156-
hfst_ol::Speller * speller;
156+
hfst_ospell::Speller * speller;
157157

158158
try {
159-
speller = new hfst_ol::Speller(mutator, lexicon);
160-
} catch (hfst_ol::AlphabetTranslationException& e) {
159+
speller = new hfst_ospell::Speller(mutator, lexicon);
160+
} catch (hfst_ospell::AlphabetTranslationException& e) {
161161
std::cerr <<
162162
"Unable to build speller - symbol " << e.what() << " not "
163163
"present in lexicon's alphabet\n";
@@ -182,7 +182,7 @@ int main(int argc, char **argv)
182182
assert(tok != NULL);
183183
char* context = strdup(tok);
184184
// unknown += (corr in NWORDS)
185-
hfst_ol::CorrectionQueue corrections = speller->correct(mispelt);
185+
hfst_ospell::CorrectionQueue corrections = speller->correct(mispelt);
186186
if (corrections.size() == 0)
187187
{
188188
// correction too far

0 commit comments

Comments
 (0)