org.apache.uima.resource.CustomResourceSpecifier Java Examples

The following examples show how to use org.apache.uima.resource.CustomResourceSpecifier. 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: CachedUtsSynonymExpansionProvider.java    From bioasq with Apache License 2.0 6 votes vote down vote up
@Override
public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
        throws ResourceInitializationException {
  boolean ret = super.initialize(aSpecifier, aAdditionalParams);
  // initialize delegate
  CustomResourceSpecifier delegateResourceSpecifier = new CustomResourceSpecifier_impl();
  delegateResourceSpecifier.setResourceClassName(delegateClass.getCanonicalName());
  delegate = delegateClass.cast(UIMAFramework.produceResource(delegateClass,
          delegateResourceSpecifier, aAdditionalParams));
  // initialize mapdb
  File file = new File((String) getParameterValue("db-file"));
  db = DBMaker.newFileDB(file).compressionEnable().commitFileSyncDisable().cacheSize(128)
          .closeOnJvmShutdown().make();
  String map = (String) getParameterValue("map-name");
  id2synonyms = db.getHashMap(map);
  return ret;
}
 
Example #2
Source File: CachedUtsConceptSearchProvider.java    From bioasq with Apache License 2.0 6 votes vote down vote up
@Override
public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
        throws ResourceInitializationException {
  boolean ret = super.initialize(aSpecifier, aAdditionalParams);
  // initialize delegate
  CustomResourceSpecifier delegateResourceSpecifier = new CustomResourceSpecifier_impl();
  delegateResourceSpecifier.setResourceClassName(delegateClass.getCanonicalName());
  delegate = delegateClass.cast(UIMAFramework.produceResource(delegateClass,
          delegateResourceSpecifier, aAdditionalParams));
  // initialize mapdb
  File file = new File((String) getParameterValue("db-file"));
  db = DBMaker.newFileDB(file).compressionEnable().commitFileSyncDisable().cacheSize(128)
          .closeOnJvmShutdown().make();
  String map = (String) getParameterValue("map-name");
  string2concept = db.getHashMap(map);
  return ret;
}
 
Example #3
Source File: UimaFactoryInjectionTest.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
private static void initUimaApplicationContext(final ApplicationContext aApplicationContext) {
  new UIMAFramework_impl() {
    {
      CompositeResourceFactory_impl factory = (CompositeResourceFactory_impl) getResourceFactory();
      factory.registerFactory(CasConsumerDescription.class,
              aApplicationContext.getBean(CasConsumerFactory_impl.class));
      factory.registerFactory(CasInitializerDescription.class,
              aApplicationContext.getBean(CasInitializerFactory_impl.class));
      factory.registerFactory(CollectionReaderDescription.class,
              aApplicationContext.getBean(CollectionReaderFactory_impl.class));
      factory.registerFactory(ResourceCreationSpecifier.class,
              aApplicationContext.getBean(AnalysisEngineFactory_impl.class));
      factory.registerFactory(CustomResourceSpecifier.class,
              aApplicationContext.getBean(CustomResourceFactory_impl.class));
    }
  };
}
 
Example #4
Source File: CustomResourceSpecifierFactory_implTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testProduceResource() throws Exception {
  CustomResourceSpecifier specifier = UIMAFramework.getResourceSpecifierFactory().createCustomResourceSpecifier();
  specifier.setResourceClassName("org.apache.uima.impl.SomeCustomResource");
  Parameter[] parameters = new Parameter[2];
  parameters[0] = UIMAFramework.getResourceSpecifierFactory().createParameter();
  parameters[0].setName("param1");
  parameters[0].setValue("val1");
  parameters[1] = UIMAFramework.getResourceSpecifierFactory().createParameter();
  parameters[1].setName("param2");
  parameters[1].setValue("val2");
  specifier.setParameters(parameters);    
  
  Resource res = crFactory.produceResource(Resource.class, specifier, Collections.EMPTY_MAP);   
  assertTrue(res instanceof SomeCustomResource);
  assertEquals("val1", ((SomeCustomResource)res).paramMap.get("param1"));
  assertEquals("val2", ((SomeCustomResource)res).paramMap.get("param2"));
  
  //also UIMAFramework.produceResource should do the same thing
  res = UIMAFramework.produceResource(specifier, Collections.EMPTY_MAP);    
  assertTrue(res instanceof SomeCustomResource);
  assertEquals("val1", ((SomeCustomResource)res).paramMap.get("param1"));
  assertEquals("val2", ((SomeCustomResource)res).paramMap.get("param2"));  
}
 
Example #5
Source File: XMLParser_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public CustomResourceSpecifier parseCustomResourceSpecifier(XMLInputSource aInput, ParsingOptions aOptions) throws InvalidXMLException {
  // attempt to locate resource specifier schema
  XMLizable object = parse(aInput, RESOURCE_SPECIFIER_NAMESPACE, SCHEMA_URL, aOptions);

  if (object instanceof CustomResourceSpecifier) {
    return (CustomResourceSpecifier) object;
  } else {
    throw new InvalidXMLException(InvalidXMLException.INVALID_CLASS, new Object[] {
            CustomResourceSpecifier.class.getName(), object.getClass().getName() });
  }
}
 
Example #6
Source File: XMLParser_implTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testParseCustomResourceSpecifier() throws Exception {
  XMLInputSource in = new XMLInputSource(
          JUnitExtension.getFile("XmlParserTest/TestCustomResourceSpecifier.xml"));
  CustomResourceSpecifier uriSpec = mXmlParser.parseCustomResourceSpecifier(in);
  assertEquals("foo.bar.MyResource", uriSpec.getResourceClassName());
  Parameter[] params = uriSpec.getParameters();
  assertEquals(2, params.length);
  assertEquals("param1", params[0].getName());
  assertEquals("val1", params[0].getValue());
  assertEquals("param2", params[1].getName());
  assertEquals("val2", params[1].getValue());  
}
 
Example #7
Source File: SomeCustomResource.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public boolean initialize(ResourceSpecifier aSpecifier, Map aAdditionalParams) throws ResourceInitializationException {
  Assert.assertTrue(aSpecifier instanceof CustomResourceSpecifier);
  Parameter[] params = ((CustomResourceSpecifier)aSpecifier).getParameters();
  for (int i = 0; i < params.length; i++) {
    paramMap.put(params[i].getName(), params[i].getValue());
  }
  return true;
}
 
Example #8
Source File: XMLParser_impl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public CustomResourceSpecifier parseCustomResourceSpecifier(XMLInputSource aInput) throws InvalidXMLException {
  return parseCustomResourceSpecifier(aInput, DEFAULT_PARSING_OPTIONS);
}
 
Example #9
Source File: ResourceSpecifierFactory_impl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public CustomResourceSpecifier createCustomResourceSpecifier() {
  return (CustomResourceSpecifier) createObject(CustomResourceSpecifier.class);
}
 
Example #10
Source File: ExternalResourceFactory.java    From uima-uimafit with Apache License 2.0 3 votes vote down vote up
/**
 * Find the name of the class implementing this resource. The location where this name is stored
 * varies, depending if the resource extends {@link SharedResourceObject} or implements
 * {@link Resource}.
 * 
 * @param aDesc
 *          the external resource description.
 * @return the implementation name.
 */
protected static String getImplementationName(ExternalResourceDescription aDesc) {
  if (aDesc.getResourceSpecifier() instanceof CustomResourceSpecifier) {
    return ((CustomResourceSpecifier) aDesc.getResourceSpecifier()).getResourceClassName();
  } else {
    return aDesc.getImplementationName();
  }
}
 
Example #11
Source File: AbstractSection.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Checks if is jms descriptor.
 *
 * @param inputDescription the input description
 * @return true, if is jms descriptor
 */
protected boolean isJmsDescriptor (XMLizable inputDescription) {
  return (inputDescription instanceof CustomResourceSpecifier) &&
  ("org.apache.uima.aae.jms_adapter.JmsAnalysisEngineServiceAdapter".equals(
      ((CustomResourceSpecifier)inputDescription).getResourceClassName()));
}
 
Example #12
Source File: ResourceSpecifierFactory.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a <code>CustomResourceSpecifier</code>.
 * 
 * @return an instance of an object implementing <code>CustomResourceSpecifier</code>.
 */
public CustomResourceSpecifier createCustomResourceSpecifier();
 
Example #13
Source File: XMLParser.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Parses a CustomResourceSpecifier from an XML input stream.
 * 
 * @param aInput
 *          the input source from which to read the XML document
 * 
 * @return a <code>CustomResourceSpecifier</code> object constructed from the XML document
 * 
 * @throws InvalidXMLException
 *           if the input XML is not valid or does not specify a valid CustomResourceSpecifier
 */
public CustomResourceSpecifier parseCustomResourceSpecifier(XMLInputSource aInput)
        throws InvalidXMLException;
 
Example #14
Source File: XMLParser.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Parses a CustomResourceSpecifier from an XML input stream.
 * 
 * @param aInput
 *          the input source from which to read the XML document
 * @param aOptions
 *          option settings
 * 
 * @return a <code>CustomResourceSpecifier</code> object constructed from the XML document
 * 
 * @throws InvalidXMLException
 *           if the input XML is not valid or does not specify a valid CustomResourceSpecifier
 */
public CustomResourceSpecifier parseCustomResourceSpecifier(XMLInputSource aInput,
        ParsingOptions aOptions) throws InvalidXMLException;