src/Generic/wordnet/xx_WordNet.cpp
/*04.04.06 Michael Levit:
	the following two functions provide a more flexible interface to WordNet:
	1) getSynonyms() allows to collect all kinds of relations (synonyms/antonyms/hypernyms)
	from different levels (and different word senses, if needed)
	2) collectNextLevel() is an auxiliary function that enables recursion for getSynonyms()
  03.28.12 Marjorie Freedman
	Stem before getting a synset (wordnet assumes lemmatization). Typically (maybe always?) the stem will be in the results vector.
	This method provides access to word-relations beyond synonyms.  It is used for hypernyms (HYPERPTR), hyponyms(HYPOPTR), and HASPARTPTR.
	The relations *are not* mutually exclusive, e.g. synonyms will also be returned for hypernyms
	

*/
04.04.06 Michael Levit:
the following two functions provide a more flexible interface to WordNet:
1) getSynonyms() allows to collect all kinds of relations (synonyms/antonyms/hypernyms)
from different levels (and different word senses, if needed)
2) collectNextLevel() is an auxiliary function that enables recursion for getSynonyms()
03.28.12 Marjorie Freedman
Stem before getting a synset (wordnet assumes lemmatization). Typically (maybe always?) the stem will be in the results vector.
This method provides access to word-relations beyond synonyms.  It is used for hypernyms (HYPERPTR), hyponyms(HYPOPTR), and HASPARTPTR.
The relations *are not* mutually exclusive, e.g. synonyms will also be returned for hypernyms
04 . 04 . 06 Michael Levit : the following two functions provide a more flexible interface to WordNet : 1 ) getSynonyms () allows to collect all kinds of relations ( synonyms / antonyms / hypernyms ) from different levels ( and different word senses if needed ) 2 ) collectNextLevel () is an auxiliary function that enables recursion for getSynonyms () 03 . 28 . 12 Marjorie Freedman Stem before getting a synset ( wordnet assumes lemmatization ) . Typically ( maybe always? ) the stem will be in the results vector . This method provides access to word - relations beyond synonyms . It is used for hypernyms ( HYPERPTR ) hyponyms ( HYPOPTR ) and HASPARTPTR . The relations * are not * mutually exclusive e . g . synonyms will also be returned for hypernyms
int WordNet::getSynonyms(const Symbol& word, WordNet::CollectedSynonyms& results, int pos, int ptrType, int level, int sense) {
	results.clear();
	SynsetPtr syn = 0;
	Symbol stem = WordNet::stem(word, pos);	
	synset_cache_key_type cache_key( stem, pos, ptrType );
	synset_cache_type::iterator cit = synset_cache.find( cache_key );
	if( cit != synset_cache.end() ){
		pair< synset_cache_key_type, SynsetPtr > entry = (*(*cit).second);
		synset_lru_list.erase( (*cit).second );
		synset_lru_list.push_front( entry );
		(*cit).second = synset_lru_list.begin();
		syn = entry.second;
	} else {
		char cstr[WORDBUF];
		copywchar_tochar(stem.to_string(), cstr, WORDBUF);
		syn = findtheinfo_ds(cstr, pos, ptrType, sense);
		pair< synset_cache_key_type, SynsetPtr > entry = make_pair( cache_key, syn );
		synset_lru_list.push_front( entry );
		synset_cache.insert( make_pair( cache_key, synset_lru_list.begin() ) );
		if( synset_lru_list.size() > (size_t)WORDNET_CACHE_SIZE ){
			free_syns( synset_lru_list.back().second );
			synset_cache.erase( synset_lru_list.back().first );
			synset_lru_list.pop_back();
		}
	}
	if (syn == 0) return 0;
	int n=0;
	SynsetPtr synnext=syn;
	do {
		n += collectNextLevel(synnext, level, results);
		synnext = synnext->nextss;
	} while ( synnext != 0 );
	return n;
}
int WordNet :: getSynonyms ( const Symbol & word , WordNet :: CollectedSynonyms & results , int pos , int ptrType , int level , int sense ) { results . clear ( ) ; SynsetPtr syn = 0 ; Symbol stem = WordNet :: stem ( word , pos ) ; synset_cache_key_type cache_key ( stem , pos , ptrType ) ; synset_cache_type :: iterator cit = synset_cache . find ( cache_key ) ; if ( cit != synset_cache . end ( ) ) { pair < synset_cache_key_type , SynsetPtr > entry = ( * ( * cit ) . second ) ; synset_lru_list . erase ( ( * cit ) . second ) ; synset_lru_list . push_front ( entry ) ; ( * cit ) . second = synset_lru_list . begin ( ) ; syn = entry . second ; } else { char cstr [ WORDBUF ] ; copywchar_tochar ( stem . to_string ( ) , cstr , WORDBUF ) ; syn = findtheinfo_ds ( cstr , pos , ptrType , sense ) ; pair < synset_cache_key_type , SynsetPtr > entry = make_pair ( cache_key , syn ) ; synset_lru_list . push_front ( entry ) ; synset_cache . insert ( make_pair ( cache_key , synset_lru_list . begin ( ) ) ) ; if ( synset_lru_list . size ( ) > ( size_t ) WORDNET_CACHE_SIZE ) { free_syns ( synset_lru_list . back ( ) . second ) ; synset_cache . erase ( synset_lru_list . back ( ) . first ) ; synset_lru_list . pop_back ( ) ; } } if ( syn == 0 ) return 0 ; int n = 0 ; SynsetPtr synnext = syn ; do { n += collectNextLevel ( synnext , level , results ) ; synnext = synnext -> nextss ; } while ( synnext != 0 ) ; return n ; }
04.04.06 Michael Levit:
the following two functions provide a more flexible interface to WordNet:
1) getSynonyms() allows to collect all kinds of relations (synonyms/antonyms/hypernyms)
from different levels (and different word senses, if needed)
2) collectNextLevel() is an auxiliary function that enables recursion for getSynonyms()
03.28.12 Marjorie Freedman
Stem before getting a synset (wordnet assumes lemmatization).
04 . 04 . 06 Michael Levit : the following two functions provide a more flexible interface to WordNet : 1 ) getSynonyms () allows to collect all kinds of relations ( synonyms / antonyms / hypernyms ) from different levels ( and different word senses if needed ) 2 ) collectNextLevel () is an auxiliary function that enables recursion for getSynonyms () 03 . 28 . 12 Marjorie Freedman Stem before getting a synset ( wordnet assumes lemmatization ) .
// first check the cache
 // move the entry to the lru list head
 // update the cached list iterator
 // not found-- do a wordnet lookup
 // add the entry to the lru list, and to the cache. Insertion should never fail.
 // free the LRU entry
