|
MutableLexicalKnowledgeBaseImpl |
|
1 /* 2 * MutableLexicalKnowledgeBaseImpl.java 3 * 4 * Copyright (c) 1998-2003, 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 * Kalina Bontcheva, 28/January/2003 12 * 13 * $Id: MutableLexicalKnowledgeBaseImpl.java,v 1.1 2003/02/26 16:24:53 kalina Exp $ 14 15 */ 16 17 package gate.lexicon; 18 19 import gate.creole.AbstractLanguageResource; 20 import gate.util.*; 21 import gate.*; 22 import java.util.*; 23 import gate.persist.PersistenceException; 24 import gate.security.SecurityException; 25 import gate.creole.ResourceInstantiationException; 26 import java.net.*; 27 import java.io.*; 28 29 public class MutableLexicalKnowledgeBaseImpl extends AbstractLanguageResource 30 implements MutableLexicalKnowledgeBase { 31 32 private String version = "1.0"; 33 protected List synsets = new ArrayList(); 34 protected HashMap words = new HashMap(); 35 protected List posTypes = new ArrayList(); 36 static final long serialVersionUID = -2543190013851016324L; 37 private Object lexId = "MIAKT Lexical KB Lexicon"; 38 39 public MutableLexicalKnowledgeBaseImpl() { 40 for (int i = 0; i < POS_TYPES.length; i++) 41 posTypes.add(POS_TYPES[i]); 42 } 43 44 public Resource init() throws gate.creole.ResourceInstantiationException { 45 return this; 46 } 47 48 public Iterator getSynsets() { 49 return synsets.iterator(); 50 } 51 52 public Iterator getSynsets(Object pos) { 53 if (pos == null) 54 return null; 55 List tempList = new ArrayList(); 56 for (int i=0; i<synsets.size(); i++) { 57 LexKBSynset synset = (LexKBSynset) synsets.get(i); 58 if (pos.equals(synset.getPOS())) 59 tempList.add(synset); 60 }//for 61 return tempList.iterator(); 62 } 63 64 public List lookupWord(String lemma) { 65 if (lemma == null) 66 return null; 67 Word myWord = (Word) words.get(lemma); 68 if (myWord == null) 69 return null; 70 return myWord.getWordSenses(); 71 } 72 73 public List lookupWord(String lemma, Object pos) { 74 if (lemma == null || pos == null) 75 return null; 76 Word myWord = (Word) words.get(lemma); 77 if (myWord == null) 78 return null; 79 List posSenses = new ArrayList(); 80 Iterator iter = myWord.getWordSenses().iterator(); 81 while (iter.hasNext()) { 82 LexKBWordSense sense = (LexKBWordSense) iter.next(); 83 if (sense.getPOS().equals(pos)) 84 posSenses.add(sense); 85 } //while loop through senses 86 return posSenses; 87 } 88 89 /** add a new word */ 90 public MutableWord addWord(String lemma){ 91 if (words.containsKey(lemma)) 92 return (MutableWord) words.get(lemma); 93 94 MutableWordImpl newWord = new MutableWordImpl(lemma); 95 words.put(lemma, newWord); 96 return newWord; 97 } 98 99 /** sets the lexicon version */ 100 public void setVersion(String newVersion){ 101 version = newVersion; 102 } 103 104 /** returns the lexicon version */ 105 public String getVersion() { 106 return version; 107 } 108 109 public MutableLexKBSynset addSynset() { 110 MutableLexKBSynset newSynset = new MutableLexKBSynsetImpl(); 111 synsets.add(newSynset); 112 return newSynset; 113 } 114 115 public Object[] getPOSTypes() { 116 return posTypes.toArray(); 117 } 118 119 public void addPOSType(Object newPOSType) { 120 if (newPOSType == null) 121 return; 122 posTypes.add(newPOSType); 123 } 124 125 public void removeWord(MutableWord theWord) { 126 if (theWord == null) 127 return; 128 theWord.removeSenses(); 129 words.remove(theWord.getLemma()); 130 }//removeWord 131 132 public void removeSynset(MutableLexKBSynset synset) { 133 if (synset == null) 134 return; 135 List senses = synset.getWordSenses(); 136 for (int i = 0; i < senses.size(); i++) { 137 LexKBWordSense sense = (LexKBWordSense) senses.get(i); 138 ((MutableWord) sense.getWord()).removeSense(sense); 139 }//for 140 synset.removeSenses(); 141 synsets.remove(synset); 142 }//removeSynset 143 144 public Object getLexiconId() { 145 return lexId; 146 } 147 148 public void setLexiconId(Object Id) { 149 lexId = Id; 150 } 151 }
|
MutableLexicalKnowledgeBaseImpl |
|