Timothy Baldridge <tbaldri...@gmail.com> writes:

> I think the first hint to an answer is found in your question. You are
> dealing with complex data, simplify the data, and querying the data is much
> simpler.

Part of the problem is that the data structure that I have is
intrinsically fairly complex; I have already simplified it from it's
original form some what. Having said that, the "schema" is predefined,
so, although the rules are fairly complex, there are rules about what
can appear inside what.


> For instance, if you have a tree, you could flatten the tree into a hash
> map like this:
>
> {parent-id {:children [child-id1 child-id2]}
>  child-id1 {:children [child-id3 child-id4]}
>  child-id2 ...}
>
> Now it's very simple to say things like "who are the parents of this child
> node?". Cedric is right, once you get a somewhat normalized data structure
> it's fairly trivial to query it with core.logic (using hash maps like the
> one above). You just have to write some code to get it into a format that
> core.logic can consume.

I had a go with core.match. It does allow me to write stuff like this.... 

(defn match-only-label [entity]
  (match [entity]
         [{:annotation a}]
         (map
          (fn [annotation]
            (match
             [annotation]
             [(['label l "it"] :seq)] l
             :else nil
             )) a)))

This still leaves me handling all the nil catching myself. The outer
part of this query is, essentially this:

(defn match-annotation [entity]
  (match [entity]
         [{:annotation a}] a
         :else nil))

which is a complex way of saying (get entity :annotation).

As far as I can see, there is now way with core.match to query at
arbitrary level (my data structures can be quite highly nested). So I
can't say "match anything that is a list starting with 'label and ending
in "it". I guess I could use core.match with clojure.core.walk to get this.

Still, it think it is worth pursing; core.match can match on any Java
object which is what I am handling here. My clojure data structure is
actually generating by a recursive rendering of Java objects into some
clojure objects.

> However, to be honest, this is where I reach for Datomic. It has a wicked
> fast query engine (datalog), you can run it in-memory (no disk access
> required), it has an excellent Clojure interface, the free version should
> do everything you need, and it has many many other features. For instance,
> given a child node in Datomic, you can find it's parents via:
>
> (let [parents (:_children child-node)]
>   ...)
>
> Not to mention that you can also create Datalog rules that allow you to
> create pre-defined queries that simplify your code quite a bit.

I think that this is more than I would want to pull into my application
at the moment. Probably core.match with some macros at do things like
add an automatic :else nil, and do the map that I have used above would
be enough.

Thanks for the feedback

Phil

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to