You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by Greg Holmberg <ho...@comcast.net> on 2011/01/27 02:02:01 UTC
Fwd: UimaTypeSystem2Ecore
Hi UIMA users--
When I call UimaTypeSystem2Ecore (in UIMA 2.3.1), I get an exception:
ResourceInitializationException : The feature uima.tcas.DocumentAnnotation:language is declared twice, with incompatible multipleReferencesAllowed specifications. (Descriptor: <unknown>) : The feature uima.tcas.DocumentAnnotation:language is declared twice, with incompatible multipleReferencesAllowed specifications. (Descriptor: <unknown>)
I think this shouldn't have happened because I get the descriptor from a working type system, so it should be valid:
TypeSystemDescription tsDesc = TypeSystemUtil. typeSystem2TypeSystemDescription (typeSystem);
Looking at the source code for UimaTypeSystem2Ecore, I see this:
// Add the default definition of uima.tcas.DocumentAnnotation. If the // Add the default definition of uima.tcas.DocumentAnnotation. If the
// user also defines this type (with additional features), it will be merged // user also defines this type (with additional features), it will be merged
// with this. First clone the aTypeSystem object so user won't notice // with this. First clone the aTypeSystem object so user won't notice
// we have added a new type definition to their TypeSystemDescription. // we have added a new type definition to their TypeSystemDescription.
aTypeSystem = (TypeSystemDescription) aTypeSystem.clone();
TypeDescription docAnnotType = aTypeSystem.addType( "uima.tcas.DocumentAnnotation" , "" , "uima.tcas.Annotation" );
docAnnotType.addFeature( "language" , "" , "uima.cas.String" ); "uima.tcas.DocumentAnnotation" , "" , "uima.tcas.Annotation" );
docAnnotType.addFeature( "language" , "" , "uima.cas.String" ); "language" , "" , "uima.cas.String" );
Well, that certainly seems to correlate with the exception message.
But the comments says that this feature should have been merged, and not caused an exception. Appently, this didn't happen.
Is this a bug in UIMA or in my code?
Here's my code.
private static Map<URI,String>
writeTypeSystemAsEcore(
final TypeSystem typeSystem,
final OutputStream outputStream)
throws IOException
{
Map<URI,String> schemaLocationMap = new HashMap<URI,String>();
TypeSystemDescription tsDesc = TypeSystemUtil
. typeSystem2TypeSystemDescription (typeSystem);
// register default EMF resource factory private static Map<URI,String>
writeTypeSystemAsEcore(
final TypeSystem typeSystem,
final OutputStream outputStream)
throws IOException
{
Map<URI,String> schemaLocationMap = new HashMap<URI,String>();
TypeSystemDescription tsDesc = TypeSystemUtil
. typeSystem2TypeSystemDescription (typeSystem);
// register default EMF resource factory final TypeSystem typeSystem,
final OutputStream outputStream)
throws IOException
{
Map<URI,String> schemaLocationMap = new HashMap<URI,String>();
TypeSystemDescription tsDesc = TypeSystemUtil
. typeSystem2TypeSystemDescription (typeSystem);
// register default EMF resource factory final OutputStream outputStream)
throws IOException
{
Map<URI,String> schemaLocationMap = new HashMap<URI,String>();
TypeSystemDescription tsDesc = TypeSystemUtil
. typeSystem2TypeSystemDescription (typeSystem);
// register default EMF resource factory throws IOException
{
Map<URI,String> schemaLocationMap = new HashMap<URI,String>();
TypeSystemDescription tsDesc = TypeSystemUtil
. typeSystem2TypeSystemDescription (typeSystem);
// register default EMF resource factory new HashMap<URI,String>();
TypeSystemDescription tsDesc = TypeSystemUtil
. typeSystem2TypeSystemDescription (typeSystem);
// register default EMF resource factory // register default EMF resource factory
Resource.Factory.Registry. INSTANCE .getExtensionToFactoryMap().
put( "*" , new XMIResourceFactoryImpl()) ;
ResourceSet resourceSet = new ResourceSetImpl();
org.eclipse.emf.common.util.URI outputURI =
org.eclipse.emf.common.util.URI. createFileURI ( "typesystem.ecore" );
Resource outputResource = resourceSet.createResource(outputURI);
try {
UimaTypeSystem2Ecore. uimaTypeSystem2Ecore (
tsDesc,
outputResource,
null ,
schemaLocationMap);
outputResource.save(outputStream, null );
} catch (InvalidXMLException ixe) {
// this should not happen. INSTANCE .getExtensionToFactoryMap().
put( "*" , new XMIResourceFactoryImpl()) ;
ResourceSet resourceSet = new ResourceSetImpl();
org.eclipse.emf.common.util.URI outputURI =
org.eclipse.emf.common.util.URI. createFileURI ( "typesystem.ecore" );
Resource outputResource = resourceSet.createResource(outputURI);
try {
UimaTypeSystem2Ecore. uimaTypeSystem2Ecore (
tsDesc,
outputResource,
null ,
schemaLocationMap);
outputResource.save(outputStream, null );
} catch (InvalidXMLException ixe) {
// this should not happen. "*" , new XMIResourceFactoryImpl()) ;
ResourceSet resourceSet = new ResourceSetImpl();
org.eclipse.emf.common.util.URI outputURI =
org.eclipse.emf.common.util.URI. createFileURI ( "typesystem.ecore" );
Resource outputResource = resourceSet.createResource(outputURI);
try {
UimaTypeSystem2Ecore. uimaTypeSystem2Ecore (
tsDesc,
outputResource,
null ,
schemaLocationMap);
outputResource.save(outputStream, null );
} catch (InvalidXMLException ixe) {
// this should not happen. new ResourceSetImpl();
org.eclipse.emf.common.util.URI outputURI =
org.eclipse.emf.common.util.URI. createFileURI ( "typesystem.ecore" );
Resource outputResource = resourceSet.createResource(outputURI);
try {
UimaTypeSystem2Ecore. uimaTypeSystem2Ecore (
tsDesc,
outputResource,
null ,
schemaLocationMap);
outputResource.save(outputStream, null );
} catch (InvalidXMLException ixe) {
// this should not happen. "typesystem.ecore" );
Resource outputResource = resourceSet.createResource(outputURI);
try {
UimaTypeSystem2Ecore. uimaTypeSystem2Ecore (
tsDesc,
outputResource,
null ,
schemaLocationMap);
outputResource.save(outputStream, null );
} catch (InvalidXMLException ixe) {
// this should not happen. try {
UimaTypeSystem2Ecore. uimaTypeSystem2Ecore (
tsDesc,
outputResource,
null ,
schemaLocationMap);
outputResource.save(outputStream, null );
} catch (InvalidXMLException ixe) {
// this should not happen. null ,
schemaLocationMap);
outputResource.save(outputStream, null );
} catch (InvalidXMLException ixe) {
// this should not happen. null );
} catch (InvalidXMLException ixe) {
// this should not happen. catch (InvalidXMLException ixe) {
// this should not happen. // this should not happen.
// TypeSystemUtil.typeSystem2TypeSystemDescription // TypeSystemUtil.typeSystem2TypeSystemDescription
// should never produce an invalid TypeSystemDescription! // should never produce an invalid TypeSystemDescription!
throw new UIMARuntimeException(ixe);
}
return schemaLocationMap;
} throw new UIMARuntimeException(ixe);
}
return schemaLocationMap;
} return schemaLocationMap;
}