| EntitySet.java |
1 /*
2 * EntitySet.java
3 *
4 * Copyright (c) 1998-2004, 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 * Valentin Tablan, July/2000
12 *
13 * $Id: EntitySet.java,v 1.7 2004/07/21 17:10:05 akshay Exp $
14 */
15
16 package gate.creole.nerc;
17
18 import java.io.Serializable;
19 import java.util.*;
20
21 import gate.*;
22
23 /** Representing a set of entities found in a single text file.
24 * Each member a the set is an EntityDescriptor
25 */
26 public class EntitySet extends AbstractSet implements Set, Serializable {
27
28 /** Constructs an entity set from a Gate annotation set*/
29 public EntitySet(String fileName, Document document,
30 AnnotationSet annotationSet) {
31 this.fileName = fileName;
32 myEntities = new HashSet();
33 if(annotationSet != null){
34 Iterator annIter = annotationSet.iterator();
35 while(annIter.hasNext()){
36 myEntities.add(new EntityDescriptor(document,
37 (Annotation)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 * "==== FILE : " 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 }