Package com.thinkaurelius.titan.core

Examples of com.thinkaurelius.titan.core.TitanTransaction


        super(metaGraph, jobId, projectId, branchId, srcGraphId, dstGraphId);
    }

    @Override
    public void copyGraph(DendriteGraph srcGraph, DendriteGraph dstGraph) {
        TitanTransaction srcTx = srcGraph.newTransaction();
        TitanTransaction dstTx = dstGraph.newTransaction();

        snapshotVertices(srcTx, dstTx);
        snapshotEdges(srcTx, dstTx);

        dstTx.commit();
        srcTx.commit();
    }
View Full Code Here


        logger.debug("faunusCountDegrees: finished job: " + jobId);
    }


    private void createIndices(DendriteGraph graph) {
        TitanTransaction tx = graph.newTransaction();

        if (tx.getType("in_degrees") == null) {
            tx.makeKey("in_degrees")
                    .dataType(Integer.class)
                    .indexed(DendriteGraph.INDEX_NAME, Vertex.class)
                    .make();
        }

        if (tx.getType("out_degrees") == null) {
            tx.makeKey("out_degrees")
                    .dataType(Integer.class)
                    .indexed(DendriteGraph.INDEX_NAME, Vertex.class)
                    .make();
        }

        if (tx.getType("degrees") == null) {
            tx.makeKey("degrees")
                    .dataType(Integer.class)
                    .indexed(DendriteGraph.INDEX_NAME, Vertex.class)
                    .make();
        }

        tx.commit();
    }
View Full Code Here

        logger.debug("Snap " + algorithm + ": finished job: " + jobId);
    }

    private void createIndices(DendriteGraph graph, String algorithm) {
        TitanTransaction tx = graph.newTransaction();

        if (algorithm.equals("centrality")) {
            if (tx.getType("snap_degree") == null) {
                tx.makeKey("snap_degree")
                        .dataType(FullDouble.class)
                        .indexed(DendriteGraph.INDEX_NAME, Vertex.class)
                        .make();
            }
            if (tx.getType("snap_closeness") == null) {
                tx.makeKey("snap_closeness")
                        .dataType(FullDouble.class)
                        .indexed(DendriteGraph.INDEX_NAME, Vertex.class)
                        .make();
            }
            if (tx.getType("snap_betweenness") == null) {
                tx.makeKey("snap_betweenness")
                        .dataType(FullDouble.class)
                        .indexed(DendriteGraph.INDEX_NAME, Vertex.class)
                        .make();
            }
            if (tx.getType("snap_eigenvector") == null) {
                tx.makeKey("snap_eigenvector")
                        .dataType(FullDouble.class)
                        .indexed(DendriteGraph.INDEX_NAME, Vertex.class)
                        .make();
            }
            if (tx.getType("snap_network_constraint") == null) {
                tx.makeKey("snap_network_constraint")
                        .dataType(FullDouble.class)
                        .indexed(DendriteGraph.INDEX_NAME, Vertex.class)
                        .make();
            }
            if (tx.getType("snap_clustering_coefficient") == null) {
                tx.makeKey("snap_clustering_coefficient")
                        .dataType(FullDouble.class)
                        .indexed(DendriteGraph.INDEX_NAME, Vertex.class)
                        .make();
            }
            if (tx.getType("snap_pagerank") == null) {
                tx.makeKey("snap_pagerank")
                        .dataType(FullDouble.class)
                        .indexed(DendriteGraph.INDEX_NAME, Vertex.class)
                        .make();
            }
            if (tx.getType("snap_hub_score") == null) {
                tx.makeKey("snap_hub_score")
                        .dataType(FullDouble.class)
                        .indexed(DendriteGraph.INDEX_NAME, Vertex.class)
                        .make();
            }
            if (tx.getType("snap_authority_score") == null) {
                tx.makeKey("snap_authority_score")
                        .dataType(FullDouble.class)
                        .indexed(DendriteGraph.INDEX_NAME, Vertex.class)
                        .make();
            }
        }

        tx.commit();
    }
View Full Code Here

        }
    }

    private void runImport(DendriteGraph graph, FileSystem fs, Path importDir, String algorithm) throws IOException {
        // FIXME this is due to the AdjacencyFileInputFormat not properly creating edges
        TitanTransaction tx = graph.newTransaction();

        try {
            for (FileStatus status: fs.listStatus(importDir)) {
                BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(status.getPath())));
                String line;

                // get rid of header
                line = br.readLine();
                for (int i = 0; i < 3; i++) {
                    line = br.readLine();
                }

                while (line != null) {
                    String[] parts;
                    parts = line.split("\t");

                    String id = parts[0];
                    if (algorithm.equals("centrality")) {
                        double degree = Double.valueOf(parts[1]);
                        double closeness = Double.valueOf(parts[2]);
                        double betweenness = Double.valueOf(parts[3]);
                        double eigenvector = Double.valueOf(parts[4]);
                        double networkConstraint = Double.valueOf(parts[5]);
                        double clusteringCoefficient = Double.valueOf(parts[6]);
                        double pagerank = Double.valueOf(parts[7]);
                        double hubScore = Double.valueOf(parts[8]);
                        double authorityScore = Double.valueOf(parts[9]);

                        // feed snap output as input for updating each vertex
                        Vertex vertex = tx.getVertex(id);
                        vertex.setProperty("snap_degree", degree);
                        vertex.setProperty("snap_closeness", closeness);
                        vertex.setProperty("snap_betweenness", betweenness);
                        vertex.setProperty("snap_eigenvector", eigenvector);
                        vertex.setProperty("snap_network_constraint", networkConstraint);
                        vertex.setProperty("snap_clustering_coefficient", clusteringCoefficient);
                        vertex.setProperty("snap_pagerank", pagerank);
                        vertex.setProperty("snap_hub_score", hubScore);
                        vertex.setProperty("snap_authority_score", authorityScore);
                    } else {
                        double value = Double.valueOf(parts[1]);

                        // feed snap output as input for updating each vertex
                        Vertex vertex = tx.getVertex(id);
                        vertex.setProperty("snap_" + algorithm, value);
                    }
                    line = br.readLine();
                }
            }
        } catch (Exception e) {
            tx.rollback();
            throw e;
        }

        tx.commit();
    }
View Full Code Here

    protected void copyIndices(DendriteGraph srcGraph, DendriteGraph dstGraph) {
        // This is very much a hack, but unfortunately Titan does not yet expose a proper way to copy indices from
        // one graph to another.

        TitanTransaction srcTx = srcGraph.newTransaction();
        DendriteGraphTx dstTx = dstGraph.newTransaction();

        for(TitanKey titanKey: srcTx.getTypes(TitanKey.class)) {
            if (titanKey instanceof TitanKeyVertex) {
                TitanKeyVertex keyVertex = (TitanKeyVertex) titanKey;
                TypeAttribute.Map definition = getDefinition(keyVertex);
                if (dstTx.getType(keyVertex.getName()) == null) {
                    dstTx.makePropertyKey(keyVertex.getName(), definition);
                }
            }
        }

        for(TitanLabel titanLabel: srcTx.getTypes(TitanLabel.class)) {
            TitanLabelVertex keyVertex = (TitanLabelVertex) titanLabel;
            TypeAttribute.Map definition = getDefinition(keyVertex);
            if (dstTx.getType(keyVertex.getName()) == null) {
                dstTx.makeEdgeLabel(keyVertex.getName(), definition);
            }
        }

        dstTx.commit();
        srcTx.commit();
    }
View Full Code Here

                .setQuery(queryBuilder)
                .setSize(SIZE)
                .setSearchType(SearchType.SCAN)
                .setScroll(new TimeValue(60000));

        TitanTransaction srcTx = srcGraph.newTransaction();

        try {
            TitanTransaction dstTx = dstGraph.newTransaction();

            try {
                for (SearchHit hit: scan(srcGraph.getElasticSearchClient(), srb)) {
                    Vertex vertex = srcTx.getVertex(hit.getId());
                    copyVertex(srcTx, dstTx, vertex, 0);
                }
            } catch (Exception e) {
                dstTx.rollback();
                throw e;
            }

            dstTx.commit();
        } catch (Exception e) {
            srcTx.rollback();
            throw e;
        }
View Full Code Here

        logger.debug("GraphLab " + algorithm + ": finished job: " + jobId);
    }

    private void createIndices(DendriteGraph graph, String algorithm) {
        TitanTransaction tx = graph.newTransaction();

        if (tx.getType("graphlab_"+algorithm) == null) {
            tx.makeKey("graphlab_"+algorithm)
                    .dataType(FullDouble.class)
                    .indexed(DendriteGraph.INDEX_NAME, Vertex.class)
                    .make();
        }

        tx.commit();
    }
View Full Code Here

        logger.debug("process exited with " + exitCode);
    }

    private void runImport(DendriteGraph graph, FileSystem fs, Path importDir, String algorithm) throws IOException {
        // FIXME this is due to the AdjacencyFileInputFormat not properly creating edges
        TitanTransaction tx = graph.newTransaction();

        try {
            for (FileStatus status: fs.listStatus(importDir)) {
                BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(status.getPath())));
                String line;
                line = br.readLine();
                while (line != null) {
                    String[] parts;
                    if (algorithm.equals("connected_component") || algorithm.equals("connected_component_stats")) {
                        parts = line.split(",");
                    } else {
                        parts = line.split("\t");
                    }

                    String id = parts[0];
                    double value = Double.valueOf(parts[1]);

                    // feed graphlab output as input for updating each vertex
                    Vertex vertex = tx.getVertex(id);
                    vertex.setProperty("graphlab_" + algorithm, value);

                    line = br.readLine();
                }
            }
        } catch (Exception e) {
            tx.rollback();
            throw e;
        }

        tx.commit();
    }
View Full Code Here

            gen.generate(g, schema.getEdgeCount());
        }

        g.commit();

        TitanTransaction tx = g.newTransaction();
        // Add a vertex that has an out edge to every other vertex
        Vertex hiOutDeg = tx.addVertex(Schema.SUPERNODE_UID);
        String label = schema.getSupernodeOutLabel();
        TitanKey uidKey = tx.getPropertyKey(Schema.UID_PROP);
        hiOutDeg.setProperty(Schema.UID_PROP, Schema.SUPERNODE_UID);
        String pKey = schema.getSortKeyForLabel(label);
        for (long i = INITIAL_VERTEX_UID; i < schema.getVertexCount(); i++) {
            Vertex in = tx.getVertex(uidKey, i);
            Edge e = hiOutDeg.addEdge(label, in);
            e.setProperty(pKey, (int) i);
        }

        tx.commit();
    }
View Full Code Here


    public void makeTypes(TitanGraph g) {
        Preconditions.checkArgument(edgeLabels <= edgePropKeys);

        TitanTransaction tx = g.newTransaction();
        for (int i = 0; i < vertexPropKeys; i++) {
            tx.makeKey(getVertexPropertyName(i)).dataType(Integer.class).indexed(Vertex.class).single().make();
        }
        for (int i = 0; i < edgePropKeys; i++) {
            tx.makeKey(getEdgePropertyName(i)).dataType(Integer.class).indexed(Edge.class).single().make();
        }
        for (int i = 0; i < edgeLabels; i++) {
            String labelName = getEdgeLabelName(i);
            String pkName = getSortKeyForLabel(labelName);
            TitanKey pk = tx.getPropertyKey(pkName);
            tx.makeLabel(getEdgeLabelName(i)).sortKey(pk).make();
        }

        tx.makeKey(UID_PROP).dataType(Long.class).indexed(Vertex.class).single().unique().make();
        tx.commit();
    }
View Full Code Here

TOP

Related Classes of com.thinkaurelius.titan.core.TitanTransaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.