Search in sources :

Example 66 with QNm

use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.

the class NameIndexListener method listen.

@Override
public void listen(ChangeType type, @Nonnull ImmutableNode node, long pathNodeKey) throws SirixIOException {
    if (node instanceof NameNode) {
        final NameNode nameNode = (NameNode) node;
        final QNm name = nameNode.getName();
        final boolean included = (mIncludes.isEmpty() || mIncludes.contains(name));
        final boolean excluded = (!mExcludes.isEmpty() && mExcludes.contains(name));
        if (!included || excluded) {
            return;
        }
        switch(type) {
            case INSERT:
                final Optional<NodeReferences> textReferences = mAVLTreeWriter.get(name, SearchMode.EQUAL);
                if (textReferences.isPresent()) {
                    setNodeReferences(node, textReferences.get(), name);
                } else {
                    setNodeReferences(node, new NodeReferences(), name);
                }
                break;
            case DELETE:
                mAVLTreeWriter.remove(name, node.getNodeKey());
                break;
            default:
        }
    }
}
Also used : NameNode(org.sirix.node.interfaces.NameNode) QNm(org.brackit.xquery.atomic.QNm) NodeReferences(org.sirix.index.avltree.keyvalue.NodeReferences)

Example 67 with QNm

use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.

the class Indexes method init.

@Override
public synchronized void init(final Node<?> root) throws DocumentException {
    final QNm name = root.getName();
    if (!INDEXES_TAG.equals(name)) {
        throw new DocumentException("Expected tag '%s' but found '%s'", INDEXES_TAG, name);
    }
    final Stream<? extends Node<?>> children = root.getChildren();
    try {
        Node<?> child;
        while ((child = children.next()) != null) {
            QNm childName = child.getName();
            if (!childName.equals(IndexDef.INDEX_TAG)) {
                throw new DocumentException("Expected tag '%s' but found '%s'", IndexDef.INDEX_TAG, childName);
            }
            final IndexDef indexDefinition = new IndexDef();
            indexDefinition.init(child);
            mIndexes.add(indexDefinition);
        }
    } finally {
        children.close();
    }
}
Also used : QNm(org.brackit.xquery.atomic.QNm) DocumentException(org.brackit.xquery.xdm.DocumentException)

Example 68 with QNm

use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.

the class IndexDef method init.

@Override
public void init(Node<?> root) throws DocumentException {
    QNm name = root.getName();
    if (!name.equals(INDEX_TAG)) {
        throw new DocumentException("Expected tag '%s' but found '%s'", INDEX_TAG, name);
    }
    Node<?> attribute;
    attribute = root.getAttribute(ID_ATTRIBUTE);
    if (attribute != null) {
        mID = Integer.valueOf(attribute.getValue().stringValue());
    }
    attribute = root.getAttribute(TYPE_ATTRIBUTE);
    if (attribute != null) {
        mType = (IndexType.valueOf(attribute.getValue().stringValue()));
    }
    attribute = root.getAttribute(CONTENT_TYPE_ATTRIBUTE);
    if (attribute != null) {
        mContentType = (resolveType(attribute.getValue().stringValue()));
    }
    attribute = root.getAttribute(UNIQUE_ATTRIBUTE);
    if (attribute != null) {
        mUnique = (Boolean.valueOf(attribute.getValue().stringValue()));
    }
    final Stream<? extends Node<?>> children = root.getChildren();
    try {
        Node<?> child;
        while ((child = children.next()) != null) {
            // if (child.getName().equals(IndexStatistics.STATISTICS_TAG)) {
            // indexStatistics = new IndexStatistics();
            // indexStatistics.init(child);
            // } else {
            QNm childName = child.getName();
            String value = child.getValue().stringValue();
            if (childName.equals(PATH_TAG)) {
                final String path = value;
                mPaths.add(Path.parse(path));
            } else if (childName.equals(INCLUDING_TAG)) {
                for (final String s : value.split(",")) {
                    if (s.length() > 0) {
                        mIncluded.add(new QNm(s));
                    // String includeString = s;
                    // String[] tmp = includeString.split("@");
                    // included.put(new QNm(tmp[0]),
                    // Cluster.valueOf(tmp[1]));
                    }
                }
            } else if (childName.equals(EXCLUDING_TAG)) {
                for (final String s : value.split(",")) {
                    if (s.length() > 0)
                        mExcluded.add(new QNm(s));
                }
            }
        // }
        }
    } finally {
        children.close();
    }
}
Also used : QNm(org.brackit.xquery.atomic.QNm) DocumentException(org.brackit.xquery.xdm.DocumentException)

Example 69 with QNm

use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.

the class TraverseCompareTree method createSunburstItem.

@Override
public float createSunburstItem(final Item pItem, @Nonnegative final int pDepth, @Nonnegative final int pIndex) {
    checkNotNull(pItem);
    checkArgument(pDepth >= 0, "pDepth must be positive!");
    checkArgument(pIndex >= 0, "pIndex must be >= 0!");
    // Initialize variables.
    final float angle = pItem.mAngle;
    final float parExtension = pItem.mExtension;
    final int indexToParent = pItem.mIndexToParent;
    final int descendantCount = pItem.mDescendantCount;
    final int parentDescCount = pItem.mParentDescendantCount;
    final int modificationCount = pItem.mModificationCount;
    long parentModificationCount = pItem.mParentModificationCount;
    final boolean subtract = pItem.mSubtract;
    final DiffTuple diffCont = pItem.mDiff;
    final int origDepth = pItem.mOrigDepth;
    final int nextDepth = pItem.mNextDepth;
    final int depth = pDepth;
    // Calculate extension.
    float extension = 2 * PConstants.PI;
    if (indexToParent > -1) {
        if (mItems.get(indexToParent).getSubtract()) {
            parentModificationCount -= FACTOR;
        }
        extension = (1f - mModWeight) * (parExtension * (float) descendantCount / ((float) parentDescCount - 1f)) + mModWeight * // modificationCount/parentModificationCount.
        (parExtension * (float) modificationCount / ((float) parentModificationCount - 1f));
    }
    LOGWRAPPER.debug("ITEM: " + pIndex);
    LOGWRAPPER.debug("modificationCount: " + modificationCount);
    LOGWRAPPER.debug("parentModificationCount: " + parentModificationCount);
    LOGWRAPPER.debug("descendantCount: " + descendantCount);
    LOGWRAPPER.debug("parentDescCount: " + parentDescCount);
    LOGWRAPPER.debug("indexToParent: " + indexToParent);
    LOGWRAPPER.debug("extension: " + extension);
    LOGWRAPPER.debug("depth: " + depth);
    LOGWRAPPER.debug("next Depth: " + nextDepth);
    LOGWRAPPER.debug("angle: " + angle);
    if (mPrune == Pruning.ITEMSIZE && extension < TraverseModel.ANGLE_TO_PRUNE && modificationCount <= descendantCount) {
        nodePruned();
    } else {
        // Add a sunburst item.
        if (mPrune == Pruning.DIFF && diffCont.getDiff() == DiffType.SAMEHASH) {
            mIsPruned = true;
        } else {
            mIsPruned = false;
        }
        final NodeReadTrx rtx = (diffCont.getDiff() == DiffType.DELETED || diffCont.getDiff() == DiffType.MOVEDFROM || diffCont.getDiff() == DiffType.REPLACEDOLD) ? mOldRtx : mNewRtx;
        final EStructType structKind = nextDepth > depth ? EStructType.ISINNERNODE : EStructType.ISLEAFNODE;
        // Set node relations.
        String text = "";
        NodeRelations relations = null;
        final DiffType currDiff = diffCont.getDiff();
        if (rtx.getKind() == Kind.TEXT) {
            if (currDiff == DiffType.DELETED || currDiff == DiffType.MOVEDFROM || currDiff == DiffType.REPLACEDOLD) {
                text = mOldRtx.getValue();
            } else {
                text = mNewRtx.getValue();
            }
            if (currDiff == DiffType.UPDATED || ((currDiff == DiffType.REPLACEDNEW || currDiff == DiffType.REPLACEDOLD) && mOldRtx.getKind() == mNewRtx.getKind())) {
                final String oldValue = mOldRtx.getValue();
                final String newValue = mNewRtx.getValue();
                float similarity = 1;
                // try {
                // Integer.parseInt(oldValue);
                // Integer.parseInt(newValue);
                // 
                // // TODO: Implement similarity measure on numerical data (easy!).
                // } catch (final NumberFormatException e) {
                similarity = mLevenshtein.getSimilarity(oldValue, newValue);
                // }
                relations = new NodeRelations(origDepth, depth, structKind, similarity, 0, 1, indexToParent).setSubtract(subtract);
            } else if (currDiff == DiffType.SAME || currDiff == DiffType.SAMEHASH) {
                relations = new NodeRelations(origDepth, depth, structKind, 1, 0, 1, indexToParent).setSubtract(subtract);
            } else {
                relations = new NodeRelations(origDepth, depth, structKind, 0, 0, 1, indexToParent).setSubtract(subtract);
            }
        } else {
            if (mMaxDescendantCount == 0) {
                if (mPrune == Pruning.NO) {
                    try {
                        mMaxDescendantCount = mMaxDescendantCountFuture.get().getDescendants();
                    } catch (final InterruptedException | ExecutionException e) {
                        LOGWRAPPER.error(e.getMessage(), e);
                    }
                } else {
                    mMaxDescendantCount = mAxis.getDescendantCount();
                }
            }
            relations = new NodeRelations(origDepth, depth, structKind, descendantCount, 1, mMaxDescendantCount, indexToParent).setSubtract(subtract);
        }
        // Build item.
        final SunburstItem.Builder builder = new SunburstItem.Builder(mParent, angle, extension, relations, mDb, mGUI).setNodeKey(rtx.getNodeKey()).setKind(rtx.getKind()).setDiff(diffCont.getDiff());
        if (modificationCount > descendantCount) {
            final int diffCounts = (modificationCount - descendantCount) / TraverseModel.FACTOR;
            LOGWRAPPER.debug("modCount: " + diffCounts);
            builder.setModifications(diffCounts);
        }
        if (text.isEmpty()) {
            QNm name = null;
            if (diffCont.getDiff() == DiffType.DELETED || diffCont.getDiff() == DiffType.MOVEDFROM || diffCont.getDiff() == DiffType.REPLACEDOLD) {
                name = mOldRtx.getName();
                builder.setAttributes(fillAttributes(mOldRtx));
                builder.setNamespaces(fillNamespaces(mOldRtx));
                builder.setOldKey(mOldRtx.getNodeKey());
                LOGWRAPPER.debug("name: " + name.getLocalName());
                builder.setOldQName(name);
            } else {
                name = mNewRtx.getName();
                builder.setAttributes(fillAttributes(mNewRtx));
                builder.setNamespaces(fillNamespaces(mNewRtx));
                LOGWRAPPER.debug("name: " + name.getLocalName());
                builder.setQName(name);
            }
        } else {
            LOGWRAPPER.debug("text: " + text);
            if (currDiff == DiffType.DELETED || currDiff == DiffType.MOVEDFROM || currDiff == DiffType.REPLACEDOLD) {
                builder.setOldText(text);
                builder.setOldKey(mOldRtx.getNodeKey());
            } else {
                builder.setText(text);
            }
        }
        updated(diffCont.getDiff(), builder);
        final SunburstItem item = builder.build();
        if (item.getDiff() == DiffType.MOVEDFROM) {
            LOGWRAPPER.debug("movedToIndex: " + diffCont.getIndex());
            item.setIndexMovedTo(diffCont.getIndex() - mAxis.getPrunedNodes());
        }
        mItems.add(item);
        // Set depth max.
        mNewDepthMax = Math.max(depth, mNewDepthMax);
    }
    return extension;
}
Also used : DiffTuple(org.sirix.diff.DiffTuple) NodeRelations(org.sirix.gui.view.sunburst.NodeRelations) DiffType(org.sirix.diff.DiffFactory.DiffType) QNm(org.brackit.xquery.atomic.QNm) NodeReadTrx(org.sirix.api.NodeReadTrx) SunburstItem(org.sirix.gui.view.sunburst.SunburstItem) EStructType(org.sirix.gui.view.sunburst.SunburstItem.EStructType) ExecutionException(java.util.concurrent.ExecutionException)

Example 70 with QNm

use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.

the class StAXDiffSerializer method emitEndTag.

/**
 * Emit end tag.
 *
 * @param pRTX
 *          sirix reading transaction {@link NodeReadTrx}.
 */
private void emitEndTag(final NodeReadTrx pRTX) {
    assert pRTX != null;
    final long nodeKey = pRTX.getNodeKey();
    final QNm name = pRTX.getName();
    mEvent = mFac.createEndElement(new QName(name.getNamespaceURI(), name.getLocalName(), name.getPrefix()), new NamespaceIterator(pRTX));
    pRTX.moveTo(nodeKey);
}
Also used : QNm(org.brackit.xquery.atomic.QNm) QName(javax.xml.namespace.QName)

Aggregations

QNm (org.brackit.xquery.atomic.QNm)89 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)20 Test (org.junit.Test)18 QueryException (org.brackit.xquery.QueryException)15 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)15 DBNode (org.sirix.xquery.node.DBNode)12 QName (javax.xml.namespace.QName)11 PathSummaryReader (org.sirix.index.path.summary.PathSummaryReader)11 IndexController (org.sirix.access.IndexController)10 IndexDef (org.sirix.index.IndexDef)10 Item (org.brackit.xquery.xdm.Item)7 Axis (org.sirix.api.Axis)7 DescendantAxis (org.sirix.axis.DescendantAxis)7 SirixException (org.sirix.exception.SirixException)7 Attribute (javax.xml.stream.events.Attribute)5 Namespace (javax.xml.stream.events.Namespace)5 DocumentException (org.brackit.xquery.xdm.DocumentException)5 SirixIOException (org.sirix.exception.SirixIOException)5 Ignore (org.junit.Ignore)4 SirixUsageException (org.sirix.exception.SirixUsageException)4