예제 #1
0
파일: ACS.c 프로젝트: 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);
}
예제 #2
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);
}