EntitySet.java
01 /*
02  *  EntitySet.java
03  *
04  *  Copyright (c) 1995-2010, The University of Sheffield. See the file
05  *  COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
06  *
07  *  This file is part of GATE (see http://gate.ac.uk/), and is free
08  *  software, licenced under the GNU Library General Public License,
09  *  Version 2, June 1991 (in the distribution as file licence.html,
10  *  and also available at http://gate.ac.uk/gate/licence.html).
11  *
12  *  Valentin Tablan, July/2000
13  *
14  *  $Id: EntitySet.java 12006 2009-12-01 17:24:28Z thomas_heitz $
15  */
16 
17 package gate.creole.nerc;
18 
19 import java.io.Serializable;
20 import java.util.*;
21 
22 import gate.*;
23 
24 /** Representing a set of entities found in a single text file.
25   * Each member a the set is an EntityDescriptor
26   */
27 public class EntitySet extends AbstractSet implements Set, Serializable {
28 
29   /** Constructs an entity set from a Gate annotation set*/
30   public EntitySet(String fileName, Document document,
31                    AnnotationSet annotationSet) {
32     this.fileName = fileName;
33     myEntities = new HashSet();
34     if(annotationSet != null){
35       Iterator<Annotation> annIter = annotationSet.iterator();
36       while(annIter.hasNext()){
37         myEntities.add(new EntityDescriptor(document, annIter.next()));
38       }
39     }
40   }
41 
42   /** Returns the name of the file where the entities in this set
43     *  were discovered
44     */
45   public String getTextFileName() {
46     return fileName;
47   }
48 
49   /** Returns a string giving the file name on one line (preceded by
50     * &quot;==== FILE : &quot; followed by each entity descriptor's string
51     * representation, one-per-line.
52     */
53   public String toString() {
54     ///String res = "==== FILE: " + fileName + "\n";
55     StringBuffer res = new StringBuffer(gate.Gate.STRINGBUFFER_SIZE);
56 
57     res.append("==== FILE: ");
58     res.append(fileName);
59     res.append("\n");
60 
61     Iterator entIter = myEntities.iterator();
62     while(entIter.hasNext()){
63 ///      res += entIter.next().toString() + "\n";
64       res.append(entIter.next().toString());
65       res.append("\n");
66     }
67     return res.toString();
68   }
69 
70   public int size(){ return myEntities.size();}
71 
72   public Iterator iterator() {return myEntities.iterator();}
73 
74   String fileName;
75   Set myEntities;
76 }