Search in sources :

Example 6 with Formula

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

the class ModelRifToRifTranslator method createExternalPredicateFilter.

private void createExternalPredicateFilter(ModelRifMappingCondition mappingCondition, Formula filterFormula) {
    // create an <External>/<content>/<Atom> element hierarchy
    ExternalFORMULAType external = factory.createExternalFORMULAType();
    filterFormula.setExternal(external);
    ContentFORMULAType content = factory.createContentFORMULAType();
    external.setContent(content);
    Atom atom = factory.createAtom();
    content.setAtom(atom);
    Op op = factory.createOp();
    ArgsUNITERMType args = factory.createArgsUNITERMType();
    atom.setOp(op);
    Const opConst = factory.createConst();
    // $NON-NLS-1$
    opConst.setType("rif:iri");
    opConst.getContent().add(mappingCondition.getOperator().getRifPredicate());
    op.setConst(opConst);
    atom.setArgs(args);
    // $NON-NLS-1$
    args.setOrdered("yes");
    Var var = factory.createVar();
    var.getContent().add(mappingCondition.getLeft().getName());
    args.getTERM().add(var);
    Const argsConst = factory.createConst();
    argsConst.setType(getLiteralTypeFor(mappingCondition.getLiteralClass()));
    String literalValue = mappingCondition.getLiteralValue().toString();
    // remove any wildcards
    if (mappingCondition.getOperator().equals(ComparisonType.STRING_CONTAINS)) {
        // $NON-NLS-1$ //$NON-NLS-2$
        literalValue = literalValue.replaceAll("%", "");
    }
    argsConst.getContent().add(literalValue);
    args.getTERM().add(argsConst);
    // $NON-NLS-1$ //$NON-NLS-2$
    log.fine("Filter is a " + mappingCondition.getOperator().toString() + " filter");
}
Also used : Op(org.w3._2007.rif.Op) ExternalFORMULAType(org.w3._2007.rif.ExternalFORMULAType) ContentFORMULAType(org.w3._2007.rif.ContentFORMULAType) ActionVar(org.w3._2007.rif.Do.ActionVar) Var(org.w3._2007.rif.Var) Const(org.w3._2007.rif.Const) ArgsUNITERMType(org.w3._2007.rif.ArgsUNITERMType) Atom(org.w3._2007.rif.Atom)

Example 7 with Formula

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

the class ModelRifToRifTranslator method createComparativeFilter.

private void createComparativeFilter(List<Formula> list, ModelRifMappingCondition mappingCondition) {
    // $NON-NLS-1$
    log.fine("Creating comparative filter");
    Formula filterFormula = factory.createFormula();
    list.add(filterFormula);
    if (mappingCondition.getOperator().equals(ComparisonType.NUMBER_EQUALS) || mappingCondition.getOperator().equals(ComparisonType.STRING_EQUALS)) {
        createEqualsFilter(mappingCondition, filterFormula);
    } else if (mappingCondition.getOperator().equals(ComparisonType.NUMBER_GREATER_THAN) || mappingCondition.getOperator().equals(ComparisonType.NUMBER_LESS_THAN) || mappingCondition.getOperator().equals(ComparisonType.STRING_CONTAINS)) {
        createExternalPredicateFilter(mappingCondition, filterFormula);
    } else {
        throw new UnsupportedOperationException(// $NON-NLS-1$
        "Comparison type is not supported: " + mappingCondition.getOperator().toString());
    }
}
Also used : Formula(org.w3._2007.rif.Formula)

Example 8 with Formula

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

the class ModelRifToRifTranslator method createEqualsFilter.

private void createEqualsFilter(ModelRifMappingCondition mappingCondition, Formula filterFormula) {
    // create an <Equals> element
    Equal equal = factory.createEqual();
    filterFormula.setEqual(equal);
    Left left = factory.createLeft();
    Right right = factory.createRight();
    equal.setLeft(left);
    Var var = factory.createVar();
    var.getContent().add(mappingCondition.getLeft().getName());
    left.setVar(var);
    equal.setRight(right);
    Const const1 = factory.createConst();
    const1.setType(getLiteralTypeFor(mappingCondition.getLiteralClass()));
    right.setConst(const1);
    const1.getContent().add(mappingCondition.getLiteralValue());
    // $NON-NLS-1$ //$NON-NLS-2$
    log.fine("Filter is a " + mappingCondition.getOperator().toString() + " filter");
}
Also used : Left(org.w3._2007.rif.Left) Equal(org.w3._2007.rif.Equal) ActionVar(org.w3._2007.rif.Do.ActionVar) Var(org.w3._2007.rif.Var) Const(org.w3._2007.rif.Const) Right(org.w3._2007.rif.Right)

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