Question

How would I go about getting (or computing) the UIMA Type System from a CPE Descriptor XML file? I've had a look through the classes I'm using to load in the CPE Descriptor in Java, but can't see anything that will get me the Type System.

I know that the CAS has a getTypeSystem() function, but I need to get the Type System prior to running the CPE pipeline (i.e. before I have a CAS object).

Was it helpful?

Solution

Eventually figured out how to do it... and it's not pretty! Code below for anyone else who ends up in a similar situation.

CpeDescription cpeDesc = UIMAFramework.getXMLParser().parseCpeDescription(new XMLInputSource(cpeFile));
File rootFolder = new File(cpeDesc.getSourceUrl().getFile()).getParentFile();
ArrayList<TypeSystemDescription> typeSystems = new ArrayList<>();

for(CpeCollectionReader collReader : cpeDesc.getAllCollectionCollectionReaders()){
    File descFile = new File(rootFolder + System.getProperty("file.separator") + collReader.getDescriptor().getImport().getLocation());

    CollectionReaderDescription crd = UIMAFramework.getXMLParser().parseCollectionReaderDescription(new XMLInputSource(descFile));

    TypeSystemDescription typeSystem = crd.getCollectionReaderMetaData().getTypeSystem();
    typeSystem.resolveImports();

    typeSystems.add(typeSystem);
}

for(CpeCasProcessor casProcessor : cpeDesc.getCpeCasProcessors().getAllCpeCasProcessors()){
    File descFile = new File(rootFolder + System.getProperty("file.separator") + casProcessor.getCpeComponentDescriptor().getImport().getLocation());

    AnalysisEngineDescription aed = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(new XMLInputSource(descFile));

    TypeSystemDescription typeSystem = aed.getAnalysisEngineMetaData().getTypeSystem();
    typeSystem.resolveImports();

    typeSystems.add(typeSystem);
}

TypeSystemDescription mergedTypeSystem = CasCreationUtils.mergeTypeSystems(typeSystems);

Note that this only considers Imports, and not Includes within the CPE Descriptor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top