link-grammar-5.8.0/link-grammar/parse/prune.c
/**
 * Take this connector list, and try to match it with the words
 * w-1, w-2, w-3...  Returns the word to which the first connector of
 * the list could possibly be matched.  If c is NULL, returns w.  If
 * there is no way to match this list, it returns -1 (which is also
 * BAD_WORD in unsigned 8-bit representation).
 * If it does find a way to match it, it updates the c->nearest_word
 * and c->farthest_word fields correctly. When tracons are shared, this
 * update is done simultaneously on all of them. The main loop of
 * power_prune() then marks them with the pass number that is checked
 * here.
 */
Take this connector list, and try to match it with the words
w-1, w-2, w-3...  Returns the word to which the first connector of
the list could possibly be matched.  If c is NULL, returns w.  If
there is no way to match this list, it returns -1 (which is also
BAD_WORD in unsigned 8-bit representation).
If it does find a way to match it, it updates the c->nearest_word
and c->farthest_word fields correctly. When tracons are shared, this
update is done simultaneously on all of them. The main loop of
power_prune() then marks them with the pass number that is checked
here.
Take this connector list and try to match it with the words w - 1 w - 2 w - 3 ... Returns the word to which the first connector of the list could possibly be matched . If c is NULL returns w . If there is no way to match this list it returns - 1 ( which is also BAD_WORD in unsigned 8 - bit representation ) . If it does find a way to match it it updates the c - > nearest_word and c - > farthest_word fields correctly . When tracons are shared this update is done simultaneously on all of them . The main loop of power_prune () then marks them with the pass number that is checked here .
static int
left_connector_list_update(prune_context *pc, Connector *c,
                           int w, bool shallow)
{
	int n, lb;
	int foundmatch = -1;
	if (c == NULL) return w;
	if (c->prune_pass == pc->pass_number) return c->nearest_word;
	n = left_connector_list_update(pc, c->next, w, false) - 1;
	if (0 > n) return -1;
	if (((int) c->nearest_word) < n) n = c->nearest_word;
	lb = c->farthest_word;
	for (; n >= lb; n--)
	{
		pc->power_cost++;
		if (right_table_search(pc, n, c, shallow, w))
		{
			foundmatch = n;
			break;
		}
	}
	if (foundmatch < ((int) c->nearest_word))
	{
		c->nearest_word = foundmatch;
		pc->N_changed++;
	}
	if (foundmatch != -1)
	{
		int farthest_word = n;
		for (int l = lb; l < n; l++)
		{
			pc->power_cost++;
			if (right_table_search(pc, l, c, shallow, w))
			{
				farthest_word = l;
				break;
			}
		}
		if (farthest_word > (int)c->farthest_word)
		{
			c->farthest_word = farthest_word;
			pc->N_changed++;
		}
	}
	return foundmatch;
}
static int left_connector_list_update ( prune_context * pc , Connector * c , int w , bool shallow ) { int n , lb ; int foundmatch = -1 ; if ( c == NULL ) return w ; if ( c -> prune_pass == pc -> pass_number ) return c -> nearest_word ; n = left_connector_list_update ( pc , c -> next , w , false ) - 1 ; if ( 0 > n ) return -1 ; if ( ( ( int ) c -> nearest_word ) < n ) n = c -> nearest_word ; lb = c -> farthest_word ; for ( ; n >= lb ; n -- ) { pc -> power_cost ++ ; if ( right_table_search ( pc , n , c , shallow , w ) ) { foundmatch = n ; break ; } } if ( foundmatch < ( ( int ) c -> nearest_word ) ) { c -> nearest_word = foundmatch ; pc -> N_changed ++ ; } if ( foundmatch != -1 ) { int farthest_word = n ; for ( int l = lb ; l < n ; l ++ ) { pc -> power_cost ++ ; if ( right_table_search ( pc , l , c , shallow , w ) ) { farthest_word = l ; break ; } } if ( farthest_word > ( int ) c -> farthest_word ) { c -> farthest_word = farthest_word ; pc -> N_changed ++ ; } } return foundmatch ; }
Take this connector list, and try to match it with the words
 w-1, w-2, w-3...  Returns the word to which the first connector of
 the list could possibly be matched.
Take this connector list and try to match it with the words w - 1 w - 2 w - 3 ... Returns the word to which the first connector of the list could possibly be matched .
/* lb is now the leftmost word we need to check */ /* n is now the rightmost word we need to check */