-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhfst_lexc_extensions.cc
57 lines (52 loc) · 2.02 KB
/
hfst_lexc_extensions.cc
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
namespace hfst {
// *** Wrapper variables for IOString outputs *** //
std::string hfst_lexc_output("");
std::string get_hfst_lexc_output() { return hfst::hfst_lexc_output; }
hfst::HfstTransducer * hfst_compile_lexc(hfst::lexc::LexcCompiler & comp, const std::string & filename, const std::string & error_stream)
{
hfst_lexc_output="";
if (error_stream == "cout")
{
comp.set_error_stream(&std::cout);
if (comp.getVerbosity() > 1)
std::cout << "Parsing the lexc file..." << std::endl;
comp.parse(filename.c_str());
if (comp.getVerbosity() > 1)
std::cout << "Compiling..." << std::endl;
hfst::HfstTransducer * retval = comp.compileLexical();
if (comp.getVerbosity() > 1)
std::cout << "Compilation done." << std::endl;
return retval;
}
else if (error_stream == "cerr")
{
comp.set_error_stream(&std::cerr);
if (comp.getVerbosity() > 1)
std::cerr << "Parsing the lexc file..." << std::endl;
comp.parse(filename.c_str());
if (comp.getVerbosity() > 1)
std::cerr << "Compiling..." << std::endl;
hfst::HfstTransducer * retval = comp.compileLexical();
if (comp.getVerbosity() > 1)
std::cerr << "Compilation done." << std::endl;
return retval;
}
else
{
std::ostringstream os(std::ostringstream::ate);
comp.set_error_stream(&os);
hfst::set_warning_stream(&os);
if (comp.getVerbosity() > 1)
os << "Parsing the lexc file..." << std::endl;
comp.parse(filename.c_str());
if (comp.getVerbosity() > 1)
os << "Compiling..." << std::endl;
hfst::HfstTransducer * retval = comp.compileLexical();
if (comp.getVerbosity() > 1)
os << "Compilation done." << std::endl;
hfst_lexc_output = os.str();
hfst::set_warning_stream(&std::cerr);
return retval;
}
}
}