Search in sources :

Example 1 with Formula

use of org.w3._2007.rif.Formula in project hale by halestudio.

the class TestModelRifToRifTranslator method checkAndChildren.

private void checkAndChildren(And and) {
    assertNotNull(and.getFormula());
    assertTrue(and.getFormula().size() >= 1);
    for (Formula formula : and.getFormula()) {
        if (formula.getMember() != null) {
            checkMemberElement(formula.getMember());
        } else if (formula.getFrame() != null) {
        // checkPropertyFrame(formula.getFrame());
        }
    }
}
Also used : Formula(org.w3._2007.rif.Formula)

Example 2 with Formula

use of org.w3._2007.rif.Formula in project hale by halestudio.

the class ModelRifToRifTranslator method createSourceInstanceMembershipFormula.

private Formula createSourceInstanceMembershipFormula(ModelSentence sentence, RifVariable instanceVariable) {
    Formula result = factory.createFormula();
    Member member = factory.createMember();
    Instance instance = factory.createInstance();
    Var var = factory.createVar();
    String name = sentence.getSourceClass().getName();
    var.getContent().add(name);
    Const const1 = factory.createConst();
    // $NON-NLS-1$
    const1.setType("rif:iri");
    const1.getContent().add(instanceVariable.getClassName());
    org.w3._2007.rif.Class clazz = factory.createClass();
    instance.setVar(var);
    clazz.setConst(const1);
    member.setInstance(instance);
    member.setClazz(clazz);
    result.setMember(member);
    return result;
}
Also used : Formula(org.w3._2007.rif.Formula) Instance(org.w3._2007.rif.Instance) ActionVar(org.w3._2007.rif.Do.ActionVar) Var(org.w3._2007.rif.Var) Const(org.w3._2007.rif.Const) Member(org.w3._2007.rif.Member)

Example 3 with Formula

use of org.w3._2007.rif.Formula in project hale by halestudio.

the class ModelRifToRifTranslator method recurseChildren.

private void recurseChildren(final Exists exists, Do do1, RifVariable variable, ModelSentence sentence, boolean isSource) {
    List<RifVariable> children = sentence.findChildren(variable);
    if (isSource) {
        exists.getDeclare().add(createSourceDeclare(variable));
        if (variable.getType().equals(Type.INSTANCE)) {
            exists.getFormula().getAnd().getFormula().add(createSourceInstanceMembershipFormula(sentence, variable));
        }
    } else {
        // if (!children.isEmpty()) // problem?
        do1.getActionVar().add(createTargetVariableDeclare(variable));
        if (variable.getType() == Type.INSTANCE) {
            do1.getActions().getACTION().add(createTargetInstanceMembershipFormula(do1.getActions(), sentence, variable));
        }
    }
    if (!children.isEmpty()) {
        if (isSource) {
            Frame frame = initialiseFrame(variable);
            for (RifVariable child : children) {
                recurseChildren(exists, do1, child, sentence, isSource);
                createBindingSlot(child, frame);
            }
            Formula frameFormula = factory.createFormula();
            frameFormula.setFrame(frame);
            exists.getFormula().getAnd().getFormula().add(frameFormula);
        } else {
            for (RifVariable child : children) {
                recurseChildren(exists, do1, child, sentence, isSource);
            }
        }
    }
}
Also used : Formula(org.w3._2007.rif.Formula) Frame(org.w3._2007.rif.Frame) RifVariable(com.onespatial.jrc.tns.oml_to_rif.translate.context.RifVariable)

Example 4 with Formula

use of org.w3._2007.rif.Formula 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 5 with Formula

use of org.w3._2007.rif.Formula in project hale by halestudio.

the class ModelRifToRifTranslator method createLogicalFilter.

private void createLogicalFilter(List<Formula> list, ModelRifMappingCondition mappingCondition) {
    // $NON-NLS-1$
    log.fine("Creating logical filter");
    Formula logicFilterFormula = factory.createFormula();
    if (mappingCondition.getLogicalType().equals(NOT)) {
        INeg negation = factory.createINeg();
        logicFilterFormula.setINeg(negation);
        // Formula subNegationFormula = factory.createFormula();
        List<Formula> notList = new ArrayList<Formula>();
        // notList.add(subNegationFormula);
        createChildFilters(mappingCondition, notList);
        negation.setFormula(notList.get(0));
        // $NON-NLS-1$
        log.fine("Filter is a NOT filter");
    } else {
        if (mappingCondition.getLogicalType().equals(AND)) {
            And and1 = factory.createAnd();
            logicFilterFormula.setAnd(and1);
            createChildFilters(mappingCondition, and1.getFormula());
            // $NON-NLS-1$
            log.fine("Filter is an AND filter");
        } else if (mappingCondition.getLogicalType().equals(OR)) {
            Or or = factory.createOr();
            logicFilterFormula.setOr(or);
            createChildFilters(mappingCondition, or.getFormula());
            // $NON-NLS-1$
            log.fine("Filter is an OR filter");
        }
    }
    list.add(logicFilterFormula);
}
Also used : Formula(org.w3._2007.rif.Formula) Or(org.w3._2007.rif.Or) INeg(org.w3._2007.rif.INeg) And(org.w3._2007.rif.And) ArrayList(java.util.ArrayList)

Aggregations

Formula (org.w3._2007.rif.Formula)6 Const (org.w3._2007.rif.Const)3 ActionVar (org.w3._2007.rif.Do.ActionVar)3 Var (org.w3._2007.rif.Var)3 RifVariable (com.onespatial.jrc.tns.oml_to_rif.translate.context.RifVariable)2 And (org.w3._2007.rif.And)2 Frame (org.w3._2007.rif.Frame)2 ModelRifMappingCondition (com.onespatial.jrc.tns.oml_to_rif.model.rif.ModelRifMappingCondition)1 PropertyMapping (com.onespatial.jrc.tns.oml_to_rif.model.rif.PropertyMapping)1 StaticAssignment (com.onespatial.jrc.tns.oml_to_rif.model.rif.StaticAssignment)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 ArgsUNITERMType (org.w3._2007.rif.ArgsUNITERMType)1 Assert (org.w3._2007.rif.Assert)1 Target (org.w3._2007.rif.Assert.Target)1 Atom (org.w3._2007.rif.Atom)1 ContentFORMULAType (org.w3._2007.rif.ContentFORMULAType)1 Actions (org.w3._2007.rif.Do.Actions)1 Equal (org.w3._2007.rif.Equal)1 ExternalFORMULAType (org.w3._2007.rif.ExternalFORMULAType)1