Search in sources :

Example 1 with LookupTable

use of eu.esdihumboldt.hale.common.lookup.LookupTable in project hale by halestudio.

the class LookupTableTypeTest method testComplexLookupJsonGroovy.

/**
 * Test if a lookup table containing only complex values is the same when
 * converted to JSON and back again.
 */
@Test
public void testComplexLookupJsonGroovy() {
    Map<Value, Value> values2 = createComplexLookup();
    LookupTable org2 = new LookupTableImpl(values2);
    // converter
    LookupTableType ltt = new LookupTableType();
    // convert to Json
    Object json = ltt.toJson(org2);
    System.out.println(new JsonBuilder(json).toString());
    // convert back
    LookupTable conv = ltt.fromJson(json, null);
    checkTable(conv, values2);
}
Also used : JsonBuilder(groovy.json.JsonBuilder) Value(eu.esdihumboldt.hale.common.core.io.Value) LookupTable(eu.esdihumboldt.hale.common.lookup.LookupTable) LookupTableImpl(eu.esdihumboldt.hale.common.lookup.impl.LookupTableImpl) Test(org.junit.Test)

Example 2 with LookupTable

use of eu.esdihumboldt.hale.common.lookup.LookupTable in project hale by halestudio.

the class LookupTableTypeTest method createComplexLookup.

private Map<Value, Value> createComplexLookup() {
    // simple internal table
    Map<Value, Value> values = new HashMap<Value, Value>();
    values.put(Value.of("a"), Value.of("1"));
    values.put(Value.of("b"), Value.of("1"));
    LookupTable org = new LookupTableImpl(values);
    // external table
    Map<Value, Value> values2 = new HashMap<Value, Value>();
    values2.put(Value.of("sub"), Value.complex(org));
    values2.put(Value.of("c"), Value.of("2"));
    return values2;
}
Also used : HashMap(java.util.HashMap) Value(eu.esdihumboldt.hale.common.core.io.Value) LookupTable(eu.esdihumboldt.hale.common.lookup.LookupTable) LookupTableImpl(eu.esdihumboldt.hale.common.lookup.impl.LookupTableImpl)

Example 3 with LookupTable

use of eu.esdihumboldt.hale.common.lookup.LookupTable in project hale by halestudio.

the class ClassificationMapping 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 {
    String source = variables.values().iterator().next().getValueAs(String.class);
    LookupTable lookup = ClassificationMappingUtil.getClassificationLookup(getParameters(), getExecutionContext());
    if (lookup == null) {
        // throw new TransformationException("No classification specified");
        log.warn(log.createMessage("No classification specified", null));
    } else {
        Value target = lookup.lookup(Value.of(source));
        if (target != null) {
            // return value w/ transformation variables replaced
            return getExecutionContext().getVariables().replaceVariables(target);
        }
    }
    String notClassifiedAction = getOptionalParameter(PARAMETER_NOT_CLASSIFIED_ACTION, Value.of(USE_NULL_ACTION)).as(String.class);
    if (USE_SOURCE_ACTION.equals(notClassifiedAction)) {
        return source;
    } else if (notClassifiedAction.startsWith(USE_FIXED_VALUE_ACTION_PREFIX)) {
        String notClassified = notClassifiedAction.substring(notClassifiedAction.indexOf(':') + 1);
        // return w/ transformation variables replaced
        return getExecutionContext().getVariables().replaceVariables(notClassified);
    } else {
        // return null;
        throw new NoResultException();
    }
}
Also used : LookupTable(eu.esdihumboldt.hale.common.lookup.LookupTable) PropertyValue(eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue) Value(eu.esdihumboldt.hale.common.core.io.Value) NoResultException(eu.esdihumboldt.hale.common.align.transformation.function.impl.NoResultException)

Example 4 with LookupTable

use of eu.esdihumboldt.hale.common.lookup.LookupTable in project hale by halestudio.

the class ClassificationMappingParameterPage method setParameter.

@Override
public void setParameter(Set<FunctionParameterDefinition> params, ListMultimap<String, ParameterValue> initialValues) {
    // this page is only for parameter classificationMapping, ignore params
    if (initialValues == null)
        return;
    // Load the lookupTableConfiguration
    List<ParameterValue> lookupTableId = initialValues.get(PARAMETER_LOOKUPTABLE_ID);
    if (!lookupTableId.isEmpty()) {
        selectedLookupTableID = lookupTableId.get(0).as(String.class);
    }
    // Load the complex value configuration
    List<ParameterValue> lookupTableComplex = initialValues.get(PARAMETER_LOOKUPTABLE);
    if (!lookupTableComplex.isEmpty()) {
        LookupTable table = (LookupTable) lookupTableComplex.get(0).getValue();
        lookupTable.putAll(table.asMap());
    }
    // For reason of compatibility we need the following code
    List<ParameterValue> mappings = initialValues.get(PARAMETER_CLASSIFICATIONS);
    for (ParameterValue value : mappings) {
        String s = value.as(String.class);
        String[] splitted = s.split(" ");
        try {
            for (int i = 0; i < splitted.length; i++) splitted[i] = URLDecoder.decode(splitted[i], "UTF-8");
        } catch (UnsupportedEncodingException e) {
        // UTF-8 should be everywhere
        }
        Value targetValue = Value.of(splitted[0]);
        for (int i = 1; i < splitted.length; i++) lookupTable.put(Value.of(splitted[i]), targetValue);
    }
    List<ParameterValue> notClassifiedActionParams = initialValues.get(PARAMETER_NOT_CLASSIFIED_ACTION);
    if (!notClassifiedActionParams.isEmpty())
        notClassifiedAction = notClassifiedActionParams.get(0).as(String.class);
}
Also used : ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) LookupTable(eu.esdihumboldt.hale.common.lookup.LookupTable) Value(eu.esdihumboldt.hale.common.core.io.Value) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StyledString(org.eclipse.jface.viewers.StyledString) Point(org.eclipse.swt.graphics.Point)

Example 5 with LookupTable

use of eu.esdihumboldt.hale.common.lookup.LookupTable in project hale by halestudio.

the class ClassificationMappingParameterPage method getConfiguration.

/**
 * @see eu.esdihumboldt.hale.ui.function.generic.pages.ParameterPage#getConfiguration()
 */
@Override
public ListMultimap<String, ParameterValue> getConfiguration() {
    ListMultimap<String, ParameterValue> configuration = ArrayListMultimap.create();
    for (TabItem tabItem : tabs.getSelection()) {
        if (tabItem.equals(fromFileItem)) {
            // Set the selected lookupTable
            IStructuredSelection selection = (IStructuredSelection) lookupTableComboViewer.getSelection();
            configuration.put(PARAMETER_LOOKUPTABLE_ID, new ParameterValue(selection.getFirstElement().toString()));
        } else {
            if (tabItem.equals(manualItem)) {
                LookupTable realLookupTable = new LookupTableImpl(lookupTable);
                configuration.put(PARAMETER_LOOKUPTABLE, new ParameterValue(Value.complex(realLookupTable)));
            }
        }
    }
    switch(notClassifiedActionOptions.indexOf(((IStructuredSelection) notClassifiedActionViewer.getSelection()).getFirstElement())) {
        case 1:
            notClassifiedAction = "source";
            break;
        case 2:
            notClassifiedAction = "fixed:" + fixedValueText.getText();
            break;
        case 0:
        case -1:
        default:
            notClassifiedAction = "null";
    }
    configuration.put(PARAMETER_NOT_CLASSIFIED_ACTION, new ParameterValue(notClassifiedAction));
    return configuration;
}
Also used : TabItem(org.eclipse.swt.widgets.TabItem) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) LookupTable(eu.esdihumboldt.hale.common.lookup.LookupTable) StyledString(org.eclipse.jface.viewers.StyledString) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) LookupTableImpl(eu.esdihumboldt.hale.common.lookup.impl.LookupTableImpl)

Aggregations

LookupTable (eu.esdihumboldt.hale.common.lookup.LookupTable)13 Value (eu.esdihumboldt.hale.common.core.io.Value)12 LookupTableImpl (eu.esdihumboldt.hale.common.lookup.impl.LookupTableImpl)8 Test (org.junit.Test)6 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)4 Entity (eu.esdihumboldt.hale.common.align.model.Entity)2 StringReader (java.io.StringReader)2 StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 StyledString (org.eclipse.jface.viewers.StyledString)2 Element (org.w3c.dom.Element)2 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 Property (eu.esdihumboldt.hale.common.align.model.Property)1 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)1 PropertyValue (eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue)1 NoResultException (eu.esdihumboldt.hale.common.align.transformation.function.impl.NoResultException)1 ComplexValue (eu.esdihumboldt.hale.common.core.io.impl.ComplexValue)1 StringValue (eu.esdihumboldt.hale.common.core.io.impl.StringValue)1 ServiceManager (eu.esdihumboldt.hale.common.core.service.ServiceManager)1 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)1