{"id":15657389,"url":"https://github.com/s1ck/gdl","last_synced_at":"2025-05-01T12:22:07.163Z","repository":{"id":54162940,"uuid":"46107276","full_name":"s1ck/gdl","owner":"s1ck","description":"Graph Definition Language","archived":false,"fork":false,"pushed_at":"2024-04-05T08:16:24.000Z","size":235,"stargazers_count":24,"open_issues_count":7,"forks_count":15,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-30T04:08:30.030Z","etag":null,"topics":["cypher","gdl","hacktoberfest","property-graphs"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/s1ck.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-11-13T07:39:13.000Z","updated_at":"2024-10-10T16:44:01.000Z","dependencies_parsed_at":"2024-10-23T05:09:32.357Z","dependency_job_id":null,"html_url":"https://github.com/s1ck/gdl","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s1ck%2Fgdl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s1ck%2Fgdl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s1ck%2Fgdl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s1ck%2Fgdl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/s1ck","download_url":"https://codeload.github.com/s1ck/gdl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251872380,"owners_count":21657634,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cypher","gdl","hacktoberfest","property-graphs"],"created_at":"2024-10-03T13:06:40.219Z","updated_at":"2025-05-01T12:22:07.136Z","avatar_url":"https://github.com/s1ck.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://github.com/s1ck/gdl/workflows/Java%20CI/badge.svg)](https://github.com/s1ck/gdl/actions?workflow=Java+CI)\n\n## GDL - Graph Definition Language\n\nInspired by the popular graph query language [Cypher](http://neo4j.com/docs/stable/cypher-query-lang.html),\nwhich is implemented in [Neo4j](http://neo4j.com/), I started developing an [ANTLR](http://www.antlr.org/)\ngrammar to define property graphs. I added the concept of subgraphs into the language to support multiple, \npossible overlapping property graphs in one database. \n\nFor me, this project is a way to learn more about ANTLR and context-free grammars. Furthermore, GDL is used\nfor unit testing and graph definition in [Gradoop](https://github.com/dbs-leipzig/gradoop), a framework for \ndistributed graph analytics.\n\nThe project contains the grammar and a listener implementation which transforms GDL scripts into\nproperty graph model elements (i.e. graphs, vertices and edges).\n\nThere is also a [Rust version](https://github.com/s1ck/nom-gdl) of GDL available on GitHub.\n\n## Data model\n\nThe data model contains three elements: graphs, vertices and edges. Any element has an optional\nlabel and can have multiple attributes in the form of key-value pairs. Vertices and edges may \nbe contained in an arbitrary number of graphs including zero graphs. Edges are binary and directed.\n\n## Language Examples\n\nDefine a vertex:\n\n```\n()\n```\n\nDefine a vertex and assign it to variable `alice`:\n\n```\n(alice)\n```\n\nDefine a vertex with label `User`:\n\n```\n(:User)\n```\n\nDefine a vertex with label `User`, assign it to variable `alice` and give it some properties:\n\n```\n(alice:User {name : \"Alice\", age : 23})\n```\n\nProperty values can also be null:\n\n```\n(alice:User {name : \"Alice\", age : 23, city : NULL})\n```\n\nNumeric property values can have specific data types:\n\n```\n(alice:User {name : \"Alice\", age : 23L, height : 1.82f, weight : 42.7d})\n```\n\nProperty values can also be ordered lists:\n\n```\n(alice:User {name : \"Alice\", age : 23, codes: [\"Java\", \"Rust\", \"Scala\"]})\n```\n\nDefine an outgoing edge:\n\n```\n(alice)--\u003e()\n```\n\nDefine an incoming edge:\n\n```\n(alice)\u003c--()\n```\n\nDefine an edge with label `knows`, assign it to variable `e1` and give it some properties:\n\n```\n(alice)-[e1:knows {since : 2014}]-\u003e(bob)\n```\n\nDefine multiple outgoing edges from the same source vertex (i.e. `alice`):\n\n```\n(alice)-[e1:knows {since : 2014}]-\u003e(bob)\n(alice)-[e2:knows {since : 2013}]-\u003e(eve)\n```\n\nDefine paths (four vertices and three edges are created):\n\n```\n()--\u003e()\u003c--()--\u003e()\n```\n\nDefine a graph with one vertex (graphs can be empty):\n\n```\n[()]\n```\n\nDefine a graph and assign it to variable `g`:\n\n```\ng[()]\n```\n\nDefine a graph with label `Community`:\n\n```\n:Community[()]\n```\n\nDefine a graph with label `Community`, assign it to variable `g` and give it some properties:\n\n```\ng:Community {title : \"Graphs\", memberCount : 42}[()]\n```\n\nDefine mixed path and graph statements (elements in the paths don't belong to a specific graph):\n\n```\n()--\u003e()\u003c--()--\u003e()\n[()]\n```\n\nDefine a fragmented graph with variable reuse:\n\n```\ng[(a)--\u003e()]\ng[(a)--\u003e(b)]\ng[(b)--\u003e(c)]\n```\n\nDefine three graphs with overlapping vertex sets (e.g. `alice` is in `g1` and `g2`):\n\n```\ng1:Community {title : \"Graphs\", memberCount : 23}[\n    (alice:User)\n    (bob:User)\n    (eve:User)\n]\ng2:Community {title : \"Databases\", memberCount : 42}[\n    (alice)\n]\ng2:Community {title : \"Hadoop\", memberCount : 31}[\n    (bob)\n    (eve)\n]\n```\n\nDefine three graphs with overlapping vertex and edge sets (`e` is in `g1` and `g2`):\n\n```\ng1:Community {title : \"Graphs\", memberCount : 23}[\n    (alice:User)-[:knows]-\u003e(bob:User),\n    (bob)-[e:knows]-\u003e(eve:User),\n    (eve)\n]\ng2:Community {title : \"Databases\", memberCount : 42}[\n    (alice)\n]\ng2:Community {title : \"Hadoop\", memberCount : 31}[\n    (bob)-[e]-\u003e(eve)\n]\n```\n\n### Query Expressions\n\nAs part of his thesis, [Max](https://github.com/DarthMax) extended the grammar to support `MATCH .. WHERE ..`\nstatements analogous to Cypher. Besides defining a graph it is now also possible to formulate a query including \npatterns, variable length paths and predicates:\n\n```\nMATCH (alice:Person)-[:knows]-\u003e(bob:Person)-[:knows*2..2]-\u003e(eve:Person)\nWHERE (alice.name = \"Alice\" AND bob.name = \"Bob\") \nOR (alice.age \u003e bob.age)\nOR (alice.age \u003e eve.age)\n```\n\n**Note** that queries always start with the `MATCH` keyword optionally followed by one or more\n`WHERE` clauses. \n\n## Usage examples\n\nAdd dependency to your maven project:\n\n```\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.s1ck\u003c/groupId\u003e\n    \u003cartifactId\u003egdl\u003c/artifactId\u003e\n    \u003cversion\u003e0.3.8\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nCreate a database from a GDL string:\n\n```java\nGDLHandler handler = new GDLHandler.Builder().buildFromString(\"g[(alice)-[e1:knows {since : 2014}]-\u003e(bob)]\");\n\nfor (Vertex v : handler.getVertices()) {\n    // do something\n}\n\n// access elements by variable\nGraph g = handler.getGraphCache().get(\"g\");\nVertex alice = handler.getVertexCache().get(\"alice\");\nEdge e = handler.getEdgeCache().get(\"e1\");\n```\n\nRead predicates from a Cypher query:\n\n```java\nGDLHandler handler = new GDLHandler.Builder().buildFromString(\"MATCH (a:Person)-[e:knows]-\u003e(b:Person) WHERE a.age \u003e b.age\");\n\n// prints (((a.age \u003e b.age AND a.__label__ = Person) AND b.__label__ = Person) AND e.__label__ = knows)\nhandler.getPredicates().ifPresent(System.out::println);\n```\n\nCreate a database from an `InputStream` or an input file:\n\n```java\nGDLHandler handler1 = new GDLHandler.Builder().buildFromStream(stream);\nGDLHandler handler2 = new GDLHandler.Builder().buildFromFile(fileName);\n```\n\nAppend data to a given handler:\n\n```java\nGDLHandler handler = new GDLHandler.Builder().buildFromString(\"g[(alice)-[e1:knows {since : 2014}]-\u003e(bob)]\");\n\nhandler.append(\"g[(alice)-[:knows]-\u003e(eve)]\");\n```\n\n## License\n\nLicensed under the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs1ck%2Fgdl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fs1ck%2Fgdl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs1ck%2Fgdl/lists"}