Package org.apache.uima.analysis_engine

Examples of org.apache.uima.analysis_engine.AnalysisEngine


      url = HtmlConverter.class.getClassLoader().getResource(
              "org/apache/uima/ruta/engine/HtmlConverter.xml");
    }
    XMLInputSource in = new XMLInputSource(url);
    ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);
    AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
    CAS cas = ae.newCAS();

    ae.setConfigParameterValue(HtmlConverter.OUTPUT_VIEW, outputViewName);
    ae.reconfigure();
    cas.reset();
    cas.setDocumentText(htmlWithComments);

    // go:
    ae.process(cas);

    CAS modifiedView = cas.getView(outputViewName);
    String text = modifiedView.getDocumentText();

    String expectedText = "start of body\nnormal bold\nend of body";
View Full Code Here


      url = HtmlConverter.class.getClassLoader().getResource(
              "org/apache/uima/ruta/engine/HtmlConverter.xml");
    }
    XMLInputSource in = new XMLInputSource(url);
    ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);
    AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
    CAS cas = ae.newCAS();

    ae.setConfigParameterValue(HtmlConverter.OUTPUT_VIEW, outputViewName);
    ae.setConfigParameterValue(HtmlConverter.NEWLINE_INDUCING_TAGS, new String[] { "br" });
    ae.reconfigure();
    cas.reset();
    cas.setDocumentText(htmlWin);

    // go:
    ae.process(cas);

    CAS modifiedView = cas.getView(outputViewName);
    String text = modifiedView.getDocumentText();

    String expectedText = "start of body\nnormal bold\nend of body";
View Full Code Here

      url = HtmlConverter.class.getClassLoader().getResource(
              "org/apache/uima/ruta/engine/HtmlConverter.xml");
    }
    XMLInputSource in = new XMLInputSource(url);
    ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);
    AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
    CAS cas = ae.newCAS();

    ae.setConfigParameterValue(HtmlConverter.OUTPUT_VIEW, outputViewName);
    ae.reconfigure();
    cas.reset();
    cas.setDocumentText(htmlWithCommentsAndScript);

    // go:
    ae.process(cas);

    CAS modifiedView = cas.getView(outputViewName);
    String text = modifiedView.getDocumentText();

    String expectedText = "start of body\nnormal bold\nend of body";
View Full Code Here

              "uima.tcas.Annotation");
      basicTypeSystem.addType(HtmlAnnotator.NAMESPACE + "U", "Type for Testing",
              "uima.tcas.Annotation");
      specifier.getAnalysisEngineMetaData().setTypeSystem(basicTypeSystem);

      AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
      ae.setConfigParameterValue("outputView", outputViewName);
      ae.reconfigure();

      // create the cas and input annotation
      CAS cas = ae.newCAS();
      cas.reset();
      cas.setDocumentText(htmlContent);
      Type boldType = cas.getTypeSystem().getType(HtmlAnnotator.NAMESPACE + "B");
      AnnotationFS fs = cas.createAnnotation(boldType, 78, 89);
      cas.addFsToIndexes(fs);

      // go:
      ae.process(cas);

      // test:
      CAS modifiedView = cas.getView(outputViewName);
      AnnotationIndex<AnnotationFS> ai = modifiedView.getAnnotationIndex(boldType);
      FSIterator<AnnotationFS> iterator = ai.iterator();
View Full Code Here

            "uima.tcas.Annotation");
    basicTypeSystem.addType(HtmlAnnotator.NAMESPACE + "U", "Type for Testing",
            "uima.tcas.Annotation");
    specifier.getAnalysisEngineMetaData().setTypeSystem(basicTypeSystem);
   
    AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
    ae.setConfigParameterValue("outputView", outputViewName);
    ae.reconfigure();

    // create the cas and input annotation
    CAS cas = ae.newCAS();
    cas.reset();
    cas.setDocumentText(htmlDecodingAnnotations);
    Type boldType = cas.getTypeSystem().getType(HtmlAnnotator.NAMESPACE + "B");
    AnnotationFS fs1 = cas.createAnnotation(boldType, 210, 221);
    AnnotationFS fs2 = cas.createAnnotation(boldType, 279, 290);
    cas.addFsToIndexes(fs1);
    cas.addFsToIndexes(fs2);

    // go:
    ae.process(cas);

    // test: should be:
    //
    // start of body\nnormal normal bold\nend of body 3€ äöü and bold.
    // 01234567890123 4567890123456789012 34567890123456789012345678901234567890
View Full Code Here

      url = HtmlConverter.class.getClassLoader().getResource(
              "org/apache/uima/ruta/engine/HtmlConverter.xml");
    }
    XMLInputSource in = new XMLInputSource(url);
    ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);
    AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
    CAS cas = ae.newCAS();

    String inputViewName = "inview";

    ae.setConfigParameterValue(HtmlConverter.INPUT_VIEW, inputViewName);
    ae.setConfigParameterValue(HtmlConverter.OUTPUT_VIEW, outputViewName);
    ae.reconfigure();
    cas.reset();
    CAS inview = cas.createView(inputViewName);
    inview.setDocumentText(htmlUnix);

    // go:
    ae.process(cas);

    CAS modifiedView = cas.getView(outputViewName);
    String text = modifiedView.getDocumentText();

    String expectedText = "start of body\nnormal bold\nend of body";
View Full Code Here

  @Test
  public void test() throws ResourceInitializationException, IOException, InvalidXMLException,
          AnalysisEngineProcessException, ResourceConfigurationException {
    final String name = getClass().getSimpleName();
    final String namespace = getClass().getPackage().getName();
    final AnalysisEngine ae = createAE(namespace + "." + name);
    List<ResourceMetaData> metaData = new ArrayList<ResourceMetaData>();
    metaData.add(ae.getMetaData());
    String input = "This is a test.";
    Type t1 = null;
   
   
    // create a cas and apply rules
    final CAS cas = CasCreationUtils.createCas(metaData);
    cas.setDocumentText(input);
    SimplePipeline.runPipeline(cas, ae);

    t1 = cas.getTypeSystem().getType(TEST_TYPE);
    assertEquals(1, cas.getAnnotationIndex(t1).size());

    // reset the cas and do it again
    cas.reset();
    cas.setDocumentText(input);
    SimplePipeline.runPipeline(cas, ae);

    t1 = cas.getTypeSystem().getType(TEST_TYPE);
    assertEquals(1, cas.getAnnotationIndex(t1).size());
   
    // create a new cas and force the ae to update its types
    ae.setConfigParameterValue(RutaEngine.PARAM_RELOAD_SCRIPT, true);
    ae.reconfigure();
   
    final CAS cas2 = CasCreationUtils.createCas(metaData);
    cas2.setDocumentText(input);
    SimplePipeline.runPipeline(cas2, ae);

    t1 = cas2.getTypeSystem().getType(TEST_TYPE);
    assertEquals(1, cas2.getAnnotationIndex(t1).size());
   
    // create a new cas and do not force the ae to update its types
    ae.setConfigParameterValue(RutaEngine.PARAM_RELOAD_SCRIPT, false);
    ae.reconfigure();
    final CAS cas3 = CasCreationUtils.createCas(metaData);
    cas3.setDocumentText(input);
    SimplePipeline.runPipeline(cas3, ae);

    t1 = cas3.getTypeSystem().getType(TEST_TYPE);
    assertEquals(1, cas3.getAnnotationIndex(t1).size());
   
    // create a new cas and do not reconfigure the engine
    final CAS cas4 = CasCreationUtils.createCas(metaData);
    cas4.setDocumentText(input);
    SimplePipeline.runPipeline(cas4, ae);

    t1 = cas4.getTypeSystem().getType(TEST_TYPE);
    assertEquals(1, cas4.getAnnotationIndex(t1).size());
   
    if (ae != null) {
      ae.destroy();
    }
    if (cas != null) {
      cas.release();
    }
    if (cas2 != null) {
View Full Code Here

  @Test
  public void test() throws ResourceInitializationException, IOException, InvalidXMLException, AnalysisEngineProcessException {
    final String name = getClass().getSimpleName();
    final String namespace = getClass().getPackage().getName();
    final AnalysisEngine ae = createAE(namespace + "." + name);
    final CAS cas = ae.newCAS();

    cas.setDocumentText("text is not relevant here");

    try {
      ae.process(cas);
      fail("An IllegalArgumentException should be triggered because W is ambiguous.");
    } catch (AnalysisEngineProcessException e) {
      // we are expecting an IllegalArgumentException because both org.apache.uima.ruta.type.W and
      // org.apache.uima.ruta.type.conflicting.W are imported into RUTA's namespace as W;
      assertTrue(e.getCause() instanceof IllegalArgumentException);
    } finally {
        cas.release();
        ae.destroy();
    }
  }
View Full Code Here

    return AnalysisEngineFactory.createEngine(ruta);
  }

  @Test
  public void testImportType() throws Exception {
    AnalysisEngine ae = createAE(NAMESPACE + "/" + NAME + "ImportType", true);
    try {
      CAS cas = ae.newCAS();
      cas.setDocumentText("Word");
      ae.process(cas);

      assertEquals(Arrays.asList("Word"), selectText(cas, "org.apache.uima.ruta.Type1"));
    } finally {
      ae.destroy();
    }
  }
View Full Code Here

    }
  }

  @Test
  public void testImportTypeFromDefaultTypesystem() throws Exception {
    AnalysisEngine ae = createAE(NAMESPACE + "/" + NAME + "ImportTypeFromDefaultTypeSystem", true);
    try {
      CAS cas = ae.newCAS();
      cas.setDocumentText("Word");
      ae.process(cas);

      assertEquals(Arrays.asList("Word"), selectText(cas, "org.apache.uima.ruta.Type1"));
    } finally {
      ae.destroy();
    }
  }
View Full Code Here

TOP

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

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.