org.apache.uima.resource.ExternalResourceDescription Java Examples

The following examples show how to use org.apache.uima.resource.ExternalResourceDescription. 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: ExternalResourceFactory.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
/**
 * Scan the given resource specifier for external resource dependencies and whenever a dependency
 * with the given key is encountered, the given resource is bound to it.
 * 
 * @param aDesc
 *          a description.
 * @param aKey
 *          the key to bind to.
 * @param aResDesc
 *          the resource description.
 */
private static void scanRecursivelyForDependenciesByKeyAndBind(AnalysisEngineDescription aDesc,
        String aKey, ExternalResourceDescription aResDesc) throws InvalidXMLException {
  // Recursively address delegates
  if (!aDesc.isPrimitive()) {
    for (ResourceSpecifier delegate : aDesc.getDelegateAnalysisEngineSpecifiers().values()) {
      bindResource(delegate, aKey, aResDesc);
    }
  }

  // Bind if necessary
  for (ExternalResourceDependency dep : aDesc.getExternalResourceDependencies()) {
    if (aKey.equals(dep.getKey())) {
      bindResourceOnce(aDesc, aKey, aResDesc);
    }
  }
}
 
Example #2
Source File: UimaMeetingAnnotator.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  File outputDirectory = new File("target/examples/tutorial/ex6/");
  outputDirectory.mkdirs();

  ExternalResourceDescription resource = createSharedResourceDescription(
          "file:org/apache/uima/fit/examples/tutorial/ex6/uimaAcronyms.txt",
          StringMapResource_impl.class);

  AggregateBuilder builder = new AggregateBuilder();
  builder.add(createEngineDescription(UimaAcronymAnnotator.class,
          UimaAcronymAnnotator.RES_ACRONYM_TABLE, resource));
  builder.add(createEngineDescription(UimaMeetingAnnotator.class,
          UimaMeetingAnnotator.RES_UIMA_TERM_TABLE, resource));
  AnalysisEngineDescription aggregate = builder.createAggregateDescription();

  aggregate.toXML(new FileOutputStream(new File(outputDirectory, "UimaMeetingDetectorTAE.xml")));
}
 
Example #3
Source File: BaleenCollectionReaderTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void testHasNextLooping() throws Exception {

  ExternalResourceDescription contentExtractor =
      ExternalResourceFactory.createNamedResourceDescription(
          KEY_CONTENT_EXTRACTOR, FakeBaleenContentExtractor.class);

  DummyBaleenCollectionReader cr =
      (DummyBaleenCollectionReader)
          CollectionReaderFactory.createReader(
              DummyBaleenCollectionReader.class,
              BaleenCollectionReader.KEY_CONTENT_EXTRACTOR,
              contentExtractor);

  while (cr.hasNext()) {
    JCas jCas = JCasSingleton.getJCasInstance();
    cr.getNext(jCas.getCas());
  }

  cr.destroy();
}
 
Example #4
Source File: ExternalResourceFactory.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
/**
 * Determine which kind of external resource the given value is. This is only meant for
 * uimaFIT internal use. This method is required by the ConfigurationParameterFactory, so it is
 * package private instead of private.
 */
static ResourceValueType getResourceParameterType(Object aValue) {
  if (aValue == null) {
    return ResourceValueType.NO_RESOURCE;
  }
  
  boolean isResourcePrimitive = aValue instanceof ExternalResourceDescription;
  boolean isResourceArray = aValue.getClass().isArray()
          && ExternalResourceDescription.class.isAssignableFrom(aValue.getClass()
                  .getComponentType());
  boolean isResourceCollection = (Collection.class.isAssignableFrom(aValue
          .getClass()) && !((Collection) aValue).isEmpty() && ((Collection) aValue)
          .iterator().next() instanceof ExternalResourceDescription);
  if (isResourcePrimitive) {
    return ResourceValueType.PRIMITIVE;
  } else if (isResourceArray) {
    return ResourceValueType.ARRAY;
  } else if (isResourceCollection) {
    return ResourceValueType.COLLECTION;
  } else {
    return ResourceValueType.NO_RESOURCE;
  }
}
 
Example #5
Source File: TopicModelTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void testSingleFileToTopic() throws Exception {
  ExternalResourceDescription stopWordsErd =
      ExternalResourceFactory.createNamedResourceDescription(
          TopicModelTrainer.KEY_STOPWORDS, SharedStopwordResource.class);

  jCas.setDocumentText("Baleen is amazing!.");

  processJCas(
      PARAM_MODEL,
      Paths.get(MODEL_URL.toURI()).toString(),
      PARAM_METADTA_KEY,
      "key",
      KEY_STOPWORDS,
      stopWordsErd);

  JCasMetadata metadata = new JCasMetadata(jCas);
  Optional<String> value = metadata.find("key");
  assertTrue(value.isPresent());
  assertEquals("[amazing, tired, view, awesome, place]", value.get());
}
 
Example #6
Source File: ExternalResourceFactoryTest.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
/**
 * Test sharing a resource list across aggregates.
 */
@Test
public void testMultiValue3() throws Exception {
  MultiValuedResourceAE.resources.clear();
  
  ExternalResourceDescription extDesc1 = createResourceDescription(ResourceWithAssert.class);
  ExternalResourceDescription extDesc2 = createResourceDescription(ResourceWithAssert.class);

  AnalysisEngineDescription aed = createEngineDescription(
          createEngineDescription(MultiValuedResourceAE.class,
                  MultiValuedResourceAE.RES_RESOURCE_ARRAY, asList(extDesc1, extDesc2)),
          createEngineDescription(createEngineDescription(MultiValuedResourceAE.class,
                  MultiValuedResourceAE.RES_RESOURCE_ARRAY, asList(extDesc1, extDesc2))));
  
  AnalysisEngine ae = createEngine(aed);
  ae.process(ae.newJCas());

  // Check that the shared resources are really the same
  assertEquals(MultiValuedResourceAE.resources.get(0), MultiValuedResourceAE.resources.get(2));
  assertEquals(MultiValuedResourceAE.resources.get(1), MultiValuedResourceAE.resources.get(3));
}
 
Example #7
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 #8
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 #9
Source File: ElasticsearchRestTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws UIMAException, IOException {

  ExternalResourceDescription erd =
      ExternalResourceFactory.createNamedResourceDescription(
          ELASTICSEARCH,
          SharedElasticsearchRestResource.class,
          PARAM_URL,
          elasticsearch.getHttpUrl());

  AnalysisEngineDescription aed =
      AnalysisEngineFactory.createEngineDescription(
          ElasticsearchRest.class,
          TypeSystemSingleton.getTypeSystemDescriptionInstance(),
          ELASTICSEARCH,
          erd);

  ae = AnalysisEngineFactory.createEngine(aed);
}
 
Example #10
Source File: ExternalResourceFactoryTest.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
/**
 * Test sharing a resource list between two AEs on the same aggregate.
 */
@Test
public void testMultiValue2() throws Exception {
  MultiValuedResourceAE.resources.clear();
  
  ExternalResourceDescription extDesc1 = createResourceDescription(ResourceWithAssert.class);
  ExternalResourceDescription extDesc2 = createResourceDescription(ResourceWithAssert.class);

  AnalysisEngineDescription aed = createEngineDescription(
          createEngineDescription(MultiValuedResourceAE.class,
                  MultiValuedResourceAE.RES_RESOURCE_ARRAY, asList(extDesc1, extDesc2)),
          createEngineDescription(MultiValuedResourceAE.class,
                  MultiValuedResourceAE.RES_RESOURCE_ARRAY, asList(extDesc1, extDesc2)));
  
  AnalysisEngine ae = createEngine(aed);
  ae.process(ae.newJCas());
  
  // Check that the shared resources are really the same
  assertEquals(MultiValuedResourceAE.resources.get(0), MultiValuedResourceAE.resources.get(2));
  assertEquals(MultiValuedResourceAE.resources.get(1), MultiValuedResourceAE.resources.get(3));
}
 
Example #11
Source File: ExtnlResBindSection.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Bindings can't be edited. They can be removed or new ones bound. External resources can be
 * edited. Edit button is disabled unles an editable thing is selected. But user could double
 * click an illegal entry
 * 
 */
private void handleEdit() {
  TreeItem item = tree.getSelection()[0];
  if (isBoundSpec(item))
    return;
  ExternalResourceDescription xrd = getXRDescriptionFromTreeItem(item);
  ResourceSpecifier rs = xrd.getResourceSpecifier();
  if (!((rs instanceof FileResourceSpecifier) || (rs instanceof FileLanguageResourceSpecifier))) {
    Utility.popMessage("Can''t edit custom resource", "This resource is a '"
            + rs.getClass().getName()
            + "', and any edits have to be done directly in the XML in the Source view.",
            MessageDialog.INFORMATION);
    return;
  }

  AddExternalResourceDialog dialog = new AddExternalResourceDialog(this, xrd);

  if (dialog.open() == Window.CANCEL)
    return;
  alterExistingXRD(dialog, xrd, item);
}
 
Example #12
Source File: ExternalResourceFactoryTest.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
/**
 * Test sharing a resource list between two AEs on the same aggregate.
 */
@SuppressWarnings("javadoc")
@Test
public void testMultiValue2() throws Exception {
  MultiValuedResourceAE.resources.clear();

  ExternalResourceDescription extDesc1 = createResourceDescription(ResourceWithAssert.class);
  ExternalResourceDescription extDesc2 = createResourceDescription(ResourceWithAssert.class);

  AnalysisEngineDescription aed = createEngineDescription(
          createEngineDescription(MultiValuedResourceAE.class,
                  MultiValuedResourceAE.RES_RESOURCE_ARRAY, asList(extDesc1, extDesc2)),
          createEngineDescription(MultiValuedResourceAE.class,
                  MultiValuedResourceAE.RES_RESOURCE_ARRAY, asList(extDesc1, extDesc2)));

  CpePipeline.runPipeline(CollectionReaderFactory.createReaderDescription(Reader.class), aed);

  // Check that the shared resources are really the same
  assertEquals(MultiValuedResourceAE.resources.get(0), MultiValuedResourceAE.resources.get(2));
  assertEquals(MultiValuedResourceAE.resources.get(1), MultiValuedResourceAE.resources.get(3));
}
 
Example #13
Source File: ExternalResourceFactoryTest.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
@Test
  public void testMultiBoundNested() throws Exception {
    ExternalResourceDescription extDesc = createResourceDescription(
            IntermediateResourceWithAssert.class,
            IntermediateResourceWithAssert.PARAM_NESTED_RESOURCE,
            createResourceDescription(ResourceWithAssert.class));

    // Binding external resource to each Annotator individually
    AnalysisEngineDescription aed1 = createEngineDescription(MultiBindAE.class,
            MultiBindAE.RES_KEY, extDesc);
    AnalysisEngineDescription aed2 = createEngineDescription(MultiBindAE.class,
            MultiBindAE.RES_KEY, extDesc);

    // Check the external resource was injected
    MultiBindAE.reset();
    AnalysisEngineDescription aed = createEngineDescription(aed1, aed2);
    AnalysisEngine ae = createEngine(aed);
    ae.process(ae.newJCas());


    // Check the external resource was injected
    MultiBindAE.reset();
//    SimplePipeline.runPipeline(CasCreationUtils.createCas(aed.getAnalysisEngineMetaData()), aed);
    SimplePipeline.runPipeline(ae.newCAS(), aed);
  }
 
Example #14
Source File: PipelineBuilder.java    From baleen with Apache License 2.0 5 votes vote down vote up
protected void configureResources() throws BaleenException {
  LOGGER.debug("Configuring history");
  ExternalResourceDescription erdHistory = configureHistory();
  resourceDescriptors.put(BALEEN_HISTORY, erdHistory);

  LOGGER.debug("Configuring content extractor");
  ExternalResourceDescription erdContentExtractor = configureContentExtractor();
  resourceDescriptors.put(CONTENT_EXTRACTOR, erdContentExtractor);
}
 
Example #15
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
  final ExternalResourceDescription erd =
      ExternalResourceFactory.createNamedResourceDescription(
          MONGO,
          SharedFongoResource.class,
          PARAM_FONGO_COLLECTION,
          "test",
          PARAM_FONGO_DATA,
          "[]");
  final ExternalResourceDescription idErd =
      ExternalResourceFactory.createNamedResourceDescription(
          SharedIdGenerator.RESOURCE_KEY, SharedIdGenerator.class);

  // Create the analysis engine
  final AnalysisEngineDescription aed =
      AnalysisEngineFactory.createEngineDescription(
          Mongo.class, MONGO, erd, SharedIdGenerator.RESOURCE_KEY, idErd);
  ae = AnalysisEngineFactory.createEngine(aed);
  ae.initialize(new CustomResourceSpecifier_impl(), Collections.emptyMap());
  final SharedFongoResource sfr =
      (SharedFongoResource) ae.getUimaContext().getResourceObject(MONGO);

  final MongoDatabase db = sfr.getDB();
  documentCollection = db.getCollection(Mongo.DEFAULT_DOCUMENTS_COLLECTION);
  entityCollection = db.getCollection(Mongo.DEFAULT_ENTITY_COLLECTION);
  mentionCollection = db.getCollection(Mongo.DEFAULT_MENTION_COLLECTION);
  relationCollection = db.getCollection(Mongo.DEFAULT_REALTION_COLLECTION);

  assertEquals(0, documentCollection.count());
  assertEquals(0, entityCollection.count());
  assertEquals(0, relationCollection.count());
  assertEquals(0, mentionCollection.count());
}
 
Example #16
Source File: ExtnlResBindSection.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Resource name already defined.
 *
 * @param name the name
 * @return true, if successful
 */
public boolean resourceNameAlreadyDefined(String name) {
  ExternalResourceDescription[] xrds = getExternalResources();
  if (xrds != null) {
    for (int i = 0; i < xrds.length; i++) {
      if (xrds[i].getName().equals(name)) {
        Utility.popMessage("Name Already Defined",
                "The External Resource Name specified is already defined", MessageDialog.ERROR);
        return true;
      }
    }
  }
  return false;
}
 
Example #17
Source File: ExtendedExternalResourceDescription_impl.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
/**
 * @param aExternalResourceDescriptions the external resource descriptions
 */
public void setExternalResources(
        Collection<ExternalResourceDescription> aExternalResourceDescriptions) {
  externalResources = new ArrayList<ExternalResourceDescription>();
  if (externalResources != null) {
    externalResources.addAll(aExternalResourceDescriptions);
  }
}
 
Example #18
Source File: ExternalResourceFactory.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
/**
 * Create a binding for the given external resource in the given resource manager. This method
 * also scans the given external resource for any nested external resources and creates
 * bindings for them as well.
 * <p>
 * <b>NOTE:</b>If you use this method on resource manager configurations of aggregate analysis
 * engine descriptions because it will <b>not have any effects on the delegate analysis
 * engines</b> of the aggregate. If you want to recursively bind an external resource to the
 * delegates in an aggregate engine, use e.g.
 * {@link #bindResource(ResourceSpecifier, String, ExternalResourceDescription)}.
 * 
 * @param aResMgrCfg
 *          the resource manager to create the binding in.
 * @param aBindTo
 *          what key to bind to.
 * @param aRes
 *          the resource that should be bound.
 */
public static void bindResourceOnce(ResourceManagerConfiguration aResMgrCfg, String aBindTo,
        ExternalResourceDescription aRes) {
  // Create a map of all bindings
  Map<String, ExternalResourceBinding> bindings = new HashMap<>();
  for (ExternalResourceBinding b : aResMgrCfg.getExternalResourceBindings()) {
    bindings.put(b.getKey(), b);
  }

  // Create a map of all resources
  Map<String, ExternalResourceDescription> resources = new HashMap<>();
  for (ExternalResourceDescription r : aResMgrCfg.getExternalResources()) {
    resources.put(r.getName(), r);
  }

  // For the current resource, add resource and binding
  ExternalResourceBinding extResBind = createResourceBinding(aBindTo, aRes);
  bindings.put(extResBind.getKey(), extResBind);
  resources.put(aRes.getName(), aRes);

  // Handle nested resources
  bindNestedResources(aRes, bindings, resources);

  // Commit everything to the resource manager configuration
  aResMgrCfg.setExternalResourceBindings(bindings.values().toArray(
          new ExternalResourceBinding[bindings.size()]));
  aResMgrCfg.setExternalResources(resources.values().toArray(
          new ExternalResourceDescription[resources.size()]));
}
 
Example #19
Source File: ElasticsearchTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Before
public void before() throws Exception {

  elasticsearch = new EmbeddedElasticsearch5();

  final ExternalResourceDescription erd =
      ExternalResourceFactory.createNamedResourceDescription(
          RESOURCE_KEY,
          SharedElasticsearchResource.class,
          PARAM_CLUSTER,
          elasticsearch.getClusterName(),
          PARAM_PORT,
          Integer.toString(elasticsearch.getTransportPort()));
  final ExternalResourceDescription idErd =
      ExternalResourceFactory.createNamedResourceDescription(
          SharedIdGenerator.RESOURCE_KEY, SharedIdGenerator.class);

  final AnalysisEngineDescription aed =
      AnalysisEngineFactory.createEngineDescription(
          Elasticsearch.class,
          TypeSystemSingleton.getTypeSystemDescriptionInstance(),
          RESOURCE_KEY,
          erd,
          SharedIdGenerator.RESOURCE_KEY,
          idErd);

  ae = AnalysisEngineFactory.createEngine(aed);
  ae.initialize(new CustomResourceSpecifier_impl(), Collections.emptyMap());

  assertEquals(0, countTypeInIndex(Elasticsearch.DEFAULT_DOCUMENT_TYPE));
  assertEquals(0, countTypeInIndex(Elasticsearch.DEFAULT_ENTITY_TYPE));
  assertEquals(0, countTypeInIndex(Elasticsearch.DEFAULT_RELATION_TYPE));
  assertEquals(0, countTypeInIndex(Elasticsearch.DEFAULT_MENTION_TYPE));
}
 
Example #20
Source File: MaltParserTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Override
protected AnalysisEngine[] createAnalysisEngines() throws ResourceInitializationException {

  // Use OpenNlp to generate the POS etc for us
  final ExternalResourceDescription tokensDesc =
      ExternalResourceFactory.createNamedResourceDescription("tokens", SharedOpenNLPModel.class);
  final ExternalResourceDescription sentencesDesc =
      ExternalResourceFactory.createNamedResourceDescription(
          "sentences", SharedOpenNLPModel.class);
  final ExternalResourceDescription posDesc =
      ExternalResourceFactory.createNamedResourceDescription("posTags", SharedOpenNLPModel.class);
  final ExternalResourceDescription chunksDesc =
      ExternalResourceFactory.createNamedResourceDescription(
          "phraseChunks", SharedOpenNLPModel.class);

  return asArray(
      createAnalysisEngine(
          OpenNLP.class,
          "tokens",
          tokensDesc,
          "sentences",
          sentencesDesc,
          "posTags",
          posDesc,
          "phraseChunks",
          chunksDesc),
      createAnalysisEngine(MaltParser.class));
}
 
Example #21
Source File: MongoStatsTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmptyFile()
    throws ResourceInitializationException, AnalysisEngineProcessException, IOException {
  // Due to limitations in the shared fongo resource we only test document count here!
  ExternalResourceDescription erd =
      ExternalResourceFactory.createNamedResourceDescription(
          "mongo",
          SharedFongoResource.class,
          SharedFongoResource.PARAM_FONGO_COLLECTION,
          "documents",
          SharedFongoResource.PARAM_FONGO_DATA,
          objectMapper.writeValueAsString(DATA));

  File tempFile = File.createTempFile("test", "mongostats");
  try {

    AnalysisEngine task =
        create(MongoStats.class, "mongo", erd, "file", tempFile.getAbsolutePath());
    execute(task);
    task.destroy();

    List<String> lines = Files.readAllLines(tempFile.toPath());
    assertEquals(2, lines.size());
    assertEquals("timestamp,documents,entities,relations", lines.get(0));

    String[] split = lines.get(1).split(",");
    assertEquals("3", split[1]);
    assertEquals("0", split[2]);
    assertEquals("0", split[3]);
  } finally {
    tempFile.delete();
  }
}
 
Example #22
Source File: PipelineBuilder.java    From baleen with Apache License 2.0 5 votes vote down vote up
/** Create a new Collection Reader */
private CollectionReader createCollectionReader() throws BaleenException {
  String className = BuilderUtils.getClassNameFromConfig(collectionReaderConfig);
  Map<String, Object> params =
      BuilderUtils.flattenConfig(null, BuilderUtils.getParamsFromConfig(collectionReaderConfig));

  if (className == null || className.isEmpty()) {
    throw new InvalidParameterException("Collection Reader class not specified");
  }

  Map<String, Object> nonNullParams = params;
  if (nonNullParams == null) {
    nonNullParams = Collections.emptyMap();
  }

  try {
    Class<? extends CollectionReader> clazz =
        BuilderUtils.getClassFromString(className, getDefaultReaderPackage());
    Map<String, ExternalResourceDescription> crResources = getOrCreateResources(clazz);
    Object[] paramArr =
        BuilderUtils.mergeAndExtractParams(
            globalConfig, nonNullParams, ignoreParams, crResources);

    return UIMAFramework.produceCollectionReader(
        CollectionReaderFactory.createReaderDescription(clazz, paramArr), resourceManager, null);
  } catch (ResourceInitializationException e) {
    throw new BaleenException("Couldn't initialize collection reader", e);
  }
}
 
Example #23
Source File: Example6Test.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
@Test
public void test1() throws Exception {
  // This resource is shared between the UimaAcronymAnnotator and UimaMeetingAnnotator
  ExternalResourceDescription resource = createSharedResourceDescription(
          "file:src/main/resources/org/apache/uima/fit/examples/tutorial/ex6/uimaAcronyms.txt",
          StringMapResource_impl.class);

  AggregateBuilder builder = new AggregateBuilder();
  builder.add(createEngineDescription(UimaAcronymAnnotator.class,
          UimaAcronymAnnotator.RES_ACRONYM_TABLE, resource));
  builder.add(createEngineDescription(UimaMeetingAnnotator.class,
          UimaMeetingAnnotator.RES_UIMA_TERM_TABLE, resource));
  AnalysisEngine engine = createEngine(builder.createAggregateDescription());

  JCas jCas = engine.newJCas();
  jCas.setDocumentText("Let's meet to talk about the CPE. The meeting is over at Yorktown 01-144");
  new Meeting(jCas, 0, 33).addToIndexes();

  engine.process(jCas);

  UimaAcronym uimaAcronym = JCasUtil.selectByIndex(jCas, UimaAcronym.class, 0);
  assertNotNull(uimaAcronym);
  assertEquals("CPE", uimaAcronym.getCoveredText());
  assertEquals("Collection Processing Engine", uimaAcronym.getExpandedForm());

  UimaMeeting uimaMeeting = JCasUtil.selectByIndex(jCas, UimaMeeting.class, 0);
  assertNotNull(uimaMeeting);
  assertEquals("Let's meet to talk about the CPE.", uimaMeeting.getCoveredText());
}
 
Example #24
Source File: GenderEnhancerTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() throws Exception {
  ExternalResourceDescription erd =
      ExternalResourceFactory.createNamedResourceDescription(
          "gender", SharedGenderMultiplicityResource.class);
  genderResource = new SharedGenderMultiplicityResource();
  genderResource.initialize(erd.getResourceSpecifier(), Collections.emptyMap());

  genderEnhancer = new GenderEnhancer(genderResource);

  jCas = JCasSingleton.getJCasInstance();
}
 
Example #25
Source File: OpenNLPTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeTest() throws UIMAException {
  super.beforeTest();

  ExternalResourceDescription tokensDesc =
      ExternalResourceFactory.createNamedResourceDescription("tokens", SharedOpenNLPModel.class);
  ExternalResourceDescription sentencesDesc =
      ExternalResourceFactory.createNamedResourceDescription(
          "sentences", SharedOpenNLPModel.class);
  ExternalResourceDescription posDesc =
      ExternalResourceFactory.createNamedResourceDescription("posTags", SharedOpenNLPModel.class);
  ExternalResourceDescription chunksDesc =
      ExternalResourceFactory.createNamedResourceDescription(
          "phraseChunks", SharedOpenNLPModel.class);

  AnalysisEngineDescription descLanguage =
      AnalysisEngineFactory.createEngineDescription(
          uk.gov.dstl.baleen.annotators.language.OpenNLP.class,
          "tokens",
          tokensDesc,
          "sentences",
          sentencesDesc,
          "posTags",
          posDesc,
          "phraseChunks",
          chunksDesc);
  aeLanguage = AnalysisEngineFactory.createEngine(descLanguage);

  String text =
      "This is a mention of John Smith visiting Thomas Brown at the United Nations in New York on the afternoon of February 10th, 2014.";

  jCas.setDocumentText(text);
}
 
Example #26
Source File: HmsTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Before
public void before() throws UIMAException {
  ExternalResourceDescription tokensDesc =
      ExternalResourceFactory.createNamedResourceDescription("tokens", SharedOpenNLPModel.class);
  ExternalResourceDescription sentencesDesc =
      ExternalResourceFactory.createNamedResourceDescription(
          "sentences", SharedOpenNLPModel.class);
  ExternalResourceDescription posDesc =
      ExternalResourceFactory.createNamedResourceDescription("posTags", SharedOpenNLPModel.class);
  ExternalResourceDescription chunksDesc =
      ExternalResourceFactory.createNamedResourceDescription(
          "phraseChunks", SharedOpenNLPModel.class);

  AnalysisEngineDescription desc =
      AnalysisEngineFactory.createEngineDescription(
          OpenNLP.class,
          "tokens",
          tokensDesc,
          "sentences",
          sentencesDesc,
          "posTags",
          posDesc,
          "phraseChunks",
          chunksDesc);

  languageAE = AnalysisEngineFactory.createEngine(desc);
}
 
Example #27
Source File: NationalityTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Override
@Before
public void beforeTest() throws UIMAException {
  super.beforeTest();

  ExternalResourceDescription erd =
      ExternalResourceFactory.createNamedResourceDescription(
          "country", SharedCountryResource.class);
  AnalysisEngineDescription aed =
      AnalysisEngineFactory.createEngineDescription(NationalityRegex.class, "country", erd);

  ae = AnalysisEngineFactory.createEngine(aed);
}
 
Example #28
Source File: RakeKeywordsTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Test
public void testLongDocumentWithText() throws Exception {
  ExternalResourceDescription erd =
      ExternalResourceFactory.createNamedResourceDescription(
          STOPWORDS, SharedStopwordResource.class);
  AnalysisEngineDescription aed =
      AnalysisEngineFactory.createEngineDescription(
          RakeKeywords.class,
          STOPWORDS,
          erd,
          RakeKeywords.PARAM_MAX_KEYWORDS,
          12,
          RakeKeywords.PARAM_ADD_BUZZWORDS,
          true);

  AnalysisEngine ae = AnalysisEngineFactory.createEngine(aed);

  jCas.setDocumentText(
      new String(Files.readAllBytes(Paths.get(getClass().getResource("turing.txt").toURI()))));
  ae.process(jCas);

  JCasMetadata metadata1 = new JCasMetadata(jCas);
  Set<String> fullDocKeywords = metadata1.findAll(KEYWORD_METADATA_KEY);

  jCas.reset();

  jCas.setDocumentText(
      new String(Files.readAllBytes(Paths.get(getClass().getResource("turing.txt").toURI()))));
  new Text(jCas, 0, 250).addToIndexes();
  ae.process(jCas);

  JCasMetadata metadata2 = new JCasMetadata(jCas);
  Set<String> textKeywords = metadata2.findAll(KEYWORD_METADATA_KEY);
  assertFalse(textKeywords.isEmpty());
  assertNotEquals(fullDocKeywords, textKeywords);

  ae.destroy();
}
 
Example #29
Source File: ExternalResourceFactoryTest.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiBinding() throws Exception {
  ExternalResourceDescription extDesc = createResourceDescription(ResourceWithAssert.class);

  // Binding external resource to each Annotator individually
  AnalysisEngineDescription aed1 = createEngineDescription(MultiBindAE.class,
          MultiBindAE.RES_KEY, extDesc);
  AnalysisEngineDescription aed2 = createEngineDescription(MultiBindAE.class,
          MultiBindAE.RES_KEY, extDesc);

  // Check the external resource was injected
  MultiBindAE.reset();
  AnalysisEngineDescription aaed = createEngineDescription(aed1, aed2);
  CpePipeline.runPipeline(CollectionReaderFactory.createReaderDescription(Reader.class), aaed);
}
 
Example #30
Source File: AnalysisEngineFactoryExternalResourceTest.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
/**
   * Test self-injection
   */
  @Test
  public void resource_testDoubleSelfInjection() throws Exception {
    ExternalResourceDescription resDesc = createResourceDescription(
            TestExternalResource2.class, TestExternalResource.PARAM_VALUE,
            TestExternalResource.EXPECTED_VALUE);
    bindResourceOnce(resDesc, TestExternalResource2.PARAM_RESOURCE, resDesc);

    AnalysisEngineDescription aeDesc1 = saveLoad(createEngineDescription(
            TestAnalysisEngineWithResource.class, TestAnalysisEngineWithResource.PARAM_RESOURCE,
            resDesc));

    AnalysisEngineDescription aeDesc2 = saveLoad(createEngineDescription(
            TestAnalysisEngineWithResource.class, TestAnalysisEngineWithResource.PARAM_RESOURCE,
            resDesc));

//    dumpResourceConfiguration(aeDesc1);
//    dumpResourceConfiguration(aeDesc2);

    AnalysisEngine ae1 = createEngine(aeDesc1);
    AnalysisEngine ae2 = createEngine(aeDesc2);
    ae1.process(ae1.newCAS());
    ae2.process(ae2.newCAS());

    AnalysisEngine ae3 = createEngine(createEngineDescription(aeDesc1, aeDesc2));
    ae3.process(ae3.newCAS());
  }