Exemplo n.º 1
0
struct Matcher * new_matcher(const char* signature_directory){
	int j,i;
	/* Read in the signatures of the signature directory */
	int numOf_SignatureClasses = 0;
	struct BayesSignature ** signatures = read_signature_files(signature_directory, &numOf_SignatureClasses);
	/* Initialize the matcher with those read-in signatures */
	struct Matcher * matcher;
	matcher = malloc(sizeof(struct Matcher));

	/* Add to matcher->signatures */
	matcher->signatures = signatures;

	/*  Add to matcher->ktree */
	matcher->ktree = new_KTree();

	for (j = 0; j < numOf_SignatureClasses; ++j){
		for (i = 0; i < matcher->signatures[j]->numOfTokens; ++i){
			//printf("j = %i, Token = \"%s\"\n", j, matcher->signatures[j]->tokens[i]->tokenstring);
			add_keyword(matcher->ktree, matcher->signatures[j]->tokens[i]->tokenstring, matcher->signatures[j]->tokens[i]->tokenlength);
		}
	}

	/* Finally set the integer values */
	matcher->numOfClasses = numOf_SignatureClasses;

	/* Now initialize the matcher->mapper with the subsumed informations from above */
	matcher->mapper = new_mapper(matcher);

	return matcher;
}
Exemplo n.º 2
0
void test1(){
	struct KTree *ktree;
	ktree = new_KTree();

	struct KTreeNode * ptr_addedKeyword;
	ptr_addedKeyword = add_keyword(ktree, "01", 2);
	ptr_addedKeyword = add_keyword(ktree, "012", 3);
	ptr_addedKeyword = add_keyword(ktree, "012", 3);
	char * string_broken = "012\n3";
	ptr_addedKeyword = add_keyword(ktree, string_broken, 5);

	trace_back_keyword(ktree, 3);

	destruct_KTree(ktree);
}
Exemplo n.º 3
0
void test1_5(){
	struct KTree *ktree;
	ktree = new_KTree();

	struct KTreeNode * ptr_addedKeyword;
	ptr_addedKeyword = add_keyword(ktree, "bist", 4);
	ptr_addedKeyword = add_keyword(ktree, "ist", 3);
	ptr_addedKeyword = add_keyword(ktree, "ist", 3);

	ptr_addedKeyword = add_keyword(ktree, "abcdef", 6);

	printf("find_string: %i\n", find_string(ktree, "012"));

	int * matches;
	char *  flow = "istn\n \0\12\n30130123\n012313230103";
	matches = match(ktree, flow, strlen(flow));

	int i;
	for (i = 0; i < ktree->numofkeywords_actual; ++i)
		printf("%i : ", matches[i]);
	printf("\n");

	destruct_KTree(ktree);
}