Skip to main content

g2c is a python script to convert Gremlin query to Cypher query with OpenAI API

Project description

g2c

License

Overview

g2c is a python script to convert Gremlin query to Cypher query with OpenAI API

Table of Contents

Installation

Just add tap and install homebrew package.

brew tap rioriost/g2c
brew install g2c

Prerequisites

Usage

Execute g2c command.

g2c --help
usage: g2c [-h] [-a] (-g GREMLIN | -f FILEPATH | -u URL)

Convert Gremlin queries to Cypher queries.

options:
  -h, --help            show this help message and exit
  -a, --age             Convert to the Cypher query for Apache AGE.
  -g GREMLIN, --gremlin GREMLIN
                        The Gremlin query to convert.
  -f FILEPATH, --filepath FILEPATH
                        Path to the source code file (.py, .java, .cs, .txt)
  -u URL, --url URL     URL to the source code file (.py, .java, .cs, .txt)

The indentical usage is shown below.

with -g(--gremlin)

g2c -g 'g.V().has(“name”, “Alice”).as(“a”).V().has(“name”, “Bob”).as(“b”).select(“a”, “b”).by(“name”)'
Converted Cypher queries:

line 1, g.V().has("name", "Alice").as("a").V().has("name", "Bob").as("b").select("a", "b").by("name") ->
MATCH (a {name: "Alice"}), (b {name: "Bob"}) RETURN a.name AS a, b.name AS b

with -u(--url)

g2c --url https://raw.githubusercontent.com/nedlowe/gremlin-python-example/refs/heads/master/app.py
Converted Cypher queries:

line 42, g.V(person_id).toList() ->
MATCH (p) WHERE id(p) = person_id RETURN p

line 42, g.V(person_id) ->
MATCH (n) WHERE id(n) = person_id RETURN n

line 55, g.V(vertex).valueMap().toList() ->
MATCH (n) WHERE id(n) = $vertex RETURN n

line 55, g.V(vertex).valueMap() ->
MATCH (n) WHERE id(n) = $vertex RETURN n

line 55, g.V(vertex) ->
MATCH (n) WHERE id(n) = vertex RETURN n

line 77, g.addV('person').property(T.id, person_id).next() ->
CREATE (n:person {id: person_id})
......

with -f(--filepath)

g2c --file ~/Desktop/g.py
Converted Cypher queries:

line 1, "g.V()" ->
MATCH (n) RETURN n

line 3, "g.E()" ->
MATCH ()-[r]->() RETURN r

line 4, "g.V('vertexId')" ->
MATCH (n) WHERE id(n) = 'vertexId' RETURN n
......

with -a(--age)

g2c -a -g "g.V().hasLabel('person').aggregate('a')"
Converted Cypher queries:

line 1, g.V().hasLabel('person').aggregate('a') ->
SELECT * FROM cypher('GRAPH_NAME', $$ MATCH (n:person) WITH collect(n) AS a RETURN a $$) AS (a agtype, n agtype);

Release Notes

0.3.0 Release

  • Refactored the code
  • Fixed a bug to save a cache. If you're using the old versions, please delete the .g2c_cache file under your home directory.
  • Added '--age' argument to convert Gremlin query to Cypher using Apache AGE

0.2.0 Release

  • Changed the default behaviour to accept a Gremlin query (-g), a file (-f), or a URL (-u).
  • Added feature to extract Gremlin queries from a file or URL.
  • Added CacheManager and a feature to deploy a cache file to user home directory if it doesn't exist.

0.1.0 Release

  • Initial release.

License

MIT License

Cypher.interp, Cypher.tokens, CypherLexer.interp, CypherLexer.py, CypherLexer.tokens, CypherListener.py, CypherParser.py, and CypherVisitor.py under src/g2c/ were generated from Cypher.g4 Apache License, Version 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

g2c-0.3.0.tar.gz (107.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

g2c-0.3.0-py3-none-any.whl (103.3 kB view details)

Uploaded Python 3

File details

Details for the file g2c-0.3.0.tar.gz.

File metadata

  • Download URL: g2c-0.3.0.tar.gz
  • Upload date:
  • Size: 107.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.27

File hashes

Hashes for g2c-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f85fa86431a2e9389071150293a55042dcc2aa1874b07c3aabcaede6f2a0f9a2
MD5 e0cba3607443c6ab2be37ba04db03494
BLAKE2b-256 2b4be18aef88a172e87985e0c065786eec93153e0c39e13f739a9c7c43a48e54

See more details on using hashes here.

File details

Details for the file g2c-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: g2c-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 103.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.27

File hashes

Hashes for g2c-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6afdd9aa90ea6ef76b2e6b369e450f5ce71d2b40a939ae94c34c3e6aa5f99f4d
MD5 222ec21c3cfae449af3b1ecfe7d6721d
BLAKE2b-256 7dfde589587b35be00578cbf2daee377587a9153239b68caafcc3791ce49cd76

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page