Skip to content

Commit

Permalink
feat: phase 3 of networkx/nebula engine #32
Browse files Browse the repository at this point in the history
feat: phase 3 of networkx/nebula engine
  • Loading branch information
wey-gu authored Mar 29, 2023
2 parents b31df86 + 9268173 commit b0ac4fc
Show file tree
Hide file tree
Showing 16 changed files with 675 additions and 125 deletions.
42 changes: 41 additions & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ df.show(10)
```python
from ng_ai import NebulaReader
from ng_ai.config import NebulaGraphConfig
# read data with spark engine, query mode
# read data with nebula engine, query mode
config_dict = {
"graphd_hosts": "127.0.0.1:9669",
"user": "root",
Expand Down Expand Up @@ -197,6 +197,46 @@ MATCH (v:louvain)
RETURN id(v), v.louvain.cluster_id LIMIT 10;
```

#### NebulaGraph Engine(NetworkX) Writer

Create schema in NebulaGraph:

```ngql
CREATE TAG IF NOT EXISTS pagerank (
pagerank double NOT NULL
);
```

Assuming we have a `graph_result` computed with `graph.algo.pagerank()`:

```python
graph_result = g.algo.pagerank()
```

Then we could write the pagerank result back to NebulaGraph with the following code:

```python
from ng_ai import NebulaWriter

writer = NebulaWriter(
data=graph_result,
sink="nebulagraph_vertex",
config=config,
engine="nebula",
)

# properties to write
properties = ["pagerank"]

writer.set_options(
tag="pagerank",
properties=properties,
batch_size=256,
write_mode="insert",
)
# write back to NebulaGraph
writer.write()
```

## NebulaGNN

Expand Down
19 changes: 8 additions & 11 deletions examples/networkx_engine.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,14 @@
"metadata": {},
"outputs": [],
"source": [
"# lpa_result = df.algo.label_propagation()\n",
"# louvain_result = df.algo.louvain()\n",
"# k_core_result = df.algo.k_core()\n",
"# degree_statics_result = df.algo.degree_statics()\n",
"# betweenness_centrality_result = df.algo.betweenness_centrality()\n",
"# coefficient_centrality_result = df.algo.coefficient_centrality()\n",
"# bfs_result = df.algo.bfs()\n",
"# hanp_result = df.algo.hanp()\n",
"# jaccard_result = df.algo.jaccard()\n",
"# strong_connected_components_result = df.algo.strong_connected_components()\n",
"# triangle_count_result = df.algo.triangle_count()"
"# get all algorithms\n",
"g.algo.get_all_algo()\n",
"\n",
"# get help of each algo\n",
"help(g.algo.node2vec)\n",
"\n",
"# call the algo\n",
"g.algo.node2vec()"
]
}
],
Expand Down
3 changes: 2 additions & 1 deletion examples/ng_ai_from_ngql_udf.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "c4630751",
"metadata": {},
Expand All @@ -131,7 +132,7 @@
"CREATE TAG IF NOT EXISTS k_core(kcore string);\n",
"CREATE TAG IF NOT EXISTS degree_statics(degree int,inDegree int,outDegree int);\n",
"CREATE TAG IF NOT EXISTS betweenness_centrality(betweenness double);\n",
"CREATE TAG IF NOT EXISTS coefficient_centrality(clustercoefficient double);\n",
"CREATE TAG IF NOT EXISTS clustering_coefficient(clustercoefficient double);\n",
"CREATE TAG IF NOT EXISTS bfs(bfs string);\n",
"CREATE TAG IF NOT EXISTS hanp(hanp string);\n",
"CREATE TAG IF NOT EXISTS jaccard(jaccard string);\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/spark_engine.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@
"# k_core_result = df.algo.k_core()\n",
"# degree_statics_result = df.algo.degree_statics()\n",
"# betweenness_centrality_result = df.algo.betweenness_centrality()\n",
"# coefficient_centrality_result = df.algo.coefficient_centrality()\n",
"# clustering_coefficient_result = df.algo.clustering_coefficient()\n",
"# bfs_result = df.algo.bfs()\n",
"# hanp_result = df.algo.hanp()\n",
"# jaccard_result = df.algo.jaccard()\n",
Expand Down
4 changes: 4 additions & 0 deletions ng_ai/engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,23 @@ def __init__(self, config=None):
self.config = config

# let's make all nx related import here
import community as community_louvain
import networkx as nx
import ng_nx
from ng_nx import NebulaReader as NxReader
from ng_nx import NebulaScanReader as NxScanReader
from ng_nx import NebulaWriter as NxWriter
from ng_nx.utils import NebulaGraphConfig as NxConfig
from ng_nx.utils import result_to_df
from node2vec import Node2Vec

self.nx = nx
self.ng_nx = ng_nx
self.nx_reader = NxReader
self.nx_writer = NxWriter
self.nx_scan_reader = NxScanReader
self.nx_community_louvain = community_louvain
self.nx_node2vec = Node2Vec
self._nx_config = NxConfig
self.nx_config = None

Expand Down
Loading

0 comments on commit b0ac4fc

Please sign in to comment.