This repository was archived by the owner on Sep 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
[master < T350] Add graphml docs #1020
Open
ind1xa
wants to merge
6
commits into
master
Choose a base branch
from
T350-MAGE-add-graphml-docs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bcb7b99
add graphml docs
ind1xa 983235a
add examples
ind1xa a25a322
add import data
ind1xa d02866a
Apply suggestions from code review
vpavicic a8225d2
PR review changes
ind1xa a60be34
Merge branch 'T350-MAGE-add-graphml-docs' of https://github.com/memgr…
ind1xa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -21,7 +21,7 @@ export const Highlight = ({children, color}) => ( | |||||
); | ||||||
|
||||||
Module for exporting a graph database or query results in different formats. Currently, this | ||||||
module supports [**exporting database to a JSON file format**](#jsonpath) and [**exporting query results in a CSV file format**](#csv_queryquery-file_path-stream). | ||||||
module supports [**exporting database to a JSON file format**](#jsonpath), [**exporting query results in a CSV file format**](#csv_queryquery-file_path-stream) and [**exporting database to a graphML file format**](#graphmlpath-config). | ||||||
|
||||||
[](https://github.com/memgraph/mage/blob/main/python/export_util.py) | ||||||
|
||||||
|
@@ -165,6 +165,83 @@ where `path` is the path to a local CSV file that will be created inside the | |||||
|
||||||
</Tabs> | ||||||
|
||||||
### `graphml(path, config)` | ||||||
|
||||||
#### Input: | ||||||
|
||||||
* `path: string` ➡ path to the graphML file that will contain the exported graph database. | ||||||
* `config: Map (default={})` ➡ configuration parameters explained below. | ||||||
|
||||||
#### Parameters: | ||||||
|
||||||
| Name | Type | Default | Description | | ||||||
|- |- |- |- | | ||||||
| stream | Bool | False | Stream the file content directly to the client into the status field. | | ||||||
| format | String | " " | Set the export format to either "gephi" or "tinkerpop". | | ||||||
| caption | List | [ ] | A list of keys of properties whose value is eligible as value for the `label` data element in Gephi format. Order is important and if no match is found, then there is a fallback to the node's first property. If the node has no properties then the ID is used. | | ||||||
| useTypes | Bool | False | Store property values' type information. | | ||||||
| leaveOutLabels | Bool | False | Do not store node's labels. | | ||||||
| leaveOutProperties | Bool | False | Do not store node's properties. | | ||||||
|
||||||
#### Output: | ||||||
|
||||||
* `status: string` ➡ file content if stream is set to `True` in configuration parameters, `success` otherwise. | ||||||
|
||||||
#### Usage: | ||||||
|
||||||
The `path` you have to provide as procedure argument depends on how you started | ||||||
Memgraph. | ||||||
|
||||||
<Tabs | ||||||
groupId="export_to_json_usage" | ||||||
defaultValue="docker" | ||||||
values={[ | ||||||
{label: 'Docker', value: 'docker'}, | ||||||
{label: 'Linux', value: 'linux'}, | ||||||
] | ||||||
}> | ||||||
|
||||||
<TabItem value="docker"> | ||||||
|
||||||
If you ran Memgraph with Docker, database will be exported to a graphML file inside | ||||||
the Docker container. We recommend exporting the database to the graphML file | ||||||
inside the `/usr/lib/memgraph/query_modules` directory. | ||||||
|
||||||
You can call the procedure by running the following query: | ||||||
|
||||||
```cypher | ||||||
CALL export_util.graphml(path); | ||||||
``` | ||||||
where `path` is the path to the JSON file inside the | ||||||
`/usr/lib/memgraph/query_modules` directory in the running Docker container (e.g., | ||||||
`/usr/lib/memgraph/query_modules/export.graphml`). | ||||||
|
||||||
:::info | ||||||
You can [**copy the exported CSV file to your local file system**](/memgraph/how-to-guides/work-with-docker#how-to-copy-files-from-and-to-a-docker-container) using the [`docker cp`](https://docs.docker.com/engine/reference/commandline/cp/) command. | ||||||
::: | ||||||
</TabItem> | ||||||
|
||||||
<TabItem value="linux"> | ||||||
|
||||||
To export database to a local graphML file create a new directory (for example, | ||||||
`export_folder`) and run the following command to give the user `memgraph` the | ||||||
necessary permissions: | ||||||
|
||||||
``` | ||||||
sudo chown memgraph export_folder | ||||||
``` | ||||||
|
||||||
Then, call the procedure by running the following query: | ||||||
|
||||||
```cypher | ||||||
CALL export_util.graphml(path); | ||||||
``` | ||||||
where `path` is the path to a local JSON file that will be created inside the | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
again, json? |
||||||
`export_folder` (e.g., `/users/my_user/export_folder/export.graphml`). | ||||||
</TabItem> | ||||||
|
||||||
</Tabs> | ||||||
|
||||||
|
||||||
## Example - Exporting database to a JSON file | ||||||
|
||||||
|
@@ -306,8 +383,8 @@ You can create a simple graph database by running the following queries: | |||||
```cypher | ||||||
CREATE (StrangerThings:TVShow {title:'Stranger Things', released:2016, program_creators:['Matt Duffer', 'Ross Duffer']}) | ||||||
CREATE (Eleven:Character {name:'Eleven', portrayed_by:'Millie Bobby Brown'}) | ||||||
CREATE (JoyceByers:Character {name:'Joyce Byers', portrayed_by:'Millie Bobby Brown'}) | ||||||
CREATE (JimHopper:Character {name:'Jim Hopper', portrayed_by:'Millie Bobby Brown'}) | ||||||
CREATE (JoyceByers:Character {name:'Joyce Byers', portrayed_by:'Winona Ryder'}) | ||||||
CREATE (JimHopper:Character {name:'Jim Hopper', portrayed_by:'David Harbour'}) | ||||||
Comment on lines
+386
to
+387
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed this once and I was like... will i fix this... is this worth opening a PR for :D :D naaaah... :D thnx |
||||||
CREATE (MikeWheeler:Character {name:'Mike Wheeler', portrayed_by:'Finn Wolfhard'}) | ||||||
CREATE (DustinHenderson:Character {name:'Dustin Henderson', portrayed_by:'Gaten Matarazzo'}) | ||||||
CREATE (LucasSinclair:Character {name:'Lucas Sinclair', portrayed_by:'Caleb McLaughlin'}) | ||||||
|
@@ -376,8 +453,8 @@ The output in the `export.csv` file looks like this: | |||||
```csv | ||||||
name,portrayed_by,title,released,program_creators | ||||||
Eleven,Millie Bobby Brown,Stranger Things,2016,"['Matt Duffer', 'Ross Duffer']" | ||||||
Joyce Byers,Millie Bobby Brown,Stranger Things,2016,"['Matt Duffer', 'Ross Duffer']" | ||||||
Jim Hopper,Millie Bobby Brown,Stranger Things,2016,"['Matt Duffer', 'Ross Duffer']" | ||||||
Joyce Byers,Winona Ryder,Stranger Things,2016,"['Matt Duffer', 'Ross Duffer']" | ||||||
Jim Hopper,David Harbour,Stranger Things,2016,"['Matt Duffer', 'Ross Duffer']" | ||||||
Mike Wheeler,Finn Wolfhard,Stranger Things,2016,"['Matt Duffer', 'Ross Duffer']" | ||||||
Dustin Henderson,Gaten Matarazzo,Stranger Things,2016,"['Matt Duffer', 'Ross Duffer']" | ||||||
Lucas Sinclair,Caleb McLaughlin,Stranger Things,2016,"['Matt Duffer', 'Ross Duffer']" | ||||||
|
@@ -392,3 +469,133 @@ Erica Sinclair,Priah Ferguson,Stranger Things,2016,"['Matt Duffer', 'Ross Duffer | |||||
</TabItem> | ||||||
|
||||||
</Tabs> | ||||||
|
||||||
vpavicic marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
## Example - Exporting database to a graphML file | ||||||
|
||||||
<Tabs | ||||||
groupId="export_to_graphml_example" | ||||||
defaultValue="input" | ||||||
values={[ | ||||||
{label: 'Step 1: Cypher load commands', value: 'load'}, | ||||||
{label: 'Step 2: Input graph', value: 'input'}, | ||||||
{label: 'Step 3: Running command', value: 'run'}, | ||||||
{label: 'Step 4: Results', value: 'result'}, | ||||||
] | ||||||
}> | ||||||
|
||||||
<TabItem value="load"> | ||||||
|
||||||
You can create a simple graph database by running the following queries: | ||||||
|
||||||
```cypher | ||||||
CREATE (StrangerThings:TVShow {title:'Stranger Things', released:2016, program_creators:['Matt Duffer', 'Ross Duffer']}) | ||||||
CREATE (Eleven:Character {name:'Eleven', portrayed_by:'Millie Bobby Brown'}) | ||||||
CREATE (JoyceByers:Character {name:'Joyce Byers', portrayed_by:'Winona Ryder'}) | ||||||
CREATE (JimHopper:Character {name:'Jim Hopper', portrayed_by:'David Harbour'}) | ||||||
CREATE (MikeWheeler:Character {name:'Mike Wheeler', portrayed_by:'Finn Wolfhard'}) | ||||||
CREATE (DustinHenderson:Character {name:'Dustin Henderson', portrayed_by:'Gaten Matarazzo'}) | ||||||
CREATE (LucasSinclair:Character {name:'Lucas Sinclair', portrayed_by:'Caleb McLaughlin'}) | ||||||
CREATE (NancyWheeler:Character {name:'Nancy Wheeler', portrayed_by:'Natalia Dyer'}) | ||||||
CREATE (JonathanByers:Character {name:'Jonathan Byers', portrayed_by:'Charlie Heaton'}) | ||||||
CREATE (WillByers:Character {name:'Will Byers', portrayed_by:'Noah Schnapp'}) | ||||||
CREATE (SteveHarrington:Character {name:'Steve Harrington', portrayed_by:'Joe Keery'}) | ||||||
CREATE (MaxMayfield:Character {name:'Max Mayfield', portrayed_by:'Sadie Sink'}) | ||||||
CREATE (RobinBuckley:Character {name:'Robin Buckley', portrayed_by:'Maya Hawke'}) | ||||||
CREATE (EricaSinclair:Character {name:'Erica Sinclair', portrayed_by:'Priah Ferguson'}) | ||||||
CREATE | ||||||
(Eleven)-[:ACTED_IN {seasons:[1, 2, 3, 4]}]->(StrangerThings), | ||||||
(JoyceByers)-[:ACTED_IN {seasons:[1, 2, 3, 4]}]->(StrangerThings), | ||||||
(JimHopper)-[:ACTED_IN {seasons:[1, 2, 3, 4]}]->(StrangerThings), | ||||||
(MikeWheeler)-[:ACTED_IN {seasons:[1, 2, 3, 4]}]->(StrangerThings), | ||||||
(DustinHenderson)-[:ACTED_IN {seasons:[1, 2, 3, 4]}]->(StrangerThings), | ||||||
(LucasSinclair)-[:ACTED_IN {seasons:[1, 2, 3, 4]}]->(StrangerThings), | ||||||
(NancyWheeler)-[:ACTED_IN {seasons:[1, 2, 3, 4]}]->(StrangerThings), | ||||||
(JonathanByers)-[:ACTED_IN {seasons:[1, 2, 3, 4]}]->(StrangerThings), | ||||||
(WillByers)-[:ACTED_IN {seasons:[1, 2, 3, 4]}]->(StrangerThings), | ||||||
(SteveHarrington)-[:ACTED_IN {seasons:[1, 2, 3, 4]}]->(StrangerThings), | ||||||
(MaxMayfield)-[:ACTED_IN {seasons:[2, 3, 4]}]->(StrangerThings), | ||||||
(RobinBuckley)-[:ACTED_IN {seasons:[3, 4]}]->(StrangerThings), | ||||||
(EricaSinclair)-[:ACTED_IN {seasons:[2, 3, 4]}]->(StrangerThings); | ||||||
``` | ||||||
</TabItem> | ||||||
|
||||||
<TabItem value="input"> | ||||||
|
||||||
The image below shows the above data as a graph: | ||||||
|
||||||
<img src={require('../../data/query-modules/python/export-util/export-util-csv-1.png').default}/> | ||||||
|
||||||
</TabItem> | ||||||
|
||||||
<TabItem value="run"> | ||||||
|
||||||
If you're using **Memgraph with Docker**, the following Cypher query will | ||||||
export the database to the `export.graphml` file in the | ||||||
`/usr/lib/memgraph/query_modules` directory inside the running Docker container. | ||||||
|
||||||
```cypher | ||||||
CALL export_util.graphml("/usr/lib/memgraph/query_modules/export.graphml, {useTypes: true}) | ||||||
YIELD status RETURN status; | ||||||
``` | ||||||
|
||||||
If you're using **Memgraph on Ubuntu, Debian, RPM package or WSL**, the | ||||||
following Cypher query will export the database to the `export.graphml` file in the | ||||||
`/users/my_user/export_folder`. | ||||||
|
||||||
```cypher | ||||||
CALL export_util.graphml("/users/my_user/export_folder/export.graphml, {useTypes: true}) | ||||||
YIELD status RETURN status; | ||||||
``` | ||||||
|
||||||
</TabItem> | ||||||
|
||||||
<TabItem value="result"> | ||||||
|
||||||
The output in the `export.graphml` file looks like this: | ||||||
|
||||||
|
||||||
```xml | ||||||
<?xml version="1.0" encoding="UTF-8"?> | ||||||
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd"> | ||||||
<key id="labels" for="node" attr.name="labels" attr.type="string"/> | ||||||
<key id="title" for="node" attr.name="title" attr.type="string"/> | ||||||
<key id="released" for="node" attr.name="released" attr.type="int"/> | ||||||
<key id="program_creators" for="node" attr.name="program_creators" attr.type="string" attr.list="string"/> | ||||||
<key id="name" for="node" attr.name="name" attr.type="string"/> | ||||||
<key id="portrayed_by" for="node" attr.name="portrayed_by" attr.type="string"/> | ||||||
<key id="label" for="edge" attr.name="label" attr.type="string"/> | ||||||
<key id="seasons" for="edge" attr.name="seasons" attr.type="string" attr.list="int"/> | ||||||
<graph id="G" edgedefault="directed"> | ||||||
<node id="n0" labels=":TVShow"><data key="labels">:TVShow</data><data key="title">Stranger Things</data><data key="released">2016</data><data key="program_creators">["Matt Duffer", "Ross Duffer"]</data></node> | ||||||
<node id="n1" labels=":Character"><data key="labels">:Character</data><data key="name">Eleven</data><data key="portrayed_by">Millie Bobby Brown</data></node> | ||||||
<node id="n2" labels=":Character"><data key="labels">:Character</data><data key="name">Joyce Byers</data><data key="portrayed_by">Winona Ryder</data></node> | ||||||
<node id="n3" labels=":Character"><data key="labels">:Character</data><data key="name">Jim Hopper</data><data key="portrayed_by">David Harbour</data></node> | ||||||
<node id="n4" labels=":Character"><data key="labels">:Character</data><data key="name">Mike Wheeler</data><data key="portrayed_by">Finn Wolfhard</data></node> | ||||||
<node id="n5" labels=":Character"><data key="labels">:Character</data><data key="name">Dustin Henderson</data><data key="portrayed_by">Gaten Matarazzo</data></node> | ||||||
<node id="n6" labels=":Character"><data key="labels">:Character</data><data key="name">Lucas Sinclair</data><data key="portrayed_by">Caleb McLaughlin</data></node> | ||||||
<node id="n7" labels=":Character"><data key="labels">:Character</data><data key="name">Nancy Wheeler</data><data key="portrayed_by">Natalia Dyer</data></node> | ||||||
<node id="n8" labels=":Character"><data key="labels">:Character</data><data key="name">Jonathan Byers</data><data key="portrayed_by">Charlie Heaton</data></node> | ||||||
<node id="n9" labels=":Character"><data key="labels">:Character</data><data key="name">Will Byers</data><data key="portrayed_by">Noah Schnapp</data></node> | ||||||
<node id="n10" labels=":Character"><data key="labels">:Character</data><data key="name">Steve Harrington</data><data key="portrayed_by">Joe Keery</data></node> | ||||||
<node id="n11" labels=":Character"><data key="labels">:Character</data><data key="name">Max Mayfield</data><data key="portrayed_by">Sadie Sink</data></node> | ||||||
<node id="n12" labels=":Character"><data key="labels">:Character</data><data key="name">Robin Buckley</data><data key="portrayed_by">Maya Hawke</data></node> | ||||||
<node id="n13" labels=":Character"><data key="labels">:Character</data><data key="name">Erica Sinclair</data><data key="portrayed_by">Priah Ferguson</data></node> | ||||||
<edge id="e0" source="n1" target="n0" label="ACTED_IN"><data key="label">ACTED_IN</data><data key="seasons">[1, 2, 3, 4]</data></edge> | ||||||
<edge id="e1" source="n2" target="n0" label="ACTED_IN"><data key="label">ACTED_IN</data><data key="seasons">[1, 2, 3, 4]</data></edge> | ||||||
<edge id="e2" source="n3" target="n0" label="ACTED_IN"><data key="label">ACTED_IN</data><data key="seasons">[1, 2, 3, 4]</data></edge> | ||||||
<edge id="e3" source="n4" target="n0" label="ACTED_IN"><data key="label">ACTED_IN</data><data key="seasons">[1, 2, 3, 4]</data></edge> | ||||||
<edge id="e4" source="n5" target="n0" label="ACTED_IN"><data key="label">ACTED_IN</data><data key="seasons">[1, 2, 3, 4]</data></edge> | ||||||
<edge id="e5" source="n6" target="n0" label="ACTED_IN"><data key="label">ACTED_IN</data><data key="seasons">[1, 2, 3, 4]</data></edge> | ||||||
<edge id="e6" source="n7" target="n0" label="ACTED_IN"><data key="label">ACTED_IN</data><data key="seasons">[1, 2, 3, 4]</data></edge> | ||||||
<edge id="e7" source="n8" target="n0" label="ACTED_IN"><data key="label">ACTED_IN</data><data key="seasons">[1, 2, 3, 4]</data></edge> | ||||||
<edge id="e8" source="n9" target="n0" label="ACTED_IN"><data key="label">ACTED_IN</data><data key="seasons">[1, 2, 3, 4]</data></edge> | ||||||
<edge id="e9" source="n10" target="n0" label="ACTED_IN"><data key="label">ACTED_IN</data><data key="seasons">[1, 2, 3, 4]</data></edge> | ||||||
<edge id="e10" source="n11" target="n0" label="ACTED_IN"><data key="label">ACTED_IN</data><data key="seasons">[2, 3, 4]</data></edge> | ||||||
<edge id="e11" source="n12" target="n0" label="ACTED_IN"><data key="label">ACTED_IN</data><data key="seasons">[3, 4]</data></edge> | ||||||
<edge id="e12" source="n13" target="n0" label="ACTED_IN"><data key="label">ACTED_IN</data><data key="seasons">[2, 3, 4]</data></edge> | ||||||
</graph> | ||||||
</graphml> | ||||||
``` | ||||||
</TabItem> | ||||||
|
||||||
</Tabs> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON or graphml?