Selecting tiddlers with *only* two tags

143 views
Skip to first unread message

Diego Mesa

unread,
Nov 3, 2017, 5:59:19 PM11/3/17
to TiddlyWiki

Hello all,

How can I return all tiddlers that have only two tags: tagA, tagB, for example? I might have posts with tagA, taB, tagC, ... with an undetermined number of additional tags. How can I just return tiddlers with just those two tags?

Thanks!

Mark S.

unread,
Nov 3, 2017, 6:42:08 PM11/3/17
to TiddlyWiki
I think you're saying you want it to have TagA AND TagB but no other tags. So a filter like:

[tag[TagA]tag[TagB]] -[has[tags]!tag[TagA]!tag[TagB]]

Might do it.

Mark

Jed Carty

unread,
Nov 4, 2017, 5:48:51 AM11/4/17
to TiddlyWiki
The short answer is that you can probably do this using the contains plugin by Tobias https://tobibeer.github.io/tw5-plugins/#contains and ignore everything I say below. The long answer is below and as much for a later discussion as anything else.

Sorry about the long a overly detailed response, this is an area that I am very interested in and you gave me a good example to work with. So thank you!

I have been trying to track down which logic statements you can't express using filters and I believe that you have found one. From what I can determine right now the only way to do this currently is to use an intermediate step where you would have to save a list to a field and then use that list to get your final result, which means you would have to click a button at least once to update the list.

I made a wiki with some explanation of how logic statements correspond to filters, it may be useful: http://ooktech.com/jed/ExampleWikis/FilterLogicExamples/

I have a working version that makes you click a button to update the list correctly, but it is mostly for my notes so that I can make a filter that lets you do this because this version is kind of awkward.

To do this with any number of tags you need to fulfil two criteria: 
* You need the set TagA and TagB to be a subset of the tags of the tiddler 
* You also need the union of the set of all tags minus TagA and TagB with the tags of your filter to the the empty set.

You can put this demo code into a tiddler on tiddlywiki.com, after clicking the button 
<!-- Get the set of all tags minus (TagA, TagB), store it in a field -->
<$button>
<$action-setfield $tiddler='$:/temp/IntermediateList' list=''/>
Get Excluded Tiddlers
<!-- The first filter builds the set of excluded tags -->
<$list filter='[all[]tags[]] -[[ActionWidgets]] -[[Widgets]]' variable=ExcludedTag>
<!-- The second list returns all tiddlers that have tags that we need to exclude from our result -->
<$list filter='[tag<ExcludedTag>]'>
<$action-listops $tiddler='$:/temp/IntermediateList' $field='list' $subfilter='+[append<currentTiddler>]'/>
</$list>
</$list>
</$button>
<!-- Now take the set of all tiddlers with the TagA and TagB and subtract the excluded tiddlers list -->

! Excluding Other Tags

<$list filter='[tag[ActionWidgets]tag[Widgets]]-[list[$:/temp/IntermediateList]]'>


</$list>

! Without Excluding Other Tags

<$list filter='[tag[ActionWidgets]tag[Widgets]]'>

</$list>

Is looks like one thing we are missing from what filters can do is checking if a set contains an element. We can check if A is contained in set B (that is what tag[foo] or field:foo[bar] does), but we can't check if set B contains A. Tobias may have worked on a filter to do this a while ago. If we had that filter than we could replace the above code with something like this:

<$set name=ExcludedTags filter='[all[]tags[]]-TagA-TagB'>
<$list filter='[tag[TagA]tag[TagB]!contains:tags<ExcludedTags>]'>

</$list>
</$set>

the contains operator would return the input title if the set intersection between the field of the input tiddler and the parameter (which could be a list or a single item) is anything other than the empty set. The negated operator (!contains) would return the input title if the intersection is the empty set.

@TiddlyTweeter

unread,
Nov 4, 2017, 7:25:06 AM11/4/17
to TiddlyWiki
Ciao Mark S.

The odd "add then exclude all else by negatives" of that is enlightening.

Is it the LONG way to Pimlico? OR efficient enough?

Best wishes
Josiah

Jed Carty

unread,
Nov 4, 2017, 9:59:12 AM11/4/17
to TiddlyWiki
Take everything and exclude what you don't want based on negative conditions is a very common tactic in set theory and if often the only way to get a result you want.

I made a plugin that with some filter operators that will allow you to do what Diego is asking about. You can see the demo here the plugin tiddler to add it to your wiki is here but I am the only one who has tested it so far.

Mark S.

unread,
Nov 4, 2017, 10:06:44 AM11/4/17
to TiddlyWiki
If efficiency is your goal, you're probably using the wrong product. No, really. There are no permanent indices in TW as in dbf and sql environments. It's like the universe is created anew every morning.

Mark

P.S. Is there a pressing need to get to Pimlico?

Mark S.

unread,
Nov 4, 2017, 10:09:58 AM11/4/17
to TiddlyWiki
Hi Jed,

Please consider submitting a PR to have these filters put in the core. I know you probably think they're beta, but by the time they're accepted you'll have had plenty time to thrash them a bit.

Re the name 'overlap', maybe 'intersect' ?

Mark

Diego Mesa

unread,
Nov 4, 2017, 4:08:35 PM11/4/17
to TiddlyWiki
Thanks very much Jef! 

TonyM

unread,
Nov 4, 2017, 7:03:15 PM11/4/17
to TiddlyWiki
Jed,

I too, took this request as an opportunity to test my growing knowledge of TiddlyWiki, I do not have the skills, or perhaps tiddlywiki does not have the features to finish the approach I came up with but given your interest I thought I would pass it on to you.

One approach is as follows (Test tags called On and Off)

Determine the sum of characters required for the two tags +1 =Tagslength
thus length of the tag field if only tagged with these two tiddlers

Use a List to extract only tiddlers tagged with the required tiddlers
<$list filter="[tag[On]] +[tag[Off]]">

Then throw away all cases where tags field in longer than Tagslength
What remains is what was needed.

Notes:
This should be extensible to any number of tags


Opinion
I suspect Diego could have designed his TiddlyWiki such that this was not needed, the fact he does not know what other tags to exclude, or must exclude, suggests something astray in his wiki's design.
Note: I am prepared to prove this if Diego wants my help, not code but design.

As someone climbing the TiddlyWiki learning mountain, I find my path impeded by two things;
  1. The Complexity and context sensitive nature of references.
  2. The Gaps between what may need to be done and what can be done (especially in light of my ignorance)

I am not ignorant of coding with expertise in at least two languages, but I admit I am struggling to make progress as rapidly as I expect (although I am learning quickly). Either I am loosing my faculties or TiddlyWiki is resisting my learning it.


In TiddlyWiki we should be able to do any primitive set manipulation, queue manipulation, any basic database lookup, basic counts and structures like do until, decisions, cases etc... and do this on any TiddlyWiki object like tiddlers, Tags, Fields. Until this is the case it will be hard to learn, because we can waist a lot of time looking for things that do not exist.  (or are undocumented).


I value your contribution to addressing the gaps.


Regards

Tony








 

@TiddlyTweeter

unread,
Nov 4, 2017, 7:24:35 PM11/4/17
to TiddlyWiki
P.S. Is there a pressing need to get to Pimlico?

Victoria or Vauxhall would do.

Ste Wilson

unread,
Nov 5, 2017, 5:18:19 AM11/5/17
to TiddlyWiki
Invokes the Hapsburg convention... Again...
Reply all
Reply to author
Forward
0 new messages