Search in sources :

Example 11 with Entity

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

the class NetworkExpansionExplanation method getExplanation.

@Override
protected String getExplanation(Cell cell, boolean html, ServiceProvider services, Locale locale) {
    Entity target = CellUtil.getFirstEntity(cell.getTarget());
    String expression = CellUtil.getFirstParameter(cell, PARAMETER_BUFFER_WIDTH).as(String.class);
    List<? extends Entity> variables = cell.getSource().get(ENTITY_VARIABLE);
    List<? extends Entity> geom = cell.getSource().get(null);
    if (target != null && expression != null) {
        if (html)
            expression = "<pre>" + expression + "</pre>";
        String explanation = MessageFormat.format(getMessage("main", locale), formatEntity(geom.get(0), html, true, locale), formatEntity(target, html, true, locale), expression);
        if (html)
            explanation = explanation.replaceAll("\n", "<br />");
        if (html) {
            Map<String, String> varToProperty = variables.stream().collect(Collectors.toMap(entity -> {
                return getEntityNameWithoutCondition(entity);
            }, entity -> {
                return formatEntity(entity, true, false, locale);
            }));
            explanation += buildReplacementTable(varToProperty, locale);
        }
        return explanation;
    }
    return null;
}
Also used : List(java.util.List) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Locale(java.util.Locale) Map(java.util.Map) ServiceProvider(eu.esdihumboldt.hale.common.core.service.ServiceProvider) Entity(eu.esdihumboldt.hale.common.align.model.Entity) AbstractCellExplanation(eu.esdihumboldt.hale.common.align.model.impl.AbstractCellExplanation) Collectors(java.util.stream.Collectors) CellUtil(eu.esdihumboldt.hale.common.align.model.CellUtil) MessageFormat(java.text.MessageFormat) Entity(eu.esdihumboldt.hale.common.align.model.Entity)

Example 12 with Entity

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

the class GroovyExplanation method getExplanation.

@Override
protected String getExplanation(Cell cell, boolean html, ServiceProvider services, Locale locale) {
    Entity target = CellUtil.getFirstEntity(cell.getTarget());
    String script = getScript(cell);
    if (target != null && script != null) {
        if (html)
            script = "<pre><code class=\"language-groovy\">" + script + "</code></pre>";
        String pre = MessageFormat.format(getMessage("pre", locale), formatEntity(target, html, true, locale));
        String post = MessageFormat.format(getMessage("post", locale), formatEntity(target, html, true, locale));
        if (html) {
            pre = pre.replaceAll("\n", "<br />");
            pre = pre + "<br /><br />";
            post = post.replaceAll("\n", "<br />");
            post = "<br />" + post;
        } else {
            pre = pre + "\n\n";
            post = "\n\n" + post;
        }
        return pre + script + post;
    }
    return null;
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity)

Example 13 with Entity

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

the class GroovyGreedyTransformation method createGroovyBinding.

/**
 * Create a Groovy binding from the list of variables.
 *
 * @param vars the variable values
 * @param varDefs definition of the assigned variables, in case some
 *            variable values are not set, may be <code>null</code>
 * @param cell the cell the binding is created for
 * @param typeCell the type cell the binding is created for, may be
 *            <code>null</code>
 * @param builder the instance builder for creating target instances, or
 *            <code>null</code> if not applicable
 * @param useInstanceVariables if instances should be used as variables for
 *            the binding instead of extracting the instance values
 * @param log the transformation log
 * @param context the execution context
 * @param targetInstanceType the type of the target instance
 * @return the binding for use with {@link GroovyShell}
 */
public static Binding createGroovyBinding(List<PropertyValue> vars, List<? extends Entity> varDefs, Cell cell, Cell typeCell, InstanceBuilder builder, boolean useInstanceVariables, TransformationLog log, ExecutionContext context, TypeDefinition targetInstanceType) {
    Binding binding = GroovyUtil.createBinding(builder, cell, typeCell, log, context, targetInstanceType);
    // collect definitions to check if all were provided
    Set<EntityDefinition> notDefined = new HashSet<>();
    if (varDefs != null) {
        for (Entity entity : varDefs) {
            notDefined.add(entity.getDefinition());
        }
    }
    // keep only defs where no value is provided
    if (!notDefined.isEmpty()) {
        for (PropertyValue var : vars) {
            notDefined.remove(var.getProperty());
        }
    }
    // add empty lists to environment if necessary
    if (!notDefined.isEmpty()) {
        for (EntityDefinition entity : notDefined) {
            GroovyTransformation.addToBinding(binding, (PropertyEntityDefinition) entity, Collections.emptyList());
        }
    }
    Map<PropertyEntityDefinition, InstanceAccessorArrayList<Object>> bindingMap = new HashMap<>();
    // collect the values
    for (PropertyValue var : vars) {
        PropertyEntityDefinition property = var.getProperty();
        InstanceAccessorArrayList<Object> valueList = bindingMap.get(property);
        if (valueList == null) {
            valueList = new InstanceAccessorArrayList<>();
            bindingMap.put(property, valueList);
        }
        valueList.add(GroovyTransformation.getUseValue(var.getValue(), useInstanceVariables));
    }
    // add collected values to environment
    for (Entry<PropertyEntityDefinition, InstanceAccessorArrayList<Object>> entry : bindingMap.entrySet()) {
        GroovyTransformation.addToBinding(binding, entry.getKey(), entry.getValue());
    }
    return binding;
}
Also used : Binding(groovy.lang.Binding) Entity(eu.esdihumboldt.hale.common.align.model.Entity) HashMap(java.util.HashMap) PropertyValue(eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) InstanceAccessorArrayList(eu.esdihumboldt.cst.functions.groovy.internal.InstanceAccessorArrayList) HashSet(java.util.HashSet)

Example 14 with Entity

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

the class GeographicalNameExplanation method getExplanation.

@Override
protected String getExplanation(Cell cell, boolean html, ServiceProvider services, Locale locale) {
    // only one locale supported in this explanation (the function is
    // deprecated)
    Locale targetLocale = Locale.ENGLISH;
    Entity target = CellUtil.getFirstEntity(cell.getTarget());
    PropertyFunctionDefinition function = FunctionUtil.getPropertyFunction(ID, null);
    StringBuilder sb = new StringBuilder();
    sb.append("The {0} property is populated with an Inspire Geographical Name composed as follows:");
    addLineBreak(sb, html);
    addLineBreak(sb, html);
    // unique parameters
    if (html)
        sb.append("<ul>");
    addOptionalParameter(sb, cell, PROPERTY_NAMESTATUS, function, html);
    addOptionalParameter(sb, cell, PROPERTY_LANGUAGE, function, html);
    addOptionalParameter(sb, cell, PROPERTY_NATIVENESS, function, html);
    addOptionalParameter(sb, cell, PROPERTY_SOURCEOFNAME, function, html);
    addOptionalParameter(sb, cell, PROPERTY_PRONUNCIATIONIPA, function, html);
    addOptionalParameter(sb, cell, PROPERTY_PRONUNCIATIONSOUNDLINK, function, html);
    addOptionalParameter(sb, cell, PROPERTY_GRAMMA_GENDER, function, html);
    addOptionalParameter(sb, cell, PROPERTY_GRAMMA_NUMBER, function, html);
    if (html)
        sb.append("</ul>");
    addLineBreak(sb, html);
    // per source parameters
    List<? extends Entity> sources = cell.getSource().get(null);
    // PROPERTY_TEXT
    List<ParameterValue> scripts = cell.getTransformationParameters().get(PROPERTY_SCRIPT);
    List<ParameterValue> transs = cell.getTransformationParameters().get(PROPERTY_TRANSLITERATION);
    if (!sources.isEmpty()) {
        sb.append("For each source property a spelling is created, the spelling text is the value of the source property.");
        addLineBreak(sb, html);
        if (html) {
            sb.append("<table border=\"1\">");
            sb.append("<tr><th>Source property</th><th>Script</th><th>Transliteration</th></tr>");
        }
        int index = 0;
        for (Entity source : sources) {
            String script = (index < scripts.size()) ? (scripts.get(index).as(String.class)) : (null);
            String trans = (index < transs.size()) ? (transs.get(index).as(String.class)) : (null);
            if (html) {
                sb.append("<tr>");
                sb.append("<td>");
                sb.append(formatEntity(source, html, false, targetLocale));
                sb.append("</td>");
                sb.append("<td>");
                if (script != null) {
                    sb.append(script);
                }
                sb.append("</td>");
                sb.append("<td>");
                if (trans != null) {
                    sb.append(trans);
                }
                sb.append("</td>");
                sb.append("</tr>");
            } else {
                sb.append("Source: ");
                sb.append(formatEntity(source, html, false, targetLocale));
                addLineBreak(sb, html);
                if (script != null && !script.isEmpty()) {
                    sb.append("  Script: ");
                    sb.append(script);
                    addLineBreak(sb, html);
                }
                if (trans != null && !trans.isEmpty()) {
                    sb.append("  Transliteration: ");
                    sb.append(trans);
                    addLineBreak(sb, html);
                }
                addLineBreak(sb, html);
            }
            index++;
        }
        if (html) {
            sb.append("</table>");
        }
    }
    String result = sb.toString();
    if (target != null) {
        result = MessageFormat.format(result, formatEntity(target, html, true, targetLocale));
    }
    return result;
}
Also used : Locale(java.util.Locale) Entity(eu.esdihumboldt.hale.common.align.model.Entity) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) PropertyFunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.PropertyFunctionDefinition)

Example 15 with Entity

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

the class IdentifierExplanation method getExplanation.

@Override
protected String getExplanation(Cell cell, boolean html, ServiceProvider services, Locale locale) {
    // only one locale supported in this explanation (the function is
    // deprecated)
    Locale targetLocale = Locale.ENGLISH;
    Entity source = CellUtil.getFirstEntity(cell.getSource());
    Entity target = CellUtil.getFirstEntity(cell.getTarget());
    String country = CellUtil.getFirstParameter(cell, COUNTRY_PARAMETER_NAME).as(String.class);
    String provider = CellUtil.getFirstParameter(cell, DATA_PROVIDER_PARAMETER_NAME).as(String.class);
    String product = CellUtil.getFirstParameter(cell, PRODUCT_PARAMETER_NAME).as(String.class);
    String namespace = Identifier.getNamespace(country, provider, product, target.getDefinition().getType());
    String version = CellUtil.getFirstParameter(cell, VERSION).as(String.class);
    StringBuilder sb = new StringBuilder();
    sb.append("The {1} property is populated with an Inspire Identifier composed as follows: <br /><br />");
    sb.append("1. <i>localId</i> contains the value of the {0} property.<br />");
    sb.append("2. The <i>namespace</i> is <b>{2}</b>.<br />");
    if (version != null && !version.isEmpty()) {
        sb.append("3. <i>version</i> is set to <b>{3}</b>.");
    } else {
        version = CellUtil.getFirstParameter(cell, VERSION_NIL_REASON).as(String.class);
        if (version != null && !version.isEmpty()) {
            sb.append("3. The reason why the version is not set is given as <b>{3}</b>.");
        } else {
            sb.append("3. No reason for the missing version number is given.");
        }
    }
    String result = sb.toString();
    if (source != null) {
        result = // 
        MessageFormat.format(// 
        result, // 
        formatEntity(source, html, true, targetLocale), // 
        formatEntity(target, html, true, targetLocale), // 
        namespace, version);
    }
    if (!html) {
        result = result.replaceAll("<br />", "\n");
        result = result.replaceAll("<i>", "");
        result = result.replaceAll("</i>", "");
        result = result.replaceAll("<b>", "");
        result = result.replaceAll("</b>", "");
    }
    return result;
}
Also used : Locale(java.util.Locale) Entity(eu.esdihumboldt.hale.common.align.model.Entity)

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