Пример #1
0
void *assoc_find(char *key) {
    Word_t * PValue;  
    JSLG( PValue, PJSLArray, key);
    if (PValue) {
        return ((void *)*PValue);
    } else return 0;
}
Пример #2
0
void db_filelist_rem_pkg_paths(const struct db_pkg* pkg)
{
  gchar path[MAXPATHLEN];
  gint rc;
  Word_t *p1, *p2;

  strcpy(path, "");
  JSLF(p1, pkg->paths, path);
  while (p1 != NULL)
  {
    JSLG(p2, _db.paths, path);
    if (p2)
    {
      Word_t* refs = p2;
      if (*refs == 1)
      {
        JSLD(rc, _db.paths, path);
      }
      else
      {
        (*refs)--;
      }
    }
    JSLN(p1, pkg->paths, path);
  }
}
Пример #3
0
void * map_get(void * map, char * key) {
	PWord_t v;
	JSLG(v, map, key);
	if (v) {
		return (void *)*v;
	}
	return NULL;
}
Пример #4
0
void test_param(const Pvoid_t params, const char *param, const char *cmp)
{
  Word_t *ptr;
  JSLG(ptr, params, (unsigned char*)param);
  if (!ptr)
    die("parameter %s not found", param);
  if (strcmp(((p_entry*)*ptr)->data, cmp))
    die("parameter %s value invalid: Expected %s got %s",
        param, cmp, ((p_entry*)*ptr)->data);
}
int find_word(char *str)
{
	PWord_t  PValue;      
	memset(Index, 0, sizeof(Index));
	strncpy(Index, str, strlen(str));

	JSLG(PValue, PJArray, Index);

	if(PValue != NULL) {
		return 1;        
	}	

	return 0;
}
Пример #6
0
tree find_instr_node(tree temp)
{
	int ret = 0;
    tree decl_node;
    PWord_t PV;
    JSLG(PV, decl_map, mf_varname_tree(temp));
    if(PV){
        decl_node = ((tree) *PV);
        gcc_assert(decl_node != NULL_TREE);
        DEBUGLOG("[find_instr] Match found for %s --> %s\n",mf_varname_tree(temp), IDENTIFIER_POINTER(DECL_NAME(decl_node)));
        return decl_node;
    }else
        DEBUGLOG("[find_instr] Match not found for %s\n",mf_varname_tree(temp));
    return NULL_TREE;
}
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;
}
Пример #8
0
void *jtableS_get(jtableS *table, const char *key) {
	PWord_t PValue;
	JSLG(PValue, table->t, (const uint8_t*)key);

	return PValue ? (void *)*PValue : NULL;
}