Author: cwiklik Date: Tue Jan 19 18:12:15 2016 New Revision: 1725579 URL: http://svn.apache.org/viewvc?rev=1725579&view=rev Log: UIMA-4265 updated to support specifying data file by name in addtion to by location
Modified: uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/WarmUpDataProvider.java Modified: uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/WarmUpDataProvider.java URL: http://svn.apache.org/viewvc/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/WarmUpDataProvider.java?rev=1725579&r1=1725578&r2=1725579&view=diff ============================================================================== --- uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/WarmUpDataProvider.java (original) +++ uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/WarmUpDataProvider.java Tue Jan 19 18:12:15 2016 @@ -35,8 +35,12 @@ import org.apache.uima.cas.CAS; import org.apache.uima.cas.TypeSystem; import org.apache.uima.cas.impl.Serialization; import org.apache.uima.cas.impl.XmiCasDeserializer; +import org.apache.uima.resource.ResourceManager; +import org.apache.uima.resource.metadata.Import; import org.apache.uima.resource.metadata.TypeSystemDescription; +import org.apache.uima.resource.metadata.impl.Import_impl; import org.apache.uima.util.CasCreationUtils; +import org.apache.uima.util.Level; import org.apache.uima.util.XMLInputSource; import org.apache.uima.util.XMLParser; @@ -51,18 +55,53 @@ public class WarmUpDataProvider { private boolean readingXmiFormat; private TypeSystem inputTS; - public static void main(String[] args) { + private static final Class<?> CLASS_NAME = WarmUpDataProvider.class; + public static void main(String[] args) { + try { + WarmUpDataProvider wdp = new WarmUpDataProvider(args[0]); + + System.out.println("Got it initialized"); + wdp.hasNext(); + + System.out.println("done"); + + } catch( Exception e) { + e.printStackTrace(); + } } - public WarmUpDataProvider(String inputFileName) - throws IOException { + public WarmUpDataProvider(String inputFileName) throws IOException { this.inputFileName = inputFileName; - fis = new FileInputStream(new File(inputFileName)); + Import_impl theImport = new Import_impl(); + theImport.setSuffix(".zip"); + + if ( !inputFileName.endsWith(".zip")) { + theImport.setName(inputFileName); + this.inputFileName = resolveToAbsolutePath(theImport); + // strip 'file:' from the begining + this.inputFileName = this.inputFileName.substring(this.inputFileName.indexOf(':')+1); + } + + + fis = new FileInputStream(new File(this.inputFileName)); zis = new ZipInputStream(new BufferedInputStream(fis, 1024 * 100)); docSeq = 0; } + private String resolveToAbsolutePath(Import theImport) { + ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager(); + try { + return theImport.findAbsoluteUrl(resourceManager).toExternalForm(); + } catch (Exception e) { + if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.WARNING)) { + UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, WarmUpDataProvider.class.getName(), + "resolveToAbsolutePath", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE, "UIMAEE_exception__WARNING", e); + } + return "ERROR converting import by name to absolute path"; + } + } + public boolean hasNext() throws AnalysisEngineProcessException { try { nextEntry = zis.getNextEntry(); @@ -83,8 +122,7 @@ public class WarmUpDataProvider { } else { if (nextEntry.getName().equals("typesystem.xml")) { throw new AnalysisEngineProcessException(new RuntimeException( - "typesystem.xml entry found in the middle of input zipfile " - + inputFileName)); + "typesystem.xml entry found in the middle of input zipfile " + inputFileName)); } } byte[] buff = new byte[10000]; @@ -94,8 +132,7 @@ public class WarmUpDataProvider { while (-1 != (bytesread = zis.read(buff))) { baos.write(buff, 0, bytesread); } - ByteArrayInputStream bis = new ByteArrayInputStream( - baos.toByteArray()); + ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray()); if (readingXmiFormat) { XmiCasDeserializer.deserialize(bis, cas, true); } else { @@ -116,18 +153,15 @@ public class WarmUpDataProvider { while (-1 != (bytesread = zis.read(buff))) { baos.write(buff, 0, bytesread); } - ByteArrayInputStream bis = new ByteArrayInputStream( - baos.toByteArray()); + ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray()); // Get XML parser from framework XMLParser xmlParser = UIMAFramework.getXMLParser(); // Parse type system descriptor TypeSystemDescription tsDesc = xmlParser - .parseTypeSystemDescription(new XMLInputSource( - (InputStream) bis, null)); + .parseTypeSystemDescription(new XMLInputSource((InputStream) bis, null)); // Use type system description to create CAS and get the type system // object - inputTS = CasCreationUtils.createCas(tsDesc, null, null) - .getTypeSystem(); + inputTS = CasCreationUtils.createCas(tsDesc, null, null).getTypeSystem(); // advance to first input CAS nextEntry = zis.getNextEntry(); } catch (Exception e) {