Search in sources :

Example 1 with NamedEntityBean

use of eu.esdihumboldt.hale.common.align.io.impl.internal.NamedEntityBean 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 2 with NamedEntityBean

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

the class OmlReader method loadAlignment.

@Override
protected MutableAlignment loadAlignment(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    try {
        progress.begin("Load ontology mapping file", ProgressIndicator.UNKNOWN);
        OmlRdfReader reader = new OmlRdfReader();
        Alignment alignment = reader.read(getSource().getLocation().toURL());
        AlignmentBean align = new AlignmentBean();
        List<CellBean> cells = new ArrayList<CellBean>();
        List<ICell> map = alignment.getMap();
        for (ICell cell : map) {
            // create a new CellBean for each ICell
            CellBean cellBean = new CellBean();
            IEntity entity = cell.getEntity1();
            IEntity entity2 = cell.getEntity2();
            // temporary list to be copied into the CellBean
            List<NamedEntityBean> temp_source = new ArrayList<NamedEntityBean>();
            List<NamedEntityBean> temp_target = new ArrayList<NamedEntityBean>();
            setBeanLists(entity, temp_source, getSourceSchema());
            setBeanLists(entity2, temp_target, getTargetSchema());
            // set source/target lists of the CellBean
            cellBean.setSource(temp_source);
            cellBean.setTarget(temp_target);
            // check if one of the entities has a transformation
            if (entity.getTransformation() != null || entity2.getTransformation() != null) {
                // entity 1 if it has the transformation
                if (entity.getTransformation() != null) {
                    setParameters(cellBean, entity, reporter, cell);
                    setTransformationId(cellBean, entity);
                } else {
                    // else set parameters and transformation id from entity
                    // 2
                    setParameters(cellBean, entity2, reporter, cell);
                    setTransformationId(cellBean, entity2);
                }
            }
            // add the CellBean to a list of CellBeans
            cells.add(cellBean);
        }
        // set the cells for the alignment after the all iterations
        align.setCells(cells);
        MutableAlignment mutableAlignment = align.createAlignment(reporter, getSourceSchema(), getTargetSchema(), new PathUpdate(null, null));
        reporter.setSuccess(true);
        return mutableAlignment;
    } finally {
        progress.end();
    }
}
Also used : IEntity(eu.esdihumboldt.hale.io.oml.internal.model.align.IEntity) ArrayList(java.util.ArrayList) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) ICell(eu.esdihumboldt.hale.io.oml.internal.model.align.ICell) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) Alignment(eu.esdihumboldt.hale.io.oml.internal.goml.align.Alignment) CellBean(eu.esdihumboldt.hale.common.align.io.impl.internal.CellBean) NamedEntityBean(eu.esdihumboldt.hale.common.align.io.impl.internal.NamedEntityBean) AlignmentBean(eu.esdihumboldt.hale.common.align.io.impl.internal.AlignmentBean) PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) OmlRdfReader(eu.esdihumboldt.hale.io.oml.internal.goml.oml.io.OmlRdfReader)

Example 3 with NamedEntityBean

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

the class OmlReader method setBeanLists.

private void setBeanLists(IEntity entity, List<NamedEntityBean> list, TypeIndex schema) {
    if (entity.getAbout().getAbout().equals(Entity.NULL_ENTITY.getAbout().getAbout())) {
        return;
    }
    if (entity instanceof ComposedFeatureClass) {
        ComposedFeatureClass cfc = (ComposedFeatureClass) entity;
        List<FeatureClass> coll = cfc.getCollection();
        for (FeatureClass fc : coll) {
            setBeanLists(fc, list, schema);
        }
    } else if (entity instanceof ComposedProperty) {
        ComposedProperty cp = (ComposedProperty) entity;
        List<Property> coll = cp.getCollection();
        for (Property prop : coll) {
            setBeanLists(prop, list, schema);
        }
    } else if (entity instanceof FeatureClass) {
        // get the detailed about-information
        IDetailedAbout about = DetailedAbout.getDetailedAbout(entity.getAbout(), false);
        TypeBean typeBean = new TypeBean();
        setTypeNameBean(typeBean, about, schema);
        NamedEntityBean namedEntityBean = new NamedEntityBean();
        namedEntityBean.setEntity(typeBean);
        namedEntityBean.setName(null);
        list.add(namedEntityBean);
    } else if (entity instanceof Property) {
        // get the detailed about-information
        IDetailedAbout about = DetailedAbout.getDetailedAbout(entity.getAbout(), true);
        PropertyBean prop = new PropertyBean();
        List<ChildContextBean> childList = new ArrayList<ChildContextBean>();
        List<String> props = about.getProperties();
        for (String property : props) {
            ChildContextBean ccb = new ChildContextBean();
            ccb.setChildName(new QName(property));
            childList.add(ccb);
        }
        setTypeNameBean(prop, about, schema);
        prop.setProperties(childList);
        NamedEntityBean namedEntityBean = new NamedEntityBean();
        namedEntityBean.setEntity(prop);
        namedEntityBean.setName(null);
        list.add(namedEntityBean);
    }
}
Also used : QName(javax.xml.namespace.QName) TypeBean(eu.esdihumboldt.hale.common.align.io.impl.internal.TypeBean) ComposedFeatureClass(eu.esdihumboldt.hale.io.oml.internal.goml.omwg.ComposedFeatureClass) ComposedFeatureClass(eu.esdihumboldt.hale.io.oml.internal.goml.omwg.ComposedFeatureClass) FeatureClass(eu.esdihumboldt.hale.io.oml.internal.goml.omwg.FeatureClass) ChildContextBean(eu.esdihumboldt.hale.common.align.io.impl.internal.ChildContextBean) NamedEntityBean(eu.esdihumboldt.hale.common.align.io.impl.internal.NamedEntityBean) ComposedProperty(eu.esdihumboldt.hale.io.oml.internal.goml.omwg.ComposedProperty) IDetailedAbout(eu.esdihumboldt.hale.io.oml.internal.goml.rdf.IDetailedAbout) List(java.util.List) ArrayList(java.util.ArrayList) ComposedProperty(eu.esdihumboldt.hale.io.oml.internal.goml.omwg.ComposedProperty) Property(eu.esdihumboldt.hale.io.oml.internal.goml.omwg.Property) PropertyBean(eu.esdihumboldt.hale.common.align.io.impl.internal.PropertyBean)

Example 4 with NamedEntityBean

use of eu.esdihumboldt.hale.common.align.io.impl.internal.NamedEntityBean 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)

Example 5 with NamedEntityBean

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

the class OrdinatesToPointTranslator 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) {
    reporter.warn(new IOMessageImpl("Behavior of this function has changed.", null));
    List<NamedEntityBean> src = cellBean.getSource();
    for (int i = 0; i < src.size(); i++) {
        NamedEntityBean bean = src.get(i);
        if (i == 0) {
            bean.setName("X");
        }
        if (i == 1) {
            bean.setName("Y");
        }
        if (i == 2) {
            bean.setName("Z");
        }
    }
    return params;
}
Also used : NamedEntityBean(eu.esdihumboldt.hale.common.align.io.impl.internal.NamedEntityBean) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)

Aggregations

NamedEntityBean (eu.esdihumboldt.hale.common.align.io.impl.internal.NamedEntityBean)5 ArrayList (java.util.ArrayList)4 ChildContextBean (eu.esdihumboldt.hale.common.align.io.impl.internal.ChildContextBean)2 ParameterValueBean (eu.esdihumboldt.hale.common.align.io.impl.internal.ParameterValueBean)2 PropertyBean (eu.esdihumboldt.hale.common.align.io.impl.internal.PropertyBean)2 AlignmentBean (eu.esdihumboldt.hale.common.align.io.impl.internal.AlignmentBean)1 CellBean (eu.esdihumboldt.hale.common.align.io.impl.internal.CellBean)1 TypeBean (eu.esdihumboldt.hale.common.align.io.impl.internal.TypeBean)1 MutableAlignment (eu.esdihumboldt.hale.common.align.model.MutableAlignment)1 PathUpdate (eu.esdihumboldt.hale.common.core.io.PathUpdate)1 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)1 Alignment (eu.esdihumboldt.hale.io.oml.internal.goml.align.Alignment)1 OmlRdfReader (eu.esdihumboldt.hale.io.oml.internal.goml.oml.io.OmlRdfReader)1 ComposedFeatureClass (eu.esdihumboldt.hale.io.oml.internal.goml.omwg.ComposedFeatureClass)1 ComposedProperty (eu.esdihumboldt.hale.io.oml.internal.goml.omwg.ComposedProperty)1 FeatureClass (eu.esdihumboldt.hale.io.oml.internal.goml.omwg.FeatureClass)1 Property (eu.esdihumboldt.hale.io.oml.internal.goml.omwg.Property)1 IDetailedAbout (eu.esdihumboldt.hale.io.oml.internal.goml.rdf.IDetailedAbout)1 ICell (eu.esdihumboldt.hale.io.oml.internal.model.align.ICell)1 IEntity (eu.esdihumboldt.hale.io.oml.internal.model.align.IEntity)1