Search code examples
clojuregremlintinkerpopgremlin-server

clojure Ogre adding vertices


I'm using Clojure/Ogre to add vertices in Tinkergraph. Since I'm very new to this technologies, I guess that I might have missed something.

Here's what I tried:

(def graph (open-graph {(graph/GRAPH) (.getName org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph)}))

(def g (traversal graph))

(traverse g (add-V :person) (property :name "Dave"))

After these step, when I typed 'graph', I see no vertex added - output is like this:

#object[org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph 0x710f92c7 "tinkergraph[vertices:0 edges:0]"]

I guess very simple step is missed or something, but cannot figure it out.

Thanks a lot for your time. Looking forward for the solution


Thanks so much Stephen! I have one more question, if you don't mind. Following your comment, I added codes as these:

(def dave (traverse g (add-V :person) (property :name "Dave") (iterate!)))
(def josh (traverse g (add-V :person) (property :name "Josh") (iterate!)))

After this, now I want to add an edge between dave and josh. I tried:

(traverse g V (add-E :friends) (from dave) (to ted) (iterate!))

which returns with error. Anything I am missing here again? Thanks in advance!


Solution

  • it doesn't matter what programming language you use, you always need to iterate your traversal. In other words, you need a traversal termination step like iterate(), `toList(), etc. See the Ogre documentation for a listing of these in the "The Traversal" Section, but basically you just need to do something like this:

    (traverse g (add-V :person) (property :name "Dave") (iterate!))
    

    Note that iterate! does not return the result of a traversal. It simply consumes it. If you need the result of the traversal then you would want to look at other terminator steps. In the particular case you have you would like to have the Vertex object so, you would likely use next!