use of eu.esdihumboldt.hale.common.align.model.MutableCell in project hale by halestudio.
the class GenerateDefaults method generateMapping.
private void generateMapping() {
System.out.println("Generating default value mapping cells for");
// collect all ADE feature types
List<TypeDefinition> featureTypes = BGISAppUtil.getADEFeatureTypes(schema);
// visit ADE properties and create cells
DefaultsVisitor defs = new DefaultsVisitor(defaultValues);
for (TypeDefinition type : featureTypes) {
System.out.println(type.getDisplayName() + "...");
defs.accept(new TypeEntityDefinition(type, SchemaSpaceID.TARGET, null));
}
if (defs.getCells().isEmpty()) {
System.out.println("WARNING: no cells were created");
} else {
System.out.println(defs.getCells().size() + " cells were created.");
}
// create alignment
MutableAlignment align = new DefaultAlignment();
for (MutableCell cell : defs.getCells()) {
align.addCell(cell);
}
this.alignment = align;
}
use of eu.esdihumboldt.hale.common.align.model.MutableCell in project hale by halestudio.
the class GenerateDuplicates method generateMapping.
private void generateMapping() {
System.out.println("Indexing example cells...");
// index all cells based on the target property name
SetMultimap<String, Cell> exampleCells = HashMultimap.create();
for (Cell cell : examples.getCells()) {
if (cell.getTarget().size() == 1) {
// only supports cells with one target
EntityDefinition entityDef = CellUtil.getFirstEntity(cell.getTarget()).getDefinition();
if (entityDef.getDefinition() instanceof PropertyDefinition) {
if (ADE_NS.equals(entityDef.getDefinition().getName().getNamespaceURI())) {
exampleCells.put(entityDef.getDefinition().getName().getLocalPart(), cell);
} else
System.out.println("WARNING: ignoring cell with non-ADE target property");
} else
System.out.println("WARNING: ignoring type cell");
} else
System.out.println("WARNING: ignoring cell with multiple or no targets");
}
// collect all ADE feature types
List<TypeDefinition> featureTypes = BGISAppUtil.getADEFeatureTypes(targetSchema);
// visit ADE properties and create cells
System.out.println("Generating mapping from example cells for");
String cellNote = MessageFormat.format("Generated through duplication of example cells on BGIS ADE feature types.\n" + "{0,date,medium}", new Date());
DuplicateVisitor visitor = new DuplicateVisitor(exampleCells, cellNote);
for (TypeDefinition type : featureTypes) {
System.out.println(type.getDisplayName() + "...");
visitor.accept(new TypeEntityDefinition(type, SchemaSpaceID.TARGET, null));
}
if (visitor.getCells().isEmpty()) {
System.out.println("WARNING: no cells were created");
} else {
System.out.println(visitor.getCells().size() + " cells were created.");
}
// create alignment
MutableAlignment align = new DefaultAlignment();
for (MutableCell cell : visitor.getCells()) {
align.addCell(cell);
}
this.alignment = align;
}
use of eu.esdihumboldt.hale.common.align.model.MutableCell in project hale by halestudio.
the class DefaultAlignmentMigrator method updateAligmment.
@Override
public MutableAlignment updateAligmment(Alignment originalAlignment, AlignmentMigration migration, MigrationOptions options, SimpleLog log) {
MutableAlignment result = new DefaultAlignment(originalAlignment);
// XXX TODO adapt custom functions?!
// result.getCustomPropertyFunctions();
Collection<? extends Cell> cellList = new ArrayList<>(result.getCells());
for (Cell cell : cellList) {
// XXX
if (cell instanceof MutableCell) {
CellMigrator cm = getCellMigrator(cell.getTransformationIdentifier());
MutableCell newCell = cm.updateCell(cell, migration, options, log);
MigrationUtil.removeIdPrefix(newCell, options.transferBase(), options.transferBase());
result.removeCell(cell);
if (newCell != null) {
result.addCell(newCell);
}
} else {
// XXX can we deal with other cases? (Base alignment cells)
if (options.transferBase()) {
// include base alignment cell as mutable mapping cell
CellMigrator cm = getCellMigrator(cell.getTransformationIdentifier());
MutableCell newCell = cm.updateCell(cell, migration, options, log);
MigrationUtil.removeIdPrefix(newCell, true, true);
result.removeCell(cell);
if (newCell != null) {
result.addCell(newCell);
}
}
}
}
if (options.transferBase()) {
MigrationUtil.removeBaseCells(result);
} else {
// does something need to be done to correctly retain base
// alignments?
}
return result;
}
use of eu.esdihumboldt.hale.common.align.model.MutableCell in project hale by halestudio.
the class DefaultCellMigrator method updateCell.
@Override
public MutableCell updateCell(final Cell originalCell, final AlignmentMigration migration, final MigrationOptions options, SimpleLog log) {
MutableCell result = new DefaultCell(originalCell);
SimpleLog cellLog = SimpleLog.all(log, new CellLog(result, CELL_LOG_CATEGORY));
final AtomicBoolean replacedEntities = new AtomicBoolean(false);
EntryTransformer<String, Entity, Entity> entityTransformer = new EntryTransformer<String, Entity, Entity>() {
@Override
public Entity transformEntry(String key, Entity value) {
EntityDefinition org = value.getDefinition();
Optional<EntityDefinition> replace = migration.entityReplacement(org, cellLog);
EntityDefinition entity = replace.orElse(org);
if (!Objects.equal(entity, org)) {
replacedEntities.set(true);
}
if (entity instanceof PropertyEntityDefinition) {
return new DefaultProperty((PropertyEntityDefinition) entity);
} else if (entity instanceof TypeEntityDefinition) {
return new DefaultType((TypeEntityDefinition) entity);
} else {
throw new IllegalStateException("Invalid entity definition for creating entity");
}
}
};
// update source entities
if (options.updateSource() && result.getSource() != null && !result.getSource().isEmpty()) {
result.setSource(ArrayListMultimap.create(Multimaps.transformEntries(result.getSource(), entityTransformer)));
}
// update target entities
if (options.updateTarget() && result.getTarget() != null && !result.getTarget().isEmpty()) {
result.setTarget(ArrayListMultimap.create(Multimaps.transformEntries(result.getTarget(), entityTransformer)));
}
// TODO anything else?
postUpdateCell(result, options, replacedEntities.get(), cellLog);
return result;
}
use of eu.esdihumboldt.hale.common.align.model.MutableCell in project hale by halestudio.
the class EffectiveMapping method expand.
/**
* Convert an alignment into an expanded version where all effective
* mappings are defined explicitly, i.e. mappings effective due to
* inheritance are converted to use the respective sub-types. Also, base
* alignment cells are converted into normal cells.
*
* @param alignment the alignment to convert
* @return the expanded copy of the alignment
*/
public static MutableAlignment expand(Alignment alignment) {
MutableAlignment result = new DefaultAlignment(alignment);
// remove base alignment cells keeping custom functions
MigrationUtil.removeBaseCells(result);
// remove other cells
result.clearCells();
// transfer cells based on effective mapping
// set of all cells used as they are in the resulting alignment
Set<Cell> usedAsIs = new HashSet<>();
for (Cell typeCell : alignment.getTypeCells()) {
// transfer type cell unchanged
MutableCell typeCellNew = new DefaultCell(typeCell);
MigrationUtil.removeIdPrefix(typeCellNew, true, true);
result.addCell(typeCellNew);
usedAsIs.add(typeCell);
Collection<? extends Cell> propertyCells = alignment.getPropertyCells(typeCell, true, false);
for (Cell propertyCell : propertyCells) {
// FIXME what does this do in case of a join where there are
// potentially multiple cells to be handled?
Cell reparented = AlignmentUtil.reparentCell(propertyCell, typeCell, true);
if (reparented == propertyCell) {
// use as is
if (!usedAsIs.contains(propertyCell)) {
// only add if not done yet
// transfer unchanged
MutableCell newCell = new DefaultCell(propertyCell);
MigrationUtil.removeIdPrefix(newCell, true, true);
result.addCell(newCell);
usedAsIs.add(propertyCell);
}
} else {
// inherited cell
// add the reparented cell
// TODO check if similar cell has been added already?
MutableCell rCell = (MutableCell) reparented;
MigrationUtil.removeIdPrefix(rCell, true, true);
// avoid ID collision
// no updates needed in other places because it's a property
// cell
rCell.setId(rCell.getId() + '_' + typeCellNew.getId());
result.addCell(rCell);
}
}
}
return result;
}
Aggregations