int test_czstr_manual() { zstr a = cs_as_z("abcdefgh"); czstr b = { a.len, a.buf }; printf("%d:%s\n", b.len, b.buf); return 0; }
int test_czstr() { zstr a = cs_as_z("abcdefgh"); czstr b = cz(a); printf("%d:%s\n", b.len, b.buf); /*b.len = 5;*/ /* should be a compile error since b is const. */ /*b.buf = NULL;*/ /* should be a compile error since b is const. */ /*b.buf[0] = '\0';*/ /* should be a compile error since b is a czstr. */ return 0; }
int test_czstr_union_cast_manual() { zstr a; czstr b; z_union_zstr_czstr u; a = cs_as_z("abcdefgh"); u.z = a; b = u.c; printf("%d:%s\n", b.len, b.buf); return 0; }
int main(int argc, char** argv) { if (argc < 2) { printf("usage: BackOffTrigramModelPipe arpafile\n"); return 1; } FILE* arpafile = fopen(argv[1], "r"); Pvoid_t UP = (Pvoid_t) NULL; /* map from unigram to probability */ Pvoid_t UB = (Pvoid_t) NULL; /* map from unigram to backoff */ Pvoid_t BP = (Pvoid_t) NULL; /* map from bigram to probability */ Pvoid_t BB = (Pvoid_t) NULL; /* map from bigram to backoff */ Pvoid_t TP = (Pvoid_t) NULL; /* map from trigram to probability */ read_arpa_file(arpafile, &UP, &UB, &BP, &BB, &TP); zbyte inputbuf[MAXTRIGRAMSIZE + 4]; zbyte* p; PWord_t ptr; size_t i; do { fgets((char*)inputbuf, MAXTRIGRAMSIZE + 4, stdin); i = strlen((char*)inputbuf); if (inputbuf[i-1] == '\n') { inputbuf[--i] = '\0'; } else { inputbuf[i] = '\0'; } p = inputbuf; if (*p == 'i') { if (*(p+1) == 'u') { // in unigrams p+=3; // command and space JSLG(ptr, UP, p); if (ptr == NULL) { printf("0\n"); fflush(stdout); } else { printf("1\n"); fflush(stdout); } } else if (*(p+1) == 'b') { // in bigrams p+=3; // command and space JSLG(ptr, BP, p); if (ptr == NULL) { printf("0\n"); fflush(stdout); } else { printf("1\n"); fflush(stdout); } } else if (*(p+1) == 't') { // in trigrams p+=3; // command and space JSLG(ptr, TP, p); if (ptr == NULL) { printf("0\n"); fflush(stdout); } else { printf("1\n"); fflush(stdout); } } } else if (*p == 'u'){ if (*(p+1) == 'p') { // unigram probability p+=3; // command and space float uniprob = unigram_prob_1(cs_as_z((char*)p), &UP); printf("%f\n", uniprob); fflush(stdout); } else if (*(p+1) == 'b'){ // unigram backoff p+=3; // command and space JSLG(ptr, UB, p); if (ptr == NULL) { printf("None\n"); fflush(stdout); } else { printf("%f\n", *(float*)ptr); fflush(stdout); } } else if (*(p+1) == 's') { // all vocabulary starting with prefix p+=3; // command and space size_t prefixlength = i - 3; zbyte prefix[MAXUNIGRAMSIZE]; memcpy (prefix, p, prefixlength); JSLF(ptr, UP, p); while ((ptr != NULL) && (memcmp(p, prefix, prefixlength) == 0)) { printf("%s ", p); fflush(stdout); JSLN(ptr, UP, p); } printf("\n"); fflush(stdout); } } else if (*p == 'b'){ if (*(p+1) == 'b'){ // bigram backoff p+=3; // command and space JSLG(ptr, BB, p); if (ptr == NULL) { printf("None\n"); fflush(stdout); } else { printf("%f\n", *(float*)ptr); fflush(stdout); } } } else if (*p == 't') { if (*(p+1) == 'p') { // trigram probability p+=3; // command and space float triprob = trigram_split_unkify_prob_3(cs_as_z((char*)p), &UP, &UB, &BP, &BB, &TP); printf("%f\n", triprob); fflush(stdout); } } else if (*p == 'U') { // is this a unk model? if (*(p+1) == 'p') { // unigram probability of unk *p = UNKBYTESTR[0]; *(p+1) = '\0'; JSLG(ptr, UP, p); if (ptr == NULL) { printf("None\n"); fflush(stdout); } else { printf("%f\n", *(float*)ptr); fflush(stdout); } } else if (*(p+1) == 'b') { // unigram backoff of unk *p = UNKBYTESTR[0]; *(p+1) = '\0'; JSLG(ptr, UB, p); if (ptr == NULL) { printf("None\n"); fflush(stdout); } else { printf("%f\n", *(float*)ptr); fflush(stdout); } } } } while ( (i > 0) && (feof(stdin) == 0) && (ferror(stdin) == 0) ); Word_t temp; JSLFA(temp, UP); JSLFA(temp, UB); JSLFA(temp, BP); JSLFA(temp, BB); JSLFA(temp, TP); fflush(stdout); return 0; }