Package com.thinkaurelius.faunus

Examples of com.thinkaurelius.faunus.FaunusEdge


     */
    public static void inputGraph(final Graph inputGraph, final InputStream inputStream, int bufferSize) throws IOException {
      // titan requires creation of vertices before edges
      // unless enabling the option to set vertex id upon creation,
      // use a map to store the idFaunus->idBlueprints transformation
      FaunusEdge fe;
      Vertex vertexIn, vertexOut;
      long faunusIdIn, faunusIdOut, blueprintsIdIn, blueprintsIdOut;
      HashMap<Long, Long> faunusToBlueprintsId = new HashMap<Long, Long>();

      // if this is a transactional graph then we're buffering
      final BatchGraph graph = BatchGraph.wrap(inputGraph, bufferSize);

      // load list of vertices
      List<FaunusVertex> faunusVertexList = FaunusGraphSONUtility.fromJSON(inputStream);

      // add vertices w/ properties to graph, also saving id->id mapping for edge creation
      Vertex blueprintsVertex;
      for (FaunusVertex faunusVertex : faunusVertexList) {
        blueprintsVertex = graph.addVertex(faunusVertex.getIdAsLong());
        for (String property : faunusVertex.getPropertyKeys()) {
          blueprintsVertex.setProperty(property, faunusVertex.getProperty(property));
        }
        faunusToBlueprintsId.put(faunusVertex.getIdAsLong(), (Long) blueprintsVertex.getId());
      }

      // add edges between vertices
      for (FaunusVertex faunusVertex : faunusVertexList) {
        for (Edge edge : faunusVertex.getEdges(Direction.BOTH)) {
            fe = (FaunusEdge) edge;

            // retrieve the vertices stored in the graph
            faunusIdIn = fe.getVertexId(Direction.IN);
            blueprintsIdIn = faunusToBlueprintsId.get(faunusIdIn);
            faunusIdOut = fe.getVertexId(Direction.OUT);
            blueprintsIdOut = faunusToBlueprintsId.get(faunusIdOut);
            vertexIn = graph.getVertex(blueprintsIdIn);
            vertexOut = graph.getVertex(blueprintsIdOut);

            // save the edge to the graph
            graph.addEdge(null, vertexIn, vertexOut, fe.getLabel());
        }
      }

      // commit changes to the graph
      graph.commit();
View Full Code Here


    private static void fromJSONEdges(final FaunusVertex vertex, final JSONArray edges, final Direction direction) throws JSONException, IOException {
        if (null != edges) {
            for (int i = 0; i < edges.length(); i++) {
                final JSONObject edge = edges.optJSONObject(i);
                FaunusEdge faunusEdge = null;
                if (direction.equals(Direction.IN)) {
                    faunusEdge = (FaunusEdge) graphson.edgeFromJson(edge, new FaunusVertex(edge.optLong(GraphSONTokens._OUT_V)), vertex);
                } else if (direction.equals(Direction.OUT)) {
                    faunusEdge = (FaunusEdge) graphson.edgeFromJson(edge, vertex, new FaunusVertex(edge.optLong(GraphSONTokens._IN_V)));
                }
View Full Code Here

    }

    private static class FaunusElementFactory implements ElementFactory<FaunusVertex, FaunusEdge> {
        @Override
        public FaunusEdge createEdge(final Object id, final FaunusVertex out, final FaunusVertex in, final String label) {
            return new FaunusEdge(convertIdentifier(id), out.getIdAsLong(), in.getIdAsLong(), label);
        }
View Full Code Here

            if (this.type.isPropertyKey()) {
                Preconditions.checkNotNull(value);
                vertex.setProperty(this.type.getName(), this.value);
            } else {
                Preconditions.checkArgument(this.type.isEdgeLabel());
                FaunusEdge edge = null;
                if (this.direction.equals(Direction.IN))
                    edge = new FaunusEdge(this.relationID, this.otherVertexID, getVertexID(), this.type.getName());
                else if (this.direction.equals(Direction.OUT))
                    edge = new FaunusEdge(this.relationID, getVertexID(), this.otherVertexID, this.type.getName());
                else if (this.direction.equals(Direction.BOTH))
                    throw ExceptionFactory.bothIsNotSupported();

                if (null != edge) {
                    // load edge properties
                    for (final Map.Entry<String, Object> entry : this.properties.entrySet()) {
                        if (entry.getValue() != null) {
                            edge.setProperty(entry.getKey(), entry.getValue());
                        }
                    }
                    vertex.addEdge(this.direction, edge);
                }
            }
View Full Code Here

                    context.getCounter(Counters.VERTICES_PROCESSED).increment(1);
                }
            } else {
                long edgesProcessed = 0;
                for (final Edge e : value.getEdges(Direction.OUT)) {
                    final FaunusEdge edge = (FaunusEdge) e;
                    if (edge.hasPaths()) {
                        edgesProcessed++;
                        //for (int i = 0; i < edge.pathCount(); i++) {
                        this.closure.call(edge);
                        //}
                    }
View Full Code Here

                    context.getCounter(Counters.VERTICES_PROCESSED).increment(1l);
                }
            } else {
                long edgesProcessed = 0;
                for (final Edge e : value.getEdges(Direction.OUT)) {
                    final FaunusEdge edge = (FaunusEdge) e;
                    if (edge.hasPaths()) {
                        final Object object = (null == this.keyClosure) ? new FaunusEdge.MicroEdge(edge.getIdAsLong()) : this.keyClosure.call(edge);
                        final Number number = (null == this.valueClosure) ? 1 : (Number) this.valueClosure.call(edge);
                        this.map.incr(object, number.longValue() * edge.pathCount());
                        edgesProcessed++;
                    }
                }
                context.getCounter(Counters.OUT_EDGES_PROCESSED).increment(edgesProcessed);
            }
View Full Code Here

                    context.getCounter(Counters.VERTICES_FILTERED).increment(1l);
                }
            } else {
                long edgesFiltered = 0;
                for (Edge e : value.getEdges(Direction.BOTH)) {
                    final FaunusEdge edge = (FaunusEdge) e;
                    if (edge.hasPaths() && !this.elementChecker.isLegal(edge)) {
                        edge.clearPaths();
                        edgesFiltered++;
                    }
                }
                context.getCounter(Counters.EDGES_FILTERED).increment(edgesFiltered);
            }
View Full Code Here

            if (this.useFragments)
                object.setProperty(RDFInputFormat.NAME, createFragment(s.getObject()));
            object.enablePath(this.enablePath);
            this.queue.add(object);

            final FaunusEdge predicate = new FaunusEdge(-1, subjectId, objectId, postProcess(s.getPredicate()));
            predicate.setProperty(RDFInputFormat.URI, s.getPredicate().stringValue());
            if (null != s.getContext())
                predicate.setProperty(RDFInputFormat.CONTEXT, s.getContext().stringValue());
            predicate.enablePath(this.enablePath);
            this.queue.add(predicate);
        }
    }
View Full Code Here

                    context.getCounter(Counters.VERTICES_DEDUPED).increment(1l);
                }
            } else {
                long counter = 0;
                for (final Edge e : value.getEdges(Direction.BOTH)) {
                    final FaunusEdge edge = (FaunusEdge) e;
                    if (edge.hasPaths()) {
                        if (this.pathEnabled) {
                            final List<FaunusElement.MicroElement> path = edge.getPaths().get(0);
                            edge.clearPaths();
                            edge.addPath(path, false);
                        } else {
                            edge.clearPaths();
                            edge.startPath();
                        }
                        counter++;
                    }
                }
                context.getCounter(Counters.EDGES_DEDUPED).increment(counter);
View Full Code Here

                    context.getCounter(Counters.VERTICES_FILTERED).increment(1l);
                }
            } else {
                long counter = 0;
                for (final Edge e : value.getEdges(Direction.BOTH)) {
                    final FaunusEdge edge = (FaunusEdge) e;
                    if (edge.hasPaths() && !this.closure.call(edge)) {
                        edge.clearPaths();
                        counter++;
                    }
                }
                context.getCounter(Counters.EDGES_FILTERED).increment(counter);
            }
View Full Code Here

TOP

Related Classes of com.thinkaurelius.faunus.FaunusEdge

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.