mirror of
https://gitee.com/lionsoul/friso.git
synced 2024-12-01 18:57:50 +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 "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);
|
||||
@ -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 ) {
|
||||
@ -38,30 +37,30 @@ int main(int argc, char **argv)
|
||||
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] ));
|
||||
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] ));
|
||||
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,47 +28,47 @@ 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 ) {
|
||||
while (1) {
|
||||
printf("friso-%d>> ", lex);
|
||||
scanf("%s", _line);
|
||||
if ( strcmp( _line, "quit" ) == 0 ) {
|
||||
if (strcmp( _line, "quit" ) == 0) {
|
||||
break;
|
||||
} else if ( strcmp( _line, "help" ) == 0 ) {
|
||||
} else if ( strcmp(_line, "help") == 0 ) {
|
||||
___PRINT_HELP_INFO___
|
||||
} else if ( strcmp( _line, "#set" ) == 0 ) {
|
||||
printf("lex_t>> ");
|
||||
@ -78,17 +77,20 @@ int main(int argc, char **argv)
|
||||
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 );
|
||||
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>
|
||||
|
||||
|
@ -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 );
|
||||
|
||||
@ -27,4 +26,3 @@ int main ( int argc, char **args )
|
||||
|
||||
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,11 +19,16 @@ 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++ )
|
||||
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 );
|
||||
|
Loading…
Reference in New Issue
Block a user