From f53454ef6478b43ea88e9f20203ab88b8e038730 Mon Sep 17 00:00:00 2001 From: Enrico Deusebio Date: Sat, 23 Nov 2024 21:31:56 +0100 Subject: [PATCH 1/2] bug: allow data dir specification --- docker/Dockerfile | 1 + utils.py | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index f9eb2e3..47d1e37 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -15,6 +15,7 @@ USER ${user} ENV HOME /home/${user} ENV NB_USER=${user} ENV XDG_CACHE_HOME=/home/${user}/.cache/ +ENV DATA_FOLDER=/data RUN git clone https://github.com/deusebio/Graph-Machine-Learning.git /home/${user}/Graph-Machine-Learning WORKDIR /home/${user}/Graph-Machine-Learning diff --git a/utils.py b/utils.py index b9a368a..a524daf 100644 --- a/utils.py +++ b/utils.py @@ -6,7 +6,12 @@ _chapter = os.path.basename(os.getcwd()) -DATA_DIR = pathlib.Path("/") / "data" / _chapter +if _chapter.startswith("Chapter"): + BASE_FOLDER = os.environ.get("DATA_FOLDER", os.path.join(os.getcwd(), "..", "data")) + DATA_DIR = pathlib.Path(BASE_FOLDER) / _chapter +else: + BASE_FOLDER = os.environ.get("DATA_FOLDER", os.getcwd()) + DATA_DIR = pathlib.Path(BASE_FOLDER) FIGURES_DIR = DATA_DIR / "figures" @@ -65,4 +70,4 @@ def draw_enhanced_path(G, path_to_enhance, node_names={}, filename=None, layout axis.set_ylim([1.2*y for y in axis.get_ylim()]) if filename: - plt.savefig(FIGURES_DIR / filename, format="png") \ No newline at end of file + plt.savefig(FIGURES_DIR / filename, format="png") From d2a33f96a792a3339b2cfdd3a62360d7defda0ac Mon Sep 17 00:00:00 2001 From: Enrico Deusebio Date: Sun, 24 Nov 2024 09:36:28 +0100 Subject: [PATCH 2/2] adding readme documentation about data_folder --- README.md | 13 +++++++++---- docker/README.md | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d2c504e..a62a9fe 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,6 @@ If you feel this book is for you, get your [copy](https://www.amazon.com/dp/1800 https://www.packtpub.com/ -## Errata -Page 16 - -The expression nt.to.numpy.matrix(G) should be nx.to.numpy.matrix(G) ## Instructions and Navigations All of the code is organized into folders. For example, Chapter02. @@ -44,6 +40,15 @@ generator = HinSAGENodeGenerator( head_node_type="document" ) ``` + +The notebooks in the repositories save files and figures into dedicated folders as they are executed. The format for these folders are: + +``` +/Chapter +``` + +where `DATA_FOLDER` is an environment variable that you can use to customize the position for the data. If the variable is not set, its value fall back to `/data`. + **Following is what you need for this book:** This book is for data analysts, graph developers, graph analysts, and graph professionals who want to leverage the information embedded in the connections and relations between data points to boost their analysis and model performance. The book will also be useful for data scientists and machine learning developers who want to build ML-driven graph databases. A beginner-level understanding of graph databases and graph data is required. Intermediate-level working knowledge of Python programming and machine learning is also expected to make the most out of this book. diff --git a/docker/README.md b/docker/README.md index d062fc7..cfd50d5 100644 --- a/docker/README.md +++ b/docker/README.md @@ -32,7 +32,7 @@ $ docker run --rm \ graph-machine-learning:latest ``` -to start the image. We suggest to use the default port 8888 for the ``. This will start a Jupyter server which should be locally accessible at `[http://localhost:8888](http://localhost:8888)` (or change the port accordingly). +to start the image. Please make sure that the data folder can be written by the Docker image. We suggest to use the default port 8888 for the ``. This will start a Jupyter server which should be locally accessible at `[http://localhost:8888](http://localhost:8888)` (or change the port accordingly). ## For Developers