|
Transducer |
|
1 /* 2 * Transducer.java - transducer class 3 * 4 * Copyright (c) 1998-2001, 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 * Hamish Cunningham, 24/07/98 12 * 13 * $Id: Transducer.java,v 1.21 2001/11/01 15:49:10 valyt Exp $ 14 */ 15 16 17 package gate.jape; 18 19 import java.util.*; 20 import java.net.*; 21 import java.io.*; 22 23 import gate.annotation.*; 24 import gate.util.*; 25 import gate.event.*; 26 import gate.creole.*; 27 import gate.*; 28 29 30 /** 31 * Represents a single or multiphase transducer. 32 */ 33 public abstract class Transducer implements Serializable 34 { 35 /** Debug flag */ 36 private static final boolean DEBUG = false; 37 38 /** Name of this transducer. */ 39 protected String name; 40 41 /** Get the phase name of this transducer */ 42 public String getName() { return name; } 43 44 /** Transduce a document. */ 45 public abstract void transduce(Document doc, AnnotationSet inputAS, 46 AnnotationSet outputAS) 47 throws JapeException, ExecutionException; 48 49 /** Finish: replace dynamic data structures with Java arrays; called 50 * after parsing. 51 */ 52 public abstract void finish(); 53 54 /** Clean up (delete action class files, for e.g.). */ 55 public abstract void cleanUp(); 56 57 /** Create a string representation of the object with padding. */ 58 public abstract String toString(String pad); 59 60 61 /** 62 * Checks whether this PR has been interrupted since the lsat time its 63 * {@link execute()} method was called. 64 */ 65 public synchronized boolean isInterrupted(){ 66 return interrupted; 67 } 68 69 /** 70 * Notifies this PR that it should stop its execution as soon as possible. 71 */ 72 public synchronized void interrupt(){ 73 interrupted = true; 74 } 75 76 protected boolean interrupted = false; 77 78 79 public void setBaseURL(java.net.URL newBaseURL) { 80 baseURL = newBaseURL; 81 } 82 public java.net.URL getBaseURL() { 83 return baseURL; 84 } 85 public synchronized void removeProgressListener(ProgressListener l) { 86 if (progressListeners != null && progressListeners.contains(l)) { 87 Vector v = (Vector) progressListeners.clone(); 88 v.removeElement(l); 89 progressListeners = v; 90 } 91 } 92 public synchronized void addProgressListener(ProgressListener l) { 93 Vector v = progressListeners == null ? new Vector(2) : (Vector) progressListeners.clone(); 94 if (!v.contains(l)) { 95 v.addElement(l); 96 progressListeners = v; 97 } 98 } 99 100 public void setDebugMode(boolean debugMode) { 101 this.debugMode = debugMode; 102 } 103 public boolean isDebugMode() { 104 return debugMode; 105 } 106 107 private boolean debugMode = false; 108 109 110 111 private URL baseURL; 112 113 private transient Vector progressListeners; 114 private transient Vector statusListeners; 115 /** 116 * This property affects the Appelt style of rules application. 117 * If true then the longest match will be fired otherwise the shortest will 118 * be used. By default it is true. 119 */ 120 protected void fireProgressChanged(int e) { 121 if (progressListeners != null || progressListeners.isEmpty()) { 122 Vector listeners = progressListeners; 123 int count = listeners.size(); 124 for (int i = 0; i < count; i++) { 125 ((ProgressListener) listeners.elementAt(i)).progressChanged(e); 126 } 127 } 128 } 129 protected void fireProcessFinished() { 130 if (progressListeners != null) { 131 Vector listeners = progressListeners; 132 int count = listeners.size(); 133 for (int i = 0; i < count; i++) { 134 ((ProgressListener) listeners.elementAt(i)).processFinished(); 135 } 136 } 137 } 138 public synchronized void removeStatusListener(StatusListener l) { 139 if (statusListeners != null && statusListeners.contains(l)) { 140 Vector v = (Vector) statusListeners.clone(); 141 v.removeElement(l); 142 statusListeners = v; 143 } 144 } 145 public synchronized void addStatusListener(StatusListener l) { 146 Vector v = statusListeners == null ? new Vector(2) : (Vector) statusListeners.clone(); 147 if (!v.contains(l)) { 148 v.addElement(l); 149 statusListeners = v; 150 } 151 } 152 protected void fireStatusChanged(String e) { 153 if (statusListeners != null) { 154 Vector listeners = statusListeners; 155 int count = listeners.size(); 156 for (int i = 0; i < count; i++) { 157 ((StatusListener) listeners.elementAt(i)).statusChanged(e); 158 } 159 } 160 } 161 162 //ProcessProgressReporter implementation ends here 163 164 } // class Transducer 165 166 167 168
|
Transducer |
|