use of eu.esdihumboldt.commons.goml.align.Alignment 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);
}
use of eu.esdihumboldt.commons.goml.align.Alignment 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());
}
Aggregations