org.apache.uima.util.XMLInputSource Java Examples

The following examples show how to use org.apache.uima.util.XMLInputSource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JsonMetaDataObjectTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testTypeSystemDescriptionSerialization() throws Exception {
  
  XMLInputSource in = new XMLInputSource(JUnitExtension.getFile("CASTests/desc/casTestCaseTypesystem.xml"));
  TypeSystemDescription tsd;
  tsd = UIMAFramework.getXMLParser().parseTypeSystemDescription(in);
  in.close();

  StringWriter sw = new StringWriter();
  
  JsonMetaDataSerializer.toJSON(tsd, sw, false);  // no pretty print
  assertEquals(getExpected("testTypesystem-plain.json"),sw.toString());

  sw = new StringWriter();
  JsonMetaDataSerializer.toJSON(tsd, sw, true);
  assertEquals(getExpected("testTypesystem.json"),canonicalizeNewLines(sw.toString()));
  
}
 
Example #2
Source File: CollectionProcessingEngine_implTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testExternalResoures() throws Exception {
  try {
    ResourceManager rm = UIMAFramework.newDefaultResourceManager();
    rm.setDataPath(TEST_DATAPATH);
    CpeDescription cpeDesc = UIMAFramework.getXMLParser().parseCpeDescription(
 new XMLInputSource(JUnitExtension
     .getFile("CollectionProcessingEngineImplTest/externalResourceTestCpe.xml")));
    CollectionProcessingEngine cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc, rm,
 null);
    CollectionReader colRdr = (CollectionReader) cpe.getCollectionReader();
    assertNotNull(colRdr.getUimaContext().getResourceObject("TestFileResource"));
    CasInitializer casIni = colRdr.getCasInitializer();
    assertNotNull(casIni.getUimaContext().getResourceObject("TestFileLanguageResource",
 new String[] { "en" }));
    AnalysisEngine ae = (AnalysisEngine) cpe.getCasProcessors()[0];
    assertNotNull(ae.getUimaContext().getResourceObject("TestResourceObject"));
    assertNotNull(ae.getUimaContext().getResourceObject("TestLanguageResourceObject",
 new String[] { "en" }));
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example #3
Source File: CollectionProcessingEngine_implTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testCasMultiplierTypeSystem() throws Throwable {
  CpeDescription cpeDesc = UIMAFramework.getXMLParser()
          .parseCpeDescription(new XMLInputSource(
                  JUnitExtension.getFile("CollectionProcessingEngineImplTest/cpeWithWrappedCasMultiplier.xml")));
  CollectionProcessingEngine cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc);
  // create and register a status callback listener
  TestStatusCallbackListener listener = new TestStatusCallbackListener();
  cpe.addStatusCallbackListener(listener);

  // run CPM
  cpe.process();

  // wait until CPM has finished
  while (!listener.isFinished()) {
    Thread.sleep(5);
  }
  
  //check that there was no exception
  if (listener.getLastStatus().isException()) {
    throw (Throwable)listener.getLastStatus().getExceptions().get(0);
  }
}
 
Example #4
Source File: AnnotatorTester.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * create a CAS object from the given XCAS and typesystem files.
 *
 * @param tsFile -
 *           a typesystem file
 * @param xcasFile -
 *           a xcas file
 * @return CAS - CAS object created from the given input data
 * @throws Exception passthru
 */
public static CAS getCASfromXCAS(File tsFile, File xcasFile)
      throws Exception {
   try {
      Object tsDescriptor = UIMAFramework.getXMLParser().parse(
            new XMLInputSource(tsFile));
      TypeSystemDescription tsDesc = (TypeSystemDescription) tsDescriptor;
      CAS cas = CasCreationUtils.createCas(tsDesc, null,
            new FsIndexDescription[0]);

      SAXParser parser = XMLUtils.createSAXParserFactory().newSAXParser();
      XCASDeserializer xcasDeserializer = new XCASDeserializer(cas
            .getTypeSystem());
      parser.parse(xcasFile, xcasDeserializer.getXCASHandler(cas));

      return cas;
   } catch (Exception ex) {
      JUnitExtension.handleException(ex);
   }

   return null;
}
 
Example #5
Source File: CpeDescriptorSerialization_Test.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * test to be sure, that first reading and then writing a discriptor produces the same file as the
 * original (new configuration file format).
 * 
 * @throws Exception -
 */
public void testReadDescriptor2() throws Exception {

  // input file
  File cpeDescFile = JUnitExtension.getFile("CpmTests/CpeAPITest/refConf2.xml");
  XMLInputSource in = new XMLInputSource(cpeDescFile);
  cpeDesc = UIMAFramework.getXMLParser().parseCpeDescription(in);

  // output file
  File outputFile = new File(this.testBaseDir, "outConf2.xml");

  // serialize input file to output file
  ByteArrayOutputStream outStream = new ByteArrayOutputStream();
  cpeDesc.toXML(outStream);
  FileOutputStream fOut = new FileOutputStream(outputFile);
  fOut.write(outStream.toByteArray());
  fOut.close();

  equal(cpeDescFile, cpeDesc);

  outputFile.delete();
}
 
Example #6
Source File: ResultSpecTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testComputeAnalysisComponentResultSpec() throws Exception {
  try {
    AnalysisEngineDescription aeDesc = UIMAFramework.getXMLParser()
            .parseAnalysisEngineDescription(
                    new XMLInputSource(JUnitExtension.getFile("SequencerTest/Annotator1.xml")));
    PrimitiveAnalysisEngine_impl ae = (PrimitiveAnalysisEngine_impl) UIMAFramework
            .produceAnalysisEngine(aeDesc);
    CAS cas = ae.newCAS();
    ResultSpecification_impl resultSpec = new ResultSpecification_impl();
    resultSpec.addResultType("uima.tt.TokenLikeAnnotation", true);
    resultSpec.setTypeSystem(cas.getTypeSystem());
    
    ResultSpecification_impl rs2 = new ResultSpecification_impl(cas.getTypeSystem());
    rs2.addCapabilities(ae.getAnalysisEngineMetaData().getCapabilities());
    ResultSpecification acResultSpec = resultSpec.intersect(rs2);
    assertTrue(acResultSpec.containsType("uima.tt.TokenAnnotation"));
    assertFalse(acResultSpec.containsType("uima.tt.SentenceAnnotation"));
    assertFalse(acResultSpec.containsType("uima.tt.Lemma"));
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example #7
Source File: ResultSpecTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testComputeAnalysisComponentResultSpecInherit() throws Exception {
  try {
    AnalysisEngineDescription aeDesc = UIMAFramework.getXMLParser()
            .parseAnalysisEngineDescription(
                    new XMLInputSource(JUnitExtension.getFile("SequencerTest/Annotator1.xml")));
    PrimitiveAnalysisEngine_impl ae = (PrimitiveAnalysisEngine_impl) UIMAFramework
            .produceAnalysisEngine(aeDesc);
    CAS cas = ae.newCAS();
    ResultSpecification_impl resultSpec = new ResultSpecification_impl(cas.getTypeSystem());
    resultSpec.addResultType("uima.tcas.Annotation", true);
    
    ResultSpecification_impl rs2 = new ResultSpecification_impl(cas.getTypeSystem());
    rs2.addCapabilities(ae.getAnalysisEngineMetaData().getCapabilities());
    ResultSpecification acResultSpec = resultSpec.intersect(rs2);
    assertTrue(acResultSpec.containsType("uima.tt.TokenAnnotation"));
    assertTrue(acResultSpec.containsType("uima.tt.SentenceAnnotation"));
    assertFalse(acResultSpec.containsType("uima.tt.Lemma"));
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example #8
Source File: AnnotatorTester.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * initialize the analysis engine with the specified specifier.
 * 
 * @throws Exception passthru
 */
private void setup() throws Exception {
   try {
      this.ae = null;
      // Create an XML input source from the specifier file.
      XMLInputSource in = new XMLInputSource(this.descFile);
      // Parse the specifier.
      ResourceSpecifier specifier = UIMAFramework.getXMLParser()
            .parseResourceSpecifier(in);
      // Create the Text Analysis Engine.
      this.ae = UIMAFramework.produceAnalysisEngine(specifier, this.mgr,
            null);
   } catch (Exception ex) {
      JUnitExtension.handleException(ex);
   }
}
 
Example #9
Source File: TypePriorities_implTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testClone() throws Exception {
  try {
    File descriptor = JUnitExtension.getFile("TypePrioritiesImplTest/TestTypePriorities.xml");
    TypePriorities pri = UIMAFramework.getXMLParser().parseTypePriorities(
            new XMLInputSource(descriptor));

    TypePriorities clone = (TypePriorities) pri.clone();

    assertEquals(clone, pri);
    assertFalse(clone.getPriorityLists()[0] == pri.getPriorityLists()[0]);

  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }

}
 
Example #10
Source File: JCasCoverClassFactoryTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateJCasCoverClass() throws InvalidXMLException, IOException, ResourceInitializationException {
  File file = JUnitExtension.getFile("JCasGen/typeSystemAllKinds.xml");
  TypeSystemDescription tsDesc = UIMAFramework.getXMLParser().parseTypeSystemDescription(
          new XMLInputSource(file));
 
  CAS cas = CasCreationUtils.createCas(tsDesc, null, null);
  
  JCasCoverClassFactory jcf = new JCasCoverClassFactory();
  
  byte[] r = jcf.createJCasCoverClass((TypeImpl) cas.getTypeSystem().getType("pkg.sample.name.All"));

  Path root = Paths.get(".");  // should resolve to the project path
  Path dir = root.resolve("temp/test/JCasGen");
  dir.toFile().mkdirs();
  Files.write(dir.resolve("testOutputAllKinds.class"), r);
  
  System.out.println("debug: generated byte array");
}
 
Example #11
Source File: ResourceManagerConfiguration_implTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testClone() throws Exception {
  try {
    File descriptor = JUnitExtension
            .getFile("ResourceManagerConfigurationImplTest/TaeImportingResourceManagerConfiguration.xml");
    AnalysisEngineDescription aeDesc = UIMAFramework.getXMLParser()
            .parseAnalysisEngineDescription(new XMLInputSource(descriptor));
    ResourceManagerConfiguration rmc = aeDesc.getResourceManagerConfiguration();
    ResourceManagerConfiguration rmcClone = (ResourceManagerConfiguration) rmc.clone();
    assertEquals(0, rmcClone.getExternalResources().length);
    assertEquals(0, rmcClone.getExternalResourceBindings().length);
    assertEquals(1, rmcClone.getImports().length);

    rmc.resolveImports();

    assertEquals(4, rmc.getExternalResources().length);
    assertEquals(4, rmc.getExternalResourceBindings().length);
    assertEquals(0, rmc.getImports().length);

    assertEquals(0, rmcClone.getExternalResources().length);
    assertEquals(0, rmcClone.getExternalResourceBindings().length);
    assertEquals(1, rmcClone.getImports().length);
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example #12
Source File: AnalysisEngineFactoryTest.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
@Test
public void testPear() throws Exception {
  // Install PEAR package
  PackageBrowser instPear = PackageInstaller.installPackage(
          new File("target/test-output/AnalysisEngineFactoryTest/testPear"), 
          new File("src/test/resources/pear/DateTime.pear"), true);

  // Create analysis engine from the installed PEAR package
  XMLInputSource in = new XMLInputSource(instPear.getComponentPearDescPath());
  PearSpecifier specifier = UIMAFramework.getXMLParser().parsePearSpecifier(in);
  
  AnalysisEngine ae = createEngine(createEngineDescription(specifier));
  
  // 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");
  cas.setDocumentLanguage("en");
  ae.process(cas);
}
 
Example #13
Source File: ResourceManager_implTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testOverrides() throws Exception {
  try {
    final String TEST_DATAPATH = JUnitExtension.getFile("AnnotatorContextTest").getPath();

    File descFile = JUnitExtension.getFile("ResourceManagerImplTest/ResourceTestAggregate.xml");
    AnalysisEngineDescription desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(
            new XMLInputSource(descFile));
    ResourceManager resMgr = UIMAFramework.newDefaultResourceManager();
    resMgr.setDataPath(TEST_DATAPATH);
    UIMAFramework.produceAnalysisEngine(desc, resMgr, null);

    URL url = resMgr.getResourceURL("/Annotator1/TestFileResource");
    assertTrue(url.toString().endsWith("testDataFile2.dat"));
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example #14
Source File: JcasSofaTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testGetSofa() throws Exception {
  try {
    File typeSystemFile = JUnitExtension.getFile("ExampleCas/testTypeSystem.xml");
    TypeSystemDescription typeSystem = UIMAFramework.getXMLParser().parseTypeSystemDescription(
            new XMLInputSource(typeSystemFile));
    CAS newCas = CasCreationUtils.createCas(typeSystem, null, null);
    File xcasFile = JUnitExtension.getFile("ExampleCas/multiSofaCas.xml"); 
    XCASDeserializer.deserialize(new FileInputStream(xcasFile), newCas);
    JCas newJCas = newCas.getJCas();
    
    SofaID sofaId = new SofaID_impl("EnglishDocument");
    JCas view = newJCas.getView(newJCas.getSofa(sofaId));
  }
  catch (Exception e) {
    JUnitExtension.handleException(e);      
  }      
}
 
Example #15
Source File: Import_implTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testNestedImports() throws Exception {
  try {
    File baseDescriptorFile = JUnitExtension
            .getFile("ImportImplTest/subdir/subdir2/AggregateTaeForNestedImportTest.xml");
    File importedFile = JUnitExtension
            .getFile("ImportImplTest/subdir/PrimitiveTaeForNestedImportTest.xml");
    AnalysisEngineDescription_impl agg = (AnalysisEngineDescription_impl) UIMAFramework.getXMLParser()
            .parseAnalysisEngineDescription(new XMLInputSource(baseDescriptorFile));
    assertEquals(baseDescriptorFile.toURL(), agg.getSourceUrl());

    AnalysisEngineDescription_impl prim = (AnalysisEngineDescription_impl) agg.getDelegateAnalysisEngineSpecifiers()
            .get("Annotator1");
    assertEquals(importedFile.toURL(), prim.getSourceUrl());

    prim.getAnalysisEngineMetaData().getTypeSystem().resolveImports();
    assertEquals(1, prim.getAnalysisEngineMetaData().getTypeSystem().getTypes().length);
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example #16
Source File: AnalysisEngine_implTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testMultiViewAnnotatorInput() throws Exception {
  try {
    AnalysisEngineDescription transAnnotatorDesc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(
            new XMLInputSource(JUnitExtension
                    .getFile("TextAnalysisEngineImplTest/MultiViewAnnotator.xml")));
    PrimitiveAnalysisEngine_impl ae = new PrimitiveAnalysisEngine_impl();
    ae.initialize(transAnnotatorDesc, null);
    CAS tcas = ae.newCAS();
    tcas.setDocumentText("this beer is good");
    assertTrue(tcas.getView("_InitialView").getDocumentText().equals("this beer is good"));
    ae.process(tcas);
    assertTrue(tcas.getView("GermanDocument").getViewName().equals("GermanDocument"));
    assertTrue(tcas.getView("GermanDocument").getDocumentText().equals("das bier ist gut"));
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example #17
Source File: XMLParser_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public CollectionReaderDescription parseCollectionReaderDescription(XMLInputSource aInput,
        ParsingOptions aOptions) throws InvalidXMLException {
  // attempt to locate resource specifier schema
  XMLizable object = parse(aInput, RESOURCE_SPECIFIER_NAMESPACE, SCHEMA_URL, aOptions);

  if (object instanceof CollectionReaderDescription) {
    return (CollectionReaderDescription) object;
  } else {
    throw new InvalidXMLException(InvalidXMLException.INVALID_CLASS, new Object[] {
        CollectionReaderDescription.class.getName(), object.getClass().getName() });
  }
}
 
Example #18
Source File: SimpleRunCPE.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor for the class.
 *
 * @param args          command line arguments into the program - see class description
 * @throws Exception the exception
 */
public SimpleRunCPE(String args[]) throws Exception {
  mStartTime = System.currentTimeMillis();

  // check command line args
  if (args.length < 1) {
    printUsageMessage();
    System.exit(1);
  }

  // parse CPE descriptor
  System.out.println("Parsing CPE Descriptor");
  CpeDescription cpeDesc = UIMAFramework.getXMLParser().parseCpeDescription(
          new XMLInputSource(args[0]));
  // instantiate CPE
  System.out.println("Instantiating CPE");
  mCPE = UIMAFramework.produceCollectionProcessingEngine(cpeDesc);

  // Create and register a Status Callback Listener
  mCPE.addStatusCallbackListener(new StatusCallbackListenerImpl());

  // Start Processing
  System.out.println("Running CPE");
  mCPE.process();

  // Allow user to abort by pressing Enter
  System.out.println("To abort processing, type \"abort\" and press enter.");
  while (true) {
    String line = new BufferedReader(new InputStreamReader(System.in)).readLine();
    if ("abort".equals(line) && mCPE.isProcessing()) {
      System.out.println("Aborting...");
      mCPE.stop();
      break;
    }
  }
}
 
Example #19
Source File: XMLParser_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public TypePriorities parseTypePriorities(XMLInputSource aInput, ParsingOptions aOptions)
        throws InvalidXMLException {
  // attempt to locate resource specifier schema
  XMLizable object = parse(aInput, RESOURCE_SPECIFIER_NAMESPACE, SCHEMA_URL, aOptions);

  if (object instanceof TypePriorities) {
    return (TypePriorities) object;
  } else {
    throw new InvalidXMLException(InvalidXMLException.INVALID_CLASS, new Object[] {
        TypePriorities.class.getName(), object.getClass().getName() });
  }
}
 
Example #20
Source File: XMLParser_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a ResourceMetaData object from an XML input stream. XML schema validation will be done
 * against the {@link #RESOURCE_SPECIFIER_SCHEMA_NAME} if it can be found in the classpath.
 * 
 * @param aInput
 *          the input source from which to read the XML document
 * 
 * @return a <code>ResourceMetaData</code> object constructed from the XML document
 * 
 * @throws InvalidXMLException
 *           if the input XML is not valid or does not specify a valid ResourceSpecifier
 */
public ResourceMetaData parseResourceMetaData(XMLInputSource aInput, ParsingOptions aOptions)
        throws InvalidXMLException {
  // attempt to locate resource specifier schema
  XMLizable object = parse(aInput, RESOURCE_SPECIFIER_NAMESPACE, SCHEMA_URL, aOptions);

  if (object instanceof ResourceMetaData) {
    return (ResourceMetaData) object;
  } else {
    throw new InvalidXMLException(InvalidXMLException.INVALID_CLASS, new Object[] {
        ResourceMetaData.class.getName(), object.getClass().getName() });
  }
}
 
Example #21
Source File: TypeSystemReinitTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testReinitCASCompleteSerializerWithArrays() throws Exception {
  try {
    AnalysisEngineDescription aed = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(
            new XMLInputSource(JUnitExtension
                    .getFile("ExampleTae/arrayTypeSerialization.xml")));
   
    CAS cas1 = CasCreationUtils.createCas(aed);
    cas1.setDocumentText("foo");
    CASCompleteSerializer ser = Serialization.serializeCASComplete((CASMgr) cas1);

    CAS tcas2 = CasCreationUtils.createCas(new TypeSystemDescription_impl(), null, null);
    CASImpl cas2 = ((CASImpl) tcas2).getBaseCAS();
    tcas2.setDocumentText("bar");

    // reinit
    //  This uses cas2 which only has a base type system to start, 
    //    and loads it from a complete serialization which has other new types
    cas2.getBinaryCasSerDes().reinit(ser);
    CAS tcas3 = cas2.getCurrentView();

    assertTrue(tcas2 == tcas3);
    assertNotNull(cas1.getTypeSystem().getType("Test.ArrayType"));
    assertNotNull(tcas3.getTypeSystem().getType("Test.ArrayType"));
    
    TypeSystemImpl ts = (TypeSystemImpl)cas2.getTypeSystem();
    Type arrayType = ts.getType("Test.ArrayType");
    Feature arrayFeat = arrayType.getFeatureByBaseName("arrayFeature");
    TypeImpl featRange = (TypeImpl)(arrayFeat.getRange());
   
    assertTrue(ts.ll_isArrayType(featRange.getCode()));
    assertFalse(arrayFeat.isMultipleReferencesAllowed());
    
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example #22
Source File: ResourceManagerConfiguration_implTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testResolveImports() throws Exception {
  try {
    File descriptor = JUnitExtension
            .getFile("ResourceManagerConfigurationImplTest/TaeImportingResourceManagerConfiguration.xml");
    AnalysisEngineDescription aeDesc = UIMAFramework.getXMLParser()
            .parseAnalysisEngineDescription(new XMLInputSource(descriptor));
    ResourceManagerConfiguration rmc = aeDesc.getResourceManagerConfiguration();
    assertEquals(0, rmc.getExternalResources().length);
    assertEquals(0, rmc.getExternalResourceBindings().length);

    rmc.resolveImports();

    assertEquals(4, rmc.getExternalResources().length);
    assertEquals(4, rmc.getExternalResourceBindings().length);

    // test old single-import style
    descriptor = JUnitExtension
            .getFile("ResourceManagerConfigurationImplTest/TaeImportingResourceManagerConfiguration.xml");
    aeDesc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(
            new XMLInputSource(descriptor));
    rmc = aeDesc.getResourceManagerConfiguration();
    assertEquals(0, rmc.getExternalResources().length);
    assertEquals(0, rmc.getExternalResourceBindings().length);

    rmc.resolveImports();

    assertEquals(4, rmc.getExternalResources().length);
    assertEquals(4, rmc.getExternalResourceBindings().length);

  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example #23
Source File: XMLParser_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a AnalysisEngineDescription from an XML input stream. XML schema validation will be done
 * against the {@link #RESOURCE_SPECIFIER_SCHEMA_NAME} if it can be found in the classpath.
 * 
 * @param aInput
 *          the input source from which to read the XML document
 * 
 * @return a <code>AnalysisEngineDescription</code> object constructed from the XML document
 * 
 * @throws InvalidXMLException
 *           if the input XML is not valid or does not specify a valid AnalysisEngineDescription
 */
public AnalysisEngineDescription parseAnalysisEngineDescription(XMLInputSource aInput,
        ParsingOptions aOptions) throws InvalidXMLException {
  // attempt to locate resource specifier schema
  XMLizable object = parse(aInput, RESOURCE_SPECIFIER_NAMESPACE, SCHEMA_URL, aOptions);

  if (object instanceof AnalysisEngineDescription) {
    return (AnalysisEngineDescription) object;
  } else {
    throw new InvalidXMLException(InvalidXMLException.INVALID_CLASS, new Object[] {
        AnalysisEngineDescription.class.getName(), object.getClass().getName() });
  }
}
 
Example #24
Source File: XMLParser_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a URISpecifier from an XML input stream. XML schema validation will be done against the
 * {@link #RESOURCE_SPECIFIER_SCHEMA_NAME} if it can be found in the classpath.
 * 
 * @param aInput
 *          the input source from which to read the XML document
 * 
 * @return a <code>URISpecifier</code> object constructed from the XML document
 * 
 * @throws InvalidXMLException
 *           if the input XML is not valid or does not specify a valid URISpecifier
 */
public URISpecifier parseURISpecifier(XMLInputSource aInput, ParsingOptions aOptions)
        throws InvalidXMLException {
  // attempt to locate resource specifier schema
  XMLizable object = parse(aInput, RESOURCE_SPECIFIER_NAMESPACE, SCHEMA_URL, aOptions);

  if (object instanceof URISpecifier) {
    return (URISpecifier) object;
  } else {
    throw new InvalidXMLException(InvalidXMLException.INVALID_CLASS, new Object[] {
        URISpecifier.class.getName(), object.getClass().getName() });
  }
}
 
Example #25
Source File: DocumentAnalyzer.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a CAS from an descriptor. Supports both local AE descriptors and remote service
 * specifiers. In the latter case the service is contacted to obtain its type system.
 *
 * @param aDescriptorFile the a descriptor file
 * @return the cas
 * @throws ResourceInitializationException -
 * @throws InvalidXMLException -
 * @throws IOException -
 */
protected CAS createCasFromDescriptor(String aDescriptorFile) // JMP
        throws ResourceInitializationException, InvalidXMLException, IOException {
  ResourceSpecifier spec = UIMAFramework.getXMLParser().parseResourceSpecifier(
          new XMLInputSource(aDescriptorFile));
  if (spec instanceof AnalysisEngineDescription) {
    return CasCreationUtils.createCas((AnalysisEngineDescription) spec);
  } else {
    AnalysisEngine currentAe = UIMAFramework.produceAnalysisEngine(spec);
    return CasCreationUtils.createCas(currentAe.getAnalysisEngineMetaData());
  }
}
 
Example #26
Source File: AnnotatorTester.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * does configuration parameter test.
 *
 * @param configDescFilePath the config desc file path
 * @return AnalysisEngine
 * @throws Exception passthru
 */
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);
   }

   return null;

}
 
Example #27
Source File: XMLParser_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public CpeDescription parseCpeDescription(XMLInputSource aInput) throws InvalidXMLException {
  XMLizable object = parse(aInput);

  if (object instanceof CpeDescription) {
    return (CpeDescription) object;
  } else {
    throw new InvalidXMLException(InvalidXMLException.INVALID_CLASS, new Object[] {
        CpeDescription.class.getName(), object.getClass().getName() });
  }
}
 
Example #28
Source File: RemoteStringMatchingNerRecommender.java    From inception with Apache License 2.0 5 votes vote down vote up
private CAS buildCas(String typeSystem) throws IOException, UIMAException
{
    // We need to save the typeSystem XML to disk as the
    // JCasFactory needs a file and not a string
    TypeSystemDescription tsd = UIMAFramework.getXMLParser().parseTypeSystemDescription(
            new XMLInputSource(IOUtils.toInputStream(typeSystem, UTF_8), null));
    JCas jCas = JCasFactory.createJCas(tsd);
    return jCas.getCas();
}
 
Example #29
Source File: TypeSystemDescription_implTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testBuildFromXmlElement() throws Exception {
  try {
    File descriptor = JUnitExtension.getFile("TypeSystemDescriptionImplTest/TestTypeSystem.xml");
    TypeSystemDescription ts = UIMAFramework.getXMLParser().parseTypeSystemDescription(
            new XMLInputSource(descriptor));

    assertEquals("TestTypeSystem", ts.getName());
    assertEquals("This is a test.", ts.getDescription());
    assertEquals("The Apache Software Foundation", ts.getVendor());
    assertEquals("0.1", ts.getVersion());
    Import[] imports = ts.getImports();
    assertEquals(3, imports.length);
    assertEquals("org.apache.uima.resource.metadata.impl.TypeSystemImportedByName", imports[0]
            .getName());
    assertNull(imports[0].getLocation());
    assertNull(imports[1].getName());
    assertEquals("TypeSystemImportedByLocation.xml", imports[1].getLocation());

    TypeDescription[] types = ts.getTypes();
    assertEquals(6, types.length);
    TypeDescription paragraphType = types[4];
    assertEquals("Paragraph", paragraphType.getName());
    assertEquals("A paragraph.", paragraphType.getDescription());
    assertEquals("DocumentStructure", paragraphType.getSupertypeName());
    FeatureDescription[] features = paragraphType.getFeatures();
    assertEquals(2, features.length);
    assertEquals("sentences", features[0].getName());
    assertEquals("Direct references to sentences in this paragraph", features[0].getDescription());
    assertEquals("uima.cas.FSArray", features[0].getRangeTypeName());
    assertEquals("Sentence", features[0].getElementType());
    assertFalse(features[0].getMultipleReferencesAllowed());

    // ts.toXML(System.out);
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example #30
Source File: XMLParser_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public PearSpecifier parsePearSpecifier(XMLInputSource aInput, ParsingOptions aOptions) throws InvalidXMLException {
  // attempt to locate resource specifier schema
  XMLizable object = parse(aInput, RESOURCE_SPECIFIER_NAMESPACE, SCHEMA_URL, aOptions);

  if (object instanceof PearSpecifier) {
    return (PearSpecifier) object;
  } else {
    throw new InvalidXMLException(InvalidXMLException.INVALID_CLASS, new Object[] {
            PearSpecifier.class.getName(), object.getClass().getName() });
  }
}