/** * We've already built the sentence disjuncts, and we've pruned them * and power_pruned(GENTLE) them also. The sentence contains a * conjunction. deletable[][] has been initialized to indicate the * ranges which may be deleted in the final linkage. * * This routine deletes irrelevant disjuncts. It finds them by first * marking them all as irrelevant, and then marking the ones that * might be useable. Finally, the unmarked ones are removed. */ void conjunction_prune(Sentence sent, Parse_Options opts) { Disjunct * d; int w; count_context_t *ctxt = sent->count_ctxt; ctxt->current_resources = opts->resources; ctxt->deletable = sent->deletable; count_set_effective_distance(sent); /* We begin by unmarking all disjuncts. This would not be necessary if whenever we created a disjunct we cleared its marked field. I didn't want to search the program for all such places, so I did this way. XXX FIXME, someday ... */ for (w=0; w<sent->length; w++) { for (d=sent->word[w].d; d != NULL; d=d->next) { d->marked = FALSE; } } init_fast_matcher(sent); ctxt->local_sent = sent->word; ctxt->null_links = (opts->min_null_count > 0); /* for (d = sent->word[0].d; d != NULL; d = d->next) { if ((d->left == NULL) && region_valid(sent, 0, sent->length, d->right, NULL)) { mark_region(sent, 0, sent->length, d->right, NULL); d->marked = TRUE; } } mark_region(sent, 0, sent->length, NULL, NULL); */ if (ctxt->null_links) { mark_region(sent, -1, sent->length, NULL, NULL); } else { for (w=0; w<sent->length; w++) { /* consider removing the words [0,w-1] from the beginning of the sentence */ if (ctxt->deletable[-1][w]) { for (d = sent->word[w].d; d != NULL; d = d->next) { if ((d->left == NULL) && region_valid(sent, w, sent->length, d->right, NULL)) { mark_region(sent, w, sent->length, d->right, NULL); d->marked = TRUE; } } } } } delete_unmarked_disjuncts(sent); free_fast_matcher(sent); ctxt->local_sent = NULL; ctxt->current_resources = NULL; ctxt->deletable = NULL; count_unset_effective_distance(sent); }
int sentence_parse(Sentence sent, Parse_Options opts) { int nl; verbosity = opts->verbosity; free_sentence_disjuncts(sent); resources_reset_space(opts->resources); if (resources_exhausted(opts->resources)) { sent->num_valid_linkages = 0; return 0; } expression_prune(sent); print_time(opts, "Finished expression pruning"); prepare_to_parse(sent, opts); init_fast_matcher(sent); init_table(sent); /* A parse set may have been already been built for this sentence, if it was previously parsed. If so we free it up before building another. */ free_parse_set(sent); init_x_table(sent); for (nl = opts->min_null_count; (nl<=opts->max_null_count) && (!resources_exhausted(opts->resources)); ++nl) { sent->null_count = nl; sent->num_linkages_found = parse(sent, sent->null_count, opts); print_time(opts, "Counted parses"); post_process_linkages(sent, opts); if (sent->num_valid_linkages > 0) break; } free_table(sent); free_fast_matcher(sent); print_time(opts, "Finished parse"); return sent->num_valid_linkages; }