Example #1
0
static inline void
_initmember(struct member* m, struct tmemberdetail* detail) {
    memset(m, 0, sizeof(*m));
    m->detail = *detail;
    m->base = m->detail.attri;
    m->connid = -1;
    m->delaymap = idmap_create(1);
    m->buffmap = idmap_create(1); 
}
Example #2
0
int init_author_lda(AuthorLda * alda){

    IdMap * uidmap = idmap_create();
    IdMap * vidmap = idmap_create();
    IdMap * aidmap = idmap_create();

    if (0 != load_author(alda, uidmap, aidmap)){
        goto free_maps;
    }
    fprintf(stderr, "author load done, doc : %d, author : %d\n", alda->D, alda->A);

    if (0 != load_tokens(alda, uidmap, vidmap, aidmap)){
        goto free_author;
    }
    fprintf(stderr, "tokens laod done, tokens : %d, words : %d\n", alda->T, alda->V);

    alda->nkw = (int*)malloc(sizeof(int) * alda->p.k);
    memset(alda->nkw, 0, sizeof(int) * alda->p.k);

#ifdef PHI
    if (0 != load_phi(alda, vidmap)){
        goto free_author;
    }
    fprintf(stderr, "phi load done\n");
#endif

    return 0;

free_author:
    free_author_lda(alda);

free_maps:
    idmap_free(uidmap);   uidmap = NULL;
    idmap_free(vidmap);   vidmap = NULL;
    idmap_free(aidmap);   aidmap = NULL;

    return -1;
}
Example #3
0
File: lda.c Project: nionjo/dm
int init_lda(Lda *lda) {
    FILE *fp = NULL;
    if (NULL == (fp = fopen(lda->p.in_file, "r"))) {
        fprintf(stderr, "can not open file \"%s\"\n", lda->p.in_file);
        return -1;
    }
    char buffer[LDA_LINE_LEN];
    char **str_array = NULL;
    int count = 0, token_size = 0;

    IdMap *uidmap = idmap_create();
    IdMap *vidmap = idmap_create();

    while (NULL != fgets(buffer, LDA_LINE_LEN, fp)) {
        str_array = split(trim(buffer, 3), '\t', &count);
        if (count < 2) {
            goto free_str;
        }

        if (-1 == idmap_get_value(uidmap, str_array[0])) {
            idmap_add(uidmap, dupstr(str_array[0]), idmap_size(uidmap));
        }

        if (-1 == idmap_get_value(vidmap, str_array[1])) {
            idmap_add(vidmap, dupstr(str_array[1]), idmap_size(vidmap));
        }
        token_size += 1;

free_str:
        free(str_array[0]);
        free(str_array);
    }

    lda->d = idmap_size(uidmap);
    lda->t = token_size;
    lda->v = idmap_size(vidmap);

    malloc_space(lda);

    rewind(fp);
    int uid = -1, vid = -1, tid = -1;
    int token_index = 0;

    while (NULL != fgets(buffer, LDA_LINE_LEN, fp)) {
        str_array = split(trim(buffer, 3), '\t', &count);
        if (count < 2) {
            goto str_free;
        }

        uid = idmap_get_value(uidmap, str_array[0]);
        strncpy(lda->id_doc_map[uid], str_array[0], KEY_SIZE - 1);
        lda->tokens[token_index][0] = uid;

        vid = idmap_get_value(vidmap, str_array[1]);
        strncpy(lda->id_v_map[vid], str_array[1], KEY_SIZE - 1);
        lda->tokens[token_index][1] = vid;

        tid = (int) ((1.0 + rand()) / (1.0 + RAND_MAX) * (lda->p.k));
        if (count == 3){
            tid = atoi(str_array[2]);
        }

        lda->tokens[token_index][2] = tid;
        token_index += 1;

str_free:
        free(str_array[0]);
        free(str_array);
    }
    fclose(fp);

    idmap_free(uidmap);   uidmap = NULL;
    idmap_free(vidmap);   vidmap = NULL;

    return 0;
}