static Disjunct * build_disjuncts_for_X_node(X_node * x, int cost_cutoff) { Clause *c ; Disjunct * dis; c = build_clause(x->exp, cost_cutoff); dis = build_disjunct(c, x->string, cost_cutoff); free_clause_list(c); return dis; }
Disjunct * build_disjuncts_for_exp(Exp* exp, const char *word, double cost_cutoff) { Clause *c ; Disjunct * dis; /* print_expression(exp); printf("\n"); */ c = build_clause(exp); /* print_clause_list(c); */ dis = build_disjunct(c, word, cost_cutoff); /* print_disjunct_list(dis); */ free_clause_list(c); return dis; }
/** * Build a list of disjuncts. * * This is mostly used only for counting the number of disjuncts * (but is otherwise "almost" obsolete ??) */ Disjunct * build_disjuncts_for_dict_node(Dict_node *dn) { Clause *c ; Disjunct * dis; /* print_expression(dn->exp); */ /* printf("\n"); */ c = build_clause(dn->exp, NOCUTOFF); /* print_clause_list(c); */ dis = build_disjunct(c, dn->string, NOCUTOFF); /* print_disjunct_list(dis); */ free_clause_list(c); return dis; }
/** * Build the clause for the expression e. Does not change e */ static Clause * build_clause(Exp *e, int cost_cutoff) { Clause *c = NULL, *c1, *c2, *c3, *c4, *c_head; E_list * e_list; assert(e != NULL, "build_clause called with null parameter"); if (e->type == AND_type) { c1 = (Clause *) xalloc(sizeof (Clause)); c1->c = NULL; c1->next = NULL; c1->cost = 0; c1->maxcost = 0 ; for (e_list = e->u.l; e_list != NULL; e_list = e_list->next) { c2 = build_clause(e_list->e, cost_cutoff); c_head = NULL; for (c3 = c1; c3 != NULL; c3 = c3->next) { for (c4 = c2; c4 != NULL; c4 = c4->next) { c = (Clause *) xalloc(sizeof (Clause)); c->cost = c3->cost + c4->cost; c->maxcost = MAX(c3->maxcost,c4->maxcost); c->c = catenate(c3->c, c4->c); c->next = c_head; c_head = c; } } free_clause_list(c1); free_clause_list(c2); c1 = c_head; } c = c1; } else if (e->type == OR_type) { /* we'll catenate the lists of clauses */ c = NULL; for (e_list = e->u.l; e_list != NULL; e_list = e_list->next) { c1 = build_clause(e_list->e, cost_cutoff); while(c1 != NULL) { c3 = c1->next; c1->next = c; c = c1; c1 = c3; } } } else if (e->type == CONNECTOR_type) { c = (Clause *) xalloc(sizeof(Clause)); c->c = build_terminal(e); c->cost = 0; c->maxcost = 0; c->next = NULL; } else { assert(FALSE, "an expression node with no type"); } /* c now points to the list of clauses */ for (c1 = c; c1 != NULL; c1 = c1->next) { c1->cost += e->cost; /* c1->maxcost = MAX(c1->maxcost,e->cost); */ /* Above is how Dennis had it. Someone changed it to below. * However, this can sometimes lead to a maxcost that is less * than the cost ! -- which seems wrong to me ... seems Dennis * had it right!? */ c1->maxcost += e->cost; } return c; }