Search in sources :

Example 1 with HaleAlignment

use of com.onespatial.jrc.tns.oml_to_rif.HaleAlignment in project hale by halestudio.

the class AlignmentToModelAlignmentDigester method translate.

/**
 * Translates a {@link HaleAlignment} into an intermediate
 * {@link ModelAlignment} format.
 *
 * @param hal the HALE alignment
 * @return {@link ModelAlignment}
 * @throws TranslationException
 *             if any problems occurred during translation
 */
@Override
public ModelAlignment translate(HaleAlignment hal) throws TranslationException {
    List<ModelClassMappingCell> classMappings = new ArrayList<ModelClassMappingCell>();
    List<ModelAttributeMappingCell> attributeMappings = new ArrayList<ModelAttributeMappingCell>();
    ArrayList<ModelStaticAssignmentCell> staticAssigments = new ArrayList<ModelStaticAssignmentCell>();
    Alignment source = hal.getAlignment();
    Map<String, SchemaElement> sourceFeatures = hal.getSourceElements();
    Map<String, SchemaElement> targetFeatures = hal.getTargetElements();
    for (ICell cell : source.getMap()) {
        IEntity sourceEntity = cell.getEntity1();
        IEntity targetEntity = cell.getEntity2();
        boolean sourceIsFeatureClass = sourceEntity instanceof FeatureClass;
        boolean targetIsFeatureClass = targetEntity instanceof FeatureClass;
        if (sourceIsFeatureClass && targetIsFeatureClass) {
            // type mapping
            classMappings.add(createCell((FeatureClass) sourceEntity, (FeatureClass) targetEntity, sourceFeatures, targetFeatures));
        } else if (!sourceIsFeatureClass && !targetIsFeatureClass) {
            // property mapping
            ModelAttributeMappingCell modelCell = createAttribute(cell, (Property) sourceEntity, (Property) targetEntity, sourceFeatures, targetFeatures);
            if (modelCell != null) {
                attributeMappings.add(modelCell);
            }
        } else if (sourceIsFeatureClass && !targetIsFeatureClass) {
            // augmentations
            ModelStaticAssignmentCell modelCell = createStaticAssignment(cell, (Property) targetEntity, targetFeatures);
            if (modelCell != null) {
                staticAssigments.add(modelCell);
            }
        } else {
            // $NON-NLS-1$
            throw new TranslationException("Unhandled combination");
        }
    }
    return new ModelAlignment(classMappings, attributeMappings, staticAssigments);
}
Also used : ModelClassMappingCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelClassMappingCell) IEntity(eu.esdihumboldt.specification.cst.align.IEntity) ModelStaticAssignmentCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelStaticAssignmentCell) ArrayList(java.util.ArrayList) ModelAlignment(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAlignment) TranslationException(com.onespatial.jrc.tns.oml_to_rif.api.TranslationException) FeatureClass(eu.esdihumboldt.commons.goml.omwg.FeatureClass) ICell(eu.esdihumboldt.specification.cst.align.ICell) ModelAlignment(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAlignment) Alignment(eu.esdihumboldt.commons.goml.align.Alignment) HaleAlignment(com.onespatial.jrc.tns.oml_to_rif.HaleAlignment) ModelAttributeMappingCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell) SchemaElement(eu.esdihumboldt.hale.schemaprovider.model.SchemaElement) Property(eu.esdihumboldt.commons.goml.omwg.Property) ComposedProperty(eu.esdihumboldt.commons.goml.omwg.ComposedProperty)

Example 2 with HaleAlignment

use of com.onespatial.jrc.tns.oml_to_rif.HaleAlignment in project hale by halestudio.

the class UrlToAlignmentDigester method translate.

/**
 * Translates an {@link URL} into a HALE {@link Alignment}.
 *
 * @param source
 *            {@link URL} the source URL
 * @return {@link Alignment}
 * @throws TranslationException
 *             if anything goes wrong during the translation
 */
@Override
public HaleAlignment translate(URL source) throws TranslationException {
    if (source == null) {
        // $NON-NLS-1$
        throw new TranslationException("url is null");
    }
    Alignment al = new OmlRdfReader().read(source);
    ApacheSchemaProvider sp = new ApacheSchemaProvider();
    Schema s, t;
    try {
        URI suri = new URI(al.getSchema1().getLocation());
        // if (!suri.isAbsolute()) {
        // suri = source.toURI();
        // suri = new URI(suri.getScheme(), suri.getUserInfo(),
        // suri.getHost(), suri.getPort(),
        // al.getSchema1().getLocation(), null, null);
        // }
        s = sp.loadSchema(suri, null);
        t = sp.loadSchema(new URI(al.getSchema2().getLocation()), null);
    } catch (Exception e) {
        // $NON-NLS-1$
        throw new TranslationException("Error loading schemas", e);
    }
    return new HaleAlignment(al, s.getElements().values(), t.getElements().values());
}
Also used : HaleAlignment(com.onespatial.jrc.tns.oml_to_rif.HaleAlignment) Alignment(eu.esdihumboldt.commons.goml.align.Alignment) HaleAlignment(com.onespatial.jrc.tns.oml_to_rif.HaleAlignment) Schema(eu.esdihumboldt.hale.schemaprovider.Schema) ApacheSchemaProvider(eu.esdihumboldt.hale.schemaprovider.provider.ApacheSchemaProvider) TranslationException(com.onespatial.jrc.tns.oml_to_rif.api.TranslationException) OmlRdfReader(eu.esdihumboldt.commons.goml.oml.io.OmlRdfReader) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) TranslationException(com.onespatial.jrc.tns.oml_to_rif.api.TranslationException)

Example 3 with HaleAlignment

use of com.onespatial.jrc.tns.oml_to_rif.HaleAlignment in project hale by halestudio.

the class RifMappingExportProvider method export.

/**
 * @see MappingExportProvider#export(Alignment, String, Collection, Collection)
 */
@Override
public MappingExportReport export(Alignment al, String path, Collection<SchemaElement> sourceSchema, Collection<SchemaElement> targetSchema) throws MappingExportException {
    MappingExportReport report = new MappingExportReport();
    try {
        HaleAlignment hal = new HaleAlignment(al, sourceSchema, targetSchema);
        Document document = AlignmentToRifTranslator.getInstance(report).translate(hal);
        DOMSource source = new DOMSource(document);
        File newFile = new File(path);
        OutputStream stream = new FileOutputStream(newFile);
        StreamResult result = new StreamResult(stream);
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = tFactory.newTransformer();
        // $NON-NLS-1$
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        // $NON-NLS-1$ //$NON-NLS-2$
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        transformer.transform(source, result);
    } catch (TranslationException e) {
        throw new MappingExportException(e.getMessage(), e);
    } catch (FileNotFoundException e) {
        throw new MappingExportException(e.getMessage(), e);
    } catch (TransformerException e) {
        throw new MappingExportException(e.getMessage(), e);
    }
    return report;
}
Also used : HaleAlignment(com.onespatial.jrc.tns.oml_to_rif.HaleAlignment) DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) TranslationException(com.onespatial.jrc.tns.oml_to_rif.api.TranslationException) Document(org.w3c.dom.Document) MappingExportReport(eu.esdihumboldt.hale.ui.io.legacy.mappingexport.MappingExportReport) MappingExportException(eu.esdihumboldt.hale.ui.io.legacy.mappingexport.MappingExportException) FileOutputStream(java.io.FileOutputStream) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

Aggregations

HaleAlignment (com.onespatial.jrc.tns.oml_to_rif.HaleAlignment)3 TranslationException (com.onespatial.jrc.tns.oml_to_rif.api.TranslationException)3 Alignment (eu.esdihumboldt.commons.goml.align.Alignment)2 ModelAlignment (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAlignment)1 ModelAttributeMappingCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell)1 ModelClassMappingCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelClassMappingCell)1 ModelStaticAssignmentCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelStaticAssignmentCell)1 OmlRdfReader (eu.esdihumboldt.commons.goml.oml.io.OmlRdfReader)1 ComposedProperty (eu.esdihumboldt.commons.goml.omwg.ComposedProperty)1 FeatureClass (eu.esdihumboldt.commons.goml.omwg.FeatureClass)1 Property (eu.esdihumboldt.commons.goml.omwg.Property)1 Schema (eu.esdihumboldt.hale.schemaprovider.Schema)1 SchemaElement (eu.esdihumboldt.hale.schemaprovider.model.SchemaElement)1 ApacheSchemaProvider (eu.esdihumboldt.hale.schemaprovider.provider.ApacheSchemaProvider)1 MappingExportException (eu.esdihumboldt.hale.ui.io.legacy.mappingexport.MappingExportException)1 MappingExportReport (eu.esdihumboldt.hale.ui.io.legacy.mappingexport.MappingExportReport)1 ICell (eu.esdihumboldt.specification.cst.align.ICell)1 IEntity (eu.esdihumboldt.specification.cst.align.IEntity)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1