Retrieving the number of link paths to a tiddler

108 views
Skip to first unread message

Soren Bjornstad

unread,
Aug 7, 2021, 10:12:51 PM8/7/21
to TiddlyWiki
I have a wiki where I want to cross-correlate concepts across uses of these concepts. (A concept, in this example, can be defined as any tiddler not tagged Use, while a use is obviously any tiddler tagged Use.) By "cross-correlate", I mean that given the current tiddler is a concept tiddler, find all the other concept tiddlers that are used on any use tiddler that links to the current tiddler (that is, they are often used together).

I can do this with the following filter:

[all[current]backlinks[]tag[Use]links[]!tag[Use]]

However, I would now like to retrieve (and sort by) the number of discrete link paths by which you can reach each concept (i.e., the number of times the current tiddler and this other concept are used together on a use tiddler). So if 5 use tiddlers which link to the current tiddler also link to a particular other concept tiddler, the number 5 should be accessible in a variable when $list'ing through that concept tiddler, to be used in sortsub[] or the like and the template displaying each match.

I haven't been able to think of any way to do this – I tried using the = filter prefix, but this evidently does not work when you're not adding the results to anything (and probably tag[] and links[] already deduplicate before they start).

Since I'm sure what I want is absolutely clear as mud at this point, here's a diagram of a toy example, with arrows representing links and the green numbers showing how many “matches” there would be for my search criteria:

ksnip_20210807-210609.png

As always, thanks for any suggestions!

TW Tones

unread,
Aug 8, 2021, 1:45:51 AM8/8/21
to TiddlyWiki
Soren

Without working through this requirement of yours, I suspect some of the code patterns in my recent reply to another thread could help you.
  1. Your could make a list of all tiddler links (as a variable) without removing duplicates, then listing a given tiddler you could count how many mentions it has.
  2. With the prerelease Sort Filter Run Prefix should allow you to sortby the count of mentions as per the filter in 1.
Regards
Tones

Soren Bjornstad

unread,
Aug 8, 2021, 8:56:23 AM8/8/21
to TiddlyWiki
Thanks Tones!

Looks like I may have been overthinking this – just :filter, working backwards from the match found and seeing when you hit the current tiddler, is sufficient:

\define xcor-sort() [backlinks[]tag[Use]] :filter[links[]field:title<currentTiddler>] +[count[]]
\define xcor-count() [<crossRef>backlinks[]tag[Use]] :filter[links[]field:title<currentTiddler>] +[count[]]

...

<$list filter="[all[current]backlinks[]tag[Use]links[]!tag[Use]!field:title<currentTiddler>sort[]!sortsub<xcor-sort>]" variable="crossRef">
  <$set name=numPaths filter=<<xcor-count>>>
<li><$link to=<<crossRef>>/> (<$text text=<<numPaths>>/> occurrence(s))</li>
  </$set>
</$list>

(A different subfilter is needed for the sort than to populate the count variable in 5.2.3 since the tiddler being processed by a subfilter can't be retrieved through a variable. This could probably be tweaked in prerelease so you only need one subfilter.)
Reply all
Reply to author
Forward
0 new messages