in src/cas/internal_casdeserializer.cpp [146:258]
bool CASDeserializer::isTypeSystemMergable(uima::internal::SerializedCAS const & crSerializedCAS,
uima::internal::CASDefinition const & casDef) {
uima::lowlevel::TypeSystem const & crTypeSystem = casDef.getTypeSystem();
vector<UnicodeStringRef> const & crTypeSymbolTable = crSerializedCAS.getTypeSymbolTable();
vector<UnicodeStringRef> const & crFeatureSymbolTable = crSerializedCAS.getFeatureSymbolTable();
vector<SerializedCAS::TyNum> const & crTypeInhTable = crSerializedCAS.getTypeInheritanceTable();
vector<SerializedCAS::TyNum> const & crFeatureDefTable = crSerializedCAS.getFeatureDefinitionTable();
// this method only succeeds if merging is possible, i.e., if rCAS contains
// a "subset" of the type system in crSerializedCAS
vector<uima::lowlevel::TyFSType> allTypes;
crTypeSystem.getAllTypes(allTypes);
vector<uima::lowlevel::TyFSFeature> allFeatures;
crTypeSystem.getAllFeatures(allFeatures);
if (!( allTypes.size() <= ( crTypeSymbolTable.size()-1) ) ) {
return false;
}
// check that all types in the serialized CAS exist in the CAS by name
size_t i;
for (i=0; i<allTypes.size(); ++i) {
// check type name
lowlevel::TyFSType tyType = allTypes[i];
uima::UnicodeStringRef typeName(crTypeSystem.getTypeName(tyType));
int iIndex = findIndex(crTypeSymbolTable, typeName);
if (!( iIndex == tyType ) ) {
return false;
}
}
// check that inheritance is compatible
for (i=0; i<allTypes.size(); ++i) {
uima::lowlevel::TyFSType tyChild = allTypes[i];
uima::lowlevel::TyFSType tyParent = crTypeSystem.getParentType(tyChild);
if (tyParent != uima::lowlevel::TypeSystem::INVALID_TYPE) {
if (!( tyChild < crTypeInhTable.size() )) {
return false;
}
if (!( tyParent == crTypeInhTable[tyChild] )) {
return false;
}
} else {
assert( tyChild == crTypeSystem.getTopType() );
}
}
// check features names
#ifdef DEBUG_VERBOSE
for (i=0; i<crFeatureSymbolTable.size(); ++i) {
UIMA_TPRINT("Feature name " << i << ": " << crFeatureSymbolTable[i]);
}
#endif
for (i=0; i<allFeatures.size(); ++i) {
uima::lowlevel::TyFSFeature tyFeat = allFeatures[i];
uima::UnicodeStringRef featureName( crTypeSystem.getFeatureBaseName(tyFeat) );
UIMA_TPRINT("Looking for feature: " << featureName);
int iIndex = findIndex(crFeatureSymbolTable, featureName);
if (!( iIndex != -1 )) {
return false;
}
if (!( iIndex != 0 )) {
return false;
}
}
assert( crFeatureDefTable.size() %2 == 0 );
if ( crFeatureDefTable.size() > 0 ) {
assert( crFeatureDefTable[0] == uima::lowlevel::TypeSystem::INVALID_TYPE );
assert( crFeatureDefTable[1] == uima::lowlevel::TypeSystem::INVALID_TYPE );
}
// check feature definition
UIMA_TPRINT("Checking feature definitions");
UIMA_TPRINT("Feature def table:");
#ifdef DEBUG_VERBOSE
for (i=2; i<crFeatureDefTable.size(); i+=2) {
if (crTypeSystem.isValidFeature(i/2) ) {
UIMA_TPRINT(" feature: " << (i/2) << " (" << crTypeSystem.getFeatureName(i/2) << ") "
<< ", intro type: " << crFeatureDefTable[i] << "(" << crTypeSystem.getTypeName(crFeatureDefTable[i]) << ") "
<< ", range type: " << crFeatureDefTable[i+1] << "(" << crTypeSystem.getTypeName(crFeatureDefTable[i+1]) << ") ");
}
}
#endif
for (i=0; i<allFeatures.size(); ++i) {
uima::lowlevel::TyFSFeature tyFeat = allFeatures[i];
uima::lowlevel::TyFSType tyIntroType = crTypeSystem.getIntroType(tyFeat);
uima::lowlevel::TyFSType tyRangeType = crTypeSystem.getRangeType(tyFeat);
UIMA_TPRINT("Checking feature: " << crTypeSystem.getFeatureName(tyFeat) );
UIMA_TPRINT(" intro type: " << crTypeSystem.getTypeName(tyIntroType) );
UIMA_TPRINT(" range type: " << crTypeSystem.getTypeName(tyRangeType) );
assert( (tyFeat*2) < crFeatureDefTable.size());
assert( (tyFeat*2+1) < crFeatureDefTable.size());
UIMA_TPRINT(" intro type in serialized CAS: " << crTypeSystem.getTypeName(crFeatureDefTable[tyFeat*2]) );
UIMA_TPRINT(" range type in serialized CAS: " << crTypeSystem.getTypeName(crFeatureDefTable[tyFeat*2+1]) );
if (!( crFeatureDefTable[tyFeat*2] == tyIntroType )) {
return false;
}
if (!( crFeatureDefTable[tyFeat*2+1] == tyRangeType )) {
return false;
}
}
return true;
}