Search in sources :

Example 36 with Entity

use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.

the class PropertiesLabelProvider method getImage.

/**
 * @see LabelProvider#getImage(Object)
 */
@Override
public Image getImage(Object element) {
    if (element instanceof IStructuredSelection) {
        element = ((IStructuredSelection) element).getFirstElement();
    }
    element = TransformationTreeUtil.extractObject(element);
    if (element instanceof Entity) {
        element = ((Entity) element).getDefinition();
    }
    if (element instanceof EntityDefinition || element instanceof Definition<?>) {
        return definitionLabels.getImage(element);
    }
    if (element instanceof Cell) {
        Cell cell = (Cell) element;
        FunctionDefinition<?> function = FunctionUtil.getFunction(cell.getTransformationIdentifier(), HaleUI.getServiceProvider());
        if (function != null) {
            element = function;
        }
    }
    if (element instanceof FunctionDefinition) {
        return functionLabels.getImage(element);
    }
    return super.getImage(element);
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) FunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 37 with Entity

use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.

the class FormattedStringHandler method getSourceExpressionAsCQL.

/**
 * @see eu.esdihumboldt.hale.io.appschema.writer.internal.AbstractPropertyTransformationHandler#getSourceExpressionAsCQL()
 */
@Override
protected String getSourceExpressionAsCQL() {
    ListMultimap<String, ParameterValue> parameters = propertyCell.getTransformationParameters();
    String pattern = parameters.get(PARAMETER_PATTERN).get(0).as(String.class);
    List<int[]> startEndList = new ArrayList<int[]>();
    List<String> varList = new ArrayList<String>();
    Matcher m = VARIABLE_PATTERN.matcher(pattern);
    while (m.find()) {
        int[] startEnd = new int[2];
        // index of '{' character
        startEnd[0] = m.start();
        // index of '}' character
        startEnd[1] = m.end();
        startEndList.add(startEnd);
        // the variable name, without curly braces
        varList.add(m.group(1));
    }
    // list of string to be concatenated, either string constants or
    // variable names
    String[] partsToConcat = new String[varList.size() * 2 + 1];
    int lastPos = 0;
    for (int i = 0; i < varList.size(); i++) {
        int[] startEnd = startEndList.get(i);
        String var = varList.get(i);
        String textBeforeVar = pattern.substring(lastPos, startEnd[0]);
        if (textBeforeVar != null && textBeforeVar.length() == 0) {
            textBeforeVar = null;
        }
        partsToConcat[i * 2] = (textBeforeVar != null) ? "'" + textBeforeVar + "'" : null;
        partsToConcat[i * 2 + 1] = var;
        lastPos = startEnd[1];
    }
    // add text after last variable
    String textAfterLastVar = pattern.substring(lastPos, pattern.length());
    if (textAfterLastVar != null && textAfterLastVar.length() == 0) {
        textAfterLastVar = null;
    }
    partsToConcat[partsToConcat.length - 1] = (textAfterLastVar != null) ? "'" + textAfterLastVar + "'" : null;
    String strConcatExpr = "";
    int lastPartIdx = 0;
    while (lastPartIdx < partsToConcat.length) {
        if (lastPartIdx == 0) {
            // initialize strConcatExpr
            for (int notNullIdx = lastPartIdx; notNullIdx < partsToConcat.length; notNullIdx++) {
                if (partsToConcat[notNullIdx] != null) {
                    strConcatExpr = partsToConcat[notNullIdx];
                    lastPartIdx = notNullIdx;
                    break;
                }
            }
        }
        String secondArgument = null;
        for (int notNullIdx = lastPartIdx + 1; notNullIdx < partsToConcat.length; notNullIdx++) {
            if (partsToConcat[notNullIdx] != null) {
                secondArgument = partsToConcat[notNullIdx];
                lastPartIdx = notNullIdx;
                break;
            }
        }
        if (secondArgument != null) {
            strConcatExpr = "strConcat(" + strConcatExpr + ", " + secondArgument + ")";
        } else {
            // no second argument could be found: should stop here
            break;
        }
    }
    // expression should be evaluated only if all conditions are met
    if (propertyCell.getSource() != null) {
        List<? extends Entity> sourceEntities = propertyCell.getSource().get(FormattedStringFunction.ENTITY_VARIABLE);
        if (sourceEntities != null) {
            for (Entity source : sourceEntities) {
                PropertyEntityDefinition propEntityDef = (PropertyEntityDefinition) source.getDefinition();
                strConcatExpr = getConditionalExpression(propEntityDef, strConcatExpr);
            }
        }
    }
    return strConcatExpr;
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) FormattedString(eu.esdihumboldt.cst.functions.core.FormattedString) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)

Example 38 with Entity

use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.

the class MathematicalExpressionHandler method getSourceExpressionAsCQL.

/**
 * @see eu.esdihumboldt.hale.io.appschema.writer.internal.AbstractPropertyTransformationHandler#getSourceExpressionAsCQL()
 */
@Override
protected String getSourceExpressionAsCQL() {
    // TODO: verify math expressions work as-is in CQL
    String mathExpression = propertyCell.getTransformationParameters().get(PARAMETER_EXPRESSION).get(0).getStringRepresentation();
    // expression should be evaluated only if all conditions are met
    if (propertyCell.getSource() != null) {
        List<? extends Entity> sourceEntities = propertyCell.getSource().get(MathematicalExpression.ENTITY_VARIABLE);
        if (sourceEntities != null) {
            for (Entity source : sourceEntities) {
                PropertyEntityDefinition propEntityDef = (PropertyEntityDefinition) source.getDefinition();
                mathExpression = getConditionalExpression(propEntityDef, mathExpression);
            }
        }
    }
    return mathExpression;
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)

Example 39 with Entity

use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.

the class DefaultsVisitor method addDefaultCell.

/**
 * Add a cell assigning a default value to the given entity.
 *
 * @param ped the property entity definition
 * @param value the value to assign or <code>null</code> if it should be
 *            auto-detected
 */
private void addDefaultCell(PropertyEntityDefinition ped, String value) {
    String note;
    // determine value to assign
    if (value == null) {
        value = determineDefaultValue(ped.getDefinition().getPropertyType());
        note = "Generated default value based on property type.";
    } else {
        note = "Generated cell with specified default value.";
    }
    if (value == null) {
        return;
    }
    // create cell template
    MutableCell cell = new DefaultCell();
    cell.setPriority(Priority.LOWEST);
    ListMultimap<String, Entity> target = ArrayListMultimap.create();
    cell.setTarget(target);
    ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
    cell.setTransformationParameters(parameters);
    // set transformation identifier (Assign)
    cell.setTransformationIdentifier(AssignFunction.ID);
    // set cell target (Property)
    target.put(null, new DefaultProperty(ped));
    // set cell parameters (Value)
    parameters.put(AssignFunction.PARAMETER_VALUE, new ParameterValue(value));
    BGISAppUtil.appendNote(cell, note);
    cells.add(cell);
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)

Example 40 with Entity

use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.

the class CityGMLPropagateVisitor method findSourceTypes.

/**
 * Find source types to use to propagate the given example cell. If
 * possible, common super types will be returned.
 *
 * @param exampleCell the example cell
 * @param targetType the target type
 * @param index the index to store the replacement property paths in
 * @return the source types to propagate the cell to
 */
private Collection<TypeDefinition> findSourceTypes(Cell exampleCell, TypeDefinition targetType, TypeEntityIndex<List<ChildContext>> index) {
    Set<TypeDefinition> possibleSources = findAllPossibleSources(targetType);
    /*
		 * Add all super types, because if possible, we want to do the mapping
		 * on super types.
		 */
    Set<TypeDefinition> superTypes = new HashSet<TypeDefinition>();
    for (TypeDefinition type : possibleSources) {
        TypeDefinition superType = type.getSuperType();
        while (superType != null) {
            if (superTypes.add(superType) || !possibleSources.contains(superType)) {
                superType = superType.getSuperType();
            } else {
                superType = null;
            }
        }
    }
    possibleSources.addAll(superTypes);
    /*
		 * Check source entities and filter all source types that don't match
		 * the entity.
		 */
    TypeDefinition originalSource = null;
    for (Entity source : exampleCell.getSource().values()) {
        EntityDefinition ed = source.getDefinition();
        // check source type
        if (originalSource == null) {
            originalSource = ed.getType();
        } else {
            if (!originalSource.equals(ed.getType())) {
                System.err.println("WARNING: ignoring cell with sources in different types");
                return null;
            }
        }
        if (ed.getPropertyPath().isEmpty()) {
            // don't handle type cells
            return null;
        }
        // remove all types w/o compatible property
        Iterator<TypeDefinition> it = possibleSources.iterator();
        while (it.hasNext()) {
            TypeDefinition type = it.next();
            List<ChildContext> newPath = hasCompatibleProperty(type, ed.getPropertyPath());
            if (newPath == null) {
                it.remove();
            } else {
                // remember child path per root type and entity
                index.put(type, source, newPath);
            }
        }
    }
    /*
		 * Remove all types that have super types contained in the set.
		 */
    Set<TypeDefinition> toTest = new HashSet<TypeDefinition>(possibleSources);
    for (TypeDefinition type : toTest) {
        TypeDefinition superType = type.getSuperType();
        while (superType != null) {
            if (possibleSources.contains(superType)) {
                possibleSources.remove(type);
                // other super types are tested on their own
                break;
            }
            superType = superType.getSuperType();
        }
    }
    return possibleSources;
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) HashSet(java.util.HashSet)

Aggregations

Entity (eu.esdihumboldt.hale.common.align.model.Entity)64 Cell (eu.esdihumboldt.hale.common.align.model.Cell)25 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)21 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)14 ArrayList (java.util.ArrayList)12 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)9 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)9 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)9 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)9 List (java.util.List)9 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)8 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)7 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)6 HashSet (java.util.HashSet)6 Locale (java.util.Locale)6 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)5 FunctionDefinition (eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition)4 CellUtil (eu.esdihumboldt.hale.common.align.model.CellUtil)4 CellLog (eu.esdihumboldt.hale.common.align.model.annotations.messages.CellLog)4 AbstractCellExplanation (eu.esdihumboldt.hale.common.align.model.impl.AbstractCellExplanation)4