neoxygen/neogen

Neo4j 图生成器,支持 PHP5.4+


README

Build Status

Neo4j 图生成器

该库简化了测试图的生成。还使用了faker库来生成随机的属性值。

您可以使用 YAML 或稍作修改的 Cypher 模式定义您的图模型。

此库处于开发中

该库处于早期阶段,旨在用于开发环境。

该库是流行的Graphgen 网络应用程序的核心

用法

下载库

git clone https://github.com/neoxygen/neogen

cd neogen

在 YAML 中定义您的图模型

connection:
  scheme: http
  host: localhost
  port: 7474

nodes:
  persons:
    label: Person
    count: 50
    properties:
      firstname: firstName
      lastname: lastName

  companies:
    label: Company
    count: 10
    properties:
      name: company
      description: catchPhrase

relationships:
  person_works_for:
    start: persons
    end: companies
    type: WORKS_AT
    mode: n..1

  friendships:
    start: persons
    end: persons
    type: KNOWS
    mode: n..n

运行生成命令

vendor/bin/neogen generate

或者您可能想要将生成查询导出到文件中,便于在 Neo4j 控制台中导入

./vendor/bin/neogen generate --export="myfile.cql"

在图浏览器中查看结果!

快速配置细节

  • 当定义属性类型(如公司、firstName 等)时,这些类型指的是标准faker类型。
  • count 定义您想要的节点数量
  • 关系模式:1 表示每个节点只有一个现有关系,random 表示随机数量的关系

属性参数

有时您可能想要为属性定义一些参数,例如,为了为 Person 节点提供一个现实生活中的出生日期,您可能想确保日期在 50 年前和 18 年前之间,如果您为在一家公司工作的人设置了 dob。

nodes:
  persons:
    label: Person
    count: 10
    properties:
      firstname: firstName
      date_of_birth: { type: "dateTimeBetween", params: ["-50 years", "-18 years"]}

relationships:
    person_works_for:
        start: persons
        end: companies
        type: WORKS_AT
        mode: random
        properties:
            since: { type: "dateTimeBetween", params: ["-10 years", "now"]}

在 Cypher 中定义您的图模型

//eg:
(person:Person {firstname:firstName, lastname:lastName} *30)-[:KNOWS *n..n]->(person)
(person)-[:WORKS_AT *n..1]->(company:Company {name:company, slogan:catchPhrase} *5)

对于完整描述,请参阅Graphgen 文档

从 Cypher 模式生成图

./bin/neogen generate-cypher --source="pattern.cypher" --export="export.gen"

或者您可能希望直接将图导入可访问的 Neo4j 数据库

./bin/neogen generate-cypher --source="pattern.cypher" --export-db="localhost:7474"

开发

欢迎贡献、反馈和要求。请通过打开问题或 PR 或在推特上联系我:@ikwattro