Package org.apache.uima.analysis_engine

Examples of org.apache.uima.analysis_engine.AnalysisEngine


//    new XMLSerializer(); xmlSerializer.setWriter(writer);
//    desc.toXML(xmlSerializer.getContentHandler(), true); writer.close();
   

    // Create analysis engine from aggregate ae description
    AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(desc, null, null);
    Assert.assertNotNull(ae);

    // Create a CAS with a sample document text and process the CAS
    CAS cas = ae.newCAS();
    cas.setDocumentText("Sample text to process with a date 05/29/07 and a time 9:45 AM and a Room number GN-K35 or two GN-K37");
    cas.setDocumentLanguage("en");
    ae.process(cas);
   
    return cas;
  }
View Full Code Here


   *
   * @throws Exception
   */
  public static AnalysisEngine doConfigurationTest(String configDescFilePath) throws Exception {
    try {
      AnalysisEngine ae = null;
      // Create an XML input source from the specifier file.
      XMLInputSource in = new XMLInputSource(configDescFilePath);
      // Parse the specifier.
      ResourceSpecifier specifier = UIMAFramework.getXMLParser().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) {
      JUnitExtension.handleException(ex);
    }
View Full Code Here

   * @throws Exception
   */
  public static CAS performTest(String descFilePath, String text, String language)
          throws Exception {
    try {
      AnalysisEngine ae = null;
      // Create an XML input source from the specifier file.
      XMLInputSource in = new XMLInputSource(descFilePath);
      // Parse the specifier.
      ResourceSpecifier specifier = UIMAFramework.getXMLParser().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(text);
      cas.setDocumentLanguage(language);
      // Process the sample document.
      ae.process(cas);

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

    // get Resource Specifier from XML file
    XMLInputSource in = new XMLInputSource(descriptor);
    ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);
   
    // create Analysis Engine
    AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
   
    // create a CAS
    CAS cas = ae.newCAS();
   
    // Create a file filter depending on the format
    // to filter out all file which do not have the
    // expected file ending
    FileFilter fileFilter;
    if (InputFormat.CAS.equals(inputFormat)) {
      fileFilter = new FileFilter() {
       
        public boolean accept(File file) {
          return file.getName().endsWith(".xmi") || file.getName().endsWith(".xcas") ||
                  (inputRecursive && file.isDirectory());
        }
      };
    }
    else if (InputFormat.PLAIN_TEXT.equals(inputFormat)) {
      fileFilter = new FileFilter() {
       
        public boolean accept(File file) {
          return file.getName().endsWith(".txt") || (inputRecursive && file.isDirectory());
        }
      };
    }
    else {
      throw new IllegalStateException("Unexpected input format!");
    }
   
    findAndProcessFiles(inputResource, fileFilter, ae, cas);
   
    ae.collectionProcessComplete(new ProcessTrace_impl());
    ae.destroy();
  }
View Full Code Here

    assertTrue("Descriptor must exist: " + descriptorFile.getAbsolutePath(), descriptorFile.exists());
   
    try {
      XMLParser parser = UIMAFramework.getXMLParser();
      ResourceSpecifier spec = (ResourceSpecifier) parser.parse(new XMLInputSource(descriptorFile));
      AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(spec);
      this.cas = (CASImpl) ae.newCAS();
      assertTrue(this.cas != null);
      this.ts = this.cas.getTypeSystem();
      assertTrue(this.ts != null);
    } catch (IOException e) {
      e.printStackTrace();
View Full Code Here

  }

  @Test
  public void testEmptyMapInitialization() throws Exception {
    AEProvider aeProvider = new OverridingParamsAEProvider("/uima/TestEntityAnnotatorAE.xml", new HashMap<String, Object>());
    AnalysisEngine analysisEngine = aeProvider.getAE();
    assertNotNull(analysisEngine);
  }
View Full Code Here

  @Test
  public void testOverridingParamsInitialization() throws Exception {
    Map<String, Object> runtimeParameters = new HashMap<String, Object>();
    runtimeParameters.put("ngramsize", "3");
    AEProvider aeProvider = new OverridingParamsAEProvider("/uima/AggregateSentenceAE.xml", runtimeParameters);
    AnalysisEngine analysisEngine = aeProvider.getAE();
    assertNotNull(analysisEngine);
    Object parameterValue = analysisEngine.getConfigParameterValue("ngramsize");
    assertNotNull(parameterValue);
    assertEquals(Integer.valueOf(3), Integer.valueOf(parameterValue.toString()));
  }
View Full Code Here

    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);
View Full Code Here

      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

   * test reconfiguration of an existing AE
   */
  @Test
  public void reconfigureTest() {
    try {
      AnalysisEngine ae = TestUtils.getAE("desc/TextCategorizationAEDescriptor.xml");
      ae.reconfigure();
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getLocalizedMessage());
    }
  }
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.