private String serializeTypeSystem(CAS aCas) throws RecommendationException { try (StringWriter out = new StringWriter()) { TypeSystemUtil.typeSystem2TypeSystemDescription(aCas.getTypeSystem()).toXML(out); return out.toString(); } catch (CASRuntimeException | SAXException | IOException e) { throw new RecommendationException("Coud not serialize type system", e); } }
private Set<String> getTypes(URL resource, ResourceManager resMgr) throws IOException, InvalidXMLException { Set<String> types = new HashSet<String>(); TypeSystemDescription typeSysDescr = null; typeSysDescr = UIMAFramework.getXMLParser().parseTypeSystemDescription( new XMLInputSource(resource)); typeSysDescr.resolveImports(resMgr); for (TypeDescription each : typeSysDescr.getTypes()) { String name = each.getName(); String[] nameSpace = name.split("[.]"); types.add(nameSpace[nameSpace.length - 1]); StringBuffer fullName = new StringBuffer(); if (nameSpace.length > 0) { fullName.append(nameSpace[0]); } for (int i = 1; i < nameSpace.length; i++) { // TODO fix workaround if (!nameSpace[i].equals("type")) { fullName.append('.'); fullName.append(nameSpace[i]); } } types.add(fullName.toString()); } return types; }
/** * Checks if is imported type. * * @param typeName the type name * @return true, if is imported type */ public boolean isImportedType(String typeName) { return null != editor.getImportedTypeSystemDesription().getType(typeName); }
/** * Sets the imported type system description. * * @throws ResourceInitializationException the resource initialization exception */ private void setImportedTypeSystemDescription() throws ResourceInitializationException { Collection tsdc = new ArrayList(1); TypeSystemDescription tsd = typeSystemDescription; if (null != tsd) { tsd = (TypeSystemDescription) tsd.clone(); tsd.setTypes(typeDescriptionArray0); } tsdc.clear(); tsdc.add(tsd); importedTypeSystemDescription = CasCreationUtils .mergeTypeSystems(tsdc, createResourceManager()); }
@Override protected void setModelImportArray(Import[] imports) { savedCAS = editor.getCurrentView(); Import[] oldImports = getTypeSystemDescription().getImports(); importWasRemoved = (null != oldImports) && (oldImports.length > imports.length); getTypeSystemDescription().setImports(imports); }
Import_impl import_impl = new Import_impl(); if (options.isImportByName()) { String name = initialTypeSystem.getName(); import_impl.setName(name); } else if (options.isResolveImports()) { String absoluteLocation = initialTypeSystem.getSourceUrlString(); import_impl.setLocation(absoluteLocation); } else { import_impl.setLocation(relativeLocation); } else { import_impl.setName(initialTypeSystem.getName()); each.resolveImports(rm); toInclude.add(each); } else { import_impl.setName(eachName); } else if (options.isResolveImports()) { String absoluteLocation = each.getSourceUrlString(); import_impl.setLocation(absoluteLocation); } else { import_impl.setName(eachName + options.getTypeSystemSuffix()); } else if (options.isResolveImports()) { String absoluteLocation = each.getSourceUrlString(); import_impl.setLocation(absoluteLocation); } else {
@Override public void exitImportDeclaration(ImportDeclarationContext ctx) { String value = ctx.Identifier().getText(); String filePath = value.replaceAll("\\.", "/") + ".xml"; try { typeSystemDescription = TypeSystemDescriptionFactory.createTypeSystemDescription(); typeSystemDescription.resolveImports(); } catch (Exception e) { throw new AutomataParsingException("Failed to load type system " + filePath, e); } }
@Override public void generateTypes(TypeSystemDescription aTsd, AnnotationLayer aLayer) { TypeDescription td = aTsd.addType(aLayer.getName(), "", CAS.TYPE_NAME_ANNOTATION_BASE); generateFeatures(aTsd, td, aLayer); }
.parse(xmlTypeSystemSource); typeSystemDesciptor.resolveImports(); typeSystemDesciptor.toXML(typeSystemBytes);
private boolean fillTypeNameMap(Map<String, String> typeNameMap, TypeSystemDescription desc) { boolean contained = false; for (TypeDescription each : desc.getTypes()) { String name = each.getName(); int lastIndexOf = name.lastIndexOf("."); String shortName = name.substring(lastIndexOf + 1, name.length()); typeNameMap.put(shortName, name); } return contained; }
public void addConceptType(String conceptName, Collection<String> featureNames, String superTypeName, HashMap<String, String> featureTypes) { conceptName = checkNameSpace(conceptName); superTypeName = DeterminantValueSet.checkNameSpace(superTypeName); if (typeSystemDescription.getType(conceptName) == null || !classLoaded(conceptName)) { typeSystemDescription.addType(conceptName, "an automatic generated concept type", superTypeName); if (featureNames != null && featureNames.size() > 0) { featureNames = filterFeatureNames(superTypeName, featureNames); TypeDescription type = typeSystemDescription.getType(conceptName); FeatureDescription[] aFeatures = new FeatureDescription[featureNames.size()]; int i = 0;
typeSystem.setImports(imports.toArray(importArray)); typeSystemFile.getParentFile().mkdirs(); typeSystemOs = new FileOutputStream(typeSystemFile); typeSystem.toXML(typeSystemOs); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e.getCause());
/** * Creates a TypeSystemDescription from descriptor names. * * @param descriptorNames * The fully qualified, Java-style, dotted descriptor names. * @return A TypeSystemDescription that includes the types from all of the specified files. */ 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; }
protected TypeSystemDescription mergeTypeSystemImports(TypeSystemDescription tsd) throws ResourceInitializationException { Collection tsdc = new ArrayList(1); tsdc.add(tsd.clone()); mergedTypesAddingFeatures.clear(); TypeSystemDescription mergedTsd = CasCreationUtils.mergeTypeSystems(tsdc, createResourceManager(), mergedTypesAddingFeatures); return mergedTsd; }
public static TypeSystemDescription createTypeSystemDescription(InputStream in) { // Note: // Type System location is not set correctly, // resolving a referenced type system will fail XMLInputSource xmlTypeSystemSource = new XMLInputSource(in, new File("")); XMLParser xmlParser = UIMAFramework.getXMLParser(); TypeSystemDescription typeSystemDesciptor; try { typeSystemDesciptor = (TypeSystemDescription) xmlParser .parse(xmlTypeSystemSource); typeSystemDesciptor.resolveImports(); } catch (InvalidXMLException e) { e.printStackTrace(); typeSystemDesciptor = null; } return typeSystemDesciptor; }
@Override public void generateTypes(TypeSystemDescription aTsd, AnnotationLayer aLayer) { TypeDescription td = aTsd.addType(aLayer.getName(), "", CAS.TYPE_NAME_ANNOTATION); generateFeatures(aTsd, td, aLayer); }
.parse(xmlTypeSystemSource); typeSystemDesciptor.resolveImports(); typeSystemDesciptor.toXML(typeSystemBytes);
public TreeSet<String> getImportedTypeNames() { TreeSet<String> typeNames = new TreeSet<>(); for (TypeDescription typeDescription : typeSystemDescription.getTypes()) { typeNames.add(typeDescription.getName()); } return typeNames; }