private Set<String> getTypes(URL resource, ResourceManager resMgr) throws IOException, InvalidXMLException { Set<String> types = new HashSet<String>(); TypeSystemDescription typeSysDescr = null; typeSysDescr = UIMAFramework.getXMLParser().parseTypeSystemDescription( new XMLInputSource(resource)); typeSysDescr.resolveImports(resMgr); for (TypeDescription each : typeSysDescr.getTypes()) { String name = each.getName(); String[] nameSpace = name.split("[.]"); types.add(nameSpace[nameSpace.length - 1]); StringBuffer fullName = new StringBuffer(); if (nameSpace.length > 0) { fullName.append(nameSpace[0]); } for (int i = 1; i < nameSpace.length; i++) { // TODO fix workaround if (!nameSpace[i].equals("type")) { fullName.append('.'); fullName.append(nameSpace[i]); } } types.add(fullName.toString()); } return types; }
@Override public void exitImportDeclaration(ImportDeclarationContext ctx) { String value = ctx.Identifier().getText(); String filePath = value.replaceAll("\\.", "/") + ".xml"; try { typeSystemDescription = TypeSystemDescriptionFactory.createTypeSystemDescription(); typeSystemDescription.resolveImports(); } catch (Exception e) { throw new AutomataParsingException("Failed to load type system " + filePath, e); } }
public static TypeSystemDescription createTypeSystemDescription(InputStream in) { // Note: // Type System location is not set correctly, // resolving a referenced type system will fail XMLInputSource xmlTypeSystemSource = new XMLInputSource(in, new File("")); XMLParser xmlParser = UIMAFramework.getXMLParser(); TypeSystemDescription typeSystemDesciptor; try { typeSystemDesciptor = (TypeSystemDescription) xmlParser .parse(xmlTypeSystemSource); typeSystemDesciptor.resolveImports(); } catch (InvalidXMLException e) { e.printStackTrace(); typeSystemDesciptor = null; } return typeSystemDesciptor; }
private void resolveImport(URL aURL, Collection<String> aAlreadyImportedTypeSystemURLs, Collection<TypeDescription> aResults, ResourceManager aResourceManager) throws InvalidXMLException, IOException { //check the import cache TypeSystemDescription desc; String urlString = aURL.toString(); Map<String, XMLizable> importCache = ((ResourceManager_impl)aResourceManager).getImportCache(); Map<String, Set<String>> importUrlsCache = ((ResourceManager_impl)aResourceManager).getImportUrlsCache(); synchronized(importCache) { XMLizable cachedObject = importCache.get(urlString); if (cachedObject instanceof TypeSystemDescription) { desc = (TypeSystemDescription)cachedObject; // Add the URLs parsed for this cached object to the list already-parsed (UIMA-5058) aAlreadyImportedTypeSystemURLs.addAll(importUrlsCache.get(urlString)); } else { XMLInputSource input; input = new XMLInputSource(aURL); desc = UIMAFramework.getXMLParser().parseTypeSystemDescription(input); TreeSet<String> previouslyImported = new TreeSet<String>(aAlreadyImportedTypeSystemURLs); desc.resolveImports(aAlreadyImportedTypeSystemURLs, aResourceManager); importCache.put(urlString, desc); // Save the URLS parsed by this import TreeSet<String> locallyImported = new TreeSet<String>(aAlreadyImportedTypeSystemURLs); locallyImported.removeAll(previouslyImported); importUrlsCache.put(urlString, locallyImported); } } aResults.addAll(Arrays.asList(desc.getTypes())); }
.parse(xmlTypeSystemSource); typeSystemDesciptor.resolveImports();
TypeSystemDescription tsd = TypeSystemDescriptionFactory.createTypeSystemDescription(typesystem); try { tsd.resolveImports(getResourceManager()); } catch (InvalidXMLException e) { throw new RuntimeException("Cannot resolve imports in " + typesystem, e);
private TypeSystemDescription getTypeSystemDescriptor(URL url, RutaBuildOptions option, ResourceManager rm) throws InvalidXMLException, IOException { TypeSystemDescription tsdesc = UIMAFramework.getXMLParser() .parseTypeSystemDescription(new XMLInputSource(url)); if (option.isResolveImports()) { tsdesc.resolveImports(rm); } return tsdesc; }
private TypeSystemDescription getLocalTSD(String toLoad) throws InvalidXMLException, IOException { TypeSystemDescription localTSD = localTSDMap.get(toLoad); if (localTSD == null) { String locateTSD = locate(toLoad, descriptorPaths, "TypeSystem.xml", true); if (locateTSD != null) { localTSD = UIMAFramework.getXMLParser().parseTypeSystemDescription( new XMLInputSource(locateTSD)); ResourceManager resMgr = UIMAFramework.newDefaultResourceManager(); resMgr.setDataPath(getDataPath()); localTSD.resolveImports(resMgr); localTSDMap.put(toLoad, localTSD); } } return localTSD; }
/** * Import all typesystems that are imported in the script. * * @param casTS * Type system containing all known types. * @throws InvalidXMLException * When import cannot be resolved. */ private void importDeclaredTypesystems(TypeSystem casTS) throws InvalidXMLException { String[] descriptors = typesystems.toArray(new String[typesystems.size()]); TypeSystemDescription ts = TypeSystemDescriptionFactory.createTypeSystemDescription(descriptors); ts.resolveImports(getResourceManager()); for (TypeDescription td : ts.getTypes()) { Type type = casTS.getType(td.getName()); if (type != null) { addType(type); } else { throw new RuntimeException("Type '" + td.getName() + "' not found"); } } }
.parse(xmlTypeSystemSource); typeSystemDesciptor.resolveImports();
.parseTypeSystemDescription(new XMLInputSource(descriptorPath.toPortableString())); ResourceManager resMgr = getResourceManager(classLoader); typeSysDescr.resolveImports(resMgr); } else { .parseTypeSystemDescription(new XMLInputSource(resources[0].getURL())); ResourceManager resMgr = getResourceManager(classLoader); typeSysDescr.resolveImports(resMgr);
TypeSystemDescription tsd = (TypeSystemDescription) desc; tsd.resolveImports(); TypeDescription[] types = tsd.getTypes(); for (TypeDescription each : types) {
} else if (descriptor instanceof TypeSystemDescription) { TypeSystemDescription tsDesc = (TypeSystemDescription) descriptor; tsDesc.resolveImports(); cas = CasCreationUtils.createCas(tsDesc, null, new FsIndexDescription[0]); styleMapFile = getStyleMapFile((TypeSystemDescription) descriptor, descriptorFile.getPath());
CollectionReaderDescription crd = UIMAFramework.getXMLParser().parseCollectionReaderDescription(new XMLInputSource(descFile)); TypeSystemDescription typeSystem = crd.getCollectionReaderMetaData().getTypeSystem(); typeSystem.resolveImports(); typeSystems.add(typeSystem); AnalysisEngineDescription aed = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(new XMLInputSource(descFile)); TypeSystemDescription typeSystem = aed.getAnalysisEngineMetaData().getTypeSystem(); typeSystem.resolveImports(); typeSystems.add(typeSystem);
CollectionReaderDescription crd = UIMAFramework.getXMLParser().parseCollectionReaderDescription(new XMLInputSource(descFile)); TypeSystemDescription typeSystem = crd.getCollectionReaderMetaData().getTypeSystem(); typeSystem.resolveImports(); typeSystems.add(typeSystem); AnalysisEngineDescription aed = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(new XMLInputSource(descFile)); TypeSystemDescription typeSystem = aed.getAnalysisEngineMetaData().getTypeSystem(); typeSystem.resolveImports(); typeSystems.add(typeSystem);
} else if (descriptor instanceof TypeSystemDescription) { TypeSystemDescription tsDesc = (TypeSystemDescription) descriptor; tsDesc.resolveImports(); cas = CasCreationUtils.createCas(tsDesc, null, new FsIndexDescription[0]); styleMapFile = getStyleMapFile((TypeSystemDescription) descriptor, descriptorFile.getPath());
tsDesc.resolveImports(); this.main.destroyAe(); this.main.setCas(CasCreationUtils
public void resolveImports(ResourceManager aResourceManager) throws InvalidXMLException { if (getTypeSystem() != null) { getTypeSystem().resolveImports(aResourceManager); } if (getTypePriorities() != null) { getTypePriorities().resolveImports(aResourceManager); } if (getFsIndexCollection() != null) { getFsIndexCollection().resolveImports(aResourceManager); } }
resourceManager.setDataPath(dataPath); typeSystemDesciptor.resolveImports(resourceManager); } catch (InvalidXMLException e) { String message = e.getMessage() != null ? e.getMessage() : "";
tsDesc.resolveImports(resMgr); for (TypeDescription each : tsDesc.getTypes()) { String longName = each.getName();