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 2013/03/28 20:31:16 UTC
svn commit: r1462267 [1/2] - in /uima/uimaj/trunk: ./
PearPackagingMavenPlugin/ aggregate-uimaj-docbooks/
aggregate-uimaj-eclipse-plugins/ aggregate-uimaj/ jVinci/ src/
src/main/scripts/ uima-docbook-overview-and-setup/ uima-docbook-references/
uima-do...
Author: schor
Date: Thu Mar 28 19:31:14 2013
New Revision: 1462267
URL: http://svn.apache.org/r1462267
Log:
[UIMA-2498] reintegrate branch for this Jira back into trunk.
Added:
uima/uimaj/trunk/uima-docbook-tutorials-and-users-guides/src/docbook/tug.type_mapping.xml
- copied unchanged from r1462257, uima/uimaj/branches/filteredCompress-uima-2498/uima-docbook-tutorials-and-users-guides/src/docbook/tug.type_mapping.xml
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes6.java
- copied unchanged from r1462257, uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes6.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CasSeqAddrMaps.java
- copied unchanged from r1462257, uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/main/java/org/apache/uima/cas/impl/CasSeqAddrMaps.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CasTypeSystemMapper.java (with props)
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/SlotKinds.java
- copied unchanged from r1462257, uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/main/java/org/apache/uima/cas/impl/SlotKinds.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntKeyValueIterator.java
- copied unchanged from r1462257, uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/main/java/org/apache/uima/internal/util/IntKeyValueIterator.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/rb_trees/Int2IntRBT.java
- copied unchanged from r1462257, uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/main/java/org/apache/uima/internal/util/rb_trees/Int2IntRBT.java
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/CasTypeSystemMapperTst.java
- copied unchanged from r1462257, uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/test/java/org/apache/uima/cas/impl/CasTypeSystemMapperTst.java
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/SerDesTest6.java
- copied unchanged from r1462257, uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/test/java/org/apache/uima/cas/impl/SerDesTest6.java
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/internal/util/rb_trees/
- copied from r1462257, uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/test/java/org/apache/uima/internal/util/rb_trees/
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/internal/util/rb_trees/Int2IntRBTtest.java
- copied unchanged from r1462257, uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/test/java/org/apache/uima/internal/util/rb_trees/Int2IntRBTtest.java
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/internal/util/rb_trees/IntArrayRBTtest.java
- copied unchanged from r1462257, uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/test/java/org/apache/uima/internal/util/rb_trees/IntArrayRBTtest.java
Removed:
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/SerDesTest.java
Modified:
uima/uimaj/trunk/ (props changed)
uima/uimaj/trunk/PearPackagingMavenPlugin/ (props changed)
uima/uimaj/trunk/aggregate-uimaj/ (props changed)
uima/uimaj/trunk/aggregate-uimaj-docbooks/ (props changed)
uima/uimaj/trunk/aggregate-uimaj-eclipse-plugins/ (props changed)
uima/uimaj/trunk/jVinci/ (props changed)
uima/uimaj/trunk/src/ (props changed)
uima/uimaj/trunk/src/main/scripts/ (props changed)
uima/uimaj/trunk/uima-docbook-overview-and-setup/ (props changed)
uima/uimaj/trunk/uima-docbook-references/ (props changed)
uima/uimaj/trunk/uima-docbook-references/src/docbook/ref.cas.xml
uima/uimaj/trunk/uima-docbook-tools/ (props changed)
uima/uimaj/trunk/uima-docbook-tutorials-and-users-guides/ (props changed)
uima/uimaj/trunk/uima-docbook-tutorials-and-users-guides/src/docbook/tutorials_and_users_guides.xml
uima/uimaj/trunk/uimaj-adapter-soap/ (props changed)
uima/uimaj/trunk/uimaj-adapter-vinci/ (props changed)
uima/uimaj/trunk/uimaj-bootstrap/ (props changed)
uima/uimaj/trunk/uimaj-component-test-util/ (props changed)
uima/uimaj/trunk/uimaj-core/ (props changed)
uima/uimaj/trunk/uimaj-core/src/main/java/ (props changed)
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes4.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASSerializer.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexComparatorImpl.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexRepositoryImpl.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntArrayUtils.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntVector.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/SortedIntSet.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/rb_trees/CompIntArrayRBT.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/rb_trees/IntArrayRBT.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/rb_trees/IntRBTNode.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/rb_trees/IntRedBlackTree.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/SerializationMeasures.java
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/SerDesTest4.java
uima/uimaj/trunk/uimaj-cpe/ (props changed)
uima/uimaj/trunk/uimaj-document-annotation/ (props changed)
uima/uimaj/trunk/uimaj-eclipse-feature-runtime/ (props changed)
uima/uimaj/trunk/uimaj-eclipse-feature-tools/ (props changed)
uima/uimaj/trunk/uimaj-eclipse-update-site/ (props changed)
uima/uimaj/trunk/uimaj-ep-cas-editor/ (props changed)
uima/uimaj/trunk/uimaj-ep-cas-editor-ide/icons/svgicons/document.png (props changed)
uima/uimaj/trunk/uimaj-ep-cas-editor-ide/icons/svgicons/explorer.png (props changed)
uima/uimaj/trunk/uimaj-ep-cas-editor-ide/icons/svgicons/fsview.png (props changed)
uima/uimaj/trunk/uimaj-ep-cas-editor-ide/plugin.xml (props changed)
uima/uimaj/trunk/uimaj-ep-cas-editor-ide/pom.xml (props changed)
uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/CasEditorIdePlugin.java (props changed)
uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java (props changed)
uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/NlpProject.java (props changed)
uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/TypeSystemLocationPropertyPage.java (props changed)
uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/WorkspaceResourceDialog.java (props changed)
uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/ (props changed)
uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/resources/org/apache/uima/caseditor/ide/wizards/ts.xml (props changed)
uima/uimaj/trunk/uimaj-ep-configurator/ (props changed)
uima/uimaj/trunk/uimaj-ep-debug/ (props changed)
uima/uimaj/trunk/uimaj-ep-jcasgen/ (props changed)
uima/uimaj/trunk/uimaj-ep-pear-packager/ (props changed)
uima/uimaj/trunk/uimaj-ep-runtime/ (props changed)
uima/uimaj/trunk/uimaj-examples/ (props changed)
uima/uimaj/trunk/uimaj-internal-tools/ (props changed)
uima/uimaj/trunk/uimaj-test-util/ (props changed)
uima/uimaj/trunk/uimaj-tools/ (props changed)
Propchange: uima/uimaj/trunk/
------------------------------------------------------------------------------
Merged /uima/uimaj/branches/filteredCompress-uima-2498:r1436573-1462257
Propchange: uima/uimaj/trunk/PearPackagingMavenPlugin/
------------------------------------------------------------------------------
Merged /uima/uimaj/branches/filteredCompress-uima-2498/PearPackagingMavenPlugin:r1436573-1462257
Propchange: uima/uimaj/trunk/aggregate-uimaj/
------------------------------------------------------------------------------
Reverse-merged /uima/uimaj/branches/mavenAlign/aggregate-uimaj:r944252
Merged /uima/uimaj/branches/filteredCompress-uima-2498/aggregate-uimaj:r1436573-1462257
Propchange: uima/uimaj/trunk/aggregate-uimaj-docbooks/
------------------------------------------------------------------------------
Merged /uima/uimaj/branches/filteredCompress-uima-2498/aggregate-uimaj-docbooks:r1436573-1462257
Propchange: uima/uimaj/trunk/aggregate-uimaj-eclipse-plugins/
------------------------------------------------------------------------------
Reverse-merged /uima/uimaj/branches/mavenAlign/aggregate-uimaj-eclipse-plugins:r944252
Merged /uima/uimaj/branches/filteredCompress-uima-2498/aggregate-uimaj-eclipse-plugins:r1436573-1462257
Propchange: uima/uimaj/trunk/jVinci/
------------------------------------------------------------------------------
Merged /uima/uimaj/branches/filteredCompress-uima-2498/jVinci:r1436573-1462257
Propchange: uima/uimaj/trunk/src/
------------------------------------------------------------------------------
Merged /uima/uimaj/branches/filteredCompress-uima-2498/src:r1436573-1462257
Propchange: uima/uimaj/trunk/src/main/scripts/
------------------------------------------------------------------------------
Merged /uima/uimaj/branches/filteredCompress-uima-2498/src/main/scripts:r1436573-1462257
Propchange: uima/uimaj/trunk/uima-docbook-overview-and-setup/
------------------------------------------------------------------------------
Reverse-merged /uima/uimaj/branches/mavenAlign/uima-docbook-overview-and-setup:r944252
Merged /uima/uimaj/branches/filteredCompress-uima-2498/uima-docbook-overview-and-setup:r1436573-1462257
Propchange: uima/uimaj/trunk/uima-docbook-references/
------------------------------------------------------------------------------
Reverse-merged /uima/uimaj/branches/mavenAlign/uima-docbook-references:r944251-944252
Merged /uima/uimaj/branches/filteredCompress-uima-2498/uima-docbook-references:r1436573-1462257
Modified: uima/uimaj/trunk/uima-docbook-references/src/docbook/ref.cas.xml
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uima-docbook-references/src/docbook/ref.cas.xml?rev=1462267&r1=1462266&r2=1462267&view=diff
==============================================================================
--- uima/uimaj/trunk/uima-docbook-references/src/docbook/ref.cas.xml (original)
+++ uima/uimaj/trunk/uima-docbook-references/src/docbook/ref.cas.xml Thu Mar 28 19:31:14 2013
@@ -960,4 +960,30 @@ FSIterator it = cas.createFilteredIterat
defined features within them.</para>
</section>
</section>
+
+ <section id="ugr.ref.cas.typemerging">
+ <title>Type Merging</title>
+
+ <para>When annotators are combined in an aggregate, their defined type systems are merged.
+ This is designed to support independent development of annotator components. The merge
+ results in a single defined type system for CASes that flow through a particular set of
+ annotators.</para>
+
+ <para>The basic operation of a type system merge is to iterate through all the defined types,
+ and if two annotators define the same fully qualified type name,
+ to take the features defined for those types
+ and form a logical union of those features. This operation requires that same-named features
+ have the same range type names. The resulting type system has features comprising the union
+ of all features over all the various definitions for this type in different annotators.
+ </para>
+
+ <para>Feature merging checks that for all features having the same name in a type, that the
+ range type is identical; otherwise an error is signaled.</para>
+
+ <para>Types are combined for merging when their fully qualified names are the same.
+ Two different definitions can be merged even if their supertype definitions do not match, if
+ one supertype subsumes the other supertype; otherwise an error is signaled. Likewise, two types
+ with the same name can be merged only if their features can be merged.
+ </para>
+ </section>
</chapter>
\ No newline at end of file
Propchange: uima/uimaj/trunk/uima-docbook-tools/
------------------------------------------------------------------------------
Reverse-merged /uima/uimaj/branches/mavenAlign/uima-docbook-tools:r944252
Merged /uima/uimaj/branches/filteredCompress-uima-2498/uima-docbook-tools:r1436573-1462257
Propchange: uima/uimaj/trunk/uima-docbook-tutorials-and-users-guides/
------------------------------------------------------------------------------
Reverse-merged /uima/uimaj/branches/mavenAlign/uima-docbook-tutorials-and-users-guides:r944252
Merged /uima/uimaj/branches/filteredCompress-uima-2498/uima-docbook-tutorials-and-users-guides:r1436573-1462257
Modified: uima/uimaj/trunk/uima-docbook-tutorials-and-users-guides/src/docbook/tutorials_and_users_guides.xml
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uima-docbook-tutorials-and-users-guides/src/docbook/tutorials_and_users_guides.xml?rev=1462267&r1=1462266&r2=1462267&view=diff
==============================================================================
--- uima/uimaj/trunk/uima-docbook-tutorials-and-users-guides/src/docbook/tutorials_and_users_guides.xml (original)
+++ uima/uimaj/trunk/uima-docbook-tutorials-and-users-guides/src/docbook/tutorials_and_users_guides.xml Thu Mar 28 19:31:14 2013
@@ -33,5 +33,6 @@ under the License.
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="tug.multi_views.xml"/>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="tug.cas_multiplier.xml"/>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="tug.xmi_emf.xml"/>
- <!-- xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="tug.configuration.xml"/-->
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="tug.configuration.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="tug.type_mapping.xml"/>
</book>
Propchange: uima/uimaj/trunk/uimaj-adapter-soap/
------------------------------------------------------------------------------
Merged /uima/uimaj/branches/filteredCompress-uima-2498/uimaj-adapter-soap:r1436573-1462257
Propchange: uima/uimaj/trunk/uimaj-adapter-vinci/
------------------------------------------------------------------------------
Merged /uima/uimaj/branches/filteredCompress-uima-2498/uimaj-adapter-vinci:r1436573-1462257
Propchange: uima/uimaj/trunk/uimaj-bootstrap/
------------------------------------------------------------------------------
Merged /uima/uimaj/branches/filteredCompress-uima-2498/uimaj-bootstrap:r1436573-1462257
Propchange: uima/uimaj/trunk/uimaj-component-test-util/
------------------------------------------------------------------------------
Merged /uima/uimaj/branches/filteredCompress-uima-2498/uimaj-component-test-util:r1436573-1462257
Propchange: uima/uimaj/trunk/uimaj-core/
------------------------------------------------------------------------------
Merged /uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core:r1436573-1462257
Propchange: uima/uimaj/trunk/uimaj-core/src/main/java/
------------------------------------------------------------------------------
Merged /uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/main/java:r1436573-1462257
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes4.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes4.java?rev=1462267&r1=1462266&r2=1462267&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes4.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes4.java Thu Mar 28 19:31:14 2013
@@ -1144,7 +1144,12 @@ public class BinaryCasSerDes4 {
if (((v > 0) && (prev > 0)) ||
((v < 0) && (prev < 0))) {
final int diff = v - prev; // guaranteed not to overflow
- final int absDiff = Math.abs(diff);
+// Math.abs of Integer.MIN_VALUE + 1 sometimes (after jit?) (on some JVMs) gives wrong annswer
+ // failure observed on IBM Java 7 SR1 and SR2 3/28/2013 schor
+ // failure only observed when running entire suite of uimaj-core tests via eclipse - mvn test doesn't fail
+// final int absDiff = Math.abs(diff);
+ // this seems to work around
+ final int absDiff = (diff < 0) ? -diff : diff;
writeVnumber(kind,
(absV <= absDiff) ?
((long)absV << 2) + ((v < 0) ? 2L : 0L) :
@@ -1522,7 +1527,7 @@ public class BinaryCasSerDes4 {
shortHeapObj = cas.getShortHeap();
byteHeapObj = cas.getByteHeap();
- deserIn.readInt(); // reserved to record additional version info
+// deserIn.readInt(); // reserved to record additional version info // already read before calling
final int nbrEntries = deserIn.readInt(); // number of compressed streams
IntVector idxAndLen = new IntVector(nbrEntries * 3);
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java?rev=1462267&r1=1462266&r2=1462267&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java Thu Mar 28 19:31:14 2013
@@ -20,6 +20,7 @@
package org.apache.uima.cas.impl;
import java.io.ByteArrayInputStream;
+import java.io.DataInput;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -42,7 +43,6 @@ import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
-import org.apache.uima.cas.AbstractCas;
import org.apache.uima.cas.AbstractCas_ImplBase;
import org.apache.uima.cas.AnnotationBaseFS;
import org.apache.uima.cas.ArrayFS;
@@ -79,13 +79,13 @@ import org.apache.uima.cas.admin.CASMgr;
import org.apache.uima.cas.admin.FSIndexComparator;
import org.apache.uima.cas.admin.FSIndexRepositoryMgr;
import org.apache.uima.cas.admin.TypeSystemMgr;
+import org.apache.uima.cas.impl.BinaryCasSerDes6.ReuseInfo;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.cas.text.AnnotationIndex;
import org.apache.uima.cas.text.Language;
import org.apache.uima.internal.util.IntVector;
import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.impl.JCasImpl;
-import org.apache.uima.util.impl.SerializationMeasures;
/**
* Implements the CAS interfaces. This class must be public because we need to
@@ -246,10 +246,6 @@ public class CASImpl extends AbstractCas
*/
private List<Marker> trackingMarkList;
- // must be in svd part because has a field that is updated
- // while serializing
- private BinaryCasSerDes4 binaryCompressor;
-
private SharedViewData(boolean useFSCache) {
this.useFSCache = useFSCache;
}
@@ -1165,9 +1161,14 @@ public class CASImpl extends AbstractCas
* @param istream
* @throws CASRuntimeException
*/
+
public void reinit(InputStream istream) throws CASRuntimeException {
+ reinit(istream, null);
+ }
+
+ public void reinit(InputStream istream, ReuseInfo rfs) throws CASRuntimeException {
if (this != this.svd.baseCAS) {
- this.svd.baseCAS.reinit(istream);
+ this.svd.baseCAS.reinit(istream, rfs);
return;
}
@@ -1195,10 +1196,12 @@ public class CASImpl extends AbstractCas
}
if (0 != (version & 4)) {
- if (svd.binaryCompressor == null) {
- svd.binaryCompressor = new BinaryCasSerDes4(this.getTypeSystemImpl(), false);
+ final int compressedVersion = readInt(dis, swap);
+ if (compressedVersion == 0) {
+ (new BinaryCasSerDes4(this.getTypeSystemImpl(), false)).deserialize(this, dis, delta);
+ } else {
+ (new BinaryCasSerDes6(this, rfs)).deserializeAfterVersion(dis, delta);
}
- svd.binaryCompressor.deserialize(this, dis, delta);
return;
}
@@ -1372,8 +1375,12 @@ public class CASImpl extends AbstractCas
}
} // of delta - modified processing
} catch (IOException e) {
+ String msg = e.getMessage();
+ if (msg == null) {
+ msg = e.toString();
+ }
CASRuntimeException exception = new CASRuntimeException(
- CASRuntimeException.BLOB_DESERIALIZATION, new String[] { e.getMessage() });
+ CASRuntimeException.BLOB_DESERIALIZATION, new String[] { msg });
throw exception;
}
}
@@ -1455,6 +1462,9 @@ public class CASImpl extends AbstractCas
iterator.moveToNext();
}
+ getInitialView(); // done for side effect of creating the initial view.
+ // must be done before the next line, because it sets the
+ // viewCount to 1.
this.svd.viewCount = numViews; // total number of views
for (int viewNbr = 1; viewNbr <= numViews; viewNbr++) {
@@ -1549,9 +1559,10 @@ public class CASImpl extends AbstractCas
// Get indexes for base CAS
fsLoopIndex = this.svd.baseCAS.indexRepository.getIndexedFSs();
v.add(fsLoopIndex.length);
- for (int k = 0; k < fsLoopIndex.length; k++) {
- v.add(fsLoopIndex[k]);
- }
+ v.add(fsLoopIndex, 0, fsLoopIndex.length);
+// for (int k = 0; k < fsLoopIndex.length; k++) {
+// v.add(fsLoopIndex[k]);
+// }
// Get indexes for each SofaFS in the CAS
for (int sofaNum = 1; sofaNum <= numViews; sofaNum++) {
@@ -1603,9 +1614,10 @@ public class CASImpl extends AbstractCas
}
v.add(newSofas.size());
- for (int k = 0; k < newSofas.size(); k++) {
- v.add(newSofas.get(k));
- }
+ v.add(newSofas.getArray(), 0, newSofas.size());
+// for (int k = 0; k < newSofas.size(); k++) {
+// v.add(newSofas.get(k));
+// }
// Get indexes for each SofaFS in the CAS
for (int sofaNum = 1; sofaNum <= numViews; sofaNum++) {
@@ -1621,17 +1633,20 @@ public class CASImpl extends AbstractCas
fsReindexed = INT0;
}
v.add(fsLoopIndex.length);
- for (int k = 0; k < fsLoopIndex.length; k++) {
- v.add(fsLoopIndex[k]);
- }
+ v.add(fsLoopIndex, 0, fsLoopIndex.length);
+// for (int k = 0; k < fsLoopIndex.length; k++) {
+// v.add(fsLoopIndex[k]);
+// }
v.add(fsDeletedFromIndex.length);
- for (int k = 0; k < fsDeletedFromIndex.length; k++) {
- v.add(fsDeletedFromIndex[k]);
- }
+ v.add(fsDeletedFromIndex, 0, fsDeletedFromIndex.length);
+// for (int k = 0; k < fsDeletedFromIndex.length; k++) {
+// v.add(fsDeletedFromIndex[k]);
+// }
v.add(fsReindexed.length);
- for (int k = 0; k < fsReindexed.length; k++) {
- v.add(fsReindexed[k]);
- }
+ v.add(fsReindexed, 0, fsReindexed.length);
+// for (int k = 0; k < fsReindexed.length; k++) {
+// v.add(fsReindexed[k]);
+// }
}
return v.toArray();
}
@@ -3786,6 +3801,10 @@ public class CASImpl extends AbstractCas
final int offset = this.getHeap().heap[getArrayStartAddress(fsRef)];
long value = Double.doubleToLongBits(d);
this.getLongHeap().setHeapValue(value, offset + position);
+ if (this.svd.trackingMark != null) {
+ this.logFSUpdate(fsRef, offset+position, ModifiedHeap.LONGHEAP, 1);
+ }
+
}
public void ll_setDoubleArrayValue(int fsRef, int position, double value, boolean doTypeChecks) {
@@ -4293,10 +4312,7 @@ public class CASImpl extends AbstractCas
* @throws IOException
*/
public void serializeWithCompression(Object out) throws IOException {
- if (svd.binaryCompressor == null) {
- svd.binaryCompressor = new BinaryCasSerDes4(this.getTypeSystemImpl(), false);
- }
- svd.binaryCompressor.serialize(this, out);
+ (new BinaryCasSerDes4(this.getTypeSystemImpl(), false)).serialize(this, out);
}
}
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASSerializer.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASSerializer.java?rev=1462267&r1=1462266&r2=1462267&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASSerializer.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASSerializer.java Thu Mar 28 19:31:14 2013
@@ -56,7 +56,7 @@ import org.apache.uima.cas.Marker;
* This class is for internal use. Some of the serialized formats are readable by the C++
* implementation, and used for efficiently transferring CASes between Java frameworks and other ones.
* Others are used with Vinci or SOAP to communicate to remote annotators.
- *
+ *
* To serialize the shared common information among a group of CASes sharing the same
* type definition and index specifications,
* @see org.apache.uima.cas.impl.CASMgrSerializer
Added: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CasTypeSystemMapper.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CasTypeSystemMapper.java?rev=1462267&view=auto
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CasTypeSystemMapper.java (added)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CasTypeSystemMapper.java Thu Mar 28 19:31:14 2013
@@ -0,0 +1,285 @@
+/*
+ * 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.impl;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.uima.cas.Type;
+
+/**
+ * This class gets initialized with two type systems, and then provides
+ * resources to map type and feature codes between them.
+ *
+ * It is used by some Binary serialization/ deserialization
+ * code to allow non-exact matched type systems to send and
+ * receive CASes in a binary-like format.
+ *
+ * Use cases:
+ *
+ * Serializing: Source ts -> generate serialized form in Target ts
+ * Deserializing: Target ts -> generate deserialized form in Source ts
+ * - either from remote or
+ * - from disk-stored-form
+ *
+ * Mapping details:
+ * Types are mapped by name.
+ * Same-named types do not need to have the same number of features.
+ * Same-named features must have same Range - otherwise, not mapped.
+ * Types with 0 features mapped allowed.
+ * LifeCycle:
+ * Instance of this are created for a CAS when needed, and then
+ * kept in the (source) TypeSystemImpl, in a map indexed by
+ * the target type system (identity map)
+ *
+ *
+ */
+
+public class CasTypeSystemMapper {
+ private final static int[] INT0 = new int[0];
+ private final static boolean[] BOOLEAN0 = new boolean[0];
+
+ public final TypeSystemImpl tsSrc; // source type system
+ public final TypeSystemImpl tsTgt; // target type system
+
+ /**
+ * Map from source type codes to target type codes.
+ * Source type code used as index,
+ * value is target type code
+ */
+ final private int[] tSrc2Tgt;
+
+ /**
+ * First index is src type code, 2nd index is src feature offset, 0 is 1st feature.
+ * Value is true if target has source feature
+ */
+ final private boolean[][] fSrcInTgt;
+
+ /**
+ * First index is src type code, 2nd index is tgt feature offset, 0 is 1st feature.
+ * Value is -1 if src doesn't have feature, else it is the feature offset in source.
+ * Only used for type codes that are not arrays.
+ * Use: When serializing a source type that exists in the target, have to output
+ * the slots in the target feature order
+ * Also, when comparing the slots in the target with a given source
+ */
+ final private int[][] fTgt2Src;
+
+ /**
+ * Same as tSrc2Tgt, but reversed
+ * used when deserializing a target back into a source
+ */
+ final private int[] tTgt2Src;
+
+ public CasTypeSystemMapper(TypeSystemImpl tsSrc, TypeSystemImpl tsTgt) {
+ if (!tsSrc.isCommitted() || !tsTgt.isCommitted()) {
+ throw new RuntimeException("Type Systems must be committed before calling this method");
+ }
+ this.tsSrc = tsSrc;
+ this.tsTgt = tsTgt;
+
+ this.tSrc2Tgt = addTypes(tsSrc, tsTgt);
+ this.tTgt2Src = addTypes(tsTgt, tsSrc);
+ this.fSrcInTgt = new boolean[tsSrc.getTypeArraySize()] [];
+ this.fTgt2Src = new int[tsSrc.getTypeArraySize()] [];
+ addFeatures(tsSrc, tsTgt);
+// this.fTgt2Src = addFeatures(tsTgt, tsSrc);
+ }
+
+ /**
+ * @param c
+ * @return 0 if type doesn't have corresponding code in other type system
+ */
+ public int mapTypeCodeSrc2Tgt(int c) {
+ return tSrc2Tgt[c];
+ }
+
+ /**
+ * @param c
+ * @return 0 if type doesn't have corresponding code in other type system
+ */
+ public int mapTypeCodeTgt2Src(int c) {
+ return tTgt2Src[c];
+ }
+ /**
+ *
+ * @param c
+ * @param src2tgt
+ * @return 0 if type doesn't have corresponding code in other type system
+ */
+ public int mapTypeCode2Other(int c, boolean src2tgt) {
+ if (src2tgt) {
+ return mapTypeCodeSrc2Tgt(c);
+ }
+ return mapTypeCodeTgt2Src(c);
+ }
+
+ /**
+ *
+ * @param tCode - source type code
+ * @return int vec of 0-based feat offsets in src of feats in tgt, in the order of the target
+ */
+ public int[] getTgtFeatOffsets2Src(int tCode) {
+ return fTgt2Src[tCode];
+ }
+
+ public boolean[] getFSrcInTgt(int tCode) {
+ return fSrcInTgt[tCode];
+ }
+
+// /**
+// *
+// * @param tCode source type code
+// * @param offset feature slot offset, 0 = first feature after type code
+// * @return offset to slot in target, 0 = first feature slot after type code, -1 if feature doesn't have corresponding code in other type system
+// */
+// public int mapFeatureOffsetSrc2Tgt(int tCode, int offset) {
+// return fSrc2Tgt[tCode][offset];
+// }
+
+ // returns 0 if feature doesn't have corresponding code in other type system
+// public int mapFeatureCodeTgt2Src(int c) {
+// return fTgt2Src[c];
+// }
+
+ private int[] addTypes(TypeSystemImpl tsSrc, TypeSystemImpl tsTgt) {
+ Map<TypeImpl, TypeImpl> mSrc2Tgt = new LinkedHashMap<TypeImpl, TypeImpl>();
+ for (Iterator<Type> it = tsSrc.getTypeIterator(); it.hasNext();) {
+ TypeImpl tSrc = (TypeImpl) it.next();
+ TypeImpl tTgt = (TypeImpl) tsTgt.getType(tSrc.getName());
+ if (tTgt != null) {
+ mSrc2Tgt.put(tSrc, tTgt);
+ }
+ }
+ int[] r = new int[tsSrc.getNumberOfTypes() + 1]; // type codes are numbered starting with 1
+ for (Entry<TypeImpl, TypeImpl> e : mSrc2Tgt.entrySet()) {
+ r[e.getKey().getCode()] = e.getValue().getCode();
+ }
+ return r;
+ }
+
+ private void addFeatures(TypeSystemImpl tsSrc, TypeSystemImpl tsTgt) {
+ for (int tCodeSrc = 0; tCodeSrc < tsSrc.getTypeArraySize(); tCodeSrc++) {
+ final int tCodeTgt = mapTypeCodeSrc2Tgt(tCodeSrc);
+ if (tCodeTgt == 0) { // this type not in target
+ fSrcInTgt[tCodeSrc] = BOOLEAN0;
+ fTgt2Src[tCodeSrc] = null; // should never be referenced
+ continue;
+ }
+
+ // type is part of target ts
+ final int[] fcSrc = tsSrc.ll_getAppropriateFeatures(tCodeSrc);
+ final int[] fcTgt = tsTgt.ll_getAppropriateFeatures(tCodeTgt);
+
+ if (fcSrc.length == 0) {
+ // source has no features
+ fSrcInTgt[tCodeSrc] = BOOLEAN0;
+ fTgt2Src[tCodeSrc] = new int[fcTgt.length];
+ Arrays.fill(fTgt2Src[tCodeSrc], -1);
+ continue; // source type has no features
+ }
+
+ final boolean[] srcInTgt = new boolean[fcSrc.length];
+ fSrcInTgt[tCodeSrc] = srcInTgt;
+
+ if (fcTgt.length == 0) {
+ Arrays.fill(srcInTgt, false);
+ fTgt2Src[tCodeSrc] = INT0;
+ continue; // target type has no features
+ }
+
+ final int[] tgt2srcOffsets = new int[fcTgt.length];
+ fTgt2Src[tCodeSrc] = tgt2srcOffsets;
+
+// // debug
+// if (tCodeTgt == 228) {
+// String ss[] = new String[fcTgt.length];
+// for (int i = 0; i < fcTgt.length; i++) {
+// ss[i] = tsTgt.ll_getFeatureForCode(fcTgt[i]).getName();
+// }
+// System.out.print("");
+// }
+// // debug - verify features are in alpha order
+// String ss[] = new String[fcSrc.length];
+// String prev = " ";
+// boolean fault = false;
+// for (int i = 0; i < fcSrc.length; i++) {
+// String s = tsSrc.ll_getFeatureForCode(fcSrc[i]).getName();
+// ss[i] = s;
+// if (prev.compareTo(s) >= 0) {
+// fault = true;
+// System.out.format("Source feature names not sorted, prev = %s, this = %s%n", prev, s);
+// }
+// prev = s;
+// }
+// if (fault) {
+// System.out.print("");
+// }
+// prev = " ";
+// if (tCodeTgt == 228) {
+//
+// for (int i = 0; i < fcTgt.length; i++) {
+// String s = tsTgt.ll_getFeatureForCode(fcTgt[i]).getName();
+// if (prev.compareTo(s) >= 0) {
+// fault = true;
+// System.out.format("Target feature names not sorted, prev = %s, this = %s%n", prev, s);
+// }
+// prev = s;
+// }
+// }
+
+ // get List of names of appropriate features in the target for this type
+ List<String> namesTgt = new ArrayList<String>(fcTgt.length);
+ for (int i = 0; i < fcTgt.length; i++) {
+ namesTgt.add(tsTgt.ll_getFeatureForCode(fcTgt[i]).getName());
+ }
+
+ // get List of names of appropriate features in the source for this type
+ List<String> namesSrc = new ArrayList<String>(fcSrc.length);
+ for (int i = 0; i < fcSrc.length; i++) {
+ namesSrc.add(tsSrc.ll_getFeatureForCode(fcSrc[i]).getName());
+ }
+
+
+ // for each feature in the source, find the corresponding target feature by name match (if any)
+ for (int fciSrc = 0; fciSrc < fcSrc.length; fciSrc++) {
+ final String nameSrc = namesSrc.get(fciSrc);
+ // feature names are semi sorted, not completely sorted due to inheritence
+ final int iTgt = namesTgt.indexOf(nameSrc);
+ srcInTgt[fciSrc] = ((-1) != iTgt); // -1 if not there
+ } // end of for loop over all source features of a type code
+
+ // for each feature in the target, find the corresponding source feature by name match (if any)
+ for (int fciTgt = 0; fciTgt < fcTgt.length; fciTgt++) {
+ final String nameTgt = namesTgt.get(fciTgt);
+ // feature names are semi sorted, not completely sorted due to inheritence
+ final int iSrc = namesSrc.indexOf(nameTgt);
+ tgt2srcOffsets[fciTgt] = iSrc; // -1 if not there
+ } // end of for loop over all target features of a type code
+ } // end of for loop over all typecodes
+ }
+
+
+}
Propchange: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CasTypeSystemMapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexComparatorImpl.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexComparatorImpl.java?rev=1462267&r1=1462266&r2=1462267&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexComparatorImpl.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexComparatorImpl.java Thu Mar 28 19:31:14 2013
@@ -169,10 +169,12 @@ public class FSIndexComparatorImpl imple
FSIndexComparatorImpl copy = new FSIndexComparatorImpl(this.cas);
copy.type = this.type;
final int max = this.getNumberOfKeys();
+ copy.compVector.add(this.compVector.getArray(), 0, this.compVector.size());
+ copy.keyTypeVector.add(this.keyTypeVector.getArray(), 0, this.keyTypeVector.size());
for (int i = 0; i < max; i++) {
copy.keyVector.add(this.keyVector.get(i));
- copy.compVector.add(this.compVector.get(i));
- copy.keyTypeVector.add(this.keyTypeVector.get(i));
+// copy.compVector.add(this.compVector.get(i));
+// copy.keyTypeVector.add(this.keyTypeVector.get(i));
}
return copy;
}
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexRepositoryImpl.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexRepositoryImpl.java?rev=1462267&r1=1462266&r2=1462267&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexRepositoryImpl.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexRepositoryImpl.java Thu Mar 28 19:31:14 2013
@@ -68,13 +68,13 @@ public class FSIndexRepositoryImpl imple
private class IndexIteratorCachePair implements Comparable<IndexIteratorCachePair> {
// The "root" index, i.e., index of the type of the iterator.
- private FSLeafIndexImpl index = null;
+ private FSLeafIndexImpl<?> index = null;
// A list of indexes (the sub-indexes that we need for an
// iterator). I.e., one index for each type that's subsumed by the
// iterator
// type.
- private ArrayList<FSLeafIndexImpl> iteratorCache = null;
+ private ArrayList<FSLeafIndexImpl<?>> iteratorCache = null;
private IndexIteratorCachePair() {
super();
@@ -102,7 +102,7 @@ public class FSIndexRepositoryImpl imple
if (this.iteratorCache != null) {
return;
}
- this.iteratorCache = new ArrayList<FSLeafIndexImpl>();
+ this.iteratorCache = new ArrayList<FSLeafIndexImpl<?>>();
final Type rootType = this.index.getComparator().getType();
ArrayList<Type> allTypes = null;
if (this.index.getIndexingStrategy() == FSIndex.DEFAULT_BAG_INDEX) {
@@ -211,12 +211,12 @@ public class FSIndexRepositoryImpl imple
private void initPointerIterator(IndexIteratorCachePair iicp0) {
this.iicp = iicp0;
// Make sure the iterator cache exists.
- final ArrayList<FSLeafIndexImpl> iteratorCache = iicp0.iteratorCache;
+ final ArrayList<FSLeafIndexImpl<?>> iteratorCache = iicp0.iteratorCache;
this.indexes = new ComparableIntPointerIterator[iteratorCache.size()];
this.iteratorComparator = iteratorCache.get(0);
ComparableIntPointerIterator it;
for (int i = 0; i < this.indexes.length; i++) {
- final FSLeafIndexImpl leafIndex = iteratorCache.get(i);
+ final FSLeafIndexImpl<?> leafIndex = iteratorCache.get(i);
it = leafIndex.pointerIterator(this.iteratorComparator,
FSIndexRepositoryImpl.this.detectIllegalIndexUpdates,
((TypeImpl) leafIndex.getType()).getCode());
@@ -645,8 +645,8 @@ public class FSIndexRepositoryImpl imple
private void initPointerIterator(IndexIteratorCachePair iicp0) {
this.iicp = iicp0;
// Make sure the iterator cache exists.
- final ArrayList<FSLeafIndexImpl> iteratorCache = iicp0.iteratorCache;
- final FSLeafIndexImpl leafIndex = iteratorCache.get(0);
+ final ArrayList<FSLeafIndexImpl<?>> iteratorCache = iicp0.iteratorCache;
+ final FSLeafIndexImpl<?> leafIndex = iteratorCache.get(0);
this.index = leafIndex.pointerIterator(leafIndex,
FSIndexRepositoryImpl.this.detectIllegalIndexUpdates,
((TypeImpl) leafIndex.getType()).getCode());
@@ -833,7 +833,7 @@ public class FSIndexRepositoryImpl imple
this.iicp.createIndexIteratorCache();
// int size = this.iicp.index.size();
int size = 0;
- final ArrayList<FSLeafIndexImpl> subIndex = this.iicp.iteratorCache;
+ final ArrayList<FSLeafIndexImpl<?>> subIndex = this.iicp.iteratorCache;
final int max = subIndex.size();
for (int i = 0; i < max; i++) {
size += subIndex.get(i).size();
@@ -1073,7 +1073,7 @@ public class FSIndexRepositoryImpl imple
}
final ArrayList<IndexIteratorCachePair> indexVector = this.indexArray[typeCode];
// final int vecLen = indexVector.size();
- FSLeafIndexImpl ind;
+ FSLeafIndexImpl<?> ind;
switch (indexType) {
case FSIndex.SET_INDEX: {
ind = new FSRBTSetIndex(this.cas, type, indexType);
@@ -1458,8 +1458,8 @@ public class FSIndexRepositoryImpl imple
// index, pick one arbitrarily and add its FSs (since it contains all
// FSs that all other indexes for the same type contain). If there are
// only set indexes, create a set of the FSs in those indexes, since they
- // may all contain different elements (FSs that are duplicates for one
- // index may not be duplicates for a different one).
+ // may all contain different elements (different FSs that have the same "key"
+ // are duplicates for one index, but may not be duplicates for a different one).
cv = new ArrayList<IndexIteratorCachePair>();
for (int j = 0; j < jMax; j++) {
iicp = iv.get(j);
@@ -1467,14 +1467,17 @@ public class FSIndexRepositoryImpl imple
if (indStrat == FSIndex.SET_INDEX) {
cv.add(iicp);
} else {
- if (cv.size() > 0) {
- cv = new ArrayList<IndexIteratorCachePair>();
- }
+ cv.clear(); // only need to save this one
cv.add(iicp);
break;
}
}
if (cv.size() > 0) {
+ // Note: This next loop removes duplicates (and also sorts
+ // the fs addrs associated with one type)
+ // Duplicates arise from having mulitple sets combined, and
+ // also if a non-set index had the same identical FS added
+ // multiple times.
set = new SortedIntSet();
for (int k = 0; k < cv.size(); k++) {
it = cv.get(k).index.refIterator();
@@ -1483,9 +1486,10 @@ public class FSIndexRepositoryImpl imple
it.inc();
}
}
- for (int k = 0; k < set.size(); k++) {
- v.add(set.get(k));
- }
+ v.add(set.getArray(), 0, set.size()); // bulk add of all elements
+// for (int k = 0; k < set.size(); k++) {
+// v.add(set.get(k));
+// }
}
}
return v.toArray();
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java?rev=1462267&r1=1462266&r2=1462267&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java Thu Mar 28 19:31:14 2013
@@ -19,6 +19,20 @@
package org.apache.uima.cas.impl;
+import static org.apache.uima.cas.impl.SlotKinds.SlotKind.Slot_ArrayLength;
+import static org.apache.uima.cas.impl.SlotKinds.SlotKind.Slot_Boolean;
+import static org.apache.uima.cas.impl.SlotKinds.SlotKind.Slot_Byte;
+import static org.apache.uima.cas.impl.SlotKinds.SlotKind.Slot_ByteRef;
+import static org.apache.uima.cas.impl.SlotKinds.SlotKind.Slot_DoubleRef;
+import static org.apache.uima.cas.impl.SlotKinds.SlotKind.Slot_Float;
+import static org.apache.uima.cas.impl.SlotKinds.SlotKind.Slot_HeapRef;
+import static org.apache.uima.cas.impl.SlotKinds.SlotKind.Slot_Int;
+import static org.apache.uima.cas.impl.SlotKinds.SlotKind.Slot_LongRef;
+import static org.apache.uima.cas.impl.SlotKinds.SlotKind.Slot_Short;
+import static org.apache.uima.cas.impl.SlotKinds.SlotKind.Slot_ShortRef;
+import static org.apache.uima.cas.impl.SlotKinds.SlotKind.Slot_StrRef;
+import static org.apache.uima.cas.impl.SlotKinds.SlotKind.Slot_TypeCode;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
@@ -36,6 +50,7 @@ import org.apache.uima.cas.TypeNameSpace
import org.apache.uima.cas.TypeSystem;
import org.apache.uima.cas.admin.CASAdminException;
import org.apache.uima.cas.admin.TypeSystemMgr;
+import org.apache.uima.cas.impl.SlotKinds.SlotKind;
import org.apache.uima.internal.util.IntVector;
import org.apache.uima.internal.util.StringToIntMap;
import org.apache.uima.internal.util.SymbolTable;
@@ -47,6 +62,8 @@ import org.apache.uima.internal.util.rb_
*
*/
public class TypeSystemImpl implements TypeSystemMgr, LowLevelTypeSystem {
+
+ private static int[] INT0 = new int[0];
private static class ListIterator<T> implements Iterator<T> {
@@ -186,6 +203,10 @@ public class TypeSystemImpl implements T
private int numFeatureNames = 0;
final CASMetadata casMetadata; // needs to be visible in package
+
+ // map from type code to TypeInfo instance for that type code,
+ // set up lazily
+ TypeInfo[] typeInfoArray;
boolean areBuiltInTypesSetup = false;
@@ -553,11 +574,11 @@ public class TypeSystemImpl implements T
}
static final String getArrayComponentName(String arrayTypeName) {
- return arrayTypeName.substring(0, arrayTypeName.length() - 2);
+ return arrayTypeName.substring(0, arrayTypeName.length() - 2);
}
static boolean isArrayTypeNameButNotBuiltIn(String typeName) {
- return typeName.endsWith(arrayTypeSuffix);
+ return typeName.endsWith(arrayTypeSuffix);
}
private static final String getBuiltinArrayComponent(String typeName) {
@@ -1092,6 +1113,7 @@ public class TypeSystemImpl implements T
this.numCommittedTypes = this.types.size(); // do before
this.numTypeNames = this.typeNameST.size();
this.numFeatureNames = this.featureNameST.size();
+ this.typeInfoArray = new TypeInfo[getTypeArraySize()];
// cas.commitTypeSystem -
// because it will call the type system iterator
this.casMetadata.setupFeaturesAndCreatableTypes();
@@ -1415,4 +1437,167 @@ public class TypeSystemImpl implements T
return this.stringSets.get(this.stringSetMap.get(typeCode));
}
+ /**
+ * Each instance holds info needed in binary serialization
+ * of data for a particular type
+ */
+ class TypeInfo {
+ // constant data about a particular type
+ public final TypeImpl type; // for debug
+ /**
+ * Array of slot kinds; index 0 is for 1st slot after feature code, length = number of slots excluding type code
+ */
+ public final SlotKind[] slotKinds;
+ public final int[] strRefOffsets;
+
+ public final boolean isArray;
+ public final boolean isHeapStoredArray; // true if array elements are
+ // stored on the main heap
+
+ public TypeInfo(TypeImpl type) {
+
+ this.type = type;
+ List<Feature> features = type.getFeatures();
+
+ isArray = type.isArray(); // feature structure array types named
+ // type-of-fs[]
+ isHeapStoredArray = (type == intArrayType) || (type == floatArrayType)
+ || (type == fsArrayType) || (type == stringArrayType)
+ || (TypeSystemImpl.isArrayTypeNameButNotBuiltIn(type.getName()));
+
+ final ArrayList<Integer> strRefsTemp = new ArrayList<Integer>();
+ // set up slot kinds
+ if (isArray) {
+ // slotKinds has 2 slots: 1st is for array length, 2nd is the slotkind
+ // for the array element
+ SlotKind arrayKind;
+ if (isHeapStoredArray) {
+ if (type == intArrayType) {
+ arrayKind = Slot_Int;
+ } else if (type == floatArrayType) {
+ arrayKind = Slot_Float;
+ } else if (type == stringArrayType) {
+ arrayKind = Slot_StrRef;
+ } else {
+ arrayKind = Slot_HeapRef;
+ }
+ } else {
+
+ // array, but not heap-store-array
+ if (type == booleanArrayType || type == byteArrayType) {
+ arrayKind = Slot_ByteRef;
+ } else if (type == shortArrayType) {
+ arrayKind = Slot_ShortRef;
+ } else if (type == longArrayType) {
+ arrayKind = Slot_LongRef;
+ } else if (type == doubleArrayType) {
+ arrayKind = Slot_DoubleRef;
+ } else {
+ throw new RuntimeException("never get here");
+ }
+ }
+
+ slotKinds = new SlotKind[] { Slot_ArrayLength, arrayKind };
+ strRefOffsets = INT0;
+
+ } else {
+
+ // set up slot kinds for non-arrays
+ ArrayList<SlotKind> slots = new ArrayList<SlotKind>();
+ int i = -1;
+ for (Feature feat : features) {
+ i++;
+ TypeImpl slotType = (TypeImpl) feat.getRange();
+
+ if (slotType == stringType || (slotType instanceof StringTypeImpl)) {
+ slots.add(Slot_StrRef);
+ strRefsTemp.add(i + 1); // first feature is offset 1 from fs addr
+ } else if (slotType == intType) {
+ slots.add(Slot_Int);
+ } else if (slotType == booleanType) {
+ slots.add(Slot_Boolean);
+ } else if (slotType == byteType) {
+ slots.add(Slot_Byte);
+ } else if (slotType == shortType) {
+ slots.add(Slot_Short);
+ } else if (slotType == floatType) {
+ slots.add(Slot_Float);
+ } else if (slotType == longType) {
+ slots.add(Slot_LongRef);
+ } else if (slotType == doubleType) {
+ slots.add(Slot_DoubleRef);
+ } else {
+ slots.add(Slot_HeapRef);
+ }
+ } // end of for loop
+ slotKinds = slots.toArray(new SlotKind[slots.size()]);
+ // convert to int []
+ final int srlength = strRefsTemp.size();
+ if (srlength > 0) {
+ strRefOffsets = new int[srlength];
+ for (int j = 0; j < srlength; j++) {
+ strRefOffsets[j] = strRefsTemp.get(j);
+ }
+ } else {
+ strRefOffsets = INT0;
+ }
+ }
+ }
+
+ /**
+ * @param offset 0 = typeCode, 1 = first feature, ...
+ * @return
+ */
+ SlotKind getSlotKind(int offset) {
+ if (0 == offset) {
+ return Slot_TypeCode;
+ }
+ return slotKinds[offset - 1];
+ }
+
+ @Override
+ public String toString() {
+ return type.toString();
+ }
+ }
+
+ TypeInfo getTypeInfo(int typeCode) {
+ if (null == typeInfoArray[typeCode]) {
+ TypeImpl type = (TypeImpl) ll_getTypeForCode(typeCode);
+// if (null == type) {
+// diagnoseBadTypeCode(typeCode);
+// }
+ typeInfoArray[typeCode] = new TypeInfo(type);
+ }
+ return typeInfoArray[typeCode];
+ }
+
+// // debugging
+// private void diagnoseBadTypeCode(int typeCode) {
+// System.err.format("Bad type code %,d passed to TypeSystem.getTypeInfo, largest type code is %,d, size of types list is %,d%n",
+// typeCode, getLargestTypeCode(), types.size());
+// System.err.println(this.toString());
+// System.err.format("Type in types: %s%n", types.get(typeCode));
+// throw new RuntimeException();
+// }
+
+ /*********************************************************
+ * Type Mapping Objects
+ * used in compressed binary (de)serialization
+ * These are in an identity map, key = target type system
+ *********************************************************/
+ Map<TypeSystemImpl, CasTypeSystemMapper> typeSystemMappers = new HashMap<TypeSystemImpl, CasTypeSystemMapper>();
+
+ synchronized CasTypeSystemMapper getTypeSystemMapper(TypeSystemImpl tgtTs) {
+ if ((null == tgtTs) || (this == tgtTs)) {
+ return null; // conventions for no type mapping
+ }
+ CasTypeSystemMapper m = typeSystemMappers.get(tgtTs);
+ if (null == m) {
+ m = new CasTypeSystemMapper(this, tgtTs);
+ typeSystemMappers.put(tgtTs, m);
+ }
+ return m;
+ }
+
}
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntArrayUtils.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntArrayUtils.java?rev=1462267&r1=1462266&r2=1462267&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntArrayUtils.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntArrayUtils.java Thu Mar 28 19:31:14 2013
@@ -33,16 +33,16 @@ public final class IntArrayUtils {
}
// done this way to allow more inlining
- public static final int[] ensure_size(int[] array, int req, int growth_factor,
- int multiplication_limit) {
+ public static final int[] ensure_size(final int[] array, final int req, final int growth_factor,
+ final int multiplication_limit) {
if (array.length < req) {
return expand_size(array, req, growth_factor, multiplication_limit);
}
return array;
}
- private static final int[] expand_size(int[] array, int req, int growth_factor,
- int multiplication_limit) {
+ private static final int[] expand_size(final int[] array, final int req, final int growth_factor,
+ final int multiplication_limit) {
if (array.length == 0)
return new int[req];
int new_array_size = array.length;
@@ -54,7 +54,7 @@ public final class IntArrayUtils {
new_array_size = new_array_size + multiplication_limit;
}
}
- int[] new_array = new int[new_array_size];
+ final int[] new_array = new int[new_array_size];
System.arraycopy(array, 0, new_array, 0, array.length);
return new_array;
}
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntVector.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntVector.java?rev=1462267&r1=1462266&r2=1462267&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntVector.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntVector.java Thu Mar 28 19:31:14 2013
@@ -38,9 +38,9 @@ public class IntVector implements Serial
private static final int default_multiplication_limit = 2000000;
- private int growth_factor;
+ final private int growth_factor;
- private int multiplication_limit;
+ final private int multiplication_limit;
// Points to the next free cell in the array.
protected int pos = 0;
@@ -115,6 +115,22 @@ public class IntVector implements Serial
}
/**
+ * Add an array of elements to the end.
+ * @param elements
+ */
+ public void add(int[] elements) {
+ add(elements, 0, elements.length);
+ }
+
+ public void add(int[] elements, int startpos, int endpos) {
+ final int len = endpos - startpos;
+ final int posNow = this.pos;
+ ensure_size(this.pos + len); // changes pos
+ System.arraycopy(elements, startpos, this.array, posNow, len);
+// this.pos += len; done by ensure_size
+ }
+
+ /**
* Add an element at the end of vector. Behaves like add(Object o) of
* {@link java.util.Vector Vector}.
*/
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/SortedIntSet.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/SortedIntSet.java?rev=1462267&r1=1462266&r2=1462267&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/SortedIntSet.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/SortedIntSet.java Thu Mar 28 19:31:14 2013
@@ -127,6 +127,10 @@ public class SortedIntSet {
public int[] toArray() {
return this.vector.toArrayCopy();
}
+
+ public int[] getArray() {
+ return vector.getArray();
+ }
// public static void main(String [] args) {
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/rb_trees/CompIntArrayRBT.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/rb_trees/CompIntArrayRBT.java?rev=1462267&r1=1462266&r2=1462267&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/rb_trees/CompIntArrayRBT.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/rb_trees/CompIntArrayRBT.java Thu Mar 28 19:31:14 2013
@@ -46,23 +46,23 @@ public class CompIntArrayRBT extends Int
// Insert a node for key. Returns index of new node if node was inserted, or
// index of old node for the key.
- protected int treeInsert(int k) {
+ protected int treeInsert(final int k) {
int x = this.root;
int y = NIL;
int z;
- int cv; // Return value of compare().
- if ((this.greatestNode != NIL) && (this.comp.compare(this.key[this.greatestNode], k) < 0)) {
+// int cv; // Return value of compare().
+ if ((this.greatestNode != NIL) && (this.comp.compare(getKey(this.greatestNode), k) < 0)) {
y = this.greatestNode;
z = newNode(k);
this.greatestNode = z;
} else {
while (x != NIL) {
y = x;
- cv = this.comp.compare(k, this.key[x]);
+ final int cv = this.comp.compare(k, getKey(x));
if (cv < 0) {
- x = this.left[x];
+ x = getLeft(x);
} else if (cv > 0) {
- x = this.right[x];
+ x = getRight(x);
} else { // cv == 0
return x;
}
@@ -74,50 +74,50 @@ public class CompIntArrayRBT extends Int
if (y == NIL) {
this.root = z;
this.greatestNode = z;
- this.parent[z] = NIL;
+ setParent(z, NIL);
} else {
- this.parent[z] = y;
- cv = this.comp.compare(k, this.key[y]);
+ setParent(z, y);
+ final int cv = this.comp.compare(k, getKey(y));
if (cv < 0) {
- this.left[y] = z;
+ setLeft(y, z);
} else {
- this.right[y] = z;
+ setRight(y, z);
}
}
return z;
}
- protected int treeInsertWithDups(int k) {
+ protected int treeInsertWithDups(final int k) {
int x = this.root;
- int y, z, cv;
+ int y, z;
boolean wentLeft = false;
- if ((this.greatestNode != NIL) && (this.comp.compare(this.key[this.greatestNode], k) <= 0)) {
+ if ((this.greatestNode != NIL) && (this.comp.compare(getKey(this.greatestNode), k) <= 0)) {
y = this.greatestNode;
z = newNode(k);
this.greatestNode = z;
- this.parent[z] = y;
- this.right[y] = z;
+ setParent(z, y);
+ setRight(y, z);
return z;
}
y = NIL;
int xKey;
while (x != NIL) {
y = x;
- xKey = this.key[x];
- cv = this.comp.compare(k, xKey);
+ xKey = getKey(x);
+ final int cv = this.comp.compare(k, xKey);
if (cv < 0) {
- x = this.left[x];
+ x = getLeft(x);
} else if (cv > 0) {
- x = this.right[x];
+ x = getRight(x);
} else { // k == key[x]
// Randomly search to the left or right.
// if (false) {
if (this.rand.nextBoolean()) {
wentLeft = true;
- x = this.left[x];
+ x = getLeft(x);
} else {
wentLeft = false;
- x = this.right[x];
+ x = getRight(x);
}
}
}
@@ -125,20 +125,20 @@ public class CompIntArrayRBT extends Int
if (y == NIL) {
this.root = z;
this.greatestNode = z;
- this.parent[z] = NIL;
+ setParent(z, NIL);
} else {
- this.parent[z] = y;
- cv = this.comp.compare(k, this.key[y]);
+ setParent(z, y);
+ final int cv = this.comp.compare(k, getKey(y));
if (cv < 0) {
- this.left[y] = z;
+ setLeft(y, z);
} else if (cv > 0) {
- this.right[y] = z;
+ setRight(y, z);
} else { // k == key[y]
// Randomly insert node to the left or right.
if (wentLeft) {
- this.left[y] = z;
+ setLeft(y, z);
} else {
- this.right[y] = z;
+ setRight(y, z);
}
}
}
@@ -146,15 +146,15 @@ public class CompIntArrayRBT extends Int
return z;
}
- public int findKey(int k) {
+ public int findKey(final int k) {
int node = this.root;
int cv;
while (node != NIL) {
- cv = this.comp.compare(k, this.key[node]);
+ cv = this.comp.compare(k, getKey(node));
if (cv < 0) {
- node = this.left[node];
+ node = getLeft(node);
} else if (cv > 0) {
- node = this.right[node];
+ node = getRight(node);
} else {
return node;
}
@@ -163,17 +163,17 @@ public class CompIntArrayRBT extends Int
return NIL;
}
- public int findInsertionPoint(int k) {
+ public int findInsertionPoint(final int k) {
int node = this.root;
int found = this.root;
int cv = 0;
while (node != NIL) {
found = node;
- cv = this.comp.compare(k, this.key[node]);
+ cv = this.comp.compare(k, getKey(node));
if (cv < 0) {
- node = this.left[node];
+ node = getLeft(node);
} else if (cv > 0) {
- node = this.right[node];
+ node = getRight(node);
} else {
return node;
}