1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-24 17:10:29 +00:00

Merge branch 'tiddlywiki-com'

This commit is contained in:
jeremy@jermolene.com 2021-12-06 17:05:43 +00:00
commit 804bc9e9c0
8 changed files with 119 additions and 21 deletions

View File

@ -2,7 +2,7 @@ caption: Quoi de neuf dans <<version>>
color: #fff
created: 20160603124050989
fr-title: BonjourLaVignette - Dernière Version
image: New Release Banner.png
image: New Release Banner
link: Releases
modified: 20160603124131122
tags: HelloThumbnail

View File

@ -1,5 +1,5 @@
created: 20150124182421000
modified: 20211124193218807
modified: 20211129014550442
tags: [[Filter Syntax]]
title: Filter Expression
type: text/vnd.tiddlywiki
@ -23,7 +23,9 @@ If a run has:
* the prefix `~`, if the filter output so far is an empty list then the output titles of the run are [[dominantly appended|Dominant Append]] to the filter's output. If the filter output so far is not an empty list then the run is ignored. <<.from-version "5.1.18">>
* named prefixes for filter runs are available. <<.from-version "5.1.23">>
* named prefix `:filter`, it receives the filter output so far as its input. The next run is evaluated for each title of the input, removing every input title for which the output is an empty list. <<.from-version "5.1.23">>
** See [[Filter Filter Run Prefix]].
* named prefix `:intersection` replaces all filter output so far with titles that are present in the output of this run, as well as the output from previous runs. Forms the input for the next run. <<.from-version "5.1.23">>
** See [[Intersection Filter Run Prefix]].
* named prefix `:reduce` replaces all filter output so far with a single item by repeatedly applying a formula to each input title. A typical use is to add up the values in a given field of each input title. <<.from-version "5.1.23">>
** See [[Reduce Filter Run Prefix]].
* named prefix `:sort` sorts all filter output so far by applying this run to each input title and sorting according to that output. <<.from-version "5.2.0">>

View File

@ -0,0 +1,30 @@
created: 20211129022707404
modified: 20211204154839890
tags: [[Filter Syntax]] [[Filter Run Prefix Examples]] [[Filter Filter Run Prefix]]
title: Filter Filter Run Prefix (Examples)
type: text/vnd.tiddlywiki
<<.operator-example 1 "[tag[HelloThere]] :filter[get[text]length[]compare:integer:gteq[1000]]">>
<<.operator-example 2 "[tag[HelloThere]] :filter[get[text]length[]compare:integer:lteq[2000]]">>
<<.operator-example 3 "[tag[HelloThere]] :filter[get[text]length[]compare:integer:gteq[1000]] :filter[get[text]length[]compare:integer:lteq[2000]]">>
<<.operator-example 4 "[tag[Features]] :filter[links[]!is[shadow]is[missing]]">>
<<.operator-example 5 "A B C D E F :filter[<index>remainder[2]compare:integer:eq[0]]" "Return every other element of the input list">>
<<.operator-example 6 "[tag[shopping]] :filter[{!!quantity}compare:integer:gt[4]] :map[addprefix[ ]addprefix{!!quantity}]">>
<<.operator-example 7 "[tag[shopping]] :filter[{!!quantity}compare:integer:lteq[4]] :map[addprefix[ ]addprefix{!!quantity}]">>
!! Comparison between `:filter` and `:and`/`+` filter run prefixes
The functionality of the <<.op :filter>> filter run prefix has some overlap with the <<.op :and>> prefix (alias <<.op +>>). Notice the filter expressions above all have the following two properties:
# The start of the filter expression transforms the input titles (i.e. `get[text]length[]`, `links[]`, `<index>remainder[2]`, `{!!quantity}`.
# The end of the filter expression only sends input items to the output if they meet some condition (i.e. `compare`, `is`).
The purpose of the <<.op :filter>> prefix is to return the original input titles despite property #1 causing those input titles to be transformed. That way, the "meet some condition" check can be performed on something other than the original input. If some filter expression does not require property #1, then the <<.op :and>> prefix can be used instead.
| <<.op :filter>> | <<.op :and>> |
|^<<.operator-example c1.1 "[tag[HelloThere]] :filter[get[text]length[]compare:integer:gteq[1000]]">>|^<<.operator-example c1.2 "[tag[HelloThere]] :and[get[text]length[]compare:integer:gteq[1000]]">>|
|^<<.operator-example c2.1 "[tag[Features]] :filter[links[]!is[shadow]is[missing]]">>|^<<.operator-example c2.2 "[tag[Features]] :and[links[]!is[shadow]is[missing]]">>|
|!results are the same|<|
|^<<.operator-example c3.1 "cat can bat bug :filter[suffix[at]minlength[3]]">>|^<<.operator-example c3.2 "cat can bat bug :and[suffix[at]minlength[3]]">>|

View File

@ -0,0 +1,27 @@
created: 20211129022455873
modified: 20211129022550425
tags: [[Filter Syntax]] [[Filter Run Prefix]]
title: Filter Filter Run Prefix
type: text/vnd.tiddlywiki
<<.from-version "5.1.23">>
|''purpose'' |remove every input title for which the filter run output is an empty list |
|''input'' |all titles from previous filter runs |
|''output''|the input titles for which the filter run is not empty |
It receives the filter output so far as its input. The next run is evaluated for each title of the input, removing every input title for which the output is an empty list.
Note that within the filter run, the "currentTiddler" variable is set to the title of the tiddler being processed. This permits filter runs like `:filter[{!!price}multiply{!!cost}compare:integer:gteq[5]]` to be used for computation. The value of currentTiddler outside the run is available in the variable "..currentTiddler".
The following variables are available within the filter run:
* ''currentTiddler'' - the input title
* ''..currentTiddler'' - the value of the variable `currentTiddler` outside the filter run.
* ''index'' - <<.from-version "5.2.1">> the numeric index of the current list item (with zero being the first item in the list).
* ''revIndex'' - <<.from-version "5.2.1">> the reverse numeric index of the current list item (with zero being the last item in the list).
* ''length'' - <<.from-version "5.2.1">> the total length of the input list.
<<.tip "Compare named filter run prefix `:filter` with [[filter Operator]] which applies a subfilter to every input title, removing the titles that return an empty result from the subfilter">>
[[Examples|Filter Filter Run Prefix (Examples)]]

View File

@ -1,29 +1,16 @@
created: 20201117073343969
modified: 20211124153029405
modified: 20211129032537195
tags: [[Filter Syntax]] [[Filter Run Prefix Examples]]
title: Filter Run Prefix (Examples)
type: text/vnd.tiddlywiki
!! Difference between `+` and `:intersection`
!! `:filter` examples
The `+` prefix should be thought of as an "AND" in formal logic, e.g. "give me all titles that satisfy condition A ''and'' condition B". But it's not suitable for all cases; if condition B uses a filter operator that replaces its input, then it will be difficult to use the `+` prefix. For example, if you wanted to find out what tags two tiddlers have in common, you might try to write a filter expression like:
See [[Filter Filter Run Prefix (Examples)]]
* <$link to="tags Operator">`[[field Operator]tags[]] +[[compare Operator]tags[]]`</$link>
!! `:intersection` examples
But that won't work, because the second filter run will end up throwing away its input and replacing it with an input consisting of the single title `[[compare Operator]]`. So the result you'd get from that filter expression would be just the tags of the `compare Operator` tiddler.
For cases like this, the `:intersection` prefix is what you need. It takes the filter output so far, //sets it aside//, and starts the next filter run with all tiddler titles as input. Then once the latest filter run has completed, it takes the latest output, compares it to the set-aside output, and produces a new output that contains only titles that appeared in both the set-aside output and the latest output. So to get only the tags that the `field Operator` and `compare Operator` tiddlers have in common, you would write a filter expression like this:
* <$link to="tags Operator">`[[field Operator]tags[]] :intersection[[compare Operator]tags[]]`</$link>
The following examples use the [[field Operator]] and [[compare Operator]] tiddlers and their respective tags.
<<.operator-example 1 "[[field Operator]tags[]]">>
<<.operator-example 2 "[[compare Operator]tags[]]">>
<<.operator-example 3 "[[field Operator]tags[]] +[[compare Operator]tags[]]" """The "field Operator" tiddler's tags are lost, so only the "compare Operator" tiddler's tags are returned""">>
<<.operator-example 4 "[[field Operator]tags[]] :intersection[[compare Operator]tags[]]" """Returns the tags that both tiddlers have in common""">>
See [[Intersection Filter Run Prefix (Examples)]]
!! `:reduce` examples
@ -31,4 +18,4 @@ See [[Reduce Filter Run Prefix (Examples)]]
!! `:sort` examples
See [[Sort Filter Run Prefix (Examples)]]
See [[Sort Filter Run Prefix (Examples)]]

View File

@ -0,0 +1,36 @@
created: 20211128212902292
modified: 20211128233320674
tags: [[Filter Syntax]] [[Filter Run Prefix Examples]] [[Intersection Filter Run Prefix]]
title: Intersection Filter Run Prefix (Examples)
type: text/vnd.tiddlywiki
<<.operator-example 1 "A B C D :intersection[enlist[C D E F]]">>
<<.operator-example 2 "A B C D :intersection[enlist[A B C D]]">>
<<.operator-example 3 "A B C D :intersection[enlist[E F G H]]">>
<<.operator-example 4 ":intersection[enlist[A B C D]]" "Using intersection in the first filter run is of little use. The result will always be empty.">>
!! Difference between `+` and `:intersection`
The `+` prefix should be thought of as an "AND" in formal logic, e.g. "give me all titles that satisfy condition A ''and'' condition B". But it's not suitable for all cases; if condition B uses a filter operator that replaces its input, then it will be difficult to use the `+` prefix. For example, if you wanted to find out what tags two tiddlers have in common, you might try to write a filter expression like:
* <$link to="tags Operator">`[[field Operator]tags[]] +[[compare Operator]tags[]]`</$link>
But that won't work, because the second filter run will end up throwing away its input and replacing it with an input consisting of the single title `[[compare Operator]]`. So the result you'd get from that filter expression would be just the tags of the `compare Operator` tiddler.
For cases like this, the `:intersection` prefix is what you need. It takes the filter output so far, //sets it aside//, and starts the next filter run with all tiddler titles as input. Then once the latest filter run has completed, it takes the latest output, compares it to the set-aside output, and produces a new output that contains only titles that appeared in both the set-aside output and the latest output. So to get only the tags that the `field Operator` and `compare Operator` tiddlers have in common, you would write a filter expression like this:
* <$link to="tags Operator">`[[field Operator]tags[]] :intersection[[compare Operator]tags[]]`</$link>
The following examples use the [[field Operator]] and [[compare Operator]] tiddlers and their respective tags.
<<.operator-example 5 "[[field Operator]tags[]]">>
<<.operator-example 6 "[[compare Operator]tags[]]">>
<<.operator-example 7 "[[field Operator]tags[]] +[[compare Operator]tags[]]" """The "field Operator" tiddler's tags are lost, so only the "compare Operator" tiddler's tags are returned""">>
<<.operator-example 8 "[[field Operator]tags[]] :intersection[[compare Operator]tags[]]" """Returns the tags that both tiddlers have in common""">>

View File

@ -0,0 +1,15 @@
created: 20211128212902292
modified: 20211128212904721
tags: [[Filter Syntax]] [[Filter Run Prefix]]
title: Intersection Filter Run Prefix
type: text/vnd.tiddlywiki
<<.from-version "5.1.23">>
|''purpose'' |find the intersection of titles from previous runs with titles in this filter run |
|''input'' |all titles from previous filter runs |
|''output''|the titles that are present in both the result of this filter run and the output from previous runs |
The filter output from previous runs is set aside. The `:intersection` filter run is started with all tiddler titles as input. Once this latest filter run has completed, the latest output is compared to the set-aside output. A new output is produced that contains only titles that appeared in both the set-aside output and the latest output.
[[Examples|Intersection Filter Run Prefix (Examples)]]

View File

@ -474,3 +474,4 @@ Brian Theado, @btheado, 2021-10-10
@eiro10, 2021-11-14
Fred, @tw-FRed, 2021/12/04