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.

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.

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.

In short, when I hear my self saying "find X where Y" or "I'd like to query
this structure", I reach for Datomic, when that doesn't work for me (for
whatever reason) then I start coding with core.logic.

Timothy



On Wed, Jul 24, 2013 at 1:14 PM, Cedric Greevey <cgree...@gmail.com> wrote:

> Don't quote me on this, but it might be the sort of problem for which
> core.logic is well suited. Though really it seems like what's wanted is a
> variation on the theme of core.match but which does destructuring
> assignments rather than flow control.
>
>
> On Wed, Jul 24, 2013 at 8:16 AM, Phillip Lord <
> phillip.l...@newcastle.ac.uk> wrote:
>
>>
>> I have a relatively complex data structure, a simple example of which
>> looks
>> likes like this. This is the print representation -- the bits like
>> "<OWLClassImpl>" are java classes.
>>
>> {:annotation
>>    #{(annotation #<OWLAnnotationPropertyImpl
>>       <http://www.purl.org/ontolink/tawny/name>>
>>       "PizzaTopping" "en")
>>      (annotation #<OWLAnnotationPropertyImpl
>>       <http://www.ncl.ac.uk/pizza#creator>>
>>       "Phillip Lord" "en")
>>       (label "Ingredienti di Pizza" "it")},
>>  :disjoint #{#<OWLClassImpl <http://www.ncl.ac.uk/pizza#Pizza>>
>>              #<OWLClassImpl <http://www.ncl.ac.uk/pizza#PizzaBase>>},
>>  :type :class}
>>
>> I want to be able to query this data structure, mostly by equality
>> testing,
>> although in some cases, I will need to call methods on the Java objects
>> embedded. And all of this needs to be nil safe because any of the
>> components
>> might be missing.
>>
>> So, with this case, say I want the Italian label, in the set which is the
>> value of the annotation key, find any list with the first element 'label,
>> and
>> third element "it", and return the second element. Of course, this can be
>> done
>> in Clojure, but the code gets complex very quickly.
>>
>> What I'd really want to be able to do is to use some sort of query; so I'd
>> write a data structure like so:
>>
>> {:annotation
>>  #{(label ? "it")}}
>>
>> and have this match and return
>>
>> {:annotation
>>  #{(label "Ingredienti di Pizza" "it")}}
>>
>> which is the bit that matches.
>>
>> I was wondering whether I am missing a trick here, or whether there is
>> some library which does something similar to this.
>>
>> These data structures can get larger and quite heavily nested. To give
>> some
>> idea, this is a more complex example!
>>
>> Thanks!
>>
>>
>>
>> {:annotation
>>   #{(annotation
>>      #<OWLAnnotationPropertyImpl
>>      <http://www.purl.org/ontolink/tawny/name>>
>>      "Parmense" "en")
>>     (label "Parmense" "it")
>>     (annotation #<OWLAnnotationPropertyImpl
>>     <http://www.ncl.ac.uk/pizza#creator>> "Phillip Lord" "en")},
>>  :disjoint
>>    #{#<OWLClassImpl <http://www.ncl.ac.uk/pizza#CapricciosaPizza>>
>>      #<OWLClassImpl <http://www.ncl.ac.uk/pizza#MargheritaPizza>>
>>      #<OWLClassImpl <http://www.ncl.ac.uk/pizza#CajunPizza>>
>>      #<OWLClassImpl <http://www.ncl.ac.uk/pizza#SohoPizza>>},
>>  :type :class,
>>  :subclass
>>     #{(owlonly
>>         #<OWLObjectPropertyImpl <http://www.ncl.ac.uk/pizza#hasTopping>>
>>       (owlor
>>         #<OWLClassImpl <http://www.ncl.ac.uk/pizza#AsparagusTopping>>
>>         #<OWLClassImpl <http://www.ncl.ac.uk/pizza#HamTopping>>
>>         #<OWLClassImpl <http://www.ncl.ac.uk/pizza#MozzarellaTopping>>
>>         #<OWLClassImpl <http://www.ncl.ac.uk/pizza#ParmesanTopping>>
>>         #<OWLClassImpl <http://www.ncl.ac.uk/pizza#TomatoTopping>>))
>>     #<OWLClassImpl <http://www.ncl.ac.uk/pizza#NamedPizza>>
>>     (owlsome #<OWLObjectPropertyImpl
>>       <http://www.ncl.ac.uk/pizza#hasTopping>>
>>       #<OWLClassImpl <http://www.ncl.ac.uk/pizza#HamTopping>>)
>>     (owlsome #<OWLObjectPropertyImpl <
>> http://www.ncl.ac.uk/pizza#hasTopping>>
>>       #<OWLClassImpl <http://www.ncl.ac.uk/pizza#AsparagusTopping>>)
>>     (owlsome #<OWLObjectPropertyImpl <
>> http://www.ncl.ac.uk/pizza#hasTopping>>
>>       #<OWLClassImpl <http://www.ncl.ac.uk/pizza#MozzarellaTopping>>)
>>     (owlsome #<OWLObjectPropertyImpl <
>> http://www.ncl.ac.uk/pizza#hasTopping>>
>>       #<OWLClassImpl <http://www.ncl.ac.uk/pizza#TomatoTopping>>)
>>     (owlsome #<OWLObjectPropertyImpl <
>> http://www.ncl.ac.uk/pizza#hasTopping>>
>>       #<OWLClassImpl <http://www.ncl.ac.uk/pizza#ParmesanTopping>>)}}
>>
>>
>>
>>
>>
>>
>>
>> --
>> Phillip Lord,                           Phone: +44 (0) 191 222 7827
>> Lecturer in Bioinformatics,             Email:
>> phillip.l...@newcastle.ac.uk
>> School of Computing Science,
>> http://homepages.cs.ncl.ac.uk/phillip.lord
>> Room 914 Claremont Tower,               skype: russet_apples
>> Newcastle University,                   twitter: phillord
>> NE1 7RU
>>
>> --
>> --
>> 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.
>>
>>
>>
>  --
> --
> 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.
>
>
>



-- 
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)

-- 
-- 
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