DictionaryTiddlers to fields

I created a DictionaryTiddler (ContentType application/x-tiddler-dictionary) & name it $:/accounting.directory. The $:/accounting.directory file’s data sits in the DictionaryTiddler like so

0.028349g Gold Troy	:	000.000.000002
0.141747g Gold Troy	:	000.000.000014
0.283495g Gold Troy	:	000.000.000028
0.709823g Gold Troy	:	000.000.000070
1.419475g Gold Troy	:	000.000.000141
28.34952g Gold Troy	:	000.000.002834
56.69905g Gold Troy	:	000.000.005669

The following tiddlywiki code sits in a separate Tiddler titled journal.entry; it retrieves an individual entry from the DictionaryTiddler and allocates its value into a variable $:/name; as part of a form; here’s the following block:

<$select tiddler="$:/name" default="action-navigate">
<$list filter='[[$:/accounting.directory]indexes[]sort[title]]'>
<option value=<<currentTiddler>>>
<$text text=<<currentTiddler>>/>
</option>
</$list>
</$select>
var: 
[[$:/name]] => {{$:/name}}
  1. How can I transfer that selected choice (name: value) pairs into two fields one holding the name and the other the value?

  2. Can a one field solution be possible? i.e. [name : value] into [field : value]?

1 Like

I think these do what you’re looking for:

  1. val: {{{ [[$:/accounting.directory]getindex<currentTiddler>] }}}
    

    The operator getIndex retrieves the value for the given key in dictionary tiddler

  2.  <option value={{{ [<currentTiddler>]  [[$:/accounting.directory]getindex<currentTiddler>] +[join[ : ]] }}}>
    

    Here we just change the value of the OPTION element while leaving its display name as the key.

That’s how I did understand it:

\procedure getValue()
<$action-setfield $tiddler=test $field=value $value={{{ [[$:/accounting.directory]getindex{$:/name}] }}}/>
<$action-setfield $tiddler=test $field=name $value={{$:/name}}/>
<$action-setfield $tiddler=test text=`name: {{!!name}}<br>
value: {{!!value}}`/>
\end

<$select tiddler="$:/name" actions=<<getValue>> default="select a value">
<$list filter='[[$:/accounting.directory]indexes[]sort[title]]'>
<option value=<<currentTiddler>>>
<$text text=<<currentTiddler>>/>
</option>
</$list>
</$select>
var: 
[[$:/name]] => {{$:/name}}

And your dictionary should also have an additional index

select a value:
0.028349g Gold Troy	:	000.000.000002
1 Like

Why would you put that in the dictionary rather than in a separate OPTION before the ListWidget?

That seems to be mixing display information with data, which sounds like a bad idea.

For some korky reason any changes to my code breaks the function to populate the selectWidget; hence I haven’t been able to grab each side of the (pair:data). I was hoping someone could set it up and test their suggestions to see if it produces the desired outcome.

Haven’t figured out why indexing has become so tricky. I spent like 50 itirations back and forth with a few ai’s and their code suggesstions.

If there is an easier approach/better practice to setup datatiddlers to select an entry from a lengthy directory of account numbers, I am open to any solution.

First of all, I didn’t say in my first response, welcome to the talk.tiddlywiki community!

I have fixed my two answers above. I don’t know why they were broken, as I did test them before posting. The changes to your original were so slight that I only posted the new lines. But they are definitely broken. It’s still not clear to me how that happened.

In any case, here’s #2, the way I understood it. Download the following link and drag the resulting file to any wiki (I would use https://tiddlywiki.com/ myself) and select Import:

ttw9802.json (844 Bytes)

The only change here is the value of each option:

<option value={{{ [<currentTiddler>] [[$:/accounting.directory]getindex<currentTiddler>] +[join[ : ]] }}}>

First of all, I didn’t say in my first response, *welcome to the talk.tiddlywiki community!

Lol I was the one plunging into the tiddly pool all cannon ball <style> splashing questions all over you fine people. I apologize for not greeting the community, by the time I found myself at this forum I was down to my last tiddly.

Thank you Scott for accepting me into your clan. I really don’t know jack tiddly about this non-linear notebook, I don’t know a tiddly soul in this cruel world who uses TW5, So I truly appreciate your communitty’s warm/rapid responces, your knowledge, your experience and perhaps even a tiddly bit of your heart.

About this fat.elephant in the tiddlyroom:

I am confused as to how to setup your suggestions; or what is the purpose/function for the ‘.json’ file?

Could you include the tiddly’s entire codeblock to assure i’m snipping it into the Tiddler correctly. As a non programmer I tend to waste unnecessary time causing bugs rather than results.

The example text / key may be misleading. It could also be

default: n/a or
none: --

I would add it there for maintenance reasons. It’s less error prone to modify a data-tiddler than the code.

Just my thoughts

1 Like

I just updated the title to be a little more specific, feel free to edit, it was just misleadingly generic.

  • However this has inspired me to ask if I could use functions and macros to provide a set of “methods” to read and write data tiddlers as if they were files so people less familiar with filters could make use of data tiddlers.
  • Ultimately we could extend this to groups of tiddlers and even a form of SQL.

Not at all. We do have a tradition here of greeting first-time posters, and welcoming back long-absent ones. I was the first responder, and although I did get the notification that you were new, I was deep in my answer and forgot to include it. Again, welcome!

Right above the link, I said,

In any case, here’s #2, the way I understood it. Download the following link and drag the resulting file to any wiki (I would use https://tiddlywiki.com/ myself) and select Import

That included my versions of the two tiddlers you discussed. When you download it and then drag the resulting file to, say, tiddlywiki.com, you will get a “Do you want to import these files?” message. Import them and you will have links to $:/accounting.directory and journal.entry. Open the latter one and you should see a version where the dropdown displays only the key, but the value selected has a :-separated key and value…

That’s very interesting. I have the exact opposite feeling. I expect that if I’m putting it in a data tiddler it’s because it might get used in multiple places. I would never want to have one drop-down’s display to alter my data. Perhaps I have another spot with a list or grid of checkboxes with those key/values. Perhaps elsewhere I need to count the number of elements in the data. Etc.

I don’t want to argue. It takes all sorts. But it’s interesting to see the differing approaches.

I don’t know what that would look like. Forgetting how it’s implemented for now, do you have a proposed syntax for how we would access them and use them?

If I had this data tiddler:

title: Town Buildings
type: application/x-tiddler-dictionary

Town Hall: 123 Center Street
Library: 100 Biblio Lane
Maintenance Garage: 999 Trucking Road
Fire Department:  555 Hearth Avenue
Primary School: 987 School Street
Secondary School: 456 Ridge Road

what would you like to see to get you the list of building names, the street for a building, the list of all addresses involved, etc? Or when you talk about this as similar to files, is there a higher level you’re considering where you “load” this data? What would that look like?

Curious minds want to know!

When you download [the file] and then drag the resulting [.json] file to a [TW notebook], you will get … [pre-setup set of tiddlers]

Wow, i did not know that dragging a text file into a tiddly can produce a tiddler setup with multiple tiddlies; its like digital reproduction, we should call that process Tiddlyficial insemination; I have much to learn from you OB1.

We managed to retrieve both pieces of data; however we should include code that will satisfy this treads new title’s objective, that has not yet been met, a snippet transferring the value retrieved into the fields.

1 Like

Well this is a dictionary tiddler, thus only has a key and value, although our value can be divided into street-number/name “NNN XXXXXXXXXXXXXXXXX”, or split[ ]first[] and split[ ]rest[]. We could have an open, read, write, list, and search, with knowledge of the fields/columns. I am not sure how to trigger the write.

Perhaps its just a “Brain Fart” but the idea would be to obtain a simple syntax for file handling, such as found in the Basic programing language, but this would refer to a data tiddler.

But rather than use a dictionary tiddler for anything beyond key/value pairs, I am tempted to use JSON.

Did you test my code? DictionaryTiddlers to fields - #3 by pmario

I did, and now I am embarrassed that I was looking for a <<currentTiddler>>, last night, instead of a quite introverted tiddler named test; my apologies to both you and poor test who been holding on to those two index values all night like a good tiddler.

Great Scott!! Did I mention that you guys are awesome? Thanks Mario, I now see why Princess Peach Toadstool is infatuated with you, you’re a hero with amazing tiddly powers.

Yes, understood. I’m just wondering what sort of syntax you are imagining. For a data tiddler or for JSON, how would you expect this new syntax to look?

But if you don’t want me to leave it to your imagination I asked ChatGPT as an example below. However This terminology is still “open”, if you have a good set of words let me know.

Notes on below example;

  • Open may actually be the act of selecting the tiddler to act on, close just end of open.
  • Within read and write we could add field/column references or have the recordVariable then define the fields there in, eg to a temp tiddler.
  • I would put a greater emphasis on direct access not batch lists.

Pseudocode is a simplified, high-level representation of a programming task, using plain language mixed with programming conventions. When writing pseudocode for file and record handling, it's important to use clear, understandable terms that convey the operations being performed without being tied to the syntax of a specific programming language.

Here are suitable pseudocode terms and structures you might use for file and record handling tasks:

General Terms for File Handling

  • File: Represents a collection of data stored in a non-volatile storage system, such as a hard disk.
  • Record: A collection of related data items stored as a single unit within a file, typically represented as a row in a database or a line in a text file.

Pseudocode Operations

  1. Open File: Prepare a file for reading or writing.

    Open file "filename" for [mode]
    
  2. Close File: Close the file once operations are completed to free up system resources.

    Close file "filename"
    
  3. Read Record: Retrieve a record from a file.

    Read record from "filename" into recordVariable
    
  4. Write Record: Write a record to a file.

    Write recordVariable to "filename"
    
  5. Check End of File (EOF): Determine if the end of the file has been reached during a read operation.

    If EndOfFile("filename") then
    
  6. Seek: Move to a specific part of the file, often used in files that allow random access.

    Seek "filename" to position
    
  7. Delete Record: Remove a record from a file (this may require rewriting the file without the deleted record).

    Delete record from "filename"
    
  8. Update Record: Modify a record within a file.

    Update record in "filename" with newDetails
    

Example Pseudocode for File Handling

Here’s an example of how you might structure pseudocode to handle reading from a file and processing records:

Open file "data.txt" for reading
While not EndOfFile("data.txt")
    Read record from "data.txt" into currentRecord
    Process currentRecord
End While
Close file "data.txt"

This pseudocode outlines a common pattern where a file is opened, processed record-by-record until the end of the file is reached, and then the file is closed. These terms and operations are typical for file and record handling in any programming task, providing a clear, structured approach that can be translated into actual code in most programming languages.

Sure. What I don’t remember from my (ancient) BASIC days, I can easily look up. I’m trying to figure out how you’d want to use your ideas inside TW.

And is this what you’d want for TiddlyWiki syntax? That doesn’t look likely.

And in the end, it seems no more useful than something like:

<$list filter="[[Town Buildings]indexes[]]" variable="key">
  <$transclude $mode=block $variable=process key=<<key>> value={{{ [[Town Buildings]getindex<key>] }}}>>
</$list>

What is it I’m missing?

I thought the suggestions I made was enough to trigger your imagination. For me to illustrate further, I need to take the step of implementing a case. Which is further than I planned to go at this point.

The idea would be to reduce the complexity to simple variables you can set then have “standard procedures and functions”, that hide the complexity of index and field handling though a kind of subject area specific meta language.

  • Especially when it comes to action widgets

The same method could be used many times for different data tiddlers.

  • Basically giving you a canned set of refined tools for handling data tiddlers.
  • Another way to explain it may be to “parametrise it”, hide the complexity behind a set of parameters.
1 Like