Skip to content

Commit

Permalink
new: adjust DGL to ArangoDB for increased accessibility to python-ara…
Browse files Browse the repository at this point in the history
…ngo interface (#24)

* #23: initial commit

* Update build.yml

* Update README.md

* remove: unecessary dict merge using Kwargs

The DGL HeteroNodeDataView / HeteroEdgeDataView is able to track previously inserted features, so this is not needed

* remove: setuptools_scm from setup.py

deprecated in favor of pyproject.toml usage

* Update README.md

* remove: __validate_attributes()

Uncessary noise as we already have proper docstring examples

* pragma: no cover

* fix: black

* chg: #24 (after redefining scope)

* new: CodeQL Action v2

* drop python 3.6 support

mirrors arangoml/networkx-adapter@5930c80

* Update adapter.py

* fix: increase coverage

* prep for 2.1.0 release: documentation tweaks

* bump: python-arango version
  • Loading branch information
aMahanna authored Jun 29, 2022
1 parent fc758de commit 84fdbd2
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 154 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -52,7 +52,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -66,4 +66,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.6", "3.7", "3.8", "3.9"]
python: ["3.7", "3.8", "3.9"]
name: Python ${{ matrix.python }}
steps:
- uses: actions/checkout@v2
Expand All @@ -38,7 +38,7 @@ jobs:
- name: Run mypy
run: mypy ${{env.PACKAGE_DIR}} ${{env.TESTS_DIR}}
- name: Run pytest
run: py.test --cov=${{env.PACKAGE_DIR}} --cov-report xml --cov-report term-missing -v --color=yes --no-cov-on-fail --code-highlight=yes
run: py.test -s --cov=${{env.PACKAGE_DIR}} --cov-report xml --cov-report term-missing -v --color=yes --no-cov-on-fail --code-highlight=yes
- name: Publish to coveralls.io
if: matrix.python == '3.8'
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.6", "3.7", "3.8", "3.9"]
python: ["3.7", "3.8", "3.9"]
name: Python ${{ matrix.python }}
steps:
- uses: actions/checkout@v2
Expand Down
32 changes: 12 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<a href="https://www.arangodb.com/" rel="arangodb.com">![](https://raw.githubusercontent.com/arangoml/dgl-adapter/master/examples/assets/adb_logo.png)</a>
<a href="https://www.dgl.ai/" rel="dgl.ai"><img src="https://raw.githubusercontent.com/arangoml/dgl-adapter/master/examples/assets/dgl_logo.png" width=40% /></a>

The ArangoDB-DGL Adapter exports Graphs from ArangoDB, a multi-model Graph Database, into Deep Graph Library (DGL), a python package for graph neural networks, and vice-versa.
The ArangoDB-DGL Adapter exports Graphs from ArangoDB, the multi-model database for graph & beyond, into Deep Graph Library (DGL), a python package for graph neural networks, and vice-versa.


## About DGL
Expand Down Expand Up @@ -45,33 +45,25 @@ pip install git+https://github.com/arangoml/dgl-adapter.git
Also available as an ArangoDB Lunch & Learn session: [Graph & Beyond Course #2.8](https://www.arangodb.com/resources/lunch-sessions/graph-beyond-lunch-break-2-8-dgl-adapter/)

```py
# Import the ArangoDB-DGL Adapter
from adbdgl_adapter import ADBDGL_Adapter
from arango import ArangoClient # Python-Arango driver
from dgl.data import KarateClubDataset # Sample graph from DGL

# Import the Python-Arango driver
from arango import ArangoClient
# Let's assume that the ArangoDB "fraud detection" dataset is imported to this endpoint
db = ArangoClient(hosts="http://localhost:8529").db("_system", username="root", password="")

# Import a sample graph from DGL
from dgl.data import KarateClubDataset

# Instantiate driver client based on user preference
# Let's assume that the ArangoDB "fraud detection" dataset is imported to this endpoint for example purposes
db = ArangoClient(hosts="http://localhost:8529").db("_system", username="root", password="openSesame")

# Instantiate the ADBDGL Adapter with driver client
adbdgl_adapter = ADBDGL_Adapter(db)

# Convert ArangoDB to DGL via Graph Name
# Use Case 1.1: ArangoDB to DGL via Graph name
dgl_fraud_graph = adbdgl_adapter.arangodb_graph_to_dgl("fraud-detection")

# Convert ArangoDB to DGL via Collection Names
# Use Case 1.2: ArangoDB to DGL via Collection names
dgl_fraud_graph_2 = adbdgl_adapter.arangodb_collections_to_dgl(
"fraud-detection",
{"account", "Class", "customer"}, # Specify vertex collections
{"accountHolder", "Relationship", "transaction"}, # Specify edge collections
{"account", "Class", "customer"}, # Vertex collections
{"accountHolder", "Relationship", "transaction"}, # Edge collections
)

# Convert ArangoDB to DGL via a Metagraph
# Use Case 1.3: ArangoDB to DGL via Metagraph
metagraph = {
"vertexCollections": {
"account": {"Balance", "account_type", "customer_id", "rank"},
Expand All @@ -84,7 +76,7 @@ metagraph = {
}
dgl_fraud_graph_3 = adbdgl_adapter.arangodb_to_dgl("fraud-detection", metagraph)

# Convert DGL to ArangoDB
# Use Case 2: DGL to ArangoDB
dgl_karate_graph = KarateClubDataset()[0]
adb_karate_graph = adbdgl_adapter.dgl_to_arangodb("Karate", dgl_karate_graph)
```
Expand All @@ -107,4 +99,4 @@ def pytest_addoption(parser):
parser.addoption("--dbName", action="store", default="_system")
parser.addoption("--username", action="store", default="root")
parser.addoption("--password", action="store", default="")
```
```
16 changes: 5 additions & 11 deletions adbdgl_adapter/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ def arangodb_graph_to_dgl(self, name: str, **query_options: Any) -> DGLHeteroGra
raise NotImplementedError # pragma: no cover

def dgl_to_arangodb(
self, name: str, dgl_g: Union[DGLGraph, DGLHeteroGraph], batch_size: int
self,
name: str,
dgl_g: Union[DGLGraph, DGLHeteroGraph],
overwrite_graph: bool = False,
**import_options: Any,
) -> ArangoDBGraph:
raise NotImplementedError # pragma: no cover

Expand All @@ -48,23 +52,13 @@ def __insert_dgl_features(self) -> None:
def __prepare_adb_attributes(self) -> None:
raise NotImplementedError # pragma: no cover

def __insert_adb_docs(self) -> None:
raise NotImplementedError # pragma: no cover

def __fetch_adb_docs(self) -> None:
raise NotImplementedError # pragma: no cover

def __validate_attributes(self) -> None:
raise NotImplementedError # pragma: no cover

@property
def DEFAULT_CANONICAL_ETYPE(self) -> List[DGLCanonicalEType]:
return [("_N", "_E", "_N")]

@property
def METAGRAPH_ATRIBS(self) -> Set[str]:
return {"vertexCollections", "edgeCollections"}


class Abstract_ADBDGL_Controller(ABC):
def _adb_attribute_to_dgl_feature(self, key: str, col: str, val: Any) -> Any:
Expand Down
Loading

0 comments on commit 84fdbd2

Please sign in to comment.