use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition in project hale by halestudio.
the class PopulationContainer method addToPopulation.
/**
* Add to Population
*
* @param instance an {@link Instance}
* @param entityDef an {@link EntityDefinition}
*/
public void addToPopulation(Instance instance, EntityDefinition entityDef) {
if (entityDef == null) {
TypeEntityDefinition def = getTypeEntity(instance.getDefinition(), SchemaSpaceID.SOURCE);
if (def.getFilter() == null || def.getFilter().match(instance)) {
increase(def, 1);
populationCount.addToPopulation(instance, def);
}
} else {
populationCount.countPopulation(entityDef, instance);
}
}
use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition in project hale by halestudio.
the class InlineTransformation method evaluate.
@Override
protected Object evaluate(String transformationIdentifier, TransformationEngine engine, ListMultimap<String, PropertyValue> variables, String resultName, PropertyEntityDefinition resultProperty, Map<String, String> executionParameters, TransformationLog log) throws TransformationException, NoResultException {
List<PropertyValue> sources = variables.get(null);
if (sources.isEmpty()) {
throw new NoResultException("No source available to transform");
}
PropertyValue source = sources.get(0);
Object sourceValue = source.getValue();
if (sourceValue == null) {
throw new NoResultException("Source value is null");
}
if (!(sourceValue instanceof Instance)) {
throw new TransformationException("Sources for inline transformation must be instances");
}
Instance sourceInstance = (Instance) sourceValue;
TypeDefinition sourceType = sourceInstance.getDefinition();
// get the original alignment
Alignment orgAlignment = getExecutionContext().getAlignment();
MutableAlignment alignment = new DefaultAlignment(orgAlignment);
// identify relevant type cell(s)
MutableCell queryCell = new DefaultCell();
ListMultimap<String, Type> sourceEntities = ArrayListMultimap.create();
sourceEntities.put(null, new DefaultType(new TypeEntityDefinition(sourceType, SchemaSpaceID.SOURCE, null)));
queryCell.setSource(sourceEntities);
ListMultimap<String, Type> targetEntities = ArrayListMultimap.create();
targetEntities.put(null, new DefaultType(new TypeEntityDefinition(resultProperty.getDefinition().getPropertyType(), SchemaSpaceID.TARGET, null)));
queryCell.setTarget(targetEntities);
Collection<? extends Cell> candidates = alignment.getTypeCells(queryCell);
if (candidates.isEmpty()) {
log.error(log.createMessage("No type transformations found for inline transformation", null));
throw new NoResultException();
}
// filter alignment -> only keep relevant type relations
List<Cell> allTypeCells = new ArrayList<>(alignment.getTypeCells());
for (Cell cell : allTypeCells) {
// remove cell
alignment.removeCell(cell);
if (!cell.getTransformationMode().equals(TransformationMode.disabled)) {
// only readd if not disabled
MutableCell copy = new DefaultCell(cell);
if (candidates.contains(cell)) {
// readd as active
copy.setTransformationMode(TransformationMode.active);
} else {
// readd as passive
copy.setTransformationMode(TransformationMode.passive);
}
alignment.addCell(copy);
}
}
// prepare transformation input/output
DefaultInstanceCollection sourceInstances = new DefaultInstanceCollection();
sourceInstances.add(sourceInstance);
DefaultInstanceSink target = new DefaultInstanceSink();
// run transformation
TransformationService ts = getExecutionContext().getService(TransformationService.class);
if (ts == null) {
throw new TransformationException("Transformation service not available for inline transformation");
}
ProgressIndicator progressIndicator = new LogProgressIndicator();
TransformationReport report = ts.transform(alignment, sourceInstances, new ThreadSafeInstanceSink<InstanceSink>(target), getExecutionContext(), progressIndicator);
// copy report messages
log.importMessages(report);
if (!report.isSuccess()) {
// copy report messages
log.importMessages(report);
throw new TransformationException("Inline transformation failed");
}
// extract result
List<Instance> targetList = target.getInstances();
if (targetList.isEmpty()) {
log.error(log.createMessage("Inline transformation yielded no result", null));
throw new NoResultException("No result from inline transformation");
}
if (targetList.size() > 1) {
log.error(log.createMessage("Inline transformation yielded multiple results, only first result is used", null));
}
return targetList.get(0);
}
use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition in project hale by halestudio.
the class SourceTargetTypeSelector method getSelectedCell.
/**
* Returns the selected cell. If no cell is selected a dummy cell with the
* selected source and target is returned. Both source and target may or may
* not be empty in that case.
*
* @return the selected cell (or a dummy)
*/
public Cell getSelectedCell() {
if (selectedCell != null)
return selectedCell;
DefaultCell cell = new DefaultCell();
if (sourceTypeSelector.getSelectedObject() != null) {
ListMultimap<String, Type> sources = ArrayListMultimap.create(1, 1);
sources.put(null, new DefaultType((TypeEntityDefinition) sourceTypeSelector.getSelectedObject()));
cell.setSource(sources);
}
if (targetTypeSelector.getSelectedObject() != null) {
ListMultimap<String, Type> targets = ArrayListMultimap.create(1, 1);
targets.put(null, new DefaultType((TypeEntityDefinition) targetTypeSelector.getSelectedObject()));
cell.setTarget(targets);
}
return cell;
}
use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition in project hale by halestudio.
the class TypeEntityDialog method setupViewer.
/**
* @see EntityDialog#setupViewer(TreeViewer, EntityDefinition)
*/
@Override
protected void setupViewer(TreeViewer viewer, EntityDefinition initialSelection) {
viewer.setLabelProvider(new StyledDefinitionLabelProvider(viewer));
EntityDefinitionService entityDefinitionService = PlatformUI.getWorkbench().getService(EntityDefinitionService.class);
flatRelevantProvider = new TreePathProviderAdapter(new EntityTypeIndexContentProvider(entityDefinitionService, ssid, true, true));
if (!onlyMappingRelevant) {
hierarchicalRelevantProvider = new TreePathProviderAdapter(new EntityTypeIndexHierarchy(entityDefinitionService, ssid, true, true));
flatAllProvider = new TreePathProviderAdapter(new EntityTypeIndexContentProvider(entityDefinitionService, ssid, false, true));
hierarchicalAllProvider = new TreePathProviderAdapter(new EntityTypeIndexHierarchy(entityDefinitionService, ssid, false, true));
viewer.setContentProvider(flatAllProvider);
} else {
viewer.setContentProvider(flatRelevantProvider);
}
SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
viewer.setInput(ss.getSchemas(ssid));
if (initialSelection instanceof TypeEntityDefinition) {
viewer.setSelection(new StructuredSelection(initialSelection));
}
}
use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition in project hale by halestudio.
the class TypeEntitySelector method createFilters.
private static ViewerFilter[] createFilters(TypeParameterDefinition field) {
if (field == null) {
return null;
}
List<TypeCondition> conditions = field.getConditions();
if (conditions == null)
return new ViewerFilter[0];
ViewerFilter[] filters = new ViewerFilter[conditions.size()];
int i = 0;
for (final TypeCondition condition : conditions) {
filters[i] = new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof TypeEntityDefinition) {
Type property = new DefaultType((TypeEntityDefinition) element);
return condition.accept(property);
} else
return false;
}
};
}
return filters;
}
Aggregations