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.