Module: Legion::Extensions::Neo4j::Runners::GraphDataScience
- Includes:
- Helpers::Lex, Helpers::Client
- Included in:
- Client
- Defined in:
- lib/legion/extensions/neo4j/runners/graph_data_science.rb
Instance Method Summary collapse
- #drop_graph(name:, database: 'neo4j', url: nil, username: nil, password: nil, read_only: false) ⇒ Object
- #list_graphs(database: 'neo4j', url: nil, username: nil, password: nil) ⇒ Object
- #project_graph(name:, node_projection:, relationship_projection:, database: 'neo4j', url: nil, username: nil, password: nil, read_only: false) ⇒ Object
- #run_louvain(graph_name:, write_property: nil, database: 'neo4j', url: nil, username: nil, password: nil, read_only: false) ⇒ Object
- #run_node_similarity(graph_name:, limit: 25, database: 'neo4j', url: nil, username: nil, password: nil) ⇒ Object
- #run_pagerank(graph_name:, write_property: nil, database: 'neo4j', url: nil, username: nil, password: nil, read_only: false) ⇒ Object
Methods included from Helpers::Client
Instance Method Details
#drop_graph(name:, database: 'neo4j', url: nil, username: nil, password: nil, read_only: false) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/legion/extensions/neo4j/runners/graph_data_science.rb', line 28 def drop_graph(name:, database: 'neo4j', url: nil, username: nil, password: nil, read_only: false, **) raise ReadOnlyError, 'Write operations disabled (read_only mode)' if read_only execute_cypher('CALL gds.graph.drop($name)', parameters: { name: name }, database: database, url: url, username: username, password: password) end |
#list_graphs(database: 'neo4j', url: nil, username: nil, password: nil) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/legion/extensions/neo4j/runners/graph_data_science.rb', line 12 def list_graphs(database: 'neo4j', url: nil, username: nil, password: nil, **) execute_cypher('CALL gds.graph.list() YIELD graphName, nodeCount, relationshipCount ' \ 'RETURN graphName, nodeCount, relationshipCount', parameters: {}, database: database, url: url, username: username, password: password) end |
#project_graph(name:, node_projection:, relationship_projection:, database: 'neo4j', url: nil, username: nil, password: nil, read_only: false) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/legion/extensions/neo4j/runners/graph_data_science.rb', line 19 def project_graph(name:, node_projection:, relationship_projection:, database: 'neo4j', url: nil, username: nil, password: nil, read_only: false, **) raise ReadOnlyError, 'Write operations disabled (read_only mode)' if read_only execute_cypher('CALL gds.graph.project($name, $nodes, $rels)', parameters: { name: name, nodes: node_projection, rels: relationship_projection }, database: database, url: url, username: username, password: password) end |
#run_louvain(graph_name:, write_property: nil, database: 'neo4j', url: nil, username: nil, password: nil, read_only: false) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/legion/extensions/neo4j/runners/graph_data_science.rb', line 54 def run_louvain(graph_name:, write_property: nil, database: 'neo4j', url: nil, username: nil, password: nil, read_only: false, **) if write_property raise ReadOnlyError, 'Write operations disabled (read_only mode)' if read_only execute_cypher('CALL gds.louvain.write($name, {writeProperty: $prop}) ' \ 'YIELD communityCount, modularity', parameters: { name: graph_name, prop: write_property }, database: database, url: url, username: username, password: password) else execute_cypher('CALL gds.louvain.stream($name) YIELD nodeId, communityId ' \ 'RETURN gds.util.asNode(nodeId).name AS name, communityId ' \ 'ORDER BY communityId LIMIT 100', parameters: { name: graph_name }, database: database, url: url, username: username, password: password) end end |
#run_node_similarity(graph_name:, limit: 25, database: 'neo4j', url: nil, username: nil, password: nil) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/legion/extensions/neo4j/runners/graph_data_science.rb', line 72 def run_node_similarity(graph_name:, limit: 25, database: 'neo4j', url: nil, username: nil, password: nil, **) execute_cypher('CALL gds.nodeSimilarity.stream($name) YIELD node1, node2, similarity ' \ 'RETURN gds.util.asNode(node1).name AS from, ' \ 'gds.util.asNode(node2).name AS to, similarity ' \ 'ORDER BY similarity DESC LIMIT $limit', parameters: { name: graph_name, limit: limit }, database: database, url: url, username: username, password: password) end |
#run_pagerank(graph_name:, write_property: nil, database: 'neo4j', url: nil, username: nil, password: nil, read_only: false) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/legion/extensions/neo4j/runners/graph_data_science.rb', line 36 def run_pagerank(graph_name:, write_property: nil, database: 'neo4j', url: nil, username: nil, password: nil, read_only: false, **) if write_property raise ReadOnlyError, 'Write operations disabled (read_only mode)' if read_only execute_cypher('CALL gds.pageRank.write($name, {writeProperty: $prop}) ' \ 'YIELD nodePropertiesWritten, ranIterations', parameters: { name: graph_name, prop: write_property }, database: database, url: url, username: username, password: password) else execute_cypher('CALL gds.pageRank.stream($name) YIELD nodeId, score ' \ 'RETURN gds.util.asNode(nodeId).name AS name, score ' \ 'ORDER BY score DESC LIMIT 25', parameters: { name: graph_name }, database: database, url: url, username: username, password: password) end end |