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