link-grammar-5.8.0/link-grammar/post-process/constituents.c
/**
 * This function looks for constituents of type ctype1. Say it finds
 * one, call it c1. It searches for the next larger constituent of
 * type ctype2, call it c2. It then generates a new constituent of
 * ctype3, containing all the words in c2 but not c1.
 */
This function looks for constituents of type ctype1. Say it finds
one, call it c1. It searches for the next larger constituent of
type ctype2, call it c2. It then generates a new constituent of
ctype3, containing all the words in c2 but not c1.
This function looks for constituents of type ctype1 . Say it finds one call it c1 . It searches for the next larger constituent of type ctype2 call it c2 . It then generates a new constituent of ctype3 containing all the words in c2 but not c1 .
static int gen_comp(con_context_t *ctxt, Linkage linkage,
                    int numcon_total, int numcon_subl,
                    const char * ctype1, const char * ctype2,
                    const char * ctype3, case_type x)
{
	size_t w, w2, w3;
	int c, c1, c2;
	bool done;
	c = numcon_total + numcon_subl;
	for (c1=numcon_total; c1<numcon_total + numcon_subl; c1++)
	{
		if ((x==CASE_APPOS) && (post_process_match("MX#*", ctxt->constituent[c1].start_link)==0))
			continue;
#ifdef REVIVE_DEAD_CODE
		if ((x==CASE_UNUSED) && (ctxt->constituent[c1].domain_type=='t'))
			continue;
#endif 
		if (ctxt->constituent[c1].domain_type=='z')
			continue;
#ifdef REVIVE_DEAD_CODE
#endif 
		if ((x==CASE_S) &&
			(((post_process_match("S", ctxt->constituent[c1].start_link) == 0) &&
			  (post_process_match("SX", ctxt->constituent[c1].start_link) == 0) &&
			  (post_process_match("SF", ctxt->constituent[c1].start_link) == 0)) ||
			 (post_process_match("S##w", ctxt->constituent[c1].start_link) != 0)))
			continue;
		if ((x==CASE_REL_CLAUSE) &&
			((post_process_match("Rn", ctxt->constituent[c1].start_link) == 0) &&
			 (post_process_match("R*", ctxt->constituent[c1].start_link) == 0) &&
			 (post_process_match("MX#r", ctxt->constituent[c1].start_link) == 0) &&
			 (post_process_match("Mr", ctxt->constituent[c1].start_link) == 0) &&
			 (post_process_match("MX#d", ctxt->constituent[c1].start_link) == 0)))
			continue;
		if ((x==CASE_OPENER) && (ctxt->constituent[c1].domain_type!='f'))
			continue;
		if ((x==CASE_PPOPEN) && (ctxt->constituent[c1].domain_type!='g'))
			continue;
		if ((x==CASE_SVINV) && (post_process_match("SI", ctxt->constituent[c1].start_link)==0))
			continue;
		if ((x==CASE_PART_MOD) && (post_process_match("M", ctxt->constituent[c1].start_link)==0))
			continue;
		if ((x==CASE_PART_OPEN) && (post_process_match("COp", ctxt->constituent[c1].start_link)==0))
			continue;
		if (!(strcmp(ctxt->constituent[c1].type, ctype1)==0))
			continue;
		if (verbosity_level(D_CONST))
			err_msg(lg_Debug, "Generating complement constituent for c %d of type %s\n\\",
				   c1, ctype1);
		done = false;
		for (w2 = ctxt->constituent[c1].left; (done == false) && (w2 != (size_t)-1); w2--)
		{
			for (w3 = ctxt->constituent[c1].right; w3<linkage->num_words; w3++)
			{
				for (c2 = numcon_total; (done == false) &&
						 (c2 < numcon_total + numcon_subl); c2++) {
					if (!((ctxt->constituent[c2].left == w2) &&
						  (ctxt->constituent[c2].right == w3)) || (c2==c1))
						continue;
					if (!(strcmp(ctxt->constituent[c2].type, ctype2)==0))
						continue;
					if ((x==CASE_OPENER) || (x==CASE_PPOPEN) || (x==CASE_PART_OPEN))
					{
						w = ctxt->constituent[c1].right + 1;
						if (w > ctxt->constituent[c2].right)
						{
							done = true;
							continue;
						}
						ctxt->constituent[c].left = w;
						ctxt->constituent[c].right = ctxt->constituent[c2].right;
					}
					else
					{
						w = ctxt->constituent[c1].left - 1;
						if (w < ctxt->constituent[c2].left) {
							done = true;
							continue;
						}
						ctxt->constituent[c].right = w;
						ctxt->constituent[c].left = ctxt->constituent[c2].left;
					}
					adjust_for_left_comma(ctxt, linkage, c1);
					adjust_for_right_comma(ctxt, linkage, c1);
					ctxt->constituent[c].type =
						string_set_add(ctype3, ctxt->phrase_ss);
					ctxt->constituent[c].domain_type = 'x';
					ctxt->constituent[c].start_link =
						string_set_add("XX", ctxt->phrase_ss);
					if (verbosity_level(D_CONST))
					{
						err_msg(lg_Debug, "Larger c found: c %d (%s); ", c2, ctype2);
						err_msg(lg_Debug, "Adding constituent:\n\\");
						print_constituent(ctxt, linkage, c);
					}
					c++;
					assert (c < ctxt->conlen, "Too many constituents");
					done = true;
				}
			}
		}
		if (verbosity_level(D_CONST))
		{
			if (done == false)
				err_msg(lg_Debug, "No constituent added, because no larger %s"
					               " was found\n", ctype2);
			else
				lg_error_flush();
		}
	}
	numcon_subl = c - numcon_total;
	return numcon_subl;
}
static int gen_comp ( con_context_t * ctxt , Linkage linkage , int numcon_total , int numcon_subl , const char * ctype1 , const char * ctype2 , const char * ctype3 , case_type x ) { size_t w , w2 , w3 ; int c , c1 , c2 ; bool done ; c = numcon_total + numcon_subl ; for ( c1 = numcon_total ; c1 < numcon_total + numcon_subl ; c1 ++ ) { if ( ( x == CASE_APPOS ) && ( post_process_match ( " " , ctxt -> constituent [ c1 ] . start_link ) == 0 ) ) continue ; #ifdef REVIVE_DEAD_CODE if ( ( x == CASE_UNUSED ) && ( ctxt -> constituent [ c1 ] . domain_type == ' ' ) ) continue ; #endif if ( ctxt -> constituent [ c1 ] . domain_type == ' ' ) continue ; #ifdef REVIVE_DEAD_CODE #endif if ( ( x == CASE_S ) && ( ( ( post_process_match ( " " , ctxt -> constituent [ c1 ] . start_link ) == 0 ) && ( post_process_match ( " " , ctxt -> constituent [ c1 ] . start_link ) == 0 ) && ( post_process_match ( " " , ctxt -> constituent [ c1 ] . start_link ) == 0 ) ) || ( post_process_match ( " " , ctxt -> constituent [ c1 ] . start_link ) != 0 ) ) ) continue ; if ( ( x == CASE_REL_CLAUSE ) && ( ( post_process_match ( " " , ctxt -> constituent [ c1 ] . start_link ) == 0 ) && ( post_process_match ( " " , ctxt -> constituent [ c1 ] . start_link ) == 0 ) && ( post_process_match ( " " , ctxt -> constituent [ c1 ] . start_link ) == 0 ) && ( post_process_match ( " " , ctxt -> constituent [ c1 ] . start_link ) == 0 ) && ( post_process_match ( " " , ctxt -> constituent [ c1 ] . start_link ) == 0 ) ) ) continue ; if ( ( x == CASE_OPENER ) && ( ctxt -> constituent [ c1 ] . domain_type != ' ' ) ) continue ; if ( ( x == CASE_PPOPEN ) && ( ctxt -> constituent [ c1 ] . domain_type != ' ' ) ) continue ; if ( ( x == CASE_SVINV ) && ( post_process_match ( " " , ctxt -> constituent [ c1 ] . start_link ) == 0 ) ) continue ; if ( ( x == CASE_PART_MOD ) && ( post_process_match ( " " , ctxt -> constituent [ c1 ] . start_link ) == 0 ) ) continue ; if ( ( x == CASE_PART_OPEN ) && ( post_process_match ( " " , ctxt -> constituent [ c1 ] . start_link ) == 0 ) ) continue ; if ( ! ( strcmp ( ctxt -> constituent [ c1 ] . type , ctype1 ) == 0 ) ) continue ; if ( verbosity_level ( D_CONST ) ) err_msg ( lg_Debug , " \n \\ " , c1 , ctype1 ) ; done = false ; for ( w2 = ctxt -> constituent [ c1 ] . left ; ( done == false ) && ( w2 != ( size_t ) -1 ) ; w2 -- ) { for ( w3 = ctxt -> constituent [ c1 ] . right ; w3 < linkage -> num_words ; w3 ++ ) { for ( c2 = numcon_total ; ( done == false ) && ( c2 < numcon_total + numcon_subl ) ; c2 ++ ) { if ( ! ( ( ctxt -> constituent [ c2 ] . left == w2 ) && ( ctxt -> constituent [ c2 ] . right == w3 ) ) || ( c2 == c1 ) ) continue ; if ( ! ( strcmp ( ctxt -> constituent [ c2 ] . type , ctype2 ) == 0 ) ) continue ; if ( ( x == CASE_OPENER ) || ( x == CASE_PPOPEN ) || ( x == CASE_PART_OPEN ) ) { w = ctxt -> constituent [ c1 ] . right + 1 ; if ( w > ctxt -> constituent [ c2 ] . right ) { done = true ; continue ; } ctxt -> constituent [ c ] . left = w ; ctxt -> constituent [ c ] . right = ctxt -> constituent [ c2 ] . right ; } else { w = ctxt -> constituent [ c1 ] . left - 1 ; if ( w < ctxt -> constituent [ c2 ] . left ) { done = true ; continue ; } ctxt -> constituent [ c ] . right = w ; ctxt -> constituent [ c ] . left = ctxt -> constituent [ c2 ] . left ; } adjust_for_left_comma ( ctxt , linkage , c1 ) ; adjust_for_right_comma ( ctxt , linkage , c1 ) ; ctxt -> constituent [ c ] . type = string_set_add ( ctype3 , ctxt -> phrase_ss ) ; ctxt -> constituent [ c ] . domain_type = ' ' ; ctxt -> constituent [ c ] . start_link = string_set_add ( " " , ctxt -> phrase_ss ) ; if ( verbosity_level ( D_CONST ) ) { err_msg ( lg_Debug , " " , c2 , ctype2 ) ; err_msg ( lg_Debug , " \n \\ " ) ; print_constituent ( ctxt , linkage , c ) ; } c ++ ; assert ( c < ctxt -> conlen , " " ) ; done = true ; } } } if ( verbosity_level ( D_CONST ) ) { if ( done == false ) err_msg ( lg_Debug , " " " \n " , ctype2 ) ; else lg_error_flush ( ) ; } } numcon_subl = c - numcon_total ; return numcon_subl ; }
This function looks for constituents of type ctype1.
This function looks for constituents of type ctype1 .
/* If ctype1 is NP, it has to be an appositive to continue */ /* If ctype1 is X, and domain_type is t, it's an infinitive - skip it */ /* REVIVE_DEAD_CODE */ /* If it's domain-type z, it's a subject-relative clause;
		   the VP doesn't need an NP */ /* If ctype1 is X or VP, and it's not started by an S, don't generate an NP
		 (Neither of the two previous checks are necessary now, right?) */ /* use this ... if ((x==CASE_S || x==CASE_UNUSED) && */ /* REVIVE_DEAD_CODE */ /* If it's an SBAR (relative clause case), it has to be a relative clause */ /* If ctype1 is SBAR (clause opener case), it has to be an f domain */ /* If ctype1 is SBAR (pp opener case), it has to be a g domain */ /* If ctype1 is NP (paraphrase case), it has to be started by an SI */ /* If ctype1 is VP (participle modifier case), it has to be
		   started by an Mv or Mg */ /* If ctype1 is VP (participle opener case), it has
		   to be started by a COp */ /* Now start at the bounds of c1, and work outwards until you
		   find a larger constituent of type ctype2 */ /* if the new constituent (c) is to the left
					   of c1, its right edge should be adjacent to the
					   left edge of c1 - or as close as possible. */ /* This is the case where c is to the
								   RIGHT of c1 */