link-grammar-5.8.0/link-grammar/dict-common/idiom.c
/**
 * Takes as input a pointer to a Dict_node.
 * The string of this Dict_node is an idiom string.
 * This string is torn apart, and its components are inserted into the
 * dictionary as special idiom words (ending in .I*, where * is a number).
 * The expression of this Dict_node (its node field) has already been
 * read and constructed.  This will be used to construct the special idiom
 * expressions.
 * The given dict node is freed.  The string is also freed.
 */
Takes as input a pointer to a Dict_node.
The string of this Dict_node is an idiom string.
This string is torn apart, and its components are inserted into the
dictionary as special idiom words (ending in .I*, where * is a number).
The expression of this Dict_node (its node field) has already been
read and constructed.  This will be used to construct the special idiom
expressions.
The given dict node is freed.  The string is also freed.
Takes as input a pointer to a Dict_node . The string of this Dict_node is an idiom string . This string is torn apart and its components are inserted into the dictionary as special idiom words ( ending in . I * where * is a number ) . The expression of this Dict_node ( its node field ) has already been read and constructed . This will be used to construct the special idiom expressions . The given dict node is freed . The string is also freed .
void insert_idiom(Dictionary dict, Dict_node * dn)
{
	Exp * nc, * no, * n1;
	const char * s;
	Dict_node * dn_list, * xdn, * start_dn_list;
	no = dn->exp;
	s = dn->string;
	if (!is_idiom_string(s))
	{
		prt_error("Warning: Word \"%s\" on line %d "
		          "is not a correctly formed idiom string.\n"
		          "\tThis word will be ignored\n",
		          s, dict->line_number);
		return;
	}
	dn_list = start_dn_list = make_idiom_Dict_nodes(dict, s);
	assert(dn_list->right != NULL, "Idiom string with only one connector");
	nc = Exp_create(dict->Exp_pool);
	nc->condesc = condesc_add(&dict->contable, generate_id_connector(dict));
	nc->dir = '-';
	nc->multi = false;
	nc->type = CONNECTOR_type;
	nc->operand_next = no;
	nc->cost = 0;
	n1 = Exp_create(dict->Exp_pool);
	n1->operand_first = nc;
	n1->type = AND_type;
	n1->operand_next = NULL;
	n1->cost = 0;
	dn_list->exp = n1;
	dn_list = dn_list->right;
	while(dn_list->right != NULL)
	{
		n1 = Exp_create(dict->Exp_pool);
		n1->type = AND_type;
		n1->operand_next = NULL;
		n1->cost = 0;
		nc = Exp_create(dict->Exp_pool);
		nc->condesc = condesc_add(&dict->contable, generate_id_connector(dict));
		nc->dir = '+';
		nc->multi = false;
		nc->type = CONNECTOR_type;
		nc->operand_next = NULL;
		nc->cost = 0;
		n1->operand_first = nc;
		increment_current_name(dict);
		no = Exp_create(dict->Exp_pool);
		no->condesc = condesc_add(&dict->contable, generate_id_connector(dict));
		no->dir = '-';
		no->multi = false;
		no->type = CONNECTOR_type;
		no->operand_next = NULL;
		no->cost = 0;
		nc->operand_next = no;
		dn_list->exp = n1;
		dn_list = dn_list->right;
	}
	nc = Exp_create(dict->Exp_pool);
	nc->condesc = condesc_add(&dict->contable, generate_id_connector(dict));
	nc->dir = '+';
	nc->multi = false;
	nc->type = CONNECTOR_type;
	nc->operand_next = NULL;
	nc->cost = 0;
	dn_list->exp = nc;
	increment_current_name(dict);
	dn_list = start_dn_list;
	while (dn_list != NULL)
	{
		xdn = dn_list->right;
		dn_list->left = dn_list->right = NULL;
		dn_list->string = build_idiom_word_name(dict, dn_list->string);
		dict->root = insert_dict(dict, dict->root, dn_list);
		dict->num_entries++;
		dn_list = xdn;
	}
}
void insert_idiom ( Dictionary dict , Dict_node * dn ) { Exp * nc , * no , * n1 ; const char * s ; Dict_node * dn_list , * xdn , * start_dn_list ; no = dn -> exp ; s = dn -> string ; if ( ! is_idiom_string ( s ) ) { prt_error ( " \" \" " " \n " " \t \n " , s , dict -> line_number ) ; return ; } dn_list = start_dn_list = make_idiom_Dict_nodes ( dict , s ) ; assert ( dn_list -> right != NULL , " " ) ; nc = Exp_create ( dict -> Exp_pool ) ; nc -> condesc = condesc_add ( & dict -> contable , generate_id_connector ( dict ) ) ; nc -> dir = ' ' ; nc -> multi = false ; nc -> type = CONNECTOR_type ; nc -> operand_next = no ; nc -> cost = 0 ; n1 = Exp_create ( dict -> Exp_pool ) ; n1 -> operand_first = nc ; n1 -> type = AND_type ; n1 -> operand_next = NULL ; n1 -> cost = 0 ; dn_list -> exp = n1 ; dn_list = dn_list -> right ; while ( dn_list -> right != NULL ) { n1 = Exp_create ( dict -> Exp_pool ) ; n1 -> type = AND_type ; n1 -> operand_next = NULL ; n1 -> cost = 0 ; nc = Exp_create ( dict -> Exp_pool ) ; nc -> condesc = condesc_add ( & dict -> contable , generate_id_connector ( dict ) ) ; nc -> dir = ' ' ; nc -> multi = false ; nc -> type = CONNECTOR_type ; nc -> operand_next = NULL ; nc -> cost = 0 ; n1 -> operand_first = nc ; increment_current_name ( dict ) ; no = Exp_create ( dict -> Exp_pool ) ; no -> condesc = condesc_add ( & dict -> contable , generate_id_connector ( dict ) ) ; no -> dir = ' ' ; no -> multi = false ; no -> type = CONNECTOR_type ; no -> operand_next = NULL ; no -> cost = 0 ; nc -> operand_next = no ; dn_list -> exp = n1 ; dn_list = dn_list -> right ; } nc = Exp_create ( dict -> Exp_pool ) ; nc -> condesc = condesc_add ( & dict -> contable , generate_id_connector ( dict ) ) ; nc -> dir = ' ' ; nc -> multi = false ; nc -> type = CONNECTOR_type ; nc -> operand_next = NULL ; nc -> cost = 0 ; dn_list -> exp = nc ; increment_current_name ( dict ) ; dn_list = start_dn_list ; while ( dn_list != NULL ) { xdn = dn_list -> right ; dn_list -> left = dn_list -> right = NULL ; dn_list -> string = build_idiom_word_name ( dict , dn_list -> string ) ; dict -> root = insert_dict ( dict , dict -> root , dn_list ) ; dict -> num_entries ++ ; dn_list = xdn ; } }
Takes as input a pointer to a Dict_node.
Takes as input a pointer to a Dict_node .
/* first make the nodes for the base word of the idiom (last word) */ /* note that the last word of the idiom is first in our list */ /* ----- this code just sets up the node fields of the dn_list ----*/ /* generate the expression for a middle idiom word */ /* now generate the last one */ /* ---- end of the code alluded to above ---- */ /* now its time to insert them into the dictionary */