Package org.apache.uima.collection.metadata

Examples of org.apache.uima.collection.metadata.CpeCasProcessor


    } else if (source == moveAeLeftButton) {
      int index = aeTabbedPane.getSelectedIndex();
      if (index > 0) {
        // update CPE descriptor
        try {
          CpeCasProcessor casProcToMove = currentCpeDesc.getCpeCasProcessors().getCpeCasProcessor(
                  index);
          currentCpeDesc.getCpeCasProcessors().removeCpeCasProcessor(index);
          currentCpeDesc.getCpeCasProcessors().addCpeCasProcessor(casProcToMove, index - 1);
        } catch (CpeDescriptorException e) {
          displayError(e);
          return;
        }
        // update GUI
        aeTabbedPane.moveTab(index, index - 1);
        aeTabbedPane.setSelectedIndex(index - 1);
        Object specifierToMove = aeSpecifiers.remove(index);
        aeSpecifiers.add(index - 1, specifierToMove);
      }
    } else if (source == moveAeRightButton) {
      int index = aeTabbedPane.getSelectedIndex();
      if (index > -1 && index < aeTabbedPane.getTabCount() - 1) {
        // update CPE descriptor
        try {
          CpeCasProcessor casProcToMove = currentCpeDesc.getCpeCasProcessors().getCpeCasProcessor(
                  index);
          currentCpeDesc.getCpeCasProcessors().removeCpeCasProcessor(index);
          currentCpeDesc.getCpeCasProcessors().addCpeCasProcessor(casProcToMove, index + 1);
        } catch (CpeDescriptorException e) {
          displayError(e);
          return;
        }
        // update GUI
        aeTabbedPane.moveTab(index, index + 1);
        aeTabbedPane.setSelectedIndex(index + 1);
        Object specifierToMove = aeSpecifiers.remove(index);
        aeSpecifiers.add(index + 1, specifierToMove);
      }
    } else if (source == addConsumerButton) {
      int rv = consumerFileChooser.showOpenDialog(addConsumerButton);

      if (rv == JFileChooser.APPROVE_OPTION) {
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

        File file = consumerFileChooser.getSelectedFile();

        // Create consumer panel on the tabbed pane
        // for this consumer specifier file:

        try {
          addConsumer(file.getPath());
        } catch (Exception e) {
          displayError(e);
        }

        int lastTabIndex = consumerTabbedPane.getTabCount() - 1;
        consumerTabbedPane.setSelectedIndex(lastTabIndex);

        setCursor(Cursor.getDefaultCursor());
      }
    } else if (source == moveConsumerLeftButton) {
      int index = consumerTabbedPane.getSelectedIndex();
      if (index > 0) {
        // update CPE descriptor
        try {
          int absIndex = aeSpecifiers.size() + index;
          CpeCasProcessor casProcToMove = currentCpeDesc.getCpeCasProcessors().getCpeCasProcessor(
                  absIndex);
          currentCpeDesc.getCpeCasProcessors().removeCpeCasProcessor(absIndex);
          currentCpeDesc.getCpeCasProcessors().addCpeCasProcessor(casProcToMove, absIndex - 1);
        } catch (CpeDescriptorException e) {
          displayError(e);
          return;
        }
        // update GUI
        consumerTabbedPane.moveTab(index, index - 1);
        consumerTabbedPane.setSelectedIndex(index - 1);
        Object specifierToMove = consumerSpecifiers.remove(index);
        consumerSpecifiers.add(index - 1, specifierToMove);
      }
    } else if (source == moveConsumerRightButton) {
      int index = consumerTabbedPane.getSelectedIndex();
      if (index > -1 && index < consumerTabbedPane.getTabCount() - 1) {
        // update CPE descriptor
        try {
          int absIndex = aeSpecifiers.size() + index;
          CpeCasProcessor casProcToMove = currentCpeDesc.getCpeCasProcessors().getCpeCasProcessor(
                  absIndex);
          currentCpeDesc.getCpeCasProcessors().removeCpeCasProcessor(absIndex);
          currentCpeDesc.getCpeCasProcessors().addCpeCasProcessor(casProcToMove, absIndex + 1);
        } catch (CpeDescriptorException e) {
          displayError(e);
View Full Code Here


  }

  private void addAE(String aeSpecifierFile) throws CpeDescriptorException, InvalidXMLException,
          IOException, ResourceConfigurationException {
    String tempAeName = new File(aeSpecifierFile).getName(); // overriden later
    CpeCasProcessor casProc = CpeDescriptorFactory.produceCasProcessor(tempAeName);
    casProc.setDescriptor(aeSpecifierFile);
    casProc.setBatchSize(10000);
    casProc.getErrorHandling().getErrorRateThreshold().setMaxErrorCount(0);

    // add to pipeline as last AE but before CAS Consumers
    currentCpeDesc.addCasProcessor(aeTabbedPane.getTabCount(), casProc);

    // update GUI
View Full Code Here

  }

  private void addConsumer(String consumerSpecifierFile) throws CpeDescriptorException,
          InvalidXMLException, IOException, ResourceConfigurationException {
    String tempName = new File(consumerSpecifierFile).getName(); // overriden later
    CpeCasProcessor casProc = CpeDescriptorFactory.produceCasProcessor(tempName);
    casProc.setDescriptor(consumerSpecifierFile);
    casProc.setBatchSize(10000);
    casProc.getErrorHandling().getErrorRateThreshold().setMaxErrorCount(0);

    // add to pipeline as last CAS Processor
    currentCpeDesc.addCasProcessor(casProc);
    // update GUI
    addConsumer(casProc);
View Full Code Here

                                        .currentThread().getName() })));
      }

      Hashtable namesMap = new Hashtable();
      for (int i = 0; i < casProcessorList.length; i++) {
        CpeCasProcessor processorType = casProcessorList[i];
        if (processorType == null) {
          throw new ResourceConfigurationException(InvalidXMLException.ELEMENT_NOT_FOUND,
                  new Object[] { "<casProcessor>", "<casProcessors>" }, new Exception(
                          CpmLocalizedMessage.getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                                  "UIMA_CPM_EXP_bad_cpe_descriptor__WARNING", new Object[] { Thread
                                          .currentThread().getName() })));
        }

        // Check for duplicate Cas Processor names. Names must be unique
        if (namesMap.containsKey(processorType.getName())) {
          throw new ResourceConfigurationException(InvalidXMLException.INVALID_CPE_DESCRIPTOR,
                  new Object[] { "casProcessor", "name" }, new CPMException(CpmLocalizedMessage
                          .getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                                  "UIMA_CPM_EXP_duplicate_name__WARNING", new Object[] {
                                      Thread.currentThread().getName(), processorType.getName() })));
        } else {
          namesMap.put(processorType.getName(), processorType.getName());
        }

        String deploymentType = processorType.getDeployment();
        if (deploymentType == null) {
          throw new ResourceConfigurationException(InvalidXMLException.REQUIRED_ATTRIBUTE_MISSING,
                  new Object[] { "deployment", "<casProcessor>" }, new Exception(
                          CpmLocalizedMessage.getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                                  "UIMA_CPM_EXP_missing_attribute_from_xml_element__WARNING",
                                  new Object[] { Thread.currentThread().getName(),
                                      processorType.getName(), "deployment", "casProcessor" })));
        }
        CasProcessor casProcessor = null;
        String deployModel = "";
        boolean cpInMap = false;

        // Check if the CP has already been instantiated. The map holds one instance of a CP with a
        // given name
        // The purpose of the map is to provide access to CP operational parameters. This is needed
        // to
        // determine if multiple instances of the CP are allowed.
        if (cpMap.containsKey(processorType.getName())) {
          cpInMap = true; // the CasProcessor is in the map
          casProcessor = (CasProcessor) cpMap.get(processorType.getName());
          // Check operational parameters to determine if multiple instances of the CP are allowed
          if (!casProcessor.getProcessingResourceMetaData().getOperationalProperties()
                  .isMultipleDeploymentAllowed()) {
            continue; // one instance already created. Multiple instances of this CP not allowed
          }
        }

        if (Constants.DEPLOYMENT_LOCAL.equals(deploymentType.toLowerCase())) {
          casProcessor = produceLocalCasProcessor(processorType);
          deployModel = Constants.DEPLOYMENT_LOCAL;
        } else if (Constants.DEPLOYMENT_INTEGRATED.equals(deploymentType.toLowerCase())) {

          casProcessor = produceIntegratedCasProcessor(processorType);
          deployModel = Constants.DEPLOYMENT_INTEGRATED;
        } else if (Constants.DEPLOYMENT_REMOTE.equals(deploymentType.toLowerCase())) {
          casProcessor = produceRemoteCasProcessor(processorType);
          deployModel = Constants.DEPLOYMENT_REMOTE;
        } else {
          throw new ResourceConfigurationException(InvalidXMLException.REQUIRED_ATTRIBUTE_MISSING,
                  new Object[] { "deployment", "<casProcessor>" }, new Exception(
                          CpmLocalizedMessage.getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                                  "UIMA_CPM_Exception_invalid_deployment__WARNING", new Object[] {
                                      Thread.currentThread().getName(), processorType.getName(),
                                      deploymentType })));
        }

        // Add the casProcessor instantiated above to the map. The map is used to check if
        // multiple instances of the cp are allowed. Need to store an instance in the map
        // since the only way to determine whether or not multiple instances are allowed is
        // to check OperationalProperties in the CP metadata.
        if (!cpInMap) {
          cpMap.put(processorType.getName(), casProcessor);
        }

        String name = casProcessor.getProcessingResourceMetaData().getName();
        if (!casProcessorConfigMap.containsKey(name)) {
          casProcessorConfigMap.put(name, processorType);
        } else {
          // Throw an exception due to a non-unique name. CPM requires Cas Processors to have a
          // unique name.
          // The unique name enforcement for Local and Remote CP's is done
          // above 'if ( namesMap.containsKey(processorType.getName()))'. In case of integrated CP,
          // the
          // name is taken from the CP descriptor. For Local and Remote, the names are taken from
          // the
          // CPE descriptor
          if (firstTime && Constants.DEPLOYMENT_INTEGRATED.equalsIgnoreCase(deployModel)) {
            throw new ResourceConfigurationException(new CPMException(CpmLocalizedMessage
                    .getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                            "UIMA_CPM_EXP_duplicate_name__WARNING", new Object[] {
                                Thread.currentThread().getName(), processorType.getName() })));
          }
        }

        v.add(casProcessor);
      }
View Full Code Here

    if (getCpeDescriptor().getCpeCasProcessors() != null
            && getCpeDescriptor().getCpeCasProcessors().getAllCpeCasProcessors() != null) {
      index = getCpeDescriptor().getCpeCasProcessors().getAllCpeCasProcessors().length;
    }
    for (int i = 0; i < index; i++) {
      CpeCasProcessor processor = getCpeDescriptor().getCpeCasProcessors().getCpeCasProcessor(i);
      String name = processor.getName();
      if (name != null && name.equalsIgnoreCase(aName)) {
        return false;
      }
    }
    return true;
View Full Code Here

   *
   * @return -
   */
  private CpeCasProcessor addCasProcessor(String aCasProcessorName)
          throws ResourceConfigurationException {
    CpeCasProcessor newProcessor = null;
    try {
      if (!isUniqueName(aCasProcessorName)) {
        throw new ResourceConfigurationException(new Exception(CpmLocalizedMessage
                .getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                        "UIMA_CPM_EXP_duplicate_name__WARNING", new Object[] {
                            Thread.currentThread().getName(), aCasProcessorName })));
      }
      int index = getCpeDescriptor().getCpeCasProcessors().getAllCpeCasProcessors().length; // getcasProcessorCount();

      if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
        UIMAFramework.getLogger(this.getClass()).logrb(
                Level.FINEST,
                this.getClass().getName(),
                "initialize",
                CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                "UIMA_CPM_add_cp_with_index__FINEST",
                new Object[] { Thread.currentThread().getName(), aCasProcessorName,
                    String.valueOf(index) });
      }
      CpeCasProcessor processor = getCpeDescriptor().getCpeCasProcessors().getCpeCasProcessor(
              index - 1);

      if (processor.getCheckpoint() == null) {
        throw new ResourceConfigurationException(InvalidXMLException.ELEMENT_NOT_FOUND,
                new Object[] { "checkpoint", "casProcessor" }, new Exception(CpmLocalizedMessage
                        .getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                                "UIMA_CPM_EXP_missing_xml_element__WARNING", new Object[] {
                                    Thread.currentThread().getName(), aCasProcessorName,
                                    "<checkpoint>" })));
      }

      // For remote Cas Processor make sure that the required parameters are defined.
      // Specifically, VNS host and port are required. Do validation now. If it fails, the
      // ResourceConfigurationException is thrown and we are out here.
      if (Constants.DEPLOYMENT_REMOTE.equals(processor.getDeployment())) {
        String protocol = DeployFactory.getProtocol(processor, getResourceManager());
        if (Constants.VINCI_PROTOCOL.equals(protocol)) {
          verifyDeploymentParams(aCasProcessorName, processor.getDeploymentParams());
        }
      }

      if (processorCount == 0) {
        newProcessor = processor;
View Full Code Here

        // entries.
        numProcessors = aList.size() - procIndex;
      } else {
        numProcessors = processorList.getAllCpeCasProcessors().length;
      }
      CpeCasProcessor newProcessor = null;

      // Now add each casProcessor to a descriptor
      for (int i = 0; i < numProcessors; i++) {
        String[] casProcInfo = (String[]) aList.get(procIndex + i);
        if (create) {
          if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
            UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
                    "initialize", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                    "UIMA_CPM_create_new_cp_from_list__FINEST",
                    new Object[] { Thread.currentThread().getName(), casProcInfo[0] });
          }
          // The list suppose to contain an array of Strings of size 2.
          // Where the the first element is the name of the CasProcessor
          // and the second is the descriptor path
          if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
            UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
                    "initialize", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                    "UIMA_CPM_add_cp_from_list__FINEST",
                    new Object[] { Thread.currentThread().getName(), casProcInfo[0] });
          }
          newProcessor = addCasProcessor(casProcInfo[0]);
        } else {
          newProcessor = processorList.getCpeCasProcessor(i);
        }
        if (newProcessor != null) {
          newProcessor.setDescriptor(casProcInfo[1]);
        }
      }

      if (create) {
        // Set global flag as an indicator that the CPE Descriptor has been instantiated
View Full Code Here

                .setConfigurationParameterSettings(null);
      }
    }
    // Analysis Engines
    for (int i = 0; i < aeSpecifiers.size(); i++) {
      CpeCasProcessor casProc = currentCpeDesc.getCpeCasProcessors().getCpeCasProcessor(i);
      AnalysisEnginePanel aePanel = (AnalysisEnginePanel) aeTabbedPane.getComponentAt(i);
      if (aePanel.isModified()) {
        CasProcessorConfigurationParameterSettings settings = CpeDescriptorFactory
                .produceCasProcessorConfigurationParameterSettings();
        casProc.setConfigurationParameterSettings(settings);
        createParameterOverrides(settings, aePanel);
      } else {
        casProc.setConfigurationParameterSettings(null);
      }
    }
    // CAS Consumers
    for (int i = 0; i < consumerSpecifiers.size(); i++) {
      CpeCasProcessor casProc = currentCpeDesc.getCpeCasProcessors().getCpeCasProcessor(
              aeSpecifiers.size() + i);
      ConsumerPanel consumerPanel = (ConsumerPanel) consumerTabbedPane.getComponentAt(i);
      if (consumerPanel.isModified()) {
        CasProcessorConfigurationParameterSettings settings = CpeDescriptorFactory
                .produceCasProcessorConfigurationParameterSettings();
        casProc.setConfigurationParameterSettings(settings);
        createParameterOverrides(settings, consumerPanel);
      } else {
        casProc.setConfigurationParameterSettings(null);
      }
    }
  }
View Full Code Here

        }
       
        // CAS Processors
        casProcs = cpeDesc.getCpeCasProcessors().getAllCpeCasProcessors();
        for (int i=0; i < casProcs.length; i++) {
            CpeCasProcessor casProc = casProcs[i];
            String specifierFile = casProcs[i].getDescriptor();
            ResourceSpecifier specifier = UIMAFramework.getXMLParser().
            parseResourceSpecifier(new XMLInputSource(specifierFile));
//            if (isCasConsumerSpecifier(specifier)) {
//                addConsumer(specifierFile);
View Full Code Here

    // if no explicite settings in CPE Xml descriptor
    static public CasProcessorErrorHandling getCpeDefaultErrorHandling ()
    {
        // CPE BUG!!! Need to call CpeDescriptorFactory.produceDescriptor();
//        CpeDescription cpeDesc = CpeDescriptorFactory.produceDescriptor();
        CpeCasProcessor casProc = CpeDescriptorFactory.produceCasProcessor("dummy name");
        return casProc.getErrorHandling();
    }
View Full Code Here

TOP

Related Classes of org.apache.uima.collection.metadata.CpeCasProcessor

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.