This is an automated email from the ASF dual-hosted git repository. rec pushed a commit to branch refactoring/UIMA-6373-Format-UIMA-Core-Java-SDK-codebase in repository https://gitbox.apache.org/repos/asf/uima-uimaj.git
commit 2950fa0edf18310b2a2566fdd1ee06422a5574ff Author: Richard Eckart de Castilho <[email protected]> AuthorDate: Thu Feb 10 15:01:09 2022 +0100 [UIMA-6373] Format UIMA Core Java SDK codebase - Auto-format --- .../test/junit_extension/AnnotationWriter.java | 678 ++++++++++----------- .../AnnotatorPerformanceTester.java | 41 +- .../uima/test/junit_extension/AnnotatorTester.java | 676 ++++++++++---------- .../junit_extension/PerformanceTestResult.java | 20 +- .../junit_extension/PerformanceTestResultImpl.java | 148 +++-- 5 files changed, 795 insertions(+), 768 deletions(-) diff --git a/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotationWriter.java b/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotationWriter.java index ba8a58c..1f83888 100644 --- a/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotationWriter.java +++ b/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotationWriter.java @@ -43,363 +43,331 @@ 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 + * 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 -{ - - /** The out file. */ - //output file - private File outFile; - - /** The file writer. */ - //output file writer - private OutputStreamWriter fileWriter; - - /** The tofs. */ - //respected annotations - private String[] tofs; - - /** The reconfig. */ - //check if reconfigure must be called - private boolean reconfig = false; - - /** The Constant featureOnlyKey. */ - 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 - */ - @Override - 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), - StandardCharsets.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 someTofs the some 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; - } - - /* (non-Javadoc) - * @see org.apache.uima.collection.base_cpm.CasObjectProcessor#processCas(org.apache.uima.cas.CAS) - */ - @Override - 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); - } - - } - - /* (non-Javadoc) - * @see org.apache.uima.collection.CasConsumer_ImplBase#batchProcessComplete(org.apache.uima.util.ProcessTrace) - */ - @Override - public void batchProcessComplete(ProcessTrace aTrace) throws ResourceProcessException, IOException - { - // nothing to do here - } - - /* (non-Javadoc) - * @see org.apache.uima.collection.CasConsumer_ImplBase#collectionProcessComplete(org.apache.uima.util.ProcessTrace) - */ - @Override - public void collectionProcessComplete(ProcessTrace aTrace) throws ResourceProcessException, IOException - { - if (this.fileWriter != null) - { - this.fileWriter.close(); - } - } - - /* (non-Javadoc) - * @see org.apache.uima.collection.CasConsumer_ImplBase#reconfigure() - */ - @Override - 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), StandardCharsets.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); - - } - - /* (non-Javadoc) - * @see org.apache.uima.collection.CasConsumer_ImplBase#destroy() - */ - @Override - public void destroy() - { - if (this.fileWriter != null) - { - try - { - this.fileWriter.close(); - } - catch (IOException e) - { - // ignore IOException on destroy - } - } - } +public class AnnotationWriter extends CasConsumer_ImplBase implements CasConsumer { + + /** The out file. */ + // output file + private File outFile; + + /** The file writer. */ + // output file writer + private OutputStreamWriter fileWriter; + + /** The tofs. */ + // respected annotations + private String[] tofs; + + /** The reconfig. */ + // check if reconfigure must be called + private boolean reconfig = false; + + /** The Constant featureOnlyKey. */ + 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 + */ + @Override + 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), + StandardCharsets.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 someTofs + * the some 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; + } + + /* + * (non-Javadoc) + * + * @see org.apache.uima.collection.base_cpm.CasObjectProcessor#processCas(org.apache.uima.cas.CAS) + */ + @Override + 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); + } + + } + + /* + * (non-Javadoc) + * + * @see org.apache.uima.collection.CasConsumer_ImplBase#batchProcessComplete(org.apache.uima.util. + * ProcessTrace) + */ + @Override + public void batchProcessComplete(ProcessTrace aTrace) + throws ResourceProcessException, IOException { + // nothing to do here + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.uima.collection.CasConsumer_ImplBase#collectionProcessComplete(org.apache.uima.util. + * ProcessTrace) + */ + @Override + public void collectionProcessComplete(ProcessTrace aTrace) + throws ResourceProcessException, IOException { + if (this.fileWriter != null) { + this.fileWriter.close(); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.uima.collection.CasConsumer_ImplBase#reconfigure() + */ + @Override + 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), + StandardCharsets.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); + + } + + /* + * (non-Javadoc) + * + * @see org.apache.uima.collection.CasConsumer_ImplBase#destroy() + */ + @Override + public void destroy() { + if (this.fileWriter != null) { + try { + this.fileWriter.close(); + } catch (IOException e) { + // ignore IOException on destroy + } + } + } } diff --git a/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotatorPerformanceTester.java b/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotatorPerformanceTester.java index 1b3ceef..f79c7fc 100644 --- a/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotatorPerformanceTester.java +++ b/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotatorPerformanceTester.java @@ -36,7 +36,6 @@ import org.apache.uima.util.Logger; import org.apache.uima.util.XMLInputSource; import org.junit.Assert; - /** * AnnotatorPerfTester is a helper class to execute annotator performance tests. The performance * test results are returned as {@link PerformanceTestResultImpl} object. @@ -55,7 +54,9 @@ public class AnnotatorPerformanceTester { private FileFileFilter() { } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see java.io.FileFilter#accept(java.io.File) */ @Override @@ -82,16 +83,23 @@ public class AnnotatorPerformanceTester { /** * runs an annotator performance test. * - * @param repeatSingle if true, every document is process "numsToRun" times before the next document is + * @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 + * @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 passthru + * @throws Exception + * passthru */ public static PerformanceTestResult runPerformanceTest(boolean repeatSingle, int numsToRun, File taeDescFilePath, File testFileDir, String dataPath, boolean doWarmup) @@ -118,8 +126,7 @@ public class AnnotatorPerformanceTester { } // get current log level setting - Level defaultLogLevel = (Level) logLevels.get(LogManager.getLogManager() - .getProperty(".level")); + 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 @@ -130,7 +137,7 @@ public class AnnotatorPerformanceTester { Logger logger = UIMAFramework.getLogger(); logger.setLevel(Level.OFF); - //create timer + // create timer Timer globalTimer = new Timer(); Timer initTimer = new Timer(); Timer warmupTimer = new Timer(); @@ -138,16 +145,16 @@ public class AnnotatorPerformanceTester { Timer processResetTimer = new Timer(); Timer cleanupTimer = new Timer(); Timer documentPreparationTimer = new Timer(); - - //start timer for global time + + // start timer for global time globalTimer.start(); // init analysis engine try { - // start initialization timer + // start initialization timer initTimer.start(); - + // set datapath ResourceManager resMgr = UIMAFramework.newDefaultResourceManager(); if (dataPath != null) { @@ -178,7 +185,7 @@ public class AnnotatorPerformanceTester { result.setInitTime(initTimer.getTimeSpan()); if (doWarmup) { - // start warmup timer + // start warmup timer warmupTimer.start(); // process dummy document diff --git a/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotatorTester.java b/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotatorTester.java index 99b6627..4dd448a 100644 --- a/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotatorTester.java +++ b/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/AnnotatorTester.java @@ -43,352 +43,350 @@ import org.apache.uima.util.InvalidXMLException; import org.apache.uima.util.XMLInputSource; import org.junit.Assert; - /** * AnnotatorTester is the helper class to test annotators. */ public class AnnotatorTester { - - /** The desc file. */ - // annotator descriptor - private File descFile; - - /** The ae. */ - // analysis engine instance - private AnalysisEngine ae; - - /** The mgr. */ - // Resource Manager - private ResourceManager mgr; - - /** - * Constructor save the specified descriptor file path and initialize the - * analysis engine. - * - * @param descFilePath - * descriptor file path - * @throws Exception passthru - * 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 passthru - * 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 passthru - */ - private void setup() throws Exception { - 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); - } - - /** - * 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 passthru - */ - 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 passthru - * @throws ResourceInitializationException passthru - * @throws IOException passthru - */ - public void changeDelegateParameterSetting(String delegeteKey, - String groupName, String paramName, Object paramValue) - throws InvalidXMLException, ResourceInitializationException, - IOException { - // create CasConsumer description - AnalysisEngineDescription aeSpecifier = UIMAFramework.getXMLParser() + + /** The desc file. */ + // annotator descriptor + private File descFile; + + /** The ae. */ + // analysis engine instance + private AnalysisEngine ae; + + /** The mgr. */ + // Resource Manager + private ResourceManager mgr; + + /** + * Constructor save the specified descriptor file path and initialize the analysis engine. + * + * @param descFilePath + * descriptor file path + * @throws Exception + * passthru 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 + * passthru 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 + * passthru + */ + private void setup() throws Exception { + 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); + } + + /** + * 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 + * passthru + */ + 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 + * passthru + * @throws ResourceInitializationException + * passthru + * @throws IOException + * passthru + */ + 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); - } + // 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 the config desc file path - * @return AnalysisEngine - * @throws Exception passthru - */ - public static AnalysisEngine doConfigurationTest(String configDescFilePath) - throws Exception { - 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; - } - - /** - * Creates a new fresh CAS instance which can be used for testing. - * @return a new fresh CAS instance which can be used for testing - * @throws Exception passthru - */ - public CAS createCAS() throws Exception { - return ae.newCAS(); + // produce new AE + this.ae = UIMAFramework.produceAnalysisEngine(aeSpecifier, this.mgr, null); + + } + + /** + * does configuration parameter test. + * + * @param configDescFilePath + * the config desc file path + * @return AnalysisEngine + * @throws Exception + * passthru + */ + public static AnalysisEngine doConfigurationTest(String configDescFilePath) throws Exception { + 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; + } + + /** + * Creates a new fresh CAS instance which can be used for testing. + * + * @return a new fresh CAS instance which can be used for testing + * @throws Exception + * passthru + */ + public CAS createCAS() throws Exception { + return ae.newCAS(); + } + + /** + * 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 + * passthru + */ + public CAS performTest(String text, String language) throws Exception { + // 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; + } + + /** + * 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 + * passthru + */ + public CAS performTest(CAS cas) throws Exception { + // Process the sample document. + this.ae.process(cas); + + return cas; + } + + /** + * 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 + * passthru + */ + public static CAS performTest(String descFilePath, String text, String language) + throws Exception { + 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; + } + + /** + * 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 + * passthru + */ + public static CAS getCASfromXCAS(File tsFile, File xcasFile) throws Exception { + Object tsDescriptor = UIMAFramework.getXMLParser().parse(new XMLInputSource(tsFile)); + TypeSystemDescription tsDesc = (TypeSystemDescription) tsDescriptor; + CAS cas = CasCreationUtils.createCas(tsDesc, null, new FsIndexDescription[0]); + + SAXParser parser = XMLUtils.createSAXParserFactory().newSAXParser(); + XCASDeserializer xcasDeserializer = new XCASDeserializer(cas.getTypeSystem()); + parser.parse(xcasFile, xcasDeserializer.getXCASHandler(cas)); + + return cas; + } + + /** + * 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 + * passthru + */ + public static String readFileContent(File file, String encoding) throws Exception { + return FileUtils.file2String(file, encoding); + } + + /** + * 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 + * passthru + */ + public static void checkResult(CAS cas, String[] AnnotationTypes, File refFile, File testFile) + throws Exception { + + 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(); } - - /** - * 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 passthru - */ - public CAS performTest(String text, String language) throws Exception { - // 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; - } - - /** - * 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 passthru - */ - public CAS performTest(CAS cas) throws Exception { - // Process the sample document. - this.ae.process(cas); - - return cas; - } - - /** - * 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 passthru - */ - public static CAS performTest(String descFilePath, String text, - String language) throws Exception { - 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; - } - - /** - * 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 passthru - */ - public static CAS getCASfromXCAS(File tsFile, File xcasFile) - throws Exception { - Object tsDescriptor = UIMAFramework.getXMLParser().parse( - new XMLInputSource(tsFile)); - TypeSystemDescription tsDesc = (TypeSystemDescription) tsDescriptor; - CAS cas = CasCreationUtils.createCas(tsDesc, null, - new FsIndexDescription[0]); - - SAXParser parser = XMLUtils.createSAXParserFactory().newSAXParser(); - XCASDeserializer xcasDeserializer = new XCASDeserializer(cas - .getTypeSystem()); - parser.parse(xcasFile, xcasDeserializer.getXCASHandler(cas)); - - return cas; - } - - /** - * 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 passthru - */ - public static String readFileContent(File file, String encoding) - throws Exception { - return FileUtils.file2String(file, encoding); - } - - /** - * 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 passthru - */ - public static void checkResult(CAS cas, String[] AnnotationTypes, - File refFile, File testFile) throws Exception { - - 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); - } + + Assert.assertTrue(isIdentical); + } } diff --git a/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/PerformanceTestResult.java b/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/PerformanceTestResult.java index d0da3db..511b0e8 100644 --- a/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/PerformanceTestResult.java +++ b/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/PerformanceTestResult.java @@ -23,20 +23,19 @@ 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 { - /** - * Gets the number of processed characters. - * - * @return Returns the number of processed characters. - */ + /** + * Gets the number of processed characters. + * + * @return Returns the number of processed characters. + */ int getNumberOfProcessedCharacters(); - + /** * Gets the number of processed files. * @@ -50,7 +49,7 @@ public interface PerformanceTestResult { * @return Returns the UIMA datapath setting used for the performance test. */ String getUIMADatapath(); - + /** * Gets the ae init time. * @@ -136,10 +135,11 @@ public interface PerformanceTestResult { * @param file * Output file where the results are written to * - * @throws Exception passthru + * @throws Exception + * passthru */ void writePerfResultsAsColumn(String level, File file) throws Exception; - + /** * Gets the ae cleanup time. * diff --git a/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/PerformanceTestResultImpl.java b/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/PerformanceTestResultImpl.java index 8f6a15f..d741da5 100644 --- a/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/PerformanceTestResultImpl.java +++ b/uimaj-component-test-util/src/main/java/org/apache/uima/test/junit_extension/PerformanceTestResultImpl.java @@ -26,10 +26,9 @@ import java.util.GregorianCalendar; import org.apache.uima.internal.util.TimeSpan; - /** - * PerformanceTestResultImpl implements the PerformanceTestResult interface and provides the results of a performance - * test run. + * PerformanceTestResultImpl implements the PerformanceTestResult interface and provides the results + * of a performance test run. * */ public class PerformanceTestResultImpl implements PerformanceTestResult { @@ -88,8 +87,11 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { /** The document preparation time. */ private TimeSpan documentPreparationTime = null; - /* (non-Javadoc) - * @see org.apache.uima.test.junit_extension.PerformanceTestResult#getNumberOfProcessedCharacters() + /* + * (non-Javadoc) + * + * @see + * org.apache.uima.test.junit_extension.PerformanceTestResult#getNumberOfProcessedCharacters() */ @Override public int getNumberOfProcessedCharacters() { @@ -99,13 +101,16 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { /** * Sets the number of characters. * - * @param numberOfCharacters The number of characters. + * @param numberOfCharacters + * The number of characters. */ public void setNumberOfCharacters(int numberOfCharacters) { this.numberOfCharacters = numberOfCharacters; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.apache.uima.test.junit_extension.PerformanceTestResult#getNumberOfProcessedFiles() */ @Override @@ -116,13 +121,16 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { /** * Sets the number of files. * - * @param numberOfFiles The number of files. + * @param numberOfFiles + * The number of files. */ public void setNumberOfFiles(int numberOfFiles) { this.numberOfFiles = numberOfFiles; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.apache.uima.test.junit_extension.PerformanceTestResult#getUIMADatapath() */ @Override @@ -133,13 +141,16 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { /** * Sets the datapath. * - * @param datapath The UIMA datapath. + * @param datapath + * The UIMA datapath. */ public void setDatapath(String datapath) { this.datapath = datapath; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.apache.uima.test.junit_extension.PerformanceTestResult#getAeInitTime() */ @Override @@ -150,13 +161,16 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { /** * Sets the inits the time. * - * @param initTime The analysis engine init time. + * @param initTime + * The analysis engine init time. */ public void setInitTime(TimeSpan initTime) { this.initTime = initTime; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.apache.uima.test.junit_extension.PerformanceTestResult#getFileIoTime() */ @Override @@ -167,13 +181,16 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { /** * Sets the io time. * - * @param ioTime The file io time to set. + * @param ioTime + * The file io time to set. */ public void setIoTime(TimeSpan ioTime) { this.ioTime = ioTime; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.apache.uima.test.junit_extension.PerformanceTestResult#getNumberOfCreatedAnnotations() */ @Override @@ -184,13 +201,16 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { /** * Sets the number of created annotations. * - * @param numberOfCreatedAnnotations The number of created annotations to set. + * @param numberOfCreatedAnnotations + * The number of created annotations to set. */ public void setNumberOfCreatedAnnotations(int numberOfCreatedAnnotations) { this.numberOfCreatedAnnotations = numberOfCreatedAnnotations; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.apache.uima.test.junit_extension.PerformanceTestResult#getNumberOfRepeatedRuns() */ @Override @@ -201,13 +221,16 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { /** * Sets the nums to run. * - * @param numsToRun The number of repeated runs. + * @param numsToRun + * The number of repeated runs. */ public void setNumsToRun(int numsToRun) { this.numsToRun = numsToRun; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.apache.uima.test.junit_extension.PerformanceTestResult#getOverallTime() */ @Override @@ -218,13 +241,16 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { /** * Sets the overall time. * - * @param overallTime The overall processing time. + * @param overallTime + * The overall processing time. */ public void setOverallTime(TimeSpan overallTime) { this.overallTime = overallTime; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.apache.uima.test.junit_extension.PerformanceTestResult#getAeProcessingTime() */ @Override @@ -235,13 +261,16 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { /** * Sets the processing time. * - * @param processingTime The analysis engine processing time. + * @param processingTime + * The analysis engine processing time. */ public void setProcessingTime(TimeSpan processingTime) { this.processingTime = processingTime; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.apache.uima.test.junit_extension.PerformanceTestResult#isRepeatSingleMode() */ @Override @@ -252,13 +281,16 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { /** * Sets the repeat single mode. * - * @param repeatSingleMode The repeat single mode setting + * @param repeatSingleMode + * The repeat single mode setting */ public void setRepeatSingleMode(boolean repeatSingleMode) { this.repeatSingleMode = repeatSingleMode; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.apache.uima.test.junit_extension.PerformanceTestResult#getAeDescFilePath() */ @Override @@ -269,13 +301,16 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { /** * Sets the ae desc file path. * - * @param aeDescFile The analysis engine descriptor file. + * @param aeDescFile + * The analysis engine descriptor file. */ public void setAeDescFilePath(File aeDescFile) { this.aeDescFile = aeDescFile; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.apache.uima.test.junit_extension.PerformanceTestResult#getTestFileDirectoryPath() */ @Override @@ -286,13 +321,16 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { /** * Sets the test file dir. * - * @param testFileDir The test file directory. + * @param testFileDir + * The test file directory. */ public void setTestFileDir(File testFileDir) { this.testFileDir = testFileDir; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.apache.uima.test.junit_extension.PerformanceTestResult#getAeWarmupTime() */ @Override @@ -303,13 +341,16 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { /** * Sets the warmup time. * - * @param warmupTime The analysis engine warmup time. + * @param warmupTime + * The analysis engine warmup time. */ public void setWarmupTime(TimeSpan warmupTime) { this.warmupTime = warmupTime; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.apache.uima.test.junit_extension.PerformanceTestResult#isDoAeWarmup() */ @Override @@ -320,7 +361,8 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { /** * Sets the do warmup. * - * @param doWarmup the doWarmup setting + * @param doWarmup + * the doWarmup setting */ public void setDoWarmup(boolean doWarmup) { this.doWarmup = doWarmup; @@ -344,9 +386,10 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { resultString.append("Use " + this.aeDescFile.getAbsolutePath() + " descriptor" + NEWLINE); resultString.append("Fileset " + this.testFileDir + " is used" + NEWLINE); resultString.append("Datapath setting is: " + this.datapath + NEWLINE); - resultString.append("Number of documents (overall): " + this.getNumberOfProcessedFiles() + NEWLINE); resultString - .append("Number of characters (overall): " + this.getNumberOfProcessedCharacters() + NEWLINE); + .append("Number of documents (overall): " + this.getNumberOfProcessedFiles() + NEWLINE); + resultString.append( + "Number of characters (overall): " + this.getNumberOfProcessedCharacters() + NEWLINE); resultString.append("Total document size (overall): " + (float) (this.getProcessedFileSize() / 1024) + " KB" + NEWLINE); resultString.append(NEWLINE + "Initialize: " + NEWLINE); @@ -361,10 +404,11 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { resultString.append("Analysis Engine processing time: " + this.processingTime + NEWLINE); if (this.processingTime.getFullMilliseconds() > 0 && this.getProcessedFileSize() > 0) { resultString.append("Processing throughput: " - + (long) ((this.getProcessedFileSize() / 1024) / ((float) this.processingTime - .getFullMilliseconds() / 1000)) + " KB/s" + NEWLINE); - long mbPerSecond = (long) ((this.getProcessedFileSize() / 1024 / 1024) / ((float) this.processingTime - .getFullMilliseconds() / 1000 / 60 / 60)); + + (long) ((this.getProcessedFileSize() / 1024) + / ((float) this.processingTime.getFullMilliseconds() / 1000)) + + " KB/s" + NEWLINE); + long mbPerSecond = (long) ((this.getProcessedFileSize() / 1024 / 1024) + / ((float) this.processingTime.getFullMilliseconds() / 1000 / 60 / 60)); resultString.append("Processing throughput: " + mbPerSecond + " MB/h" + NEWLINE); } @@ -385,7 +429,8 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { * @param file * Output file where the results are written to * - * @throws Exception passthru + * @throws Exception + * passthru */ @Override public void writePerfResultsAsColumn(String level, File file) throws Exception { @@ -441,8 +486,8 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { FileWriter fileWriter = new FileWriter(file, true); if (writeHeader) { - fileWriter - .write("Timestamp ; Levelname ; singleMode ; warmup; Docs ; Annotations ; Processing time ; init time ; io time"); + fileWriter.write( + "Timestamp ; Levelname ; singleMode ; warmup; Docs ; Annotations ; Processing time ; init time ; io time"); fileWriter.write(System.getProperty("line.separator")); } @@ -454,7 +499,9 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { fileWriter.close(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.apache.uima.test.junit_extension.PerformanceTestResult#getAeCleanupTime() */ @Override @@ -465,13 +512,16 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { /** * Sets the cleanup time. * - * @param cleanupTime the analysis engine cleanup time + * @param cleanupTime + * the analysis engine cleanup time */ public void setCleanupTime(TimeSpan cleanupTime) { this.cleanupTime = cleanupTime; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.apache.uima.test.junit_extension.PerformanceTestResult#getDocumentPreparationTime() */ @Override @@ -482,13 +532,16 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { /** * Sets the document preparation time. * - * @param documentPreparationTime the document preparation time + * @param documentPreparationTime + * the document preparation time */ public void setDocumentPreparationTime(TimeSpan documentPreparationTime) { this.documentPreparationTime = documentPreparationTime; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.apache.uima.test.junit_extension.PerformanceTestResult#getProcessedFileSize() */ @Override @@ -499,7 +552,8 @@ public class PerformanceTestResultImpl implements PerformanceTestResult { /** * Sets the total file size. * - * @param collectionFileSize the collection file size + * @param collectionFileSize + * the collection file size */ public void setTotalFileSize(long collectionFileSize) { this.collectionFileSize = collectionFileSize;
