Search in sources :

Example 66 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.

the class InteriorPoint 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 {
    // get input geometry
    PropertyValue input = variables.get(null).get(0);
    Object inputValue = input.getValue();
    GeometryProperty<?> result = calculateInteriorPoint(inputValue);
    // try to yield a result compatible to the target
    TypeDefinition targetType = resultProperty.getDefinition().getPropertyType();
    // TODO check element type?
    Class<?> binding = targetType.getConstraint(Binding.class).getBinding();
    if (Geometry.class.isAssignableFrom(binding) && binding.isAssignableFrom(result.getClass())) {
        return result.getGeometry();
    }
    return result;
}
Also used : Binding(eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding) Geometry(com.vividsolutions.jts.geom.Geometry) PropertyValue(eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 67 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.

the class SpatialJoinParameter method validate.

/**
 * Checks whether this join parameter is valid.<br>
 * <br>
 * Valid means, that there has to be at least two types, with each type
 * after the first having at least one join condition on previous types.
 *
 * @return a error description or <code>null</code> if the parameter is
 *         valid.
 */
public String validate() {
    // enough types?
    if (types.size() < 2)
        return "Less than two types.";
    // Check that each type is only in here once.
    Set<TypeDefinition> typeSet = new HashSet<>();
    for (TypeEntityDefinition type : types) {
        if (typeSet.contains(type.getDefinition())) {
            return "Same base type is used twice.";
        } else {
            typeSet.add(type.getDefinition());
        }
    }
    // direct parent map
    int[] parent = new int[types.size()];
    // marker for found conditions for each type
    boolean[] conditionFound = new boolean[types.size()];
    // use sorted conditions (by join type)
    List<SpatialJoinCondition> sortedConditions = new ArrayList<>(conditions);
    Collections.sort(sortedConditions, new Comparator<SpatialJoinCondition>() {

        @Override
        public int compare(SpatialJoinCondition o1, SpatialJoinCondition o2) {
            TypeEntityDefinition o1Type = AlignmentUtil.getTypeEntity(o1.baseProperty);
            TypeEntityDefinition o2Type = AlignmentUtil.getTypeEntity(o2.baseProperty);
            return types.indexOf(o1Type) - types.indexOf(o2Type);
        }
    });
    // check types of each condition
    for (SpatialJoinCondition condition : sortedConditions) {
        TypeEntityDefinition baseType = AlignmentUtil.getTypeEntity(condition.baseProperty);
        TypeEntityDefinition joinType = AlignmentUtil.getTypeEntity(condition.joinProperty);
        int baseIndex = types.indexOf(baseType);
        int joinIndex = types.indexOf(joinType);
        // types have to exist, and join has to be after base
        if (baseIndex == -1 || joinIndex == -1) {
            return "Property references no specified type.";
        }
        if (joinIndex <= baseIndex) {
            return "Invalid condition for type order.";
        }
        conditionFound[joinIndex] = true;
        // sorted conditions allow this dependsOn-check
        if (parent[joinIndex] < baseIndex) {
            if (!dependsOn(baseIndex, parent[joinIndex], parent)) {
                return "A join type depends on two types which do not depend on each other.";
            }
            parent[joinIndex] = baseIndex;
        }
    }
    // check whether each type (except the first) has a join condition
    for (int i = 1; i < conditionFound.length; i++) {
        if (!conditionFound[i]) {
            return "A joined type does not have any join conditions.";
        }
    }
    return null;
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) ArrayList(java.util.ArrayList) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) HashSet(java.util.HashSet)

Example 68 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.

the class GroovyRetype method execute.

@Override
public void execute(String transformationIdentifier, TransformationEngine engine, Map<String, String> executionParameters, TransformationLog log, Cell cell) throws TransformationException {
    // for each source instance create a target instance
    TypeDefinition targetType = getTarget().values().iterator().next().getDefinition().getDefinition();
    InstanceBuilder builder = new InstanceBuilder(false);
    Binding binding = createBinding(getSource(), cell, builder, log, getExecutionContext(), targetType);
    try {
        GroovyService service = getExecutionContext().getService(GroovyService.class);
        Script script = GroovyUtil.getScript(this, binding, service);
        Iterable<MutableInstance> targets = GroovyUtil.evaluateAll(script, builder, targetType, service, log);
        for (MutableInstance target : targets) {
            getPropertyTransformer().publish(getSource(), target, log, cell);
        }
    } catch (TransformationException e) {
        throw e;
    } catch (NoResultException e) {
        log.info(log.createMessage("Skipping target instance because received NoResultException from script", null));
    } catch (Exception e) {
        throw new TransformationException(e.getMessage(), e);
    }
}
Also used : Binding(groovy.lang.Binding) Script(groovy.lang.Script) TransformationException(eu.esdihumboldt.hale.common.align.transformation.function.TransformationException) MutableInstance(eu.esdihumboldt.hale.common.instance.model.MutableInstance) NoResultException(eu.esdihumboldt.hale.common.align.transformation.function.impl.NoResultException) GroovyService(eu.esdihumboldt.util.groovy.sandbox.GroovyService) TransformationException(eu.esdihumboldt.hale.common.align.transformation.function.TransformationException) NoResultException(eu.esdihumboldt.hale.common.align.transformation.function.impl.NoResultException) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) InstanceBuilder(eu.esdihumboldt.hale.common.instance.groovy.InstanceBuilder)

Example 69 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.

the class GeographicalName method evaluate.

/**
 * @see AbstractSingleTargetPropertyTransformation#evaluate(String,
 *      TransformationEngine, ListMultimap, String,
 *      PropertyEntityDefinition, Map, TransformationLog)
 */
@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 {
    // list of all source properties
    List<PropertyValue> inputs = variables.get(null);
    if (inputs.isEmpty()) {
        // no input, so don't create any structure
        throw new NoResultException();
    }
    // get all parameters defined by the wizard page
    String ipa = getParameterChecked(PROPERTY_PRONUNCIATIONIPA).as(String.class);
    // we need a default value and a try/catch-block because in older
    // version we couldn't edit the pronunciationSoundLink text field
    String sound = "";
    try {
        sound = getParameterChecked(PROPERTY_PRONUNCIATIONSOUNDLINK).as(String.class);
    } catch (Exception e) {
    // do nothing
    }
    String language = getParameterChecked(PROPERTY_LANGUAGE).as(String.class);
    String sourceOfName = getParameterChecked(PROPERTY_SOURCEOFNAME).as(String.class);
    String nameStatus = getParameterChecked(PROPERTY_NAMESTATUS).as(String.class);
    String nativeness = getParameterChecked(PROPERTY_NATIVENESS).as(String.class);
    String gender = getParameterChecked(PROPERTY_GRAMMA_GENDER).as(String.class);
    String number = getParameterChecked(PROPERTY_GRAMMA_NUMBER).as(String.class);
    // get the script and transliteration parameters
    // should have the same order like source properties
    ListMultimap<String, ParameterValue> params = getParameters();
    List<ParameterValue> scripts = params.get(PROPERTY_SCRIPT);
    List<ParameterValue> trans = params.get(PROPERTY_TRANSLITERATION);
    if (inputs.size() != scripts.size() || inputs.size() != trans.size()) {
        throw new TransformationException("Number of inputs does not match number of configured spellings, can't determine script and transliteration of spellings.");
    // XXX could this be dealt with if the property "text" would be used
    // again for this purpose?
    }
    // definition of the target property
    TypeDefinition targetType = resultProperty.getDefinition().getPropertyType();
    // instance that can be changed (add property/instance as child)
    DefaultInstance targetInstance = new DefaultInstance(targetType, null);
    // search for the child named "GeographicalName"
    PropertyDefinition targetChildGeoName = Util.getChild("GeographicalName", targetType);
    // get type definition to create the "GeographicalName" instance
    TypeDefinition geoType = targetChildGeoName.getPropertyType();
    // name/GeographicalName/
    DefaultInstance geoInstance = new DefaultInstance(geoType, null);
    targetInstance.addProperty(targetChildGeoName.getName(), geoInstance);
    // name/GeographicalName/grammaticalGender/
    if (gender != null && !gender.isEmpty()) {
        PropertyDefinition geoChildGramGender = Util.getChild("grammaticalGender", geoType);
        TypeDefinition grammarGenderType = geoChildGramGender.getPropertyType();
        DefaultInstance grammarGenderInst = new DefaultInstance(grammarGenderType, null);
        grammarGenderInst.setValue(gender);
        geoInstance.addProperty(geoChildGramGender.getName(), grammarGenderInst);
    }
    // name/GeographicalName/grammaticalNumber
    if (number != null && !number.isEmpty()) {
        PropertyDefinition geoChildGramNumber = Util.getChild("grammaticalNumber", geoType);
        TypeDefinition grammarNumberType = geoChildGramNumber.getPropertyType();
        DefaultInstance grammarNumberInst = new DefaultInstance(grammarNumberType, null);
        // set value of the grammaticalNumber instance
        grammarNumberInst.setValue(number);
        geoInstance.addProperty(geoChildGramNumber.getName(), grammarNumberInst);
    }
    // name/GeographicalName/language
    if (language != null && !language.isEmpty()) {
        PropertyDefinition geoChildLanguage = Util.getChild("language", geoType);
        TypeDefinition languageType = geoChildLanguage.getPropertyType();
        DefaultInstance languageInstance = new DefaultInstance(languageType, null);
        // set value of the language instance
        languageInstance.setValue(language);
        geoInstance.addProperty(geoChildLanguage.getName(), languageInstance);
    }
    // name/GeographicalName/nameStatus
    if (nameStatus != null && !nameStatus.isEmpty()) {
        PropertyDefinition geoChildNameStatus = Util.getChild("nameStatus", geoType);
        TypeDefinition nameStatusType = geoChildNameStatus.getPropertyType();
        DefaultInstance nameStatusInstance = new DefaultInstance(nameStatusType, null);
        // set value of the nameStatus instance
        nameStatusInstance.setValue(nameStatus);
        geoInstance.addProperty(geoChildNameStatus.getName(), nameStatusInstance);
    }
    // name/GeographicalName/nativeness
    if (nativeness != null && !nativeness.isEmpty()) {
        PropertyDefinition geoChildNativeness = Util.getChild("nativeness", geoType);
        TypeDefinition nativenessType = geoChildNativeness.getPropertyType();
        DefaultInstance nativenessInstance = new DefaultInstance(nativenessType, null);
        // set value of the nativeness instance
        nativenessInstance.setValue(nativeness);
        geoInstance.addProperty(geoChildNativeness.getName(), nativenessInstance);
    }
    if ((ipa != null && !ipa.isEmpty()) || (sound != null && !sound.isEmpty())) {
        // name/GeographicalName/pronunciation
        PropertyDefinition geoChildPronun = Util.getChild("pronunciation", geoType);
        TypeDefinition pronunType = geoChildPronun.getPropertyType();
        DefaultInstance pronunInstance = new DefaultInstance(pronunType, null);
        geoInstance.addProperty(geoChildPronun.getName(), pronunInstance);
        // name/GeographicalName/pronunciation/PronunciationOfName
        PropertyDefinition pronunChildPronOfName = Util.getChild("PronunciationOfName", pronunType);
        TypeDefinition pronOfNameType = pronunChildPronOfName.getPropertyType();
        DefaultInstance pronOfNameInst = new DefaultInstance(pronOfNameType, null);
        pronunInstance.addProperty(pronunChildPronOfName.getName(), pronOfNameInst);
        if (ipa != null && !ipa.isEmpty()) {
            // name/GeographicalName/pronunciation/PronunciationOfName/pronunciationIPA
            PropertyDefinition pronOfNameChildIPA = Util.getChild("pronunciationIPA", pronOfNameType);
            TypeDefinition pronunIpaType = pronOfNameChildIPA.getPropertyType();
            DefaultInstance pronunIpaInstance = new DefaultInstance(pronunIpaType, null);
            pronunIpaInstance.setValue(ipa);
            pronOfNameInst.addProperty(pronOfNameChildIPA.getName(), pronunIpaInstance);
        }
        if (sound != null && !sound.isEmpty()) {
            // name/GeographicalName/pronunciation/PronunciationOfName/pronunciationSoundLink
            PropertyDefinition pronOfNameChildSound = Util.getChild("pronunciationSoundLink", pronOfNameType);
            TypeDefinition pronunSoundType = pronOfNameChildSound.getPropertyType();
            DefaultInstance pronunSoundInstance = new DefaultInstance(pronunSoundType, null);
            pronunSoundInstance.setValue(sound);
            pronOfNameInst.addProperty(pronOfNameChildSound.getName(), pronunSoundInstance);
        }
    }
    // name/GeographicalName/sourceOfName
    if (sourceOfName != null && !sourceOfName.isEmpty()) {
        PropertyDefinition geoChildSource = Util.getChild("sourceOfName", geoType);
        TypeDefinition sourceType = geoChildSource.getPropertyType();
        DefaultInstance sourceInstance = new DefaultInstance(sourceType, null);
        // set value of the sourceOfName instance
        sourceInstance.setValue(sourceOfName);
        geoInstance.addProperty(geoChildSource.getName(), sourceInstance);
    }
    // name/GeographicalName/spelling
    PropertyDefinition geoChildSpelling = Util.getChild("spelling", geoType);
    TypeDefinition spellingType = geoChildSpelling.getPropertyType();
    // name/GeographicalName/spelling/SpellingOfName
    PropertyDefinition spellingChildSpellOfName = Util.getChild("SpellingOfName", spellingType);
    TypeDefinition spellOfNameType = spellingChildSpellOfName.getPropertyType();
    // create a "spelling" instance for each spelling
    for (int i = 0; i < scripts.size(); i++) {
        DefaultInstance spellingInstance = new DefaultInstance(spellingType, null);
        DefaultInstance spellOfNameInst = new DefaultInstance(spellOfNameType, null);
        // name/GeographicalName/spelling/SpellingOfName/script
        PropertyDefinition spellOfNameChildScript = Util.getChild("script", spellOfNameType);
        TypeDefinition scriptType = spellOfNameChildScript.getPropertyType();
        DefaultInstance scriptInstance = new DefaultInstance(scriptType, null);
        // name/GeographicalName/spelling/SpellingOfName/text
        PropertyDefinition spellOfNameChildText = Util.getChild("text", spellOfNameType);
        // name/GeographicalName/spelling/SpellingOfName/transliterationScheme
        PropertyDefinition spellOfNameChildTransliteration = Util.getChild("transliterationScheme", spellOfNameType);
        TypeDefinition transliterationType = spellOfNameChildTransliteration.getPropertyType();
        DefaultInstance transliterationInstance = new DefaultInstance(transliterationType, null);
        // build the spelling instance
        scriptInstance.setValue(scripts.get(i).as(String.class));
        transliterationInstance.setValue(trans.get(i).as(String.class));
        spellOfNameInst.addProperty(spellOfNameChildScript.getName(), scriptInstance);
        // set text value from inputs
        spellOfNameInst.addProperty(spellOfNameChildText.getName(), inputs.get(i).getValue());
        spellOfNameInst.addProperty(spellOfNameChildTransliteration.getName(), transliterationInstance);
        spellingInstance.addProperty(spellingChildSpellOfName.getName(), spellOfNameInst);
        geoInstance.addProperty(geoChildSpelling.getName(), spellingInstance);
    }
    return targetInstance;
}
Also used : TransformationException(eu.esdihumboldt.hale.common.align.transformation.function.TransformationException) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) PropertyValue(eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue) NoResultException(eu.esdihumboldt.hale.common.align.transformation.function.impl.NoResultException) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TransformationException(eu.esdihumboldt.hale.common.align.transformation.function.TransformationException) NoResultException(eu.esdihumboldt.hale.common.align.transformation.function.impl.NoResultException) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) DefaultInstance(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance)

Example 70 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.

the class XPathPropertyDefinitionDialog method getInputDefinition.

private static TypeDefinition getInputDefinition(EntityDefinition entityDef) {
    if (entityDef.getPropertyPath() == null || entityDef.getPropertyPath().isEmpty()) {
        // types?
        return entityDef.getType();
    } else {
        PropertyDefinition def = (PropertyDefinition) entityDef.getDefinition();
        // create a dummy type for the input
        TypeDefinition dummyType = new DefaultTypeDefinition(new QName("ValueFilterDummy"));
        TypeDefinition emptyType = new DefaultTypeDefinition(new QName("EmptyDummy"));
        // with .. as parent link
        new DefaultPropertyDefinition(PARENT_NAME, dummyType, emptyType);
        // and the value property added as itself
        dummyType.addChild(def);
        return dummyType;
    }
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) QName(javax.xml.namespace.QName) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)

Aggregations

TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)192 QName (javax.xml.namespace.QName)58 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)38 ArrayList (java.util.ArrayList)32 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)26 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)26 Test (org.junit.Test)24 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)22 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)21 HashSet (java.util.HashSet)21 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)20 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)20 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)16 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)15 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)15 Cell (eu.esdihumboldt.hale.common.align.model.Cell)14 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)14 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)12 Binding (eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding)12 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)12