예제 #1
0
int expand_rootword(const char * ts, int wl, const char * ap, int al)
{
    int i;
    int j;
    int nh=0;
    int nwl;
    char * strclass;

    for (i=0; i < numsfx; i++) {
        if (isdigit((stable[i].aep)->achar)) {
            char * ap1 = mystrdup(ap);            

            strclass=strtok(ap1,",");
            while (strclass != NULL) {
                if (strcmp(strclass,(stable[i].aep)->numflag) == 0) {
                    suf_add(ts, wl, stable[i].aep, stable[i].num);
                }
                strclass=strtok(NULL,",");
            }

            free(ap1);
        }else if (strchr(ap,(stable[i].aep)->achar)) {
            suf_add(ts, wl, stable[i].aep, stable[i].num);
        }
    }

    nh = numwords;

    if (nh > 1) {
       for (j=1;j<nh;j++){
         if (wlist[j].pallow) {
            for (i=0; i < numpfx; i++) {
               if (strchr(ap,(ptable[i].aep)->achar)) {
		 if ((ptable[i].aep)->xpflg & XPRODUCT) {
                   nwl = strlen(wlist[j].word);
                   pfx_add(wlist[j].word, nwl, ptable[i].aep, ptable[i].num);
		 }
	       }
	    }
	 }
       }
    }

    for (i=0; i < numpfx; i++) {
       if (strchr(ap,(ptable[i].aep)->achar)) {
          pfx_add(ts, wl, ptable[i].aep, ptable[i].num);
       }
    }
    return 0;
}
예제 #2
0
static int sf_subscribe (void *core_, void *sf_,
    const unsigned char *data_, size_t size_)
{
    if (pfx_add ((pfx_node_t*) sf_, data_, size_, NULL))
        return xs_filter_subscribed (core_, data_, size_);
    return 0;
}
예제 #3
0
int expand_rootword(const char * ts, int wl, const char * ap)
{
    int i;
    int j;
    int nh=0;
    int nwl;

    for (i=0; i < numsfx; i++) {
      if (strchr(ap,(stable[i].aep)->achar)) {
         suf_add(ts, wl, stable[i].aep, stable[i].num);
      }
    }
   
    nh = numwords;

    if (nh > 1) {
       for (j=1;j<nh;j++){
         if (wlist[j].pallow) {
            for (i=0; i < numpfx; i++) {
               if (strchr(ap,(ptable[i].aep)->achar)) {
		 if ((ptable[i].aep)->xpflg & XPRODUCT) {
                   nwl = strlen(wlist[j].word);
                   pfx_add(wlist[j].word, nwl, ptable[i].aep, ptable[i].num);
		 }
	       }
	    }
	 }
       }
    }

    for (i=0; i < numpfx; i++) {
       if (strchr(ap,(ptable[i].aep)->achar)) {
          pfx_add(ts, wl, ptable[i].aep, ptable[i].num);
       }
    }
    return 0;
}
예제 #4
0
static bool pfx_add (pfx_node_t *node_,
    const unsigned char *prefix_, size_t size_, void *subscriber_)
{
    //  We are at the node corresponding to the prefix. We are done.
    if (!size_) {
        bool result = !node_->subscribers;
        if (!node_->subscribers)
            node_->subscribers = new (std::nothrow) pfx_node_t::subscribers_t;
        pfx_node_t::subscribers_t::iterator it = node_->subscribers->insert (
            pfx_node_t::subscribers_t::value_type (subscriber_, 0)).first;
        ++it->second;
        return result;
    }

    unsigned char c = *prefix_;
    if (c < node_->min || c >= node_->min + node_->count) {

        //  The character is out of range of currently handled
        //  charcters. We have to extend the table.
        if (!node_->count) {
            node_->min = c;
            node_->count = 1;
            node_->next.node = NULL;
        }
        else if (node_->count == 1) {
            unsigned char oldc = node_->min;
            pfx_node_t *oldp = node_->next.node;
            node_->count =
                (node_->min < c ? c - node_->min : node_->min - c) + 1;
            node_->next.table = (pfx_node_t**)
                malloc (sizeof (pfx_node_t*) * node_->count);
            alloc_assert (node_->next.table);
            for (unsigned short i = 0; i != node_->count; ++i)
                node_->next.table [i] = 0;
            node_->min = std::min (node_->min, c);
            node_->next.table [oldc - node_->min] = oldp;
        }
        else if (node_->min < c) {

            //  The new character is above the current character range.
            unsigned short old_count = node_->count;
            node_->count = c - node_->min + 1;
            node_->next.table =
                (pfx_node_t**) realloc ((void*) node_->next.table,
                sizeof (pfx_node_t*) * node_->count);
            xs_assert (node_->next.table);
            for (unsigned short i = old_count; i != node_->count; i++)
                node_->next.table [i] = NULL;
        }
        else {

            //  The new character is below the current character range.
            unsigned short old_count = node_->count;
            node_->count = (node_->min + old_count) - c;
            node_->next.table =
                (pfx_node_t**) realloc ((void*) node_->next.table,
                sizeof (pfx_node_t*) * node_->count);
            xs_assert (node_->next.table);
            memmove (node_->next.table + node_->min - c, node_->next.table,
                old_count * sizeof (pfx_node_t*));
            for (unsigned short i = 0; i != node_->min - c; i++)
                node_->next.table [i] = NULL;
            node_->min = c;
        }
    }

    //  If next node does not exist, create one.
    if (node_->count == 1) {
        if (!node_->next.node) {
            node_->next.node = (pfx_node_t*) malloc (sizeof (pfx_node_t));
            alloc_assert (node_->next.node);
            pfx_init (node_->next.node);
            ++node_->live_nodes;
            xs_assert (node_->next.node);
        }
        return pfx_add (node_->next.node, prefix_ + 1, size_ - 1, subscriber_);
    }
    else {
        if (!node_->next.table [c - node_->min]) {
            node_->next.table [c - node_->min] =
                (pfx_node_t*) malloc (sizeof (pfx_node_t));
            alloc_assert (node_->next.table [c - node_->min]);
            pfx_init (node_->next.table [c - node_->min]);
            ++node_->live_nodes;
            xs_assert (node_->next.table [c - node_->min]);
        }
        return pfx_add (node_->next.table [c - node_->min],
            prefix_ + 1, size_ - 1, subscriber_);
    }
}
예제 #5
0
static int pf_subscribe (void *core_, void *pf_, void *subscriber_,
    const unsigned char *data_, size_t size_)
{
    return pfx_add ((pfx_node_t*) pf_, data_, size_, subscriber_) ? 1 : 0;
}