Loading JSON data into Apache Age Viewer?

huangapple go评论132阅读模式
英文:

Loading JSON data into apache age viewer?

问题

我想加载以下数据到AGE。我该如何做到这一点?

数据:

{
  "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"
      }
    }
  ]
}
英文:

I want to load the following data to AGE. How can I do that?

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"
      }
    }
  ]
}

答案1

得分: 1

以下是翻译好的部分:

  1. 在年龄查看器中创建一个图形
  2. 创建标签
  3. 在创建的标签上创建索引
  4. 在索引后,只需使用复制命令加载数据以导入数据。
  5. 成功加载后,您可以使用age-viewer查询和可视化数据。

示例代码:

创建图形 newgraph;
创建标签 personLabel;
创建标签 friends_withLabel;

 personLabel 上创建图形索引;
 friends_withLabel 上创建图形索引;

 '您的 JSON 文件路径' 复制 personLabel(id, name, age);
 '您的 JSON 文件路径' 复制 friends_withLabel(id, source, target, since);

请注意,代码部分没有进行翻译。

英文:

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';

答案2

得分: 1

Apache AGE使用openCypher查询语言。我建议将您的JSON数据转换为等价的Cypher CREATE查询。

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);
英文:

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);

答案3

得分: 1

Apache Age中没有可用的内置函数,可以直接将您的数据转换为图数据库。您需要编写一个脚本,将整个数据转换为Cypher查询的形式,然后可以执行这些查询以获取图数据库。

脚本应该执行以下操作:

  • 首先,创建顶点。
  • 然后,将节点添加到该顶点以及它们的属性。
  • 然后,查看边缘数据并在节点之间创建边缘。
  • 最后,它应该返回所有的Cypher查询,然后可以执行这些查询以获取Apache Age中的数据。

对于上面的示例,它应该生成三个Cypher查询:

  • 第一个用于创建名为John的Person
  • 第二个用于创建名为Alice的Person
  • 第三个用于建立它们之间的关系。
英文:

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.

答案4

得分: 1

你可以使用 Cypher 查询 将数据加载到 Apache AGE 图中。

-- 创建图
CREATE GRAPH mygraph;

-- 加载顶点
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;

-- 加载边
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);

请确保将 file:///path/to/your/data.json 替换为实际的 JSON 数据文件路径。

在这些查询中,使用了 apoc.load.json 过程来加载 JSON 数据。UNWIND 子句用于遍历 JSON 数据中的顶点和边数组。MERGE 语句用于创建或匹配顶点,SET 子句将属性赋给了顶点。对于边,使用 MATCH 子句找到源和目标顶点,并使用 CREATE 语句创建关系。

你可以使用 age-viewer 工具查看图中的数据。要做到这一点,你需要打开 age-viewer 工具,并选择添加图选项。在添加图对话框中,指定图的名称 (mygraph) 和图数据库的位置 (~/.age/mygraph)。然后点击打开按钮。

age-viewer 工具将以图形格式显示图形。你可以使用查询选项卡输入 Cypher 查询以探索数据。

英文:

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.

答案5

得分: 1

以下步骤可用于将相关数据加载到Apache AGE中:

  1. 确保图架构根据您需要的数据标签进行设计。
  2. 使用“GRAPH_IO”模块将数据导出到Apache AGE。
  3. 现在,您可以通过在边缘和顶点上运行示例查询来验证数据是否已正确加载。
英文:

The following steps can be followed to load the relevant data into Apache AGE:

  1. Make sure that the graph schema is designed according to the data labels that you'll need.
  2. Use the "GRAPH_IO" module to export the data into Apache AGE.
  3. Now you may verify whether the data has been loaded correctly by running a sample query on the edges and vertices.

huangapple
  • 本文由 发表于 2023年5月20日 14:35:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76293835.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定