Search in sources :

Example 1 with ParentAxis

use of org.sirix.axis.ParentAxis in project sirix by sirixdb.

the class ExpressionSingle method isDupOrd.

/**
 * Determines for a given string representation of an axis, whether this axis leads to duplicates
 * in the result sequence or not. Furthermore it determines the new state for the order state that
 * specifies, if the result sequence is in document order. This method is implemented according to
 * the automata in [Hidders, J., Michiels, P., "Avoiding Unnecessary Ordering Operations in
 * XPath", 2003]
 *
 * @param ax name of the current axis
 * @return true, if expression is still duplicate free
 */
public boolean isDupOrd(final Axis ax) {
    Axis axis = ax;
    while (axis instanceof FilterAxis) {
        axis = ((FilterAxis) axis).getAxis();
    }
    if (axis instanceof UnionAxis) {
        mOrd = mOrd.updateOrdUnion();
        mDup = mDup.updateUnion();
    } else if (axis instanceof ChildAxis) {
        mOrd = mOrd.updateOrdChild();
        mDup = mDup.updateDupChild();
    } else if (axis instanceof ParentAxis) {
        mOrd = mOrd.updateOrdParent();
        mDup = mDup.updateDupParent();
    } else if (axis instanceof DescendantAxis) {
        mOrd = mOrd.updateOrdDesc();
        mDup = mDup.updateDupDesc();
    } else if (axis instanceof AncestorAxis) {
        mOrd = mOrd.updateOrdAncestor();
        mDup = mDup.updateDupAncestor();
    } else if (axis instanceof FollowingAxis || axis instanceof PrecedingAxis) {
        mOrd = mOrd.updateOrdFollPre();
        mDup = mDup.updateDupFollPre();
    } else if (axis instanceof FollowingSiblingAxis || axis instanceof PrecedingSiblingAxis) {
        mOrd = mOrd.updateOrdFollPreSib();
        mDup = mDup.updateDupFollPreSib();
    }
    return !DupState.nodup;
}
Also used : ChildAxis(org.sirix.axis.ChildAxis) AncestorAxis(org.sirix.axis.AncestorAxis) FollowingSiblingAxis(org.sirix.axis.FollowingSiblingAxis) FollowingAxis(org.sirix.axis.FollowingAxis) PrecedingAxis(org.sirix.axis.PrecedingAxis) PrecedingSiblingAxis(org.sirix.axis.PrecedingSiblingAxis) ParentAxis(org.sirix.axis.ParentAxis) DescendantAxis(org.sirix.axis.DescendantAxis) AncestorAxis(org.sirix.axis.AncestorAxis) PrecedingAxis(org.sirix.axis.PrecedingAxis) Axis(org.sirix.api.Axis) NestedAxis(org.sirix.axis.NestedAxis) ChildAxis(org.sirix.axis.ChildAxis) FollowingSiblingAxis(org.sirix.axis.FollowingSiblingAxis) UnionAxis(org.sirix.service.xml.xpath.expr.UnionAxis) FollowingAxis(org.sirix.axis.FollowingAxis) FilterAxis(org.sirix.axis.filter.FilterAxis) DescendantAxis(org.sirix.axis.DescendantAxis) ParentAxis(org.sirix.axis.ParentAxis) DupFilterAxis(org.sirix.service.xml.xpath.filter.DupFilterAxis) PrecedingSiblingAxis(org.sirix.axis.PrecedingSiblingAxis) FilterAxis(org.sirix.axis.filter.FilterAxis) DupFilterAxis(org.sirix.service.xml.xpath.filter.DupFilterAxis) UnionAxis(org.sirix.service.xml.xpath.expr.UnionAxis)

Example 2 with ParentAxis

use of org.sirix.axis.ParentAxis in project sirix by sirixdb.

the class XPathParser method parseReverceAxis.

/**
 * Parses the the rule ReverceAxis according to the following production rule: [33] ReverseAxis
 * ::= <"parent" "::"> | <"ancestor" "::"> | <"preceding-sibling" "::">|<"preceding"
 * "::">|<"ancestor-or-self" "::"> .
 *
 * @return axis
 */
private AbstractAxis parseReverceAxis() {
    AbstractAxis axis;
    if (is("parent", true)) {
        axis = new ParentAxis(getTransaction());
    } else if (is("ancestor", true)) {
        axis = new AncestorAxis(getTransaction());
    } else if (is("ancestor-or-self", true)) {
        axis = new AncestorAxis(getTransaction(), IncludeSelf.YES);
    } else if (is("preceding", true)) {
        axis = new PrecedingAxis(getTransaction());
    } else {
        consume("preceding-sibling", true);
        axis = new PrecedingSiblingAxis(getTransaction());
    }
    consume(TokenType.COLON, true);
    consume(TokenType.COLON, true);
    return axis;
}
Also used : AncestorAxis(org.sirix.axis.AncestorAxis) PrecedingAxis(org.sirix.axis.PrecedingAxis) PrecedingSiblingAxis(org.sirix.axis.PrecedingSiblingAxis) AbstractAxis(org.sirix.axis.AbstractAxis) ParentAxis(org.sirix.axis.ParentAxis)

Example 3 with ParentAxis

use of org.sirix.axis.ParentAxis in project sirix by sirixdb.

the class ExpressionSingleTest method testDup.

@Test
public void testDup() throws SirixException {
    ExpressionSingle builder = new ExpressionSingle();
    builder.add(new ChildAxis(holder.getReader()));
    builder.add(new DescendantAxis(holder.getReader()));
    assertTrue(builder.getExpr() instanceof NestedAxis);
    builder = new ExpressionSingle();
    builder.add(new ChildAxis(holder.getReader()));
    builder.add(new DescendantAxis(holder.getReader()));
    assertEquals(true, builder.isOrdered());
    assertTrue(builder.getExpr() instanceof NestedAxis);
    builder = new ExpressionSingle();
    builder.add(new ChildAxis(holder.getReader()));
    builder.add(new DescendantAxis(holder.getReader()));
    builder.add(new ChildAxis(holder.getReader()));
    assertEquals(false, builder.isOrdered());
    builder = new ExpressionSingle();
    builder = new ExpressionSingle();
    builder.add(new ChildAxis(holder.getReader()));
    builder.add(new DescendantAxis(holder.getReader()));
    builder.add(new ChildAxis(holder.getReader()));
    builder.add(new ParentAxis(holder.getReader()));
    assertEquals(true, builder.isOrdered());
    builder = new ExpressionSingle();
    builder.add(new ChildAxis(holder.getReader()));
    builder.add(new DescendantAxis(holder.getReader()));
    builder.add(new FollowingSiblingAxis(holder.getReader()));
    assertEquals(false, builder.isOrdered());
    builder = new ExpressionSingle();
    builder.add(new UnionAxis(holder.getReader(), new DescendantAxis(holder.getReader()), new ParentAxis(holder.getReader())));
    assertEquals(false, builder.isOrdered());
    assertTrue(builder.getExpr() instanceof DupFilterAxis);
}
Also used : ChildAxis(org.sirix.axis.ChildAxis) FollowingSiblingAxis(org.sirix.axis.FollowingSiblingAxis) ParentAxis(org.sirix.axis.ParentAxis) NestedAxis(org.sirix.axis.NestedAxis) DupFilterAxis(org.sirix.service.xml.xpath.filter.DupFilterAxis) DescendantAxis(org.sirix.axis.DescendantAxis) UnionAxis(org.sirix.service.xml.xpath.expr.UnionAxis) Test(org.junit.Test)

Aggregations

ParentAxis (org.sirix.axis.ParentAxis)3 AncestorAxis (org.sirix.axis.AncestorAxis)2 ChildAxis (org.sirix.axis.ChildAxis)2 DescendantAxis (org.sirix.axis.DescendantAxis)2 FollowingSiblingAxis (org.sirix.axis.FollowingSiblingAxis)2 NestedAxis (org.sirix.axis.NestedAxis)2 PrecedingAxis (org.sirix.axis.PrecedingAxis)2 PrecedingSiblingAxis (org.sirix.axis.PrecedingSiblingAxis)2 UnionAxis (org.sirix.service.xml.xpath.expr.UnionAxis)2 DupFilterAxis (org.sirix.service.xml.xpath.filter.DupFilterAxis)2 Test (org.junit.Test)1 Axis (org.sirix.api.Axis)1 AbstractAxis (org.sirix.axis.AbstractAxis)1 FollowingAxis (org.sirix.axis.FollowingAxis)1 FilterAxis (org.sirix.axis.filter.FilterAxis)1