Package org.apache.uima.analysis_engine

Examples of org.apache.uima.analysis_engine.AnalysisEngineProcessException


    stream.setGreedyRuleElement(greedyRuleElement);
    stream.setGreedyRule(greedyRule);
    try {
      script.apply(stream, crowd);
    } catch (Throwable e) {
      throw new AnalysisEngineProcessException(AnalysisEngineProcessException.ANNOTATOR_EXCEPTION,
              new Object[] {}, e);
    }
    crowd.finished(stream);

    if (removeBasics) {
View Full Code Here


      for (String seederClass : seeders) {
        Class<?> loadClass = null;
        try {
          loadClass = Class.forName(seederClass);
        } catch (ClassNotFoundException e) {
          throw new AnalysisEngineProcessException(e);
        }
        Object newInstance = null;
        try {
          newInstance = loadClass.newInstance();
        } catch (Exception e) {
          throw new AnalysisEngineProcessException(e);
        }
        try {
          RutaAnnotationSeeder seeder = (RutaAnnotationSeeder) newInstance;
          result.add(seeder.seed(cas.getDocumentText(), cas));
        } catch (Exception e) {
          throw new AnalysisEngineProcessException(e);
        }
      }
    }
    return result;
  }
View Full Code Here

    if (scriptLocation == null) {
      try {
        String mainScriptPath = mainScript.replaceAll("\\.", "/") + SCRIPT_FILE_EXTENSION;
        script = loadScriptIS(mainScriptPath);
      } catch (IOException e) {
        throw new AnalysisEngineProcessException(new FileNotFoundException("Script [" + mainScript
                + "] cannot be found at [" + collectionToString(scriptPaths)
                + "] or classpath with extension .ruta"));
      } catch (RecognitionException e) {
        throw new AnalysisEngineProcessException(new FileNotFoundException("Script [" + mainScript
                + "] cannot be found at [" + collectionToString(scriptPaths)
                + "] or classpath  with extension .ruta"));
      }
    } else {
      try {
        script = loadScript(scriptLocation);
      } catch (Exception e) {
        throw new AnalysisEngineProcessException(e);
      }
    }

    Map<String, RutaModule> additionalScriptsMap = new HashMap<String, RutaModule>();
    Map<String, AnalysisEngine> additionalEnginesMap = new HashMap<String, AnalysisEngine>();

    if (additionalUimafitEngines != null) {
      for (String eachUimafitEngine : additionalUimafitEngines) {
        AnalysisEngine eachEngine = null;
        try {
          @SuppressWarnings("unchecked")
          // Class clazz = this.getClass().getClassLoader().loadClass(eachUimafitEngine) ;
          Class<? extends AnalysisComponent> uimafitClass = (Class<? extends AnalysisComponent>) Class
                  .forName(eachUimafitEngine);
          eachEngine = AnalysisEngineFactory.createEngine(uimafitClass);
        } catch (ClassNotFoundException e) {
          throw new AnalysisEngineProcessException(e);
        } catch (ResourceInitializationException e) {
          throw new AnalysisEngineProcessException(e);
        }
        try {
          additionalEnginesMap.put(eachUimafitEngine, eachEngine);
          String[] eachEngineLocationPartArray = eachUimafitEngine.split("\\.");
          if (eachEngineLocationPartArray.length > 1) {
            String shortEachEngineLocation = eachEngineLocationPartArray[eachEngineLocationPartArray.length - 1];
            additionalEnginesMap.put(shortEachEngineLocation, eachEngine);
          }
        } catch (Exception e) {
          throw new AnalysisEngineProcessException(e);
        }
      }
    }
    if (additionalEngines != null) {
      for (String eachEngineLocation : additionalEngines) {
        AnalysisEngine eachEngine;
        String location = locate(eachEngineLocation, descriptorPaths, ".xml");
        if (location == null) {
          String locationIS = locateIS(eachEngineLocation, descriptorPaths, ".xml");
          try {
            eachEngine = engineLoader.loadEngineIS(locationIS, viewName);
          } catch (InvalidXMLException e) {
            throw new AnalysisEngineProcessException(new FileNotFoundException("Engine at ["
                    + eachEngineLocation + "] cannot be found in ["
                    + collectionToString(descriptorPaths)
                    + "] with extension .xml (from mainScript=" + mainScript + " in "
                    + collectionToString(scriptPaths)));
          } catch (ResourceInitializationException e) {
            throw new AnalysisEngineProcessException(new FileNotFoundException("Engine at ["
                    + eachEngineLocation + "] cannot be found in ["
                    + collectionToString(descriptorPaths)
                    + "] with extension .xml (from mainScript=" + mainScript + " in "
                    + collectionToString(scriptPaths)));
          } catch (IOException e) {
            throw new AnalysisEngineProcessException(new FileNotFoundException("Engine at ["
                    + eachEngineLocation + "] cannot be found in ["
                    + collectionToString(descriptorPaths)
                    + "] with extension .xml (from mainScript=" + mainScript + " in "
                    + collectionToString(scriptPaths)));
          } catch (ResourceConfigurationException e) {
            throw new AnalysisEngineProcessException(e);
          } catch (URISyntaxException e) {
            throw new AnalysisEngineProcessException(e);
          }
        } else {
          try {
            eachEngine = engineLoader.loadEngine(location, viewName);
          } catch (Exception e) {
            throw new AnalysisEngineProcessException(e);
          }
        }
        try {
          additionalEnginesMap.put(eachEngineLocation, eachEngine);
          String[] eachEngineLocationPartArray = eachEngineLocation.split("\\.");
          if (eachEngineLocationPartArray.length > 1) {
            String shortEachEngineLocation = eachEngineLocationPartArray[eachEngineLocationPartArray.length - 1];
            additionalEnginesMap.put(shortEachEngineLocation, eachEngine);
          }
        } catch (Exception e) {
          throw new AnalysisEngineProcessException(e);
        }
      }
    }

    if (additionalScripts != null) {
View Full Code Here

    if (location == null) {
      try {
        String scriptPath = toLoad.replaceAll("\\.", "/") + SCRIPT_FILE_EXTENSION;
        eachScript = loadScriptIS(scriptPath);
      } catch (IOException e) {
        throw new AnalysisEngineProcessException(new FileNotFoundException("Script [" + toLoad
                + "] cannot be found at [" + collectionToString(scriptPaths)
                + "] with extension .ruta"));
      } catch (RecognitionException e) {
        throw new AnalysisEngineProcessException(new FileNotFoundException("Script [" + toLoad
                + "] cannot be found at [" + collectionToString(scriptPaths)
                + "] with extension .ruta"));
      }
    } else {
      try {
        eachScript = loadScript(location);
      } catch (IOException e) {
        throw new AnalysisEngineProcessException(new FileNotFoundException("Script [" + toLoad
                + "] cannot be found at [" + collectionToString(scriptPaths)
                + "] with extension .ruta"));
      } catch (RecognitionException e) {
        throw new AnalysisEngineProcessException(new FileNotFoundException("Script [" + toLoad
                + "] cannot be found at [" + collectionToString(scriptPaths)
                + "] with extension .ruta"));
      }
    }
    additionalScripts.put(toLoad, eachScript);

    for (String add : eachScript.getScripts().keySet()) {
      if (!additionalScripts.containsKey(add)) {
        recursiveLoadScript(add, additionalScripts, additionalEngines, viewName);
      }
    }

    Set<String> engineKeySet = eachScript.getEngines().keySet();
    for (String eachEngineLocation : engineKeySet) {
      if (!additionalEngines.containsKey(eachEngineLocation)) {
        String engineLocation = locate(eachEngineLocation, descriptorPaths, ".xml");
        if (engineLocation == null) {
          String engineLocationIS = locateIS(eachEngineLocation, descriptorPaths, ".xml");
          try {
            AnalysisEngine eachEngine = engineLoader.loadEngineIS(engineLocationIS, viewName);
            additionalEngines.put(eachEngineLocation, eachEngine);
          } catch (Exception e) {
            // uimaFit engine?
            try {
              @SuppressWarnings("unchecked")
              Class<? extends AnalysisComponent> uimafitClass = (Class<? extends AnalysisComponent>) Class
                      .forName(eachEngineLocation);
              AnalysisEngine eachEngine = AnalysisEngineFactory.createEngine(uimafitClass);
              additionalEngines.put(eachEngineLocation, eachEngine);
            } catch (Exception e1) {
              throw new AnalysisEngineProcessException(e1);
            }
          }
        } else {
          try {
            AnalysisEngine eachEngine = engineLoader.loadEngine(engineLocation, viewName);
            additionalEngines.put(eachEngineLocation, eachEngine);
          } catch (Exception e) {
            throw new AnalysisEngineProcessException(e);
          }
        }
      }
    }
  }
View Full Code Here

        jcas = jcaz.getView(inputViewName);
      } else {
        jcas = jcaz;
      }
    } catch (CASException e1) {
      throw new AnalysisEngineProcessException(e1.getCause());
    }
    // init:
    String documentText = jcas.getDocumentText();
    String splitSeq = documentText.contains("\r\n") ? "\r\n" : "\n";
    map = new int[documentText.length() + 1];
    JCas modview = null;
    try {
      // check if view already exists:
      Iterator<JCas> viewIterator = jcas.getViewIterator();
      while (viewIterator.hasNext()) {
        JCas jCas2 = (JCas) viewIterator.next();
        if (jCas2.getViewName().equals(modifiedViewName)) {
          modview = jCas2;
          getContext().getLogger().log(Level.WARNING,
                  "view with name \"" + modifiedViewName + "\" already exists.");
        }
      }
      if (modview == null) {
        modview = jcas.createView(modifiedViewName);
      }
    } catch (CASException e) {
      e.printStackTrace();
      return;
    }
    SortedSet<HtmlConverterPSpan> visibleSpansSoFar = new TreeSet<HtmlConverterPSpan>();
    SortedSet<HtmlConverterPSpan> linebreaksFromHtmlTags = new TreeSet<HtmlConverterPSpan>();

    // process
    try {
      Parser parser = new Parser(documentText);
      NodeList list = parser.parse(null);
      HtmlConverterVisitor visitor = new HtmlConverterVisitor(newlineInducingTags);
      list.visitAllNodesWith(visitor);
      visibleSpansSoFar = visitor.getTextSpans();
      linebreaksFromHtmlTags = visitor.getLinebreaksFromHtmlTags();
    } catch (ParserException e) {
      throw new AnalysisEngineProcessException(e);
    }
    if (replaceLinebreaks) {
      visibleSpansSoFar = this.handleLinebreaksInDocumentText(visibleSpansSoFar, splitSeq);
    }
    if (conversionPolicy == StringConversionPolicy.HEURISTIC) {
View Full Code Here

    ProcessTrace pt = ae.process(jcas);

    // analyze results
    for (ProcessTraceEvent e : pt.getEvents()) {
      if (e != null && e.getResultMessage() != null && e.getResultMessage().contains("error")) {
        throw new AnalysisEngineProcessException();
      }
    }
    return jcas;
  }
View Full Code Here

  public void process(CAS cas) throws AnalysisEngineProcessException {
    try {
      indexWriter.addDocument(createDocument(cas));
    } catch (IOException e) {
      logger.error("processCas(CAS)", e);
      throw new AnalysisEngineProcessException(e);
    }
  }
View Full Code Here

      // get stem() method from stemmer
      Method stemmerStemMethod;
      try {
        stemmerStemMethod = stemmer.getClass().getMethod("stem", new Class[0]);
      } catch (Exception ex) {
        throw new AnalysisEngineProcessException(ex);
      }

      // iterate over all token annotations and add stem if available
      FSIterator<Annotation> tokenIterator = aJCas.getAnnotationIndex(TokenAnnotation.type).iterator();
      while (tokenIterator.hasNext()) {
        // get token content
        TokenAnnotation annot = (TokenAnnotation) tokenIterator.next();
        String span = annot.getCoveredText();

        // set annotation content and call stemmer
        try {
          stemmer.setCurrent(span);
          stemmerStemMethod.invoke(stemmer, emptyArgs);
        } catch (Exception ex) {
          throw new AnalysisEngineProcessException(ex);
        }

        // get stemmer result and set annotation feature
        annot.setStem(stemmer.getCurrent());
      }
View Full Code Here

    mStructureFeature = AnnotatorUtil.getRequiredFeatureParameter(context,
        mNameType, "opennlp.uima.normalizer.StructureFeature");

    if (!SUPPORTED_TYPES.contains(mStructureFeature.getRange().getName())) {
      throw new AnalysisEngineProcessException(
          ExceptionMessages.MESSAGE_CATALOG, "range_type_unsupported",
          new Object[] { mStructureFeature.getRange().getName() });
    }
  }
View Full Code Here

                  // no new CASes are output; this cas is done being processed
                  // by that AnalysisEngine so clear the componentInfo
                  cas.setCurrentComponentInfo(null);
                }
              } else {
                throw new AnalysisEngineProcessException(
                        AnalysisEngineProcessException.UNKNOWN_ID_IN_SEQUENCE,
                        new Object[] { nextAeKey });
              }
            }
            //ParallelStep (TODO: refactor out common parts with SimpleStep?)
            else if (nextStep instanceof ParallelStep) {
              //create modifiable list of destinations
              List<String> destinations = new LinkedList<String>(((ParallelStep)nextStep).getAnalysisEngineKeys());
              //iterate over all destinations, removing them from the list as we go
              while (!destinations.isEmpty()) {
                String nextAeKey = destinations.get(0);
                destinations.remove(0);
                //execute this step as we would a single step
                AnalysisEngine nextAe = (AnalysisEngine) mComponentAnalysisEngineMap.get(nextAeKey);
                if (nextAe != null) {
                  // invoke next AE in flow
                  CasIterator casIter = null;
                  CAS outputCas = null; //used if the AE we call outputs a new CAS
                  try {
                    casIter = nextAe.processAndOutputNewCASes(cas);
                    if (casIter.hasNext()) {
                      outputCas = casIter.next();
                    }
                  }
                  catch(Exception e) {
                    //ask the FlowController if we should continue
                    //TODO: should this be configurable?
                    if (!flow.continueOnFailure(nextAeKey, e)) {
                      throw e;
                    }
                    else {
                      UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINE, CLASS_NAME.getName(), "processUntilNextOutputCas",
                              LOG_RESOURCE_BUNDLE, "UIMA_continuing_after_exception__FINE", e);
                    }
                  }
                  if (outputCas != null) // new CASes are output
                  {
                    // when pushing the stack frame so we know where to pick up later,
                    // be sure to include the incomplete ParallelStep
                    if (!destinations.isEmpty()) {
                      casIteratorStack.push(new StackFrame(casIter, cas, flow, nextAeKey,
                              new ParallelStep(destinations)));
                    } else {
                      casIteratorStack.push(new StackFrame(casIter, cas, flow, nextAeKey));                     
                    }
                     
                    // compute Flow for the output CAS and begin routing it through the flow
                    flow = flow.newCasProduced(outputCas, nextAeKey);
                    cas = outputCas;
                    activeCASes.add(cas);
                    break; //break out of processing of ParallelStep
                  } else {
                    // no new CASes are output; this cas is done being processed
                    // by that AnalysisEngine so clear the componentInfo
                    cas.setCurrentComponentInfo(null);
                  }
                } else {
                  throw new AnalysisEngineProcessException(
                          AnalysisEngineProcessException.UNKNOWN_ID_IN_SEQUENCE,
                          new Object[] { nextAeKey });
                }
              }           
            } else {
              throw new AnalysisEngineProcessException(
                      AnalysisEngineProcessException.UNSUPPORTED_STEP_TYPE, new Object[] { nextStep
                              .getClass() });
            }
            nextStep = flow.next();
          }
          // FinalStep was returned from FlowController.
          // We're done with the CAS.
          assert (nextStep instanceof FinalStep);
          FinalStep finalStep = (FinalStep) nextStep;
          activeCASes.remove(cas);
          // If this is the input CAS, just return null to indicate we're done
          // processing it. It is an error if the FlowController tried to drop this CAS.
          if (cas == mInputCas) {
            if (finalStep.getForceCasToBeDropped()) {
              throw new AnalysisEngineProcessException(
                      AnalysisEngineProcessException.ILLEGAL_DROP_CAS, new Object[0]);
            }
            return null;
          }
          // Otherwise, this is a new CAS produced within this Aggregate. We may or
          // may not return it, depending on the setting of the outputsNewCASes operational
          // property in this AE's metadata, and on the value of FinalStep.forceCasToBeDropped
          if (mOutputNewCASes && !finalStep.getForceCasToBeDropped()) {
            return cas;
          } else {
            cas.release();
          }
        }
      } catch (Exception e) {
        //notify Flow that processing has aborted on this CAS
        if (flow != null) {
          flow.aborted();
        }
        release(); // release held CASes before throwing exception
        if (e instanceof AnalysisEngineProcessException) {
          throw (AnalysisEngineProcessException) e;
        } else {
          throw new AnalysisEngineProcessException(e);
        }
      }
    }
View Full Code Here

TOP

Related Classes of org.apache.uima.analysis_engine.AnalysisEngineProcessException

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.