Ogre documentation?

48 views
Skip to first unread message

Paul Viola

unread,
Sep 27, 2013, 12:53:08 PM9/27/13
to clojure-...@googlegroups.com

The feedback link for the ogre doc clicks through to this group.  I assume that Ogre questions are OK here.

The OGRE doc seems out of date (and like a previous poster I am wondering if it is active).

Is the OGRE doc on github (sorry in advance if it is obvious where)?




(q/query (g/find-by-id 4)
         (q/--> :created)
         q/into-vec!)

Should be (right)??

(q/query (g/find-by-id 4)
         (q/--> [:created])
         q/into-vec!)

Zack Maril

unread,
Sep 27, 2013, 2:29:33 PM9/27/13
to clojure-...@googlegroups.com
The later should be correct. The documentation will be updated soon.


Like Titanium and Archimedes, Ogre is gearing up for more activity soon. 
-Zack

Paul Viola

unread,
Sep 27, 2013, 5:57:07 PM9/27/13
to clojure-...@googlegroups.com
Thanks Zack.  

Love to contribute as you move forward.   (BTW: The world of Clojure is reminiscent of the Lisp that I grew to love hacking on the Lisp Machine (back in 1984) http://en.wikipedia.org/wiki/Lisp_machine )

That said,  I was surprised to see that Ogre was fully materializing all query results before returning the first!!!

(From pipe.clj)

(defn first-of! 
  [^GremlinPipeline p]
  (-> p into-vec! first))

(defn into-vec! 
  [^GremlinPipeline p]
  (into [] (to-list! p)))

(defn to-list! 
  [^GremlinPipeline p]
  (.toList p))   ;; bad news here

The key is that you are calling the .toList method on the GremlinPipeline,  which collects *all* the results into a java.util.ArrayList.   And then you are putting that into a Clojure vector,  and then grabbing the first.

Note,  you can create the pipeline and then call (next pipeline) and I believe it does the right thing:

(defn next 
  [^GremlinPipeline p i]
  (.next p i))


Any reason you did not do it this way??

(defn to-lazy-list! 
  [^GremlinPipeline p depth]
  (let [n (oq/next p 1)]
    (if (and (first n) (> depth 0))
      (cons n (lazy-seq (to-lazy-list! p (- depth 1))))
      nil)))

The result is much faster (and I think better in many ways):

graph-explore.core> (time (oq/query 
    (ot/get-vertices)
    oq/map
    (to-lazy-list! 1)))
"Elapsed time: 0.807 msecs"

   ...

graph-explore.core> (time (oq/query 
    (ot/get-vertices)
    oq/map
    oq/first-of!))
"Elapsed time: 14.273 msecs"

Zack Maril

unread,
Sep 27, 2013, 6:14:20 PM9/27/13
to clojure-...@googlegroups.com
You're totally right. I hadn't noticed the next method and it should definitely be used. If you want to write a pull request for this, I'll accept it. Otherwise it'll get in there pretty quick. https://github.com/clojurewerkz/ogre/issues/13

As for the lazy-list implementation, that's quite neat. What is the advantage of being able to pass in the depth? Why not just have people assume it be infinite and then use `(take n (oq/to-lazy-list! p))` to get however many they want? 
-Zack

Paul Viola

unread,
Sep 27, 2013, 8:38:46 PM9/27/13
to clojure-...@googlegroups.com
I submitted some much simplified code.  The change is pretty fundamental,  since it changes a to-list!...  so accept with care.  More in the comments there.

Your right about the (take n ...) .  Much better.  Just my first pass and I combined two things that should not be combined.
Reply all
Reply to author
Forward
0 new messages