Example #1
0
/* This function tests the first word in the rule and checks if it
 * matches any of the initials in the list. */
int init_test(list * rule, list * initial) {
	/* First, find the word that we need to check. (unless there is a
	 * constituent first) */
	int i;
	list * lit = 0;
	for(i = 1; i <= rule->length; i++) {
		lit = list_get_list(rule, i);
		char * iname = list_get_token(lit, 1);
		if(!strcmp(iname, "into")) iname = list_get_token(lit, 3);
		if(!strcmp(iname, "constituent")) return 0;
		if(!strcmp(iname, "lit")) break;
	}
	
	lit = list_find_list(rule, "lit");
	if(!lit) return 0;
	char * morph = list_get_token(lit, 2);
	
	/* Then check if it starts with the right initial */
	char * test;

	for(i = 1; i <= initial->length; i++) {
		test = list_get_token(initial, i);
		if(!partial_strcmp(morph, test)) {
			return 1;
		}
	}
	return 0;
}
Example #2
0
/* Given a variable to bound, this checks it against the known ontology and returns: 
 *  0 if everything's OK,
 *  1 if the category is known but doesn't have the feature 
 *  2 if the category is known but the feature isn't.
 *  3 if the feature somehow is not known
 */
int varcheckt(list * l, list * ontology) {
	int i;
	
	int categoryfound = 0;
	int featurefound = 0;
	
	char * category = list_get_token(l, 1);
	char * feature = list_get_token(l, 2);
	
	if(!feature) return 3;
	
	/* Check all the lines in the CSV */
	for(i = 2; i <= ontology->length; i++) {
		
		/* Look up the variable name */
		char * varname = get_xy(ontology, 1, i);
		if(!varname) continue;
		
		if(!strcmp(varname, category)) {
			categoryfound = 1;
			char * varval = get_xy(ontology, 2, i);
			if(varval) if(!strcmp(feature, varval)) featurefound = 1;
		}
		
		if(categoryfound && featurefound) return 0;
	}
	if(categoryfound && featurefound) return 0;
	if(categoryfound && !featurefound) return 2;
	
	return 1;
}
Example #3
0
char * get_xy(list * ontology, int x, int y) {
	list * row = list_get_list(ontology, y);
	if(!row) return 0;
	
	list * cell = list_get_list(row, x);
	if(!cell) return 0;
	
	return list_get_token(cell, 1);
}
Example #4
0
int checkrule(list * input, list * ontology) {
	int i, j;
	
	list * command;
		
	for(i = 1; i <= input->length; i++) {
		command = list_get_list(input, i);
		if(!command) continue;
		char * cname = list_get_token(command, 1);
		if(!cname) continue;
		if(strcmp(cname, "seme")) continue;
		
		for(j = 2; j <= command->length; j++) {
			list * varl = list_get_list(command, j);
			if(varl) {
				int retval = varcheckt(varl, ontology);
				
				if(!retval) continue;
				
				if(retval == 1) 
					fprintf(stderr,"\tThe \"%s\" variable is not a recognised category in the ontology!\n", list_get_token(varl, 1));
				
				if(retval == 2) 
					fprintf(stderr,"\tThe \"%s\" category does not have the feature \"%s\".\n", list_get_token(varl, 1), list_get_token(varl, 2));
				
				if(retval == 3) {
					fprintf(stderr,"\tHow can I bind (seme (%s %s))", list_get_token(varl, 1), list_get_token(varl, 2));
					fprintf(stderr,"\n");
				}
			}
			
			char * vart = list_get_token(command, j);
			if(vart) {
				int retval = varcheckb(vart, ontology);
				
				if(retval == 1)
					fprintf(stderr,"\tThe \"%s\" variable is not a recognised category in the ontology!\n", vart);
				if(retval == 2)
					fprintf(stderr,"\tThe \"%s\" variable is not something that can be bound negative!\n", vart);
			}
		}
	}
	return 0;
}
Example #5
0
unsigned int __list_treebuilder(list * toks, list * target, unsigned int offset) {
	char * token;
	while(offset <= toks->length) {
//		printf("%d; %d; %d\n", toks->length, toks->allocated, offset);
		token = list_get_token(toks, offset++);
		if(!token) break;

		if(!strcmp(token, "(")) {
			list * k = list_append_list(target);
			offset = __list_treebuilder(toks, k, offset);
			continue;
		}
	
		if(!strcmp(token, ")")) {
			return offset;
		}
		
		list_append_token(target, token);
		
	}

	return offset;
}