[25ae32e] | 1 | #include "auttools.h" |
---|
| 2 | //#include "/src/cpp-comm/plx/Plx.h" |
---|
| 3 | |
---|
| 4 | void fullform(const char* b, const char* d, char* f) |
---|
| 5 | { |
---|
| 6 | int i,j=0; |
---|
| 7 | int n1, n2=0; |
---|
| 8 | bool g=false; |
---|
| 9 | char s1[200], s2[200], temps[200]; |
---|
| 10 | while(d[j]>='0' && d[j]<='9')j++; |
---|
| 11 | strncpy(temps,d,j); temps[j]='\0'; |
---|
| 12 | n1=atoi(temps); |
---|
| 13 | i=j; |
---|
| 14 | while(!ispunct(d[j]) || d[j]=='*') j++; |
---|
| 15 | strncpy(s1,d+i,j-i); |
---|
| 16 | s1[j-i]='\0'; |
---|
| 17 | if(d[j++]=='-') |
---|
| 18 | { |
---|
| 19 | i=j; |
---|
| 20 | while(d[j]>='0' && d[j]<='9')j++; |
---|
| 21 | strncpy(temps,d+i,j-i); temps[j]='\0'; |
---|
| 22 | n2=atoi(temps); |
---|
| 23 | i=j; |
---|
| 24 | while(!ispunct(d[j]) || d[j]=='*') j++; |
---|
| 25 | strncpy(s2,d+i,j-i); |
---|
| 26 | s2[j-i]='\0'; |
---|
| 27 | g=true; |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | int blen=strlen(b); |
---|
| 31 | if(g) |
---|
| 32 | if(n1+n2<=blen) |
---|
| 33 | { |
---|
| 34 | strcpy(f,s1); |
---|
| 35 | strcat(f,b+n1); |
---|
| 36 | f[strlen(f)-n2]='\0'; |
---|
| 37 | strcat(f,s2); |
---|
| 38 | } |
---|
| 39 | else |
---|
| 40 | strcpy(f,"<ERR>"); |
---|
| 41 | else |
---|
| 42 | if(n1<=blen) |
---|
| 43 | { |
---|
| 44 | strcpy(f,b); |
---|
| 45 | f[strlen(f)-n1]='\0'; |
---|
| 46 | strcat(f,s1); |
---|
| 47 | } |
---|
| 48 | else |
---|
| 49 | strcpy(f,"<ERR>"); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | void compose(char* stem, char* ending, char* form) |
---|
| 53 | { |
---|
| 54 | bool suffix=true; |
---|
| 55 | while(*stem) |
---|
| 56 | if(*stem=='*') |
---|
| 57 | { |
---|
| 58 | strcpy(form,ending); |
---|
| 59 | form+=strlen(ending); |
---|
| 60 | suffix=false; |
---|
| 61 | stem++; |
---|
| 62 | } |
---|
| 63 | else |
---|
| 64 | *(form++)=*(stem++); |
---|
| 65 | if(suffix) |
---|
| 66 | { |
---|
| 67 | strcpy(form,ending); |
---|
| 68 | form+=strlen(ending); |
---|
| 69 | } |
---|
| 70 | *form='\0'; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | void autodescr(const char* f, const char* des, char* lemma, char* pos, char* attr) |
---|
| 74 | { |
---|
| 75 | char lemd[MAXWORDLEN]; |
---|
| 76 | int o,l=strcspn(des,","); |
---|
| 77 | strncpy(lemd,des,l); |
---|
| 78 | lemd[l]='\0'; |
---|
| 79 | fullform(f,lemd,lemma); |
---|
| 80 | o=l+1; |
---|
| 81 | l=strcspn(des+o,"/:"); |
---|
| 82 | strncpy(pos,des+o,l); |
---|
| 83 | pos[l]='\0'; |
---|
| 84 | o=o+l; |
---|
| 85 | if(des[o]=='/') |
---|
| 86 | { |
---|
| 87 | o++; |
---|
| 88 | strcpy(attr,des+o); |
---|
| 89 | } |
---|
| 90 | else |
---|
| 91 | attr[0]='\0'; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | int common_prefix(const char* s, const char* t) |
---|
| 96 | { |
---|
| 97 | int n=0; |
---|
| 98 | while(*s==*t && *s!='\0') |
---|
| 99 | { s++,t++;n++; } |
---|
| 100 | return n; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | int strdiff(const char* s, const char* t, |
---|
| 104 | int& frontcut, char* prefix, int& endcut, char* suffix) |
---|
| 105 | { |
---|
| 106 | int slen=strlen(s); |
---|
| 107 | int tlen=strlen(t); |
---|
| 108 | int ss, ss_max=0; /* ss - s shift */ |
---|
| 109 | int ts, ts_max=0; /* ts - t shift */ |
---|
| 110 | int common, common_max=0; |
---|
| 111 | for(ss=0;ss<slen;ss++) |
---|
| 112 | for(ts=0;ts<tlen;ts++) |
---|
| 113 | if( (common=common_prefix(s+ss,t+ts))>common_max |
---|
| 114 | && (common>4 || (ss==0 && ts==0 && common>1)) ) |
---|
| 115 | { |
---|
| 116 | ss_max=ss; |
---|
| 117 | ts_max=ts; |
---|
| 118 | common_max=common; |
---|
| 119 | } |
---|
| 120 | // print "--", tsmax,"\n" |
---|
| 121 | printf("--%d\n", ts_max); |
---|
| 122 | frontcut=ss_max; |
---|
| 123 | strncpy(prefix,t,ts_max); prefix[ts_max]='\0'; |
---|
| 124 | endcut=slen-ss_max-common_max; |
---|
| 125 | strcpy(suffix,t+ts_max+common_max); |
---|
| 126 | return common_max; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | void fprndiff(FILE* f, const char* s, const char* t) |
---|
| 130 | { |
---|
| 131 | int frontcut,endcut; |
---|
| 132 | char pref[MAXWORDLEN],suff[MAXWORDLEN]; |
---|
| 133 | strdiff(s,t,frontcut,pref,endcut,suff); |
---|
| 134 | if(frontcut!=0 || pref[0]!='\0') |
---|
| 135 | fprintf(f,"%d%s-%d%s",frontcut,pref,endcut,suff); |
---|
| 136 | else |
---|
| 137 | fprintf(f,"%d%s",endcut,suff); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | void sprndiff(char* outstr, const char* s, const char* t) |
---|
| 141 | { |
---|
| 142 | int frontcut,endcut; |
---|
| 143 | char pref[MAXWORDLEN],suff[MAXWORDLEN]; |
---|
| 144 | strdiff(s,t,frontcut,pref,endcut,suff); |
---|
| 145 | if(frontcut!=0 || pref[0]!='\0') |
---|
| 146 | sprintf(outstr,"%d%s-%d%s",frontcut,pref,endcut,suff); |
---|
| 147 | else |
---|
| 148 | sprintf(outstr,"%d%s",endcut,suff); |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | void despos(const char* des, char* pos) |
---|
| 153 | { |
---|
| 154 | int di=0; |
---|
| 155 | int pi=0; |
---|
| 156 | while(des[di]!=',' && des[di]!='\0') ++di; |
---|
| 157 | if(des[di]==',') |
---|
| 158 | { |
---|
| 159 | ++di; |
---|
| 160 | while(isupper(des[di])) pos[pi++]=des[di++]; |
---|
| 161 | } |
---|
| 162 | pos[pi]='\0'; |
---|
| 163 | } |
---|
| 164 | |
---|