You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2017/05/10 09:06:02 UTC
svn commit: r1794692 - in /uima/ruta/trunk/ruta-core/src:
main/java/org/apache/uima/ruta/engine/ test/java/org/apache/uima/ruta/engine/
test/resources/org/apache/uima/ruta/engine/
Author: pkluegl
Date: Wed May 10 09:06:02 2017
New Revision: 1794692
URL: http://svn.apache.org/viewvc?rev=1794692&view=rev
Log:
UIMA-5423 - reset also imported scripts of imported scripts
Added:
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ThreeStackedScriptsVariableResetTest.java (with props)
uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script1.ruta
uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script1TypeSystem.xml (with props)
uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script2.ruta
uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script2TypeSystem.xml (with props)
uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script3.ruta
uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script3TypeSystem.xml (with props)
Modified:
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java?rev=1794692&r1=1794691&r2=1794692&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java Wed May 10 09:06:02 2017
@@ -28,6 +28,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -625,20 +626,29 @@ public class RutaEngine extends JCasAnno
}
private void resetEnvironments(CAS cas) {
- resetEnvironment(script, cas);
- Collection<RutaModule> scripts = script.getScripts().values();
- for (RutaModule module : scripts) {
- resetEnvironment(module, cas);
- }
+ resetEnvironment(script, cas, new HashSet<RutaModule>());
}
- private void resetEnvironment(RutaModule module, CAS cas) {
+ private void resetEnvironment(RutaModule module, CAS cas, Collection<RutaModule> alreadyResetted) {
+ if(alreadyResetted.contains(module)) {
+ // avoid loop in recursion
+ return;
+ }
+ alreadyResetted.add(module);
+
+ // reset all blocks
RutaBlock block = module.getBlock(null);
block.getEnvironment().reset(cas);
Collection<RutaBlock> blocks = module.getBlocks().values();
for (RutaBlock each : blocks) {
each.getEnvironment().reset(cas);
}
+
+ // reset imported scripts
+ Collection<RutaModule> scripts = module.getScripts().values();
+ for (RutaModule eachModule : scripts) {
+ resetEnvironment(eachModule, cas, alreadyResetted);
+ }
}
private void initializeTypes(RutaModule script, CAS cas, List<String> initialized) {
Added: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ThreeStackedScriptsVariableResetTest.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ThreeStackedScriptsVariableResetTest.java?rev=1794692&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ThreeStackedScriptsVariableResetTest.java (added)
+++ uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ThreeStackedScriptsVariableResetTest.java Wed May 10 09:06:02 2017
@@ -0,0 +1,85 @@
+/*
+ * 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.ruta.engine;
+
+import java.io.File;
+import java.nio.file.Paths;
+
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Feature;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.Type;
+import org.apache.uima.fit.factory.JCasFactory;
+import org.apache.uima.fit.util.CasUtil;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.resource.metadata.TypeSystemDescription;
+import org.apache.uima.ruta.descriptor.RutaBuildOptions;
+import org.apache.uima.ruta.descriptor.RutaDescriptorFactory;
+import org.apache.uima.ruta.descriptor.RutaDescriptorInformation;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ThreeStackedScriptsVariableResetTest {
+
+ @Test
+ public void test() throws Exception {
+ String input1 = "snark";
+ String input2 = "cat";
+ String input3 = "bug";
+
+ String path = "src/test/resources/org/apache/uima/ruta/engine/";
+ RutaDescriptorFactory factory = new RutaDescriptorFactory();
+ RutaBuildOptions options = new RutaBuildOptions();
+ RutaDescriptorInformation rdi = factory
+ .parseDescriptorInformation(new File(path + "script1.ruta"), options);
+ Pair<AnalysisEngineDescription, TypeSystemDescription> descriptions = factory.createDescriptions(null, Paths.get(path).toFile().getAbsolutePath(), rdi, options, new String[] { path }, new String[] { path }, null);
+
+ AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(descriptions.getKey());
+ JCas jcas = JCasFactory.createJCas(descriptions.getValue());
+
+ jcas.setDocumentText(input1);
+ ae.process(jcas);
+ checkFeatureValue(jcas);
+
+ jcas.reset();
+ jcas.setDocumentText(input2);
+ ae.process(jcas);
+ checkFeatureValue(jcas);
+
+ jcas.reset();
+ jcas.setDocumentText(input3);
+ ae.process(jcas);
+ checkFeatureValue(jcas);
+
+ }
+
+ private void checkFeatureValue(JCas jcas) {
+ CAS cas = jcas.getCas();
+ Type type = cas.getTypeSystem().getType("script3.Value");
+ Feature feature = type.getFeatureByBaseName("value");
+ FeatureStructure fs = CasUtil.selectSingle(cas, type);
+ String stringValue = fs.getStringValue(feature);
+ Assert.assertEquals("", stringValue);
+ }
+
+}
Propchange: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ThreeStackedScriptsVariableResetTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script1.ruta
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script1.ruta?rev=1794692&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script1.ruta (added)
+++ uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script1.ruta Wed May 10 09:06:02 2017
@@ -0,0 +1,3 @@
+SCRIPT script2;
+
+Document{->CALL(script2)};
Added: uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script1TypeSystem.xml
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script1TypeSystem.xml?rev=1794692&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script1TypeSystem.xml (added)
+++ uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script1TypeSystem.xml Wed May 10 09:06:02 2017
@@ -0,0 +1,30 @@
+<?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.
+-->
+
+<typeSystemDescription xmlns="http://uima.apache.org/resourceSpecifier">
+ <name>script1TypeSystem</name>
+ <imports>
+ <import name="org.apache.uima.ruta.engine.BasicTypeSystem"/>
+ <import location="script2TypeSystem.xml"/>
+ </imports>
+ <types>
+ </types>
+</typeSystemDescription>
Propchange: uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script1TypeSystem.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script2.ruta
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script2.ruta?rev=1794692&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script2.ruta (added)
+++ uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script2.ruta Wed May 10 09:06:02 2017
@@ -0,0 +1,3 @@
+SCRIPT script3;
+
+Document{->CALL(script3)};
Added: uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script2TypeSystem.xml
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script2TypeSystem.xml?rev=1794692&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script2TypeSystem.xml (added)
+++ uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script2TypeSystem.xml Wed May 10 09:06:02 2017
@@ -0,0 +1,30 @@
+<?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.
+-->
+
+<typeSystemDescription xmlns="http://uima.apache.org/resourceSpecifier">
+ <name>script2TypeSystem</name>
+ <imports>
+ <import name="org.apache.uima.ruta.engine.BasicTypeSystem"/>
+ <import location="script3TypeSystem.xml"/>
+ </imports>
+ <types>
+ </types>
+</typeSystemDescription>
Propchange: uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script2TypeSystem.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script3.ruta
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script3.ruta?rev=1794692&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script3.ruta (added)
+++ uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script3.ruta Wed May 10 09:06:02 2017
@@ -0,0 +1,5 @@
+DECLARE Value(STRING value);
+
+STRING value; // or = "dog";
+
+W{-> CREATE(Value, "value" = value), ASSIGN(value, W.ct)};
Added: uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script3TypeSystem.xml
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script3TypeSystem.xml?rev=1794692&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script3TypeSystem.xml (added)
+++ uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script3TypeSystem.xml Wed May 10 09:06:02 2017
@@ -0,0 +1,41 @@
+<?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.
+-->
+
+<typeSystemDescription xmlns="http://uima.apache.org/resourceSpecifier">
+ <name>script2TypeSystem</name>
+ <imports>
+ <import name="org.apache.uima.ruta.engine.BasicTypeSystem"/>
+ </imports>
+ <types>
+ <typeDescription>
+ <name>script3.Value</name>
+ <description/>
+ <supertypeName>uima.tcas.Annotation</supertypeName>
+ <features>
+ <featureDescription>
+ <name>value</name>
+ <description/>
+ <rangeTypeName>uima.cas.String</rangeTypeName>
+ </featureDescription>
+ </features>
+ </typeDescription>
+ </types>
+</typeSystemDescription>
Propchange: uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/engine/script3TypeSystem.xml
------------------------------------------------------------------------------
svn:eol-style = native