link-grammar-5.8.0/link-grammar/linkage/lisjuncts.c
/**
 * lg_compute_disjunct_strings -- Given sentence, compute disjuncts.
 *
 * This routine will compute the string representation of the disjunct
 * used for each word in parsing the given sentence.
 *
 * The connectors are extracted from link_array (and not chosen_disjuncts)
 * so the lexical links remain hidden when HIDE_MORPHO is true (see
 * compute_chosen_disjuncts()).
 *
 * In order that multi-connectors will not be extracted several times
 * for each disjunct (if they connect to multiple words) their tracon_id
 * is checked for duplication.
 */
- Given sentence, compute disjuncts.
This routine will compute the string representation of the disjunct
used for each word in parsing the given sentence.

The connectors are extracted from link_array (and not chosen_disjuncts)
so the lexical links remain hidden when HIDE_MORPHO is true (see
compute_chosen_disjuncts()).

In order that multi-connectors will not be extracted several times
for each disjunct (if they connect to multiple words) their tracon_id
is checked for duplication.
- Given sentence compute disjuncts . This routine will compute the string representation of the disjunct used for each word in parsing the given sentence . The connectors are extracted from link_array ( and not chosen_disjuncts ) so the lexical links remain hidden when HIDE_MORPHO is true ( see compute_chosen_disjuncts () ) . In order that multi - connectors will not be extracted several times for each disjunct ( if they connect to multiple words ) their tracon_id is checked for duplication .
void lg_compute_disjunct_strings(Linkage lkg)
{
	char djstr[MAX_LINK_NAME_LENGTH*20]; 
	size_t nwords = lkg->num_words;
	if (lkg->disjunct_list_str) return;
	lkg->disjunct_list_str = malloc(nwords * sizeof(char *));
	for (WordIdx w = 0; w < nwords; w++)
	{
		size_t len = 0;
		for (int dir = 0; dir < 2; dir++)
		{
			int last_multi_tracon_id = 0; 
			for (LinkIdx i = lkg->num_links-1; i != (WordIdx)-1; i--)
			{
				Link *lnk = &lkg->link_array[i];
				Connector *c;
				if (0 == dir)
				{
					if (lnk->rw != w) continue;
					c = lnk->rc;
				}
				else
				{
					if (lnk->lw != w) continue;
					c = lnk->lc;
				}
				if (c->multi)
				{
					if (last_multi_tracon_id == c->tracon_id) continue; 
					last_multi_tracon_id = c->tracon_id;
					djstr[len++] = '@';
				}
				len += lg_strlcpy(djstr+len, connector_string(c), sizeof(djstr)-len);
				if (len >= sizeof(djstr) - 3)
				{
					len = sizeof(djstr) - 1;
					break;
				}
				djstr[len++] = (dir == 0) ? '-' : '+';
				djstr[len++] = ' ';
			}
		}
		if ((len > 0) && (djstr[len-1] == ' ')) len--;
		djstr[len++] = '\0';
#ifdef DEBUG_lisjuncts
		assert_same_disjunct(lkg, w, djstr);
#endif 
		lkg->disjunct_list_str[w] = string_set_add(djstr, lkg->sent->string_set);
	}
}
void lg_compute_disjunct_strings ( Linkage lkg ) { char djstr [ MAX_LINK_NAME_LENGTH * 20 ] ; size_t nwords = lkg -> num_words ; if ( lkg -> disjunct_list_str ) return ; lkg -> disjunct_list_str = malloc ( nwords * sizeof ( char * ) ) ; for ( WordIdx w = 0 ; w < nwords ; w ++ ) { size_t len = 0 ; for ( int dir = 0 ; dir < 2 ; dir ++ ) { int last_multi_tracon_id = 0 ; for ( LinkIdx i = lkg -> num_links - 1 ; i != ( WordIdx ) - 1 ; i -- ) { Link * lnk = & lkg -> link_array [ i ] ; Connector * c ; if ( 0 == dir ) { if ( lnk -> rw != w ) continue ; c = lnk -> rc ; } else { if ( lnk -> lw != w ) continue ; c = lnk -> lc ; } if ( c -> multi ) { if ( last_multi_tracon_id == c -> tracon_id ) continue ; last_multi_tracon_id = c -> tracon_id ; djstr [ len ++ ] = ' ' ; } len += lg_strlcpy ( djstr + len , connector_string ( c ) , sizeof ( djstr ) - len ) ; if ( len >= sizeof ( djstr ) - 3 ) { len = sizeof ( djstr ) - 1 ; break ; } djstr [ len ++ ] = ( dir == 0 ) ? ' ' : ' ' ; djstr [ len ++ ] = ' ' ; } } if ( ( len > 0 ) && ( djstr [ len - 1 ] == ' ' ) ) len -- ; djstr [ len ++ ] = ' \0 ' ; #ifdef DEBUG_lisjuncts assert_same_disjunct ( lkg , w , djstr ) ; #endif lkg -> disjunct_list_str [ w ] = string_set_add ( djstr , lkg -> sent -> string_set ) ; } }
lg_compute_disjunct_strings -- Given sentence, compute disjuncts.
lg_compute_disjunct_strings -- Given sentence compute disjuncts .
/* no word will have more than 20 links */ /* last multi-connector */ /* already included */ /* DEBUG_lisjuncts */