コード例 #1
0
ファイル: RunAE.java プロジェクト: lovebube/myUIMA
    /**
     * Called when the collection processing is completed.
     *
     * @see org.apache.uima.collection.processing.StatusCallbackListener#collectionProcessComplete()
     */
    public void collectionProcessComplete(EntityProcessStatus aStatus) {
      if (aStatus != null && aStatus.isException()) {
        System.err.println("Error on collection process complete call to remote service:");
        List exceptions = aStatus.getExceptions();
        for (int i = 0; i < exceptions.size(); i++) {
          ((Throwable) exceptions.get(i)).printStackTrace();
        }
        System.err.println("Terminating Client...");
        stop();
      }
      System.out.print("Completed " + entityCount + " documents");
      if (size > 0) {
        System.out.print("; " + size + " characters");
      }
      System.out.println();
      long elapsedTime = System.nanoTime() / 1000000 - mStartTime;
      System.out.println("Time Elapsed : " + elapsedTime + " ms ");

      String perfReport = uimaEEEngine.getPerformanceReport();
      if (perfReport != null) {
        System.out.println("\n\n ------------------ PERFORMANCE REPORT ------------------\n");
        System.out.println(uimaEEEngine.getPerformanceReport());
      }
      // stop the JVM. Dont stop here if running with -d (deploy) option.
      // service must be first be undeployed before stop() is called. Otherwise,
      // this process hangs
      //  if ( springContainerId == null ) {
      //  stop();
      // }
    }
コード例 #2
0
ファイル: RunAE.java プロジェクト: lovebube/myUIMA
 /**
  * Called when the initialization is completed.
  *
  * @see org.apache.uima.collection.processing.StatusCallbackListener#initializationComplete()
  */
 public void initializationComplete(EntityProcessStatus aStatus) {
   if (aStatus != null && aStatus.isException()) {
     System.err.println("Error on getMeta call to remote service:");
     List exceptions = aStatus.getExceptions();
     for (int i = 0; i < exceptions.size(); i++) {
       ((Throwable) exceptions.get(i)).printStackTrace();
     }
     System.err.println("Terminating Client...");
     stop();
   }
   System.out.println("UIMA AS Service Initialization Complete");
 }
コード例 #3
0
 /**
  * Called when the processing of a Document is completed. <br>
  * The process status can be looked at and corresponding actions taken.
  *
  * @param aCas CAS corresponding to the completed processing
  * @param aStatus EntityProcessStatus that holds the status of all the events for aEntity
  */
 public void entityProcessComplete(CAS aCas, EntityProcessStatus aStatus) {
   if (aStatus.isException()) {
     List<Exception> exceptions = aStatus.getExceptions();
     for (int i = 0; i < exceptions.size(); i++) {
       ((Throwable) exceptions.get(i)).printStackTrace();
     }
     return;
   }
   entityCount++;
   String docText = aCas.getDocumentText();
   if (docText != null) {
     size += docText.length();
   }
 }
コード例 #4
0
  @Override
  public void entityProcessComplete(CAS cas, EntityProcessStatus status) {
    if (status.isException()) {
      if (status.getExceptions() != null && !status.getExceptions().isEmpty()) {
        for (Exception e : status.getExceptions()) {
          LOGGER.warn("Job ran with errors", e);
        }
      } else {
        LOGGER.warn("Job ran with errors, but no detailed exception");
      }
    }

    MetricsFactory.getInstance().getPipelineMetrics(getName()).finishDocumentProcess();
  }
コード例 #5
0
	public void entityProcessComplete(CAS aCas, EntityProcessStatus aStatus) {
		if (aStatus != null) {
			if (aStatus.isException()) {
				System.err.println("Error on process CAS call to remote service:");
				List<Exception> exceptions = aStatus.getExceptions();
				for (int i = 0; i < exceptions.size(); i++) {
					((Throwable) exceptions.get(i)).printStackTrace();
				}
			}
			
			try {
				JCas cas = aCas.getJCas();

				for(Token token : JCasUtil.select(cas, Token.class)) {
					System.out.println(token.getCoveredText() + " " + token.getPos().getPosValue());
				}

			} catch (CASException e) {
				e.printStackTrace();
			}
		}
	}
コード例 #6
0
  /**
   * Called when the processing of a Document is completed. <br>
   * The process status can be looked at and corresponding actions taken.
   *
   * @param aCas CAS corresponding to the completed processing
   * @param aStatus EntityProcessStatus that holds the status of all the events for aEntity
   */
  public void entityProcessComplete(CAS aCas, EntityProcessStatus aStatus) {

    // if there is an error above the individual document level,
    // an entityProcessStatus is created with a null value for entity
    if (aCas == null) {
      for (int i = 0; i < aStatus.getFailedComponentNames().size(); i++) {
        LOG.info("[{}] FailedComponentNames", aStatus.getFailedComponentNames().get(i));
      }
      for (int i = 0; i < aStatus.getExceptions().size(); i++) {
        LOG.info("[{}] Exceptions", aStatus.getExceptions().get(i));
      }
      return;
    }
    try {
      entityCount++;
      // FIXME int dataSize = 0;
      // // get size here
      // Type t = aCas.getTypeSystem().getType("uima.cpm.FileLocation");
      // Feature f = t.getFeatureByBaseName("DocumentSize");
      // FSIterator fsI = aCas.getAnnotationIndex(t).iterator();
      // if (fsI.isValid()) {
      // dataSize = fsI.get().getIntValue(f);
      // }
      //
      // size += dataSize;
      // to handle exceptions occured in any of the components for the
      // entity
      if (aStatus.isException()) {
        for (int q = 0; q < aStatus.getExceptions().size(); q++) {
          Exception e = (Exception) aStatus.getExceptions().get(q);
          e.printStackTrace();
        }
      }
    } catch (Exception io) {
      UIMAFramework.getLogger(this.getClass()).log(Level.WARNING, "", io);
    }
  }
コード例 #7
0
ファイル: RunAE.java プロジェクト: lovebube/myUIMA
    /**
     * Called when the processing of a Document is completed. <br>
     * The process status can be looked at and corresponding actions taken.
     *
     * @param aCas CAS corresponding to the completed processing
     * @param aStatus EntityProcessStatus that holds the status of all the events for aEntity
     */
    public void entityProcessComplete(CAS aCas, EntityProcessStatus aStatus) {
      if (aStatus != null) {
        if (aStatus.isException()) {
          System.err.println("Error on process CAS call to remote service:");
          List exceptions = aStatus.getExceptions();
          for (int i = 0; i < exceptions.size(); i++) {
            ((Throwable) exceptions.get(i)).printStackTrace();
          }
          if (!ignoreErrors) {
            System.err.println("Terminating Client...");
            stop();
          }
        }
        if (logCas) {
          String ip = "no IP";
          List eList = aStatus.getProcessTrace().getEventsByComponentName("UimaEE", false);
          for (int e = 0; e < eList.size(); e++) {
            ProcessTraceEvent event = (ProcessTraceEvent) eList.get(e);
            if (event.getDescription().equals("Service IP")) {
              ip = event.getResultMessage();
            }
          }
          String casId = ((UimaASProcessStatus) aStatus).getCasReferenceId();
          if (casId != null) {
            long current = System.nanoTime() / 1000000 - mStartTime;
            if (casMap.containsKey(casId)) {
              Object value = casMap.get(casId);
              if (value != null && value instanceof Long) {
                long start = ((Long) value).longValue();
                System.out.println(ip + "\t" + start + "\t" + (current - start));
              }
            }
          }

        } else {
          System.out.print(".");
          if (0 == (entityCount + 1) % 50) {
            System.out.print((entityCount + 1) + " processed\n");
          }
        }
      }

      // if output dir specified, dump CAS to XMI
      if (outputDir != null) {
        // try to retrieve the filename of the input file from the CAS
        File outFile = null;
        Type srcDocInfoType =
            aCas.getTypeSystem().getType("org.apache.uima.examples.SourceDocumentInformation");
        if (srcDocInfoType != null) {
          FSIterator it = aCas.getIndexRepository().getAllIndexedFS(srcDocInfoType);
          if (it.hasNext()) {
            FeatureStructure srcDocInfoFs = it.get();
            Feature uriFeat = srcDocInfoType.getFeatureByBaseName("uri");
            Feature offsetInSourceFeat = srcDocInfoType.getFeatureByBaseName("offsetInSource");
            String uri = srcDocInfoFs.getStringValue(uriFeat);
            int offsetInSource = srcDocInfoFs.getIntValue(offsetInSourceFeat);
            File inFile;
            try {
              inFile = new File(new URL(uri).getPath());
              String outFileName = inFile.getName();
              if (offsetInSource > 0) {
                outFileName += ("_" + offsetInSource);
              }
              outFileName += ".xmi";
              outFile = new File((String) outputDir, outFileName);
            } catch (MalformedURLException e1) {
              // invalid URI, use default processing below
            }
          }
        }
        if (outFile == null) {
          outFile = new File((String) outputDir, "doc" + entityCount);
        }
        try {
          FileOutputStream outStream = new FileOutputStream(outFile);
          try {
            XmiCasSerializer.serialize(aCas, outStream);
          } finally {
            outStream.close();
          }
        } catch (Exception e) {
          System.err.println("Could not save CAS to XMI file");
          e.printStackTrace();
        }
      }

      // update stats
      entityCount++;
      String docText = aCas.getDocumentText();
      if (docText != null) {
        size += docText.length();
      }

      // Called just before sendCas with next CAS from collection reader
    }