Java Code Examples for org.apache.uima.resource.metadata.Capability#addOutputType()

The following examples show how to use org.apache.uima.resource.metadata.Capability#addOutputType() . 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: AnalysisEnginePoolTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * @see junit.framework.TestCase#setUp()
 */
protected void setUp() throws Exception {
  try {
    super.setUp();
    mSimpleDesc = new AnalysisEngineDescription_impl();
    mSimpleDesc.setFrameworkImplementation(Constants.JAVA_FRAMEWORK_NAME);
    mSimpleDesc.setPrimitive(true);
    mSimpleDesc.getMetaData().setName("Test Primitive TAE");
    mSimpleDesc
            .setAnnotatorImplementationName("org.apache.uima.analysis_engine.impl.TestAnnotator");
    mSimpleDesc.getMetaData().setName("Simple Test");
    Capability cap = new Capability_impl();
    cap.addOutputType("NamedEntity", true);
    cap.addOutputType("DocumentStructure", true);
    Capability[] caps = new Capability[] {cap};
    mSimpleDesc.getAnalysisEngineMetaData().setCapabilities(caps);
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example 2
Source File: CapabilitySection.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Handle add type.
 *
 * @param selItem the sel item
 * @param itemKind the item kind
 */
private void handleAddType(TreeItem selItem, int itemKind) {
  if (itemKind == LANG || itemKind == TYPE || itemKind == SOFA)
    selItem = selItem.getParentItem();
  else if (itemKind == LANG_ITEM || itemKind == FEAT || itemKind == SOFA_ITEM)
    selItem = selItem.getParentItem().getParentItem();
  Capability c = getCapabilityFromTreeItem(selItem);
  AddCapabilityTypeDialog dialog = new AddCapabilityTypeDialog(this, c);
  if (dialog.open() == Window.CANCEL)
    return;

  for (int i = 0; i < dialog.types.length; i++) {

    if (dialog.inputs[i])
      c.addInputType(dialog.types[i], dialog.inputs[i]);

    if (dialog.outputs[i])
      c.addOutputType(dialog.types[i], dialog.outputs[i]);

    TreeItem item = new TreeItem(selItem, SWT.NONE);
    setGuiTypeName(item, dialog.types[i]);
    item.setText(INPUT_COL, dialog.inputs[i] ? INPUT : "");
    item.setText(OUTPUT_COL, dialog.outputs[i] ? OUTPUT : "");

    TreeItem fItem = new TreeItem(item, SWT.NONE);
    fItem.setData(FEAT_TITLE);
    fItem.setText(NAME_COL, ALL_FEATURES);
    fItem.setText(INPUT_COL, dialog.inputs[i] ? INPUT : "");
    fItem.setText(OUTPUT_COL, dialog.outputs[i] ? OUTPUT : "");

    item.setExpanded(true);
  }
  pack04();
  selItem.setExpanded(true);
  finishAction();
}
 
Example 3
Source File: MultiprocessingAnalysisEngine_implTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * @see junit.framework.TestCase#setUp()
 */
protected void setUp() throws Exception {
  try {
    super.setUp();
    mSimpleDesc = new AnalysisEngineDescription_impl();
    mSimpleDesc.setFrameworkImplementation(Constants.JAVA_FRAMEWORK_NAME);
    mSimpleDesc.setPrimitive(true);
    mSimpleDesc
            .setAnnotatorImplementationName("org.apache.uima.analysis_engine.impl.TestAnnotator");
    mSimpleDesc.getMetaData().setName("Simple Test");
    TypeSystemDescription typeSys = new TypeSystemDescription_impl();
    typeSys.addType("foo.Bar", "test", "uima.tcas.Annotation");
    typeSys.addType("NamedEntity", "test", "uima.tcas.Annotation");
    typeSys.addType("DocumentStructure", "test", "uima.tcas.Annotation");
    mSimpleDesc.getAnalysisEngineMetaData().setTypeSystem(typeSys);
    Capability cap = new Capability_impl();
    cap.addOutputType("NamedEntity", true);
    cap.addOutputType("DocumentStructure", true);
    Capability[] caps = new Capability[] {cap};
     mSimpleDesc.getAnalysisEngineMetaData().setCapabilities(caps);

    mAggDesc = new AnalysisEngineDescription_impl();
    mAggDesc.setPrimitive(false);
    mAggDesc.getMetaData().setName("Simple Test Aggregate");
    mAggDesc.getDelegateAnalysisEngineSpecifiersWithImports().put("Test", mSimpleDesc);
    FixedFlow_impl flow = new FixedFlow_impl();
    flow.setFixedFlow(new String[] { "Test" });
    mAggDesc.getAnalysisEngineMetaData().setFlowConstraints(flow);
    mAggDesc.getAnalysisEngineMetaData().setCapabilities(caps);
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example 4
Source File: AnalysisEngine_implTest.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public void testProcess() throws Exception {
    try {
      // test simple primitive TextAnalysisEngine (using TestAnnotator class)
      // This test should work with or without a type system description
      AnalysisEngineDescription primitiveDesc = new AnalysisEngineDescription_impl();
      primitiveDesc.setPrimitive(true);
      primitiveDesc
              .setAnnotatorImplementationName("org.apache.uima.analysis_engine.impl.TestAnnotator");
      primitiveDesc.getMetaData().setName("Test Primitive TAE");

//      TypeSystemDescription tsd = new TypeSystemDescription_impl();
//      tsd.addType("NamedEntity", "", "uima.tcas.Annotation");
//      tsd.addType("DocumentStructure", "", "uima.cas.TOP");
//      primitiveDesc.getAnalysisEngineMetaData().setTypeSystem(tsd);
      Capability cap = new Capability_impl();
      cap.addOutputType("NamedEntity", true);
      cap.addOutputType("DocumentStructure", true);
      Capability[] caps = new Capability[] {cap};
      primitiveDesc.getAnalysisEngineMetaData().setCapabilities(caps);
      _testProcess(primitiveDesc);

      primitiveDesc = new AnalysisEngineDescription_impl();
      primitiveDesc.setPrimitive(true);
      primitiveDesc
              .setAnnotatorImplementationName("org.apache.uima.analysis_engine.impl.TestAnnotator");
      primitiveDesc.getMetaData().setName("Test Primitive TAE");

      TypeSystemDescription tsd = new TypeSystemDescription_impl();
      tsd.addType("NamedEntity", "", "uima.tcas.Annotation");
      tsd.addType("DocumentStructure", "", "uima.cas.TOP");
      primitiveDesc.getAnalysisEngineMetaData().setTypeSystem(tsd);
      cap = new Capability_impl();
      cap.addOutputType("NamedEntity", true);
      cap.addOutputType("DocumentStructure", true);
      caps = new Capability[] {cap};
      primitiveDesc.getAnalysisEngineMetaData().setCapabilities(caps);
      _testProcess(primitiveDesc);

      // test simple aggregate TextAnalysisEngine (again using TestAnnotator class)
      AnalysisEngineDescription aggDesc = new AnalysisEngineDescription_impl();
      aggDesc.setPrimitive(false);
      aggDesc.getMetaData().setName("Test Aggregate TAE");
      aggDesc.getDelegateAnalysisEngineSpecifiersWithImports().put("Test", primitiveDesc);
      FixedFlow_impl flow = new FixedFlow_impl();
      flow.setFixedFlow(new String[] { "Test" });
      aggDesc.getAnalysisEngineMetaData().setFlowConstraints(flow);
      aggDesc.getAnalysisEngineMetaData().setCapabilities(caps);
      _testProcess(aggDesc);

      // test aggregate TAE containing a CAS Consumer
      File outFile = JUnitExtension.getFile("CpmOutput.txt");
      if(outFile != null && outFile.exists()) {
        //outFile.delete() //can't be relied upon.  Instead set file to zero length.
        FileOutputStream fos = new FileOutputStream(outFile, false);
        fos.close();
        assertEquals(0,outFile.length());
      }

      AnalysisEngineDescription aggWithCcDesc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(
              new XMLInputSource(JUnitExtension
                      .getFile("TextAnalysisEngineImplTest/AggregateTaeWithCasConsumer.xml")));
      
      _testProcess(aggWithCcDesc, new String[] {"en"});      
      // test that CAS Consumer ran
      if (null == outFile) {
        outFile = JUnitExtension.getFile("CpmOutput.txt");
      }
      assertTrue(outFile != null && outFile.exists());
      assertTrue(outFile.length() > 0);
      outFile.delete();
      
      //test aggregate that uses ParallelStep
      AnalysisEngineDescription desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(
        new XMLInputSource(JUnitExtension.getFile("TextAnalysisEngineImplTest/AggregateForParallelStepTest.xml")));
      AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(desc);
      CAS cas = ae.newCAS();
      cas.setDocumentText("new test");
      ae.process(cas);
      assertEquals("new test", TestAnnotator.lastDocument);
      assertEquals("new test", TestAnnotator2.lastDocument);
      cas.reset();
      
    } catch (Exception e) {
      JUnitExtension.handleException(e);
    }
  }