link-grammar-5.8.0/link-grammar/dict-common/print-dict.c
/**
 * Display the disjuncts of expressions in \p dn.
 */
Display the disjuncts of expressions in \p dn.
Display the disjuncts of expressions in \ p dn .
static char *display_disjuncts(Dictionary dict, const Dict_node *dn,
                               const void **arg)
{
	const Regex_node *rn = arg[0];
	const char *flags = arg[1];
	const Parse_Options opts = (Parse_Options)arg[2];
	double max_cost = opts->disjunct_cost;
	uint32_t int_flags = make_flags(flags);;
	Sentence dummy_sent = sentence_create("", dict); 
	dummy_sent->Disjunct_pool = pool_new(__func__, "Disjunct",
	                               8192, sizeof(Disjunct),
	                               false, false, false);
	dummy_sent->Connector_pool = pool_new(__func__, "Connector",
	                              65536, sizeof(Connector),
	                              true, false, false);
	Pool_desc *Exp_pool = pool_new(__func__, "Exp", 256,
	                               sizeof(Exp), false,
	                               false, false);
	select_data criterion = { .regex = rn };
	void *select = (rn == NULL) ? NULL : select_disjunct;
	dyn_str *s = dyn_str_new();
	dyn_strcat(s, "disjuncts:\n");
	for (; dn != NULL; dn = dn->right)
	{
		Exp *e = copy_Exp(dn->exp, Exp_pool, opts);
		Disjunct *d = build_disjuncts_for_exp(dummy_sent, e, dn->string, NULL,
		                                      max_cost, NULL);
		unsigned int dnum0 = count_disjuncts(d);
		d = eliminate_duplicate_disjuncts(d);
		unsigned int dnum1 = count_disjuncts(d);
		if ((flags != NULL) && (strchr(flags, 'm') != NULL))
		{
			criterion.exp = e;
			criterion.dict = dict;
		}
		criterion.num_selected = 0;
		dyn_str *dyn_pdl = dyn_str_new();
		dyn_print_disjunct_list(dyn_pdl, d, int_flags, select, &criterion);
		char *dliststr = dyn_str_take(dyn_pdl);
		pool_reuse(Exp_pool);
		pool_reuse(dummy_sent->Disjunct_pool);
		pool_reuse(dummy_sent->Connector_pool);
		append_string(s, "    %-*s %8u/%u disjuncts",
		              display_width(DJ_COL_WIDTH, dn->string), dn->string,
		              dnum1, dnum0);
		if (criterion.num_tunnels != 0)
			append_string(s, " (%u tunnels)", criterion.num_tunnels);
		dyn_strcat(s, "\n\n");
		dyn_strcat(s, dliststr);
		dyn_strcat(s, "\n");
		free(dliststr);
		if (rn != NULL)
		{
			if (criterion.num_selected == dnum1)
				dyn_strcat(s, "(all the disjuncts matched)\n\n");
			else
				append_string(s, "(%u disjunct%s matched)\n\n",
				              criterion.num_selected,
				              criterion.num_selected == 1 ? "" : "s");
		}
	}
	pool_delete(Exp_pool);
	sentence_delete(dummy_sent);
	return dyn_str_take(s);
}
static char * display_disjuncts ( Dictionary dict , const Dict_node * dn , const void * * arg ) { const Regex_node * rn = arg [ 0 ] ; const char * flags = arg [ 1 ] ; const Parse_Options opts = ( Parse_Options ) arg [ 2 ] ; double max_cost = opts -> disjunct_cost ; uint32_t int_flags = make_flags ( flags ) ; ; Sentence dummy_sent = sentence_create ( " " , dict ) ; dummy_sent -> Disjunct_pool = pool_new ( __func__ , " " , 8192 , sizeof ( Disjunct ) , false , false , false ) ; dummy_sent -> Connector_pool = pool_new ( __func__ , " " , 65536 , sizeof ( Connector ) , true , false , false ) ; Pool_desc * Exp_pool = pool_new ( __func__ , " " , 256 , sizeof ( Exp ) , false , false , false ) ; select_data criterion = { . regex = rn } ; void * select = ( rn == NULL ) ? NULL : select_disjunct ; dyn_str * s = dyn_str_new ( ) ; dyn_strcat ( s , " \n " ) ; for ( ; dn != NULL ; dn = dn -> right ) { Exp * e = copy_Exp ( dn -> exp , Exp_pool , opts ) ; Disjunct * d = build_disjuncts_for_exp ( dummy_sent , e , dn -> string , NULL , max_cost , NULL ) ; unsigned int dnum0 = count_disjuncts ( d ) ; d = eliminate_duplicate_disjuncts ( d ) ; unsigned int dnum1 = count_disjuncts ( d ) ; if ( ( flags != NULL ) && ( strchr ( flags , ' ' ) != NULL ) ) { criterion . exp = e ; criterion . dict = dict ; } criterion . num_selected = 0 ; dyn_str * dyn_pdl = dyn_str_new ( ) ; dyn_print_disjunct_list ( dyn_pdl , d , int_flags , select , & criterion ) ; char * dliststr = dyn_str_take ( dyn_pdl ) ; pool_reuse ( Exp_pool ) ; pool_reuse ( dummy_sent -> Disjunct_pool ) ; pool_reuse ( dummy_sent -> Connector_pool ) ; append_string ( s , " " , display_width ( DJ_COL_WIDTH , dn -> string ) , dn -> string , dnum1 , dnum0 ) ; if ( criterion . num_tunnels != 0 ) append_string ( s , " " , criterion . num_tunnels ) ; dyn_strcat ( s , " \n \n " ) ; dyn_strcat ( s , dliststr ) ; dyn_strcat ( s , " \n " ) ; free ( dliststr ) ; if ( rn != NULL ) { if ( criterion . num_selected == dnum1 ) dyn_strcat ( s , " \n \n " ) ; else append_string ( s , " \n \n " , criterion . num_selected , criterion . num_selected == 1 ? " " : " " ) ; } } pool_delete ( Exp_pool ) ; sentence_delete ( dummy_sent ) ; return dyn_str_take ( s ) ; }
Display the disjuncts of expressions in \p dn.
Display the disjuncts of expressions in \ p dn .
/* build_disjuncts_for_exp() needs memory pools for efficiency. */ /* For memory pools. */ /*num_elements*/ /*zero_out*/ /*align*/ /*num_elements*/ /*zero_out*/ /*align*/ /* copy_Exp() needs an Exp memory pool. */ /*num_elements*/ /*zero_out*/ /*align*/ /*exact*/ /* Use copy_Exp() to assign dialect cost. */