@Override public void load(DataResource dr) throws ResourceInitializationException { try { gramModel = GramModelDeserializer .from(dr.getInputStream(), String.valueOf(dr.getUrl())); } catch (Exception e) { throw new ResourceInitializationException(e); } }
public void load(DataResource dr) throws ResourceInitializationException { URI uri = dr.getUri(); if(uri != null) { if (uri.getScheme().equalsIgnoreCase("jar")) { throw new ResourceInitializationException(new RuntimeException("Attempting to load a FileResource from a jar. The File to be loaded cannot be within a jar." + uri.toString())); } iv_file = new File(dr.getUri()); } else { iv_logger.info("URI for data resource is null - using path from URL"); URL url = dr.getUrl(); if(url != null) { String path = dr.getUrl().getPath(); iv_file = new File(path); } } }
public void load(DataResource resource) throws ResourceInitializationException { try { model = loadModel(resource.getInputStream()); } catch (IOException e) { throw new ResourceInitializationException( ExceptionMessages.MESSAGE_CATALOG, ExceptionMessages.IO_ERROR_MODEL_READING, new Object[] { e.getMessage()}, e); } } }
public void load(DataResource resource) throws ResourceInitializationException { LOGGER.info("Loading configuration file from URI \"{}\" (URL: \"{}\").", resource.getUri(), resource.getUrl()); Properties properties = new Properties(); try { InputStream is; try { is = resource.getInputStream(); } catch (NullPointerException e) { LOGGER.info("Couldn't get InputStream from UIMA. Trying to load the resource by classpath lookup."); String cpAddress = resource.getUri().toString(); is = getClass().getResourceAsStream(cpAddress.startsWith("/") ? cpAddress : "/" + cpAddress); if (null == is) { String err = "Couldn't find the resource at \"" + resource.getUri() + "\" neither as an UIMA external resource file nor as a classpath resource."; LOGGER.error(err); LOGGER.info("Creating dictionary chunker with " + resource.getUrl() + " properties file.");
config.load(aData.getInputStream()); String dbName = config.getProperty(CONFIG_TRAINED_DB); if (null == dbName) new IllegalArgumentException( "The passed configuration file at " + aData.getUri() + " does define the property \"" + CONFIG_TRAINED_DB
public void load(DataResource dr) throws ResourceInitializationException { try { File file = new File(dr.getUri()); ArrayList<String> lines = new ArrayList<String>(); BufferedReader fileReader = new BufferedReader(new FileReader(file)); try { String line; while((line = fileReader.readLine()) != null) { if(!line.startsWith(COMMENT_STRING) && line.trim().length() > 0) lines.add(line); } } finally { fileReader.close(); } this.lines = (String[])lines.toArray(new String[lines.size()]); } catch(IOException ioe) { throw new ResourceInitializationException(ioe); } }
public void load(DataResource resource) throws ResourceInitializationException { resourceUri = resource.getUri(); LOGGER.info("Creating dictionary chunker with dictionary loaded from " + resourceUri); ConfigurationParameterSettings settings = resource.getMetaData().getConfigurationParameterSettings(); stopwordFilePath = (String) settings.getParameterValue(PARAM_STOPWORD_FILE); if (stopwordFilePath == null) dictFile = UriUtilities.getInputStreamFromUri(resource.getUri()); } catch (Exception e) { LOGGER.error("Could not load the dictionary from {}, see the following exception for details.", resource.getUri()); throw e; LOGGER.error("Exception while creating chunker instance from dictionary file {} with stopwords from {}", resource.getUri(), stopwordFilePath, e);
private URL getResourceAsStreamCommonUrl(Object resource) { if (resource != null && resource instanceof DataResource) { return ((DataResource) resource).getUrl(); } else { return null; } }
ConfigurationParameterSettings cps = dr.getMetaData().getConfigurationParameterSettings(); Boolean useMemoryIndex = (Boolean) cps.getParameterValue("UseMemoryIndex");
public InputStream getInputStream() throws IOException { return new BufferedInputStream(dataResource.getInputStream()); }
@Override public void load(DataResource aData) throws ResourceInitializationException { CharStream input; try { UIMAFramework.getLogger().log(Level.FINE, "Loading resource " + KEY_TOKEN_REGEX_RULES + " at: " + aData.getUri()); input = CharStreams.fromStream(aData.getInputStream()); UimaTokenRegexLexer lexer = new UimaTokenRegexLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); UimaTokenRegexParser parser = new UimaTokenRegexParser(tokens); listener = new AutomataParserListener( parser ); listener.setAllowMatchingEmptySequences(false); ParseTreeWalker.DEFAULT.walk(listener, parser.ruleList()); } catch (IOException e) { throw new ResourceInitializationException(e); } }
public void load(DataResource dr) throws ResourceInitializationException { try { File file = new File(dr.getUri()); ArrayList<String> lines = new ArrayList<String>(); BufferedReader fileReader = new BufferedReader(new FileReader(file)); try { String line; while((line = fileReader.readLine()) != null) { if(!line.startsWith(COMMENT_STRING) && line.trim().length() > 0) lines.add(line); } } finally { fileReader.close(); } this.lines = (String[])lines.toArray(new String[lines.size()]); } catch(IOException ioe) { throw new ResourceInitializationException(ioe); } }
File configFile = new File(dr.getUrl().toExternalForm()); configFileName = configFile.getPath();
ConfigurationParameterSettings cps = dr.getMetaData().getConfigurationParameterSettings(); Boolean useMemoryIndex = (Boolean) cps.getParameterValue("UseMemoryIndex");
/** * {@inheritDoc} */ @Override public void load(DataResource dr) throws ResourceInitializationException { if (this.dict != null) { throw new IllegalStateException( "Repeated SharedResourceObjectInvocation#load invocation"); } URL resUrl = dr.getUrl(); try { CachedDictionaryDeserializer deser = CachedDictionaryDeserializer.getInstance(); GetDictionaryResult deserResult = deser.getDictionary(resUrl, dr.getInputStream()); this.cacheKey = deserResult.cacheKey; this.dict = deserResult.dictionary; } catch (Exception e) { throw new ResourceInitializationException(e); } }
public void load(DataResource data) throws ResourceInitializationException { if (data != null) { try { InputStream inputStream = data.getInputStream(); this.model = null; ObjectInputStream p = new ObjectInputStream(inputStream); this.model = (ModelGeneration) p.readObject(); p.close(); } catch (IOException e) { throw new ResourceInitializationException(e); } catch (ClassNotFoundException e) { throw new ResourceInitializationException(e); } } }
public void load(DataResource dr) throws ResourceInitializationException { URI uri = dr.getUri(); if(uri != null) { if (uri.getScheme().equalsIgnoreCase("jar")) { throw new ResourceInitializationException(new RuntimeException("Attempting to load a FileResource from a jar. The File to be loaded cannot be within a jar." + uri.toString())); } iv_file = new File(dr.getUri()); } else { iv_logger.info("URI for data resource is null - using path from URL"); URL url = dr.getUrl(); if(url != null) { String path = dr.getUrl().getPath(); iv_file = new File(path); } } }
@Override public void load(DataResource aData) throws ResourceInitializationException { URI modelUri = aData.getUri(); this.component = getUriComponent(modelUri.toString(), this.language, this.getMode() ); }
/** * Initialize a component from a {@link ResourceMetaData}. * * @param component * the component to initialize. * @param dataResource * a data resource with configuration meta data. * @see #initialize(Object, UimaContext) * @throws ResourceInitializationException * if a failure occurs during initialization. */ public static void initialize(Object component, DataResource dataResource) throws ResourceInitializationException { ResourceMetaData metaData = dataResource.getMetaData(); ConfigurationParameterSettings settings = metaData.getConfigurationParameterSettings(); initialize(component, settings.getParameterSettings()); } }