You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by al...@apache.org on 2007/03/19 22:23:48 UTC
svn commit: r520107 - in /incubator/uima/uimaj/trunk/uimaj-core/src:
main/java/org/apache/uima/analysis_engine/impl/
main/java/org/apache/uima/flow/impl/ main/java/org/apache/uima/resource/
main/resources/org/apache/uima/ test/java/org/apache/uima/anal...
Author: alally
Date: Mon Mar 19 14:23:47 2007
New Revision: 520107
URL: http://svn.apache.org/viewvc?view=rev&rev=520107
Log:
make collectionProcessComplete use fixedFlow or capabilityLanguageFlow ordering if specified.
UIMA-348: https://issues.apache.org/jira/browse/UIMA-348
Added:
incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnnotatorForCollectionProcessCompleteTest.java
incubator/uima/uimaj/trunk/uimaj-core/src/test/resources/TextAnalysisEngineImplTest/AggregateForCollectionProcessCompleteTest.xml
incubator/uima/uimaj/trunk/uimaj-core/src/test/resources/TextAnalysisEngineImplTest/AnnotatorForCollectionProcessCompleteTest.xml
Modified:
incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/AggregateAnalysisEngine_impl.java
incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/flow/impl/FixedFlowController.java
incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ResourceInitializationException.java
incubator/uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties
incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/AggregateAnalysisEngine_impl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/AggregateAnalysisEngine_impl.java?view=diff&rev=520107&r1=520106&r2=520107
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/AggregateAnalysisEngine_impl.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/AggregateAnalysisEngine_impl.java Mon Mar 19 14:23:47 2007
@@ -38,6 +38,8 @@
import org.apache.uima.analysis_engine.asb.impl.FlowControllerContainer;
import org.apache.uima.analysis_engine.metadata.AnalysisEngineMetaData;
import org.apache.uima.analysis_engine.metadata.CapabilityLanguageFlow;
+import org.apache.uima.analysis_engine.metadata.FixedFlow;
+import org.apache.uima.analysis_engine.metadata.FlowConstraints;
import org.apache.uima.analysis_engine.metadata.FlowControllerDeclaration;
import org.apache.uima.analysis_engine.metadata.impl.FlowControllerDeclaration_impl;
import org.apache.uima.cas.CAS;
@@ -307,8 +309,30 @@
public void collectionProcessComplete() throws AnalysisEngineProcessException {
enterCollectionProcessComplete();
try {
- // pass call down to components, which might be (or contain) CAS Consumers
- Iterator iter = this._getASB().getComponentAnalysisEngines().values().iterator();
+ // Pass call down to all components.
+ // If there's a standard flow type, use that order, then call components not in flow
+ // at the end in arbitrary order. If there's no standard flow type
+ // (a custom FlowController must be in use), the entire order is arbitrary.
+ String[] orderedNodes = null;
+ Map components = new HashMap(this._getASB().getComponentAnalysisEngines());
+ FlowConstraints flow = getAnalysisEngineMetaData().getFlowConstraints();
+ if (flow != null) {
+ if (flow instanceof FixedFlow) {
+ orderedNodes = ((FixedFlow)flow).getFixedFlow();
+ }
+ else if (flow instanceof CapabilityLanguageFlow) {
+ orderedNodes = ((CapabilityLanguageFlow)flow).getCapabilityLanguageFlow();
+ }
+ }
+ //call components in the order specified in the flow
+ if (orderedNodes != null) {
+ for (int i = 0; i < orderedNodes.length; i++) {
+ AnalysisEngine component = (AnalysisEngine)components.remove(orderedNodes[i]);
+ component.collectionProcessComplete();
+ }
+ }
+ //now call reamining components in arbitrary order
+ Iterator iter = components.values().iterator();
while (iter.hasNext()) {
((AnalysisEngine) iter.next()).collectionProcessComplete();
}
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/flow/impl/FixedFlowController.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/flow/impl/FixedFlowController.java?view=diff&rev=520107&r1=520106&r2=520107
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/flow/impl/FixedFlowController.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/flow/impl/FixedFlowController.java Mon Mar 19 14:23:47 2007
@@ -79,7 +79,13 @@
super.initialize(aContext);
FlowConstraints flowConstraints = aContext.getAggregateMetadata().getFlowConstraints();
mSequence = new ArrayList();
- mSequence.addAll(Arrays.asList(((FixedFlow) flowConstraints).getFixedFlow()));
+ if (flowConstraints instanceof FixedFlow) {
+ String[] sequence = ((FixedFlow) flowConstraints).getFixedFlow();
+ mSequence.addAll(Arrays.asList(sequence));
+ } else {
+ throw new ResourceInitializationException(ResourceInitializationException.FLOW_CONTROLLER_REQUIRES_FLOW_CONSTRAINTS,
+ new Object[]{this.getClass().getName(), "fixedFlow", aContext.getAggregateMetadata().getSourceUrlString()});
+ }
String actionAfterCasMultiplier = (String) aContext
.getConfigParameterValue(PARAM_ACTION_AFTER_CAS_MULTIPLIER);
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ResourceInitializationException.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ResourceInitializationException.java?view=diff&rev=520107&r1=520106&r2=520107
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ResourceInitializationException.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ResourceInitializationException.java Mon Mar 19 14:23:47 2007
@@ -438,6 +438,12 @@
public static final String INVALID_ACTION_AFTER_CAS_MULTIPLIER = "invalid_action_after_cas_multiplier";
/**
+ * Message key for a standard UIMA exception message: The Flow Controller "{0}" requires a flow contraints
+ * element of type "{1}" in the aggregate descriptor
+ */
+ public static final String FLOW_CONTROLLER_REQUIRES_FLOW_CONSTRAINTS = "flow_controller_requires_flow_constraints";
+
+ /**
* Creates a new exception with a null message.
*/
public ResourceInitializationException() {
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties?view=diff&rev=520107&r1=520106&r2=520107
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties Mon Mar 19 14:23:47 2007
@@ -367,6 +367,9 @@
invalid_action_after_cas_multiplier = The value "{0}" is an invalid value for the FixedFlowController's "ActionAfterCasMultiplier" configuration \
parameter. Valid values are "continue", "stop", "drop", and "dropIfNewCasProduced".
+flow_controller_requires_flow_constraints = The Flow Controller "{0}" requires a flow contraints element of type "{1}" in the aggregate descriptor. \
+ (Descriptor: {2}).
+
#---------------------------
#ResourceAccessException
#---------------------------
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java?view=diff&rev=520107&r1=520106&r2=520107
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java Mon Mar 19 14:23:47 2007
@@ -766,11 +766,17 @@
aggDesc.getMetaData().setName("Test Aggregate TAE");
aggDesc.getDelegateAnalysisEngineSpecifiersWithImports().put("Test", primitiveDesc);
FixedFlow_impl flow = new FixedFlow_impl();
- flow.setFixedFlow(new String[] { "Test" });
aggDesc.getAnalysisEngineMetaData().setFlowConstraints(flow);
AggregateAnalysisEngine_impl aggTae = new AggregateAnalysisEngine_impl();
aggTae.initialize(aggDesc, null);
aggTae.collectionProcessComplete(new ProcessTrace_impl());
+
+ //test that fixedFlow order is used
+ File descFile = JUnitExtension.getFile("TextAnalysisEngineImplTest/AggregateForCollectionProcessCompleteTest.xml");
+ AnalysisEngineDescription cpcTestDesc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(new XMLInputSource(descFile));
+ AnalysisEngine cpcTestAe = UIMAFramework.produceAnalysisEngine(cpcTestDesc);
+ cpcTestAe.collectionProcessComplete();
+ assertEquals("One", AnnotatorForCollectionProcessCompleteTest.lastValue);
} catch (Exception e) {
JUnitExtension.handleException(e);
}
Added: incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnnotatorForCollectionProcessCompleteTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnnotatorForCollectionProcessCompleteTest.java?view=auto&rev=520107
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnnotatorForCollectionProcessCompleteTest.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnnotatorForCollectionProcessCompleteTest.java Mon Mar 19 14:23:47 2007
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.uima.analysis_engine.impl;
+
+import org.apache.uima.UimaContext;
+import org.apache.uima.analysis_component.CasAnnotator_ImplBase;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.resource.ResourceInitializationException;
+
+/**
+ * Testing that collectionProcessComplete is correctly propogated to annotators.
+ */
+public class AnnotatorForCollectionProcessCompleteTest extends CasAnnotator_ImplBase {
+
+ public static volatile String lastValue;
+
+ private String testValue;
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.analysis_component.AnalysisComponent_ImplBase#initialize(org.apache.uima.UimaContext)
+ */
+ public void initialize(UimaContext aContext) throws ResourceInitializationException {
+ super.initialize(aContext);
+ testValue = (String)aContext.getConfigParameterValue("TestValue");
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.analysis_component.CasAnnotator_ImplBase#process(org.apache.uima.cas.CAS)
+ */
+ public void process(CAS aCAS) throws AnalysisEngineProcessException {
+ //does nothing
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.analysis_component.AnalysisComponent_ImplBase#collectionProcessComplete()
+ */
+ public void collectionProcessComplete() throws AnalysisEngineProcessException {
+ lastValue = testValue;
+ }
+
+
+
+}
Added: incubator/uima/uimaj/trunk/uimaj-core/src/test/resources/TextAnalysisEngineImplTest/AggregateForCollectionProcessCompleteTest.xml
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/test/resources/TextAnalysisEngineImplTest/AggregateForCollectionProcessCompleteTest.xml?view=auto&rev=520107
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/test/resources/TextAnalysisEngineImplTest/AggregateForCollectionProcessCompleteTest.xml (added)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/test/resources/TextAnalysisEngineImplTest/AggregateForCollectionProcessCompleteTest.xml Mon Mar 19 14:23:47 2007
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+-->
+
+<!-- Aggregate descriptor for testing merging of type system, type priorities, and indexes. -->
+
+<taeDescription xmlns="http://uima.apache.org/resourceSpecifier">
+ <frameworkImplementation>org.apache.uima.java</frameworkImplementation>
+ <primitive>false</primitive>
+
+ <delegateAnalysisEngineSpecifiers>
+ <delegateAnalysisEngine key="a1">
+ <import location="AnnotatorForCollectionProcessCompleteTest.xml"/>
+ </delegateAnalysisEngine>
+ <delegateAnalysisEngine key="a2">
+ <import location="AnnotatorForCollectionProcessCompleteTest.xml"/>
+ </delegateAnalysisEngine>
+ <delegateAnalysisEngine key="a3">
+ <import location="AnnotatorForCollectionProcessCompleteTest.xml"/>
+ </delegateAnalysisEngine>
+ </delegateAnalysisEngineSpecifiers>
+
+ <analysisEngineMetaData>
+ <name>Aggregate for Collection Process Complete Test</name>
+ <description>For testing onlyr.</description>
+ <version>1.0</version>
+ <vendor>The Apache Software Foundation</vendor>
+
+ <configurationParameters>
+ <configurationParameter>
+ <name>FirstTestValue</name>
+ <description/>
+ <type>String</type>
+ <overrides>
+ <parameter>a1/TestValue</parameter>
+ </overrides>
+ </configurationParameter>
+ <configurationParameter>
+ <name>SecondTestValue</name>
+ <description/>
+ <type>String</type>
+ <overrides>
+ <parameter>a2/TestValue</parameter>
+ </overrides>
+ </configurationParameter>
+ <configurationParameter>
+ <name>ThirdTestValue</name>
+ <description/>
+ <type>String</type>
+ <overrides>
+ <parameter>a3/TestValue</parameter>
+ </overrides>
+ </configurationParameter>
+ </configurationParameters>
+
+ <configurationParameterSettings>
+ <nameValuePair>
+ <name>FirstTestValue</name>
+ <value><string>One</string></value>
+ </nameValuePair>
+ <nameValuePair>
+ <name>SecondTestValue</name>
+ <value><string>Two</string></value>
+ </nameValuePair>
+ <nameValuePair>
+ <name>ThirdTestValue</name>
+ <value><string>Three</string></value>
+ </nameValuePair>
+ </configurationParameterSettings>
+
+ <flowConstraints>
+ <fixedFlow>
+ <node>a3</node>
+ <node>a2</node>
+ <node>a1</node>
+ </fixedFlow>
+ </flowConstraints>
+
+ <!-- Capabilities: Inputs and Outputs -->
+ <capabilities>
+ <capability>
+ <inputs/>
+ <outputs/>
+ <languagesSupported/>
+ </capability>
+ </capabilities>
+
+ </analysisEngineMetaData>
+</taeDescription>
\ No newline at end of file
Added: incubator/uima/uimaj/trunk/uimaj-core/src/test/resources/TextAnalysisEngineImplTest/AnnotatorForCollectionProcessCompleteTest.xml
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/test/resources/TextAnalysisEngineImplTest/AnnotatorForCollectionProcessCompleteTest.xml?view=auto&rev=520107
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/test/resources/TextAnalysisEngineImplTest/AnnotatorForCollectionProcessCompleteTest.xml (added)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/test/resources/TextAnalysisEngineImplTest/AnnotatorForCollectionProcessCompleteTest.xml Mon Mar 19 14:23:47 2007
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ -->
+
+<!-- For testing only. -->
+
+<taeDescription xmlns="http://uima.apache.org/resourceSpecifier">
+<frameworkImplementation>org.apache.uima.java</frameworkImplementation>
+<primitive>true</primitive>
+<annotatorImplementationName>org.apache.uima.analysis_engine.impl.AnnotatorForCollectionProcessCompleteTest</annotatorImplementationName>
+
+<analysisEngineMetaData>
+<name>Annotator for Collection Process Complete Test</name>
+<description>For testing only.</description>
+<version>1.0</version>
+<vendor>The Apache Software Foundation</vendor>
+
+<configurationParameters>
+ <configurationParameter>
+ <name>TestValue</name>
+ <description/>
+ <type>String</type>
+ </configurationParameter>
+</configurationParameters>
+
+<!-- Capabilities: Inputs and Outputs -->
+<capabilities>
+<capability>
+<outputs/>
+<languagesSupported>
+<language>en</language>
+</languagesSupported>
+</capability>
+</capabilities>
+
+</analysisEngineMetaData>
+</taeDescription>