Package org.apache.uima.resource.metadata

Examples of org.apache.uima.resource.metadata.Capability


      md.setDescription("Does not do anything useful.");
      md.setVersion("1.0");
      md.setTypeSystem(typeSystem);
      md.setTypePriorities(typePriorities);
      md.setFsIndexes(new FsIndexDescription[] { index, index2 });
      Capability cap1 = new Capability_impl();
      cap1.addInputType("Fake", false);
      cap1.addInputFeature("TestFeature");
      Capability cap2 = new Capability_impl();
      cap2.addInputType("Fake", true);
      cap1.setLanguagesSupported(new String[] { "en", "de" });
      cap1.setMimeTypesSupported(new String[] { "text/plain" });
      md.setCapabilities(new Capability[] { cap1, cap2 });
      ConfigurationParameter cfgParam1 = new ConfigurationParameter_impl();
      cfgParam1.setName("param1");
View Full Code Here


    // set capabilities from the argument to this call or from the annotation present in the
    // component if the argument is null
    if (capabilities != null) {
      desc.getAnalysisEngineMetaData().setCapabilities(capabilities);
    } else {
      Capability capability = CapabilityFactory.createCapability(componentClass);
      if (capability != null) {
        desc.getAnalysisEngineMetaData().setCapabilities(new Capability[] { capability });
      }
    }
View Full Code Here

    if (!ReflectionUtil.isAnnotationPresent(componentClass, SofaCapability.class)
            && !ReflectionUtil.isAnnotationPresent(componentClass, TypeCapability.class)) {
      return null;
    }

    Capability capability = new Capability_impl();

    if (ReflectionUtil.isAnnotationPresent(componentClass, SofaCapability.class)) {
      SofaCapability annotation = ReflectionUtil.getAnnotation(componentClass, SofaCapability.class);
      String[] inputSofas = annotation.inputSofas();
      if (inputSofas.length == 1 && inputSofas[0].equals(SofaCapability.NO_DEFAULT_VALUE)) {
        inputSofas = new String[0];
      }
      capability.setInputSofas(inputSofas);

      String[] outputSofas = annotation.outputSofas();
      if (outputSofas.length == 1 && outputSofas[0].equals(SofaCapability.NO_DEFAULT_VALUE)) {
        outputSofas = new String[0];
      }
      capability.setOutputSofas(outputSofas);
    }

    if (ReflectionUtil.isAnnotationPresent(componentClass, TypeCapability.class)) {
      TypeCapability annotation = ReflectionUtil.getAnnotation(componentClass, TypeCapability.class);
      String[] inputTypesOrFeatureNames = annotation.inputs();
      capability.setInputs(createTypesOrFeatures(inputTypesOrFeatureNames));
      String[] outputTypesOrFeatureNames = annotation.outputs();
      capability.setOutputs(createTypesOrFeatures(outputTypesOrFeatureNames));
    }

    return capability;
  }
View Full Code Here

    // set capabilities from the argument to this call or from the annotation present in the
    // component if the argument is null
    if (capabilities != null) {
      desc.getCollectionReaderMetaData().setCapabilities(capabilities);
    } else {
      Capability capability = CapabilityFactory.createCapability(readerClass);
      if (capability != null) {
        desc.getCollectionReaderMetaData().setCapabilities(new Capability[] { capability });
      }
    }
View Full Code Here

    // collect all the inputs and all the outputs in 2 Hashtables
    Hashtable mergedInputs = new Hashtable();
    Hashtable mergedOutputs = new Hashtable();
    Iterator allList = allCapabilities.iterator();
    while (allList.hasNext()) {
      Capability entry = (Capability) allList.next();
      // get inputs/outputs for this entry
      TypeOrFeature[] entryInps = entry.getInputs();
      TypeOrFeature[] entryOuts = entry.getOutputs();
      // add/merge inputs in Hashtable
      for (int i = 0; i < entryInps.length; i++) {
        TypeOrFeature nextTof = entryInps[i];
        String name = nextTof.getName();
        TypeOrFeature prevTof = (TypeOrFeature) mergedInputs.get(name);
        if (prevTof != null) {
          // choose next or prev, if it's 'type'
          if (prevTof.isType()) {
            // leave more general one
            if (!prevTof.isAllAnnotatorFeatures() && nextTof.isAllAnnotatorFeatures())
              mergedInputs.put(name, nextTof);
          }
        } else
          // add next ToF
          mergedInputs.put(name, nextTof);
      }
      // add/merge outputs in Hashtable
      for (int i = 0; i < entryOuts.length; i++) {
        TypeOrFeature nextTof = entryOuts[i];
        String name = nextTof.getName();
        TypeOrFeature prevTof = (TypeOrFeature) mergedOutputs.get(name);
        if (prevTof != null) {
          // choose next or prev, if it's 'type'
          if (prevTof.isType()) {
            // leave more general one
            if (!prevTof.isAllAnnotatorFeatures() && nextTof.isAllAnnotatorFeatures())
              mergedOutputs.put(name, nextTof);
          }
        } else
          // add next ToF
          mergedOutputs.put(name, nextTof);
      }
    }
    // create merged Capability object and add merged inputs/outputs
    Capability mergedCapability = rsFactory.createCapability();
    // add merged inputs
    Enumeration inpsList = mergedInputs.keys();
    while (inpsList.hasMoreElements()) {
      String name = (String) inpsList.nextElement();
      TypeOrFeature tof = (TypeOrFeature) mergedInputs.get(name);
      if (tof.isType())
        mergedCapability.addInputType(name, tof.isAllAnnotatorFeatures());
      else
        mergedCapability.addInputFeature(name);
    }
    // add merged outputs
    Enumeration outsList = mergedOutputs.keys();
    while (outsList.hasMoreElements()) {
      String name = (String) outsList.nextElement();
      TypeOrFeature tof = (TypeOrFeature) mergedOutputs.get(name);
      if (tof.isType())
        mergedCapability.addOutputType(name, tof.isAllAnnotatorFeatures());
      else
        mergedCapability.addOutputFeature(name);
    }
    // put merged Capability in the array
    Capability[] mergedArray = new Capability[1];
    mergedArray[0] = mergedCapability;
    return mergedArray;
View Full Code Here

   */
  public void setMetadata(ProcessingResourceMetaData aMetadata) {
    metadata = aMetadata;
    Capability[] capabilities = metadata.getCapabilities();
    for (int j = 0; capabilities != null && j < capabilities.length; j++) {
      Capability capability = capabilities[j];
      TypeOrFeature[] tORf = capability.getInputs();
      if (tORf != null) {
        String newKey;
        boolean modified = false;
        // Convert the types if necessary
        for (int i = 0; i < tORf.length; i++) {
View Full Code Here

//      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)
View Full Code Here

  }

  private void handleRemove(TableTreeItem removeItem, int itemKind) {
    Table table = tt.getTable();
    int previousSelection = table.getSelectionIndex() - 1;
    Capability c = getCapability(removeItem);
    switch (itemKind) {
      case CS: {
        if (Window.CANCEL == Utility.popOkCancel("Confirm Remove",
                "This action will remove an entire capability set.  Please confirm.",
                MessageDialog.WARNING)) {
          table.setSelection(table.getSelectionIndex() + 1);
          return;
        }
        removeCapabilitySet(c);
        removeItem.dispose();
        break;
      }
      case LANG_ITEM: {
        c.setLanguagesSupported(stringArrayRemove(c.getLanguagesSupported(), removeItem
                .getText(NAME_COL)));
        removeItem.dispose();
        break;
      }
      case SOFA_ITEM: {
        if (Window.CANCEL == Utility
                .popOkCancel(
                        "Confirm Removal of Sofa",
                        "This action will remove this Sofa as a capability, and delete its mappings if no other capability set declares this Sofa."
                                + "  Please confirm.", MessageDialog.WARNING)) {
          table.setSelection(table.getSelectionIndex() + 1);
          return;
        }
        String sofaName = removeItem.getText(NAME_COL);
        boolean isInput = INPUT.equals(removeItem.getText(INPUT_COL));
        if (isInput)
          c.setInputSofas((String[]) Utility.removeElementFromArray(c.getInputSofas(), sofaName,
                  String.class));
        else
          c.setOutputSofas((String[]) Utility.removeElementFromArray(c.getOutputSofas(), sofaName,
                  String.class));
        removeItem.dispose();

        if (!anyCapabilitySetDeclaresSofa(sofaName, isInput)) {
          Comparator comparator = new Comparator() {
            public int compare(Object o1, Object o2) {
              String name = (String) o1;
              SofaMapping sofaMapping = (SofaMapping) o2;
              if (name.equals(sofaMapping.getAggregateSofaName()))
                return 0;
              return 1;
            }
          };
          editor.getAeDescription().setSofaMappings(
                  (SofaMapping[]) Utility.removeElementsFromArray(getSofaMappings(), sofaName,
                          SofaMapping.class, comparator));

          sofaMapSection.markStale();
        }
        break;
      }
      case TYPE: {
        if (Window.CANCEL == Utility.popOkCancel("Confirm Removal of Type",
                "This action will remove this type as a capability.  Please confirm.",
                MessageDialog.WARNING)) {
          table.setSelection(table.getSelectionIndex() + 1);
          return;
        }
        TableTreeItem[] features = removeItem.getItems();
        if (null != features)
          for (int i = 0; i < features.length; i++) {
            removeFeature(c, features[i]);
          }
        String typeNameToRemove = getFullyQualifiedName(removeItem);
        if (isInput(removeItem))
          c.setInputs(typeOrFeatureArrayRemove(c.getInputs(), typeNameToRemove));
        if (isOutput(removeItem) /* || isUpdate(removeItem) */)
          c.setOutputs(typeOrFeatureArrayRemove(c.getOutputs(), typeNameToRemove));

        removeItem.dispose();
        break;
      }
      case FEAT: {
View Full Code Here

      selItem = selItem.getParentItem();
    else if (itemKind == TYPE || itemKind == SOFA)
      selItem = selItem.getParentItem().getItems()[0];
    else if (itemKind == FEAT || itemKind == SOFA_ITEM)
      selItem = selItem.getParentItem().getParentItem().getItems()[0];
    Capability c = getCapabilityFromTableTreeItem(selItem.getParentItem());
    CommonInputDialog dialog = new CommonInputDialog(
            this,
            "Add Language",
            "Enter a two letter ISO-639 language code, followed optionally by a two-letter ISO-3166 country code (Examples: fr or fr-CA)",
            CommonInputDialog.LANGUAGE);
    if (dialogForLanguage(c, dialog) == Window.CANCEL)
      return;

    c.setLanguagesSupported(stringArrayAdd(c.getLanguagesSupported(), dialog.getValue()));

    // update GUI
    TableTreeItem lItem = new TableTreeItem(selItem, SWT.NONE);
    lItem.setData(LANG_TITLE);
    lItem.setText(NAME_COL, dialog.getValue());
View Full Code Here

  private void handleAddType(TableTreeItem 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 = getCapabilityFromTableTreeItem(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]);

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

TOP

Related Classes of org.apache.uima.resource.metadata.Capability

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.