Beispiel #1
0
/**
 * 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);
}
Beispiel #2
0
/** 
 * Returns the number of ways the sentence can be parsed with the
 * specified null count. Assumes that the hash table has already been
 * initialized, and is freed later. The "null_count" here is the
 * number of words that are allowed to have no links to them.
 */
s64 do_parse(Sentence sent, int null_count, Parse_Options opts)
{
	s64 total;
	count_context_t *ctxt = sent->count_ctxt;

	count_set_effective_distance(sent);
	ctxt->current_resources = opts->resources;
	ctxt->local_sent = sent->word;
	ctxt->deletable = sent->deletable;
	ctxt->null_block = opts->null_block;
	ctxt->islands_ok = opts->islands_ok;

	total = do_count(sent, -1, sent->length, NULL, NULL, null_count+1);

	ctxt->local_sent = NULL;
	ctxt->current_resources = NULL;
	return total;
}
Beispiel #3
0
/** 
 * Returns the number of ways the sentence can be parsed with the
 * specified cost. Assumes that the hash table has already been
 * initialized, and is freed later. The "cost" here is the number
 * of words that are allowed to have no links to them.
 */
s64 do_parse(Sentence sent, int cost, Parse_Options opts)
{
	s64 total;
	count_context_t *ctxt = sent->count_ctxt;

	count_set_effective_distance(sent);
	ctxt->current_resources = opts->resources;
	ctxt->local_sent = sent->word;
	ctxt->deletable = sent->deletable;
	ctxt->null_block = opts->null_block;
	ctxt->islands_ok = opts->islands_ok;

	total = do_count(sent, -1, sent->length, NULL, NULL, cost+1);
	if (verbosity > 1) {
		printf("Total count with %d null links:   %lld\n", cost, total);
	}
	if ((verbosity > 0) && (PARSE_NUM_OVERFLOW < total)) {
		printf("WARNING: Overflow in count! cnt=%lld\n", total);
	}

	ctxt->local_sent = NULL;
	ctxt->current_resources = NULL;
	return total;
}