📄 test-string-kernels.c
字号:
/*** Copyright (C) 2006 Thai Computational Linguistics Laboratory (TCL)** National Institute of Information and Communications Technology (NICT)** Canasai Kruengkrai <canasai xx gmail yy com, where xx=at and yy=dot>**** This file is part of the `libs' library.**** This library is free software; you can redistribute it and/or modify** it under the terms of the GNU General Public License as published by** the Free Software Foundation; either version 2 of the License, or** (at your option) any later version.**** This program is distributed in the hope that it will be useful,** but WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the** GNU General Public License for more details.**** You should have received a copy of the GNU General Public License** along with this program; if not, write to the Free Software** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/#include <math.h>#include <stdio.h>#include <stdlib.h>#include <ctype.h>#include <float.h>#include <string.h>#include "../svm/libsvm-string-2.71/svm.h"#include "suffix_tree.h"#define Malloc( type, n ) ( type * )malloc( ( n )*sizeof( type ) )svm_node *string2svm_node( char *s ){ int s_len = strlen( s ); svm_node *x = Malloc( svm_node, s_len + 1 ); int i; for( i = 0; i < s_len; i++ ) { x[i].index = i; x[i].value = ( unsigned char )s[i]; } x[i++].index = -1; return( x );}int main( int argc, char **argv ){ char *u = "yzxxz"; char *v = "xyzxxxy"; int u_len = strlen( u ); int v_len = strlen( v ); printf( "# string u = %s, length |u| = %d\n", u, u_len ); printf( "# string v = %s, length |v| = %d\n", v, v_len ); svm_node *xu = string2svm_node( u ); svm_node *xv = string2svm_node( v ); int r = 2; double lambda = 1.0; printf( "\n# Using `brute_force_full_substring' function, we get:\n" ); printf( "# K_r( u, v ) = %g, where 1 <= r <= %d and lambda = %g\n", brute_force_full_substring( xu, xv, r, lambda ), r, lambda ); printf( "\n# Using `brute_force_substring' function, we get:\n" ); double K_1 = brute_force_substring( xu, xv, 1, lambda ); double K_2 = brute_force_substring( xu, xv, 2, lambda ); printf( "# K_1( u, v ) = %g, where r = %d and lambda = %g\n", K_1, 1, lambda ); printf( "# K_2( u, v ) = %g, where r = %d and lambda = %g\n", K_2, 2, lambda ); printf( "# K_1( u, v ) + K_2( u, v ) = %g\n", K_1 + K_2 ); printf( "\n# Using `suffix_tree_full_substring' function, we get:\n" ); printf( "# K_r( u, v ) = %g, where 1 <= r <= %d and lambda = %g\n", suffix_tree_full_substring( xu, xv, r, lambda ), r, lambda ); printf( "\n# Using `suffix_tree_substring' function, we get:\n" ); K_1 = suffix_tree_substring( xu, xv, 1, lambda ); K_2 = suffix_tree_substring( xu, xv, 2, lambda ); printf( "# K_1( u, v ) = %g, where r = %d and lambda = %g\n", K_1, 1, lambda ); printf( "# K_2( u, v ) = %g, where r = %d and lambda = %g\n", K_2, 2, lambda ); printf( "# K_1( u, v ) + K_2( u, v ) = %g\n", K_1 + K_2 ); free( xu ); free( xv ); return( 0 );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -