public static AnalysisEngine wrapAnalysisEngine(URL descriptorUrl, String viewName,
boolean rutaEngine, String encoding) throws ResourceInitializationException,
ResourceConfigurationException, InvalidXMLException, IOException, URISyntaxException {
if (viewName.equals(CAS.NAME_DEFAULT_SOFA)) {
XMLInputSource in = new XMLInputSource(descriptorUrl);
ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);
AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
return ae;
} else {
InputStream inputStream = null;
if (rutaEngine) {
inputStream = Ruta.class.getResourceAsStream("AAEDBasicEngine.xml");
} else {
inputStream = Ruta.class.getResourceAsStream("AAED.xml");
}
String aaedString = IOUtils.toString(inputStream, encoding);
String absolutePath = descriptorUrl.toExternalForm();
aaedString = aaedString.replaceAll("\\$\\{sofaName\\}", viewName);
aaedString = aaedString.replaceAll("\\$\\{descriptorLocation\\}", absolutePath);
File tempFile = File.createTempFile("RutaAAED", ".xml");
FileUtils.saveString2File(aaedString, tempFile);
XMLInputSource in = new XMLInputSource(tempFile);
ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);
AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
tempFile.delete();
return ae;
}
}