guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/01: graph: Add Cypher backend.


From: Roel Janssen
Subject: 01/01: graph: Add Cypher backend.
Date: Thu, 11 May 2017 10:19:46 -0400 (EDT)

roelj pushed a commit to branch master
in repository guix.

commit 5899fafbfefcd7682aec8f2caaaad3add678a3c4
Author: Roel Janssen <address@hidden>
Date:   Thu May 11 16:17:49 2017 +0200

    graph: Add Cypher backend.
    
    * guix/graph.scm (%cypher-backend): New variable.
    * doc/guix.texi: Add documentation for the Cypher backend of 'guix graph'.
---
 doc/guix.texi  |  4 +++-
 guix/graph.scm | 32 +++++++++++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 81aa957..a5b7875 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -6197,7 +6197,9 @@ provides a visual representation of the DAG.  By default,
 @uref{http://www.graphviz.org/, Graphviz}, so its output can be passed
 directly to the @command{dot} command of Graphviz.  It can also emit an
 HTML page with embedded JavaScript code to display a ``chord diagram''
-in a Web browser, using the @uref{https://d3js.org/, d3.js} library.
+in a Web browser, using the @uref{https://d3js.org/, d3.js} library, or
+emit Cypher queries to construct a graph in a graph database supporting
+the @uref{http://www.opencypher.org/, openCypher} query language.
 The general syntax is:
 
 @example
diff --git a/guix/graph.scm b/guix/graph.scm
index 7af2cd3..d7fd5f3 100644
--- a/guix/graph.scm
+++ b/guix/graph.scm
@@ -229,6 +229,35 @@ nodeArray.push(nodes[\"~a\"]);~%"
                  emit-d3js-prologue emit-d3js-epilogue
                  emit-d3js-node emit-d3js-edge))
 
+
+
+;;;
+;;; Cypher export.
+;;;
+
+(define (emit-cypher-prologue name port)
+  (format port ""))
+
+(define (emit-cypher-epilogue port)
+  (format port ""))
+
+(define (emit-cypher-node id label port)
+  (format port "MERGE (p:Package { id: ~s }) SET p.name = ~s;~%"
+          id label ))
+
+(define (emit-cypher-edge id1 id2 port)
+  (format port "MERGE (a:Package { id: ~s });~%" id1)
+  (format port "MERGE (b:Package { id: ~s });~%" id2)
+  (format port "MATCH (a:Package { id: ~s }), (b:Package { id: ~s }) CREATE 
UNIQUE (a)-[:NEEDS]->(b);~%"
+          id1 id2))
+
+(define %cypher-backend
+  (graph-backend "cypher"
+                 "Generate Cypher queries."
+                 emit-cypher-prologue emit-cypher-epilogue
+                 emit-cypher-node emit-cypher-edge))
+
+
 
 ;;;
 ;;; Shared.
@@ -236,7 +265,8 @@ nodeArray.push(nodes[\"~a\"]);~%"
 
 (define %graph-backends
   (list %graphviz-backend
-        %d3js-backend))
+        %d3js-backend
+        %cypher-backend))
 
 (define* (export-graph sinks port
                        #:key



reply via email to

[Prev in Thread] Current Thread [Next in Thread]