Author: tommaso
Date: Thu Mar 11 07:00:31 2010
New Revision: 921708
URL: http://svn.apache.org/viewvc?rev=921708&view=rev
Log:
[CLEREZZA-124] - UIMAExecutor accepts also runtime parameter settings so that
one can specify them either inside the AE descriptor or programmatically
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAExecutor.java
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAExecutor.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAExecutor.java?rev=921708&r1=921707&r2=921708&view=diff
==============================================================================
---
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAExecutor.java
(original)
+++
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAExecutor.java
Thu Mar 11 07:00:31 2010
@@ -6,89 +6,113 @@ import org.apache.uima.analysis_engine.A
import org.apache.uima.jcas.JCas;
import org.apache.uima.resource.ResourceInitializationException;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* Executes a UIMA pipeline
- *
+ *
* @author tommaso
- *
*/
public class UIMAExecutor {
- private transient final AEProvider aeProvider;
+ private transient final AEProvider aeProvider;
- private boolean withResults;
+ private boolean withResults;
- private JCas results;
+ private JCas results;
- @SuppressWarnings("unused")
- private UIMAExecutor() {
- // cannot instantiate without arguments
- aeProvider = null;
- }
+ @SuppressWarnings("unused")
+ private UIMAExecutor() {
+ // cannot instantiate without arguments
+ aeProvider = null;
+ }
- public UIMAExecutor(String xmlDescriptorPath) {
- withResults = false;
- aeProvider = new AEProvider(xmlDescriptorPath);
- }
+ public UIMAExecutor(String xmlDescriptorPath) {
+ withResults = false;
+ aeProvider = new AEProvider(xmlDescriptorPath);
+ }
- public UIMAExecutor withResults() {
- this.withResults = true;
- return this;
- }
+ public UIMAExecutor withResults() {
+ this.withResults = true;
+ return this;
+ }
- /**
- * analyze a text document using with this executor
- *
- * @param doc
- * @throws AnalysisEngineProcessException
- */
- public void analyzeDocument(String doc) throws
AnalysisEngineProcessException {
- analyzeDocument(doc, aeProvider.getDefaultXMLPath());
- }
+ /**
+ * analyze a text document using with this executor
+ *
+ * @param doc
+ * @throws AnalysisEngineProcessException
+ */
+ public void analyzeDocument(String doc) throws
AnalysisEngineProcessException {
+ analyzeDocument(doc, aeProvider.getDefaultXMLPath());
+ }
- /**
- * analyze a text document specifying a different Analysis Engine descriptor
path
- *
- * @param doc
- * @param xmlPath
- * @throws AnalysisEngineProcessException
- */
- public void analyzeDocument(String doc, String xmlPath) throws
AnalysisEngineProcessException {
- try {
- this.executeAE(aeProvider.getAE(xmlPath), doc);
- } catch (ResourceInitializationException e) {
- throw new AnalysisEngineProcessException(e);
+ /**
+ * analyze a text document specifying a different Analysis Engine
descriptor path
+ *
+ * @param doc
+ * @param xmlPath
+ * @throws AnalysisEngineProcessException
+ */
+ public void analyzeDocument(String doc, String xmlPath) throws
AnalysisEngineProcessException {
+ try {
+ this.executeAE(aeProvider.getAE(xmlPath), doc);
+ } catch (ResourceInitializationException e) {
+ throw new AnalysisEngineProcessException(e);
+ }
}
- }
- private void executeAE(AnalysisEngine ae, String docText) throws
AnalysisEngineProcessException {
- try {
- // create a JCas, given an Analysis Engine (ae)
- JCas jcas = ae.newJCas();
-
- // analyze a document
- jcas.setDocumentText(docText);
-
- ae.process(jcas);
-
- if (withResults) {
- setResults(jcas);
- } else
- jcas.reset();
- } catch (Exception e) {
- throw new AnalysisEngineProcessException(e);
+ /**
+ * analyze a text document specifying a different Analysis Engine
descriptor path and specific Analysis Engine parameter settings
+ *
+ * @param doc
+ * @param xmlPath
+ * @param aeParameterSettings
+ * @throws AnalysisEngineProcessException
+ */
+ public void analyzeDocument(String doc, String xmlPath, Map<String,
Object> aeParameterSettings) throws AnalysisEngineProcessException {
+ try {
+ AnalysisEngine engine = aeProvider.getAE(xmlPath);
+ // set runtime parameters
+ for (String parameter : aeParameterSettings.keySet()) {
+ engine.setConfigParameterValue(parameter,
aeParameterSettings.get(parameter));
+ }
+ this.executeAE(engine, doc);
+ } catch (ResourceInitializationException e) {
+ throw new AnalysisEngineProcessException(e);
+ }
}
- }
+ private void executeAE(AnalysisEngine ae, String docText) throws
AnalysisEngineProcessException {
+ try {
+ // create a JCas, given an Analysis Engine (ae)
+ JCas jcas = ae.newJCas();
+
+ // analyze a document
+ jcas.setDocumentText(docText);
+
+ ae.process(jcas);
+
+ if (withResults) {
+ setResults(jcas);
+ } else
+ jcas.reset();
+ } catch (Exception e) {
+ throw new AnalysisEngineProcessException(e);
+ }
- public JCas getResults() {
- if (!withResults)
- throw new ExecutionWithoutResultsException();
- return results;
- }
+ }
+
+
+ public JCas getResults() {
+ if (!withResults)
+ throw new ExecutionWithoutResultsException();
+ return results;
+ }
- private void setResults(JCas jcas) {
- this.results = jcas;
+ private void setResults(JCas jcas) {
+ this.results = jcas;
}