Exemple #1
0
DBL_WORD ST_SelfTest(SUFFIX_TREE* tree)
{
   DBL_WORD k,j,i;

#ifdef STATISTICS
   DBL_WORD old_counter = counter;
#endif

   /* Loop for all the prefixes of the tree source string */
   for(k = 1; k<tree->length; k++)
   {
      /* Loop for each suffix of each prefix */
      for(j = 1; j<=k; j++)
      {
#ifdef STATISTICS
         counter = 0;
#endif
         /* Search the current suffix in the tree */
         i = ST_FindSubstring(tree, (char*)(tree->tree_string+j), k-j+1);
         if(i == ST_ERROR)
         {
            printf("\n\nTest Results: Fail in string (%lu,%lu).\n\n",j,k);
            return 0;
         }
      }
   }
#ifdef STATISTICS
   counter = old_counter;
#endif
   /* If we are here no search has failed and the test passed successfuly */
   printf("\n\nTest Results: Success.\n\n");
   return 1;
}
Exemple #2
0
Fichier : ACS.c Projet : jbohac/ACS
double getACS(char* String_A, char* String_B){
        unsigned long position;
	/*Create the suffix tree*/
	char strb[20];
	strcpy(strb, String_A);
	int m = strlen(strb);
	SUFFIX_TREE* tree = ST_CreateTree(strb, m);
	
	/*Strings to test*/
	char str[20];
	strcpy(str, String_B);
	int l[strlen(str)];
	char  substr[strlen(str)]; 

	
	
	int i=0;
	int j=0;
        for(i=0; i<strlen(str); i++){
	  l[i] =0;
	  for(j=1; j<strlen(str)-i+1; j++){
	    strncpy(substr, &str[i], j)[j] = 0;
	    
	   printString(substr);
	    position = ST_FindSubstring(tree, substr, strlen(substr));
	    if(position != ST_ERROR){
		l[i] =j;
	    }else{
		//printf("\nString DNE\n");
		//i++;
		//j=1;
	    }
	    
	  }
	printf("%d\n", l[i]);
	}
	
	//printf(" I == %d\n", i);
	printf("Similarity = %f\n", getSimilarity(l, i, m));
	printf("Distance = %f\n", getDistance(l, i, m));
	return getDistance(l, i, m);
}
Exemple #3
0
int main()
{
	/*Will hold the position of the substring if exists in the tree.*/
	DBL_WORD position;
	
	/*Create the suffix tree*/
	SUFFIX_TREE* tree = ST_CreateTree("mississippi", 11);
	
	/*Print the suffix tree.*/
	ST_PrintTree(tree);

	/*Search for a substring in the tree and return its position if exists.*/
	position = ST_FindSubstring(tree, "ssis", 4);
	
	/*Print the position of the substring*/
	printf("\nPosition of ssis in mississippi is %ld.\n\n", position);
	
	/*Delete the tree and all its nodes.*/
	ST_DeleteTree(tree);
}