Search in sources :

Example 1 with ModelAttributeMappingCell

use of com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell in project hale by halestudio.

the class TestAlignmentToModelAlignmentDigester method testExample3CPWithFilter.

/**
 * Tests translation based on the example 3 CP data set including a simple
 * predicate filter on the mapping of source classes to the target logical
 * schema.
 *
 * @throws TranslationException
 *             if any errors occurred during the translation
 */
@Test
public void testExample3CPWithFilter() throws TranslationException {
    URL url = getClass().getClassLoader().getResource(// $NON-NLS-1$
    "com/onespatial/jrc/tnstg/proto/oml_to_rif/alignments/example3_cp_filter.goml");
    ModelAlignment result = translator.translate(url);
    assertNotNull(result);
    assertNotNull(result.getClassMappings());
    assertNotNull(result.getAttributeMappings());
    assertNotNull(result.getStaticAssignments());
    assertThat(result.getClassMappings().size(), is(1));
    ModelClassMappingCell modelClassMappingCell = result.getClassMappings().get(0);
    assertNotNull(modelClassMappingCell);
    assertNotNull(modelClassMappingCell.getSourceClass());
    assertNotNull(modelClassMappingCell.getTargetClass());
    assertNotNull(modelClassMappingCell.getMappingConditions());
    assertThat(modelClassMappingCell.getMappingConditions().size(), is(1));
    assertNotNull(modelClassMappingCell.getMappingConditions().get(0).getRoot());
    FilterNode root = modelClassMappingCell.getMappingConditions().get(0).getRoot();
    assertThat(root, is(instanceOf(LessThanNode.class)));
    LessThanNode lessNode = (LessThanNode) root;
    assertNotNull(lessNode.getLeft());
    // $NON-NLS-1$
    assertThat(lessNode.getLeft().getPropertyName(), is(equalTo("MI_PRINX")));
    // $NON-NLS-1$
    assertThat(lessNode.getRight().getLiteralValue().toString(), is(equalTo("3.5")));
    assertNotNull(lessNode.getRight());
    // $NON-NLS-1$
    assertThat(modelClassMappingCell.getSourceClass().getElementName().getLocalPart(), is("ParcelArea"));
    // $NON-NLS-1$
    assertThat(modelClassMappingCell.getTargetClass().getElementName().getLocalPart(), is("CadastralParcel"));
    // CHECKSTYLE:OFF
    assertThat(result.getAttributeMappings().size(), is(7));
    // CHECKSTYLE:ON
    ModelAttributeMappingCell attributeMapping0 = result.getAttributeMappings().get(0);
    assertThat(attributeMapping0.getSourceAttribute().get(0).getDefinition().getName(), // $NON-NLS-1$
    is("PCVL_PRCL_"));
    assertThat(attributeMapping0.getTargetAttribute().get(0).getDefinition().getName(), // $NON-NLS-1$
    is("inspireId"));
    assertThat(result.getStaticAssignments().size(), is(1));
    ModelStaticAssignmentCell assignment0 = result.getStaticAssignments().get(0);
    // $NON-NLS-1$
    assertThat(assignment0.getTarget().get(0).getDefinition().getName(), is("inspireId"));
    // $NON-NLS-1$
    assertThat(assignment0.getContent(), is("DP.CAD.CP"));
}
Also used : ModelAttributeMappingCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell) ModelClassMappingCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelClassMappingCell) ModelStaticAssignmentCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelStaticAssignmentCell) FilterNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.FilterNode) ModelAlignment(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAlignment) LessThanNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.LessThanNode) URL(java.net.URL) Test(org.junit.Test)

Example 2 with ModelAttributeMappingCell

use of com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell in project hale by halestudio.

the class TestAlignmentToModelAlignmentDigester method testExample3CP.

/**
 * Tests translation based on the example 3 CP source dataset.
 *
 * @throws TranslationException
 *             if any errors occurred during the translation
 */
@Test
public void testExample3CP() throws TranslationException {
    URL url = getClass().getClassLoader().getResource(// $NON-NLS-1$
    "com/onespatial/jrc/tnstg/proto/oml_to_rif/alignments/example3_cp.goml");
    ModelAlignment result = translator.translate(url);
    assertNotNull(result);
    assertNotNull(result.getClassMappings());
    assertNotNull(result.getAttributeMappings());
    assertNotNull(result.getStaticAssignments());
    assertThat(result.getClassMappings().size(), is(1));
    ModelClassMappingCell modelClassMappingCell = result.getClassMappings().get(0);
    assertNotNull(modelClassMappingCell);
    assertNotNull(modelClassMappingCell.getSourceClass());
    assertNotNull(modelClassMappingCell.getTargetClass());
    // $NON-NLS-1$
    assertThat(modelClassMappingCell.getSourceClass().getElementName().getLocalPart(), is("ParcelArea"));
    // $NON-NLS-1$
    assertThat(modelClassMappingCell.getTargetClass().getElementName().getLocalPart(), is("CadastralParcel"));
    // CHECKSTYLE:OFF
    assertThat(result.getAttributeMappings().size(), is(7));
    // CHECKSTYLE:ON
    ModelAttributeMappingCell attributeMapping0 = result.getAttributeMappings().get(0);
    assertThat(attributeMapping0.getSourceAttribute().get(0).getDefinition().getName(), // $NON-NLS-1$
    is("PCVL_PRCL_"));
    assertThat(attributeMapping0.getTargetAttribute().get(0).getDefinition().getName(), // $NON-NLS-1$
    is("inspireId"));
    assertThat(result.getStaticAssignments().size(), is(1));
    ModelStaticAssignmentCell assignment0 = result.getStaticAssignments().get(0);
    // $NON-NLS-1$
    assertThat(assignment0.getTarget().get(0).getDefinition().getName(), is("inspireId"));
    // $NON-NLS-1$
    assertThat(assignment0.getContent(), is("DP.CAD.CP"));
}
Also used : ModelAttributeMappingCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell) ModelClassMappingCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelClassMappingCell) ModelStaticAssignmentCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelStaticAssignmentCell) ModelAlignment(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAlignment) URL(java.net.URL) Test(org.junit.Test)

Example 3 with ModelAttributeMappingCell

use of com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell in project hale by halestudio.

the class AlignmentToModelAlignmentDigester method translate.

/**
 * Translates a {@link HaleAlignment} into an intermediate
 * {@link ModelAlignment} format.
 *
 * @param hal the HALE alignment
 * @return {@link ModelAlignment}
 * @throws TranslationException
 *             if any problems occurred during translation
 */
@Override
public ModelAlignment translate(HaleAlignment hal) throws TranslationException {
    List<ModelClassMappingCell> classMappings = new ArrayList<ModelClassMappingCell>();
    List<ModelAttributeMappingCell> attributeMappings = new ArrayList<ModelAttributeMappingCell>();
    ArrayList<ModelStaticAssignmentCell> staticAssigments = new ArrayList<ModelStaticAssignmentCell>();
    Alignment source = hal.getAlignment();
    Map<String, SchemaElement> sourceFeatures = hal.getSourceElements();
    Map<String, SchemaElement> targetFeatures = hal.getTargetElements();
    for (ICell cell : source.getMap()) {
        IEntity sourceEntity = cell.getEntity1();
        IEntity targetEntity = cell.getEntity2();
        boolean sourceIsFeatureClass = sourceEntity instanceof FeatureClass;
        boolean targetIsFeatureClass = targetEntity instanceof FeatureClass;
        if (sourceIsFeatureClass && targetIsFeatureClass) {
            // type mapping
            classMappings.add(createCell((FeatureClass) sourceEntity, (FeatureClass) targetEntity, sourceFeatures, targetFeatures));
        } else if (!sourceIsFeatureClass && !targetIsFeatureClass) {
            // property mapping
            ModelAttributeMappingCell modelCell = createAttribute(cell, (Property) sourceEntity, (Property) targetEntity, sourceFeatures, targetFeatures);
            if (modelCell != null) {
                attributeMappings.add(modelCell);
            }
        } else if (sourceIsFeatureClass && !targetIsFeatureClass) {
            // augmentations
            ModelStaticAssignmentCell modelCell = createStaticAssignment(cell, (Property) targetEntity, targetFeatures);
            if (modelCell != null) {
                staticAssigments.add(modelCell);
            }
        } else {
            // $NON-NLS-1$
            throw new TranslationException("Unhandled combination");
        }
    }
    return new ModelAlignment(classMappings, attributeMappings, staticAssigments);
}
Also used : ModelClassMappingCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelClassMappingCell) IEntity(eu.esdihumboldt.specification.cst.align.IEntity) ModelStaticAssignmentCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelStaticAssignmentCell) ArrayList(java.util.ArrayList) ModelAlignment(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAlignment) TranslationException(com.onespatial.jrc.tns.oml_to_rif.api.TranslationException) FeatureClass(eu.esdihumboldt.commons.goml.omwg.FeatureClass) ICell(eu.esdihumboldt.specification.cst.align.ICell) ModelAlignment(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAlignment) Alignment(eu.esdihumboldt.commons.goml.align.Alignment) HaleAlignment(com.onespatial.jrc.tns.oml_to_rif.HaleAlignment) ModelAttributeMappingCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell) SchemaElement(eu.esdihumboldt.hale.schemaprovider.model.SchemaElement) Property(eu.esdihumboldt.commons.goml.omwg.Property) ComposedProperty(eu.esdihumboldt.commons.goml.omwg.ComposedProperty)

Example 4 with ModelAttributeMappingCell

use of com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell in project hale by halestudio.

the class AlignmentToModelAlignmentDigester method createAttribute.

private ModelAttributeMappingCell createAttribute(ICell original, Property sourceEntity, Property targetEntity, Map<String, SchemaElement> sourceFeatures, Map<String, SchemaElement> targetFeatures) {
    // FIXME what about composed properties?
    if (sourceEntity instanceof ComposedProperty || targetEntity instanceof ComposedProperty) {
        // $NON-NLS-1$
        report.setFailed(original, "Composed properties not supported");
        return null;
    }
    List<FeatureClass> filter = sourceEntity.getDomainRestriction();
    if (filter != null && !filter.isEmpty()) {
        // $NON-NLS-1$
        report.setWarning(original, "Filters on attributive functions currently not supported in the RIF export");
    }
    String function = sourceEntity.getTransformation().getService().getLocation();
    if (!RenameAttributeFunction.class.getName().equals(function)) {
        // $NON-NLS-1$ //$NON-NLS-2$
        report.setWarning(original, "Function " + function + " not recognized");
    }
    IDetailedAbout sourceAbout = DetailedAbout.getDetailedAbout(sourceEntity.getAbout(), true);
    IDetailedAbout targetAbout = DetailedAbout.getDetailedAbout(targetEntity.getAbout(), true);
    try {
        return new ModelAttributeMappingCell(createAttributePath(sourceAbout, sourceFeatures), createAttributePath(targetAbout, targetFeatures));
    } catch (TranslationException e) {
        report.setFailed(original, e.getMessage());
        return null;
    }
}
Also used : ModelAttributeMappingCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell) ComposedProperty(eu.esdihumboldt.commons.goml.omwg.ComposedProperty) IDetailedAbout(eu.esdihumboldt.commons.goml.rdf.IDetailedAbout) TranslationException(com.onespatial.jrc.tns.oml_to_rif.api.TranslationException) FeatureClass(eu.esdihumboldt.commons.goml.omwg.FeatureClass)

Example 5 with ModelAttributeMappingCell

use of com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell in project hale by halestudio.

the class ModelAlignmentToModelRifTranslator method buildModelSentance.

private ModelSentence buildModelSentance(ModelClassMappingCell classMapping, List<ModelAttributeMappingCell> attributeMappings, List<ModelStaticAssignmentCell> staticAssignments) {
    ModelSentence sentence = new ModelSentence();
    sentence.setSourceClass(// $NON-NLS-1$
    classMapping.getSourceClass().getElementName().getLocalPart().toLowerCase() + "-instance", getName(classMapping.getSourceClass().getElementName()));
    sentence.setTargetClass(// $NON-NLS-1$
    classMapping.getTargetClass().getElementName().getLocalPart().toLowerCase() + "-instance", getName(classMapping.getTargetClass().getElementName()));
    for (ModelMappingCondition condition : classMapping.getMappingConditions()) {
        sentence.addMappingCondition(buildRifMappingCondition(sentence, (AbstractFilterNode) condition.getRoot()));
    }
    for (ModelAttributeMappingCell attributeMapping : attributeMappings) {
        buildPropertyMapping(sentence, attributeMapping);
    }
    for (ModelStaticAssignmentCell staticAssigment : staticAssignments) {
        buildStaticAssignment(sentence, staticAssigment);
    }
    return sentence;
}
Also used : ModelSentence(com.onespatial.jrc.tns.oml_to_rif.model.rif.ModelSentence) AbstractFilterNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.AbstractFilterNode) ModelAttributeMappingCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell) ModelStaticAssignmentCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelStaticAssignmentCell) ModelMappingCondition(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition)

Aggregations

ModelAttributeMappingCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell)7 ModelStaticAssignmentCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelStaticAssignmentCell)5 ModelAlignment (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAlignment)4 ModelClassMappingCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelClassMappingCell)4 URL (java.net.URL)3 Test (org.junit.Test)3 TranslationException (com.onespatial.jrc.tns.oml_to_rif.api.TranslationException)2 FilterNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.FilterNode)2 ComposedProperty (eu.esdihumboldt.commons.goml.omwg.ComposedProperty)2 FeatureClass (eu.esdihumboldt.commons.goml.omwg.FeatureClass)2 ArrayList (java.util.ArrayList)2 HaleAlignment (com.onespatial.jrc.tns.oml_to_rif.HaleAlignment)1 ModelMappingCondition (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition)1 ModelSentence (com.onespatial.jrc.tns.oml_to_rif.model.rif.ModelSentence)1 AbstractFilterNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.AbstractFilterNode)1 LessThanNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.LessThanNode)1 Alignment (eu.esdihumboldt.commons.goml.align.Alignment)1 Property (eu.esdihumboldt.commons.goml.omwg.Property)1 IDetailedAbout (eu.esdihumboldt.commons.goml.rdf.IDetailedAbout)1 SchemaElement (eu.esdihumboldt.hale.schemaprovider.model.SchemaElement)1