Skip to content

Commit

Permalink
harmonization with cm branch: copied trivial fixes and additions and …
Browse files Browse the repository at this point in the history
…reduced spurious diffs

git-svn-id: https://pet.opendfki.de/repos/pet/main@568 4200e16c-5112-0410-ac55-d7fb557a720a
  • Loading branch information
pead01 committed Jul 2, 2009
1 parent c39db9e commit 59a7829
Show file tree
Hide file tree
Showing 14 changed files with 169 additions and 122 deletions.
3 changes: 3 additions & 0 deletions cheap/agenda.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ template <typename T, typename LESS_THAN > class agenda {
/** Test if agenda is empty */
bool empty() { return _A.empty(); }

/** Return the number of tasks in the agenda */
int size() { return _A.size();}

private:

std::priority_queue<T *, std::vector<T *>, LESS_THAN> _A;
Expand Down
14 changes: 8 additions & 6 deletions cheap/chart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "tsdb++.h"
#include "item-printer.h"
#include "hashing.h"
#include "options.h" // for verbosity
#include "logging.h"
#include <ostream>

using namespace std;
Expand Down Expand Up @@ -112,22 +112,24 @@ void chart::remove(hash_set<tItem *> &to_delete)
}

void chart::print(tAbstractItemPrinter *pr,
bool passives, bool actives) const {
bool passives, bool actives, bool blocked) const {
for(chart_iter pos(this); pos.valid(); pos++) {
tItem *curr = pos.current();
if ((curr->passive() && passives) || (! curr->passive() && actives)) {
if ((blocked || !curr->blocked())
&& ((curr->passive() && passives) || (! curr->passive() && actives))) {
pr->print(curr);// out << endl;
}
}
}

void chart::print(std::ostream &out, tAbstractItemPrinter *pr,
bool passives, bool actives) const {
tItemPrinter def_print(out, verbosity > 2, verbosity > 10);
bool passives, bool actives, bool blocked) const {
tItemPrinter def_print(out, LOG_ENABLED(logChart, INFO),
LOG_ENABLED(logChart, DEBUG));
if (pr == NULL) {
pr = &def_print;
}
print(pr, passives, actives);
print(pr, passives, actives, blocked);
}

void chart::get_statistics()
Expand Down
14 changes: 8 additions & 6 deletions cheap/chart.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,19 @@ class chart {
/** Remove the item in the set from the chart */
void remove(HASH_SPACE::hash_set<tItem *> &to_delete);

/** Print chart items to stream \a out using \a aip, select active and
* passive items with \a passives and \a actives.
/** Print chart items using \a aip.
* Enable/disable printing of passive, active and blocked items.
*/
void print(tAbstractItemPrinter *aip,
bool passives = true, bool actives = true) const;
bool passives = true, bool actives = true,
bool blocked = true) const;

/** Print chart items to stream \a out using \a aip, select active and
* passive items with \a passives and \a actives.
/** Print chart items to stream \a out using \a aip.
* Enable/disable printing of passive, active and blocked items.
*/
void print(std::ostream &out, tAbstractItemPrinter *aip = NULL,
bool passives = true, bool actives = true) const;
bool passives = true, bool actives = true,
bool blocked = true) const;

/** Get statistics from the chart, like nr. of active/passive edges, average
* feature structure size, items contributing to a reading etc.
Expand Down
88 changes: 42 additions & 46 deletions cheap/cheap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ChartDumper : public tAbstractItemPrinter {
virtual void print_common(const tItem * item, const std::string &name, dag_node *dag) {
_dmp->dump_int(item->id());
_dmp->dump_int(item->start());
_dmp->dump_int(item->end());
_dmp->dump_int(item->end());
_dmp->dump_string(name.c_str());
item_list dtrs = item->daughters();
_dmp->dump_short(dtrs.size());
Expand All @@ -115,7 +115,7 @@ class ChartDumper : public tAbstractItemPrinter {
virtual ~ChartDumper() {}

/** The top level function called by the user */
virtual void print(const tItem *arg) { arg->print_gen(this); }
virtual void print(const tItem *arg) { arg->print_gen(this); }

/** Base printer function for a tInputItem */
virtual void real_print(const tInputItem *item) {
Expand All @@ -126,7 +126,7 @@ class ChartDumper : public tAbstractItemPrinter {
virtual void real_print(const tLexItem *item) {
print_common((const tItem *)item,
(item->rule() != NULL
? item->rule()->printname()
? item->rule()->printname()
: ((string) "\"" + item->printname() + "\"")),
get_fs(item).dag());
}
Expand All @@ -149,13 +149,13 @@ void dump_jxchg(string &surface, chart *ch) {
yieldname = get_opt_string("opt_jxchg_dir") + yieldname;
try {
dumper dmp(yieldname.c_str(), true);

dump_header(&dmp, surface.c_str());

dump_toc_maker toc(&dmp);
toc.add_section(SEC_CHART);
toc.close();

toc.start_section(SEC_CHART);
dmp.dump_int(0);
dmp.dump_int(ch->rightmost());
Expand Down Expand Up @@ -218,18 +218,18 @@ void interactive() {
analyze(input, Chart, FSAS, errors, id);
if(!errors.empty())
throw errors.front();

// TODO Who needs this? Can we remove it? (pead 01.04.2008)
if(verbosity == -1)
fprintf(stdout, "%d\t%d\t%d\n",
stats.id, stats.readings, stats.pedges);

string surface = Chart->get_surface_string();

fprintf(fstatus,
fprintf(fstatus,
"(%d) `%s' [%d] --- %d (%.2f|%.2fs) <%d:%d> (%.1fK) [%.1fs]\n",
stats.id, surface.c_str(),
get_opt_int("opt_pedgelimit"), stats.readings,
stats.id, surface.c_str(),
get_opt_int("opt_pedgelimit"), stats.readings,
stats.first/1000., stats.tcpu / 1000.,
stats.words, stats.pedges, stats.dyn_bytes / 1024.0,
TotalParseTime.elapsed_ts() / 10.);
Expand All @@ -238,7 +238,7 @@ void interactive() {

tsdb_dump.finish(Chart, surface);
dump_jxchg(surface, Chart);

//ofstream out("/tmp/final-chart-bernie");
//tTclChartPrinter chp(out, 0);
//tFegramedPrinter chp("/tmp/fed-");
Expand All @@ -261,6 +261,7 @@ void interactive() {
; ++iter) {
//tFegramedPrinter fedprint("/tmp/fed-");
//tDelegateDerivationPrinter deriv(fstatus, fedprint);
//tTSDBDerivationPrinter deriv(std::cerr, 1);
tCompactDerivationPrinter deriv(std::cerr);
tItem *it = *iter;

Expand Down Expand Up @@ -289,7 +290,7 @@ void interactive() {
if (opt_mrs && (strcmp(opt_mrs, "new") == 0)) {
mrs::tPSOA* mrs = new mrs::tPSOA(it->get_fs().dag());
if (mrs->valid()) {
mrs::tPSOA* mapped_mrs = vpm->map_mrs(mrs, true);
mrs::tPSOA* mapped_mrs = vpm->map_mrs(mrs, true);
if (mapped_mrs->valid()) {
fprintf(fstatus, "\n");
mapped_mrs->print(fstatus);
Expand Down Expand Up @@ -325,7 +326,7 @@ void interactive() {
#endif
}
} /* try */

catch(tError e) {
// shouldn't this be fstatus?? it's a "return value"
fprintf(ferr, "%s\n", e.getMessage().c_str());
Expand Down Expand Up @@ -359,9 +360,9 @@ void interactive_morphology() {
while(Lexparser.next_input(std::cin, input)) {
timer clock;
list<tMorphAnalysis> res = Lexparser.morph_analyze(input);
for(list<tMorphAnalysis>::iterator it = res.begin();
it != res.end();

for(list<tMorphAnalysis>::iterator it = res.begin();
it != res.end();
++it) {
cout << it->base() << "\t";
it->print_lkb(cout);
Expand All @@ -387,7 +388,7 @@ void print_grammar(int what, ostream &out) {
out << i << "\t" << attrname[i] << endl;
}
}

out << ";; GLBs ================================================" << endl;
if(what == 'g' || what == 'a') {
int i, j;
Expand Down Expand Up @@ -424,7 +425,7 @@ void cleanup() {

void process(const char *s) {
timer t_start;

try {
cheap_settings = new settings(raw_name(s), s, "reading");
LOG(logAppl, INFO, "loading `" << s << "' ");
Expand Down Expand Up @@ -457,12 +458,12 @@ void process(const char *s) {
}
Lexparser.register_lexicon(new tInternalLexicon());


// \todo this cries for a separate tokenizer factory
tTokenizer *tok;
switch (get_opt<tokenizer_id>("opt_tok")) {
case TOKENIZER_YY:
case TOKENIZER_YY_COUNTS:
case TOKENIZER_YY:
case TOKENIZER_YY_COUNTS:
{
char *classchar = cheap_settings->value("class-name-char");
if (classchar != NULL)
Expand All @@ -477,7 +478,7 @@ void process(const char *s) {
break;

case TOKENIZER_PIC:
case TOKENIZER_PIC_COUNTS:
case TOKENIZER_PIC_COUNTS:
#ifdef HAVE_XML
xml_initialize();
XMLServices = true;
Expand Down Expand Up @@ -516,18 +517,16 @@ void process(const char *s) {
exit(1);
#endif

case TOKENIZER_INVALID:
case TOKENIZER_INVALID:
LOG(logAppl, WARN, "unknown tokenizer mode \"" << optarg
<<"\": using 'tok=string'");
case TOKENIZER_STRING:
case TOKENIZER_STRING:
default:
tok = new tLingoTokenizer(); break;
}
tok->set_comment_passthrough(get_opt_bool("opt_comment_passthrough"));
Lexparser.register_tokenizer(tok);
}

catch(tError &e) {
} catch(tError &e) {
LOG(logAppl, FATAL, "aborted" << endl << e.getMessage());
cleanup();
return;
Expand Down Expand Up @@ -558,7 +557,7 @@ void process(const char *s) {
ecl_eval_sexpr("(setq cl-user::*error-output* cl-user::erroutsave)");
#endif // HAVE_ECL

LOG(logAppl, INFO, nstatictypes << " types in " << std::setprecision(2)
LOG(logAppl, INFO, nstatictypes << " types in " << std::setprecision(2)
<< t_start.convert2ms(t_start.elapsed()) / 1000. << " s" << endl);
fflush(fstatus);

Expand All @@ -567,11 +566,11 @@ void process(const char *s) {
}
else {
initialize_version();

#if defined(YY) && defined(SOCKET_INTERFACE)
if(get_opt_int("opt_server") != 0)
cheap_server(get_opt_int("opt_server"));
else
else
#endif
#ifdef TSDBAPI
if(get_opt_int("opt_tsdb"))
Expand Down Expand Up @@ -615,10 +614,10 @@ void main_init() {
managed_opt("opt_interactive_morph",
"make cheap only run interactive morphology (only morphological rules, "
"without lexicon)", false);
managed_opt("opt_online_morph",

managed_opt("opt_online_morph",
"use the internal morphology (the regular expression style one)", true);

managed_opt("opt_tsdb_dir",
"write [incr tsdb()] item, result and parse files to this directory",
((std::string) ""));
Expand All @@ -644,7 +643,7 @@ void main_init() {

// \todo should go to yy.cpp, but this produces no code and the call is
// optimized away
managed_opt("opt_yy",
managed_opt("opt_yy",
"old shit that should be thrown out or properly reengineered and renamed.",
false);
}
Expand All @@ -658,15 +657,15 @@ int main(int argc, char* argv[])
ferr = stderr;
fstatus = stderr;
flog = (FILE *)NULL;
try {
try {
setlocale(LC_ALL, "C" );

// initialization of logging
init_logging(argv[argc-1]);

// Initialize global options
main_init();

char *grammar_file_name;
#ifndef __BORLANDC__
if((grammar_file_name = parse_options(argc, argv)) == NULL) {
Expand All @@ -678,27 +677,24 @@ int main(int argc, char* argv[])
if(argc > 1)
grammar_file_name = argv[1];
#endif

#if defined(YY) && defined(SOCKET_INTERFACE)
if(get_opt_int("opt_server") != 0) {
if(cheap_server_initialize(get_opt_int("opt_server")))
exit(1);
}
#endif

string grammar_name = find_file(grammar_file_name, GRAMMAR_EXT);
if(grammar_name.empty()) {
throw tError("Grammar not found");
}

process(grammar_name.c_str());
}
catch(tError &e) {

process(grammar_name.c_str());
} catch(tError &e) {
LOG(logAppl, FATAL, e.getMessage() << endl);
exit(1);
}

catch(bad_alloc) {
} catch(bad_alloc) {
LOG(logAppl, FATAL, "out of memory");
exit(1);
}
Expand Down
Loading

0 comments on commit 59a7829

Please sign in to comment.