Package org.apache.uima.util

Examples of org.apache.uima.util.XMLParser


  }
  private void manyDelegatesCommon() throws Exception {
    // Test that an aggregate can be copied preserving all comments and ordering of delegates
    XMLParser.ParsingOptions parsingOptions = new XMLParser.ParsingOptions(false);
    parsingOptions.preserveComments = true;
    XMLParser parser = UIMAFramework.getXMLParser();
    File inFile = JUnitExtension.getFile("TextAnalysisEngineImplTest/AggregateWithManyDelegates.xml");
    AnalysisEngineDescription desc = parser.parseAnalysisEngineDescription(new XMLInputSource(inFile), parsingOptions);

    // Write out descriptor
    File cloneFile = new File(inFile.getParentFile(), "CopyOfAggregateWithManyDelegates.xml");
    BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(cloneFile));
    XMLSerializer xmlSerializer = new XMLSerializer(true);
    xmlSerializer.setOutputStream(os);
    // set the amount to a value which will show up if used
    // indent should not be used because we're using a parser mode which preserves
    // comments and ignorable white space.
    xmlSerializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
    ContentHandler contentHandler = xmlSerializer.getContentHandler();
    contentHandler.startDocument();
    desc.toXML(contentHandler, true);
    contentHandler.endDocument();
    os.close();
   
    // When building from a source distribution the descriptor may not have
    // appropriate line-ends so compute the length as if always 1 byte.
    int diff = fileLength(cloneFile) - fileLength(inFile);
    // One platform inserts a blank line and a final newline, so don't insist on perfection
    assertTrue("File size changed by "+diff+" should be no more than 2", diff >= -2 && diff <= 2);

    // Initialize all delegates and check the initialization order (should be declaration order)
    TestAnnotator2.allContexts = "";
    UIMAFramework.produceAnalysisEngine(desc);
    assertEquals("D/C/B/A/F/E/", TestAnnotator2.allContexts);
   
    // Check that copying aggregate preserved the order of the delegates
    desc = parser.parseAnalysisEngineDescription(new XMLInputSource(cloneFile), parsingOptions);
    TestAnnotator2.allContexts = "";
    UIMAFramework.produceAnalysisEngine(desc);
    assertEquals("D/C/B/A/F/E/", TestAnnotator2.allContexts);
    cloneFile.delete();
  }
View Full Code Here


 
  public static XMLizable parseDescriptor(XMLInputSource input, boolean preserveComments) throws InvalidXMLException {
    // turn off environment variable expansion
    XMLParser.ParsingOptions parsingOptions = new XMLParser.ParsingOptions(false);
    parsingOptions.preserveComments = preserveComments;
    XMLParser parser = UIMAFramework.getXMLParser();
    // disabled - error messages from XML validation not very helpful
    // parser.enableSchemaValidation(true);
    return parser.parse(input, "http://uima.apache.org/resourceSpecifier",
            urlForResourceSpecifierSchema, parsingOptions);
  }
View Full Code Here

    File descriptorFile = JUnitExtension.getFile("CASTests/desc/casTestCaseDescriptor.xml");
    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);
View Full Code Here

    }

    XMLInputSource xmlTypeSystemSource = new XMLInputSource(inTypeSystem, extensionTypeSystemFile
            .getLocation().toFile());

    XMLParser xmlParser = UIMAFramework.getXMLParser();

    TypeSystemDescription typeSystemDesciptor;

    try {
      typeSystemDesciptor = (TypeSystemDescription) xmlParser.parse(xmlTypeSystemSource);

      typeSystemDesciptor.resolveImports();
    } catch (InvalidXMLException e) {

      String message = e.getMessage() != null ? e.getMessage() : "";
View Full Code Here

    String xmlDescUri = (xmlDescFile != null) ? xmlDescFile.getAbsolutePath() : xmlDescUrl.toString();
    try {
      // clean error message
      __errTableByUri.remove(xmlDescUri);
      // get XMLParser
      XMLParser xmlParser = UIMAFramework.getXMLParser();
      // create XML source
      xmlSource = (xmlDescFile != null) ? new XMLInputSource(xmlDescFile) : new XMLInputSource(
              xmlDescUrl);
      // parse XML source and create resource specifier
      ResourceSpecifier resourceSpec = null;
      try {
        resourceSpec = xmlParser.parseResourceSpecifier(xmlSource);
      } catch (UIMAException err) {
        __errTableByUri.put( xmlDescUri, err );
      } catch (UIMARuntimeException exc) {
        __errTableByUri.put( xmlDescUri, exc );
      }
      if (resourceSpec != null) { // AE | CR | CI | CC | CustomResourceSpecifier ?
        // identify UIMA resource category
        if (resourceSpec instanceof AnalysisEngineDescription) {
          uimaCompCtg = ANALYSIS_ENGINE_CTG;
        } else if (resourceSpec instanceof CollectionReaderDescription) {
          uimaCompCtg = COLLECTION_READER_CTG;
        } else if (resourceSpec instanceof CasInitializerDescription) {
          uimaCompCtg = CAS_INITIALIZER_CTG;
        } else if (resourceSpec instanceof CasConsumerDescription) {
          uimaCompCtg = CAS_CONSUMER_CTG;
        } else if (resourceSpec instanceof CustomResourceSpecifier) {
           // try to treat custom resource specifiers as AE
           uimaCompCtg = ANALYSIS_ENGINE_CTG;
        }
      }
      if (uimaCompCtg == null) { // CPE ?
        // refresh XML source object
        try {
          xmlSource.getInputStream().close();
        } catch (Exception e) {
        }
        xmlSource = (xmlDescFile != null) ? new XMLInputSource(xmlDescFile) : new XMLInputSource(xmlDescUrl);
        try {
          // try parsing CPE configuration
          xmlParser.parseCpeDescription(xmlSource);
          uimaCompCtg = CPE_CONFIGURATION_CTG;
          __errTableByUri.remove( xmlDescUri );
        } catch (UIMAException err) {
          __errTableByUri.put( xmlDescUri, err );
        } catch (UIMARuntimeException exc) {
          __errTableByUri.put( xmlDescUri, exc );
        }
      }
      if (uimaCompCtg == null) { // TS ?
        // refresh XML source object
        try {
          xmlSource.getInputStream().close();
        } catch (Exception e) {
        }
        xmlSource = (xmlDescFile != null) ? new XMLInputSource(xmlDescFile) : new XMLInputSource(xmlDescUrl);
        try {
          // try parsing TS description
          xmlParser.parseTypeSystemDescription(xmlSource);
          uimaCompCtg = TYPE_SYSTEM_CTG;
          __errTableByUri.remove( xmlDescUri );
        } catch (UIMAException err) {
          __errTableByUri.put( xmlDescUri, err );
        } catch (UIMARuntimeException exc) {
          __errTableByUri.put( xmlDescUri, exc );
        }
      }
      if (uimaCompCtg == null) { // RR ?
        // refresh XML source object
        try {
          xmlSource.getInputStream().close();
        } catch (Exception e) {
        }
        xmlSource = (xmlDescFile != null) ? new XMLInputSource(xmlDescFile) : new XMLInputSource(xmlDescUrl);
        try {
          // try parsing RES manager configuration
          xmlParser.parseResourceManagerConfiguration(xmlSource);
          uimaCompCtg = REUSABLE_RESOURCE_CTG;
          __errTableByUri.remove( xmlDescUri );
        } catch (UIMAException err) {
          __errTableByUri.put( xmlDescUri, err );
        } catch (UIMARuntimeException exc) {
View Full Code Here

      while (-1 != (bytesread = zis.read(buff))) {
        baos.write(buff,0,bytesread);
      }
      ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
      // Get XML parser from framework
      XMLParser xmlParser = UIMAFramework.getXMLParser();
      // Parse type system descriptor
      TypeSystemDescription tsDesc = xmlParser.parseTypeSystemDescription(new XMLInputSource((InputStream)bis,null));
      // Use type system description to create CAS and get the type system object
      inputTS = CasCreationUtils.createCas(tsDesc, null, null).getTypeSystem();
      // advance to first input CAS
    nextEntry = zis.getNextEntry();
    } catch (Exception e) {
View Full Code Here

  public void initialize() throws InvalidXMLException, ResourceConfigurationException, ResourceInitializationException {
    String mid = "initialize";
    mh.frameworkTrace(cid, mid, "enter");
    String crDescriptor = properties.getProperty(UiOption.DriverDescriptorCR.pname());
    String crOverrides = properties.getProperty(UiOption.DriverDescriptorCROverrides.pname());
    XMLParser xmlParser = UIMAFramework.getXMLParser();
    XMLInputSource in = null;
    try {
      in = UimaUtils.getXMLInputSource(crDescriptor);
    }
    catch (InvalidXMLException e) {
      mh.error(e);
      throw e;
    }
    ResourceSpecifier crrs = xmlParser.parseCollectionReaderDescription(in);
    // CR overrides - throw up if trying to override an undefined parameter
        ResourceCreationSpecifier specifier = (ResourceCreationSpecifier) crrs;
        ConfigurationParameterDeclarations configurationParameterDeclarations = specifier.getMetaData().getConfigurationParameterDeclarations();
        ConfigurationParameterSettings cps = specifier.getMetaData().getConfigurationParameterSettings();
        if(crOverrides != null) {
View Full Code Here

        // CR descriptor
        String crDescriptor = crxml;
        //
        // Read and parse the collection reader
        //
        XMLParser xmlParser = UIMAFramework.getXMLParser();
        XMLInputSource in = null;
    try {
      in = UimaUtils.getXMLInputSource(crDescriptor);
    } catch (InvalidXMLException e) {
            duccOut.error(location, job.getDuccId(), e);
            throw e;
    }
        ResourceSpecifier crrs = xmlParser.parseCollectionReaderDescription(in);

        duccOut.debug(location, job.getDuccId(), crcfg);
        // CR overrides
        ResourceCreationSpecifier specifier = (ResourceCreationSpecifier) crrs;
        ConfigurationParameterDeclarations configurationParameterDeclarations = specifier.getMetaData().getConfigurationParameterDeclarations();
View Full Code Here

    assertTrue("Expected number of results was " + expectedResultNumber + ", actual number is "
        + resultSize, (resultSize == expectedResultNumber));
  }

  private static final JCas createTestCas() {
    XMLParser parser = UIMAFramework.getXMLParser();
    File descriptorFile = JUnitExtension.getFile("desc/simpleServerTestDescriptor.xml");
    File textFile = JUnitExtension.getFile("test.txt");
    String text = null;
    try {
      text = FileUtils.file2String(textFile, "utf-8");
    } catch (IOException e1) {
      e1.printStackTrace();
      assertTrue(false);
    }
    AnalysisEngineDescription aeDesc = null;
    try {
      aeDesc = (AnalysisEngineDescription) parser.parse(new XMLInputSource(descriptorFile));
    } catch (InvalidXMLException e) {
      e.printStackTrace();
      assertTrue(false);
    } catch (IOException e) {
      e.printStackTrace();
View Full Code Here

    String xmlDescUri = (xmlDescFile != null) ? xmlDescFile.getAbsolutePath() : xmlDescUrl.toString();
    try {
      // clean error message
      __errTableByUri.remove(xmlDescUri);
      // get XMLParser
      XMLParser xmlParser = UIMAFramework.getXMLParser();
      // create XML source
      xmlSource = (xmlDescFile != null) ? new XMLInputSource(xmlDescFile) : new XMLInputSource(
              xmlDescUrl);
      // parse XML source and create resource specifier
      ResourceSpecifier resourceSpec = null;
      try {
        resourceSpec = xmlParser.parseResourceSpecifier(xmlSource);
      } catch (UIMAException err) {
        __errTableByUri.put( xmlDescUri, err );
      } catch (UIMARuntimeException exc) {
        __errTableByUri.put( xmlDescUri, exc );
      }
      if (resourceSpec != null) { // AE | CR | CI | CC | CustomResourceSpecifier ?
        // identify UIMA resource category
        if (resourceSpec instanceof AnalysisEngineDescription) {
          uimaCompCtg = ANALYSIS_ENGINE_CTG;
        } else if (resourceSpec instanceof CollectionReaderDescription) {
          uimaCompCtg = COLLECTION_READER_CTG;
        } else if (resourceSpec instanceof CasInitializerDescription) {
          uimaCompCtg = CAS_INITIALIZER_CTG;
        } else if (resourceSpec instanceof CasConsumerDescription) {
          uimaCompCtg = CAS_CONSUMER_CTG;
        } else if (resourceSpec instanceof CustomResourceSpecifier) {
           // try to treat custom resource specifiers as AE
           uimaCompCtg = ANALYSIS_ENGINE_CTG;
        }
      }
      if (uimaCompCtg == null) { // CPE ?
        // refresh XML source object
        try {
          xmlSource.getInputStream().close();
        } catch (Exception e) {
        }
        xmlSource = (xmlDescFile != null) ? new XMLInputSource(xmlDescFile) : new XMLInputSource(xmlDescUrl);
        try {
          // try parsing CPE configuration
          xmlParser.parseCpeDescription(xmlSource);
          uimaCompCtg = CPE_CONFIGURATION_CTG;
          __errTableByUri.remove( xmlDescUri );
        } catch (UIMAException err) {
          __errTableByUri.put( xmlDescUri, err );
        } catch (UIMARuntimeException exc) {
          __errTableByUri.put( xmlDescUri, exc );
        }
      }
      if (uimaCompCtg == null) { // TS ?
        // refresh XML source object
        try {
          xmlSource.getInputStream().close();
        } catch (Exception e) {
        }
        xmlSource = (xmlDescFile != null) ? new XMLInputSource(xmlDescFile) : new XMLInputSource(xmlDescUrl);
        try {
          // try parsing TS description
          xmlParser.parseTypeSystemDescription(xmlSource);
          uimaCompCtg = TYPE_SYSTEM_CTG;
          __errTableByUri.remove( xmlDescUri );
        } catch (UIMAException err) {
          __errTableByUri.put( xmlDescUri, err );
        } catch (UIMARuntimeException exc) {
          __errTableByUri.put( xmlDescUri, exc );
        }
      }
      if (uimaCompCtg == null) { // RR ?
        // refresh XML source object
        try {
          xmlSource.getInputStream().close();
        } catch (Exception e) {
        }
        xmlSource = (xmlDescFile != null) ? new XMLInputSource(xmlDescFile) : new XMLInputSource(xmlDescUrl);
        try {
          // try parsing RES manager configuration
          xmlParser.parseResourceManagerConfiguration(xmlSource);
          uimaCompCtg = REUSABLE_RESOURCE_CTG;
          __errTableByUri.remove( xmlDescUri );
        } catch (UIMAException err) {
          __errTableByUri.put( xmlDescUri, err );
        } catch (UIMARuntimeException exc) {
View Full Code Here

TOP

Related Classes of org.apache.uima.util.XMLParser

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.