I have an idea. Let's call the "associative array" a "map" just so we don't have so many "array" words.
On Tue, Sep 29, 2015 at 12:44 PM, Rolf Huehne <rhue...@fli-leibniz.de> wrote: > On 09/28/2015 06:46 PM, Robert Hanson wrote: > Implemented are now the following combinations (among others), if I > understood it correctly: > > A) associative + no brackets > -> Searches in the first-level keys of the associative array. Returns > a complete subset of the first-level array with the matching keys. > > A) map + keys -> Returns the specified subset of key/value pairs. > B) associative + brackets > -> Searches in the first-level keys of the associative array. Returns > only the values (which can be scalars or arrays) behind the matching keys. > > B) map + (keys) -> Same as (A), but returns an array of values instead of a map. > C) standard/associative + no brackets > -> Searches the second-level keys. Returns a subset of the > first-level array with the named second-level keys only. > C) any array or array of arrays of maps + keys -> returns a flat array of maps containing only the specified key/value pairs. > D) standard/associative + brackets > -> Searches the second-level keys. Returns the values behind the > named second-level keys. > D) any array or array of arrays of maps + (keys) -> returns a flat array of values of the specified keys. > E) standard/associative + WHERE + no brackets > -> Searches keys from 2) and of phrase from 3) in the second-level > keys of the associative arrays. Returns a complete subset of the > first-level array with the matching second-level keys, restricted by the > 'WHERE' phrase. > E) array or array of arrays of maps + keys + WHERE clause -> same as C, but only for maps that match the specified clause > F) standard/associative + WHERE + brackets > -> Searches keys from 2) and of phrase from 3) in the second-level keys > of the associative arrays. Returns only the values of the second-level > array with the matching second-level keys, restricted by the 'WHERE' > phrase. > > F) array or array of arrays of maps + (keys) + WHERE clause -> same as E, but returns values instead maps. > G) associative/associative + WHEREIN + no brackets > -> Searches keys from 2) in the first-level keys and keys of phrase from > 3) in the second-level keys of the associative arrays. Returns a subset > of the first-level array with the matching first-level keys, restricted > by the 'WHERE' phrase. > > G) map where values are maps + keys + WHEREIN clause -> same as A, but only returns the key/value pairs for which the value (a map as well) matches the clause. > H) associative/associative + WHEREIN + brackets > -> Searches keys from 2) in the first-level keys and keys of phrase from > 3) in the second-level keys of the associative arrays. Returns a subset > of the values of the first-level array with the matching first-level > keys, restricted by the 'WHERE' phrase. > > H) map where values are maps + (keys) + WHEREIN clause -> same as B, but only returns the key/value pairs for which the value (a map as well) matches the clause. The multi-level combinations C) to F) have in common that the key > restrictions from 1) act on the same level as the keys of the phrase > from 3). In contrast in the multi-level combinations G) and H) the > levels are mixed. This doesn't seem to be very consistent to me. At > least it seems to be counterintuitive. > > G and H simply look one level deeper into a map > Even if you don't agree, there are two missing cases where the levels > are not mixed. Assuming a "consistent" behaviour they would look like this: > > ---- Example Code ------------ > snpInfo = {"rs1229984": [resno: 48, > from: "R", > to: "H"], > "rs1041969": [resno: 57, > from: "N", > to: "K"] > }; > > print "=== Case 1 ===="; > print snpInfo.select("from,to WHEREIN to='H'").format("JSON"); > > The keys are always for the top-level map. Here you are trying to bypass a map level with the keys.That's not in the schema and should not be intuitive. The closest you can come is print snpInfo.select("* WHEREIN to='H' ") and just accept that resno is still there. > print "=== Case 2 ===="; > print snpInfo.select("(resno) WHEREIN to='H'"); > > Same here -- You are trying to bypass a map level with (resno). No one has suggested doing that. > > For my usual use of multi-level associative arrays these two cases would > be the standard. But of course also the currently implemented two cases > do make sense. I have no idea yet, how a good syntax for them could look > like. > I'm not sure why it would be important to filter out those extra keys. The way to do it is to go to a more database-like structure: snpInfo = [ [ id: "rs1229984", resno: 48, from: "R", to: "H" ], [ id: "rs1041969", resno: 57, from: "N", to: "K" ] ] Then you could use print snpInfo.select("resno,from,to WHERE to='H') It might be an idea to be able to go back and forth from map to array using something like: a = snpInfo.array("id") snpInfo = a.array("id") Then you could do what you want like this: print "=== Case 1 ===="; print snpInfo.array("id").select("id,from,to WHERE to='H'").array("id").format("JSON"); Bob -- Robert M. Hanson Larson-Anderson Professor of Chemistry Chair, Department of Chemistry St. Olaf College Northfield, MN http://www.stolaf.edu/people/hansonr If nature does not answer first what we want, it is better to take what answer we get. -- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900
------------------------------------------------------------------------------
_______________________________________________ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users