Search in sources :

Example 1 with EqualToNode

use of com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.EqualToNode in project hale by halestudio.

the class TestCqlToMappingConditionTranslator method testTranslateNegatedEquality.

/**
 * Tests translating a CQL expression that negates the result of a simple
 * equality filter.
 *
 * @throws TranslationException
 *             if any errors occurred during the translation
 * @throws CQLException
 *             if any errors occurred parsing the CQL string
 */
@Test
public void testTranslateNegatedEquality() throws CQLException, TranslationException {
    // $NON-NLS-1$
    String cqlPredicate = "ATTR1 <> '17'";
    ModelMappingCondition result = digester.translate(CQL.toFilter(cqlPredicate));
    assertNotNull(result);
    assertNotNull(result.getRoot());
    assertThat(result.getRoot(), is(instanceOf(NotNode.class)));
    NotNode notNode = (NotNode) result.getRoot();
    assertThat(notNode.getChildren().size(), is(equalTo(1)));
    assertThat(notNode.getChild(0), is(instanceOf(EqualToNode.class)));
    EqualToNode equalNode = (EqualToNode) notNode.getChild(0);
    assertThat(equalNode.getChildren().size(), is(equalTo(0)));
    // $NON-NLS-1$ //$NON-NLS-2$
    checkComparisonRightLiteral(equalNode, "ATTR1", "17");
}
Also used : EqualToNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.EqualToNode) NotNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.logical.NotNode) ModelMappingCondition(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition) Test(org.junit.Test)

Example 2 with EqualToNode

use of com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.EqualToNode in project hale by halestudio.

the class TestCqlToMappingConditionTranslator method testTranslateMoreComplexLogical.

/**
 * Test that takes a slightly more complex logical expression comprising a
 * nested tree of predicates each comprising a comparison operation. Also it
 * tests the greater than and equals operations, and contains a mix of
 * string, floating-point and integer literals.
 *
 * @throws CQLException
 *             if any errors occurred parsing the CQL string
 * @throws TranslationException
 *             if any errors occurred during the translation
 */
@Test
public void testTranslateMoreComplexLogical() throws CQLException, TranslationException {
    // $NON-NLS-1$
    String cqlPredicate = "ATTR1 < 10.5 AND ATTR2 = 'chocolate' OR ATTR3 > 10";
    ModelMappingCondition result = digester.translate(CQL.toFilter(cqlPredicate));
    assertNotNull(result);
    assertNotNull(result.getRoot());
    assertThat(result.getRoot(), is(instanceOf(OrNode.class)));
    assertNotNull(result.getRoot().getChildren());
    assertThat(result.getRoot().getChildren().size(), is(equalTo(2)));
    assertThat(result.getRoot().getChild(0), is(instanceOf(AndNode.class)));
    AndNode andNode = (AndNode) result.getRoot().getChild(0);
    assertNotNull(andNode.getChildren());
    assertThat(andNode.getChildren().size(), is(equalTo(2)));
    assertThat(andNode.getChild(0), is(instanceOf(LessThanNode.class)));
    LessThanNode lessNode = (LessThanNode) andNode.getChild(0);
    // $NON-NLS-1$ //$NON-NLS-2$
    checkComparisonRightLiteral(lessNode, "ATTR1", "10.5");
    assertThat(andNode.getChild(1), is(instanceOf(EqualToNode.class)));
    EqualToNode equalNode = (EqualToNode) andNode.getChild(1);
    // $NON-NLS-1$ //$NON-NLS-2$
    checkComparisonRightLiteral(equalNode, "ATTR2", "chocolate");
    assertThat(result.getRoot().getChild(1), is(instanceOf(GreaterThanNode.class)));
    GreaterThanNode greaterNode = (GreaterThanNode) result.getRoot().getChild(1);
    // $NON-NLS-1$ //$NON-NLS-2$
    checkComparisonRightLiteral(greaterNode, "ATTR3", "10");
}
Also used : EqualToNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.EqualToNode) AndNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.logical.AndNode) GreaterThanNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.GreaterThanNode) LessThanNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.LessThanNode) ModelMappingCondition(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition) Test(org.junit.Test)

Example 3 with EqualToNode

use of com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.EqualToNode in project hale by halestudio.

the class TestCqlToMappingConditionTranslator method testTranslateAndWithThreeChildren.

/**
 * Tests translating a CQL expression where an 'AND' filter has three child
 * comparison operators.
 *
 * @throws CQLException
 *             if any errors occurred parsing the CQL string
 * @throws TranslationException
 *             if any errors occurred during the translation
 */
@Test
public void testTranslateAndWithThreeChildren() throws CQLException, TranslationException {
    // $NON-NLS-1$
    String cqlPredicate = "ATTR1 < 10.5 AND ATTR2 = 'chocolate' AND ATTR3 > 10";
    ModelMappingCondition result = digester.translate(CQL.toFilter(cqlPredicate));
    assertNotNull(result);
    assertNotNull(result.getRoot());
    assertThat(result.getRoot(), instanceOf(AndNode.class));
    AndNode andNode = (AndNode) result.getRoot();
    assertThat(andNode.getChildren().size(), is(equalTo(2)));
    assertThat(andNode.getChild(0), is(instanceOf(AndNode.class)));
    AndNode nestedAndNode = (AndNode) andNode.getChild(0);
    assertThat(nestedAndNode.getChild(0), is(instanceOf(LessThanNode.class)));
    LessThanNode lessNode = (LessThanNode) nestedAndNode.getChild(0);
    // $NON-NLS-1$ //$NON-NLS-2$
    checkComparisonRightLiteral(lessNode, "ATTR1", "10.5");
    assertThat(nestedAndNode.getChild(1), is(instanceOf(EqualToNode.class)));
    EqualToNode equalNode = (EqualToNode) nestedAndNode.getChild(1);
    // $NON-NLS-1$ //$NON-NLS-2$
    checkComparisonRightLiteral(equalNode, "ATTR2", "chocolate");
    assertThat(andNode.getChild(1), is(instanceOf(GreaterThanNode.class)));
    GreaterThanNode greaterNode = (GreaterThanNode) andNode.getChild(1);
    // $NON-NLS-1$ //$NON-NLS-2$
    checkComparisonRightLiteral(greaterNode, "ATTR3", "10");
}
Also used : EqualToNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.EqualToNode) AndNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.logical.AndNode) GreaterThanNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.GreaterThanNode) LessThanNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.LessThanNode) ModelMappingCondition(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition) Test(org.junit.Test)

Example 4 with EqualToNode

use of com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.EqualToNode 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)

Example 5 with EqualToNode

use of com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.EqualToNode in project hale by halestudio.

the class TestCqlToMappingConditionTranslator method testTranslateLogicalPrecedenceOverridden.

/**
 * Same as testTranslateSlightlyMoreComplexLogical but brackets around the
 * 'OR' express overrides the natural precedence of the 'AND' filter.
 *
 * @throws CQLException
 *             if any errors occurred parsing the CQL string
 * @throws TranslationException
 *             if any errors occurred during the translation
 */
@Test
public void testTranslateLogicalPrecedenceOverridden() throws CQLException, TranslationException {
    // $NON-NLS-1$
    String cqlPredicate = "ATTR1 < 10.5 AND (ATTR2 = 'chocolate' OR ATTR3 > 10)";
    ModelMappingCondition result = digester.translate(CQL.toFilter(cqlPredicate));
    assertNotNull(result);
    assertNotNull(result.getRoot());
    assertThat(result.getRoot(), is(instanceOf(AndNode.class)));
    AndNode andNode = (AndNode) result.getRoot();
    assertNotNull(andNode.getChildren());
    assertThat(andNode.getChildren().size(), is(equalTo(2)));
    assertThat(andNode.getChild(0), is(instanceOf(LessThanNode.class)));
    LessThanNode lessNode = (LessThanNode) andNode.getChild(0);
    // $NON-NLS-1$ //$NON-NLS-2$
    checkComparisonRightLiteral(lessNode, "ATTR1", "10.5");
    assertThat(andNode.getChild(1), is(instanceOf(OrNode.class)));
    OrNode orNode = (OrNode) andNode.getChild(1);
    assertThat(orNode.getChildren().size(), is(equalTo(2)));
    assertThat(orNode.getChild(0), is(instanceOf(EqualToNode.class)));
    EqualToNode equalNode = (EqualToNode) orNode.getChild(0);
    // $NON-NLS-1$ //$NON-NLS-2$
    checkComparisonRightLiteral(equalNode, "ATTR2", "chocolate");
    assertThat(orNode.getChild(1), is(instanceOf(GreaterThanNode.class)));
    GreaterThanNode greaterNode = (GreaterThanNode) orNode.getChild(1);
    // $NON-NLS-1$ //$NON-NLS-2$
    checkComparisonRightLiteral(greaterNode, "ATTR3", "10");
}
Also used : EqualToNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.EqualToNode) AndNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.logical.AndNode) GreaterThanNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.GreaterThanNode) LessThanNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.LessThanNode) ModelMappingCondition(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition) OrNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.logical.OrNode) Test(org.junit.Test)

Aggregations

EqualToNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.EqualToNode)6 ModelMappingCondition (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition)5 Test (org.junit.Test)5 GreaterThanNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.GreaterThanNode)3 LessThanNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.LessThanNode)3 AndNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.logical.AndNode)3 ModelRifMappingCondition (com.onespatial.jrc.tns.oml_to_rif.model.rif.ModelRifMappingCondition)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 NotNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.logical.NotNode)1 OrNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.logical.OrNode)1