Beispiel #1
0
static crf1df_feature_t* featureset_generate(int *ptr_num_features,	\
        featureset_t* set,		\
        floatval_t minfreq,	\
        crf1de_semimarkov_t *sm)
{
    int n = 0, k = 0;
    RUMAVL_NODE *node = NULL;
    crf1df_feature_t *f = NULL;
    crf1df_feature_t *features = NULL;

    /* The first pass: count the number of valid features. */
    if (sm) {
        for (size_t i = 0; i < sm->m_num_ptrns; ++i) {
            /* TODO: get rid of length check, only generate transitions for length >= 2 */
            if (minfreq <= sm->m_ptrns[i].m_freq && 1 < sm->m_ptrns[i].m_len)
                ++n;
        }
    }

    while ((node = rumavl_node_next(set->avl, node, 1, (void**)&f)) != NULL) {
        if (minfreq <= f->freq) {
            ++n;
        }
    }

    /* The second pass: copy valid features to feature array. */
    features = (crf1df_feature_t*) calloc(n, sizeof(crf1df_feature_t));
    if (features != NULL) {
        /* add transition features from semi-markov model */
        if (sm) {
            crf1de_state_t *ptrn_entry = NULL;
            for (size_t i = 0; i < sm->m_num_ptrns; ++i) {
                ptrn_entry = &sm->m_ptrns[i];
                /* TODO: get rid of length check, only generate transitions for length >= 2 */
                if (minfreq <= ptrn_entry->m_freq  && 1 < sm->m_ptrns[i].m_len) {
                    features[k].type = FT_TRANS;
                    features[k].freq = ptrn_entry->m_freq;
                    features[k].src = sm->m_bkwid2frwid[sm->m_ptrnid2bkwid[ptrn_entry->m_id]];
                    features[k].dst = sm->m_ptrn_llabels[ptrn_entry->m_id];
                    ptrn_entry->m_feat_id = k;
                    ++k;
                }
            }
        }

        node = NULL;
        while ((node = rumavl_node_next(set->avl, node, 1, (void**)&f)) != NULL) {
            if (minfreq <= f->freq) {
                memcpy(&features[k], f, sizeof(crf1df_feature_t));
                ++k;
            }
        }
        *ptr_num_features = n;
        return features;
    } else {
        *ptr_num_features = 0;
        return NULL;
    }
}
Beispiel #2
0
static crf1df_feature_t*
featureset_generate(
    int *ptr_num_features,
    featureset_t* set,
    floatval_t minfreq
    )
{
    int n = 0, k = 0;
    RUMAVL_NODE *node = NULL;
    crf1df_feature_t *f = NULL;
    crf1df_feature_t *features = NULL;

    /* The first pass: count the number of valid features. */
    while ((node = rumavl_node_next(set->avl, node, 1, (void**)&f)) != NULL) {
        if (minfreq <= f->freq) {
            ++n;
        }
    }

    /* The second path: copy the valid features to the feature array. */
    features = (crf1df_feature_t*)calloc(n, sizeof(crf1df_feature_t));
    if (features != NULL) {
        node = NULL;
        while ((node = rumavl_node_next(set->avl, node, 1, (void**)&f)) != NULL) {
            if (minfreq <= f->freq) {
                memcpy(&features[k], f, sizeof(crf1df_feature_t));
                ++k;
            }
        }
        *ptr_num_features = n;
        return features;
    } else {
        *ptr_num_features = 0;
        return NULL;
    }
}
Beispiel #3
0
/*----------------------------------------------------------------------------
 * rumavl_foreach - loop through entire tree, using temporary iterator
 *--------------------------------------------------------------------------*/
extern int rumavl_foreach (RUMAVL *tree, int dir,
	    int (*cbfn)(RUMAVL *, void *, void *), void *udata)
{
    RUMAVL_NODE *node;
    int retv;
    void *record;

    if (cbfn == NULL)
	return RUMAVL_ERR_INVAL;
    
    retv = RUMAVL_ERR_NOENT;
    node = NULL;
    while ((node = rumavl_node_next(tree, node, dir, &record)) != NULL){
	if ((retv = cbfn(tree, record, udata)) != 0)
	    break;
    }

    return retv;
}