int main(int argc, char** argv) { init_vocabulary(); yyin = fopen ( "res/3.conj/0.single.in", "r" ); if(!yyin) { printf("Parser Error: cannot open the input file.\n"); assert(false); } yyparse(); int symbol_p = query_symbol("p",PREDICATE); assert(symbol_p >= 0); //validation assert(gformula); assert(gformula->formula_type == CONJ); assert(gformula->subformula_l); assert(gformula->subformula_r); assert(gformula->subformula_l->formula_type == ATOM); assert(gformula->subformula_l->predicate_id == symbol_p); assert(gformula->subformula_r->formula_type == ATOM); assert(gformula->subformula_r->predicate_id == symbol_p); destroy_vocabulary(); return 0; }
/* creates a vocabulary for the given text */ int create_vocabulary(char * text, char * vocab, float * frequency) { int i, state=1, prev_pos=-1, max=1; int length = strlen(text)-1; int total_words = 0; init_vocabulary(vocab); init_vocabulary_frequency(frequency); for (i = 0; i < length; i++) { if (state == 0) { /* look for the start of a word */ if (((text[i]>='a') && (text[i]<='z')) || ((text[i]>='A') && (text[i]<='Z'))) { /* change state to look for the end of a word */ state = 1; prev_pos = i; } } if (state == 1) { /* look for the end of a word */ if (word_terminator(text[i],text[i+1]) == 1) { /* change state to look for the start of a word */ state = 0; if (prev_pos > -1) { if (word_in_vocabulary(text, prev_pos, i+1, vocab, frequency,1,0)==0) { if (add_word_to_vocabulary(text, prev_pos, i+1, vocab, frequency)==1) { total_words++; } } } } } } sort_vocabulary(vocab, frequency); /* normalise word frequencies */ for (i = 0; i < 26*MAX_VOCAB_SIZE; i++) { if (frequency[i]>max) max = frequency[i]; } for (i = 0; i < 26*MAX_VOCAB_SIZE; i++) { frequency[i] /= max; } return total_words; }
int main(int argc, char** argv) { init_vocabulary(); yyin = fopen ( "res/A.cabalar/0.normal.r3.in", "r" ); if(!yyin) { printf("Parser Error: cannot open the input file.\n"); assert(false); } yyparse(); //symbols int symbol_TRUE = PRED_TRUE; int symbol_f = query_symbol("f",PREDICATE); assert(symbol_f >= 0); int symbol_g = query_symbol("g",PREDICATE); assert(symbol_g >= 0); int symbol_h = query_symbol("h",PREDICATE); assert(symbol_h >= 0); //convert _formulas *fmls = Cabalar_Trans(gformula); assert(fmls); assert(fmls->curr_formula); assert(fmls->remained_formulas == NULL); //validation _formula *fml = fmls->curr_formula; assert(fml->formula_type == IMPL); assert(fml->subformula_l->formula_type == CONJ); assert(fml->subformula_l->subformula_l->formula_type == NEGA); assert(fml->subformula_l->subformula_l->subformula_l); assert(fml->subformula_l->subformula_l->subformula_l->formula_type == ATOM); assert(fml->subformula_l->subformula_l->subformula_l->predicate_id == symbol_g); assert(fml->subformula_l->subformula_r->formula_type == ATOM); assert(fml->subformula_l->subformula_r->predicate_id == symbol_f); assert(fml->subformula_r->formula_type == ATOM); assert(fml->subformula_r->predicate_id == symbol_h); destroy_vocabulary(); return 0; }
/* parse the given text string from an XML file and update the vocabulary */ void parse_vocabulary_string(char * text, char* vocab) { int i,c,ctr=0,index,entry; int length = strlen(text); char value_str[256]; init_vocabulary(vocab); for (i = 0; i < length; i++) { if ((text[i] >= 'a') && (text[i] <= 'z') && (i < length-1)) { value_str[ctr++] = text[i]; } else { if (ctr > 0) { if ((i == length-1) && (text[i] >= 'a') && (text[i] <= 'z')) { value_str[ctr++] = text[i]; } value_str[ctr] = 0; index = (int)(tolower(value_str[0])-'a'); entry = 0; while (vocab[VINDEX(index,entry)]!=0) { entry++; if (entry==MAX_VOCAB_SIZE) break; } if (entry < MAX_VOCAB_SIZE) { for (c = 0; c <= ctr; c++) { vocab[VINDEX(index,entry) + c] = value_str[c]; } } } ctr = 0; } } }