Search in sources :

Example 1 with ProgressInfo

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

the class Gephi method add.

// http://127.0.0.1:8080/workspace0?operation=updateGraph
// TODO configure property-filters or transfer all properties
@Procedure
@Description("apoc.gephi.add(url-or-key, workspace, data, weightproperty, ['exportproperty']) | streams passed in data to Gephi")
public Stream<ProgressInfo> add(@Name("urlOrKey") String keyOrUrl, @Name("workspace") String workspace, @Name("data") Object data, @Name(value = "weightproperty", defaultValue = "null") String weightproperty, @Name(value = "exportproperties", defaultValue = "[]") List<String> exportproperties) {
    if (workspace == null)
        workspace = "workspace0";
    String url = getGephiUrl(keyOrUrl) + "/" + Util.encodeUrlComponent(workspace) + "?operation=updateGraph";
    long start = System.currentTimeMillis();
    HashSet<Node> nodes = new HashSet<>(1000);
    HashSet<Relationship> rels = new HashSet<>(10000);
    List<String> propertyNames = new ArrayList<>(exportproperties);
    propertyNames.removeAll(RESERVED);
    if (Graphs.extract(data, nodes, rels)) {
        String payload = toGephiStreaming(nodes, rels, weightproperty, propertyNames.toArray(new String[propertyNames.size()]));
        JsonUtil.loadJson(url, map("method", "POST", "Content-Type", "application/json; charset=utf-8"), payload).count();
        return Stream.of(new ProgressInfo(url, "graph", "gephi").update(nodes.size(), rels.size(), nodes.size()).done(start));
    }
    return Stream.empty();
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) ProgressInfo(apoc.result.ProgressInfo) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Example 2 with ProgressInfo

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

the class Examples method movies.

@Procedure(mode = Mode.WRITE)
@Description("apoc.example.movies() | Creates the sample movies graph")
public Stream<ProgressInfo> movies() {
    long start = System.currentTimeMillis();
    String file = "movies.cypher";
    Result result = db.execute(Util.readResourceFile(file));
    QueryStatistics stats = result.getQueryStatistics();
    ProgressInfo progress = new ProgressInfo(file, "example movie database from themoviedb.org", "cypher").update(stats.getNodesCreated(), stats.getRelationshipsCreated(), stats.getPropertiesSet()).done(start);
    result.close();
    return Stream.of(progress);
}
Also used : QueryStatistics(org.neo4j.graphdb.QueryStatistics) ProgressInfo(apoc.result.ProgressInfo) Result(org.neo4j.graphdb.Result) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Example 3 with ProgressInfo

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

the class ExportCSV method exportCsv.

private Stream<ProgressInfo> exportCsv(@Name("file") String fileName, String source, Object data, Map<String, Object> config) throws Exception {
    checkWriteAllowed();
    ExportConfig c = new ExportConfig(config);
    ProgressReporter reporter = new ProgressReporter(null, null, new ProgressInfo(fileName, source, "csv"));
    PrintWriter printWriter = getPrintWriter(fileName, null);
    CsvFormat exporter = new CsvFormat(db);
    if (data instanceof SubGraph)
        exporter.dump(((SubGraph) data), printWriter, reporter, c);
    if (data instanceof Result)
        exporter.dump(((Result) data), printWriter, reporter, c);
    return reporter.stream();
}
Also used : ExportConfig(apoc.export.util.ExportConfig) ProgressInfo(apoc.result.ProgressInfo) ProgressReporter(apoc.export.util.ProgressReporter) SubGraph(org.neo4j.cypher.export.SubGraph) NodesAndRelsSubGraph(apoc.export.util.NodesAndRelsSubGraph) DatabaseSubGraph(org.neo4j.cypher.export.DatabaseSubGraph) PrintWriter(java.io.PrintWriter) FileUtils.getPrintWriter(apoc.util.FileUtils.getPrintWriter) Result(org.neo4j.graphdb.Result)

Example 4 with ProgressInfo

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

the class ExportCypher method exportCypher.

private Stream<DataProgressInfo> exportCypher(@Name("file") String fileName, String source, SubGraph graph, ExportConfig c, boolean onlySchema) throws IOException {
    if (fileName != null)
        checkWriteAllowed();
    ProgressInfo progressInfo = new ProgressInfo(fileName, source, "cypher");
    progressInfo.batchSize = c.getBatchSize();
    ProgressReporter reporter = new ProgressReporter(null, null, progressInfo);
    boolean separatedFiles = !onlySchema && c.separateFiles();
    FileManagerFactory.ExportCypherFileManager cypherFileManager = FileManagerFactory.createFileManager(fileName, separatedFiles, c.streamStatements());
    if (c.streamStatements()) {
        Future<Boolean> future = null;
        try {
            final ArrayBlockingQueue<DataProgressInfo> queue = new ArrayBlockingQueue<>(100);
            ProgressReporter reporterWithConsumer = reporter.withConsumer((pi) -> queue.offer(pi == ProgressInfo.EMPTY ? DataProgressInfo.EMPTY : new DataProgressInfo(pi).enrich(cypherFileManager)));
            future = Util.inTxFuture(Pools.DEFAULT, db, () -> {
                doExport(graph, c, onlySchema, reporterWithConsumer, cypherFileManager);
                return true;
            });
            QueueBasedSpliterator<DataProgressInfo> spliterator = new QueueBasedSpliterator<>(queue, DataProgressInfo.EMPTY, terminationGuard);
            return StreamSupport.stream(spliterator, false);
        } finally {
            Util.waitForFutures(Collections.singletonList(future));
        }
    } else {
        doExport(graph, c, onlySchema, reporter, cypherFileManager);
        return reporter.stream().map(DataProgressInfo::new).map((dpi) -> dpi.enrich(cypherFileManager));
    }
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) QueueBasedSpliterator(apoc.util.QueueBasedSpliterator) ProgressInfo(apoc.result.ProgressInfo) ProgressReporter(apoc.export.util.ProgressReporter)

Example 5 with ProgressInfo

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

the class ExportGraphML method file.

@Procedure(name = "apoc.import.graphml", mode = Mode.WRITE)
@Description("apoc.import.graphml(file,config) - imports graphml file")
public Stream<ProgressInfo> file(@Name("file") String fileName, @Name("config") Map<String, Object> config) throws Exception {
    ProgressInfo result = Util.inThread(() -> {
        ExportConfig exportConfig = new ExportConfig(config);
        ProgressReporter reporter = new ProgressReporter(null, null, new ProgressInfo(fileName, "file", "graphml"));
        XmlGraphMLReader graphMLReader = new XmlGraphMLReader(db).reporter(reporter).batchSize(exportConfig.getBatchSize()).relType(exportConfig.defaultRelationshipType()).nodeLabels(exportConfig.readLabels());
        if (exportConfig.storeNodeIds())
            graphMLReader.storeNodeIds();
        graphMLReader.parseXML(FileUtils.readerFor(fileName));
        return reporter.getTotal();
    });
    return Stream.of(result);
}
Also used : ExportConfig(apoc.export.util.ExportConfig) ProgressInfo(apoc.result.ProgressInfo) ProgressReporter(apoc.export.util.ProgressReporter)

Aggregations

ProgressInfo (apoc.result.ProgressInfo)6 ProgressReporter (apoc.export.util.ProgressReporter)4 ExportConfig (apoc.export.util.ExportConfig)2 FileUtils.getPrintWriter (apoc.util.FileUtils.getPrintWriter)2 PrintWriter (java.io.PrintWriter)2 Result (org.neo4j.graphdb.Result)2 Description (org.neo4j.procedure.Description)2 Procedure (org.neo4j.procedure.Procedure)2 NodesAndRelsSubGraph (apoc.export.util.NodesAndRelsSubGraph)1 QueueBasedSpliterator (apoc.util.QueueBasedSpliterator)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 DatabaseSubGraph (org.neo4j.cypher.export.DatabaseSubGraph)1 SubGraph (org.neo4j.cypher.export.SubGraph)1 Node (org.neo4j.graphdb.Node)1 QueryStatistics (org.neo4j.graphdb.QueryStatistics)1 Relationship (org.neo4j.graphdb.Relationship)1