You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2008/08/29 23:43:31 UTC
svn commit: r690399 [1/2] - in
/incubator/uima/uimaj/trunk/uimaj-component-test-util: ./
src/main/java/org/apache/uima/test/junit_extension/ src/main/resources/
Author: schor
Date: Fri Aug 29 14:43:30 2008
New Revision: 690399
URL: http://svn.apache.org/viewvc?rev=690399&view=rev
Log:
[UIMA-1163] set native eol-style
Modified:
incubator/uima/uimaj/trunk/uimaj-component-test-util/pom.xml (contents, props changed)
incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotationWriter.java (contents, props changed)
incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotatorPerformanceTester.java (contents, props changed)
incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotatorTester.java (contents, props changed)
incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/PerformanceTestResult.java (contents, props changed)
incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/PerformanceTestResultImpl.java (contents, props changed)
incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/resources/AnnotationWriter.xml (contents, props changed)
Modified: incubator/uima/uimaj/trunk/uimaj-component-test-util/pom.xml
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-component-test-util/pom.xml?rev=690399&r1=690398&r2=690399&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-component-test-util/pom.xml (original)
+++ incubator/uima/uimaj/trunk/uimaj-component-test-util/pom.xml Fri Aug 29 14:43:30 2008
@@ -1,65 +1,65 @@
-<!--
- 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.
--->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.apache.uima</groupId>
- <artifactId>uimaj-component-test-util</artifactId>
- <packaging>jar</packaging>
- <version>${uimaj-release-version}</version>
- <name>Apache UIMA Utility Classes For Component JUnit Tests</name>
- <url>http://incubator.apache.org/uima</url>
- <licenses>
- <license>
- <name>The Apache Software License, Version 2.0</name>
- <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
- <distribution>repo</distribution>
- </license>
- </licenses>
- <scm>
- <url>http://svn.apache.org/viewvc/incubator/uima</url>
- </scm>
- <parent>
- <groupId>org.apache.uima</groupId>
- <artifactId>uimaj</artifactId>
- <version>2.3.0-incubating-SNAPSHOT</version> <!-- this comment is a flag for changeVersion -->
- </parent>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.uima</groupId>
- <artifactId>uimaj-core</artifactId>
- <version>${uimaj-release-version}</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.uima</groupId>
- <artifactId>uimaj-test-util</artifactId>
- <version>${uimaj-release-version}</version>
- <scope>compile</scope>
- </dependency>
- </dependencies>
+<!--
+ 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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.uima</groupId>
+ <artifactId>uimaj-component-test-util</artifactId>
+ <packaging>jar</packaging>
+ <version>${uimaj-release-version}</version>
+ <name>Apache UIMA Utility Classes For Component JUnit Tests</name>
+ <url>http://incubator.apache.org/uima</url>
+ <licenses>
+ <license>
+ <name>The Apache Software License, Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+ <scm>
+ <url>http://svn.apache.org/viewvc/incubator/uima</url>
+ </scm>
+ <parent>
+ <groupId>org.apache.uima</groupId>
+ <artifactId>uimaj</artifactId>
+ <version>2.3.0-incubating-SNAPSHOT</version> <!-- this comment is a flag for changeVersion -->
+ </parent>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.uima</groupId>
+ <artifactId>uimaj-core</artifactId>
+ <version>${uimaj-release-version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.uima</groupId>
+ <artifactId>uimaj-test-util</artifactId>
+ <version>${uimaj-release-version}</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
</project>
\ No newline at end of file
Propchange: incubator/uima/uimaj/trunk/uimaj-component-test-util/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotationWriter.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotationWriter.java?rev=690399&r1=690398&r2=690399&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotationWriter.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotationWriter.java Fri Aug 29 14:43:30 2008
@@ -1,372 +1,372 @@
-/*
- * 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.test.junit_extension;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Iterator;
-
-import org.apache.uima.cas.CAS;
-import org.apache.uima.cas.FSIterator;
-import org.apache.uima.cas.Feature;
-import org.apache.uima.cas.FeatureStructure;
-import org.apache.uima.cas.Type;
-import org.apache.uima.cas.impl.LowLevelCAS;
-import org.apache.uima.cas.impl.LowLevelTypeSystem;
-import org.apache.uima.cas.text.AnnotationFS;
-import org.apache.uima.collection.CasConsumer;
-import org.apache.uima.collection.CasConsumer_ImplBase;
-import org.apache.uima.resource.ResourceConfigurationException;
-import org.apache.uima.resource.ResourceInitializationException;
-import org.apache.uima.resource.ResourceProcessException;
-import org.apache.uima.util.ProcessTrace;
-
-/**
- * The AnnotationWriter class writes specified annotations to an output file.
- * The encoding of the output file is UTF-8
- */
-
-public class AnnotationWriter extends CasConsumer_ImplBase implements CasConsumer
-{
- //output file
- private File outFile;
- //output file writer
- private OutputStreamWriter fileWriter;
- //respected annotations
- private String[] tofs;
- //check if reconfigure must be called
- private boolean reconfig = false;
-
- private final static String featureOnlyKey = "feature";
-
- /**
- * Initializes this CAS Consumer with the parameters specified in the
- * descriptor.
- *
- * @throws ResourceInitializationException if there is error in
- * initializing the resources
- */
- public void initialize() throws ResourceInitializationException
- {
-
- // extract configuration parameter settings
- String oPath = (String) getUimaContext().getConfigParameterValue("outputFile");
-
- //Output file should be specified in the descriptor
- if (oPath == null)
- {
- //set reconfiguration - reconfig() must be called
- this.reconfig = true;
- }
- else
- {
- // If specified output directory does not exist, try to create it
- this.outFile = new File(oPath);
- if (this.outFile.getParentFile() != null && !this.outFile.getParentFile().exists())
- {
- if (!this.outFile.getParentFile().mkdirs())
- throw new ResourceInitializationException(
- ResourceInitializationException.RESOURCE_DATA_NOT_VALID,
- new Object[] { oPath, "outputFile" });
- }
- try
- {
- this.fileWriter = new OutputStreamWriter(new FileOutputStream(this.outFile, false), "UTF-8");
- }
- catch (IOException e)
- {
- throw new ResourceInitializationException(e);
- }
- }
-
- //extract annotation types
- this.tofs = (String[]) getUimaContext().getConfigParameterValue("AnnotationTypes");
- //sort array
- if (this.tofs != null)
- Arrays.sort(this.tofs);
-
- }
-
- /**
- * processTofs() writes als specified types an features to a HashMap.
- *
- * @param aCAS a CAS with a TypeSystem
- * @param tofs respected tofs
- * @return HashMap - Map with all types an features.
- */
- private HashMap processTofs(CAS aCAS, String[] someTofs)
- {
- HashMap types = new HashMap(10);
-
- for (int i = 0; i < someTofs.length; i++)
- {
- Type type = aCAS.getTypeSystem().getType(someTofs[i]);
-
- if (type == null) //maybe a feature
- {
- int index = someTofs[i].indexOf(":");
-
- if (index != -1)
- {
- String typename = someTofs[i].substring(0, index);
- Type typeKey = aCAS.getTypeSystem().getType(typename);
-
- //get feature object (Vector) for the current type
- Object obj = types.get(typeKey);
-
- //if type is not included in the typelist create type and add feature
- if (obj == null)
- {
- ArrayList list = new ArrayList(10);
- Feature fs = aCAS.getTypeSystem().getFeatureByFullName(someTofs[i]);
- list.add(0, featureOnlyKey);
- list.add(fs);
- types.put(typeKey, list);
- }
- else //add feature to type
- {
- //cast feature vector for the current type
- ArrayList vec = (ArrayList) obj;
- Feature fs = aCAS.getTypeSystem().getFeatureByFullName(someTofs[i]);
- vec.add(fs);
- }
-
- }
- }
- else
- {
- //add type as key and a Vector as Feature container
- if(types.containsKey(type)){
- ArrayList featureList = (ArrayList) types.get(type);
- if(featureList.size() >0 && featureList.get(0).equals(featureOnlyKey)){
- featureList.remove(0);
- }
- // type is already in the list do not overwrite it!
- }else{
- types.put(type, new ArrayList(10));
- }
- }
- }
-
- return types;
- }
-
- public synchronized void processCas(CAS aCAS) throws ResourceProcessException
- {
- if (this.reconfig == true)
- {
- throw new ResourceProcessException(
- ResourceInitializationException.CONFIG_SETTING_ABSENT,
- new Object[] { "outputFile" });
- }
-
- //get low level CAS
- LowLevelCAS ll_cas = aCAS.getLowLevelCAS();
-
- //get low level TypeSystem
- LowLevelTypeSystem ll_typeSystem = ll_cas.ll_getTypeSystem();
-
- //get types and feature interessted in
- HashMap types = processTofs(aCAS, this.tofs);
-
- try
- {
- //iterate and print annotations
- FSIterator typeIterator = aCAS.getAnnotationIndex().iterator();
-
- for (typeIterator.moveToFirst(); typeIterator.isValid(); typeIterator.moveToNext())
- {
- Iterator it = types.keySet().iterator();
-
- while (it.hasNext())
- {
- //get current type and features
- Type currentType = (Type) it.next();
- boolean isFeatureOnly = false;
-
- ArrayList featureList = (ArrayList) types.get(currentType);
- if(featureList.size() >0 && featureList.get(0).equals(featureOnlyKey)){
- featureList.remove(0);
- isFeatureOnly = true;
- }
- Feature[] features = (Feature[]) featureList.toArray(new Feature[] {
- });
-
- AnnotationFS annot = (AnnotationFS) typeIterator.get();
-
- if (annot.getType().getName() == currentType.getName())
- {
- //only for formatting necessary
- boolean firstFeature = true;
-
- String span = annot.getCoveredText();
- if(!isFeatureOnly){
- this.fileWriter.write(
- annot.getType().getShortName()
- + "(" + annot.getBegin() + "," + annot.getEnd() + "): " + span);
- }else{
- this.fileWriter.write(
- annot.getType().getShortName()
- + ": ");
- }
-
- for (int f = 0; f < features.length; f++)
- {
- if (firstFeature)
- {
- this.fileWriter.write(" { ");
- firstFeature = false;
- }
- else
- {
- this.fileWriter.write(", ");
- }
-
- Feature fs = features[f];
- int typeClass = ll_cas.ll_getTypeClass(ll_typeSystem.ll_getCodeForType(fs.getRange()));
- this.fileWriter.write(fs.getShortName() + "=");
-
- switch (typeClass)
- {
- case LowLevelCAS.TYPE_CLASS_FLOAT :
- this.fileWriter.write(Float.toString(annot.getFloatValue(fs)));
- break;
-
- case LowLevelCAS.TYPE_CLASS_INT :
- this.fileWriter.write(Integer.toString(annot.getIntValue(fs)));
- break;
-
- case LowLevelCAS.TYPE_CLASS_STRING :
- String value = annot.getStringValue(fs);
- if(value != null) {
- this.fileWriter.write(value);
- } else {
- this.fileWriter.write("null");
- }
- break;
-
- case LowLevelCAS.TYPE_CLASS_FS:
-
- FeatureStructure fStruct = annot.getFeatureValue(fs);
- if(fStruct != null) {
- this.fileWriter.write(fStruct.toString());
- } else {
- this.fileWriter.write("null");
- }
- break;
- }
- }
-
- if (firstFeature == false)
- {
- this.fileWriter.write(" }");
- }
-
- this.fileWriter.write(System.getProperty("line.separator"));
- }
-
- }
- }
-
- this.fileWriter.flush();
- }
- catch (Exception ex)
- {
- throw new ResourceProcessException(ex);
- }
-
- }
-
- public void batchProcessComplete(ProcessTrace aTrace) throws ResourceProcessException, IOException
- {
- // nothing to do here
- }
-
- public void collectionProcessComplete(ProcessTrace aTrace) throws ResourceProcessException, IOException
- {
- if (this.fileWriter != null)
- {
- this.fileWriter.close();
- }
- }
-
- public void reconfigure() throws ResourceConfigurationException
- {
- //reset reconfiguration - is done
- this.reconfig = false;
-
- super.reconfigure();
- // extract configuration parameter settings
- String oPath = (String) getUimaContext().getConfigParameterValue("outputFile");
- File oFile = new File(oPath);
- //if output file has changed, close exiting file and open new
- if (!oFile.equals(this.outFile))
- {
- this.outFile = oFile;
- try
- {
- if (this.fileWriter != null)
- this.fileWriter.close();
-
- // If specified output directory does not exist, try to create it
- if (oFile.getParentFile() != null && !oFile.getParentFile().exists())
- {
- if (!oFile.getParentFile().mkdirs())
- throw new ResourceConfigurationException(
- ResourceInitializationException.RESOURCE_DATA_NOT_VALID,
- new Object[] { oPath, "outputFile" });
- }
- //write result specification to the output file
- this.fileWriter = new OutputStreamWriter(new FileOutputStream(oFile, false), "UTF-8");
- }
- catch (IOException e)
- {
- throw new ResourceConfigurationException();
- }
- }
-
- //extract annotation types
- this.tofs = (String[]) getUimaContext().getConfigParameterValue("AnnotationTypes");
- //sort array
- if (this.tofs != null)
- Arrays.sort(this.tofs);
-
- }
-
- public void destroy()
- {
- if (this.fileWriter != null)
- {
- try
- {
- this.fileWriter.close();
- }
- catch (IOException e)
- {
- // ignore IOException on destroy
- }
- }
- }
-
-}
+/*
+ * 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.test.junit_extension;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Feature;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.impl.LowLevelCAS;
+import org.apache.uima.cas.impl.LowLevelTypeSystem;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.collection.CasConsumer;
+import org.apache.uima.collection.CasConsumer_ImplBase;
+import org.apache.uima.resource.ResourceConfigurationException;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.ResourceProcessException;
+import org.apache.uima.util.ProcessTrace;
+
+/**
+ * The AnnotationWriter class writes specified annotations to an output file.
+ * The encoding of the output file is UTF-8
+ */
+
+public class AnnotationWriter extends CasConsumer_ImplBase implements CasConsumer
+{
+ //output file
+ private File outFile;
+ //output file writer
+ private OutputStreamWriter fileWriter;
+ //respected annotations
+ private String[] tofs;
+ //check if reconfigure must be called
+ private boolean reconfig = false;
+
+ private final static String featureOnlyKey = "feature";
+
+ /**
+ * Initializes this CAS Consumer with the parameters specified in the
+ * descriptor.
+ *
+ * @throws ResourceInitializationException if there is error in
+ * initializing the resources
+ */
+ public void initialize() throws ResourceInitializationException
+ {
+
+ // extract configuration parameter settings
+ String oPath = (String) getUimaContext().getConfigParameterValue("outputFile");
+
+ //Output file should be specified in the descriptor
+ if (oPath == null)
+ {
+ //set reconfiguration - reconfig() must be called
+ this.reconfig = true;
+ }
+ else
+ {
+ // If specified output directory does not exist, try to create it
+ this.outFile = new File(oPath);
+ if (this.outFile.getParentFile() != null && !this.outFile.getParentFile().exists())
+ {
+ if (!this.outFile.getParentFile().mkdirs())
+ throw new ResourceInitializationException(
+ ResourceInitializationException.RESOURCE_DATA_NOT_VALID,
+ new Object[] { oPath, "outputFile" });
+ }
+ try
+ {
+ this.fileWriter = new OutputStreamWriter(new FileOutputStream(this.outFile, false), "UTF-8");
+ }
+ catch (IOException e)
+ {
+ throw new ResourceInitializationException(e);
+ }
+ }
+
+ //extract annotation types
+ this.tofs = (String[]) getUimaContext().getConfigParameterValue("AnnotationTypes");
+ //sort array
+ if (this.tofs != null)
+ Arrays.sort(this.tofs);
+
+ }
+
+ /**
+ * processTofs() writes als specified types an features to a HashMap.
+ *
+ * @param aCAS a CAS with a TypeSystem
+ * @param tofs respected tofs
+ * @return HashMap - Map with all types an features.
+ */
+ private HashMap processTofs(CAS aCAS, String[] someTofs)
+ {
+ HashMap types = new HashMap(10);
+
+ for (int i = 0; i < someTofs.length; i++)
+ {
+ Type type = aCAS.getTypeSystem().getType(someTofs[i]);
+
+ if (type == null) //maybe a feature
+ {
+ int index = someTofs[i].indexOf(":");
+
+ if (index != -1)
+ {
+ String typename = someTofs[i].substring(0, index);
+ Type typeKey = aCAS.getTypeSystem().getType(typename);
+
+ //get feature object (Vector) for the current type
+ Object obj = types.get(typeKey);
+
+ //if type is not included in the typelist create type and add feature
+ if (obj == null)
+ {
+ ArrayList list = new ArrayList(10);
+ Feature fs = aCAS.getTypeSystem().getFeatureByFullName(someTofs[i]);
+ list.add(0, featureOnlyKey);
+ list.add(fs);
+ types.put(typeKey, list);
+ }
+ else //add feature to type
+ {
+ //cast feature vector for the current type
+ ArrayList vec = (ArrayList) obj;
+ Feature fs = aCAS.getTypeSystem().getFeatureByFullName(someTofs[i]);
+ vec.add(fs);
+ }
+
+ }
+ }
+ else
+ {
+ //add type as key and a Vector as Feature container
+ if(types.containsKey(type)){
+ ArrayList featureList = (ArrayList) types.get(type);
+ if(featureList.size() >0 && featureList.get(0).equals(featureOnlyKey)){
+ featureList.remove(0);
+ }
+ // type is already in the list do not overwrite it!
+ }else{
+ types.put(type, new ArrayList(10));
+ }
+ }
+ }
+
+ return types;
+ }
+
+ public synchronized void processCas(CAS aCAS) throws ResourceProcessException
+ {
+ if (this.reconfig == true)
+ {
+ throw new ResourceProcessException(
+ ResourceInitializationException.CONFIG_SETTING_ABSENT,
+ new Object[] { "outputFile" });
+ }
+
+ //get low level CAS
+ LowLevelCAS ll_cas = aCAS.getLowLevelCAS();
+
+ //get low level TypeSystem
+ LowLevelTypeSystem ll_typeSystem = ll_cas.ll_getTypeSystem();
+
+ //get types and feature interessted in
+ HashMap types = processTofs(aCAS, this.tofs);
+
+ try
+ {
+ //iterate and print annotations
+ FSIterator typeIterator = aCAS.getAnnotationIndex().iterator();
+
+ for (typeIterator.moveToFirst(); typeIterator.isValid(); typeIterator.moveToNext())
+ {
+ Iterator it = types.keySet().iterator();
+
+ while (it.hasNext())
+ {
+ //get current type and features
+ Type currentType = (Type) it.next();
+ boolean isFeatureOnly = false;
+
+ ArrayList featureList = (ArrayList) types.get(currentType);
+ if(featureList.size() >0 && featureList.get(0).equals(featureOnlyKey)){
+ featureList.remove(0);
+ isFeatureOnly = true;
+ }
+ Feature[] features = (Feature[]) featureList.toArray(new Feature[] {
+ });
+
+ AnnotationFS annot = (AnnotationFS) typeIterator.get();
+
+ if (annot.getType().getName() == currentType.getName())
+ {
+ //only for formatting necessary
+ boolean firstFeature = true;
+
+ String span = annot.getCoveredText();
+ if(!isFeatureOnly){
+ this.fileWriter.write(
+ annot.getType().getShortName()
+ + "(" + annot.getBegin() + "," + annot.getEnd() + "): " + span);
+ }else{
+ this.fileWriter.write(
+ annot.getType().getShortName()
+ + ": ");
+ }
+
+ for (int f = 0; f < features.length; f++)
+ {
+ if (firstFeature)
+ {
+ this.fileWriter.write(" { ");
+ firstFeature = false;
+ }
+ else
+ {
+ this.fileWriter.write(", ");
+ }
+
+ Feature fs = features[f];
+ int typeClass = ll_cas.ll_getTypeClass(ll_typeSystem.ll_getCodeForType(fs.getRange()));
+ this.fileWriter.write(fs.getShortName() + "=");
+
+ switch (typeClass)
+ {
+ case LowLevelCAS.TYPE_CLASS_FLOAT :
+ this.fileWriter.write(Float.toString(annot.getFloatValue(fs)));
+ break;
+
+ case LowLevelCAS.TYPE_CLASS_INT :
+ this.fileWriter.write(Integer.toString(annot.getIntValue(fs)));
+ break;
+
+ case LowLevelCAS.TYPE_CLASS_STRING :
+ String value = annot.getStringValue(fs);
+ if(value != null) {
+ this.fileWriter.write(value);
+ } else {
+ this.fileWriter.write("null");
+ }
+ break;
+
+ case LowLevelCAS.TYPE_CLASS_FS:
+
+ FeatureStructure fStruct = annot.getFeatureValue(fs);
+ if(fStruct != null) {
+ this.fileWriter.write(fStruct.toString());
+ } else {
+ this.fileWriter.write("null");
+ }
+ break;
+ }
+ }
+
+ if (firstFeature == false)
+ {
+ this.fileWriter.write(" }");
+ }
+
+ this.fileWriter.write(System.getProperty("line.separator"));
+ }
+
+ }
+ }
+
+ this.fileWriter.flush();
+ }
+ catch (Exception ex)
+ {
+ throw new ResourceProcessException(ex);
+ }
+
+ }
+
+ public void batchProcessComplete(ProcessTrace aTrace) throws ResourceProcessException, IOException
+ {
+ // nothing to do here
+ }
+
+ public void collectionProcessComplete(ProcessTrace aTrace) throws ResourceProcessException, IOException
+ {
+ if (this.fileWriter != null)
+ {
+ this.fileWriter.close();
+ }
+ }
+
+ public void reconfigure() throws ResourceConfigurationException
+ {
+ //reset reconfiguration - is done
+ this.reconfig = false;
+
+ super.reconfigure();
+ // extract configuration parameter settings
+ String oPath = (String) getUimaContext().getConfigParameterValue("outputFile");
+ File oFile = new File(oPath);
+ //if output file has changed, close exiting file and open new
+ if (!oFile.equals(this.outFile))
+ {
+ this.outFile = oFile;
+ try
+ {
+ if (this.fileWriter != null)
+ this.fileWriter.close();
+
+ // If specified output directory does not exist, try to create it
+ if (oFile.getParentFile() != null && !oFile.getParentFile().exists())
+ {
+ if (!oFile.getParentFile().mkdirs())
+ throw new ResourceConfigurationException(
+ ResourceInitializationException.RESOURCE_DATA_NOT_VALID,
+ new Object[] { oPath, "outputFile" });
+ }
+ //write result specification to the output file
+ this.fileWriter = new OutputStreamWriter(new FileOutputStream(oFile, false), "UTF-8");
+ }
+ catch (IOException e)
+ {
+ throw new ResourceConfigurationException();
+ }
+ }
+
+ //extract annotation types
+ this.tofs = (String[]) getUimaContext().getConfigParameterValue("AnnotationTypes");
+ //sort array
+ if (this.tofs != null)
+ Arrays.sort(this.tofs);
+
+ }
+
+ public void destroy()
+ {
+ if (this.fileWriter != null)
+ {
+ try
+ {
+ this.fileWriter.close();
+ }
+ catch (IOException e)
+ {
+ // ignore IOException on destroy
+ }
+ }
+ }
+
+}
Propchange: incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotationWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotatorPerformanceTester.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotatorPerformanceTester.java?rev=690399&r1=690398&r2=690399&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotatorPerformanceTester.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotatorPerformanceTester.java Fri Aug 29 14:43:30 2008
@@ -1,298 +1,298 @@
-/*
- * 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.test.junit_extension;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.util.HashMap;
-import java.util.logging.LogManager;
-
-import junit.framework.Assert;
-
-import org.apache.uima.UIMAFramework;
-import org.apache.uima.analysis_engine.AnalysisEngine;
-import org.apache.uima.cas.CAS;
-import org.apache.uima.internal.util.Timer;
-import org.apache.uima.resource.ResourceManager;
-import org.apache.uima.resource.ResourceSpecifier;
-import org.apache.uima.util.FileUtils;
-import org.apache.uima.util.Level;
-import org.apache.uima.util.Logger;
-import org.apache.uima.util.XMLInputSource;
-
-/**
- * AnnotatorPerfTester is a helper class to execute annotator performance tests. The performance
- * test results are returned as {@link PerformanceTestResultImpl} object.
- *
- */
-public class AnnotatorPerformanceTester {
-
- private static class FileFileFilter implements FileFilter {
-
- private FileFileFilter() {
- super();
- }
-
- public boolean accept(File arg0) {
- return arg0.isFile();
- }
-
- }
-
- private static HashMap logLevels = new HashMap(9);
- static {
- logLevels.put("OFF", Level.OFF);
- logLevels.put("SEVERE", Level.SEVERE);
- logLevels.put("WARNING", Level.WARNING);
- logLevels.put("INFO", Level.INFO);
- logLevels.put("CONFIG", Level.CONFIG);
- logLevels.put("FINE", Level.FINE);
- logLevels.put("FINER", Level.FINER);
- logLevels.put("FINEST", Level.FINEST);
- logLevels.put("ALL", Level.ALL);
- }
-
- /**
- * runs an annotator performance test
- *
- * @param repeatSingle
- * if true, every document is process "numsToRun" times before the next document is
- * processed. If false, all documents are processed and this is repeated "numsToRun"
- * times.
- *
- * @param numsToRun
- * repeat count for the input documents
- * @param taeDescFilePath
- * ae descriptor - absolute file path
- * @param testFileDir
- * test file directory
- * @param dataPath
- * ae datapath
- * @param doWarmup
- * do warum for analysis engine - runs an short english sample document
- * @return PerformanceTestResult - returns the performance test results
- *
- * @throws Exception
- */
- public static PerformanceTestResult runPerformanceTest(boolean repeatSingle, int numsToRun,
- File taeDescFilePath, File testFileDir, String dataPath, boolean doWarmup)
- throws Exception {
-
- // create performance result object
- PerformanceTestResultImpl result = new PerformanceTestResultImpl();
-
- // check mandetory settings
- Assert.assertNotNull(taeDescFilePath);
- Assert.assertNotNull(testFileDir);
-
- // save settings
- result.setRepeatSingleMode(repeatSingle);
- result.setDoWarmup(doWarmup);
- result.setNumsToRun(numsToRun);
- result.setAeDescFilePath(taeDescFilePath);
- result.setTestFileDir(testFileDir);
- result.setDatapath(dataPath);
-
- // set and check test file directory
- if (testFileDir == null || !testFileDir.isDirectory() || !testFileDir.canRead()) {
- throw new Exception("test file directory not valid");
- }
-
- // get current log level setting
- Level defaultLogLevel = (Level) logLevels.get(LogManager.getLogManager()
- .getProperty(".level"));
-
- if (defaultLogLevel == null) {
- // no log level was specified, use default log level settings "INFO" that is also
- // used by the Java logging framework.
- defaultLogLevel = Level.INFO;
- }
- // turn of logging for the performance test
- Logger logger = UIMAFramework.getLogger();
- logger.setLevel(Level.OFF);
-
- //create timer
- Timer globalTimer = new Timer();
- Timer initTimer = new Timer();
- Timer warmupTimer = new Timer();
- Timer ioTimer = new Timer();
- Timer processResetTimer = new Timer();
- Timer cleanupTimer = new Timer();
- Timer documentPreparationTimer = new Timer();
-
- //start timer for global time
- globalTimer.start();
-
- // init analysis engine
- try {
-
- // start initialization timer
- initTimer.start();
-
- // set datapath
- ResourceManager resMgr = UIMAFramework.newDefaultResourceManager();
- if (dataPath != null) {
- resMgr.setDataPath(dataPath);
- }
-
- AnalysisEngine ae = null;
- CAS cas = null;
- // get resource specifier from XML file
- XMLInputSource in = new XMLInputSource(taeDescFilePath);
- ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);
-
- // create analysis engine with resource manager
- ae = UIMAFramework.produceAnalysisEngine(specifier, resMgr, null);
- // check ae
- Assert.assertNotNull(ae);
-
- // create new cas
- cas = ae.newCAS();
- // check cas
- Assert.assertNotNull(cas);
-
- // access cas type system
- cas.getTypeSystem().getFeatureByFullName(CAS.FEATURE_FULL_NAME_LANGUAGE);
-
- // stop initalization timer
- initTimer.stop();
- result.setInitTime(initTimer.getTimeSpan());
-
- if (doWarmup) {
- // start warmup timer
- warmupTimer.start();
-
- // process dummy document
- cas.setDocumentLanguage("en");
- cas.setDocumentText("This is a test sentence.");
- ae.process(cas);
- cas.reset();
-
- // stop warmup timer
- warmupTimer.stop();
- result.setWarmupTime(warmupTimer.getTimeSpan());
- }
-
- // start io timer
- ioTimer.start();
-
- // read all files in the test file directory
- File[] inputFiles = testFileDir.listFiles(new FileFileFilter());
- // create string array for the file content and language
- String[] fileTexts = new String[inputFiles.length];
- String[] languages = new String[inputFiles.length];
- int numChars = 0;
- long fileSize = 0;
- // iterate of all input files and extract content and language
- for (int i = 0; i < inputFiles.length; i++) {
- // get file language
- languages[i] = inputFiles[i].getName().substring(0, 2);
- // get file content
- fileTexts[i] = FileUtils.file2String(inputFiles[i], "UTF-8");
- fileSize += inputFiles[i].length();
- // count characters
- numChars += fileTexts[i].length();
- }
-
- // stop io timer
- ioTimer.stop();
-
- // save results
- result.setNumberOfFiles(inputFiles.length);
- result.setNumberOfCharacters(numChars);
- result.setTotalFileSize(fileSize);
- result.setIoTime(ioTimer.getTimeSpan());
-
- // start real processing
- int numAnnot = 0;
-
- // check repeat single mode setting
- // repeatSingle=true: iterates of all files and repeat each file "numsToRun" times
- // repeatSingle=false: iterates of all files and repeat the collection "numsToRun" times
- if (repeatSingle) {
- // iterate over all text files (over the cached content)
- for (int i = 0; i < fileTexts.length; i++) {
- // file repeat mode
- // iterate over the current document "numsToRun" times
- for (int j = 0; j < numsToRun; j++) {
- documentPreparationTimer.start();
- // set cas data
- cas.setDocumentLanguage(languages[i]);
- cas.setDocumentText(fileTexts[i]);
- documentPreparationTimer.stop();
- processResetTimer.start();
- ae.process(cas);
- processResetTimer.stop();
- documentPreparationTimer.start();
- numAnnot += cas.getAnnotationIndex().size();
- cas.reset();
- documentPreparationTimer.stop();
- }
- }
- }
- // use collection repeat mode
- else {
- // process the file collection "numsToRun" times
- for (int j = 0; j < numsToRun; j++) {
- // iterate over all text files (over the cached content)
- for (int i = 0; i < fileTexts.length; i++) {
- documentPreparationTimer.start();
- // set cas data
- cas.setDocumentLanguage(languages[i]);
- cas.setDocumentText(fileTexts[i]);
- documentPreparationTimer.stop();
- processResetTimer.start();
- ae.process(cas);
- processResetTimer.stop();
- documentPreparationTimer.start();
- numAnnot += cas.getAnnotationIndex().size();
- cas.reset();
- documentPreparationTimer.stop();
- }
- }
- }
-
- // cleanup ae and stop global timer
- cleanupTimer.start();
- ae.destroy();
- ae = null;
- cleanupTimer.stop();
- globalTimer.stop();
-
- // save results
- result.setNumberOfCreatedAnnotations(numAnnot);
- result.setOverallTime(globalTimer.getTimeSpan());
- result.setProcessingTime(processResetTimer.getTimeSpan());
- result.setCleanupTime(cleanupTimer.getTimeSpan());
- result.setDocumentPreparationTime(documentPreparationTimer.getTimeSpan());
-
- // turn on logging as it was before
- logger.setLevel(defaultLogLevel);
-
- // return result object
- return result;
-
- } catch (Exception e) { // Bail out.
- throw e;
- }
-
- }
-
-}
+/*
+ * 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.test.junit_extension;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.HashMap;
+import java.util.logging.LogManager;
+
+import junit.framework.Assert;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.internal.util.Timer;
+import org.apache.uima.resource.ResourceManager;
+import org.apache.uima.resource.ResourceSpecifier;
+import org.apache.uima.util.FileUtils;
+import org.apache.uima.util.Level;
+import org.apache.uima.util.Logger;
+import org.apache.uima.util.XMLInputSource;
+
+/**
+ * AnnotatorPerfTester is a helper class to execute annotator performance tests. The performance
+ * test results are returned as {@link PerformanceTestResultImpl} object.
+ *
+ */
+public class AnnotatorPerformanceTester {
+
+ private static class FileFileFilter implements FileFilter {
+
+ private FileFileFilter() {
+ super();
+ }
+
+ public boolean accept(File arg0) {
+ return arg0.isFile();
+ }
+
+ }
+
+ private static HashMap logLevels = new HashMap(9);
+ static {
+ logLevels.put("OFF", Level.OFF);
+ logLevels.put("SEVERE", Level.SEVERE);
+ logLevels.put("WARNING", Level.WARNING);
+ logLevels.put("INFO", Level.INFO);
+ logLevels.put("CONFIG", Level.CONFIG);
+ logLevels.put("FINE", Level.FINE);
+ logLevels.put("FINER", Level.FINER);
+ logLevels.put("FINEST", Level.FINEST);
+ logLevels.put("ALL", Level.ALL);
+ }
+
+ /**
+ * runs an annotator performance test
+ *
+ * @param repeatSingle
+ * if true, every document is process "numsToRun" times before the next document is
+ * processed. If false, all documents are processed and this is repeated "numsToRun"
+ * times.
+ *
+ * @param numsToRun
+ * repeat count for the input documents
+ * @param taeDescFilePath
+ * ae descriptor - absolute file path
+ * @param testFileDir
+ * test file directory
+ * @param dataPath
+ * ae datapath
+ * @param doWarmup
+ * do warum for analysis engine - runs an short english sample document
+ * @return PerformanceTestResult - returns the performance test results
+ *
+ * @throws Exception
+ */
+ public static PerformanceTestResult runPerformanceTest(boolean repeatSingle, int numsToRun,
+ File taeDescFilePath, File testFileDir, String dataPath, boolean doWarmup)
+ throws Exception {
+
+ // create performance result object
+ PerformanceTestResultImpl result = new PerformanceTestResultImpl();
+
+ // check mandetory settings
+ Assert.assertNotNull(taeDescFilePath);
+ Assert.assertNotNull(testFileDir);
+
+ // save settings
+ result.setRepeatSingleMode(repeatSingle);
+ result.setDoWarmup(doWarmup);
+ result.setNumsToRun(numsToRun);
+ result.setAeDescFilePath(taeDescFilePath);
+ result.setTestFileDir(testFileDir);
+ result.setDatapath(dataPath);
+
+ // set and check test file directory
+ if (testFileDir == null || !testFileDir.isDirectory() || !testFileDir.canRead()) {
+ throw new Exception("test file directory not valid");
+ }
+
+ // get current log level setting
+ Level defaultLogLevel = (Level) logLevels.get(LogManager.getLogManager()
+ .getProperty(".level"));
+
+ if (defaultLogLevel == null) {
+ // no log level was specified, use default log level settings "INFO" that is also
+ // used by the Java logging framework.
+ defaultLogLevel = Level.INFO;
+ }
+ // turn of logging for the performance test
+ Logger logger = UIMAFramework.getLogger();
+ logger.setLevel(Level.OFF);
+
+ //create timer
+ Timer globalTimer = new Timer();
+ Timer initTimer = new Timer();
+ Timer warmupTimer = new Timer();
+ Timer ioTimer = new Timer();
+ Timer processResetTimer = new Timer();
+ Timer cleanupTimer = new Timer();
+ Timer documentPreparationTimer = new Timer();
+
+ //start timer for global time
+ globalTimer.start();
+
+ // init analysis engine
+ try {
+
+ // start initialization timer
+ initTimer.start();
+
+ // set datapath
+ ResourceManager resMgr = UIMAFramework.newDefaultResourceManager();
+ if (dataPath != null) {
+ resMgr.setDataPath(dataPath);
+ }
+
+ AnalysisEngine ae = null;
+ CAS cas = null;
+ // get resource specifier from XML file
+ XMLInputSource in = new XMLInputSource(taeDescFilePath);
+ ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);
+
+ // create analysis engine with resource manager
+ ae = UIMAFramework.produceAnalysisEngine(specifier, resMgr, null);
+ // check ae
+ Assert.assertNotNull(ae);
+
+ // create new cas
+ cas = ae.newCAS();
+ // check cas
+ Assert.assertNotNull(cas);
+
+ // access cas type system
+ cas.getTypeSystem().getFeatureByFullName(CAS.FEATURE_FULL_NAME_LANGUAGE);
+
+ // stop initalization timer
+ initTimer.stop();
+ result.setInitTime(initTimer.getTimeSpan());
+
+ if (doWarmup) {
+ // start warmup timer
+ warmupTimer.start();
+
+ // process dummy document
+ cas.setDocumentLanguage("en");
+ cas.setDocumentText("This is a test sentence.");
+ ae.process(cas);
+ cas.reset();
+
+ // stop warmup timer
+ warmupTimer.stop();
+ result.setWarmupTime(warmupTimer.getTimeSpan());
+ }
+
+ // start io timer
+ ioTimer.start();
+
+ // read all files in the test file directory
+ File[] inputFiles = testFileDir.listFiles(new FileFileFilter());
+ // create string array for the file content and language
+ String[] fileTexts = new String[inputFiles.length];
+ String[] languages = new String[inputFiles.length];
+ int numChars = 0;
+ long fileSize = 0;
+ // iterate of all input files and extract content and language
+ for (int i = 0; i < inputFiles.length; i++) {
+ // get file language
+ languages[i] = inputFiles[i].getName().substring(0, 2);
+ // get file content
+ fileTexts[i] = FileUtils.file2String(inputFiles[i], "UTF-8");
+ fileSize += inputFiles[i].length();
+ // count characters
+ numChars += fileTexts[i].length();
+ }
+
+ // stop io timer
+ ioTimer.stop();
+
+ // save results
+ result.setNumberOfFiles(inputFiles.length);
+ result.setNumberOfCharacters(numChars);
+ result.setTotalFileSize(fileSize);
+ result.setIoTime(ioTimer.getTimeSpan());
+
+ // start real processing
+ int numAnnot = 0;
+
+ // check repeat single mode setting
+ // repeatSingle=true: iterates of all files and repeat each file "numsToRun" times
+ // repeatSingle=false: iterates of all files and repeat the collection "numsToRun" times
+ if (repeatSingle) {
+ // iterate over all text files (over the cached content)
+ for (int i = 0; i < fileTexts.length; i++) {
+ // file repeat mode
+ // iterate over the current document "numsToRun" times
+ for (int j = 0; j < numsToRun; j++) {
+ documentPreparationTimer.start();
+ // set cas data
+ cas.setDocumentLanguage(languages[i]);
+ cas.setDocumentText(fileTexts[i]);
+ documentPreparationTimer.stop();
+ processResetTimer.start();
+ ae.process(cas);
+ processResetTimer.stop();
+ documentPreparationTimer.start();
+ numAnnot += cas.getAnnotationIndex().size();
+ cas.reset();
+ documentPreparationTimer.stop();
+ }
+ }
+ }
+ // use collection repeat mode
+ else {
+ // process the file collection "numsToRun" times
+ for (int j = 0; j < numsToRun; j++) {
+ // iterate over all text files (over the cached content)
+ for (int i = 0; i < fileTexts.length; i++) {
+ documentPreparationTimer.start();
+ // set cas data
+ cas.setDocumentLanguage(languages[i]);
+ cas.setDocumentText(fileTexts[i]);
+ documentPreparationTimer.stop();
+ processResetTimer.start();
+ ae.process(cas);
+ processResetTimer.stop();
+ documentPreparationTimer.start();
+ numAnnot += cas.getAnnotationIndex().size();
+ cas.reset();
+ documentPreparationTimer.stop();
+ }
+ }
+ }
+
+ // cleanup ae and stop global timer
+ cleanupTimer.start();
+ ae.destroy();
+ ae = null;
+ cleanupTimer.stop();
+ globalTimer.stop();
+
+ // save results
+ result.setNumberOfCreatedAnnotations(numAnnot);
+ result.setOverallTime(globalTimer.getTimeSpan());
+ result.setProcessingTime(processResetTimer.getTimeSpan());
+ result.setCleanupTime(cleanupTimer.getTimeSpan());
+ result.setDocumentPreparationTime(documentPreparationTimer.getTimeSpan());
+
+ // turn on logging as it was before
+ logger.setLevel(defaultLogLevel);
+
+ // return result object
+ return result;
+
+ } catch (Exception e) { // Bail out.
+ throw e;
+ }
+
+ }
+
+}
Propchange: incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotatorPerformanceTester.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotatorTester.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotatorTester.java?rev=690399&r1=690398&r2=690399&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotatorTester.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotatorTester.java Fri Aug 29 14:43:30 2008
@@ -1,445 +1,445 @@
-/*
- * 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.test.junit_extension;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Map;
-
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import junit.framework.Assert;
-
-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.impl.XCASDeserializer;
-import org.apache.uima.collection.CasConsumer;
-import org.apache.uima.resource.ResourceConfigurationException;
-import org.apache.uima.resource.ResourceInitializationException;
-import org.apache.uima.resource.ResourceManager;
-import org.apache.uima.resource.ResourceSpecifier;
-import org.apache.uima.resource.metadata.FsIndexDescription;
-import org.apache.uima.resource.metadata.TypeSystemDescription;
-import org.apache.uima.test.junit_extension.FileCompare;
-import org.apache.uima.test.junit_extension.JUnitExtension;
-import org.apache.uima.util.CasCreationUtils;
-import org.apache.uima.util.FileUtils;
-import org.apache.uima.util.InvalidXMLException;
-import org.apache.uima.util.XMLInputSource;
-
-/**
- * AnnotatorTester is the helper class to test annotators.
- */
-public class AnnotatorTester {
- // annotator descriptor
- private File descFile;
-
- // analysis engine instance
- private AnalysisEngine ae;
-
- // Resource Manager
- private ResourceManager mgr;
-
- /**
- * Constructor save the specified descriptor file path and initialize the
- * analysis engine.
- *
- * @param descFilePath
- * descriptor file path
- * @throws Exception
- * if an analysis engine initialize error occurs.
- */
- public AnnotatorTester(String descFilePath) throws Exception {
- this.descFile = new File(descFilePath);
- this.mgr = UIMAFramework.newDefaultResourceManager();
- setup();
- }
-
- /**
- * Constructor save the specified descriptor file path and initialize the
- * analysis engine.
- *
- * @param descFile
- * descriptor file
- * @throws Exception
- * if an analysis engine initialize error occurs.
- */
- public AnnotatorTester(File descFile) throws Exception {
- this.descFile = descFile;
- this.mgr = UIMAFramework.newDefaultResourceManager();
- setup();
- }
-
- /**
- * Constructor save the specified descriptor file path and initialize the
- * analysis engine.
- *
- * @param descFilePath
- * descriptor file path
- * @param mgr
- * a ResourceManager
- * @throws Exception
- * if an analysis engine initialize error occurs.
- */
- public AnnotatorTester(String descFilePath, ResourceManager mgr)
- throws Exception {
- this.descFile = new File(descFilePath);
- this.mgr = mgr;
- setup();
- }
-
- /**
- * initialize the analysis engine with the specified specifier.
- *
- * @throws Exception
- */
- private void setup() throws Exception {
- try {
- this.ae = null;
- // Create an XML input source from the specifier file.
- XMLInputSource in = new XMLInputSource(this.descFile);
- // Parse the specifier.
- ResourceSpecifier specifier = UIMAFramework.getXMLParser()
- .parseResourceSpecifier(in);
- // Create the Text Analysis Engine.
- this.ae = UIMAFramework.produceAnalysisEngine(specifier, this.mgr,
- null);
- } catch (Exception ex) {
- JUnitExtension.handleException(ex);
- }
- }
-
- /**
- * change the parameter name for the given analysis engine
- *
- * @param groupName
- * group name, if no group is available, pass null
- * @param paramName
- * parameter name
- * @param paramValue
- * parameter value
- *
- * @throws ResourceConfigurationException
- */
- public void changeParameterSetting(String groupName, String paramName,
- Object paramValue) throws ResourceConfigurationException {
- if (groupName == null) {
- this.ae.setConfigParameterValue(paramName, paramValue);
- } else {
- this.ae.setConfigParameterValue(groupName, paramName, paramValue);
- }
- // call reconfigure to activate the change
- this.ae.reconfigure();
- }
-
- /**
- * change the parameter name for the given delegate analysis engine key
- *
- * @param delegeteKey
- * analysis engine key
- * @param groupName
- * group name
- * @param paramName
- * parameter name
- * @param paramValue
- * parameter value
- *
- * @throws InvalidXMLException
- * @throws ResourceInitializationException
- * @throws IOException
- */
- public void changeDelegateParameterSetting(String delegeteKey,
- String groupName, String paramName, Object paramValue)
- throws InvalidXMLException, ResourceInitializationException,
- IOException {
- // create CasConsumer description
- AnalysisEngineDescription aeSpecifier = UIMAFramework.getXMLParser()
- .parseAnalysisEngineDescription(new XMLInputSource(this.descFile));
-
- // get delegates
- Map delegates = aeSpecifier.getDelegateAnalysisEngineSpecifiers();
-
- // check if delegeteKey is available
- if (delegates.containsKey(delegeteKey)) {
- // create new import
- AnalysisEngineDescription delegate = (AnalysisEngineDescription) delegates
- .get(delegeteKey);
-
- if (groupName == null) {
- delegate.getMetaData().getConfigurationParameterSettings()
- .setParameterValue(paramName, paramValue);
- } else {
- delegate.getMetaData().getConfigurationParameterSettings()
- .setParameterValue(groupName, paramName, paramValue);
- }
- }
-
- // produce new AE
- this.ae = UIMAFramework
- .produceAnalysisEngine(aeSpecifier, this.mgr, null);
-
- }
-
- /**
- * does configuration parameter test
- *
- * @param configDescFilePath
- * @return AnalysisEngine
- *
- * @throws Exception
- */
- public static AnalysisEngine doConfigurationTest(String configDescFilePath)
- throws Exception {
- try {
- AnalysisEngine ae = null;
- // Create an XML input source from the specifier file.
- XMLInputSource in = new XMLInputSource(configDescFilePath);
- // Parse the specifier.
- ResourceSpecifier specifier = UIMAFramework.getXMLParser()
- .parseResourceSpecifier(in);
- // Create the Text Analysis Engine.
- ae = UIMAFramework.produceAnalysisEngine(specifier, null, null);
-
- // Create a new CAS.
- CAS cas = ae.newCAS();
- // Set the document text on the CAS.
- cas
- .setDocumentText("This is a simple text to check if the configuration works");
- cas.setDocumentLanguage("en");
- // Process the sample document.
- ae.process(cas);
-
- return ae;
- } catch (Exception ex) {
- JUnitExtension.handleException(ex);
- }
-
- return null;
-
- }
-
- /**
- * performs a test on the initialized annotator. The specified document is
- * processed with the given language.
- *
- * @param text
- * a document text
- * @param language
- * the document text language
- * @return CAS - results of the analysis
- * @throws Exception
- */
- public CAS performTest(String text, String language) throws Exception {
- try {
- // Create a new CAS.
- CAS cas = this.ae.newCAS();
- // Set the document text on the CAS.
- cas.setDocumentText(text);
- cas.setDocumentLanguage(language);
- // Process the sample document.
- this.ae.process(cas);
-
- return cas;
- } catch (Exception ex) {
- JUnitExtension.handleException(ex);
- }
-
- return null;
-
- }
-
- /**
- * performs a test on the initialized annotator. The specified CAS is
- * processed and the results are returned.
- *
- * @param cas
- * a CAS for processing
- * @return CAS - results of the analysis
- * @throws Exception
- */
- public CAS performTest(CAS cas) throws Exception {
- try {
- // Process the sample document.
- this.ae.process(cas);
-
- return cas;
- } catch (Exception ex) {
- JUnitExtension.handleException(ex);
- }
-
- return null;
-
- }
-
- /**
- * performs a test with a special annotator configuration. For this a new AE
- * is created and used to process the specified document for the specified
- * language.
- *
- * @param descFilePath
- * Descriptor file path
- * @param text
- * a document text
- * @param language
- * the document text language
- * @return CAS - results of the analysis
- * @throws Exception
- */
- public static CAS performTest(String descFilePath, String text,
- String language) throws Exception {
- try {
- AnalysisEngine ae = null;
- // Create an XML input source from the specifier file.
- XMLInputSource in = new XMLInputSource(descFilePath);
- // Parse the specifier.
- ResourceSpecifier specifier = UIMAFramework.getXMLParser()
- .parseResourceSpecifier(in);
- // Create the Text Analysis Engine.
- ae = UIMAFramework.produceAnalysisEngine(specifier, null, null);
-
- // Create a new CAS.
- CAS cas = ae.newCAS();
- // Set the document text on the CAS.
- cas.setDocumentText(text);
- cas.setDocumentLanguage(language);
- // Process the sample document.
- ae.process(cas);
-
- return cas;
- } catch (Exception ex) {
- JUnitExtension.handleException(ex);
- }
-
- return null;
-
- }
-
- /**
- * create a CAS object from the given XCAS and typesystem files
- *
- * @param tsFile -
- * a typesystem file
- * @param xcasFile -
- * a xcas file
- *
- * @return CAS - CAS object created from the given input data
- * @throws Exception
- */
- public static CAS getCASfromXCAS(File tsFile, File xcasFile)
- throws Exception {
- try {
- Object tsDescriptor = UIMAFramework.getXMLParser().parse(
- new XMLInputSource(tsFile));
- TypeSystemDescription tsDesc = (TypeSystemDescription) tsDescriptor;
- CAS cas = CasCreationUtils.createCas(tsDesc, null,
- new FsIndexDescription[0]);
-
- SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
- XCASDeserializer xcasDeserializer = new XCASDeserializer(cas
- .getTypeSystem());
- parser.parse(xcasFile, xcasDeserializer.getXCASHandler(cas));
-
- return cas;
- } catch (Exception ex) {
- JUnitExtension.handleException(ex);
- }
-
- return null;
- }
-
- /**
- * Reads the content form a file to a String with respect to the file
- * encoding.
- *
- * @param file
- * a file with the source
- * @param encoding
- * file encoding
- * @return String - file content
- * @throws Exception
- */
- public static String readFileContent(File file, String encoding)
- throws Exception {
- try {
- return FileUtils.file2String(file, encoding);
- } catch (Exception ex) {
- JUnitExtension.handleException(ex);
- }
-
- return null;
- }
-
- /**
- * checkResult compares the analyzed document with the reference output.
- *
- * @param cas
- * a cas with the analyzed data
- * @param AnnotationTypes
- * respected annotation types
- * @param refFile
- * reference output
- * @param testFile
- * test file for the current output
- * @throws Exception
- */
- public static void checkResult(CAS cas, String[] AnnotationTypes,
- File refFile, File testFile) throws Exception {
-
- try {
-
- testFile.delete(); // delete file if exist
- testFile.createNewFile(); // create new file
-
- // Create an XML input source from the specifier file.
- XMLInputSource in = new XMLInputSource(JUnitExtension
- .getURL("AnnotationWriter.xml"));
- // Parse the specifier.
- ResourceSpecifier specifier = UIMAFramework.getXMLParser()
- .parseResourceSpecifier(in);
-
- CasConsumer consumer = UIMAFramework.produceCasConsumer(specifier);
-
- consumer.setConfigParameterValue("AnnotationTypes", AnnotationTypes);
-
- consumer.setConfigParameterValue("outputFile", testFile
- .getAbsolutePath());
-
- consumer.reconfigure();
-
- consumer.processCas(cas);
- consumer.destroy();
-
- // check file output
- boolean isIdentical = FileCompare.compare(refFile, testFile);
-
- if (isIdentical) {
- testFile.delete();
- }
-
- Assert.assertTrue(isIdentical);
-
- } catch (Exception ex) {
- JUnitExtension.handleException(ex);
- }
-
- }
-}
+/*
+ * 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.test.junit_extension;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import junit.framework.Assert;
+
+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.impl.XCASDeserializer;
+import org.apache.uima.collection.CasConsumer;
+import org.apache.uima.resource.ResourceConfigurationException;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.ResourceManager;
+import org.apache.uima.resource.ResourceSpecifier;
+import org.apache.uima.resource.metadata.FsIndexDescription;
+import org.apache.uima.resource.metadata.TypeSystemDescription;
+import org.apache.uima.test.junit_extension.FileCompare;
+import org.apache.uima.test.junit_extension.JUnitExtension;
+import org.apache.uima.util.CasCreationUtils;
+import org.apache.uima.util.FileUtils;
+import org.apache.uima.util.InvalidXMLException;
+import org.apache.uima.util.XMLInputSource;
+
+/**
+ * AnnotatorTester is the helper class to test annotators.
+ */
+public class AnnotatorTester {
+ // annotator descriptor
+ private File descFile;
+
+ // analysis engine instance
+ private AnalysisEngine ae;
+
+ // Resource Manager
+ private ResourceManager mgr;
+
+ /**
+ * Constructor save the specified descriptor file path and initialize the
+ * analysis engine.
+ *
+ * @param descFilePath
+ * descriptor file path
+ * @throws Exception
+ * if an analysis engine initialize error occurs.
+ */
+ public AnnotatorTester(String descFilePath) throws Exception {
+ this.descFile = new File(descFilePath);
+ this.mgr = UIMAFramework.newDefaultResourceManager();
+ setup();
+ }
+
+ /**
+ * Constructor save the specified descriptor file path and initialize the
+ * analysis engine.
+ *
+ * @param descFile
+ * descriptor file
+ * @throws Exception
+ * if an analysis engine initialize error occurs.
+ */
+ public AnnotatorTester(File descFile) throws Exception {
+ this.descFile = descFile;
+ this.mgr = UIMAFramework.newDefaultResourceManager();
+ setup();
+ }
+
+ /**
+ * Constructor save the specified descriptor file path and initialize the
+ * analysis engine.
+ *
+ * @param descFilePath
+ * descriptor file path
+ * @param mgr
+ * a ResourceManager
+ * @throws Exception
+ * if an analysis engine initialize error occurs.
+ */
+ public AnnotatorTester(String descFilePath, ResourceManager mgr)
+ throws Exception {
+ this.descFile = new File(descFilePath);
+ this.mgr = mgr;
+ setup();
+ }
+
+ /**
+ * initialize the analysis engine with the specified specifier.
+ *
+ * @throws Exception
+ */
+ private void setup() throws Exception {
+ try {
+ this.ae = null;
+ // Create an XML input source from the specifier file.
+ XMLInputSource in = new XMLInputSource(this.descFile);
+ // Parse the specifier.
+ ResourceSpecifier specifier = UIMAFramework.getXMLParser()
+ .parseResourceSpecifier(in);
+ // Create the Text Analysis Engine.
+ this.ae = UIMAFramework.produceAnalysisEngine(specifier, this.mgr,
+ null);
+ } catch (Exception ex) {
+ JUnitExtension.handleException(ex);
+ }
+ }
+
+ /**
+ * change the parameter name for the given analysis engine
+ *
+ * @param groupName
+ * group name, if no group is available, pass null
+ * @param paramName
+ * parameter name
+ * @param paramValue
+ * parameter value
+ *
+ * @throws ResourceConfigurationException
+ */
+ public void changeParameterSetting(String groupName, String paramName,
+ Object paramValue) throws ResourceConfigurationException {
+ if (groupName == null) {
+ this.ae.setConfigParameterValue(paramName, paramValue);
+ } else {
+ this.ae.setConfigParameterValue(groupName, paramName, paramValue);
+ }
+ // call reconfigure to activate the change
+ this.ae.reconfigure();
+ }
+
+ /**
+ * change the parameter name for the given delegate analysis engine key
+ *
+ * @param delegeteKey
+ * analysis engine key
+ * @param groupName
+ * group name
+ * @param paramName
+ * parameter name
+ * @param paramValue
+ * parameter value
+ *
+ * @throws InvalidXMLException
+ * @throws ResourceInitializationException
+ * @throws IOException
+ */
+ public void changeDelegateParameterSetting(String delegeteKey,
+ String groupName, String paramName, Object paramValue)
+ throws InvalidXMLException, ResourceInitializationException,
+ IOException {
+ // create CasConsumer description
+ AnalysisEngineDescription aeSpecifier = UIMAFramework.getXMLParser()
+ .parseAnalysisEngineDescription(new XMLInputSource(this.descFile));
+
+ // get delegates
+ Map delegates = aeSpecifier.getDelegateAnalysisEngineSpecifiers();
+
+ // check if delegeteKey is available
+ if (delegates.containsKey(delegeteKey)) {
+ // create new import
+ AnalysisEngineDescription delegate = (AnalysisEngineDescription) delegates
+ .get(delegeteKey);
+
+ if (groupName == null) {
+ delegate.getMetaData().getConfigurationParameterSettings()
+ .setParameterValue(paramName, paramValue);
+ } else {
+ delegate.getMetaData().getConfigurationParameterSettings()
+ .setParameterValue(groupName, paramName, paramValue);
+ }
+ }
+
+ // produce new AE
+ this.ae = UIMAFramework
+ .produceAnalysisEngine(aeSpecifier, this.mgr, null);
+
+ }
+
+ /**
+ * does configuration parameter test
+ *
+ * @param configDescFilePath
+ * @return AnalysisEngine
+ *
+ * @throws Exception
+ */
+ public static AnalysisEngine doConfigurationTest(String configDescFilePath)
+ throws Exception {
+ try {
+ AnalysisEngine ae = null;
+ // Create an XML input source from the specifier file.
+ XMLInputSource in = new XMLInputSource(configDescFilePath);
+ // Parse the specifier.
+ ResourceSpecifier specifier = UIMAFramework.getXMLParser()
+ .parseResourceSpecifier(in);
+ // Create the Text Analysis Engine.
+ ae = UIMAFramework.produceAnalysisEngine(specifier, null, null);
+
+ // Create a new CAS.
+ CAS cas = ae.newCAS();
+ // Set the document text on the CAS.
+ cas
+ .setDocumentText("This is a simple text to check if the configuration works");
+ cas.setDocumentLanguage("en");
+ // Process the sample document.
+ ae.process(cas);
+
+ return ae;
+ } catch (Exception ex) {
+ JUnitExtension.handleException(ex);
+ }
+
+ return null;
+
+ }
+
+ /**
+ * performs a test on the initialized annotator. The specified document is
+ * processed with the given language.
+ *
+ * @param text
+ * a document text
+ * @param language
+ * the document text language
+ * @return CAS - results of the analysis
+ * @throws Exception
+ */
+ public CAS performTest(String text, String language) throws Exception {
+ try {
+ // Create a new CAS.
+ CAS cas = this.ae.newCAS();
+ // Set the document text on the CAS.
+ cas.setDocumentText(text);
+ cas.setDocumentLanguage(language);
+ // Process the sample document.
+ this.ae.process(cas);
+
+ return cas;
+ } catch (Exception ex) {
+ JUnitExtension.handleException(ex);
+ }
+
+ return null;
+
+ }
+
+ /**
+ * performs a test on the initialized annotator. The specified CAS is
+ * processed and the results are returned.
+ *
+ * @param cas
+ * a CAS for processing
+ * @return CAS - results of the analysis
+ * @throws Exception
+ */
+ public CAS performTest(CAS cas) throws Exception {
+ try {
+ // Process the sample document.
+ this.ae.process(cas);
+
+ return cas;
+ } catch (Exception ex) {
+ JUnitExtension.handleException(ex);
+ }
+
+ return null;
+
+ }
+
+ /**
+ * performs a test with a special annotator configuration. For this a new AE
+ * is created and used to process the specified document for the specified
+ * language.
+ *
+ * @param descFilePath
+ * Descriptor file path
+ * @param text
+ * a document text
+ * @param language
+ * the document text language
+ * @return CAS - results of the analysis
+ * @throws Exception
+ */
+ public static CAS performTest(String descFilePath, String text,
+ String language) throws Exception {
+ try {
+ AnalysisEngine ae = null;
+ // Create an XML input source from the specifier file.
+ XMLInputSource in = new XMLInputSource(descFilePath);
+ // Parse the specifier.
+ ResourceSpecifier specifier = UIMAFramework.getXMLParser()
+ .parseResourceSpecifier(in);
+ // Create the Text Analysis Engine.
+ ae = UIMAFramework.produceAnalysisEngine(specifier, null, null);
+
+ // Create a new CAS.
+ CAS cas = ae.newCAS();
+ // Set the document text on the CAS.
+ cas.setDocumentText(text);
+ cas.setDocumentLanguage(language);
+ // Process the sample document.
+ ae.process(cas);
+
+ return cas;
+ } catch (Exception ex) {
+ JUnitExtension.handleException(ex);
+ }
+
+ return null;
+
+ }
+
+ /**
+ * create a CAS object from the given XCAS and typesystem files
+ *
+ * @param tsFile -
+ * a typesystem file
+ * @param xcasFile -
+ * a xcas file
+ *
+ * @return CAS - CAS object created from the given input data
+ * @throws Exception
+ */
+ public static CAS getCASfromXCAS(File tsFile, File xcasFile)
+ throws Exception {
+ try {
+ Object tsDescriptor = UIMAFramework.getXMLParser().parse(
+ new XMLInputSource(tsFile));
+ TypeSystemDescription tsDesc = (TypeSystemDescription) tsDescriptor;
+ CAS cas = CasCreationUtils.createCas(tsDesc, null,
+ new FsIndexDescription[0]);
+
+ SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
+ XCASDeserializer xcasDeserializer = new XCASDeserializer(cas
+ .getTypeSystem());
+ parser.parse(xcasFile, xcasDeserializer.getXCASHandler(cas));
+
+ return cas;
+ } catch (Exception ex) {
+ JUnitExtension.handleException(ex);
+ }
+
+ return null;
+ }
+
+ /**
+ * Reads the content form a file to a String with respect to the file
+ * encoding.
+ *
+ * @param file
+ * a file with the source
+ * @param encoding
+ * file encoding
+ * @return String - file content
+ * @throws Exception
+ */
+ public static String readFileContent(File file, String encoding)
+ throws Exception {
+ try {
+ return FileUtils.file2String(file, encoding);
+ } catch (Exception ex) {
+ JUnitExtension.handleException(ex);
+ }
+
+ return null;
+ }
+
+ /**
+ * checkResult compares the analyzed document with the reference output.
+ *
+ * @param cas
+ * a cas with the analyzed data
+ * @param AnnotationTypes
+ * respected annotation types
+ * @param refFile
+ * reference output
+ * @param testFile
+ * test file for the current output
+ * @throws Exception
+ */
+ public static void checkResult(CAS cas, String[] AnnotationTypes,
+ File refFile, File testFile) throws Exception {
+
+ try {
+
+ testFile.delete(); // delete file if exist
+ testFile.createNewFile(); // create new file
+
+ // Create an XML input source from the specifier file.
+ XMLInputSource in = new XMLInputSource(JUnitExtension
+ .getURL("AnnotationWriter.xml"));
+ // Parse the specifier.
+ ResourceSpecifier specifier = UIMAFramework.getXMLParser()
+ .parseResourceSpecifier(in);
+
+ CasConsumer consumer = UIMAFramework.produceCasConsumer(specifier);
+
+ consumer.setConfigParameterValue("AnnotationTypes", AnnotationTypes);
+
+ consumer.setConfigParameterValue("outputFile", testFile
+ .getAbsolutePath());
+
+ consumer.reconfigure();
+
+ consumer.processCas(cas);
+ consumer.destroy();
+
+ // check file output
+ boolean isIdentical = FileCompare.compare(refFile, testFile);
+
+ if (isIdentical) {
+ testFile.delete();
+ }
+
+ Assert.assertTrue(isIdentical);
+
+ } catch (Exception ex) {
+ JUnitExtension.handleException(ex);
+ }
+
+ }
+}
Propchange: incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotatorTester.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/PerformanceTestResult.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/PerformanceTestResult.java?rev=690399&r1=690398&r2=690399&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/PerformanceTestResult.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/PerformanceTestResult.java Fri Aug 29 14:43:30 2008
@@ -1,128 +1,128 @@
-/*
- * 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.test.junit_extension;
-
-import java.io.File;
-
-import org.apache.uima.internal.util.TimeSpan;
-
-/**
- * PerformanceTestResult interfance contains all the methods to access the performance test results.
- *
- */
-public interface PerformanceTestResult {
-
- /**
- * @return Returns the number of processed characters.
- */
- public int getNumberOfProcessedCharacters();
-
- /**
- * @return Returns the number of processed files.
- */
- public int getNumberOfProcessedFiles();
-
- /**
- * @return Returns the UIMA datapath setting used for the performance test.
- */
- public String getUIMADatapath();
-
- /**
- * @return Returns the analysis engine initialization time.
- */
- public TimeSpan getAeInitTime();
-
- /**
- * @return Returns the file I/O time.
- */
- public TimeSpan getFileIoTime();
-
- /**
- * @return Returns the number of created annotations.
- */
- public int getNumberOfCreatedAnnotations();
-
- /**
- * @return Returns the setting for the number of repeated runs.
- */
- public int getNumberOfRepeatedRuns();
-
- /**
- * @return Returns the overall time of the performance run
- */
- public TimeSpan getOverallTime();
-
- /**
- * @return Returns the analysis engine processing time.
- */
- public TimeSpan getAeProcessingTime();
-
- /**
- * @return Returns the setting of the repeat mode mode.
- */
- public boolean isRepeatSingleMode();
-
- /**
- * @return Returns the analysis engine descriptor file path.
- */
- public String getAeDescFilePath();
-
- /**
- * @return Returns the test file directory used for the performance run.
- */
- public String getTestFileDirectoryPath();
-
- /**
- * @return Returns the analysis engine warmup time.
- */
- public TimeSpan getAeWarmupTime();
-
- /**
- * @return Returns the setting the the analysis engine warmup.
- */
- public boolean isDoAeWarmup();
-
- /**
- * write performance results as colum.
- *
- * @param level
- * Test level name of the performance test
- * @param file
- * Output file where the results are written to
- *
- * @throws Exception
- */
- public void writePerfResultsAsColumn(String level, File file) throws Exception;
-
- /**
- * @return Returns the analysis engine cleanup time.
- */
- public TimeSpan getAeCleanupTime();
-
- /**
- * @return Returns the document preparation time.
- */
- public TimeSpan getDocumentPreparationTime();
-
- /**
- * @return Returns the processed file collection size.
- */
- public long getProcessedFileSize();
-}
+/*
+ * 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.test.junit_extension;
+
+import java.io.File;
+
+import org.apache.uima.internal.util.TimeSpan;
+
+/**
+ * PerformanceTestResult interfance contains all the methods to access the performance test results.
+ *
+ */
+public interface PerformanceTestResult {
+
+ /**
+ * @return Returns the number of processed characters.
+ */
+ public int getNumberOfProcessedCharacters();
+
+ /**
+ * @return Returns the number of processed files.
+ */
+ public int getNumberOfProcessedFiles();
+
+ /**
+ * @return Returns the UIMA datapath setting used for the performance test.
+ */
+ public String getUIMADatapath();
+
+ /**
+ * @return Returns the analysis engine initialization time.
+ */
+ public TimeSpan getAeInitTime();
+
+ /**
+ * @return Returns the file I/O time.
+ */
+ public TimeSpan getFileIoTime();
+
+ /**
+ * @return Returns the number of created annotations.
+ */
+ public int getNumberOfCreatedAnnotations();
+
+ /**
+ * @return Returns the setting for the number of repeated runs.
+ */
+ public int getNumberOfRepeatedRuns();
+
+ /**
+ * @return Returns the overall time of the performance run
+ */
+ public TimeSpan getOverallTime();
+
+ /**
+ * @return Returns the analysis engine processing time.
+ */
+ public TimeSpan getAeProcessingTime();
+
+ /**
+ * @return Returns the setting of the repeat mode mode.
+ */
+ public boolean isRepeatSingleMode();
+
+ /**
+ * @return Returns the analysis engine descriptor file path.
+ */
+ public String getAeDescFilePath();
+
+ /**
+ * @return Returns the test file directory used for the performance run.
+ */
+ public String getTestFileDirectoryPath();
+
+ /**
+ * @return Returns the analysis engine warmup time.
+ */
+ public TimeSpan getAeWarmupTime();
+
+ /**
+ * @return Returns the setting the the analysis engine warmup.
+ */
+ public boolean isDoAeWarmup();
+
+ /**
+ * write performance results as colum.
+ *
+ * @param level
+ * Test level name of the performance test
+ * @param file
+ * Output file where the results are written to
+ *
+ * @throws Exception
+ */
+ public void writePerfResultsAsColumn(String level, File file) throws Exception;
+
+ /**
+ * @return Returns the analysis engine cleanup time.
+ */
+ public TimeSpan getAeCleanupTime();
+
+ /**
+ * @return Returns the document preparation time.
+ */
+ public TimeSpan getDocumentPreparationTime();
+
+ /**
+ * @return Returns the processed file collection size.
+ */
+ public long getProcessedFileSize();
+}
Propchange: incubator/uima/uimaj/trunk/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/PerformanceTestResult.java
------------------------------------------------------------------------------
svn:eol-style = native