Search in sources :

Example 1 with VirtualGraph

use of apoc.result.VirtualGraph in project neo4j-apoc-procedures by neo4j-contrib.

the class Graphs method fromCypher.

@Description("apoc.graph.fromCypher('statement',{params},'name',{properties}) - creates a virtual graph object for later processing")
@Procedure
public Stream<VirtualGraph> fromCypher(@Name("statement") String statement, @Name("params") Map<String, Object> params, @Name("name") String name, @Name("properties") Map<String, Object> properties) {
    params = params == null ? Collections.emptyMap() : params;
    Set<Node> nodes = new HashSet<>(1000);
    Set<Relationship> rels = new HashSet<>(1000);
    Map<String, Object> props = new HashMap<>(properties);
    db.execute(Cypher.withParamMapping(statement, params.keySet()), params).stream().forEach(row -> {
        row.forEach((k, v) -> {
            if (!extract(v, nodes, rels)) {
                props.put(k, v);
            }
        });
    });
    return Stream.of(new VirtualGraph(name, nodes, rels, props));
}
Also used : VirtualGraph(apoc.result.VirtualGraph) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Example 2 with VirtualGraph

use of apoc.result.VirtualGraph in project neo4j-apoc-procedures by neo4j-contrib.

the class Graphs method fromPaths.

@Description("apoc.graph.fromPaths([paths],'name',{properties}) - creates a virtual graph object for later processing")
@Procedure
public Stream<VirtualGraph> fromPaths(@Name("paths") List<Path> paths, @Name("name") String name, @Name("properties") Map<String, Object> properties) {
    List<Node> nodes = new ArrayList<>(1000);
    List<Relationship> rels = new ArrayList<>(1000);
    for (Path path : paths) {
        Iterables.addAll(nodes, path.nodes());
        Iterables.addAll(rels, path.relationships());
    }
    return Stream.of(new VirtualGraph(name, nodes, rels, properties));
}
Also used : Path(org.neo4j.graphdb.Path) VirtualGraph(apoc.result.VirtualGraph) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Example 3 with VirtualGraph

use of apoc.result.VirtualGraph in project neo4j-apoc-procedures by neo4j-contrib.

the class Graphs method from.

@Description("apoc.graph.from(data,'name',{properties}) | creates a virtual graph object for later processing it tries its best to extract the graph information from the data you pass in")
@Procedure
public Stream<VirtualGraph> from(@Name("data") Object data, @Name("name") String name, @Name("properties") Map<String, Object> properties) {
    Set<Node> nodes = new HashSet<>(1000);
    Set<Relationship> rels = new HashSet<>(10000);
    extract(data, nodes, rels);
    return Stream.of(new VirtualGraph(name, nodes, rels, properties));
}
Also used : VirtualGraph(apoc.result.VirtualGraph) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Aggregations

VirtualGraph (apoc.result.VirtualGraph)3 Node (org.neo4j.graphdb.Node)3 Relationship (org.neo4j.graphdb.Relationship)3 Description (org.neo4j.procedure.Description)3 Procedure (org.neo4j.procedure.Procedure)3 Path (org.neo4j.graphdb.Path)1