Package org.apache.uima.resource.metadata.impl

Examples of org.apache.uima.resource.metadata.impl.Import_impl


public class XsltImportByName {
  private static final Class CLASS_NAME = XsltImportByName.class;

  public static String resolveByName(String input) {
    ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager();
    Import theImport = new Import_impl();
    theImport.setName(input);
    try {
      return theImport.findAbsoluteUrl(resourceManager).toExternalForm();
    } catch (InvalidXMLException e) {
      if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.WARNING)) {
        UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, XsltImportByName.class.getName(),
                "resolveByName", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
                "UIMAEE_exception__WARNING", new Object[] { e });
View Full Code Here


public class XsltImportByName {
 
  public static String resolveByName(String input) {
    ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager();
    Import theImport = new Import_impl();
    theImport.setName(input);
    try {
      return theImport.findAbsoluteUrl(resourceManager).toExternalForm();
    } catch (InvalidXMLException e) {
      e.printStackTrace();
      return "ERROR converting import by name to absolute path";
    }
  }
View Full Code Here

  {
      XMLInputSource input;
     
      if (aFileResource.startsWith(IMPORT_BY_NAME_PREFIX))
      {
        Import theImport = new Import_impl();
        theImport.setName(aFileResource.substring(IMPORT_BY_NAME_PREFIX.length()));
        input = new XMLInputSource(theImport.findAbsoluteUrl(aResourceManager));
      }
      else
      {
        input = new XMLInputSource(aFileResource);
      }
View Full Code Here

            .parseTypeSystemDescription(new XMLInputSource(defaultTypeSystemFile));
    CAS cas = CasCreationUtils.createCas(initialTypeSystem, null, new FsIndexDescription[0]);
    fillTypeNameMap(typeNameMap, cas.getTypeSystem());
    cas.release();
    List<Import> importList = new ArrayList<Import>();
    Import_impl import_impl = new Import_impl();
    if (option.isImportByName()) {
      String name = initialTypeSystem.getName();
      import_impl.setName(name);
    } else if (option.isResolveImports()) {
      String absoluteLocation = initialTypeSystem.getSourceUrlString();
      import_impl.setLocation(absoluteLocation);
    } else {
      String relativeLocation = getRelativeLocation(defaultTypeSystemFile.getAbsolutePath(),
              typeSystemOutput);
      import_impl.setLocation(relativeLocation);
    }
    importList.add(import_impl);
    for (String eachName : desc.getImportedTypeSystems()) {
      String locate = RutaEngine.locate(eachName, enginePaths, ".xml");
      if(locate == null) {
        throw new FileNotFoundException("Build process can't find " + eachName + " in "
                + mainScript);
      }
      File file = new File(locate);
      TypeSystemDescription each = getTypeSystemDescriptor(file, option);
      if (each != null) {
        fillTypeNameMap(typeNameMap, each);
        import_impl = new Import_impl();
        if (option.isImportByName()) {
          import_impl.setName(eachName);
        } else if (option.isResolveImports()) {
          String absoluteLocation = each.getSourceUrlString();
          import_impl.setLocation(absoluteLocation);
        } else {
          String relativeLocation = getRelativeLocation(file.getAbsolutePath(), typeSystemOutput);
          import_impl.setLocation(relativeLocation);
        }
        importList.add(import_impl);
      } else {
        throw new FileNotFoundException("Build process can't find " + eachName + " in "
                + mainScript);
      }
    }
    for (String eachName : desc.getImportedScripts()) {
      String locate = RutaEngine.locate(eachName, enginePaths, "TypeSystem.xml");
      File file = new File(locate);
      TypeSystemDescription each = getTypeSystemDescriptor(file, option);
      if (each != null) {
        fillTypeNameMap(typeNameMap, each);
        import_impl = new Import_impl();
        if (option.isImportByName()) {
          import_impl.setName(eachName + "TypeSystem");
        } else if (option.isResolveImports()) {
          String absoluteLocation = each.getSourceUrlString();
          import_impl.setLocation(absoluteLocation);
        } else {
          String relativeLocation = getRelativeLocation(file.getAbsolutePath(), typeSystemOutput);
          import_impl.setLocation(relativeLocation);
        }
        importList.add(import_impl);
      } else {
        throw new FileNotFoundException("Build process can't find " + eachName + " in "
                + mainScript);
      }
    }

    Import[] newImports = importList.toArray(new Import[0]);
    typeSystemDescription.setImports(newImports);
    if (option.isResolveImports()) {
      try {
        typeSystemDescription.resolveImports(rm);
      } catch (InvalidXMLException e) {
        throw new RutaBuildException("Failed to resolve imported Type Systems", e);
      }
    }

    // TODO hotfixes: where do I get the final types??
    Set<String> finalTypes = new HashSet<String>();
    finalTypes.addAll(Arrays.asList(new String[] { "uima.cas.Boolean", "uima.cas.Byte",
        "uima.cas.Short", "uima.cas.Integer", "uima.cas.Long", "uima.cas.Float", "uima.cas.Double",
        "uima.cas.BooleanArray", "uima.cas.ByteArray", "uima.cas.ShortArray",
        "uima.cas.IntegerArray", "uima.cas.LongArray", "uima.cas.FloatArray",
        "uima.cas.DoubleArray", "uima.cas.StringArray", "uima.cas.FSArray" }));

    int typeIndex = 0;
    for (String eachType : desc.getTypeShortNames()) {
      StringTriple typeTriple = desc.getTypeTriples().get(typeIndex);
      typeTriple = resolveType(typeTriple, typeNameMap, mainScript);
      if (typeSystemDescription.getType(typeTriple.getName()) != null) {
        continue;
      }
      if (!finalTypes.contains(typeTriple.getParent())) {
        TypeDescription newType = typeSystemDescription.addType(typeTriple.getName(),
                typeTriple.getDescription(), typeTriple.getParent());
        capability.addInputType(typeTriple.getName(), false);
        capability.addOutputType(typeTriple.getName(), false);
        Collection<StringTriple> collection = desc.getFeatures().get(eachType);
        if (collection != null) {
          for (StringTriple eachFeature : collection) {
            eachFeature = resolveFeature(eachFeature, typeNameMap);
            newType.addFeature(eachFeature.getName(), eachFeature.getDescription(),
                    eachFeature.getParent());
            // capability.addInputFeature(eachFeature.getName());
            // capability.addOutputFeature(eachFeature.getName());
          }
        }
      }
      typeIndex++;
    }

    Set<String> names = new HashSet<String>();
    List<TypeDescription> types = new ArrayList<TypeDescription>();
    for (TypeDescription each : typeSystemDescription.getTypes()) {
      String name = each.getName();
      if (!names.contains(name)) {
        names.add(name);
        types.add(each);
      }
    }

    typeSystemDescription.setTypes(types.toArray(new TypeDescription[0]));
    File typeSystemFile = getFile(typeSystemOutput);
    typeSystemDescription.setName(mainScript + "TypeSystem");
    typeSystemDescription.setSourceUrl(typeSystemFile.toURI().toURL());
    TypeSystemDescription aets = uimaFactory.createTypeSystemDescription();
    import_impl = new Import_impl();
    if (option.isImportByName()) {
      import_impl.setName(typeSystemDescription.getName());
    } else {
      String relativeLocation = getRelativeLocation(engineOutput, typeSystemOutput);
      import_impl.setLocation(relativeLocation);
    }

    File engineFile = configureEngine(desc, engineOutput, option, mainScript, scriptPaths,
            enginePaths, capability, import_impl, aets);
View Full Code Here

    List<Import> imports = new ArrayList<Import>();
    boolean contextDelta = false;
    for (String descriptorLocation : ds.getIncludedFiles()) {
      File descriptorFile = new File(ds.getBasedir(), descriptorLocation);
      this.getLog().info("JCasGen: Found descriptor '" + descriptorFile.getAbsolutePath() + "'");
      Import imp = new Import_impl();
      // setLocation takes a string which must be a URL
      // https://issues.apache.org/jira/browse/UIMA-2983
      URL url;
      try {
        url = descriptorFile.toURI().toURL();
      } catch (MalformedURLException e) {
        throw new RuntimeException(e); // this should never happen for files
      }
      imp.setLocation(url.toString());
      imports.add(imp);

      contextDelta |= this.buildContext.hasDelta(new File(ds.getBasedir(), descriptorLocation));
    }
    Import[] importArray = new Import[imports.size()];
View Full Code Here

  public void testDelegateImports() throws Exception {
    // create aggregate TAE description and add delegate AE import
    AnalysisEngineDescription_impl testAgg = new AnalysisEngineDescription_impl();
    Map delegateMap = testAgg.getDelegateAnalysisEngineSpecifiersWithImports();
    Import_impl delegateImport = new Import_impl();
    delegateImport.setLocation(JUnitExtension.getFile(
            "TextAnalysisEngineImplTest/TestPrimitiveTae1.xml").toURL().toString());
    delegateMap.put("key", delegateImport);

    // test that import is resolved
    Map mapWithImportsResolved = testAgg.getDelegateAnalysisEngineSpecifiers();
View Full Code Here

  public void testDelegateImports() throws Exception {
    // create aggregate TAE description and add delegate AE import
    AnalysisEngineDescription_impl testAgg = new AnalysisEngineDescription_impl();
    Map delegateMap = testAgg.getDelegateAnalysisEngineSpecifiersWithImports();
    Import_impl delegateImport = new Import_impl();
    delegateImport.setLocation(JUnitExtension.getFile(
            "TextAnalysisEngineImplTest/TestPrimitiveTae1.xml").toURL().toString());
    delegateMap.put("key", delegateImport);

    // test that import is resolved
    Map mapWithImportsResolved = testAgg.getDelegateAnalysisEngineSpecifiers();
View Full Code Here

    if (sDescriptorRelativePath.indexOf("file:/") == -1 //$NON-NLS-1$
            && sDescriptorRelativePath.indexOf(":/") > -1) { //$NON-NLS-1$
      sDescriptorRelativePath = "file:/" + sDescriptorRelativePath; //$NON-NLS-1$
    }

    Import imp = new Import_impl();
    // fails on unix? URL url = new URL("file:/" + getDescriptorDirectory());
    // Set relative Path Base
    // a version that might work on all platforms
    URL url = new File(editor.getDescriptorDirectory()).toURL();
    ((Import_impl) imp).setSourceUrl(url);

    imp.setLocation(sDescriptorRelativePath);
    return imp;
  }
View Full Code Here

   * @throws InvalidXMLException
   *           if the input XML is not valid or does not specify a valid {@link ResourceSpecifier}
   */
  public static AnalysisEngineDescription createEngineDescription(String descriptorName,
          Object... configurationData) throws InvalidXMLException, IOException {
    Import_impl imprt = new Import_impl();
    imprt.setName(descriptorName);
    URL url = imprt.findAbsoluteUrl(UIMAFramework.newDefaultResourceManager());
    ResourceSpecifier specifier = ResourceCreationSpecifierFactory.createResourceCreationSpecifier(
            url, configurationData);
    return (AnalysisEngineDescription) specifier;
  }
View Full Code Here

   */
  public static TypeSystemDescription createTypeSystemDescription(String... descriptorNames) {
    TypeSystemDescription typeSystem = new TypeSystemDescription_impl();
    List<Import> imports = new ArrayList<Import>();
    for (String descriptorName : descriptorNames) {
      Import imp = new Import_impl();
      imp.setName(descriptorName);
      imports.add(imp);
    }
    Import[] importArray = new Import[imports.size()];
    typeSystem.setImports(imports.toArray(importArray));
    return typeSystem;
View Full Code Here

TOP

Related Classes of org.apache.uima.resource.metadata.impl.Import_impl

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.