Easy bi-directional data dictionary?

Suppose I have a data dictionary named Alphabet that looks like this

A:Alpha
B:Bravo
C:Charlie
D:Delta
E:Echo
and so on...

I know I can use a filter to index it using {{{ [[Alphabet]getindex[D]] }}}, such that given D I can get Delta. However, I also need to do the inverse: Given Delta I get back D. Right now, I am using a self-written custom javascript filter operator to get the inverse index but I am curious if there is an easier or better way of doing this? Preferably without the need for a second “inverse” data dictionary/tiddler.

1 Like

Would this be a regex pattern to get the first part until the colon, but what do you do with duplicates?

Some thoughts

A robust solution to this would be helpful, as the dictionary could be considered an index table. It is possible to split the text field into lines get[text]splitregexp[/n] and test the value split[:]last[], when matching return the key split[:]first[] however unless very big (this case not > 26) you can just treat the whole thing as a list. Rather than using index.

  • Since a lot of tiddlywiki is done in the browser memory it is most likely very fast even if not the most efficient.

If you think about each entry in the dictionary as a title it is trivial to test for suffix[:Delta].

here is an assumption here there are not duplicate values. but good question.

1 Like

Check out pmario’s keyvalues plugin

3 Likes

How would you use index?

If you have a Data Dictionary or (flat) JSON Data tiddler you can read and write to/from using index as available in a number of widgets, and using ## rather than !! for fields, however this provides only one key.

  • In my example I suggest bypassing this method

I am still thinking about this :thinking:

[Update]

Bi Directional is more than that needed in this case. @intrinsical is asking for what we may call a reverse lookup, get the key from the value. The data needs to be maintained correctly so it does not result in multiple values returned. Limiting the key to a single character is a way to do this.

  • In fact this phonetic alphabet need only be a list of words as the first character is always the key and this can be found in the value

I am very interested in a full “bi-directional data dictionary”, TiddlyWiki does have the tools and capabilities to implement a range of structures and relationships and through smart design we can build an intermediate layer to get and put to a (data) tiddler. All we need is to build the appropriate algorithm, in addition to @EricShulman’s example (below) to handle the second value as unique. Including if we try to write “Delta:” when “D:Delta” exists.

Try this:

{{{ [[Alphabet]indexes[]] :filter[[Alphabet]getindex<currentTiddler>match[Delta]] }}}

-e

3 Likes