Example #1
0
/**
 * Free all of the hash tables and Match_nodes 
 */
void free_fast_matcher(Sentence sent)
{
	int w;
	int i;
	match_context_t *ctxt = sent->match_ctxt;

	if (verbosity > 1) printf("%d Match cost\n", ctxt->match_cost);
	for (w = 0; w < sent->length; w++)
	{
		for (i = 0; i < ctxt->l_table_size[w]; i++)
		{
			free_match_list(ctxt->l_table[w][i]);
		}
		xfree((char *)ctxt->l_table[w], ctxt->l_table_size[w] * sizeof (Match_node *));
		for (i = 0; i < ctxt->r_table_size[w]; i++)
		{
			free_match_list(ctxt->r_table[w][i]);
		}
		xfree((char *)ctxt->r_table[w], ctxt->r_table_size[w] * sizeof (Match_node *));
	}
	free_match_list(ctxt->mn_free_list);
	ctxt->mn_free_list = NULL;

	free(ctxt);
	sent->match_ctxt = NULL;
}
Example #2
0
/**
 * Free all of the hash tables and Match_nodes
 */
void free_fast_matcher(fast_matcher_t *mchxt)
{
	size_t w;
	unsigned int i;

	if (verbosity > 1) printf("%d Match cost\n", mchxt->match_cost);
	for (w = 0; w < mchxt->size; w++)
	{
		for (i = 0; i < mchxt->l_table_size[w]; i++)
		{
			free_match_list(mchxt->l_table[w][i]);
		}
		xfree((char *)mchxt->l_table[w], mchxt->l_table_size[w] * sizeof (Match_node *));
		for (i = 0; i < mchxt->r_table_size[w]; i++)
		{
			free_match_list(mchxt->r_table[w][i]);
		}
		xfree((char *)mchxt->r_table[w], mchxt->r_table_size[w] * sizeof (Match_node *));
	}
	free_match_list(mchxt->mn_free_list);
	mchxt->mn_free_list = NULL;

	xfree(mchxt->l_table_size, mchxt->size * sizeof(unsigned int));
	xfree(mchxt->l_table, mchxt->size * sizeof(Match_node **));
	xfree(mchxt, sizeof(fast_matcher_t));
}
/**
 * Frees all the memory associated to the given LocateCache, including
 * its match list, if any.
 */
void free_LocateCache(LocateCache c,Abstract_allocator prv_alloc) {
if (c==NULL) return;
free_LocateCache(c->left,prv_alloc);
free_LocateCache(c->middle,prv_alloc);
free_LocateCache(c->right,prv_alloc);
free_match_list(c->matches,prv_alloc);
free_cb(c,prv_alloc);
}
Example #4
0
/**
 * This function takes two concordance index (in1 and in2) and
 * produces a HTML file (out) that shows the differences between
 * those two concordances.
 */
int diff(const VersatileEncodingConfig* vec,const char* in1,const char* in2,const char* out,
        const char* font,int size,int diff_only) {
char concor1[FILENAME_MAX];
char concor2[FILENAME_MAX];
get_path(in1,concor1);
strcat(concor1,"concord-1.txt");
get_path(in2,concor2);
strcat(concor2,"concord-2.txt");
/* First, we build the two concordances */
create_text_concordances(vec,in1,in2,concor1,concor2);
/* Then, we load the two index */
U_FILE* f1=u_fopen(vec,in1,U_READ);
if (f1==NULL) return 0;
struct match_list* l1=load_match_list(f1,NULL,NULL);
u_fclose(f1);
U_FILE* f2=u_fopen(vec,in2,U_READ);
if (f2==NULL) {
   return 0;
}
struct match_list* l2=load_match_list(f2,NULL,NULL);
u_fclose(f2);
/* We open the output file in UTF8, because the GUI expects this file
 * to be that encoded */
U_FILE* output=u_fopen(UTF8,out,U_WRITE);
if (output==NULL) {
   fatal_error("Cannot open output file %s\n",out);
   return 0;
}
/* We open the two concordance files */
f1=u_fopen(vec,concor1,U_READ);
f2=u_fopen(vec,concor2,U_READ);
/* And then we fill the output file with the differences
 * between the two concordances */
print_diff_HTML_header(output,font,size);
compute_concordance_differences(l1,l2,f1,f2,output,diff_only);
print_diff_HTML_end(output);
free_match_list(l1);
free_match_list(l2);
u_fclose(f1);
u_fclose(f2);
u_fclose(output);
/* We remove the tmp files */
//af_remove(concor1);
//af_remove(concor2);
return 1;
}
Example #5
0
int main (int argc, char **argv)
{
	int nrow = DEFAULT_NROW,
	which_seq = 0,
	do_order = 0,
	misses_allowed = 0,
	output_mode = -1;
    float cutoff = DEFAULT_CUTOFF;
    char *strand = NULL,
	 *id = NULL;
    struct mafFile *file = NULL;
    struct mafAli *ali = NULL;
    struct mafComp *comp = NULL;
    struct MOTIF *motif = NULL;
    struct MATCH *matches = NULL;

    id = ckalloc (STRSIZE);
    get_args (argc, argv, &output_mode, &file, &id, &motif, &do_order, &nrow, &cutoff, &misses_allowed);
    strand = ckalloc (sizeof (char) * (nrow + 1));

    while (NULL != (ali = mafNext (file)))
    {
        for (comp = ali->components, which_seq = 0; comp; comp = comp->next, which_seq++)
            strand[which_seq] = comp->strand;
        strand[which_seq] = '\0';

	/* skip blocks that don't have all seqs in them */
 	if (which_seq != nrow)
	{
            mafAliFree (&ali);
	    continue;
	}

	/* forward strand */
	get_matches (&matches, FORWARD, ali, nrow, motif, do_order, misses_allowed);

	/* reverse strand */
        for (comp = ali->components; comp; comp = comp->next)
            do_revcomp((uchar *)comp->text, ali->textSize );

        get_matches (&matches, REVERSE, ali, nrow, motif, do_order, misses_allowed);

	/* output matches */
        if (matches)
            output_matches (matches, strand, id, nrow, motif);
        free_match_list (&matches);

        mafAliFree (&ali);
    }

    mafFileFree (&file);
    free (strand);
    free_motif_list (&motif);
    free (id);

    return 0;
}
Example #6
0
void free_fast_matcher(Sentence sent) {
/* free all of the hash tables and Match_nodes */
    int w;
    int i;
    if (verbosity > 1) wprintf_s(L"%d Match cost\n", match_cost);
    for (w=0; w<sent->length; w++) {
	for (i=0; i<l_table_size[w]; i++) {
	    free_match_list(l_table[w][i]);
	}
	xfree((wchar_t *)l_table[w], l_table_size[w] * sizeof (Match_node *));
	for (i=0; i<r_table_size[w]; i++) {
	    free_match_list(r_table[w][i]);
	}
	xfree((wchar_t *)r_table[w], r_table_size[w] * sizeof (Match_node *));
    }
    free_match_list(mn_free_list);
    mn_free_list = NULL;
}
/**
 * This function removes all non ambiguous outputs from the given match list.
 * If renumber is non NULL, we have renumber[x]=y, where x is the position
 * of a match in the filtered list, and y its corresponding number in the
 * unfiltered original one.
 */
void filter_unambiguous_outputs(struct match_list* *list,vector_int* renumber) {
struct match_list* tmp;
if (*list==NULL) return;
struct match_list* previous=NULL;
struct match_list* l=*list;
int previous_was_identical=0;
int original_match_number=-1;
while (l!=NULL) {
  original_match_number++;
  if (previous==NULL) {
    /* Case 1: we are at the beginning of the list */
    /* Case 1a: there is only one cell */
    if (l->next==NULL) {
      free_match_list(l);
      *list=NULL;
      return;
    }
    /* Case 1b: there is a next cell, but it's not ambiguous with the current one */
    if (!are_ambiguous(l,l->next)) {
      /* We have to delete the current cell */
      tmp=l->next;
      free_match_list_element(l);
      l=tmp;
      continue;
    }
    /* Case 1c: the next cell is an ambiguous one, we can move on */
    /* Now we know the list head element */
    *list=l;
    previous=l;
    previous_was_identical=1;
    l=l->next;
    vector_int_add(renumber,original_match_number);
    continue;
  } else {
    /* Case 2: there is a previous cell */
    if (previous_was_identical) {
      vector_int_add(renumber,original_match_number);
      /* Case 2a: we know that we have to keep this current cell, but
       * we must check if the next is also an ambiguous one */
      if (l->next==NULL) {
        /* No next cell ? We're done then */
        return;
      }
      previous_was_identical=are_ambiguous(l,l->next);
      previous=l;
      l=l->next;
      continue;
    }
    /* Case 2b: previous cell is different, so we have to test the next one
     * to know whether we must keep the current one or not */
    if (l->next==NULL) {
      /* No next cell ? We have to delete the current one and then
       * we are done */
      free_match_list_element(l);
      previous->next=NULL;
      return;
    }
    previous_was_identical=are_ambiguous(l,l->next);
    if (previous_was_identical) {
      /* We have to keep the current cell */
      previous=l;
      l=l->next;
      vector_int_add(renumber,original_match_number);
      continue;
    }
    /* Final case, the next cell is not ambiguous, so we have to delete
     * the current one */
    tmp=l;
    l=l->next;
    free_match_list_element(tmp);
    previous->next=l;
    continue;
  }
}
}
Example #8
0
/***************************************************************************
* Name: fetch_current_rate_period()
*
* Description:	Fetch the rate period that corresponds to the given datetime
*		and fill in the rate_period field of the rate_keys struct.
*
* Input:	dbp - dataserver communication channel / structure
*		dbdate    - datetime of interest in arbor Arb_date format
* Output:	rate_keys - modified to indicate rate_period
*		period_discount - percent discount for retrieved rate period
*		num_match_prds - number of matching rate periods with same
*			(highest) priority.
* Returns:	SUCCESS / FAILURE
*
* GLOBALS:	giRatePeriodsCurrent - left direct access to this global
*			because it could be accessed many times per CDR.
****************************************************************************
*/
int
fetch_current_rate_period(DBPROCESS	*dbp ,
			Arb_date	*dbdate ,
			RATE_KEYS	*rate_keys ,
			int		*period_discount ,
			int		*num_match_prds )

{
   int   period;
   int	 daymin;	/* minutes since midnight (time period check) */
   int	 datemin;	/* minutes since Jan 1 1900 00:00 */
   char	 strtmp[80], bigtmp[1024];

   short	num_keys_match = 0;	/* number of key field matches */
   tiny		max_priority = 0;
   short	num_matches = 0;
   ARB_BIT	isfirstmatch = TRUE;
   PERIOD_MATCH	*firstmatch, *curmatch, *p, onematch;

   memset(&onematch, 0, sizeof(PERIOD_MATCH));
   firstmatch = &onematch;
   firstmatch->next = (PERIOD_MATCH *)NULL;
   curmatch = firstmatch;
   *period_discount = 0;

   *num_match_prds = 0;	/* no matching rate periods detected yet */

   daymin = Arbdate_to_secs_since_midnight(dbdate) / 60;

   /* Do we have proper range of active rate periods loaded? */

   datemin = Arbdate_to_mins_since_1_1_1900(dbdate);

   /* Scan the gsRatePeriods array for Rate Period which applies */
   /* to the datetime specified (dbdate). */

   for(period = 0; period < giRatePeriodCells; period++)
   {
      num_keys_match = 0;

      /* Determine if the Rate Period is active for the time of the call. */

      if(

	 /* active / inactive match? */

	 (datemin >= gsRatePeriods[period].active_datemin) &&
	 (datemin <  gsRatePeriods[period].inactive_datemin) &&

	 /* time-of-day match? */

	 (daymin >= gsRatePeriods[period].starttime) &&
	 (daymin <  gsRatePeriods[period].endtime))
      {

	 /* we have a match on active/inactive & start/end time */

	 num_keys_match++;
	 
	 /* Do we have a match on point_class_origin ?  (ORIGIN) */

	 if(gsRatePeriods[period].point_class_origin == WILD_MATCH)
	 {
	    ;		/* wildcard match, not explicit match */

	 } 
         else if(gsRatePeriods[period].point_class_origin ==
           rate_keys->point_class_origin) 
         {

	    num_keys_match++;		/* explicit point_class_origin match */

	 } else {

	    continue;			/* no match */
	 }

	 /* Do we have a match on point_class_target ?  (TARGET) */

	 if(gsRatePeriods[period].point_class_target  == WILD_MATCH)
	 {
	    ;		/* wildcard match, not explicit match */

	 } 
         else if(gsRatePeriods[period].point_class_target ==
           rate_keys->point_class_target) 
         {

	    num_keys_match++;		/* explicit point_class_target match */

	 } else {

	    continue;			/* no match */
	 }

	 /* Do we have a match on type_id_usg ? */

	 if(gsRatePeriods[period].type_id_usg == WILD_MATCH)
	 {
	    ;		/* wildcard match, not explicit match */

	 } 
         else if(gsRatePeriods[period].type_id_usg == rate_keys->type_id_usg) 
         {
	    num_keys_match++;		/* explicit type_id_usg match */
	 } 
         else 
         {
	    continue;			/* no match */
	 }

	 /* Do we have a match on rate_class ? */

	 if(gsRatePeriods[period].rate_class == WILD_MATCH)
	 {
	    ;		/* wildcard match, not explicit match */

	 } 
         else if(gsRatePeriods[period].rate_class == rate_keys->rate_class) 
         {
	    num_keys_match++;		/* explicit rate_class match */

	 } 
         else 
         {
	    continue;			/* no match */
	 }
	 /* Do we have a match on equip_type_code ? */

	 if(gsRatePeriods[period].equip_type_code == WILD_MATCH)
	 {
	    ;		/* wildcard match, not explicit match */

	 } 
         else if(gsRatePeriods[period].equip_type_code
		    == rate_keys->equip_type_code) 
         {
	    num_keys_match++;		/* explicit equip_type_code match */
	 } 
         else 
         {
	    continue;			/* no match */
	 }

	 /* Do we have a match on equip_class_code ? */

	 if(gsRatePeriods[period].equip_class_code == WILD_MATCH)
	 {
	    ;		/* wildcard match, not explicit match */

	 } else if(gsRatePeriods[period].equip_class_code
		    == rate_keys->equip_class_code) 
         {
	    num_keys_match++;		/* explicit equip_class_code match */
	 } 
         else 
         {
	    continue;			/* no match */
	 }

	 /* Do we have a match on class_of_service_code ? */

	 if(gsRatePeriods[period].class_of_service_code == WILD_MATCH)
	 {
	    ;		/* wildcard match, not explicit match */
	 } 
         else if(gsRatePeriods[period].class_of_service_code
		    == rate_keys->class_of_service_code) 
         {
	    num_keys_match++; /* explicit class_of_service_code match */
	 } 
         else 
         {
	    continue;			/* no match */
	 }

	 /* Do we have a match on element_id ? */

	 if(gsRatePeriods[period].element_id == WILD_MATCH)
	 {
	    ;		/* wildcard match, not explicit match */
	 } 
         else if(gsRatePeriods[period].element_id
		    == rate_keys->element_id) 
         {
	    num_keys_match++; /* explicit element_id match */
	 } 
         else 
         {
	    continue;			/* no match */
	 }

	 /* Do we have a match on component_id ? */

	 if(gsRatePeriods[period].component_id == WILD_MATCH)
	 {
	    ;		/* wildcard match, not explicit match */
	 } 
         else if(gsRatePeriods[period].component_id
		    == rate_keys->component_id) 
         {
	    num_keys_match++; /* explicit component_id match */
	 } 
         else 
         {
	    continue;			/* no match */
	 }

	 /* Do we have a day-of-week match ? */

	 if(gsRatePeriods[period].dayofweek == WILD_MATCH)
	 {
	    ;		/* wildcard match, not explicit match */

	 } 
         else if(gsRatePeriods[period].dayofweek == Arbdate_day_of_week(dbdate))
         {
	    num_keys_match++;		/* explicit DAY-OF-WEEK match */
	 } 
         else 
         {
	    continue;			/* no match */
	 }

	 /* Do we have a day-of-month match ? */

         if(gsRatePeriods[period].dayofmonth == WILD_MATCH)
         {
	    ;		/* wildcard match, not explicit match */
         } 
         else if(gsRatePeriods[period].dayofmonth == Arbdate_day(dbdate)) 
         {
	    num_keys_match++;		/* explicit DAY-OF-MONTH match */
         } 
         else 
         {
	    continue;			/* no match */
         }

	 /* Do we have a match on month ? */

	 if(gsRatePeriods[period].month == WILD_MATCH)
	 {
	    ;		/* wildcard match, not explicit match */

	 } 
         else if(gsRatePeriods[period].month == Arbdate_month(dbdate)) 
         {
	    num_keys_match++;		/* explicit MONTH match */
	 } 
         else 
         {
	    continue;			/* no match */
	 }

	 /* Do we have a match on year ? */

	 if(gsRatePeriods[period].year == WILD_MATCH)
	 {
	    ;		/* wildcard match, not explicit match */

	 } 
         else if(gsRatePeriods[period].year == Arbdate_year(dbdate)) 
         {
	    num_keys_match++;		/* explicit YEAR match */
	 } 
         else 
         {
	    continue;			/* no match */
	 }

	 /* Do we have a match on jurisdiction ? */

	 if(gsRatePeriods[period].jurisdiction == WILD_MATCH)
	 {
	    ;		/* wildcard match, not explicit match */

	 } 
         else if(gsRatePeriods[period].jurisdiction == rate_keys->jurisdiction) 
         {
	    num_keys_match++;		/* explicit JURISDICTION match */
	 } 
         else 
         {
	    continue;			/* no match */
	 }

	 /* Do we have a match on bill_class ? */

	 if(gsRatePeriods[period].bill_class == WILD_MATCH)
	 {
	    ;		/* wildcard match, not explicit match */

	 } 
         else if(gsRatePeriods[period].bill_class == rate_keys->bill_class) 
         {
	    num_keys_match++;		/* explicit BILL_CLASS_REF match */
	 } 
         else 
         {
	    continue;			/* no match */
	 }

	 /* Do we have a match on provider_class ? */

	 if(gsRatePeriods[period].provider_class == WILD_MATCH)
	 {
	    ;		/* wildcard match, not explicit match */

	 } 
         else if(gsRatePeriods[period].provider_class
		    == rate_keys->provider_class) 
         {
	    num_keys_match++;		/* explicit provider_class match */
	 } 
         else 
         {
	    continue;			/* no match */
	 }

	 /* If we get here, we have a matching rate period. */

debug_printf("fetch_current_rate_period> FOUND A MATCHING RATE_PERIOD: seqnum = %d\n", gsRatePeriods[period].seqnum);

	 /* Save highest priority of matching rate periods. */
	 /* Overlapping rate periods with same priority considered an error. */

	 if((int)gsRatePeriods[period].priority >= (int)max_priority)
	 {
	     max_priority = gsRatePeriods[period].priority;

	     /* Save this new (possibly tied) highest priority rate period. */
	     /* Don't bother saving lower priority matches. */

	     if(isfirstmatch)
	     {
		isfirstmatch = FALSE;
	     } 
             else 
             {
		if((p = (PERIOD_MATCH *)calloc(1, sizeof(PERIOD_MATCH))) == NULL)
		{
		   emit(ERRLOC, CALLOC_FAILURE, "PERIOD_MATCH", 1);
                   if (firstmatch->next) free_match_list(firstmatch->next);/* 1st element not calloc'd */
		   return(FAILURE);
		}
		curmatch->next = p;
		curmatch = p;
	     }
	     curmatch->periodidx   = period;
	     curmatch->keymatches  = num_keys_match;
	     curmatch->next = NULL;
	     num_matches++;
	 } 
         else 
         {
	     /* We already have a match with a higher priority, */
	     /* no need to save (or even count) this one. */
	 }
      }
   }

   /* If more than one match, resolve conflict to determine which one to use.
   ** Note that 'num_matches' is number of matching rate periods, independent
   ** of priority (not exactly, but it could be larger than number of matching
   ** rate periods with largest priority.
   */
   if(num_matches < 1)
   {
     /* no matching rate periods found */

debug_printf("fetch_current_rate_period> NO MATCHING RATE_PERIODS FOUND\n");

     rate_keys->rate_period[0] = '\0';	/* no match, use NULL rate period */
     *period_discount = 0;
     *num_match_prds = 0;

   } else {

     if(num_matches > 1)
     {
	/* Multiple matching rate periods found, but not necessarily
	** more than 1 with highest priority.
	**
	** Find number of matching rate periods with highest priority.
	** 'curmatch' will be set to highest priority match.
	*/
	*num_match_prds = rateprd_conflict(max_priority, firstmatch, curmatch);
	if(*num_match_prds > 1)
	{
	  /* Could not resolve conflict!  Means that there are  */
	  /* multiple matching rate periods with same priority! */

debug_printf("fetch_current_rate_period> ERROR: Overlapping Rate Periods defined!\n");

	  strcpy(bigtmp, "OVERLAPPING RATE PERIODS:");
	  strcpy(strtmp, "");

	  for(p = firstmatch; p != NULL; p = p->next)
	  {
	     if(gsRatePeriods[p->periodidx].priority == max_priority)
	     {
		sprintf(strtmp, "%s %d",
			bigtmp, gsRatePeriods[p->periodidx].seqnum);
		strcpy(bigtmp, strtmp);
	     }
	  }
	  emit(ERRLOC, MPS_PERIODS_OVERLAP, bigtmp);
	  free_match_list(firstmatch->next); /* 1st element not calloc'd */

          /* this is continuable error, return SUCCESS */
	  return(SUCCESS);

	} else {
	  /* There is more than 1 matching rate period, but only 1
	  ** with highest priority.  successfully resolved
	  ** rateprd_conflict
	  */
	}

     } else {
	/* Only 1 matching rate period, no need to resolve.      */
	/* Single matching rate period pointed to key 'curmatch. */
	*num_match_prds = 1;
     }

     giRatePeriodsCurrent = curmatch->periodidx;
     strcpy(rate_keys->rate_period,
	    gsRatePeriods[giRatePeriodsCurrent].rate_period);
     rate_keys->seqnum = gsRatePeriods[giRatePeriodsCurrent].seqnum;
     *period_discount = gsRatePeriods[giRatePeriodsCurrent].discount_factor;

debug_printf("fetch_current_rate_period> Using rate_period =%s=, seqnum = %d, discount_factor = %d\n",
	gsRatePeriods[giRatePeriodsCurrent].rate_period, gsRatePeriods[giRatePeriodsCurrent].seqnum,
	gsRatePeriods[giRatePeriodsCurrent].discount_factor);

     /* free match list calloc'd above (in this function) */

     free_match_list(firstmatch->next);		/* 1st element not calloc'd */
   }

   return(SUCCESS);
}