mirror of
https://gitee.com/lionsoul/friso.git
synced 2024-11-29 17:57:38 +08:00
Optimize all the code style for all the test programes
This commit is contained in:
parent
cdd37b06f0
commit
584fd65e0e
@ -1,11 +1,10 @@
|
||||
/*
|
||||
* dynamatic array test program.
|
||||
*
|
||||
* @author chenxin
|
||||
* @email chenxin619315@gmail.com
|
||||
* @author lionsoul<chenxin619315@gmail.com>
|
||||
*/
|
||||
|
||||
#include "friso_API.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -5,8 +5,9 @@
|
||||
* defferent threads/proccess use defferent friso_task_t.
|
||||
* and you could share the friso_config_t if you wish...
|
||||
*
|
||||
* @author chenxin <chenxin619315@gmail.com>
|
||||
* @author lionsoul<chenxin619315@gmail.com>
|
||||
*/
|
||||
|
||||
#include "friso_API.h"
|
||||
#include "friso.h"
|
||||
|
||||
@ -68,12 +69,13 @@ int main(int argc, char **argv)
|
||||
friso_config_t config;
|
||||
friso_task_t task;
|
||||
|
||||
//get the lexicon directory
|
||||
// get the lexicon directory from command line arguments
|
||||
for ( i = 0; i < argc; i++ ) {
|
||||
if ( strcasecmp( "-init", argv[i] ) == 0 ) {
|
||||
__path__ = argv[i+1];
|
||||
}
|
||||
}
|
||||
|
||||
if ( __path__ == NULL ) {
|
||||
println("Usage: friso -init lexicon path");
|
||||
exit(0);
|
||||
@ -82,7 +84,7 @@ int main(int argc, char **argv)
|
||||
s_time = clock();
|
||||
|
||||
//initialize
|
||||
friso = friso_new();
|
||||
friso = friso_new();
|
||||
config = friso_new_config();
|
||||
/*friso_dic_t dic = friso_dic_new();
|
||||
friso_dic_load_from_ifile( dic, __path__, __LENGTH__ );
|
||||
@ -124,7 +126,7 @@ int main(int argc, char **argv)
|
||||
print("friso>> ");
|
||||
getLine( stdin, line );
|
||||
//exit the programe
|
||||
if ( strcasecmp( line, "quit" ) == 0 ) {
|
||||
if (strcasecmp( line, "quit" ) == 0) {
|
||||
___EXIT_INFO___
|
||||
}
|
||||
|
||||
@ -135,9 +137,14 @@ int main(int argc, char **argv)
|
||||
|
||||
s_time = clock();
|
||||
while ( ( config->next_token( friso, config, task ) ) != NULL ) {
|
||||
//printf("%s[%d, %d, %d] ", task->token->word,
|
||||
// task->token->offset, task->token->length, task->token->rlen );
|
||||
printf("%s ", task->token->word );
|
||||
// printf(
|
||||
// "%s[%d, %d, %d] ",
|
||||
// task->token->word,
|
||||
// task->token->offset,
|
||||
// task->token->length,
|
||||
// task->token->rlen
|
||||
// );
|
||||
printf("%s ", task->token->word);
|
||||
}
|
||||
//}
|
||||
e_time = clock();
|
||||
@ -145,13 +152,12 @@ int main(int argc, char **argv)
|
||||
|
||||
}
|
||||
|
||||
friso_free_task( task );
|
||||
friso_free_task(task);
|
||||
|
||||
//error block.
|
||||
err:
|
||||
friso_free_config(config);
|
||||
friso_free(friso);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
/**
|
||||
* File Explain.
|
||||
* hashmap testing program
|
||||
*
|
||||
* @author chenxin
|
||||
* @see http://www.webssky.com
|
||||
* @author lionsoul<chenxin619315@gmail.com>
|
||||
*/
|
||||
#include "friso_API.h"
|
||||
|
||||
#include "friso_API.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void print_hash_info( friso_hash_t _hash ) {
|
||||
@ -17,51 +16,51 @@ int main(int argc, char **argv)
|
||||
{
|
||||
friso_hash_t _hash = new_hash_table();
|
||||
char *names[] = {
|
||||
"陈满文", "阳清华",
|
||||
"陈鑫", "罗江艳",
|
||||
"小燕子", "比比",
|
||||
"张仁芳", "阳建",
|
||||
"陈配", "李恒",
|
||||
"张志刚", "张怡少",
|
||||
"阳江波", "蔡再利",
|
||||
"阳绘章", "尹唐文",
|
||||
"谭志鹏", "肖路德",
|
||||
"潘凯", "刘潇",
|
||||
"马朝辉", "张强",
|
||||
"殷美林", "元明清",
|
||||
"周安", "郭桥安",
|
||||
"刘敏", "黄广华",
|
||||
"李胜", "黄海清"
|
||||
"陈满文", "阳清华",
|
||||
"陈鑫", "罗江艳",
|
||||
"小燕子", "比比",
|
||||
"张仁芳", "阳建",
|
||||
"陈配", "李恒",
|
||||
"张志刚", "张怡少",
|
||||
"阳江波", "蔡再利",
|
||||
"阳绘章", "尹唐文",
|
||||
"谭志鹏", "肖路德",
|
||||
"潘凯", "刘潇",
|
||||
"马朝辉", "张强",
|
||||
"殷美林", "元明清",
|
||||
"周安", "郭桥安",
|
||||
"刘敏", "黄广华",
|
||||
"李胜", "黄海清"
|
||||
};
|
||||
//char *str[] = {"陈鑫", "张仁芳", "比比"};
|
||||
char **str = names;
|
||||
int j, len = 30;
|
||||
|
||||
print_hash_info( _hash );
|
||||
for ( j = 0; j < len; j++) {
|
||||
hash_put_mapping( _hash, names[j], names[j] );
|
||||
for (j = 0; j < len; j++) {
|
||||
hash_put_mapping(_hash, names[j], names[j]);
|
||||
}
|
||||
|
||||
print_hash_info( _hash );
|
||||
print_hash_info(_hash);
|
||||
|
||||
printf("Press any key to continue.");
|
||||
getchar();
|
||||
|
||||
//remove mappings
|
||||
for ( j = 0; j < len; j++ ) {
|
||||
printf("Exist %s?%2d\n", str[j], hash_exist_mapping( _hash, str[j] ));
|
||||
printf("Now, remove %s\n", str[j]);
|
||||
hash_remove_mapping( _hash, str[j] );
|
||||
printf("Exist %s?%2d\n", str[j], hash_exist_mapping( _hash, str[j] ));
|
||||
printf("*********************************\n");
|
||||
for (j = 0; j < len; j++) {
|
||||
printf("Exist %s?%2d\n", str[j], hash_exist_mapping(_hash, str[j]));
|
||||
printf("Now, remove %s\n", str[j]);
|
||||
hash_remove_mapping(_hash, str[j]);
|
||||
printf("Exist %s?%2d\n", str[j], hash_exist_mapping(_hash, str[j]));
|
||||
printf("*********************************\n");
|
||||
}
|
||||
|
||||
printf("Press any key to continue.");
|
||||
getchar();
|
||||
|
||||
print_hash_info( _hash );
|
||||
print_hash_info(_hash);
|
||||
//free the table
|
||||
free_hash_table( _hash, 0 );
|
||||
free_hash_table(_hash, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
/*
|
||||
* lex functions test program.
|
||||
*
|
||||
* @author chenxin
|
||||
* @see http://www.webssky.com
|
||||
* @author lionsoul<chenxin619315@gmail.com>
|
||||
*/
|
||||
#include "friso.h"
|
||||
|
||||
#include "friso.h"
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
@ -29,66 +28,69 @@ int main(int argc, char **argv)
|
||||
|
||||
friso = friso_new();
|
||||
friso->dic = friso_dic_new();
|
||||
|
||||
//__CJK_WORDS__
|
||||
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-main.lex", __LENGTH__ );
|
||||
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-admin.lex", __LENGTH__ );
|
||||
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-chars.lex", __LENGTH__ );
|
||||
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-cn-mz.lex", __LENGTH__ );
|
||||
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-cn-place.lex", __LENGTH__ );
|
||||
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-company.lex", __LENGTH__ );
|
||||
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-festival.lex", __LENGTH__ );
|
||||
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-flname.lex", __LENGTH__ );
|
||||
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-food.lex", __LENGTH__ );
|
||||
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-lang.lex", __LENGTH__ );
|
||||
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-nation.lex", __LENGTH__ );
|
||||
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-net.lex", __LENGTH__ );
|
||||
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-org.lex", __LENGTH__ );
|
||||
friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-main.lex", __LENGTH__);
|
||||
friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-admin.lex", __LENGTH__);
|
||||
friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-chars.lex", __LENGTH__);
|
||||
friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-cn-mz.lex", __LENGTH__);
|
||||
friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-cn-place.lex", __LENGTH__);
|
||||
friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-company.lex", __LENGTH__);
|
||||
friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-festival.lex", __LENGTH__);
|
||||
friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-flname.lex", __LENGTH__);
|
||||
friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-food.lex", __LENGTH__);
|
||||
friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-lang.lex", __LENGTH__);
|
||||
friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-nation.lex", __LENGTH__);
|
||||
friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-net.lex", __LENGTH__);
|
||||
friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-org.lex", __LENGTH__);
|
||||
|
||||
//__CJK_UNITS__
|
||||
friso_dic_load( friso, __LEX_CJK_UNITS__, "../dict/lex-units.lex", __LENGTH__ );
|
||||
friso_dic_load(friso, __LEX_CJK_UNITS__, "../dict/lex-units.lex", __LENGTH__);
|
||||
//__MIX_WORDS__
|
||||
friso_dic_load( friso, __LEX_ECM_WORDS__, "../dict/lex-mixed.lex", __LENGTH__ );
|
||||
friso_dic_load(friso, __LEX_ECM_WORDS__, "../dict/lex-mixed.lex", __LENGTH__);
|
||||
//__CN_LNAME__
|
||||
friso_dic_load( friso, __LEX_CN_LNAME__, "../dict/lex-lname.lex", __LENGTH__ );
|
||||
friso_dic_load(friso, __LEX_CN_LNAME__, "../dict/lex-lname.lex", __LENGTH__);
|
||||
//__CN_SNAME__
|
||||
friso_dic_load( friso, __LEX_CN_SNAME__, "../dict/lex-sname.lex", __LENGTH__ );
|
||||
friso_dic_load(friso, __LEX_CN_SNAME__, "../dict/lex-sname.lex", __LENGTH__);
|
||||
//__CN_DNAME1__
|
||||
friso_dic_load( friso, __LEX_CN_DNAME1__, "../dict/lex-dname-1.lex", __LENGTH__ );
|
||||
friso_dic_load(friso, __LEX_CN_DNAME1__, "../dict/lex-dname-1.lex", __LENGTH__);
|
||||
//__CN_DNAME2__
|
||||
friso_dic_load( friso, __LEX_CN_DNAME2__, "../dict/lex-dname-2.lex", __LENGTH__ );
|
||||
friso_dic_load(friso, __LEX_CN_DNAME2__, "../dict/lex-dname-2.lex", __LENGTH__);
|
||||
//__CN_LNA__
|
||||
friso_dic_load( friso, __LEX_CN_LNA__, "../dict/lex-lna.lex", __LENGTH__ );
|
||||
friso_dic_load(friso, __LEX_CN_LNA__, "../dict/lex-lna.lex", __LENGTH__ );
|
||||
|
||||
e_time = clock();
|
||||
|
||||
printf("Done, cost: %f sec, size=%d\n", ( double ) ( e_time - s_time ) / CLOCKS_PER_SEC, \
|
||||
friso_all_dic_size( friso->dic ) );
|
||||
|
||||
while ( 1 ) {
|
||||
printf("friso-%d>> ", lex);
|
||||
scanf("%s", _line);
|
||||
if ( strcmp( _line, "quit" ) == 0 ) {
|
||||
break;
|
||||
} else if ( strcmp( _line, "help" ) == 0 ) {
|
||||
___PRINT_HELP_INFO___
|
||||
} else if ( strcmp( _line, "#set" ) == 0 ) {
|
||||
printf("lex_t>> ");
|
||||
scanf("%d", &lex);
|
||||
} else {
|
||||
s_time = clock();
|
||||
e = friso_dic_get( friso->dic, lex, _line );
|
||||
e_time = clock();
|
||||
if ( e != NULL ) {
|
||||
printf("word=%s, syn=%s, fre=%d, cost:%fsec\n",
|
||||
e->word, e->syn==NULL? "NULL" : (char *)e->syn->items[0], e->fre,
|
||||
(double) ( e_time - s_time ) / CLOCKS_PER_SEC );
|
||||
while (1) {
|
||||
printf("friso-%d>> ", lex);
|
||||
scanf("%s", _line);
|
||||
if (strcmp( _line, "quit" ) == 0) {
|
||||
break;
|
||||
} else if ( strcmp(_line, "help") == 0 ) {
|
||||
___PRINT_HELP_INFO___
|
||||
} else if ( strcmp( _line, "#set" ) == 0 ) {
|
||||
printf("lex_t>> ");
|
||||
scanf("%d", &lex);
|
||||
} else {
|
||||
printf("%s was not found.\n", _line);
|
||||
s_time = clock();
|
||||
e = friso_dic_get( friso->dic, lex, _line );
|
||||
e_time = clock();
|
||||
if (e != NULL) {
|
||||
printf(
|
||||
"word=%s, syn=%s, fre=%d, cost:%fsec\n",
|
||||
e->word, e->syn==NULL? "NULL" : (char *)e->syn->items[0],
|
||||
e->fre,
|
||||
(double) ( e_time - s_time ) / CLOCKS_PER_SEC
|
||||
);
|
||||
} else {
|
||||
printf("%s was not found.\n", _line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//friso_dic_free( friso->dic );
|
||||
// friso_dic_free( friso->dic );
|
||||
friso_free(friso);
|
||||
|
||||
return 0;
|
||||
|
@ -1,11 +1,10 @@
|
||||
/*
|
||||
* link list test programe.
|
||||
*
|
||||
* @author chenxin
|
||||
* @email chenxin619315@gmail.com
|
||||
* @author lionsoul<chenxin619315@gmail.com>
|
||||
*/
|
||||
#include "friso_API.h"
|
||||
|
||||
#include "friso_API.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@ -13,12 +12,12 @@ int main( int argc, char **args ) {
|
||||
|
||||
friso_link_t link;
|
||||
fstring keys[] = {
|
||||
"chenmanwen", "yangqinghua",
|
||||
"chenxin", "luojiangyan", "xiaoyanzi", "bibi",
|
||||
"zhangrenfang", "yangjian",
|
||||
"liuxiao", "pankai",
|
||||
"chenpei", "liheng", "zhangzhigang", "zhgangyishao", "yangjiangbo",
|
||||
"caizaili", "panpan", "xiaolude", "yintanwen"
|
||||
"chenmanwen", "yangqinghua",
|
||||
"chenxin", "luojiangyan", "xiaoyanzi", "bibi",
|
||||
"zhangrenfang", "yangjian",
|
||||
"liuxiao", "pankai",
|
||||
"chenpei", "liheng", "zhangzhigang", "zhgangyishao", "yangjiangbo",
|
||||
"caizaili", "panpan", "xiaolude", "yintanwen"
|
||||
};
|
||||
int j, len = sizeof( keys ) / sizeof( fstring );
|
||||
|
||||
@ -28,15 +27,15 @@ int main( int argc, char **args ) {
|
||||
printf("size=%d\n", link->size );
|
||||
|
||||
for ( j = 0; j < len; j++ ) {
|
||||
//link_add( link, keys[j] );
|
||||
link_list_add_last( link, keys[j] );
|
||||
//link_add( link, keys[j] );
|
||||
link_list_add_last( link, keys[j] );
|
||||
}
|
||||
|
||||
printf("size=%d\n", link->size );
|
||||
|
||||
for ( j = 0; j < len / 2; j++ ) {
|
||||
//printf("idx=%d, remove %s\n", j, ( fstring ) link_remove( link, 0 ) );
|
||||
printf("idx=%d, remove %s\n", j, ( fstring ) link_list_remove_first( link ) );
|
||||
//printf("idx=%d, remove %s\n", j, ( fstring ) link_remove( link, 0 ) );
|
||||
printf("idx=%d, remove %s\n", j, ( fstring ) link_list_remove_first( link ) );
|
||||
}
|
||||
|
||||
printf("size=%d\n", link->size );
|
||||
|
@ -1,17 +1,16 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "friso_API.h"
|
||||
|
||||
/**
|
||||
* friso fstring split test program .
|
||||
*
|
||||
* @author chenxin<chenxin619315@gmail.com>
|
||||
* @date 2013-06-09
|
||||
*/
|
||||
* @author lionsoul<chenxin619315@gmail.com>
|
||||
*/
|
||||
|
||||
#include "friso_API.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main ( int argc, char **args )
|
||||
{
|
||||
fstring source = ",I am a chinese,,my name is chenxin,and i am the author of friso,bug report email chenxin619315@gmail.com,qq:1187582057";
|
||||
fstring source = ",I am a chinese,,my name is Lion,and i am the author of friso,bug report email chenxin619315@gmail.com,qq:1187582057";
|
||||
char buffer[128];
|
||||
string_split_t split = new_string_split(",", source );
|
||||
|
||||
@ -20,11 +19,10 @@ int main ( int argc, char **args )
|
||||
printf("sst->delLen=%d\n", split->delLen);
|
||||
|
||||
while ( string_split_next(split, buffer) != NULL) {
|
||||
printf("buffer:%s\n", buffer);
|
||||
printf("buffer:%s\n", buffer);
|
||||
}
|
||||
|
||||
free_string_split(split);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
/*
|
||||
* fstring handle mode test program.
|
||||
*
|
||||
* @author chenxin <chenxin619315@gmail.com>
|
||||
* @author lionsoul<chenxin619315@gmail.com>
|
||||
*/
|
||||
#include "friso_API.h"
|
||||
|
||||
#include "friso_API.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -19,14 +19,19 @@ int main( int argc, char **args ) {
|
||||
printf("str=%s, length=%d\n", str, length );
|
||||
|
||||
|
||||
for ( t = 0; t < length; t += bytes ) {
|
||||
bytes = get_utf8_bytes( *(str + t) );
|
||||
if ( bytes == 0 ) continue;
|
||||
for ( j = 0; j < bytes; j++ )
|
||||
word[j] = *(str + t + j );
|
||||
word[j] = '\0';
|
||||
string_buffer_append( sb, word );
|
||||
printf("word=%s\n", word );
|
||||
for (t = 0; t < length; t += bytes) {
|
||||
bytes = get_utf8_bytes(*(str + t));
|
||||
if ( bytes == 0 ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for ( j = 0; j < bytes; j++ ) {
|
||||
word[j] = *(str + t + j );
|
||||
}
|
||||
|
||||
word[j] = '\0';
|
||||
string_buffer_append( sb, word );
|
||||
printf("word=%s\n", word );
|
||||
}
|
||||
|
||||
printf("length=%d, buffer=%s\n", sb->length, sb->buffer );
|
||||
|
Loading…
Reference in New Issue
Block a user