|
WordImpl |
|
1 /* 2 * WordImpl.java 3 * 4 * Copyright (c) 1998-2002, The University of Sheffield. 5 * 6 * This file is part of GATE (see http://gate.ac.uk/), and is free 7 * software, licenced under the GNU Library General Public License, 8 * Version 2, June 1991 (in the distribution as file licence.html, 9 * and also available at http://gate.ac.uk/gate/licence.html). 10 * 11 * Marin Dimitrov, 17/May/2002 12 * 13 * $Id: WordImpl.java,v 1.2 2002/05/30 09:54:17 marin Exp $ 14 */ 15 16 package gate.wordnet; 17 18 import java.util.List; 19 import java.util.ArrayList; 20 21 import junit.framework.*; 22 import net.didion.jwnl.dictionary.*; 23 import net.didion.jwnl.data.*; 24 import net.didion.jwnl.*; 25 import gate.util.*; 26 27 public class WordImpl implements Word { 28 29 private String lemma; 30 private int senseCount; 31 private ArrayList wordSenses; 32 private Dictionary wnDictionary; 33 34 public WordImpl(String _lemma, int _senseCount, Dictionary _wnDictionary) { 35 36 //0. 37 Assert.assertNotNull(_lemma); 38 Assert.assertNotNull(_wnDictionary); 39 Assert.assertTrue(_senseCount > 0); 40 41 this.lemma = _lemma; 42 this.senseCount = _senseCount; 43 this.wnDictionary = _wnDictionary; 44 } 45 46 47 /** returns the senses of this word */ 48 public List getWordSenses() throws WordNetException{ 49 50 //do we have the list already? 51 if (null == this.wordSenses) { 52 _loadWordSenses(); 53 } 54 55 return this.wordSenses; 56 } 57 58 private void _loadWordSenses() throws WordNetException { 59 60 // Dictionary dict = this.wnMain.getJWNLDictionary(); 61 62 try { 63 IndexWordSet iwSet = this.wnDictionary.lookupAllIndexWords(this.lemma); 64 IndexWord[] arrIndexWords = iwSet.getIndexWordArray(); 65 66 for (int i=0; i< arrIndexWords.length; i++) { 67 IndexWord iWord = arrIndexWords[i]; 68 net.didion.jwnl.data.Synset[] synsets = iWord.getSenses(); 69 for (int j=0; j< synsets.length; j++) { 70 net.didion.jwnl.data.Synset currSynset = synsets[j]; 71 } 72 } 73 74 // this. 75 } 76 catch(JWNLException jwne) { 77 throw new WordNetException(jwne); 78 } 79 80 } 81 82 83 /** returns the lemma of this word */ 84 public String getLemma(){ 85 return this.lemma; 86 } 87 88 89 /** returns the number of senses of this word (not necessarily loading them from storage) */ 90 public int getSenseCount(){ 91 return this.senseCount; 92 } 93 }
|
WordImpl |
|