Reverse tag trace

152 views
Skip to first unread message

Damon Pritchett

unread,
Mar 28, 2020, 9:07:55 PM3/28/20
to tiddl...@googlegroups.com
Hey all,

Hope everyone is having a safe and healthy weekend.

I would like to use the list widget and/or macro to do a tag trace on a specific set of tiddlers. In essence, it would be kind of a like a reverse table of contents. I've tried to do this myself, but am really not sure where to start especially since this would be recursive. Let me illustrate what I'd like.

Suppose I have a set of tiddlers that are tagged thusly:

* Tiddler A is tagged with Root
* Tiddler B is tagged with Tiddler A
* Tiddler C is tagged with Tiddler A
* Tiddler D is tagged with Tiddler B
* Tiddler E is tagged with Tiddler D

In Tiddler E, I would like to display something like this:

Tiddler E -> Tiddler D -> Tiddler B -> Tiddler A -> Root

Tiddler C would show Tiddler C -> Tiddler A -> Root

How would I go about doing this?

Many thanks,

Damon

Mark S.

unread,
Mar 28, 2020, 11:28:33 PM3/28/20
to TiddlyWiki
If the structure you created was a "perfect" tree, with no double-backs and only one tag per tiddler, then it might not be too hard to do.

But if you have multiple tags, then you could quickly have a large number of possible paths And if any tiddler has a tag that refers to somewhere down in the tree, then you could end up with an endless loop.

Workarounds for these problems might including a tag list with the invocation. The tag list would indicate which tags are considered part of the tree. The other thing might be to create a list of tiddlers that have already been visited. Then any tags that are that list will not be traversed a second time. These extra precautionary steps make the intended macro more intensive to write.

Another approach would be to trace down a particular path way (top down). Possibly the code in the TOC can already do this. Then save all the paths that are created. Then list over the paths, reversing them, and selecting only the ones that match your branch at the bottom. I've actually never used this approach, so it's a bit more speculative.

Perhaps, more importantly, might be to understand why you want the reverse tree. Sometimes understanding why something is wanted yields simpler solutions.

TonyM

unread,
Mar 29, 2020, 3:35:08 AM3/29/20
to TiddlyWiki
This and much more is all possible with the kin operator of Bimlas. Look for the plugin.

However I have used my own recursive toc inside a button to store the path from the root in a branch field.

Regards
Tony

TonyM

unread,
Mar 29, 2020, 3:38:50 AM3/29/20
to TiddlyWiki
Also

If you created your tree using Mario's TOCP then each tiddler has only one parent so you can climb up the tree using the parent field.

To stop loops just don't continue if a parent us the first tiddler.

Regards
Tony

bimlas

unread,
Mar 29, 2020, 4:50:50 AM3/29/20
to TiddlyWiki
Damon Pritchett,

If you created your tree using Mario's TOCP then each tiddler has only one parent so you can climb up the tree using the parent field.

To stop loops just don't continue if a parent us the first tiddler.


You can do the same with https://bimlas.gitlab.io/tw5-locator/ with tags: open Tiddler E in the sidebar by clicking >> in its toolbar, then open context settings in the toolbar (gears icon) and check "Invert direction" to list the parrents of the tiddler instead of its children.

Damon Pritchett

unread,
Mar 29, 2020, 6:05:57 PM3/29/20
to TiddlyWiki
Thanks for the suggestions. We'll see what I can come up with.

To answer Mark's question, each tiddler represents a railroad that I am researching railroads tended to be absorbed or purchased by other companies. So in an effort to show the string of companies that any particular railroad went through over time is why I asked the question.

Damon


On Saturday, March 28, 2020 at 6:07:55 PM UTC-7, Damon Pritchett wrote:

TonyM

unread,
Mar 29, 2020, 7:30:09 PM3/29/20
to TiddlyWiki
There is a great graphical timeline plugin somewhere.

Arguably tiddlywiki can do anything so I urge you try and store the information you have then learn how to present the relationships latter.

To do this well you need to create a tiddler for each entity such as railway lines and businesses then seperatly relationships such as business owns railway. Since the ownership can change you not only need to cater for ownership but start and end dates of ownership. Of course the passage of time will change ownership or add segments to a line so the relationships need to be kept as a series of events.

I will consider what is needed for this as its a critical algorithium for many applications.

Regards
Tony

Damon Pritchett

unread,
Mar 29, 2020, 7:56:34 PM3/29/20
to tiddl...@googlegroups.com
Thanks Tony,

The kin operators lists the tiddlers just like I'm looking for except that they're in alphabetical order (or reverse with the reverse operator). Now I've just got to figure out another sorting method using a field (existing or new) which is easy enough.

The Locator plugin works very well also. Decisions, decisions.......

Damon

bimlas

unread,
Mar 30, 2020, 1:44:45 AM3/30/20
to TiddlyWiki
Damon,

The kin operators lists the tiddlers just like I'm looking for except that they're in alphabetical order

You can use "[[Tiddler E]kin::from[]]" instead of "[kin::from[Tiddler E]]" to get the hierarchical order - it's not perfect, but I hope it's a good start.

Damon Pritchett

unread,
Mar 30, 2020, 7:01:11 PM3/30/20
to TiddlyWiki
Thanks Bimlas,

That did the trick.

Damon

Damon Pritchett

unread,
Mar 31, 2020, 1:48:31 PM3/31/20
to TiddlyWiki
Ok so here's what I did and it does exactly what I was looking for.

  <$list filter="[title<currentTiddler>kin:tags:from[]!is[system]!title[Railroads]!title<currentTiddler>]"> ->
    <$link><$view field="title"/>
    </$link>
  </$list>

Thanks to everyone!

Damon
Reply all
Reply to author
Forward
0 new messages