You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by tw...@apache.org on 2008/06/12 17:27:51 UTC
svn commit: r667132 - in /incubator/uima/uimaj/trunk/uimaj-core/src:
main/java/org/apache/uima/jcas/impl/JCasHashMap.java
test/java/org/apache/uima/cas/test/GrowingTheCasTestNoJcasCache.java
Author: twgoetz
Date: Thu Jun 12 08:27:51 2008
New Revision: 667132
URL: http://svn.apache.org/viewvc?rev=667132&view=rev
Log:
Jira UIMA-1068: enable the switch, add test case. Still missing documentation.
https://issues.apache.org/jira/browse/UIMA-1068
Added:
incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/GrowingTheCasTestNoJcasCache.java
Modified:
incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMap.java
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMap.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMap.java?rev=667132&r1=667131&r2=667132&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMap.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMap.java Thu Jun 12 08:27:51 2008
@@ -72,7 +72,7 @@
private final boolean useCache;
JCasHashMap(int initialSize, boolean doUseCache) {
- this.useCache = true;
+ this.useCache = doUseCache;
// round initialSize to a power of 2
int n = initialSize;
int i = 0;
Added: incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/GrowingTheCasTestNoJcasCache.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/GrowingTheCasTestNoJcasCache.java?rev=667132&view=auto
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/GrowingTheCasTestNoJcasCache.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/GrowingTheCasTestNoJcasCache.java Thu Jun 12 08:27:51 2008
@@ -0,0 +1,148 @@
+/*
+ * 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.cas.test;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.resource.Resource;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.test.junit_extension.JUnitExtension;
+import org.apache.uima.util.FileUtils;
+import org.apache.uima.util.InvalidXMLException;
+import org.apache.uima.util.XMLInputSource;
+import org.apache.uima.util.XMLParser;
+
+/**
+ * Class comment for IteratorTest.java goes here.
+ *
+ */
+public class GrowingTheCasTestNoJcasCache extends TestCase {
+
+ private AnalysisEngine ae = null;
+
+ private JCas smallHeapCas = null;
+
+ public GrowingTheCasTestNoJcasCache(String arg0) {
+ super(arg0);
+ }
+
+ public void setUp() {
+ File descriptorFile = JUnitExtension.getFile("CASTests/desc/TokensAndSentences.xml");
+ assertTrue("Descriptor must exist: " + descriptorFile.getAbsolutePath(), descriptorFile
+ .exists());
+
+ try {
+ XMLParser parser = UIMAFramework.getXMLParser();
+ AnalysisEngineDescription spec = (AnalysisEngineDescription) parser.parse(new XMLInputSource(
+ descriptorFile));
+ Properties performanceTuningSettings = new Properties();
+ performanceTuningSettings.setProperty(UIMAFramework.CAS_INITIAL_HEAP_SIZE, "0");
+ performanceTuningSettings.setProperty(UIMAFramework.JCAS_CACHE_ENABLED, "false");
+ Properties additionalParams = new Properties();
+ additionalParams.put(Resource.PARAM_PERFORMANCE_TUNING_SETTINGS, performanceTuningSettings);
+ this.ae = UIMAFramework.produceAnalysisEngine(spec, null, additionalParams);
+ this.smallHeapCas = this.ae.newJCas();
+ } catch (IOException e) {
+ e.printStackTrace();
+ assertTrue(false);
+ } catch (InvalidXMLException e) {
+ e.printStackTrace();
+ assertTrue(false);
+ } catch (ResourceInitializationException e) {
+ e.printStackTrace();
+ assertTrue(false);
+ }
+
+ }
+
+ public void tearDown() {
+ if (this.ae != null) {
+ this.ae.destroy();
+ this.ae = null;
+ }
+ }
+
+ public void testAnnotator() {
+ File textFile = JUnitExtension.getFile("data/moby.txt");
+ String text = null;
+ try {
+ text = FileUtils.file2String(textFile, "utf-8");
+ } catch (IOException e) {
+ e.printStackTrace();
+ assertTrue(false);
+ }
+ StringBuffer buf = new StringBuffer(text.length() * 10);
+ for (int i = 0; i < 10; i++) {
+ buf.append(text);
+ }
+ JCas jcas = null;
+ try {
+ jcas = this.ae.newJCas();
+ } catch (ResourceInitializationException e) {
+ e.printStackTrace();
+ assertTrue(false);
+ }
+ text = buf.toString();
+ jcas.setDocumentText(text);
+ int numberOfSentences = 0;
+ int numberOfTokens = 0;
+ try {
+ // long time = System.currentTimeMillis();
+ this.ae.process(jcas);
+ // time = System.currentTimeMillis() - time;
+ // System.out.println("Time for large CAS: " + new TimeSpan(time));
+ numberOfSentences = jcas.getAnnotationIndex(Sentence.type).size();
+ numberOfTokens = jcas.getAnnotationIndex(Token.type).size();
+ // System.out.println(numberOfSentences);
+ // System.out.println(numberOfTokens);
+ } catch (AnalysisEngineProcessException e) {
+ e.printStackTrace();
+ assertTrue(false);
+ }
+ this.smallHeapCas.setDocumentText(text);
+ try {
+ // long time = System.currentTimeMillis();
+ this.ae.process(this.smallHeapCas);
+ // time = System.currentTimeMillis() - time;
+ // System.out.println("Time for small CAS: " + new TimeSpan(time));
+ assertTrue(this.getClass().toString() + ": number of sentences does not match",
+ numberOfSentences == this.smallHeapCas.getAnnotationIndex(Sentence.type).size());
+ assertTrue(this.getClass().toString() + ": number of tokens does not match",
+ numberOfTokens == this.smallHeapCas.getAnnotationIndex(Token.type).size());
+ } catch (AnalysisEngineProcessException e) {
+ e.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(GrowingTheCasTestNoJcasCache.class);
+ }
+
+}