org.apache.uima.resource.ResourceAccessException Java Examples

The following examples show how to use org.apache.uima.resource.ResourceAccessException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UimaContext_ImplBase.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Locates Resource URL's using the ResourceManager.
 * 
 * @see org.apache.uima.analysis_engine.annotator.AnnotatorContext#getResourceURL(java.lang.String)
 */
@Override
public URL getResourceURL(String aKey) throws ResourceAccessException {
  URL result = getResourceManager().getResourceURL(makeQualifiedName(aKey));
  if (result != null) {
    return result;
  } else {
    // try as an unmanaged resource (deprecated)
    URL unmanagedResourceUrl = null;
    try {
      unmanagedResourceUrl = getResourceManager().resolveRelativePath(aKey);
    } catch (MalformedURLException e) {
      // if key is not a valid path then it cannot be resolved to an unmanged resource
    }
    if (unmanagedResourceUrl != null) {
      UIMAFramework.getLogger().logrb(Level.WARNING, this.getClass().getName(), "getResourceURL",
              LOG_RESOURCE_BUNDLE, "UIMA_unmanaged_resource__WARNING", new Object[] { aKey });
      return unmanagedResourceUrl;
    }
    return null;
  }
}
 
Example #2
Source File: AbstractCasAdapter.java    From biomedicus with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize(UimaContext aContext) throws ResourceInitializationException {
  super.initialize(aContext);

  try {
    guiceInjector = (GuiceInjector) aContext.getResourceObject("guiceInjector");

    labelAdapters = guiceInjector.attach().getInstance(LabelAdapters.class);
  } catch (ResourceAccessException e) {
    throw new ResourceInitializationException(e);
  }

  settingsMap = new HashMap<>();
  for (String parameterName : aContext.getConfigParameterNames()) {
    if (parameterName != null) {
      settingsMap.put(parameterName, aContext.getConfigParameterValue(parameterName));
    }
  }
}
 
Example #3
Source File: ConcurrentTokenizer.java    From DataVec with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the current instance with the given context.
 * 
 * Note: Do all initialization in this method, do not use the constructor.
 */
public void initialize(UimaContext context) throws ResourceInitializationException {

    super.initialize(context);

    TokenizerModel model;

    try {
        TokenizerModelResource modelResource =
                        (TokenizerModelResource) context.getResourceObject(UimaUtil.MODEL_PARAMETER);

        model = modelResource.getModel();
    } catch (ResourceAccessException e) {
        throw new ResourceInitializationException(e);
    }

    tokenizer = new TokenizerME(model);
}
 
Example #4
Source File: MongoParagraphsTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws ResourceInitializationException, ResourceAccessException {
  // Create a description of an external resource - a fongo instance, in the same way we would
  // have created a shared mongo resource
  ExternalResourceDescription erd =
      ExternalResourceFactory.createNamedResourceDescription(
          MONGO, SharedFongoResource.class, "fongo.collection", "paragraphs", "fongo.data", "[]");

  // Create the analysis engine
  AnalysisEngineDescription aed =
      AnalysisEngineFactory.createEngineDescription(MongoParagraph.class, MONGO, erd);
  ae = AnalysisEngineFactory.createEngine(aed);
  ae.initialize(new CustomResourceSpecifier_impl(), Collections.emptyMap());

  SharedFongoResource sfr = (SharedFongoResource) ae.getUimaContext().getResourceObject(MONGO);
  paragraphs = sfr.getDB().getCollection("paragraphs");

  // Ensure we start with no data!
  assertEquals(0L, paragraphs.count());
}
 
Example #5
Source File: MemReleaseI2b2CollectionReader.java    From ctakes-docker with Apache License 2.0 6 votes vote down vote up
private void loadResources( final String resourceName, final String sqlStatement ) throws ResourceInitializationException {
   try {
      final JdbcConnectionResource jdbcConnectionResource
            = (JdbcConnectionResource) getUimaContext().getResourceObject( resourceName );
      final Connection connection = jdbcConnectionResource.getConnection();
      _queryPrepStatement = connection.prepareStatement( sqlStatement );
      // TODO Upon migration to Java 7, consider merging into "catch ( ResourceAccessException | SQLException e )"
   } catch ( ResourceAccessException | ClassCastException raEccE ) {
      // thrown by UimaContext.getResourceObject(..)
       // thrown because non-specific method UimaContext.getResourceObject(..) returns an Object and we are casting
      logger.log(SEVERE, "Could not obtain a uima resource" );
      throw new ResourceInitializationException( raEccE );
   } catch ( SQLException sqlE ) {
      // thrown by Connection.prepareStatement(..) and getTotalRowCount(..)
       logger.log(SEVERE, "Could not interact with Database");
      throw new ResourceInitializationException( sqlE );
   }
}
 
Example #6
Source File: MongoRelationsTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws ResourceInitializationException, ResourceAccessException {
  // Create a description of an external resource - a fongo instance, in the same way we would
  // have created a shared mongo resource
  ExternalResourceDescription erd =
      ExternalResourceFactory.createNamedResourceDescription(
          MONGO, SharedFongoResource.class, "fongo.collection", "test", "fongo.data", "[]");

  // Create the analysis engine
  AnalysisEngineDescription aed =
      AnalysisEngineFactory.createEngineDescription(
          MongoRelations.class, MONGO, erd, "collection", "test");
  ae = AnalysisEngineFactory.createEngine(aed);
  ae.initialize(new CustomResourceSpecifier_impl(), Collections.emptyMap());
  SharedFongoResource sfr = (SharedFongoResource) ae.getUimaContext().getResourceObject(MONGO);

  relations = sfr.getDB().getCollection("test");

  // Ensure we start with no data!
  assertEquals(0L, relations.count());
}
 
Example #7
Source File: MongoPatternSaverTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws ResourceInitializationException, ResourceAccessException {
  // Create a description of an external resource - a fongo instance, in the same way we would
  // have created a shared mongo resource
  final ExternalResourceDescription erd =
      ExternalResourceFactory.createResourceDescription(
          SharedFongoResource.class, "fongo.collection", "test", "fongo.data", "[]");

  // Create the analysis engine
  final AnalysisEngineDescription aed =
      AnalysisEngineFactory.createEngineDescription(
          MongoPatternSaver.class, MongoPatternSaver.KEY_MONGO, erd, "collection", "test");
  ae = AnalysisEngineFactory.createEngine(aed);
  ae.initialize(new CustomResourceSpecifier_impl(), Collections.emptyMap());

  sfr = (SharedFongoResource) ae.getUimaContext().getResourceObject(MongoPatternSaver.KEY_MONGO);
}
 
Example #8
Source File: MongoEventsTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
private void createAnalysisEngine(String textBlockType)
    throws ResourceInitializationException, ResourceAccessException {

  AnalysisEngineDescription aed =
      AnalysisEngineFactory.createEngineDescription(
          MongoEvents.class,
          MONGO,
          erd,
          "collection",
          "test",
          MongoEvents.PARAM_TEXT_BLOCK_EXTRACTED_FROM,
          textBlockType,
          MongoEvents.PARAM_OUTPUT_HISTORY,
          true);

  ae = AnalysisEngineFactory.createEngine(aed);
  ae.initialize(new CustomResourceSpecifier_impl(), Collections.emptyMap());
  SharedFongoResource sfr = (SharedFongoResource) ae.getUimaContext().getResourceObject(MONGO);

  events = sfr.getDB().getCollection("test");

  assertEquals(0L, events.count());
}
 
Example #9
Source File: MongoSentencesTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws ResourceInitializationException, ResourceAccessException {
  // Create a description of an external resource - a fongo instance, in the same way we would
  // have created a shared mongo resource
  ExternalResourceDescription erd =
      ExternalResourceFactory.createNamedResourceDescription(
          MONGO, SharedFongoResource.class, "fongo.collection", "sentences", "fongo.data", "[]");

  // Create the analysis engine
  AnalysisEngineDescription aed =
      AnalysisEngineFactory.createEngineDescription(MongoSentences.class, MONGO, erd);
  ae = AnalysisEngineFactory.createEngine(aed);
  ae.initialize(new CustomResourceSpecifier_impl(), Collections.emptyMap());

  SharedFongoResource sfr = (SharedFongoResource) ae.getUimaContext().getResourceObject(MONGO);
  sentences = sfr.getDB().getCollection("sentences");

  // Ensure we start with no data!
  assertEquals(0L, sentences.count());
}
 
Example #10
Source File: UploadInteractionsToMongoTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void test()
    throws ResourceInitializationException, AnalysisEngineProcessException, IOException,
        ResourceAccessException {
  final File file = File.createTempFile("test", "uimt");
  Files.asCharSink(file, StandardCharsets.UTF_8)
      .write("Type,SubType\nMOVEMENT,went,source,target,went,VERB,gone");

  final AnalysisEngine ae =
      create(UploadInteractionsToMongo.class, "mongo", fongoErd, "input", file);
  execute(ae);

  final SharedFongoResource sfr =
      (SharedFongoResource) ae.getUimaContext().getResourceObject("mongo");
  final MongoCollection<Document> relationTypes = sfr.getDB().getCollection("relationTypes");
  assertTrue(relationTypes.count() > 0);
  final MongoCollection<Document> interactions = sfr.getDB().getCollection("interactions");
  assertTrue(interactions.count() > 0);
}
 
Example #11
Source File: ConcurrentTokenizer.java    From Canova with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the current instance with the given context.
 * 
 * Note: Do all initialization in this method, do not use the constructor.
 */
public void initialize(UimaContext context)
    throws ResourceInitializationException {

  super.initialize(context);

  TokenizerModel model;

  try {
    TokenizerModelResource modelResource = (TokenizerModelResource) context
        .getResourceObject(UimaUtil.MODEL_PARAMETER);

    model = modelResource.getModel();
  } catch (ResourceAccessException e) {
    throw new ResourceInitializationException(e);
  }

  tokenizer = new TokenizerME(model);
}
 
Example #12
Source File: ConcurrentTokenizer.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the current instance with the given context.
 * 
 * Note: Do all initialization in this method, do not use the constructor.
 */
public void initialize(UimaContext context) throws ResourceInitializationException {

    super.initialize(context);

    TokenizerModel model;

    try {
        TokenizerModelResource modelResource =
                        (TokenizerModelResource) context.getResourceObject(UimaUtil.MODEL_PARAMETER);

        model = modelResource.getModel();
    } catch (ResourceAccessException e) {
        throw new ResourceInitializationException(e);
    }

    tokenizer = new TokenizerME(model);
}
 
Example #13
Source File: ConcurrentTokenizer.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the current instance with the given context.
 *
 * Note: Do all initialization in this method, do not use the constructor.
 */
public void initialize(UimaContext context) throws ResourceInitializationException {

    super.initialize(context);

    TokenizerModel model;

    try {
        TokenizerModelResource modelResource =
                        (TokenizerModelResource) context.getResourceObject(UimaUtil.MODEL_PARAMETER);

        model = modelResource.getModel();
    } catch (ResourceAccessException e) {
        throw new ResourceInitializationException(e);
    }

    tokenizer = new TokenizerME(model);
}
 
Example #14
Source File: AnnotatorContext_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public URI getResourceURI(String aKey, String[] aParams) throws AnnotatorContextException {
  try {
    return mUimaContext.getResourceURI(aKey, aParams);
  } catch (ResourceAccessException e) {
    throw new AnnotatorContextException(e);
  }
}
 
Example #15
Source File: AnnotatorContext_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * @see org.apache.uima.analysis_engine.annotator.AnnotatorContext#getResourceURL(java.lang.String,
 *      java.lang.String[])
 */
public URL getResourceURL(String aKey, String[] aParams) throws AnnotatorContextException {
  try {
    return mUimaContext.getResourceURL(aKey, aParams);
  } catch (ResourceAccessException e) {
    throw new AnnotatorContextException(e);
  }
}
 
Example #16
Source File: AnnotatorContext_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * @see org.apache.uima.analysis_engine.annotator.AnnotatorContext#getResourceObject(java.lang.String,
 *      java.lang.String[])
 */
public Object getResourceObject(String aKey, String[] aParams) throws AnnotatorContextException {
  try {
    return mUimaContext.getResourceObject(aKey, aParams);
  } catch (ResourceAccessException e) {
    throw new AnnotatorContextException(e);
  }
}
 
Example #17
Source File: MalletClassifierTrainerTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Before
public void before()
    throws URISyntaxException, ResourceInitializationException, AnalysisEngineProcessException,
        ResourceAccessException {

  List<String> data = new TestData().asList();

  try {
    modelPath = Files.createTempFile("model", ".mallet");
    resultPath = Files.createTempFile("result", ".csv");
    Files.delete(resultPath);
  } catch (IOException e) {
    throw new ResourceInitializationException(e);
  }

  fongoErd =
      ExternalResourceFactory.createNamedResourceDescription(
          SharedMongoResource.RESOURCE_KEY,
          SharedFongoResource.class,
          "fongo.collection",
          COLLECTION,
          "fongo.data",
          data.toString());

  stopWordsErd =
      ExternalResourceFactory.createNamedResourceDescription(
          MaxEntClassifierTrainer.KEY_STOPWORDS, SharedStopwordResource.class);
}
 
Example #18
Source File: AnnotatorContext_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * @see org.apache.uima.analysis_engine.annotator.AnnotatorContext#getResourceAsStream(java.lang.String,
 *      java.lang.String[])
 */
public InputStream getResourceAsStream(String aKey, String[] aParams)
        throws AnnotatorContextException {
  try {
    return mUimaContext.getResourceAsStream(aKey, aParams);
  } catch (ResourceAccessException e) {
    throw new AnnotatorContextException(e);
  }
}
 
Example #19
Source File: AnnotatorContext_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Acquires a Resource object using the ResourceManager.
 * 
 * @see org.apache.uima.analysis_engine.annotator.AnnotatorContext#getResourceObject(String)
 */
public Object getResourceObject(String aKey) throws AnnotatorContextException {
  try {
    return mUimaContext.getResourceObject(aKey);
  } catch (ResourceAccessException e) {
    throw new AnnotatorContextException(e);
  }
}
 
Example #20
Source File: AnnotatorContext_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Acquires Resource InputStreams using the ResourceManager, or, if that fails, the ClassLoader.
 * 
 * @see org.apache.uima.analysis_engine.annotator.AnnotatorContext#getResourceAsStream(String)
 */
public InputStream getResourceAsStream(String aKey) throws AnnotatorContextException {
  try {
    return mUimaContext.getResourceAsStream(aKey);
  } catch (ResourceAccessException e) {
    throw new AnnotatorContextException(e);
  }
}
 
Example #21
Source File: AnnotatorContext_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public String getResourceFilePath(String aKey) throws AnnotatorContextException {
  try {
    return mUimaContext.getResourceFilePath(aKey);
  } catch (ResourceAccessException e) {
    throw new AnnotatorContextException(e);
  }
}
 
Example #22
Source File: AnnotatorContext_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public URI getResourceURI(String aKey) throws AnnotatorContextException {
  try {
    return mUimaContext.getResourceURI(aKey);
  } catch (ResourceAccessException e) {
    throw new AnnotatorContextException(e);
  }
}
 
Example #23
Source File: AnnotatorContext_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Locates Resource URL's using the ResourceManager, or, if that fails, the ClassLoader.
 * 
 * @see org.apache.uima.analysis_engine.annotator.AnnotatorContext#getResourceURL(String)
 */
public URL getResourceURL(String aKey) throws AnnotatorContextException {
  try {
    return mUimaContext.getResourceURL(aKey);
  } catch (ResourceAccessException e) {
    throw new AnnotatorContextException(e);
  }
}
 
Example #24
Source File: ResourceManager_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * @see org.apache.uima.resource.ResourceManager#getResource(String)
 */
@Override
public Object getResource(String aName) throws ResourceAccessException {
  checkDestroyed();
  Object r = mResourceMap.get(aName);
  // if this is a ParameterizedDataResource, it is an error
  if (r instanceof ParameterizedDataResource) {
    throw new ResourceAccessException(ResourceAccessException.PARAMETERS_REQUIRED,
            new Object[] { aName });
  }
  return r;
}
 
Example #25
Source File: ResourceManager_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private InputStream getResourceAsStreamCommon(Object resource) throws ResourceAccessException {
  checkDestroyed();
  try {
    if (resource != null && resource instanceof DataResource) {
      return ((DataResource) resource).getInputStream();
    } else {
      return null;
    }
  } catch (IOException e) {
    throw new ResourceAccessException(e);
  }    
}
 
Example #26
Source File: UimaContext_ImplBase.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private URI getResourceURIfromURL(URL resourceUrl) throws ResourceAccessException {
  if (resourceUrl != null) {
    try {
      return UriUtils.quote(resourceUrl);
    } catch (URISyntaxException e) {
      throw new ResourceAccessException(e);
    }
  }
  else {
    return null;
  } 
}
 
Example #27
Source File: UimaContext_ImplBase.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public String getResourceFilePath(String aKey) throws ResourceAccessException {
  URI resourceUri = getResourceURI(aKey);
  if (resourceUri != null) {
    if ("file".equals(resourceUri.getScheme())) {
      return resourceUri.getPath();
    } 
    else {
      throw new ResourceAccessException(); //TODO: error message
    }
  }
  else {
    return null;
  }
}
 
Example #28
Source File: UimaContext_ImplBase.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public String getResourceFilePath(String aKey, String[] aParams) throws ResourceAccessException {
  URI resourceUri = getResourceURI(aKey, aParams);
  if (resourceUri != null) {
    if ("file".equals(resourceUri.getScheme())) {
      return resourceUri.getPath();
    } 
    else {
      throw new ResourceAccessException(); //TODO: error message
    }
  }
  else {
    return null;
  }
}
 
Example #29
Source File: UimaContext_ImplBase.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * @see org.apache.uima.analysis_engine.annotator.AnnotatorContext#getResourceURL(java.lang.String,
 *      java.lang.String[])
 */
@Override
public URL getResourceURL(String aKey, String[] aParams) throws ResourceAccessException {
  URL result = getResourceManager().getResourceURL(makeQualifiedName(aKey), aParams);
  if (result != null) {
    return result;
  } else {
    // try as an unmanaged resource (deprecated)
    URL unmanagedResourceUrl = null;
    try {
      unmanagedResourceUrl = getResourceManager().resolveRelativePath(aKey);
    } catch (MalformedURLException e) {
      // if key is not a valid path then it cannot be resolved to an unmanged resource
    }
    if (unmanagedResourceUrl != null) {
      UIMAFramework.getLogger().logrb(Level.WARNING, this.getClass().getName(), "getResourceURL",
              LOG_RESOURCE_BUNDLE, "UIMA_unmanaged_resource__WARNING", new Object[] { aKey });
      return unmanagedResourceUrl;
    }
    return null;
  }
}
 
Example #30
Source File: MongoTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws ResourceInitializationException, ResourceAccessException {
  // Create a description of an external resource - a fongo instance, in the same way we would
  // have created a shared mongo resource
  ExternalResourceDescription erd =
      ExternalResourceFactory.createNamedResourceDescription(
          MONGO, SharedFongoResource.class, "fongo.collection", "test", "fongo.data", "[]");
  ExternalResourceDescription historyErd =
      ExternalResourceFactory.createNamedResourceDescription(
          PipelineBuilder.BALEEN_HISTORY, InMemoryBaleenHistory.class);

  history = Mockito.mock(BaleenHistory.class);

  // Create the analysis engine
  AnalysisEngineDescription aed =
      AnalysisEngineFactory.createEngineDescription(
          Mongo.class,
          MONGO,
          erd,
          "collection",
          "test",
          PipelineBuilder.BALEEN_HISTORY,
          historyErd,
          "outputHistory",
          Boolean.TRUE);
  ae = AnalysisEngineFactory.createEngine(aed);
  ae.initialize(new CustomResourceSpecifier_impl(), Collections.emptyMap());
  SharedFongoResource sfr = (SharedFongoResource) ae.getUimaContext().getResourceObject(MONGO);
  history = (BaleenHistory) ae.getUimaContext().getResourceObject(PipelineBuilder.BALEEN_HISTORY);

  entities = sfr.getDB().getCollection("entities");
  documents = sfr.getDB().getCollection("documents");
  relations = sfr.getDB().getCollection("relations");

  // Ensure we start with no data!
  assertEquals(0L, documents.count());
  assertEquals(0L, entities.count());
  assertEquals(0L, relations.count());
}