link-grammar-5.8.0/link-grammar/parse/prune.c
/**
 * Prune useless disjuncts.
 * @param null_count Optimize for parsing with this null count.
 * MAX_SENTENCE means null count optimizations is essentially ignored.
 * @param[out] \p ncu[sent->length][2] Number of different connector
 * uppercase parts per word per direction (for the fast matcher tables).
 * @return The minimal null_count expected in parsing.
 */
Prune useless disjuncts.
@param null_count Optimize for parsing with this null count.
MAX_SENTENCE means null count optimizations is essentially ignored.
@param[out] \p ncu[sent->length][2] Number of different connector
uppercase parts per word per direction (for the fast matcher tables).
@return The minimal null_count expected in parsing.
Prune useless disjuncts . @param null_count Optimize for parsing with this null count . MAX_SENTENCE means null count optimizations is essentially ignored . @param [ out ] \ p ncu [ sent - > length ] [ 2 ] Number of different connector uppercase parts per word per direction ( for the fast matcher tables ) . @return The minimal null_count expected in parsing .
unsigned int pp_and_power_prune(Sentence sent, Tracon_sharing *ts,
                                unsigned int null_count, Parse_Options opts,
                                unsigned int *ncu[2])
{
	prune_context pc = {0};
	power_table pt;
	power_table_init(sent, ts, &pt);
	bool no_mlink = !!test_enabled("no-mlink");
	mlink_table *ml = alloca(sent->length * sizeof(*pc.ml));
	pc.always_parse = test_enabled("always-parse");
	pc.sent = sent;
	pc.pt = &pt;
	pc.null_links = null_count;
	pc.islands_ok = opts->islands_ok;
	pc.is_null_word = alloca(sent->length * sizeof(*pc.is_null_word));
	memset(pc.is_null_word, 0, sent->length * sizeof(*pc.is_null_word));
	int num_deleted = power_prune(sent, &pc, opts); 
	if ((num_deleted > 0) && !no_mlink)
	{
		pc.ml = build_mlink_table(sent, ml);
		print_time(opts, "Built_mlink_table%s", pc.ml ? "" : " (empty)");
		if (pc.ml != NULL)
		{
			if (null_count == 0)
				cross_mlink_prune(sent, pc.ml);
			num_deleted = power_prune(sent, &pc, opts);
		}
	}
	if (num_deleted != -1)
	{
		if (pp_prune(sent, ts, opts) > 0)
			num_deleted = power_prune(sent, &pc, opts);
		if ((num_deleted > 0) && !no_mlink)
		{
			pc.ml = build_mlink_table(sent, ml);
			print_time(opts, "Built_mlink_table%s", pc.ml ? "" : " (empty)");
			if (pc.ml != NULL)
			{
				if (null_count == 0)
					cross_mlink_prune(sent, pc.ml);
				power_prune(sent, &pc, opts);
			}
		}
	}
	unsigned int min_nulls = sent->null_count;
	bool parsing_to_be_done = true;
	if (null_count == MAX_SENTENCE)
	{
		min_nulls = pc.null_words;
	}
	else if ((pc.null_words > sent->null_count) && !pc.always_parse)
	{
		min_nulls = sent->null_count + 1; 
		parsing_to_be_done = false;
	}
	if (parsing_to_be_done)
		get_num_con_uc(sent, &pt, ncu);
	power_table_delete(&pt);
	return min_nulls;
}
unsigned int pp_and_power_prune ( Sentence sent , Tracon_sharing * ts , unsigned int null_count , Parse_Options opts , unsigned int * ncu [ 2 ] ) { prune_context pc = { 0 } ; power_table pt ; power_table_init ( sent , ts , & pt ) ; bool no_mlink = ! ! test_enabled ( " " ) ; mlink_table * ml = alloca ( sent -> length * sizeof ( * pc . ml ) ) ; pc . always_parse = test_enabled ( " " ) ; pc . sent = sent ; pc . pt = & pt ; pc . null_links = null_count ; pc . islands_ok = opts -> islands_ok ; pc . is_null_word = alloca ( sent -> length * sizeof ( * pc . is_null_word ) ) ; memset ( pc . is_null_word , 0 , sent -> length * sizeof ( * pc . is_null_word ) ) ; int num_deleted = power_prune ( sent , & pc , opts ) ; if ( ( num_deleted > 0 ) && ! no_mlink ) { pc . ml = build_mlink_table ( sent , ml ) ; print_time ( opts , " " , pc . ml ? " " : " " ) ; if ( pc . ml != NULL ) { if ( null_count == 0 ) cross_mlink_prune ( sent , pc . ml ) ; num_deleted = power_prune ( sent , & pc , opts ) ; } } if ( num_deleted != -1 ) { if ( pp_prune ( sent , ts , opts ) > 0 ) num_deleted = power_prune ( sent , & pc , opts ) ; if ( ( num_deleted > 0 ) && ! no_mlink ) { pc . ml = build_mlink_table ( sent , ml ) ; print_time ( opts , " " , pc . ml ? " " : " " ) ; if ( pc . ml != NULL ) { if ( null_count == 0 ) cross_mlink_prune ( sent , pc . ml ) ; power_prune ( sent , & pc , opts ) ; } } } unsigned int min_nulls = sent -> null_count ; bool parsing_to_be_done = true ; if ( null_count == MAX_SENTENCE ) { min_nulls = pc . null_words ; } else if ( ( pc . null_words > sent -> null_count ) && ! pc . always_parse ) { min_nulls = sent -> null_count + 1 ; parsing_to_be_done = false ; } if ( parsing_to_be_done ) get_num_con_uc ( sent , & pt , ncu ) ; power_table_delete ( & pt ) ; return min_nulls ; }
Prune useless disjuncts.
Prune useless disjuncts .
/* pc->ml is NULL here */ /* No benefit for now to make additional pp_prune() & power_prune() -
	 * additional deletions are very rare and even then most of the
	 * times only one disjunct is deleted. */ /* Initialize tentative values. */ /* No prune optimization - this is the last pruning for this sentence. */ /* The most that can be inferred */