Java Code Examples for org.neo4j.helpers.collection.IteratorUtil#count()
The following examples show how to use
org.neo4j.helpers.collection.IteratorUtil#count() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Neo4jGraphDatabase.java From graphdb-benchmarks with Apache License 2.0 | 6 votes |
@Override public int getNodeCount() { int nodeCount = 0; try (final Transaction tx = beginUnforcedTransaction()) { try { nodeCount = IteratorUtil.count(GlobalGraphOperations.at(neo4jGraph).getAllNodes()); tx.success(); } catch (Exception e) { tx.failure(); throw new BenchmarkingException("unable to get node count", e); } } return nodeCount; }
Example 2
Source File: Neo4jGraphDatabase.java From graphdb-benchmarks with Apache License 2.0 | 6 votes |
@Override public double getGraphWeightSum() { int edgeCount = 0; try (final Transaction tx = beginUnforcedTransaction()) { try { edgeCount = IteratorUtil.count(GlobalGraphOperations.at(neo4jGraph).getAllRelationships()); tx.success(); } catch (Exception e) { tx.failure(); throw new BenchmarkingException("unable to get graph weight sum", e); } } return (double) edgeCount; }
Example 3
Source File: DataImporterNorthwindTest.java From neo4j-rdbms-import with GNU General Public License v3.0 | 5 votes |
private static String importInfo() { GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(STORE_DIR); try (Transaction tx = db.beginTx()) { int nodes = IteratorUtil.count(db.getAllNodes()); int rels = IteratorUtil.count(GlobalGraphOperations.at(db).getAllRelationships()); return "Imported nodes " + nodes + " rels " + rels; } finally { db.shutdown(); } }
Example 4
Source File: DataImporterSakilaTest.java From neo4j-rdbms-import with GNU General Public License v3.0 | 5 votes |
private static String importInfo() { GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(STORE_DIR); try (Transaction tx = db.beginTx()) { int nodes = IteratorUtil.count(db.getAllNodes()); int rels = IteratorUtil.count(GlobalGraphOperations.at(db).getAllRelationships()); return "Imported nodes " + nodes + " rels " + rels; } finally { db.shutdown(); } }
Example 5
Source File: DataImporterEmployeeTest.java From neo4j-rdbms-import with GNU General Public License v3.0 | 5 votes |
private static String importInfo() { GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(STORE_DIR); try (Transaction tx = db.beginTx()) { int nodes = IteratorUtil.count(db.getAllNodes()); int rels = IteratorUtil.count(GlobalGraphOperations.at(db).getAllRelationships()); return "Imported nodes " + nodes + " rels " + rels; } finally { db.shutdown(); } }
Example 6
Source File: DataImporterTest.java From neo4j-rdbms-import with GNU General Public License v3.0 | 5 votes |
private static String assertImport() { GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(STORE_DIR); try (Transaction tx = db.beginTx()) { int nodes = IteratorUtil.count(db.getAllNodes()); Assert.assertEquals(USERS, nodes); int rels = IteratorUtil.count(GlobalGraphOperations.at(db).getAllRelationships()); Assert.assertEquals(FRIENDSHIPS, rels); return "Imported nodes " + nodes + " rels " + rels; } finally { db.shutdown(); } }
Example 7
Source File: VectorUtil.java From graphify with Apache License 2.0 | 5 votes |
public static int getDocumentSize(GraphDatabaseService db) { int documentSize; String cacheKey = "GLOBAL_DOCUMENT_SIZE"; if(vectorSpaceModelCache.getIfPresent(cacheKey) == null) { documentSize = IteratorUtil.count(GlobalGraphOperations.at(db).getAllNodesWithLabel(DynamicLabel.label("Class"))); vectorSpaceModelCache.put(cacheKey, documentSize); } else { documentSize = (Integer)vectorSpaceModelCache.getIfPresent(cacheKey); } return documentSize; }
Example 8
Source File: VectorUtil.java From graphify with Apache License 2.0 | 5 votes |
public static int getDocumentSizeForFeature(GraphDatabaseService db, Long id) { int documentSize; String cacheKey = "DOCUMENT_SIZE_FEATURE_" + id; if(vectorSpaceModelCache.getIfPresent(cacheKey) == null) { Node startNode = db.getNodeById(id); Iterator<Node> classes = db.traversalDescription() .depthFirst() .relationships(withName("HAS_CLASS"), Direction.OUTGOING) .evaluator(Evaluators.fromDepth(1)) .evaluator(Evaluators.toDepth(1)) .traverse(startNode) .nodes().iterator(); documentSize = IteratorUtil.count(classes); vectorSpaceModelCache.put(cacheKey, documentSize); } else { documentSize = (Integer)vectorSpaceModelCache.getIfPresent(cacheKey); } return documentSize; }
Example 9
Source File: Neo4jSNAMain.java From Neo4jSNA with Apache License 2.0 | 4 votes |
public static void main(String[] args) { String zipFile = "data/cineasts_12k_movies_50k_actors_2.1.6.zip"; String path = "data/cineasts_12k_movies_50k_actors.db/"; try { FileUtils.deleteRecursively(new File(path)); extractFolder(zipFile); } catch (Exception e) { e.printStackTrace(); System.exit(1); } long nodeCount, relsCount; // Open a database instance GraphDatabaseService g = new GraphDatabaseFactory() .newEmbeddedDatabaseBuilder(path) .setConfig(GraphDatabaseSettings.allow_store_upgrade, "true") .newGraphDatabase(); try (Transaction tx = g.beginTx() ) { nodeCount = IteratorUtil.count( GlobalGraphOperations.at(g).getAllNodes() ); relsCount = IteratorUtil.count( GlobalGraphOperations.at(g).getAllRelationships() ); tx.success(); } System.out.println("Node count: "+nodeCount); System.out.println("Rel count: " + relsCount); // Declare the GraphAlgoEngine on the database instance GraphAlgoEngine engine = new GraphAlgoEngine(g); if( args.length > 1 && args[1].equals("off") ) engine.disableLogging(); Louvain louvain = new Louvain(g); louvain.execute(); LouvainResult result = louvain.getResult(); for (int layer : result.layers()) { System.out.println("Layer " + layer + ": " + result.layer(layer).size() + " nodes"); } LabelPropagation lp = new LabelPropagation(); // Starts the algorithm on the given graph g engine.execute(lp); Long2LongMap communityMap = lp.getResult(); long totCommunities = new LongOpenHashSet( communityMap.values() ).size(); System.out.println("There are " + totCommunities + " communities according to Label Propagation"); DirectedModularity modularity = new DirectedModularity(g); engine.execute(modularity); System.out.println("The directed modularity of this network is " + modularity.getResult()); UndirectedModularity umodularity = new UndirectedModularity(g); engine.execute(umodularity); System.out.println("The undirected modularity of this network is " + umodularity.getResult()); engine.clean(lp); // Now you can clean Label propagation results TriangleCount tc = new TriangleCount(); engine.execute(tc); Long2LongMap triangleCount = tc.getResult(); Optional<Long> totalTriangles = triangleCount.values().stream().reduce( (x, y) -> x + y ); System.out.println("There are "+totalTriangles.get()+" triangles"); PageRank pr = new PageRank(g); engine.execute(pr); Long2DoubleMap ranks = pr.getResult(); engine.clean(pr); Optional<Double> res = ranks.values().parallelStream().reduce( (x, y) -> x + y ); System.out.println("Check PageRank sum is 1.0: "+ res.get()); ConnectedComponents cc = new ConnectedComponents(); engine.execute(cc); Long2LongMap components = cc.getResult(); engine.clean(cc); int totalComponents = new LongOpenHashSet( components.values() ).size(); System.out.println("There are "+ totalComponents+ " different connected components"); StronglyConnectedComponents scc = new StronglyConnectedComponents(); engine.execute(scc); components = scc.getResult(); engine.clean(scc); totalComponents = new LongOpenHashSet( components.values() ).size(); System.out.println("There are "+ totalComponents+ " different strongly connected components"); // Don't forget to shutdown the database g.shutdown(); }
Example 10
Source File: Writer.java From neo4j-mazerunner with Apache License 2.0 | 4 votes |
public static Path exportSubgraphToHDFS(GraphDatabaseService db) throws IOException, URISyntaxException { FileSystem fs = FileUtil.getHadoopFileSystem(); Path pt = new Path(ConfigurationLoader.getInstance().getHadoopHdfsUri() + EDGE_LIST_RELATIVE_FILE_PATH.replace("/{job_id}", "")); BufferedWriter br = new BufferedWriter(new OutputStreamWriter(fs.create(pt))); Transaction tx = db.beginTx(); // Get all nodes in the graph Iterable<Node> nodes = GlobalGraphOperations.at(db) .getAllNodes(); br.write("# Adacency list" + "\n"); int nodeTotal = IteratorUtil.count(nodes); final int[] nodeCount = {0}; final int[] pathCount = {0}; int pathCountBlocks = 10000; int size = IteratorUtil.count(nodes.iterator()); //System.out.println(nodes.spliterator().trySplit().estimateSize()); // Fork join nodes.iterator().forEachRemaining(n -> { // Filter nodes by all paths connected by the relationship type described in the configuration properties Iterable<org.neo4j.graphdb.Path> nPaths = db.traversalDescription() .depthFirst() .relationships(withName(ConfigurationLoader.getInstance().getMazerunnerRelationshipType()), Direction.OUTGOING) .evaluator(Evaluators.fromDepth(1)) .evaluator(Evaluators.toDepth(1)) .traverse(n); for (org.neo4j.graphdb.Path path : nPaths) { try { String line = path.startNode().getId() + " " + path.endNode().getId(); br.write(line + "\n"); pathCount[0]++; if (pathCount[0] > pathCountBlocks) { pathCount[0] = 0; System.out.println("Mazerunner Export Status: " + MessageFormat.format("{0,number,#%}", ((double) nodeCount[0] / (double) nodeTotal))); } } catch (Exception ex) { System.out.println(ex.getMessage()); } } nodeCount[0]++; }); System.out.println("Mazerunner Export Status: " + MessageFormat.format("{0,number,#.##%}", 1.0)); br.flush(); br.close(); tx.success(); tx.close(); return pt; }
Example 11
Source File: Neo4jGraphDatabase.java From graphdb-benchmarks with Apache License 2.0 | 4 votes |
public double getNodeInDegree(Node node) { Iterable<Relationship> rel = node.getRelationships(Direction.OUTGOING, RelTypes.SIMILAR); return (double) (IteratorUtil.count(rel)); }
Example 12
Source File: Neo4jGraphDatabase.java From graphdb-benchmarks with Apache License 2.0 | 4 votes |
public double getNodeOutDegree(Node node) { Iterable<Relationship> rel = node.getRelationships(Direction.INCOMING, RelTypes.SIMILAR); return (double) (IteratorUtil.count(rel)); }