1   /*
2    *  MutableLexKBSynsetImpl.java
3    *
4    *  Copyright (c) 1998-2005, 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: MutableLexKBSynsetImpl.java,v 1.6 2005/01/11 13:51:36 ian Exp $
14   */
15  
16  package gate.lexicon;
17  
18  import java.io.Serializable;
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  public class MutableLexKBSynsetImpl implements MutableLexKBSynset, Serializable {
23  
24    private Object POS;
25    private String definition;
26    private Long id;
27    private static long nextID = 1;
28    private List senses = new ArrayList();
29    static final long serialVersionUID = 7483532901922245459L;
30  
31  
32    public MutableLexKBSynsetImpl() {
33      id = new Long(nextID);
34      nextID++;
35    }
36  
37    public void setPOS(Object newPOS) {
38      POS = newPOS;
39    }
40  
41    public void setDefinition(String newDefinition) {
42      definition = newDefinition;
43    }
44  
45    public boolean addWordSense(LexKBWordSense newWordSense) {
46      return addWordSense(newWordSense, senses.size());
47    }
48  
49    public boolean addWordSense(LexKBWordSense newWordSense, int offset) {
50      if (offset > senses.size() )
51        return false;
52      senses.add(offset, newWordSense);
53      return true;
54    }
55  
56    public boolean setWordSenseIndex(LexKBWordSense wordSense, int newOffset) {
57      if (newOffset > senses.size())
58        return false;
59      senses.set(newOffset, wordSense);
60      return true;
61    }
62  
63    public Object getId(){
64      return id;
65    }
66  
67    /** returns the part-of-speech for this synset*/
68    public Object getPOS(){
69      return POS;
70    }
71  
72    /** textual description of the synset */
73    public String getDefinition(){
74      return definition;
75    }
76  
77    /** WordSenses contained in this synset */
78    public List getWordSenses(){
79      return senses;
80  
81    }
82  
83    /** get specific WordSense according to its order in the synset - most important senses come first  */
84    public LexKBWordSense getWordSense(int offset){
85      return (LexKBWordSense) senses.get(offset);
86    }
87  
88    public String toString() {
89      StringBuffer theString = new StringBuffer();
90      theString.append("[");
91      for (int i = 0; i < senses.size(); i++) {
92        LexKBWordSense sense = (LexKBWordSense) senses.get(i);
93        theString.append(sense.toString() + ";");
94      }//for
95      theString.append("]");
96      return theString.toString();
97    }//toString
98  
99    public void removeSenses(){
100     senses.clear();
101   }
102 
103   public void removeSense(LexKBWordSense theSense){
104     senses.remove(theSense);
105   }
106 
107 }