Sort my number of tids using a tag

159 views
Skip to first unread message

Mat

unread,
Jul 23, 2019, 4:24:55 AM7/23/19
to TiddlyWiki
How would you sort, say, tags by how many tiddlers that use that tag?
To get a list like

grapes 10
apples 8
lemon 3
banana 3
orange 3
cherry 1

Seems elementary but I'm stumped because you lose the connection between the counted number and what tag the number belonged to. Thanks!

<:-)

Mohammad

unread,
Jul 23, 2019, 5:52:59 AM7/23/19
to TiddlyWiki
Put the number first!
i.e. when calculate number of tids in a macro put them first and sort then!

--Mohammad

Mat

unread,
Jul 23, 2019, 6:22:05 AM7/23/19
to TiddlyWiki
I guess I phrased it poorly; that number is calculated. It says how many tiddlers that use that particular tag. If I add the tag "orange" to some other tiddler then it would move to above lemon in the list. The final list doesn't actually have to show the number, just sort the tags by how many that use them.

<:-)

Mohammad

unread,
Jul 23, 2019, 6:25:30 AM7/23/19
to TiddlyWiki
A simple solution. In tiddlywiki.com

  1. create three tiddler tagged with x
  2. create four tiddler tagged with y
  3. Copy and paste the below code in another tiddler 
\define numTids()
<$list filter=<<tags>> variable="tagName">
<$count filter="[tag<tagName>]" />_._._<<tagName>>
</$list>
\end

\define listTags(tags)
<$vars tags=<<__tags__>> >
<$wikify name="mylist" text=<<numTids>> >
<$list filter="[enlist<mylist>!sortan[]]" variable="item">
<$list filter="[<item>splitbefore[_._._]removesuffix[_._._]]" variable="number">
<$list filter="[<item>removeprefix<number>removeprefix[_._._]]" variable="name">
<<name>> <<number>><br>
</$list>
</$list>
</$list>
</$wikify>
</$vars>
\end

<<listTags "x y">>


Look at the results

y 4
x 3

It works!

--Mohammad

Mohammad

unread,
Jul 23, 2019, 6:26:58 AM7/23/19
to TiddlyWiki
Yes, the code works!
I did not test it for strange tag names like this "my Crazy! [tag+?]]"

--Mohammad

Mat

unread,
Jul 23, 2019, 6:34:42 AM7/23/19
to TiddlyWiki
Thanks for this. That is a process heavy construct and I was/am kind of hoping for something much more direct. I have some vague feeling a subfilter operator might be involved but can't put my finger on it.


I did not test it for strange tag names like this "my Crazy! [tag+?]]"

...but ...but... but that's my favorite tag  :-o

<:-)


 

Mohammad

unread,
Jul 23, 2019, 6:41:12 AM7/23/19
to TiddlyWiki
Mat,
Note that a tag including space will break the code!
If you feel okay to use 5.1.20, then the process is much simpler!

By the way, wait for other people like Mark S, they normally have a magic solution :-) :-)

Cheers
Mohammad

Mohammad

unread,
Jul 23, 2019, 6:42:01 AM7/23/19
to TiddlyWiki
Note to the trick

_._._



:-)

PMario

unread,
Jul 23, 2019, 6:50:00 AM7/23/19
to TiddlyWiki
On Tuesday, July 23, 2019 at 12:34:42 PM UTC+2, Mat wrote:
Thanks for this. That is a process heavy construct and I was/am kind of hoping for something much more direct. I have some vague feeling a subfilter operator might be involved but can't put my finger on it.

The new TW 5.1.20 indexed tag list should have the numbers "for free", the second time you want to know it. ... So a construction like [tag[xx]count[]] should be much much faster than with 5.1.19. except for the first [tag[xx]] run.

The wikify widget on the other hand is a nightmare.

-m




Mohammad

unread,
Jul 23, 2019, 6:56:05 AM7/23/19
to TiddlyWiki
Yep, but it is belong to TW 5.1.20

For wikify widget, it stores the result to be sorted! I don't know what other alternative is available!

--Mohammad

Mat

unread,
Jul 23, 2019, 7:35:58 AM7/23/19
to TiddlyWiki
Thanx guys.


PMario wrote:
The new TW 5.1.20 indexed tag list should have the numbers "for free", the second time you want to know it. ... So a construction like [tag[xx]count[]] should be much much faster than with 5.1.19. except for the first [tag[xx]] run. 

How actually? I con't find any docs.

<:-) 

PMario

unread,
Jul 23, 2019, 10:17:54 AM7/23/19
to TiddlyWiki
It's an internal improvement, which should improve speed for tag _and_ field - filter operators.

see: https://tiddlywiki.com/prerelease/#TiddlyWiki%20Pre-release  Performance improvements 1st point

-mario

Mat

unread,
Jul 23, 2019, 10:47:51 AM7/23/19
to TiddlyWiki
Yes, thanks, but does this answer my question about how to "sort tags by how many tiddlers that use that tag" ? I do accept that it might make the sorting faster but I don't know how to do the sorting. What is the actual filter or widgets that I type?

Thank you for your input regardless if you have an answer to the actual question.

<:-)

Mark S.

unread,
Jul 23, 2019, 12:59:04 PM7/23/19
to TiddlyWiki
First off, I don't think there is a really elegant solution unless you're willing to do the two-step compromise.

The two-step compromise would be to run a tiddler that creates tiddlers that have the count for each tag. After that, it becomes easy to roll a simple list filter report.

Here's my solution that doesn't use the two-step compromise. It's a bit inefficient (especially if you have hundreds of tags), but is straightforward.

\define expr() ^$(counts2)$$
\define listTags(tags)
<$wikify name="counts" text=<<tagcount "$tags$">>>
<$list filter="[enlist<counts>nsort[]]" variable="counts2">
<$list filter="[enlist<__tags__>sort[]]" variable="tag">
<$list filter="[tag<tag>count[]regexp<expr>]">
<<counts2>> -- <<tag>> <br/>
</$list>
</
$list>
</$list>
</
$wikify>
\end
\define tagcount(tags)
<$list filter="[enlist<__tags__>]" variable="tag">
<$list filter="[tag<tag>count[]]"/>
</$list>
\end

<<listTags "TableOfContents About Articles">>


Mohammad

unread,
Jul 23, 2019, 1:32:48 PM7/23/19
to TiddlyWiki
Hi Mark,
Does this solution week for cray tags like the ones with whitespaces and special characters?

--Mohammad

Mark S.

unread,
Jul 23, 2019, 2:23:49 PM7/23/19
to TiddlyWiki
It should work with anything submitted as a stringified full-fledged title list. e.g. this works:

<<listTags "TableOfContents About Articles [[my tag]] [[your täg]] [[my [tag]]] [[my Crazy! [tag+?]]]]">>

I'm sure someone could come up with a title that breaks it, but it would probably also break TiddlyWiki, so the point is somewhat moot ;-)

Mohammad

unread,
Jul 23, 2019, 2:27:58 PM7/23/19
to TiddlyWiki
Yep, That works!

Many thanks for your solution!

That's a magic! :-)

Cheers 
Mohammad

Mohammad

unread,
Jul 23, 2019, 2:28:17 PM7/23/19
to TiddlyWiki
Added to TW-Scripts

Mohammad

unread,
Jul 23, 2019, 2:35:55 PM7/23/19
to TiddlyWiki
I think this can be used to generate tag cloud (or tag crowd)

--Mohammad

Mat

unread,
Jul 23, 2019, 2:43:45 PM7/23/19
to TiddlyWiki
Mark, thank you! It is surprising that what sounds like a rather mundane thing should be so complex.

<:-)

TonyM

unread,
Jul 23, 2019, 6:16:38 PM7/23/19
to TiddlyWiki
I like the ingenuity here but we should be able to find a nicer more elegant way.

I was working on writing each tagname as a key in a data tiddler with the value equal to the count. All good till then but I stopped running down that rabbit hole trying to list the keys ordered by there value.

I think we need the ability to write to a multi column array then manipulate it in the next step without needing triggers or buttons.

With 5.1.20 maths operators I have realised tiddlywiki does not have parenthesis to control the order of evaluation and this along with variables we can manipulate across widgets would give us the capacity to write more elegant solutions.

Regards
Tony

Mohammad

unread,
Jul 23, 2019, 11:55:36 PM7/23/19
to TiddlyWiki
Tony,
 What I proposed uses a tricky delimiter (_._._). As you see it is simple to generate numTids-.-.-tagName and store them in a variable using wikify!
The problem then is to sort and separate them and show as tagName numTids!

The Mark solution is great and handles crazy tag names  but it calculate the numTids in two times *redundant calculation).

--Mohammad

Luis Gonzalez

unread,
Jul 24, 2019, 5:52:05 AM7/24/19
to tiddl...@googlegroups.com
I try to understand the macro. You use the wikify widget to asign mylist the value 4_._._x 3_._._y. If you put:
<$set name="mylist" value=<<numTids>> >

instead <$wikify name="mylist" text=<<numTids>> > the macro assign the same value: 4_._._x 3_._._y to mylist variable but the code does not run. I can't understand why.

I don't understand what is the function of the wikify widget not even reading the documentation.

I think I understand the rest of the macro.

Thanks.

Reply all
Reply to author
Forward
0 new messages