示例#1
0
int main(int argc, char * argv[]) {
	
	/* create a new monad. */
	monad * m = monad_new();
	
	/* Set the rules ready for translation from the original */
	monad_rules(m, argv[1]);

	/* Make the translations. */
	panini_generate(m, argv[2], 0, 5);
	monad_rules(m, argv[3]);
	panini_generate(m, argv[4], 0, 5);
	
	/* And spit the output out! */
	FILE * output = fopen(argv[5], "a+");
	monad_map(m, print_out, output, 5);
	fclose(output);
	monad_free(m);
	return 0;
	
}
示例#2
0
文件: edict.c 项目: sseneth/libpanini
/* This function, given these parameters, will determine the meaning of
 * the English translation, and then creates a Panini function to
 * match the headword to this meaning.
 * 
 * char * headword - we will try to interpret this English word to get 
 *                   the meaning.
 * char * reading  - The phonemic shape of the Japanese word.
 * char * ttemp    - A length of text (looking at the EDICT file, this
 *                   may be any of the strings delimited by /.
 * kanji * klist   - This is the list of kanji that was generated by
 *                   the readkanjidic file.
 * char * postag   - The part-of-speech tag (eg. (n), (v), (adj-na) ...)
 * char * incode   - This string contains the Panini code the interpret
 *                   the string in ttemp.
 * char * jpos     - This is the name of the Japanese part of speech
 *                   (eg. noun, verb etc.)
 */
int learnentry_func(char * headword, char * reading, char * ttemp, \
                 kanji * klist, char * postag, char * incode, char * jpos) {
	if(!klist) {
		printf("No klist!\n");
		return 0;
	}
	/* Remove the part-of-speech tag at the front of the translation. */
	int poslen = strlen(postag);
	if(!strncmp(ttemp, postag, poslen)) ttemp += poslen + 1;
	
	/* Remove the slash at the end of the translation */
	char * translation = strdup(ttemp);
	char * slash = strstr(translation, "/");
	if(!slash) {
		free(translation);
		return 0;
	}
	slash[0] = ' ';
	slash[1] = '\0';
	
	if(!strlen(headword)) return 0;
	
	monad_map(pmonad, unlink_the_dead, (void*)0, -1);
	monad_map(pmonad, set_intext, (void *)translation, -1);
	monad_map(pmonad, set_stack, incode, -1);
	if(!monad_map(pmonad, tranny_parse, (void *)0, 20)) return 0;
	
	monad_map(pmonad, remove_ns, "rection", -1);
	monad_map(pmonad, remove_ns, "record", -1);
	monad_map(pmonad, remove_ns, "theta", -1);
	monad_map(pmonad, remove_ns, "clues", -1);
	monad_map(pmonad, remove_ns, "record", -1);

	/* Find the kanji in the list */
	while(klist) {
		if(!klist->glyph) return 0;
		if(strcmp(klist->glyph, headword)) {
			klist = klist->next;
			//printf("\n;strcmp(\"%s\", \"%s\")\n", klist->glyph, headword); 
			continue;
		} else {
			klist->used = 1;
			break;
		}
	}
	
	/* No kanji found? Then just stop here. */
	if(!klist) return 0;

	printf("; %s: %s\n", headword, translation);
	
	/* Define the Japanese word */
	printf("(df %s ", jpos);
	
	/* It should call the right kanji,*/
	char * r = transliterate(reading);
	printf("(segments %s-%s) ", klist->jiscode, r);
	free(r);
	
	/* It should have the right meaning */
	monad_map(pmonad, kill_least_confident, (void *)0, -1);
	monad_map(pmonad, print_seme, stdout, -1);

	printf(")\n");
	return 1;
}