01 /*
02 * LanguageAnalyserDocumentProcessor.java
03 * Copyright (c) 1995-2010, The University of Sheffield. See the file
04 * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
05 *
06 * This file is part of GATE (see http://gate.ac.uk/), and is free
07 * software, licenced under the GNU Library General Public License,
08 * Version 2, June 1991 (in the distribution as file licence.html,
09 * and also available at http://gate.ac.uk/gate/licence.html).
10 *
11 * Ian Roberts, 03/Sep/2009
12 *
13 * $Id: LanguageAnalyserDocumentProcessor.java 12495 2010-04-15 16:08:40Z ian_roberts $
14 */
15
16 package gate.util;
17
18 import gate.Corpus;
19 import gate.LanguageAnalyser;
20 import gate.Document;
21 import gate.Factory;
22
23 /**
24 * {@link DocumentProcessor} that processes documents using a
25 * {@link LanguageAnalyser}.
26 */
27 public class LanguageAnalyserDocumentProcessor implements DocumentProcessor {
28
29 /**
30 * The analyser used to process documents.
31 */
32 private LanguageAnalyser analyser;
33
34 /**
35 * Corpus used to contain the document being processed.
36 */
37 private Corpus corpus;
38
39 public LanguageAnalyserDocumentProcessor() {
40 }
41
42 /**
43 * Set the controller used to process documents.
44 */
45 public void setAnalyser(LanguageAnalyser a) {
46 this.analyser = a;
47 }
48
49 public synchronized void processDocument(Document doc) throws GateException {
50 if(corpus == null) {
51 corpus = Factory.newCorpus("DocumentProcessor corpus");
52 }
53 try {
54 corpus.add(doc);
55 analyser.setCorpus(corpus);
56 analyser.setDocument(doc);
57 analyser.execute();
58 }
59 finally {
60 analyser.setCorpus(null);
61 analyser.setDocument(null);
62 corpus.clear();
63 }
64 }
65
66 /**
67 * Clean up resources. Should be called when this processor is no longer
68 * required.
69 */
70 public synchronized void cleanup() {
71 Factory.deleteResource(analyser);
72 if(corpus != null) {
73 Factory.deleteResource(corpus);
74 }
75 }
76 }
|