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();
}
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);
}
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();
}
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));
}
}
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);
}
Aggregations