Search in sources :

Example 1 with ParameterValueBean

use of eu.esdihumboldt.hale.common.align.io.impl.internal.ParameterValueBean in project hale by halestudio.

the class OmlReader method setParameters.

private void setParameters(CellBean cellBean, IEntity entity, IOReporter reporter, ICell cell) {
    String transId = entity.getTransformation().getService().getLocation();
    // get the list of parameters
    List<IParameter> list = entity.getTransformation().getParameters();
    // create a list of ParameterValue (because
    // setTransformationParameters needs a list)
    List<ParameterValueBean> params = new ArrayList<ParameterValueBean>();
    for (int i = 0; i < list.size(); i++) {
        String name = list.get(i).getName();
        String value = list.get(i).getValue();
        // create the ParameterValue for the CellBean
        ParameterValueBean paramVal = new ParameterValueBean(name, value);
        // add the ParameterValue
        params.add(paramVal);
    }
    // set the new transformation parameters
    if (map.containsKey(transId)) {
        cellBean.setTransformationParameters(map.get(transId).getNewParameters(params, cellBean, reporter, cell));
    } else {
        cellBean.setTransformationParameters(params);
    }
}
Also used : IParameter(eu.esdihumboldt.hale.io.oml.internal.model.align.ext.IParameter) ParameterValueBean(eu.esdihumboldt.hale.common.align.io.impl.internal.ParameterValueBean) ArrayList(java.util.ArrayList)

Example 2 with ParameterValueBean

use of eu.esdihumboldt.hale.common.align.io.impl.internal.ParameterValueBean in project hale by halestudio.

the class ClassificationMappingTranslator method getNewParameters.

/**
 * @see eu.esdihumboldt.hale.io.oml.helper.FunctionTranslator#getNewParameters(java.util.List,
 *      eu.esdihumboldt.hale.common.align.io.impl.internal.CellBean,
 *      eu.esdihumboldt.hale.common.core.io.report.IOReporter,
 *      eu.esdihumboldt.hale.io.oml.internal.model.align.ICell)
 */
@Override
public List<ParameterValueBean> getNewParameters(List<ParameterValueBean> params, CellBean cellBean, IOReporter reporter, ICell cell) {
    List<ParameterValueBean> newList = new ArrayList<ParameterValueBean>();
    List<Restriction> sourceRest = new ArrayList<Restriction>();
    List<Restriction> tarRest = new ArrayList<Restriction>();
    sourceRest = ((Property) cell.getEntity1()).getValueCondition();
    tarRest = ((Property) cell.getEntity2()).getValueCondition();
    for (int i = 0; i < sourceRest.size(); i++) {
        Restriction r1 = sourceRest.get(i);
        Restriction r2 = tarRest.get(i);
        Joiner joiner = Joiner.on(" ").skipNulls();
        List<String> encodedParams = new ArrayList<String>();
        // first encode and add the associated value to the string list ...
        for (IValueExpression ival : r2.getValue()) {
            String temp = null;
            try {
                temp = URLEncoder.encode(ival.getLiteral(), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                reporter.error(new IOMessageImpl("Parameter could not be encoded.", null));
                e.printStackTrace();
            }
            encodedParams.add(temp);
        }
        // then encode and add the value expressions to the string list
        for (IValueExpression ival : r1.getValue()) {
            String temp = null;
            try {
                temp = URLEncoder.encode(ival.getLiteral(), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                reporter.error(new IOMessageImpl("Parameter could not be encoded.", null));
                e.printStackTrace();
            }
            encodedParams.add(temp);
        }
        String encodedParameter = joiner.join(encodedParams);
        newList.add(new ParameterValueBean(PARAMETER_CLASSIFICATIONS, encodedParameter));
    }
    return newList;
}
Also used : Restriction(eu.esdihumboldt.hale.io.oml.internal.goml.omwg.Restriction) Joiner(com.google.common.base.Joiner) IValueExpression(eu.esdihumboldt.hale.io.oml.internal.model.align.ext.IValueExpression) ParameterValueBean(eu.esdihumboldt.hale.common.align.io.impl.internal.ParameterValueBean) ArrayList(java.util.ArrayList) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 3 with ParameterValueBean

use of eu.esdihumboldt.hale.common.align.io.impl.internal.ParameterValueBean in project hale by halestudio.

the class FormattedStringTranslator method getNewParameters.

/**
 * @see eu.esdihumboldt.hale.io.oml.helper.FunctionTranslator#getNewParameters(java.util.List,
 *      eu.esdihumboldt.hale.common.align.io.impl.internal.CellBean,
 *      eu.esdihumboldt.hale.common.core.io.report.IOReporter,
 *      eu.esdihumboldt.hale.io.oml.internal.model.align.ICell)
 */
@Override
public List<ParameterValueBean> getNewParameters(List<ParameterValueBean> params, CellBean cellBean, IOReporter reporter, ICell cell) {
    List<ParameterValueBean> newList = new ArrayList<ParameterValueBean>();
    // default separator
    String separator = "";
    String concatenation = "";
    for (ParameterValueBean val : params) {
        // get original separator parameter
        if (val.getName().equals(SEPARATOR)) {
            separator = val.getValue();
        }
        // get original concatenation parameter
        if (val.getName().equals(CONCATENATION)) {
            concatenation = val.getValue();
        }
    }
    String[] concat = concatenation.split(INTERNALSEPERATOR);
    List<NamedEntityBean> src = cellBean.getSource();
    // create list of valid source variables
    Set<String> sourceVars = new HashSet<String>();
    for (NamedEntityBean bean : src) {
        if (bean.getEntity() instanceof PropertyBean) {
            List<ChildContextBean> props = ((PropertyBean) bean.getEntity()).getProperties();
            String[] children = new String[props.size()];
            for (int i = 0; i < props.size(); i++) {
                children[i] = props.get(i).getChildName().getLocalPart();
            }
            sourceVars.add(Joiner.on('.').join(children));
        }
    }
    StringBuffer pattern = new StringBuffer();
    boolean first = true;
    for (String thisElement : concat) {
        // append separator between elements
        if (first) {
            first = false;
        } else {
            pattern.append(separator);
        }
        String[] properties = thisElement.split(String.valueOf(DetailedAbout.PROPERTY_DELIMITER));
        String varString = Joiner.on('.').join(properties);
        if (sourceVars.contains(varString)) {
            // thisElement represents a variable
            pattern.append('{');
            pattern.append(varString);
            pattern.append('}');
        } else {
            // thisElement is just a string
            // TODO any escaping of {?
            pattern.append(thisElement);
        }
    }
    // add pattern parameter
    newList.add(new ParameterValueBean(PARAMETER_PATTERN, pattern.toString()));
    return newList;
}
Also used : ArrayList(java.util.ArrayList) ChildContextBean(eu.esdihumboldt.hale.common.align.io.impl.internal.ChildContextBean) NamedEntityBean(eu.esdihumboldt.hale.common.align.io.impl.internal.NamedEntityBean) ParameterValueBean(eu.esdihumboldt.hale.common.align.io.impl.internal.ParameterValueBean) PropertyBean(eu.esdihumboldt.hale.common.align.io.impl.internal.PropertyBean) HashSet(java.util.HashSet)

Example 4 with ParameterValueBean

use of eu.esdihumboldt.hale.common.align.io.impl.internal.ParameterValueBean in project hale by halestudio.

the class GeographicalNameTranslator method getNewParameters.

/**
 * @see eu.esdihumboldt.hale.io.oml.helper.FunctionTranslator#getNewParameters(java.util.List,
 *      eu.esdihumboldt.hale.common.align.io.impl.internal.CellBean,
 *      eu.esdihumboldt.hale.common.core.io.report.IOReporter,
 *      eu.esdihumboldt.hale.io.oml.internal.model.align.ICell)
 */
@Override
public List<ParameterValueBean> getNewParameters(List<ParameterValueBean> params, CellBean cellBean, IOReporter reporter, ICell cell) {
    // create the new parameter list
    List<ParameterValueBean> newParams = new ArrayList<ParameterValueBean>();
    IEntity source = cell.getEntity1();
    if (source instanceof ComposedProperty) {
        ComposedProperty cp = (ComposedProperty) source;
        // usually the composed property should only have one element in the
        // collection
        Property coll = cp.getCollection().get(0);
        // that should be a composed property too
        if (coll instanceof ComposedProperty) {
            ComposedProperty comProp = (ComposedProperty) coll;
            // parameters defined by the parameter page
            List<IParameter> pageParams = comProp.getTransformation().getParameters();
            // add each parameter defined by the parameter page
            for (IParameter p : pageParams) {
                newParams.add(new ParameterValueBean(p.getName(), p.getValue()));
            }
            // the collection of the collection contains the parameters
            // defined for the spellings
            List<Property> props = comProp.getCollection();
            for (Property prop : props) {
                // each property has a list of 3 parameters (text, script,
                // transliterationScheme)
                List<IParameter> spellingParams = prop.getTransformation().getParameters();
                for (IParameter p : spellingParams) {
                    newParams.add(new ParameterValueBean(p.getName(), p.getValue()));
                }
            }
        }
    }
    return newParams;
}
Also used : IParameter(eu.esdihumboldt.hale.io.oml.internal.model.align.ext.IParameter) IEntity(eu.esdihumboldt.hale.io.oml.internal.model.align.IEntity) ComposedProperty(eu.esdihumboldt.hale.io.oml.internal.goml.omwg.ComposedProperty) ParameterValueBean(eu.esdihumboldt.hale.common.align.io.impl.internal.ParameterValueBean) ArrayList(java.util.ArrayList) ComposedProperty(eu.esdihumboldt.hale.io.oml.internal.goml.omwg.ComposedProperty) Property(eu.esdihumboldt.hale.io.oml.internal.goml.omwg.Property)

Example 5 with ParameterValueBean

use of eu.esdihumboldt.hale.common.align.io.impl.internal.ParameterValueBean in project hale by halestudio.

the class MathematicalExpressionTranslator method getNewParameters.

/**
 * @see eu.esdihumboldt.hale.io.oml.helper.FunctionTranslator#getNewParameters(java.util.List,
 *      eu.esdihumboldt.hale.common.align.io.impl.internal.CellBean,
 *      eu.esdihumboldt.hale.common.core.io.report.IOReporter,
 *      eu.esdihumboldt.hale.io.oml.internal.model.align.ICell)
 */
@Override
public List<ParameterValueBean> getNewParameters(List<ParameterValueBean> params, CellBean cellBean, IOReporter reporter, ICell cell) {
    List<ParameterValueBean> newList = new ArrayList<ParameterValueBean>();
    for (ParameterValueBean val : params) {
        // translate "math_expression" to "expression"
        if (val.getName().equals("math_expression")) {
            newList.add(new ParameterValueBean(PARAMETER_EXPRESSION, val.getValue()));
        } else {
            newList.add(val);
        }
    }
    List<NamedEntityBean> src = cellBean.getSource();
    for (NamedEntityBean bean : src) {
        bean.setName(ENTITY_VARIABLE);
    }
    return newList;
}
Also used : NamedEntityBean(eu.esdihumboldt.hale.common.align.io.impl.internal.NamedEntityBean) ParameterValueBean(eu.esdihumboldt.hale.common.align.io.impl.internal.ParameterValueBean) ArrayList(java.util.ArrayList)

Aggregations

ParameterValueBean (eu.esdihumboldt.hale.common.align.io.impl.internal.ParameterValueBean)7 ArrayList (java.util.ArrayList)7 ChildContextBean (eu.esdihumboldt.hale.common.align.io.impl.internal.ChildContextBean)2 NamedEntityBean (eu.esdihumboldt.hale.common.align.io.impl.internal.NamedEntityBean)2 PropertyBean (eu.esdihumboldt.hale.common.align.io.impl.internal.PropertyBean)2 IParameter (eu.esdihumboldt.hale.io.oml.internal.model.align.ext.IParameter)2 Joiner (com.google.common.base.Joiner)1 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)1 ComposedProperty (eu.esdihumboldt.hale.io.oml.internal.goml.omwg.ComposedProperty)1 Property (eu.esdihumboldt.hale.io.oml.internal.goml.omwg.Property)1 Restriction (eu.esdihumboldt.hale.io.oml.internal.goml.omwg.Restriction)1 IEntity (eu.esdihumboldt.hale.io.oml.internal.model.align.IEntity)1 IValueExpression (eu.esdihumboldt.hale.io.oml.internal.model.align.ext.IValueExpression)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashSet (java.util.HashSet)1 QName (javax.xml.namespace.QName)1