1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| IndexPtr getindex(char *searchstr, int dbase)
{
int i;
int j;
int k;
int len;
char c;
char strings[MAX_FORMS][WORDBUF]; /* vector of search strings */
static IndexPtr offsets[MAX_FORMS];
static int offset;
/* This works like strrok(): if passed with a non-null string,
prepare vector of search strings and offsets. If string
is null, look at current list of offsets and return next
one, or NULL if no more alternatives for this word. */
if (searchstr != NULL)
{
offset = 0;
searchstr = strtolower( searchstr);
for( i = 0; i < MAX_FORMS; i++)
{
len = strlen( searchstr);
len++;
strcpy_s(strings[i], len, searchstr);
offsets[i] = 0;
}
strsubst(strings[1], '_', '-');
strsubst(strings[2], '-', '_');
/* remove all spaces and hyphens from last search string, then
all periods */
for( i = j = k = 0; (c = searchstr[i]) != '\0'; i++)
{
if (c != '_' && c != '-')
strings[3][j++] = c;
if (c != '.')
strings[4][k++] = c;
}
strings[3][j] = '\0';
strings[4][k] = '\0';
/* Get offset of first entry. Then eliminate duplicates
and get offsets of unique strings. */
if( strings[0][0] != NULL)
offsets[0] = index_lookup( strings[0], dbase); // c'est là que ca plante
for( i = 1; i < MAX_FORMS; i++)
if( ( strings[i][0]) != NULL && (strcmp(strings[0], strings[i])))
offsets[i] = index_lookup(strings[i], dbase);
}
for( i = offset; i < MAX_FORMS; i++)
if( offsets[i])
{
offset = i + 1;
return(offsets[i]);
}
return(NULL);
}
/* Read synset from data file at byte offset passed and return parsed
entry in data structure. */
SynsetPtr read_synset(int dbase, long boffset, char *word)
{
FILE *fp;
int len;
if((fp = datafps[dbase]) == NULL)
{
len = 42;
len += strlen( partnames[dbase]);
sprintf_s( msgbuf, len, "WordNet library error: %s datafile not open\n", partnames[dbase]);
display_message( msgbuf);
return(NULL);
}
fseek(fp, boffset, 0); /* position file to byte offset requested */
return(parse_synset(fp, dbase, word)); /* parse synset and return */
} |
Partager