Skip to content
This repository was archived by the owner on Sep 13, 2022. It is now read-only.

Commit b567fda

Browse files
committed
Make ZPar loading messages go to STDERR instead of STDOUT
- This is needed for compatibility with Apache Storm.
1 parent 0dd07f1 commit b567fda

1 file changed

Lines changed: 19 additions & 20 deletions

File tree

src/zpar.lib.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,14 @@ extern "C" int load_tagger(void* vzps, const char* sFeaturePath) {
124124
if (!FileExists(sTaggerFeatureFile)) {
125125
return 1;
126126
}
127+
128+
// redirect stdout to stderr since ZPar prints status
129+
// messages on stdout instead of stderr
130+
std::streambuf* oldCout = std::cout.rdbuf();
131+
std::cout.rdbuf(std::cerr.rdbuf());
127132
CTagger* tagger = new CTagger(sTaggerFeatureFile, false);
133+
// restore stdout
134+
std::cout.rdbuf(oldCout);
128135
zps->tagger = tagger;
129136
return 0;
130137
}
@@ -148,7 +155,13 @@ extern "C" int load_parser(void* vzps, const char *sFeaturePath) {
148155
if (!FileExists(sConParserFeatureFile)) {
149156
return 1;
150157
}
158+
// redirect stdout to stderr since ZPar prints status
159+
// messages on stdout instead of stderr
160+
std::streambuf* oldCout = std::cout.rdbuf();
161+
std::cout.rdbuf(std::cerr.rdbuf());
151162
conparser = new CConParser(sConParserFeatureFile, false);
163+
// restore stdout
164+
std::cout.rdbuf(oldCout);
152165
zps->conparser = conparser;
153166
return 0;
154167
}
@@ -172,7 +185,13 @@ extern "C" int load_depparser(void* vzps, const char *sFeaturePath) {
172185
if (!FileExists(sDepParserFeatureFile)) {
173186
return 1;
174187
}
188+
// redirect stdout to stderr since ZPar prints status
189+
// messages on stdout instead of stderr
190+
std::streambuf* oldCout = std::cout.rdbuf();
191+
std::cout.rdbuf(std::cerr.rdbuf());
175192
depparser = new CDepParser(sDepParserFeatureFile, false);
193+
// restore stdout
194+
std::cout.rdbuf(oldCout);
176195
zps->depparser = depparser;
177196
return 0;
178197
}
@@ -539,28 +558,8 @@ extern "C" void unload_models(void* vzps)
539558
// extern "C" int main(int argc, char *argv[])
540559
// {
541560
// void* vzps = initialize();
542-
// std::cerr << "initialized zpar object at " << &vzps << std::endl;
543-
// load_tagger(vzps, "/Users/nmadnani/work/NLPTools/zpar/english-models");
544-
// std::cout << std::string(tag_sentence(vzps, "I said I am going to the market.", false));
545-
// unload_models(vzps);
546-
547-
// vzps = initialize();
548-
// std::cerr << "initialized zpar object at " << &vzps << std::endl;
549561
// load_tagger(vzps, "/Users/nmadnani/work/NLPTools/zpar/english-models");
550562
// std::cout << std::string(tag_sentence(vzps, "I said I am going to the market.", false));
551563
// unload_models(vzps);
552-
// std::cout << std::string(tag_sentence("I said `` I am going to the market . \"", false)) << std::endl;
553-
// std::cout << std::string(parse_sentence("I said `` I am going to the market . \"", false)) << std::endl;
554-
// std::cout << std::string(dep_parse_sentence("I said `` I am going to the market . \"", false)) << std::endl;
555-
// std::cout << std::string(tag_sentence("I said \"I am going to the market .\"", true)) << std::endl;
556-
// std::cout << std::string(parse_sentence("I said \"I am going to the market .\"", true)) << std::endl;
557-
// std::cout << std::string(dep_parse_sentence("I said \"I am going to the market .\"", true)) << std::endl;
558-
// tag_file("/scratch/nmadnani/zpar-new/test.txt", "/scratch/nmadnani/zpar-new/test.tag", false);
559-
// parse_file("/scratch/nmadnani/zpar-new/test.txt", "/scratch/nmadnani/zpar-new/test.parse", false);
560-
// dep_parse_file("/scratch/nmadnani/zpar-new/test.txt", "/scratch/nmadnani/zpar-new/test.dep", false);
561-
// tag_file("/scratch/nmadnani/zpar-new/test2.txt", "/scratch/nmadnani/zpar-new/test2.tag", true);
562-
// parse_file("/scratch/nmadnani/zpar-new/test2.txt", "/scratch/nmadnani/zpar-new/test2.parse", true);
563-
// dep_parse_file("/scratch/nmadnani/zpar-new/test2.txt", "/scratch/nmadnani/zpar-new/test2.dep", true);
564-
// unload_models();
565564
// return 0;
566565
// }

0 commit comments

Comments
 (0)