Package org.apache.uima.cas

Examples of org.apache.uima.cas.CAS


      try {
        // create CAS:
        XMLInputSource in = new XMLInputSource(tsDescriptorPath.toPortableString());
        TypeSystemDescription tsd = UIMAFramework.getXMLParser().parseTypeSystemDescription(in);

        CAS cleanCas = getEmptyCas(tsd);

        for (TestCasData td : testCasData) {
          // init etc
          cleanCas.reset(); // clean
          // deserialize CASes
          FileInputStream inputStreamRun = null;
          try {
            inputStreamRun = new FileInputStream(new File(td.getPath().toPortableString()));
            XmiCasDeserializer.deserialize(inputStreamRun, cleanCas, true);
          } finally {
            if (inputStreamRun != null) {
              inputStreamRun.close();
            }
          }
          cleanCas = cleanCas.getView(viewCasName);
          prepareCas(cleanCas);
          // store clean CAS
          IPath path2CleanFile = computeCleanPath(cleanInputPath, td);
          String fPath = path2CleanFile.toPortableString();
          File cleanFile = new File(fPath);
          writeXmi(cleanCas, cleanFile);

          td.setResultPath(path2CleanFile);

          if (monitor.isCanceled()) {
            return;
          }
        }

        cleanCas.release();
        project.getFolder(cleanInputPath.makeRelativeTo(project.getLocation())).refreshLocal(
                IResource.DEPTH_INFINITE, new NullProgressMonitor());
      } catch (Exception e) {
        RutaAddonsPlugin.error(e);
      }
View Full Code Here


        // create (empty) CAS objects:
        String desc = null;
        desc = engineDescriptorPath.toPortableString();
        XMLInputSource in2 = new XMLInputSource(desc);
        Object descriptor = UIMAFramework.getXMLParser().parse(in2);
        CAS runCas = getEmptyCas(descriptor);
        CAS testCas = getEmptyCas(descriptor);

        for (TestCasData td : testCasData) {
          // init td etc
          runCas.reset();
          testCas.reset();
          String elementName = fScript.getLocation().lastSegment();
          monitor.setTaskName("Processing [w/o classpatch ext.] " + td.getPath().lastSegment());
          int lastIndexOf = elementName.lastIndexOf(RutaEngine.SCRIPT_FILE_EXTENSION);
          if (lastIndexOf != -1) {
            elementName = elementName.substring(0, lastIndexOf);
          }
          // deserialize CASes
          FileInputStream inputStreamTest = null;
          try {
            inputStreamTest = new FileInputStream(new File(td.getPath().toPortableString()));
            XmiCasDeserializer.deserialize(inputStreamTest, testCas, true);
          } finally {
            if (inputStreamTest != null) {
              inputStreamTest.close();
            }
          }
          FileInputStream inputStreamRun = null;
          try {
            inputStreamRun = new FileInputStream(new File(td.getPath().toPortableString()));
            XmiCasDeserializer.deserialize(inputStreamRun, runCas, true);
          } finally {
            if (inputStreamRun != null) {
              inputStreamRun.close();
            }
          }
          testCas = testCas.getView(viewCasName);
          runCas = runCas.getView(viewCasName);

          // gather uima eval-types
          prepareCas(runCas);
View Full Code Here

      ICasEvaluator evaluator = RutaAddonsPlugin.getCasEvaluatorFactoryById(factoryName)
              .createEvaluator();
      boolean includeSubtypes = store.getBoolean(TestingPreferenceConstants.INCLUDE_SUBTYPES);
      boolean useAllTypes = store.getBoolean(TestingPreferenceConstants.ALL_TYPES);

      CAS resultCas = evaluator.evaluate(goldCas, runCas, excludedTypes, includeSubtypes,
              useAllTypes);

      // store results
      IPath path2Test = td.getPath().removeLastSegments(1);

      monitor.setTaskName("Actually evaluating " + td.getPath().lastSegment());

      IPath estimatedTestPath = project.getFullPath().append(
              RutaProjectUtils.getDefaultTestLocation());
      IPath path2recource = fScript.getFullPath();
      IPath projectRelativePath2Script = path2recource.removeFirstSegments(2);
      IPath estimatedTestFolderPath = estimatedTestPath.append(projectRelativePath2Script
              .removeFileExtension());

      IPath path2Result = path2Test.append(TestCasData.RESULT_FOLDER);
      IPath path2ResultFile = path2Result.append(td.getPath().removeFileExtension().lastSegment()
              + ".result.xmi");

      if (!path2Test.toOSString().contains(estimatedTestFolderPath.toOSString())) {
        path2Result = project.getLocation().append(RutaProjectUtils.getDefaultTestLocation())
                .append(RutaProjectUtils.getDefaultTempTestLocation());
        path2ResultFile = path2Result.append(td.getPath().removeFileExtension().lastSegment()
                + ".result.xmi");
      }

      File resultFile = new File(path2ResultFile.toPortableString());
      writeXmi(resultCas, resultFile);

      td.setResultPath(path2ResultFile);

      // finally, calculate eval data and show it in the GUI
      EvalDataProcessor.calculateEvaluatData(td, resultCas);

      testPageView.getDefaultPage().getControl().getDisplay().asyncExec(new Runnable() {
        public void run() {
          debugPage.getViewer().refresh();
        }
      });
      monitor.worked(1);
      project.getFolder(path2Result.makeRelativeTo(project.getLocation())).refreshLocal(
              IResource.DEPTH_INFINITE, new NullProgressMonitor());
      runCas.release();
      goldCas.release();
      resultCas.release();
    }
View Full Code Here

      resultCas.release();
    }

    private CAS getEmptyCas(Object descriptor) throws ResourceInitializationException,
            InvalidXMLException {
      CAS testCas = null;
      if (descriptor instanceof AnalysisEngineDescription) {
        testCas = CasCreationUtils.createCas((AnalysisEngineDescription) descriptor);
      } else if (descriptor instanceof TypeSystemDescription) {
        TypeSystemDescription tsDesc = (TypeSystemDescription) descriptor;
        tsDesc.resolveImports();
View Full Code Here

  }

  @Override
  public void execute(RuleMatch match, RuleElement element, RutaStream stream, InferenceCrowd crowd) {
    List<List<RuleElementMatch>> list = match.getMatchInfo(element);
    CAS cas = stream.getCas();
    Type t = type.getType(element.getParent());
    for (List<RuleElementMatch> eachList : list) {
      for (RuleElementMatch each : eachList) {
        List<AnnotationFS> matched = each.getTextsMatched();
        for (AnnotationFS annotationFS : matched) {
          FeatureStructure createFS = cas.createFS(t);
          copyFeatures(annotationFS, createFS, cas);
          if (createFS instanceof AnnotationFS) {
            stream.addAnnotation((AnnotationFS) createFS, match);
          }
          cas.addFsToIndexes(createFS);
        }
      }
    }

  }
View Full Code Here

        if (resource != null && resource instanceof IFile
                && resource.getLocation().getFileExtension().equals("xmi")) {
          TestCasData data = new TestCasData(resource.getLocation());
          if (Boolean.valueOf(store.getString(TestingPreferenceConstants.LOAD_OLD_TEST_RESULTS))) {
            data.loadPreviousResults(script);
            CAS resultCas = CASLoader.loadCas(script, data.getResultPath());
            EvalDataProcessor.calculateEvaluatData(data, resultCas);
          }
          viewerInput.add(data);
        }
      }
View Full Code Here

      } catch (InvalidXMLException e) {
        RutaAddonsPlugin.error(e);
      } catch (IOException e) {
        RutaAddonsPlugin.error(e);
      }
      CAS cas = null;
      try {
        cas = CasCreationUtils.createCas(tsd, null, new FsIndexDescription[0]);
      } catch (ResourceInitializationException e) {
        RutaAddonsPlugin.error(e);
      }

      if (tsd == null || cas == null) {
        return Status.CANCEL_STATUS;
      }
      TreePath treePath = null;
      final IAnnotationCheckTreeNode root = new AnnotationCheckRootNode();
      for (File file : listFiles) {
        cas.reset();
        try {
          XmiCasDeserializer.deserialize(new FileInputStream(file), cas, true);
        } catch (FileNotFoundException e) {
          RutaAddonsPlugin.error(e);
        } catch (SAXException e) {
          RutaAddonsPlugin.error(e);
        } catch (IOException e) {
          RutaAddonsPlugin.error(e);
        }
        CheckDocument element = getCheckDocument(docs, file.getAbsolutePath());
        boolean documentAlreadyDone = documentAlreadyDoneforTypes(element, selectedTypes);
        if (!documentAlreadyDone) {
          AnnotationCheckTreeNode node = new AnnotationCheckTreeNode(root, element);
          root.addChild(node);
          AnnotationIndex<AnnotationFS> annotationIndex = cas.getAnnotationIndex();
          for (AnnotationFS each : annotationIndex) {
            boolean annotationAlreadyDoneforTypes = annotationAlreadyDoneforTypes(each,
                    selectedTypes, element.checkedTypes);
            if (!annotationAlreadyDoneforTypes) {
              CheckElement ac = new CheckAnnotation(each);
              AnnotationCheckTreeNode anode = new AnnotationCheckTreeNode(node, ac);
              if (treePath == null) {
                treePath = new TreePath(new Object[] { root, node, anode });
              }
              node.addChild(anode);
            }
          }
          if (treePath == null) {
            treePath = new TreePath(new Object[] { root, node });
          }
        }
      }
      if(previousSelection != null) {
        CheckElement element = previousSelection.getElement();
        TreePath oldPath = getPathTo(element, root);
        if(oldPath != null) {
          treePath = oldPath;
        }
      }
      final TreeSelection firstSelection = new TreeSelection(treePath);
     
      cas.release();
      composite.setOldDocs(docs);
      composite.getDisplay().asyncExec(new Runnable() {
        public void run() {
          TreeViewer treeView = composite.getTreeViewer();
          treeView.setInput(root);
View Full Code Here

   * We do this without changing the typeSystemDescription
   *
   * @return
   */
  private boolean validateIndexes() {
    CAS localCAS = descriptorCAS.get();
    TypePriorities savedMergedTypePriorities = getMergedTypePriorities();
    FsIndexCollection savedFsIndexCollection = getMergedFsIndexCollection();
    try {
      setMergedFsIndexCollection();
      setMergedTypePriorities();
View Full Code Here

               .parseResourceSpecifier(in);
         // Create the Text Analysis Engine.
         ae = UIMAFramework.produceAnalysisEngine(specifier, null, null);

         // Create a new CAS.
         CAS cas = ae.newCAS();
         // Set the document text on the CAS.
         cas
               .setDocumentText("This is a simple text to check if the configuration works");
         cas.setDocumentLanguage("en");
         // Process the sample document.
         ae.process(cas);

         return ae;
      } catch (Exception ex) {
View Full Code Here

    * @throws Exception
    */
   public CAS performTest(String text, String language) throws Exception {
      try {
         // Create a new CAS.
         CAS cas = this.ae.newCAS();
         // Set the document text on the CAS.
         cas.setDocumentText(text);
         cas.setDocumentLanguage(language);
         // Process the sample document.
         this.ae.process(cas);

         return cas;
      } catch (Exception ex) {
View Full Code Here

TOP

Related Classes of org.apache.uima.cas.CAS

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.