00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <ctype.h>
00005 #include "store.h"
00006 #include "score.h"
00007 #include "cut.h"
00008
00009 char *precedent=NULL;
00010
00017 void cut_words(char *token, int isporn, int isscoring)
00018 {
00019 char *separateurs = { "-=<>/\"'.{}*+,?:;|()_ " };
00020 char *data=NULL, *toStore=NULL;
00021
00022 data = malloc(sizeof(char)*(strlen(token)+1));
00023 data = strtok( token, separateurs );
00024
00025 if( data != NULL){
00026 if(strlen(data)>0 && strlen(data)<25){
00027 if (isscoring) score_storeToken(data, WORDS);
00028 else store_storeTempToken(data, WORDS);
00029 if(precedent != NULL){
00030 toStore = malloc(sizeof(char)*(strlen(precedent)+strlen(data)+2));
00031 strcpy(toStore, precedent);
00032 strcat(toStore, "_");
00033 strcat(toStore, data);
00034 if (isscoring) score_storeToken(toStore, BIWORDS);
00035 else store_storeTempToken(toStore, BIWORDS);
00036 free(toStore);
00037 toStore=NULL;
00038 free(precedent);
00039 precedent=NULL;
00040 }
00041 precedent = malloc(sizeof(char)*(strlen(data)+1));
00042 strcpy(precedent, data);
00043 }
00044 }
00045 while( data != NULL ) {
00046 data = strtok( NULL, separateurs );
00047 if( data != NULL){
00048 if(strlen(data)>0 && strlen(data)<25){
00049 if (isscoring) score_storeToken(data, WORDS);
00050 else store_storeTempToken(data, WORDS);
00051 if (precedent != NULL ) {
00052 toStore = malloc(sizeof(char)*(strlen(precedent)+strlen(data)+2));
00053 strcpy(toStore, precedent);
00054 strcat(toStore, "_");
00055 strcat(toStore, data);
00056 if (isscoring) score_storeToken(toStore, BIWORDS);
00057 else store_storeTempToken(toStore, BIWORDS);
00058 free(toStore);
00059 toStore=NULL;
00060 free(precedent);
00061 precedent = NULL;
00062 }
00063 precedent = malloc(sizeof(char)*(strlen(data)+1));
00064 strcpy(precedent, data);
00065 }
00066 }
00067 }
00068
00069 if (data != NULL) {free(data); data = NULL;}
00070 if (toStore != NULL) {free(toStore); toStore = NULL;}
00071 }
00072
00079 void cut_tags(char *token, int isporn, int isscoring)
00080 {
00081 char *separateurs = { "\\-=<>/\"'.{}*+,?:;|()_ \n" };
00082 char *data=NULL, *first=NULL, *toStore=NULL;
00083 int i;
00084
00085 for (i=0; i<strlen(token)+1; i++) {
00086 token[i] = tolower(token[i]);
00087 }
00088
00089 data = malloc(sizeof(char)*(strlen(token)+1));
00090 data = strtok( token, separateurs );
00091
00092
00093 if( data != NULL){
00094
00095 if(strlen(data)<20){
00096 first = malloc(sizeof(char)*(strlen(data)+1));
00097 strcpy(first, data);
00098 if (isscoring) score_storeToken(first, TAGS);
00099 else store_storeTempToken(first, TAGS);
00100 }else first="";
00101 }
00102 while( data != NULL) {
00103 data = strtok( NULL, separateurs );
00104 if( data != NULL){
00105
00106 if(strlen(data)<20){
00107 toStore = malloc(sizeof(char)*(strlen(data)+strlen(first)+2));
00108 strcpy(toStore, first);
00109 strcat(toStore, "_");
00110 strcat(toStore, data);
00111 if(isscoring) score_storeToken(toStore, TAGS);
00112 else store_storeTempToken(toStore, TAGS);
00113 }
00114 }
00115 }
00116
00117 if (data != NULL) {free(data); data=NULL;}
00118 if (first != NULL) {free(first); first=NULL;}
00119 if (toStore != NULL) {free(toStore); toStore=NULL;}
00120 }
00121
00122
00123
00124
00125 void cut_free(void)
00126 {
00127 if(precedent != NULL){free(precedent); precedent=NULL;}
00128 }
00129