main() { int c; while ((c = getch()) != EOF) { if (c == '#') /* directive */ { if (definedirective() == EOF) return; } else if (c == '/') { if (printcomment() == EOF) return; } else if (c == '\"') { if (printquote() == EOF) return; } else if (isspace(c)) putchar(c); else { ungetch(c); if (parseword() == EOF) return; } } }
void parse_story () /* read a sequence of sentence case-role representations into a slot-filler representation of the entire story. Calls parse_sentence as a subroutine to get each case-role rep. */ { int i, j, k, senti, /* sentence number in the input file */ step = 0, /* actual sentence number in the sequence */ modi = STORYPARSMOD; /* module number */ printcomment ("\n", "parsing input story:", "\n"); /* first clean up the network display */ if (displaying) { proc_clear_network (modi); display_current_proc_net (modi); } /* get the target slot-filler indices */ for (i = 0; i < noutputs[modi]; i++) targets[modi][i] = story.slots[i]; /* form the target activation vector */ for (i = 0; i < noutputs[modi]; i++) for (j = 0; j < nsrep; j++) tgtrep[modi][i * nsrep + j] = swords[targets[modi][i]].rep[j]; /* display the target activation */ if (displaying) { display_labeled_layer (modi, noutputs[modi], tgtrep[modi], targets[modi], net[modi].tgtx, net[modi].tgty, BELOW); wait_and_handle_events (); /* stop if stepping, check for events */ } /* previous hidden layer is blank in the beginning of the sequence */ for (i = 0; i < nhidrep[modi]; i++) prevhidrep[modi][i] = 0.0; /* process each sentence included in the input story */ for (senti = 0; senti < story.nsent; senti++) if (story.sents[senti].included) { /* first form the case-role representation for the sentence */ parse_sentence (story.sents[senti], PARATASK); /* get the indices of the correct case-role representation */ for (i = 0; i < ninputs[modi]; i++) inputs[modi][i] = story.sents[senti].caseroles[i]; /* if the modules are in a chain, use sentence parser output as input */ if (chain) for (i = 0; i < ncaserep; i++) inprep[modi][i] = caserep[i]; else /* use the correct case-role rep as input */ for (i = 0; i < ninputs[modi]; i++) for (j = 0; j < nsrep; j++) inprep[modi][i * nsrep + j] = swords[inputs[modi][i]].rep[j]; /* display the input representation and the previous hidden layer */ if (displaying) { display_labeled_layer (modi, ninputs[modi], inprep[modi], inputs[modi], net[modi].inpx, net[modi].inpy, ABOVE); display_assembly (modi, net[modi].prevx, net[modi].prevy, prevhidrep[modi], nhidrep[modi]); wait_and_handle_events (); /* stop if stepping, check events */ } /* propagate from input and prevhid layer to the output */ forward_propagate (modi); /* display hidden layer, output, and the log line */ if (displaying) { display_assembly (modi, net[modi].hidx, net[modi].hidy, hidrep[modi], nhidrep[modi]); display_labeled_layer (modi, noutputs[modi], outrep[modi], targets[modi], net[modi].outx, net[modi].outy, BELOW2); display_error (modi, outrep[modi], noutputs[modi], targets[modi], swords, nsrep, ++step); wait_and_handle_events (); /* stop if stepping, check events */ } /* update the previous hidden layer */ for (k = 0; k < nhidrep[modi]; k++) prevhidrep[modi][k] = hidrep[modi][k]; } printcomment ("\n", "into internal rep:", "\n"); /* collect statistics about the output accuracy of this module */ collect_stats (PARATASK, modi); /* if the modules are in a chain, establish the result to be used for the episodic memory or storygen */ if (chain) for (i = 0; i < nslotrep; i++) slotrep[i] = outrep[modi][i]; }