Esempio n. 1
0
/**
 * Print out the constituent tree.
 * mode 1: treebank-style constituent tree
 * mode 2: flat, bracketed tree [A like [B this B] A]
 * mode 3: flat, treebank-style tree (A like (B this))
 */
char * linkage_print_constituent_tree(Linkage linkage, ConstituentDisplayStyle mode)
{
	String * cs;
	CNode * root;
	char * p;

	if (!linkage) return NULL;
	if (mode == NO_DISPLAY)
	{
		return NULL;
	}
	else if (mode == MULTILINE || mode == SINGLE_LINE)
	{
		cs = string_new();
		root = linkage_constituent_tree(linkage);
		print_tree(cs, (mode==1), root, 0, 0);
		linkage_free_constituent_tree(root);
		append_string(cs, "\n");
		p = string_copy(cs);
		string_delete(cs);
		return p;
	}
	else if (mode == BRACKET_TREE)
	{
		return print_flat_constituents(linkage);
	}
	prt_error("Warning: Illegal mode %d for printing constituents\n"
	          "Allowed values: %d to %d\n", mode, NO_DISPLAY, MAX_STYLES);
	return NULL;
}
Esempio n. 2
0
static CNode * linkage_constituent_tree(Linkage linkage)
{
	char *p, *q, *saveptr;
	int len;
	CNode * root;

	p = print_flat_constituents(linkage);

	len = strlen(p);
	q = strtok_r(p, " ", &saveptr);
	assert(token_type(q) == OPEN_TOK, "Illegal beginning of string");
	root = make_CNode(q+1);
	root = parse_string(root, &saveptr);
	assign_spans(root, 0);
	exfree(p, sizeof(char)*(len+1));
	return root;
}
Esempio n. 3
0
/**
 * Print out the constituent tree.
 * mode 1: treebank-style constituent tree
 * mode 2: flat, bracketed tree [A like [B this B] A]
 * mode 3: flat, treebank-style tree (A like (B this) )
 */
char * linkage_print_constituent_tree(Linkage linkage, int mode)
{
	String * cs;
	CNode * root;
	char * p;

	if ((mode == 0) || (linkage->sent->dict->constituent_pp == NULL))
	{
		return NULL;
	}
	else if (mode == 1 || mode == 3)
	{
		cs = String_create();
		root = linkage_constituent_tree(linkage);
		print_tree(cs, (mode==1), root, 0, 0);
		linkage_free_constituent_tree(root);
		append_string(cs, "\n");
		p = exalloc(strlen(cs->p)+1);
		strcpy(p, cs->p);
		exfree(cs->p, sizeof(char)*cs->allocated);
		exfree(cs, sizeof(String));
		return p;
	}
	else if (mode == 2)
	{
		char * str;
		con_context_t *ctxt;

		ctxt = (con_context_t *) malloc(sizeof(con_context_t));
		str = print_flat_constituents(ctxt, linkage);
		free(ctxt);

		return str;
	}
	assert(0, "Illegal mode in linkage_print_constituent_tree");
	return NULL;
}