link-grammar-5.8.0/link-grammar/parse/parse.c
/**
 * This fills the linkage array with morphologically-acceptable
 * linkages.
 */
This fills the linkage array with morphologically-acceptable
linkages.
This fills the linkage array with morphologically - acceptable linkages .
static void process_linkages(Sentence sent, extractor_t* pex,
                             bool overflowed, Parse_Options opts)
{
	if (0 == sent->num_linkages_found) return;
	if (0 == sent->num_linkages_alloced) return; 
	bool pick_randomly = overflowed ||
	    (sent->num_linkages_found > (int) sent->num_linkages_alloced);
	sent->num_valid_linkages = 0;
	size_t N_invalid_morphism = 0;
	int itry = 0;
	size_t in = 0;
	int maxtries;
#define MAX_TRIES 250000
	if (pick_randomly)
	{
		maxtries = MIN((int) sent->num_linkages_alloced + MAX_TRIES,
		               sent->num_linkages_found);
	}
	else
	{
		maxtries = sent->num_linkages_alloced;
	}
	bool need_init = true;
	for (itry=0; itry<maxtries; itry++)
	{
		Linkage lkg = &sent->lnkages[in];
		Linkage_info * lifo = &lkg->lifo;
		lifo->index = pick_randomly ? -(itry+1) : itry;
		if (need_init)
		{
			partial_init_linkage(sent, lkg, sent->length);
			need_init = false;
		}
		extract_links(pex, lkg);
		compute_link_names(lkg, sent->string_set);
		if (verbosity_level(+D_PL))
		{
			err_msg(lg_Debug, "chosen_disjuncts before:\n\\");
			print_chosen_disjuncts_words(lkg, true);
		}
		if (sane_linkage_morphism(sent, lkg, opts))
		{
			remove_empty_words(lkg);
			if (verbosity_level(+D_PL))
			{
				err_msg(lg_Debug, "chosen_disjuncts after:\n\\");
				print_chosen_disjuncts_words(lkg, false);
			}
			need_init = true;
			in++;
			if (in >= sent->num_linkages_alloced) break;
		}
		else
		{
			N_invalid_morphism++;
			lkg->num_links = 0;
			lkg->num_words = sent->length;
			memset(lkg->chosen_disjuncts, 0, sent->length * sizeof(Disjunct *));
		}
	}
	if (!need_init) free_linkage(&sent->lnkages[in]);
	sent->num_valid_linkages = in;
	sent->num_linkages_alloced = sent->num_valid_linkages;
	if (verbosity >= D_USER_INFO)
	{
		prt_error("Info: sane_morphism(): %zu of %d linkages had "
		        "invalid morphology construction\n", N_invalid_morphism,
		        itry + (itry != maxtries));
	}
}
static void process_linkages ( Sentence sent , extractor_t * pex , bool overflowed , Parse_Options opts ) { if ( 0 == sent -> num_linkages_found ) return ; if ( 0 == sent -> num_linkages_alloced ) return ; bool pick_randomly = overflowed || ( sent -> num_linkages_found > ( int ) sent -> num_linkages_alloced ) ; sent -> num_valid_linkages = 0 ; size_t N_invalid_morphism = 0 ; int itry = 0 ; size_t in = 0 ; int maxtries ; #define MAX_TRIES  250000 if ( pick_randomly ) { maxtries = MIN ( ( int ) sent -> num_linkages_alloced + MAX_TRIES , sent -> num_linkages_found ) ; } else { maxtries = sent -> num_linkages_alloced ; } bool need_init = true ; for ( itry = 0 ; itry < maxtries ; itry ++ ) { Linkage lkg = & sent -> lnkages [ in ] ; Linkage_info * lifo = & lkg -> lifo ; lifo -> index = pick_randomly ? - ( itry + 1 ) : itry ; if ( need_init ) { partial_init_linkage ( sent , lkg , sent -> length ) ; need_init = false ; } extract_links ( pex , lkg ) ; compute_link_names ( lkg , sent -> string_set ) ; if ( verbosity_level ( + D_PL ) ) { err_msg ( lg_Debug , " \n \\ " ) ; print_chosen_disjuncts_words ( lkg , true ) ; } if ( sane_linkage_morphism ( sent , lkg , opts ) ) { remove_empty_words ( lkg ) ; if ( verbosity_level ( + D_PL ) ) { err_msg ( lg_Debug , " \n \\ " ) ; print_chosen_disjuncts_words ( lkg , false ) ; } need_init = true ; in ++ ; if ( in >= sent -> num_linkages_alloced ) break ; } else { N_invalid_morphism ++ ; lkg -> num_links = 0 ; lkg -> num_words = sent -> length ; memset ( lkg -> chosen_disjuncts , 0 , sent -> length * sizeof ( Disjunct * ) ) ; } } if ( ! need_init ) free_linkage ( & sent -> lnkages [ in ] ) ; sent -> num_valid_linkages = in ; sent -> num_linkages_alloced = sent -> num_valid_linkages ; if ( verbosity >= D_USER_INFO ) { prt_error ( " " " \n " , N_invalid_morphism , itry + ( itry != maxtries ) ) ; } }
This fills the linkage array with morphologically-acceptable
 linkages.
This fills the linkage array with morphologically - acceptable linkages .
/* Avoid a later crash. */ /* Pick random linkages if we get more than what was asked for. */ /* In the case of overflow, which will happen for some long
	 * sentences, but is particularly common for the amy/ady random
	 * splitters, we want to find as many morpho-acceptable linkages
	 * as possible, but keep the CPU usage down, as these might be
	 * very rare. This is due to a bug/feature in the interaction
	 * between the word-graph and the parser: valid morph linkages
	 * can be one-in-a-thousand.. or worse.  Search for them, but
	 * don't over-do it.
	 * Note: This problem has recently been alleviated by an
	 * alternatives-compatibility check in the fast matcher - see
	 * alt_connection_possible().
	 */ /* Try picking many more linkages, but not more than possible. */ /* Negative values tell extract-links to pick randomly; for
		 * reproducible-rand, the actual value is the rand seed. */ /*prt_opt*/ /*prt_opt*/ // memset(lkg->link_array, 0, lkg->lasz * sizeof(Link)); /* The last one was alloced, but never actually used. Free it. */ /* The remainder of the array is garbage; we never filled it in.
	 * So just pretend that it's shorter than it is */