1

I want to load the following data to age. How to do that? what would be a good approach? Are there any specific tools to do it.

Data:

{
  "vertices": [
    {
      "id": 1,
      "label": "Person",
      "properties": {
        "name": "John",
        "age": 25
      }
    },
    {
      "id": 2,
      "label": "Person",
      "properties": {
        "name": "Alice",
        "age": 30
      }
    }
  ],
  "edges": [
    {
      "id": 1,
      "label": "FRIENDS_WITH",
      "source": 1,
      "target": 2,
      "properties": {
        "since": "2022-01-01"
      }
    }
  ]
}

Would love to know your suggestion on it. How to do this task and load the data effectively.

6 Answers6

1

You can do the above procedure by following below steps:

  1. Create a graph in age viewer
  2. Create labels
  3. create indexes on the created labels
  4. After the indexes just load data using copy command to import the data.
  5. after successful loading you can query and visualize the data using age-viewer

A sample Code:

Create graph newgraph;
Create label personLabel;
Create label friends_withLabel;

Create graph index ON personLabel;
Create graph index ON friends_withLabel;

Copy personLabel(id, name, age) from 'Path to your json file';
Copy friends_withLabel(id, source, target, since) from 'Path to your json file';
Talha Munir
  • 121
  • 5
0

Apache AGE makes use of the openCypher query language. I would suggest transforming your JSON data into an equivalent set of Cypher CREATE queries.

CREATE (n:Person {id: 1, name: 'John', age: 25});
CREATE (m:Person {id: 2, name: 'Alice', age: 30});
CREATE (n)-[:FRIENDS_WITH {id: 1, since: '2022-01-01'}]->(m);
0

You can write a query in AGE's openCypher language to extract data from the JSON file and load it into AGE. An in-built function for this purpose does not currently exist.

tokamak32
  • 27
  • 7
0

There is no built-in function available in Apache Age that can directly transform your data into a graph database. You have to write a script which will convert your whole data in the form of cypher queries which can then be executed to get the graph database.

The script should do the following things

- First, make the vertex.
- Then it should add the nodes to that vertex along with their properties.
- Then it should see the edges data and make the edges between the nodes.
- Lastly, it should return all the cypher queries which can then be executed to get this data in the Apache Age.

For the above example, it should generate three cypher queries:

First one for creating John named Person
The second one for creating Alice named Person
Third one for making the relationship between them.
0

You can make use of Cypher Queries to load your data into an Apache AGE graph.

-- Create the graph
CREATE GRAPH mygraph;

-- Load the vertices
CALL apoc.load.json('file:///path/to/your/data.json') YIELD value
UNWIND value.vertices AS vertex
MERGE (n:Person {id: vertex.id})
SET n.name = vertex.properties.name,
    n.age = vertex.properties.age;

-- Load the edges
CALL apoc.load.json('file:///path/to/your/data.json') YIELD value
UNWIND value.edges AS edge
MATCH (source:Person {id: edge.source})
MATCH (target:Person {id: edge.target})
CREATE (source)-[r:FRIENDS_WITH {since: edge.properties.since}]->(target);

Make sure to replace 'file:///path/to/your/data.json' with the actual path to your JSON data file.

In these queries, the apoc.load.json procedure is used to load the JSON data. The UNWIND clause is used to iterate over the vertices and edges arrays in the JSON data. The MERGE statement is used to create or match the vertices, and the SET clause assigns the properties to the vertices. For edges, the MATCH clause is used to find the source and target vertices, and the CREATE statement is used to create the relationships.

You can use the age-viewer tool to view the data in the graph. To do this, you will need to open the age-viewer tool and select the Add Graph option. In the Add Graph dialog box, specify the name of the graph (mygraph) and the location of the graph database (~/.age/mygraph). Click on the Open button.

The age-viewer tool will display the graph in a graphical format. You can use the Query tab to enter Cypher queries to explore the data.

0

In Apache Age, you cannot directly convert your JSON data into a graph database. But you can solve this issue using openCypher language. Use openCypher to extract JSON data and then you can load it into the Age. I hope it will help you.

Aadil Bashir
  • 111
  • 5