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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| SynsetPtr findtheinfo_ds(char *searchstr, int dbase, int ptrtyp, int whichsense)
{
static Index idx;
SynsetPtr cursyn;
SynsetPtr synlist = NULL, lastsyn = NULL;
int depth = 0;
int newsense = 0;
wnresults.numforms = 0;
wnresults.printcnt = 0;
while( ( &(idx = getindex( searchstr, dbase))))
{
searchstr = NULL; /* clear out for next call */
newsense = 1;
if(ptrtyp < 0)
{
ptrtyp = -ptrtyp;
depth = 1;
}
wnresults.SenseCount[wnresults.numforms] = idx.off_cnt;
wnresults.OutSenseCount[wnresults.numforms] = 0;
wnresults.searchbuf = NULL;
wnresults.searchds = NULL;
/* Go through all of the searchword's senses in the
database and perform the search requested. */
for( sense = 0; sense < idx.off_cnt; sense++)
{
if( whichsense == ALLSENSES || whichsense == sense + 1)
{
cursyn = read_synset( dbase, idx.offset[sense], idx.wd);
if( lastsyn)
{
if( newsense)
lastsyn->nextform = cursyn;
else
lastsyn->nextss = cursyn;
}
if( !synlist)
synlist = cursyn;
newsense = 0;
cursyn->searchtype = ptrtyp;
cursyn->ptrlist = traceptrs_ds( cursyn, ptrtyp, getpos( cursyn->pos), depth);
lastsyn = cursyn;
if (whichsense == sense + 1)
break;
}
}
free_index( idx);
wnresults.numforms++;
if (ptrtyp == COORDS)
{ /* clean up by removing hypernym */
lastsyn = synlist->ptrlist;
synlist->ptrlist = lastsyn->ptrlist;
free_synset(lastsyn);
}
}
wnresults.searchds = synlist;
return(synlist);
}
/* Recursive search algorithm to trace a pointer tree and return results
in linked list of data structures. */
SynsetPtr traceptrs_ds(SynsetPtr synptr, int ptrtyp, int dbase, int depth)
{ // 1
int i;
SynsetPtr cursyn, synlist = NULL, lastsyn = NULL;
int tstptrtyp, docoords;
size_t len;
/* If synset is a satellite, find the head word of its
head synset and the head word's sense number. */
if( getsstype( synptr->pos) == SATELLITE)
{
for( i = 0; i < synptr->ptrcount; i++)
{
if (synptr->ptrtyp[i] == SIMPTR)
{
cursyn = read_synset( synptr->ppos[i], synptr->ptroff[i], "");
synptr->headword = new char [strlen(cursyn->words[0]) + 1];
assert(synptr->headword);
len = strlen( cursyn->words[0]);
strcpy_s( synptr->headword, len, cursyn->words[0]);
synptr->headsense = cursyn->lexid[0];
free_synset( cursyn);
break;
}
} //end for
}// end of if SATELLITE
if( ptrtyp == COORDS)
{
tstptrtyp = HYPERPTR;
docoords = 1;
}
else
{
tstptrtyp = ptrtyp;
docoords = 0;
}
for( i = 0; i < synptr->ptrcount; i++)
{
if( ( synptr->ptrtyp[i] == tstptrtyp) && ((synptr->pfrm[i] == 0) || (synptr->pfrm[i] == synptr->whichword)))
{
cursyn = read_synset( synptr->ppos[i], synptr->ptroff[i], "");
cursyn->searchtype = ptrtyp;
if( lastsyn)
lastsyn->nextss = cursyn;
if( !synlist)
synlist = cursyn;
lastsyn = cursyn;
if( depth)
{
depth = depthcheck( depth, cursyn);
cursyn->ptrlist = traceptrs_ds(cursyn, ptrtyp, getpos( cursyn->pos), (depth+1));
}
else if( docoords)
{
cursyn->ptrlist = traceptrs_ds( cursyn, HYPOPTR, NOUN, 0);
}
}
}//end for
return( synlist);
} |
Partager