You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by al...@apache.org on 2007/06/22 23:22:13 UTC
svn commit: r549960 - in /incubator/uima/uimaj/trunk/uimaj-core/src:
main/java/org/apache/uima/cas/CAS.java
main/java/org/apache/uima/cas/impl/CASImpl.java
test/java/org/apache/uima/cas/test/SofaTest.java
Author: alally
Date: Fri Jun 22 14:22:12 2007
New Revision: 549960
URL: http://svn.apache.org/viewvc?view=rev&rev=549960
Log:
Added getViewIterator method
UIMA-465: https://issues.apache.org/jira/browse/UIMA-465
Modified:
incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/CAS.java
incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java
incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/SofaTest.java
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/CAS.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/CAS.java?view=diff&rev=549960&r1=549959&r2=549960
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/CAS.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/CAS.java Fri Jun 22 14:22:12 2007
@@ -20,6 +20,7 @@
package org.apache.uima.cas;
import java.io.InputStream;
+import java.util.Iterator;
import org.apache.uima.cas.admin.CASAdminException;
import org.apache.uima.cas.impl.LowLevelCAS;
@@ -994,5 +995,32 @@
* If the <code>fs</code> parameter is <code>null</code>.
*/
void removeFsFromIndexes(FeatureStructure fs);
+
+ /**
+ * Get iterator over all views in this CAS. Each view provides access to Sofa data
+ * and the index repository that contains metadata (annotations and other feature
+ * structures) pertaining to that Sofa.
+ *
+ * @return an iterator which returns all views. Each object returned by
+ * the iterator is of type CAS.
+ */
+ Iterator getViewIterator();
+
+ /**
+ * Get iterator over all views with the given name prefix. Each view provides access to Sofa data
+ * and the index repository that contains metadata (annotations and other feature
+ * structures) pertaining to that Sofa.
+ * <p>
+ * If passed the prefix <i>namePrefix</i>, the iterator will return all views who
+ * name is of the form <i>namePrefix</i><code>.</code><i>suffix</i>, where
+ * <i>suffix</i> can be any String.
+ *
+ * @param localViewNamePrefix the local name prefix, before any sofa name mapping
+ * is done, for this view (note: this is the same as the associated Sofa name prefix).
+ *
+ * @return an iterator which returns all views with the given name prefix.
+ * Each object returned by the iterator is of type CAS.
+ */
+ Iterator getViewIterator(String localViewNamePrefix);
}
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java?view=diff&rev=549960&r1=549959&r2=549960
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java Fri Jun 22 14:22:12 2007
@@ -35,6 +35,8 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
import java.util.ListIterator;
import org.apache.uima.cas.AbstractCas_ImplBase;
@@ -3754,4 +3756,48 @@
}
return this;
}
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.CAS#getViewIterator()
+ */
+ public Iterator getViewIterator() {
+ List viewList = new ArrayList();
+ //add initial view if it has no sofa
+ if (!((CASImpl)getInitialView()).mySofaIsValid()) {
+ viewList.add(getInitialView());
+ }
+ //add views with Sofas
+ FSIterator sofaIter = getSofaIterator();
+ while(sofaIter.hasNext()) {
+ viewList.add(getView((SofaFS)sofaIter.next()));
+ }
+ return viewList.iterator();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.CAS#getViewIterator(java.lang.String)
+ */
+ public Iterator getViewIterator(String localViewNamePrefix) {
+ // do sofa mapping for current component
+ String absolutePrefix = null;
+ if (getCurrentComponentInfo() != null) {
+ absolutePrefix = getCurrentComponentInfo().mapToSofaID(localViewNamePrefix);
+ }
+ if (absolutePrefix == null) {
+ absolutePrefix = localViewNamePrefix;
+ }
+ absolutePrefix += '.';
+
+ //find Sofas with this prefix
+ List viewList = new ArrayList();
+ FSIterator sofaIter = getSofaIterator();
+ while(sofaIter.hasNext()) {
+ SofaFS sofa = (SofaFS)sofaIter.next();
+ if (sofa.getSofaID().startsWith(absolutePrefix))
+ viewList.add(getView(sofa));
+ }
+ return viewList.iterator();
+ }
+
+
}
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/SofaTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/SofaTest.java?view=diff&rev=549960&r1=549959&r2=549960
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/SofaTest.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/SofaTest.java Fri Jun 22 14:22:12 2007
@@ -28,10 +28,17 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
import java.util.StringTokenizer;
import junit.framework.TestCase;
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.UimaContextAdmin;
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
import org.apache.uima.cas.ArrayFS;
import org.apache.uima.cas.ByteArrayFS;
import org.apache.uima.cas.CAS;
@@ -59,6 +66,7 @@
import org.apache.uima.resource.metadata.TypeSystemDescription;
import org.apache.uima.test.junit_extension.JUnitExtension;
import org.apache.uima.util.CasCreationUtils;
+import org.apache.uima.util.XMLInputSource;
import org.apache.uima.util.XMLSerializer;
import org.xml.sax.SAXException;
@@ -560,6 +568,37 @@
SofaFS testSofa = this.cas.createSofa(id, "text");
CAS newView = this.cas.getView(testSofa);
assertTrue( newView.getViewName().equals("TestView"));
+ }
+
+ public void testGetViewIterator() throws Exception {
+ this.cas.reset();
+ CAS view1 = this.cas.createView("View1");
+ CAS view2 = this.cas.createView("View2");
+ Iterator iter = this.cas.getViewIterator();
+ assertEquals(this.cas, iter.next());
+ assertEquals(view1, iter.next());
+ assertEquals(view2, iter.next());
+ assertFalse(iter.hasNext());
+
+ CAS viewE1 = this.cas.createView("EnglishDocument.1");
+ CAS viewE2 = this.cas.createView("EnglishDocument.2");
+ iter = this.cas.getViewIterator("EnglishDocument");
+ assertEquals(viewE1, iter.next());
+ assertEquals(viewE2, iter.next());
+ assertFalse(iter.hasNext());
+
+ //try with Sofa mappings
+ UimaContextAdmin rootCtxt = UIMAFramework.newUimaContext(
+ UIMAFramework.getLogger(), UIMAFramework.newDefaultResourceManager(),
+ UIMAFramework.newConfigurationManager());
+ Map sofamap = new HashMap();
+ sofamap.put("SourceDocument","EnglishDocument");
+ UimaContextAdmin childCtxt = rootCtxt.createChild("test", sofamap);
+ cas.setCurrentComponentInfo(childCtxt.getComponentInfo());
+ iter = this.cas.getViewIterator("SourceDocument");
+ assertEquals(viewE1, iter.next());
+ assertEquals(viewE2, iter.next());
+ assertFalse(iter.hasNext());
}
public static void main(String[] args) {