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); }
/* 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; }
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; }
void check_ontology(list * output) { int i; char * dir = getenv("PANINI"); char * fn = malloc(strlen(dir) + strlen("ontology.csv")+1); strcpy(fn,dir); strcat(fn, "ontology.csv"); list * ontology = csvloader(fn); free(fn); for(i = 1; i<= output->length; i++) { int j; list * definitions = list_get_list(output, i); if(!definitions) continue; for(j = 2; j <= definitions->length; j++) { list * def = list_get_list(definitions, j); if(def) checkrule(def, ontology); } } }
int sandhi_initial(list * command, list * input, list * output) { list * initial = list_get_list(command, 2); list * sandhi = list_get_list(command, 3); int i; int j; /* This piece of code crawls through all of the rules and calls the * functions up there on each one. */ for(i = 1; i <= output->length; i++) { list * rules = list_get_list(output, i); if(!rules) continue; for(j = 1; j<=rules->length; j++) { list * rule = list_get_list(rules, j); if(!rule) continue; // if(list_contains(rule, "sandhi")) if(init_test(rule, initial)) add_sandhi(rule, sandhi); } } return 0; }