/*
 *  WordImpl.java
 *
 *  Copyright (c) 1998-2002, The University of Sheffield.
 *
 *  This file is part of GATE (see http://gate.ac.uk/), and is free
 *  software, licenced under the GNU Library General Public License,
 *  Version 2, June 1991 (in the distribution as file licence.html,
 *  and also available at http://gate.ac.uk/gate/licence.html).
 *
 *  Marin Dimitrov, 17/May/2002
 *
 *  $Id: WordImpl.java,v 1.2 2002/05/30 09:54:17 marin Exp $
 */

package gate.wordnet;

import java.util.List;
import java.util.ArrayList;

import junit.framework.*;
import net.didion.jwnl.dictionary.*;
import net.didion.jwnl.data.*;
import net.didion.jwnl.*;
import gate.util.*;

public class WordImpl implements Word {

  private String lemma;
  private int senseCount;
  private ArrayList wordSenses;
  private Dictionary wnDictionary;

  public WordImpl(String _lemma, int _senseCount, Dictionary _wnDictionary) {

    //0.
    Assert.assertNotNull(_lemma);
    Assert.assertNotNull(_wnDictionary);
    Assert.assertTrue(_senseCount > 0);

    this.lemma = _lemma;
    this.senseCount = _senseCount;
    this.wnDictionary = _wnDictionary;
  }


  /** returns the senses of this word */
  public List getWordSenses() throws WordNetException{

    //do we have the list already?
    if (null == this.wordSenses) {
      _loadWordSenses();
    }

    return this.wordSenses;
  }

  private void _loadWordSenses() throws WordNetException {

//    Dictionary dict = this.wnMain.getJWNLDictionary();

    try {
      IndexWordSet iwSet = this.wnDictionary.lookupAllIndexWords(this.lemma);
      IndexWord[] arrIndexWords = iwSet.getIndexWordArray();

      for (int i=0; i< arrIndexWords.length; i++) {
        IndexWord iWord = arrIndexWords[i];
        net.didion.jwnl.data.Synset[] synsets = iWord.getSenses();
        for (int j=0; j< synsets.length; j++) {
          net.didion.jwnl.data.Synset currSynset = synsets[j];
        }
      }

//      this.
    }
    catch(JWNLException jwne) {
      throw new WordNetException(jwne);
    }

  }


  /** returns the lemma of this word */
  public String getLemma(){
    return this.lemma;
  }


  /** returns the number of senses of this word (not necessarily loading them from storage) */
  public int getSenseCount(){
    return this.senseCount;
  }
}