Package org.apache.uima.cas.impl
Class XmiSerializationSharedData
- java.lang.Object
-
- org.apache.uima.cas.impl.XmiSerializationSharedData
-
public class XmiSerializationSharedData extends java.lang.Object
A container for data that is shared between theXmiCasSerializer
and theXmiCasDeserializer
. This has a number of uses:- Consistency of xmi:id values across serializations. If you pass an
XmiSerializationSharedData
instance to the deserializer, the deserializer will store information about the incoming xmi:id values. If you then pass the sameXmiSerializationSharedData
object to the serializer when you attempt to serialize the same CAS, all of the incoming FS will be serialized using the same xmi:id value that they had when they were deserialized. - Support for "out-of-typesystem data". If you call the XMI deserializer with the
lenient
parameter set to true, whenever it encounters an XMI element that doesn't correspond to a type in the type system, it will populate theXmiSerializationSharedData
with information about these elements. If you then pass the sameXmiSerializationSharedData
object to the serializer when you attempt to serialize the same CAS, these out-of-typesystem FS will be reserialized without loss of information. References between in-typesystem and out-of-typesystem FS (in either direction) are maintained as well. - After calling the XmiCasSerializer and passing an
XmiSerializationSharedData
, you can call thegetMaxXmiId()
method to get the maximum xmi:id value in the serialized CAS. This feature, along with the consistency of xmi:id values, allows merging multiple XMI documents into a single CAS. See TODO.
Inner classes are used to hold information about Feature Structure elements, both for out-of-typesystem data, and also when deserializing pre V3 xmi serializations where the Sofa FS are not guaranteed to come before other Feature Structures that depend on them.
- Consistency of xmi:id values across serializations. If you pass an
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
XmiSerializationSharedData.NameMultiValue
static class
XmiSerializationSharedData.OotsElementData
Data structure holding all information about an XMI element containing an out-of-typesystem FS.static class
XmiSerializationSharedData.XmiArrayElement
Data structure holding the index and the xmi:id of an array or list element that is a reference to an out-of-typesystem FS.
-
Field Summary
Fields Modifier and Type Field Description private Obj2IntIdentityHashMap<TOP>
fsToXmiId
V3: FSs have an id - use that.private int
maxXmiId
The maximum XMI ID used in the serialization.(package private) java.util.Map<TOP,TOP>
nonsharedfeatureIdToFSId
V3: key is TOP, value is TOP Map from FS of a non-shared multi-valued (Array/List) FS to the FS address of the encompassing FS which has a feature whose value is this multi-valued FS.private java.util.Map<FSArray,java.util.List<XmiSerializationSharedData.XmiArrayElement>>
ootsArrayElements
V3: Key is FSArray Map from an FSArray to a list ofXmiSerializationSharedData.XmiArrayElement
objects, each of which holds an index and an xmi:id for an out-of-typesystem array element.private java.util.Map<TOP,XmiSerializationSharedData.OotsElementData>
ootsFeatures
Map from Feature Structures to OotsElementData object, capturing information about out-of-typesystem features that were part of an in-typesystem FS.private java.util.List<XmiSerializationSharedData.OotsElementData>
ootsFs
List of OotsElementData objects, each of which captures information about incoming XMI elements that did not correspond to any type in the type system.private java.util.Map<java.lang.String,java.util.List<java.lang.String>>
ootsViewMembers
Map from the xmi:id (String) of a Sofa to a List of xmi:id's (Strings) for the out-of-typesystem FSs that are members of that Sofa's view.private Int2ObjHashMap<TOP,TOP>
xmiIdToFs
A map from xmi:id to FeatureStructure address.
-
Constructor Summary
Constructors Constructor Description XmiSerializationSharedData()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
addIdMapping(TOP fs, int xmiId)
void
addNonsharedRefToFSMapping(TOP nonsharedFS, TOP fs)
Add mapping between the address of FS that is the value of a non-shared multi-valued feature of a FeatureStructure.void
addOutOfTypeSystemArrayElement(FSArray fsarray, int index, int xmiId)
Records an out-of-typesystem array element in the XmiSerializationSharedData.void
addOutOfTypeSystemAttribute(TOP fs, java.lang.String featName, java.lang.String featVal)
Records an out-of-typesystem attribute that belongs to an in-typesystem FS.void
addOutOfTypeSystemChildElements(TOP fs, java.lang.String featName, java.util.ArrayList<java.lang.String> featVals)
Records out-of-typesystem child elements that belong to an in-typesystem FS.void
addOutOfTypeSystemElement(XmiSerializationSharedData.OotsElementData elemData)
Records information about an XMI element that was not an instance of any type in the type system.static void
addOutOfTypeSystemFeature(XmiSerializationSharedData.OotsElementData oed, java.lang.String featName, java.util.ArrayList<java.lang.String> featVals)
void
addOutOfTypeSystemViewMember(java.lang.String sofaXmiId, java.lang.String memberXmiId)
Records that an out-of-typesystem XMI element should be a member of the specified view.void
clearIdMap()
Clears the ID mapping information that was populated in previous serializations or deserializations.TOP[]
getAndSortByIdAllFSsInIdMap()
Get all FS Addresses that have been added to the id map.TOP
getEncompassingFS(TOP nonsharedFS)
TOP
getFsForXmiId(int xmiId)
Gets the FS address that corresponds to the given xmi:id, in the most recent serialization or deserialization.int
getMaxXmiId()
Gets the maximum xmi:id that has been generated or read so far.TOP[]
getNonsharedMulitValuedFSs()
java.util.List<XmiSerializationSharedData.XmiArrayElement>
getOutOfTypeSystemArrayElements(FSArray fsarray)
Gets information about out-of-typesystem array elements.java.util.List<XmiSerializationSharedData.OotsElementData>
getOutOfTypeSystemElements()
Gets a List ofXmiSerializationSharedData.OotsElementData
objects, each of which describes an incoming XMI element that did not correspond to a Type in the TypeSystem.XmiSerializationSharedData.OotsElementData
getOutOfTypeSystemFeatures(TOP fs)
Gets information about out-of-typesystem features that belong to an in-typesystem FS.java.util.List<java.lang.String>
getOutOfTypeSystemViewMembers(java.lang.String sofaXmiId)
Gets a List of xmi:id's (Strings) of all out-of-typesystem XMI elements that are members of the view with the given id.private TOP[]
getSortedKeys(java.util.Map<TOP,?> map)
java.lang.String
getXmiId(TOP fs)
(package private) int
getXmiIdAsInt(TOP fs)
boolean
hasOutOfTypeSystemArrayElements()
java.lang.String
toString()
For debugging purposes only.
-
-
-
Field Detail
-
fsToXmiId
private Obj2IntIdentityHashMap<TOP> fsToXmiId
V3: FSs have an id - use that. (Assumes id's are internal ones) A map from FeatureStructures to xmi:id. This is populated whenever an XMI element is serialized or deserialized. It is used by the getXmiId() method, which is done to ensure a consistent ID for each FS address across multiple serializations.
-
xmiIdToFs
private Int2ObjHashMap<TOP,TOP> xmiIdToFs
A map from xmi:id to FeatureStructure address. This is populated whenever an XMI element is serialized or deserialized. It is used by the getFsAddrForXmiId() method, necessary to support merging multiple XMI CASes into the same CAS object.
-
ootsFs
private java.util.List<XmiSerializationSharedData.OotsElementData> ootsFs
List of OotsElementData objects, each of which captures information about incoming XMI elements that did not correspond to any type in the type system.
-
ootsViewMembers
private java.util.Map<java.lang.String,java.util.List<java.lang.String>> ootsViewMembers
Map from the xmi:id (String) of a Sofa to a List of xmi:id's (Strings) for the out-of-typesystem FSs that are members of that Sofa's view.
-
ootsFeatures
private java.util.Map<TOP,XmiSerializationSharedData.OotsElementData> ootsFeatures
Map from Feature Structures to OotsElementData object, capturing information about out-of-typesystem features that were part of an in-typesystem FS. These include both features not defined in the typesystem and features that are references to out-of-typesystem elements. This information needs to be included when the FS is subsequently serialized.
-
ootsArrayElements
private java.util.Map<FSArray,java.util.List<XmiSerializationSharedData.XmiArrayElement>> ootsArrayElements
V3: Key is FSArray Map from an FSArray to a list ofXmiSerializationSharedData.XmiArrayElement
objects, each of which holds an index and an xmi:id for an out-of-typesystem array element.
-
maxXmiId
private int maxXmiId
The maximum XMI ID used in the serialization. Used to generate unique IDs if needed.
-
nonsharedfeatureIdToFSId
java.util.Map<TOP,TOP> nonsharedfeatureIdToFSId
V3: key is TOP, value is TOP Map from FS of a non-shared multi-valued (Array/List) FS to the FS address of the encompassing FS which has a feature whose value is this multi-valued FS. Used when deserializing a Delta CAS to find and serialize the encompassing FS when the non-shared array/list FS is modified.
-
-
Method Detail
-
addIdMapping
void addIdMapping(TOP fs, int xmiId)
-
getXmiId
public java.lang.String getXmiId(TOP fs)
-
getFsForXmiId
public TOP getFsForXmiId(int xmiId)
Gets the FS address that corresponds to the given xmi:id, in the most recent serialization or deserialization.- Parameters:
xmiId
- an xmi:id from the most recent XMI CAS that was serialized or deserialized.- Returns:
- the FeatureStructure corresponding to that xmi:id, null if none.
-
getXmiIdAsInt
int getXmiIdAsInt(TOP fs)
-
getMaxXmiId
public int getMaxXmiId()
Gets the maximum xmi:id that has been generated or read so far.- Returns:
- the maximum xmi:id
-
clearIdMap
public void clearIdMap()
Clears the ID mapping information that was populated in previous serializations or deserializations. TODO: maybe a more general reset that resets other things?
-
addOutOfTypeSystemElement
public void addOutOfTypeSystemElement(XmiSerializationSharedData.OotsElementData elemData)
Records information about an XMI element that was not an instance of any type in the type system.- Parameters:
elemData
- information about the out-of-typesystem XMI element
-
getOutOfTypeSystemElements
public java.util.List<XmiSerializationSharedData.OotsElementData> getOutOfTypeSystemElements()
Gets a List ofXmiSerializationSharedData.OotsElementData
objects, each of which describes an incoming XMI element that did not correspond to a Type in the TypeSystem.- Returns:
- List of
XmiSerializationSharedData.OotsElementData
objects
-
addOutOfTypeSystemViewMember
public void addOutOfTypeSystemViewMember(java.lang.String sofaXmiId, java.lang.String memberXmiId)
Records that an out-of-typesystem XMI element should be a member of the specified view.- Parameters:
sofaXmiId
- xmi:id of a SofamemberXmiId
- xmi:id of an out-of-typesystem element that should be a member of the view for the given Sofa
-
getOutOfTypeSystemViewMembers
public java.util.List<java.lang.String> getOutOfTypeSystemViewMembers(java.lang.String sofaXmiId)
Gets a List of xmi:id's (Strings) of all out-of-typesystem XMI elements that are members of the view with the given id.- Parameters:
sofaXmiId
- xmi:id of a Sofa- Returns:
- List of xmi:id's of members of the view for the given Sofa.
-
addOutOfTypeSystemAttribute
public void addOutOfTypeSystemAttribute(TOP fs, java.lang.String featName, java.lang.String featVal)
Records an out-of-typesystem attribute that belongs to an in-typesystem FS. This will be added to the attributes when that FS is reserialized.- Parameters:
fs
- the FSfeatName
- name of the featurefeatVal
- value of the feature, as a string
-
addOutOfTypeSystemChildElements
public void addOutOfTypeSystemChildElements(TOP fs, java.lang.String featName, java.util.ArrayList<java.lang.String> featVals)
Records out-of-typesystem child elements that belong to an in-typesystem FS. These will be added to the child elements when that FS is reserialized.- Parameters:
fs
- the FSfeatName
- name of the feature (element tag name)featVals
- values of the feature, as a List of strings
-
addOutOfTypeSystemFeature
public static void addOutOfTypeSystemFeature(XmiSerializationSharedData.OotsElementData oed, java.lang.String featName, java.util.ArrayList<java.lang.String> featVals)
-
getOutOfTypeSystemFeatures
public XmiSerializationSharedData.OotsElementData getOutOfTypeSystemFeatures(TOP fs)
Gets information about out-of-typesystem features that belong to an in-typesystem FS.- Parameters:
fs
- the FS- Returns:
- object containing information about out-of-typesystem features (both attributes and child elements)
-
getAndSortByIdAllFSsInIdMap
public TOP[] getAndSortByIdAllFSsInIdMap()
Get all FS Addresses that have been added to the id map.- Returns:
- an array containing all the FS addresses
-
getOutOfTypeSystemArrayElements
public java.util.List<XmiSerializationSharedData.XmiArrayElement> getOutOfTypeSystemArrayElements(FSArray fsarray)
Gets information about out-of-typesystem array elements.- Parameters:
fsarray
- an FSArray- Returns:
- a List of
XmiSerializationSharedData.XmiArrayElement
objects, each of which holds the index and xmi:id of an array element that is a reference to an out-of-typesystem FS.
-
hasOutOfTypeSystemArrayElements
public boolean hasOutOfTypeSystemArrayElements()
-
addOutOfTypeSystemArrayElement
public void addOutOfTypeSystemArrayElement(FSArray fsarray, int index, int xmiId)
Records an out-of-typesystem array element in the XmiSerializationSharedData.- Parameters:
fsarray
- The FSArrayindex
- index into arrayxmiId
- xmi:id of the out-of-typesystem element that is the value at the given index
-
addNonsharedRefToFSMapping
public void addNonsharedRefToFSMapping(TOP nonsharedFS, TOP fs)
Add mapping between the address of FS that is the value of a non-shared multi-valued feature of a FeatureStructure.- Parameters:
nonsharedFS
- - The non-shared Feature Structure having a multi-valued feature valuefs
- - the encompassing Feature Structure
-
getNonsharedMulitValuedFSs
public TOP[] getNonsharedMulitValuedFSs()
- Returns:
- the non-shared featureId to FS Id key set
-
getEncompassingFS
public TOP getEncompassingFS(TOP nonsharedFS)
- Parameters:
nonsharedFS
- a nonsharedFS- Returns:
- the encompassing FS or null if not found
-
toString
public java.lang.String toString()
For debugging purposes only.- Overrides:
toString
in classjava.lang.Object
-
-