Search in sources :

Example 1 with ModelRifMappingCondition

use of com.onespatial.jrc.tns.oml_to_rif.model.rif.ModelRifMappingCondition in project hale by halestudio.

the class ModelRifToRifTranslator method processChildren.

private void processChildren(ModelSentence s, final Exists exists, Do do1) {
    Formula existsFormula = factory.createFormula();
    And and = factory.createAnd();
    existsFormula.setAnd(and);
    exists.setFormula(existsFormula);
    Actions actions = factory.createDoActions();
    do1.setActions(actions);
    for (RifVariable instanceVariable : s.getVariables(Type.INSTANCE)) {
        // source instance variables
        if (!instanceVariable.isActionVar()) {
            recurseChildren(exists, do1, instanceVariable, s, true);
        } else // target instance variables
        {
            recurseChildren(exists, do1, instanceVariable, s, false);
        }
    }
    Map<RifVariable, Frame> map = new LinkedHashMap<RifVariable, Frame>();
    for (PropertyMapping mapping : s.getPropertyMappings()) {
        RifVariable contextVariable = mapping.getTarget().getContextVariable();
        Frame match = map.get(contextVariable);
        if (match == null) {
            map.put(contextVariable, initialiseFrame(contextVariable));
        }
    }
    for (StaticAssignment staticAssignment : s.getStaticAssignments()) {
        RifVariable contextVariable = staticAssignment.getTarget().getContextVariable();
        Frame match = map.get(contextVariable);
        if (match == null) {
            map.put(contextVariable, initialiseFrame(contextVariable));
        }
    }
    for (PropertyMapping mapping : s.getPropertyMappings()) {
        Frame frame = map.get(mapping.getTarget().getContextVariable());
        createAssignmentSlot(mapping, frame);
    }
    for (StaticAssignment staticAssignment : s.getStaticAssignments()) {
        Frame frame = map.get(staticAssignment.getTarget().getContextVariable());
        createStaticAssignmentSlot(staticAssignment, frame);
    }
    for (ModelRifMappingCondition mappingCondition : s.getMappingConditions()) {
        createFilter(exists.getFormula().getAnd().getFormula(), mappingCondition);
    }
    for (Frame frame : map.values()) {
        Assert assert1 = factory.createAssert();
        Target target = factory.createAssertTarget();
        target.setFrame(frame);
        assert1.setTarget(target);
        actions.getACTION().add(assert1);
    }
}
Also used : Formula(org.w3._2007.rif.Formula) StaticAssignment(com.onespatial.jrc.tns.oml_to_rif.model.rif.StaticAssignment) Frame(org.w3._2007.rif.Frame) Target(org.w3._2007.rif.Assert.Target) Assert(org.w3._2007.rif.Assert) Actions(org.w3._2007.rif.Do.Actions) And(org.w3._2007.rif.And) ModelRifMappingCondition(com.onespatial.jrc.tns.oml_to_rif.model.rif.ModelRifMappingCondition) PropertyMapping(com.onespatial.jrc.tns.oml_to_rif.model.rif.PropertyMapping) RifVariable(com.onespatial.jrc.tns.oml_to_rif.translate.context.RifVariable) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with ModelRifMappingCondition

use of com.onespatial.jrc.tns.oml_to_rif.model.rif.ModelRifMappingCondition in project hale by halestudio.

the class ModelAlignmentToModelRifTranslator method buildRifMappingCondition.

private ModelRifMappingCondition buildRifMappingCondition(ModelSentence sentence, AbstractFilterNode node) {
    ModelRifMappingCondition rifCondition = new ModelRifMappingCondition();
    if (node != null) {
        // logical ones
        if (node.isLogical()) {
            for (FilterNode child : node.getChildren()) {
                AbstractFilterNode childNode = (AbstractFilterNode) child;
                rifCondition.addChild(buildRifMappingCondition(sentence, childNode));
            }
            if (node.getNodeType().equals(AND_NODE)) {
                rifCondition.setLogicalType(LogicalType.AND);
            } else if (node.getNodeType().equals(OR_NODE)) {
                rifCondition.setLogicalType(LogicalType.OR);
            } else if (node.getNodeType().equals(NOT_NODE)) {
                rifCondition.setLogicalType(LogicalType.NOT);
                rifCondition.setNegated(true);
            }
        } else // comparison ones
        if (node.isComparison()) {
            AbstractComparisonNode cnode = (AbstractComparisonNode) node;
            if (node.getNodeType().equals(EQUAL_TO_NODE)) {
                EqualToNode equalNode = (EqualToNode) node;
                // work out if it's a string or a numeric equality test
                rifCondition.setOperator(STRING_EQUALS);
                if (equalNode.getRight().isNumeric()) {
                    rifCondition.setOperator(NUMBER_EQUALS);
                }
            } else // less-than comparisons
            if (node.getNodeType().equals(GREATER_THAN_NODE)) {
                rifCondition.setOperator(NUMBER_GREATER_THAN);
            } else if (node.getNodeType().equals(LESS_THAN_NODE)) {
                rifCondition.setOperator(NUMBER_LESS_THAN);
            } else if (node.getNodeType().equals(LIKE_NODE)) {
                rifCondition.setOperator(STRING_CONTAINS);
            }
            rifCondition.setLeft(getContents(sentence, cnode.getLeft()));
            rifCondition.setLiteralClass(cnode.getRight().getLiteralValue().getValueClass());
            rifCondition.setLiteralValue(cnode.getRight().getLiteralValue().toString());
            rifCondition.setRight(getContents(sentence, cnode.getRight()));
        } else // geometric ones
        if (node.isGeometric()) {
        // TODO add this
        }
    }
    return rifCondition;
}
Also used : EqualToNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.EqualToNode) AbstractFilterNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.AbstractFilterNode) ModelRifMappingCondition(com.onespatial.jrc.tns.oml_to_rif.model.rif.ModelRifMappingCondition) FilterNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.FilterNode) AbstractFilterNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.AbstractFilterNode) AbstractComparisonNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.AbstractComparisonNode)

Aggregations

ModelRifMappingCondition (com.onespatial.jrc.tns.oml_to_rif.model.rif.ModelRifMappingCondition)2 PropertyMapping (com.onespatial.jrc.tns.oml_to_rif.model.rif.PropertyMapping)1 StaticAssignment (com.onespatial.jrc.tns.oml_to_rif.model.rif.StaticAssignment)1 AbstractFilterNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.AbstractFilterNode)1 FilterNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.FilterNode)1 AbstractComparisonNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.AbstractComparisonNode)1 EqualToNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.EqualToNode)1 RifVariable (com.onespatial.jrc.tns.oml_to_rif.translate.context.RifVariable)1 LinkedHashMap (java.util.LinkedHashMap)1 And (org.w3._2007.rif.And)1 Assert (org.w3._2007.rif.Assert)1 Target (org.w3._2007.rif.Assert.Target)1 Actions (org.w3._2007.rif.Do.Actions)1 Formula (org.w3._2007.rif.Formula)1 Frame (org.w3._2007.rif.Frame)1