Conditional Functions: Difference between revisions
No edit summary |
(Added And()) |
||
Line 2: | Line 2: | ||
The functions in this section test one or more arguments to produce either a true or false outcome, and execute specific actions depending upon that result. |
The functions in this section test one or more arguments to produce either a true or false outcome, and execute specific actions depending upon that result. |
||
The expression language does not directly support AND, OR, and XOR operations. |
|||
However, these can be easily emulated using any of several techniques. See: [[Boolean Operations]]. |
|||
The NOT operator {{monospace|<b>!</b>}} (exclamation point) may be used in a conditional to invert the sense of the conditional test. Inverting the sense of a test can make reading expressions easier, or support better [[#IfElse|IfElse()]] sequences. |
The NOT operator {{monospace|<b>!</b>}} (exclamation point) may be used in a conditional to invert the sense of the conditional test. Inverting the sense of a test can make reading expressions easier, or support better [[#IfElse|IfElse()]] sequences. |
||
=== <span id="And">And(…)</span> === |
|||
: Tests a given set of values and returns 1 if ''all'' of them are true. |
|||
{{function description box |
|||
| name=And |
|||
| arguments=value1, value2, value''N'' … |
|||
| description= |
|||
The [[#And|And()]] function tests <i>value1</i>, <i>value2</i> through to value''N'', and returns ''1'' if all of them are true, otherwise, returns zero. |
|||
Two or more arguments may be used, separated by commas. Each ''Value'' will typically be a [[Test and Comparison Functions|Test and Comparison Function]] or a [[Conditional Functions|Conditional Function]], avoiding long nested sequences. |
|||
| examples= |
|||
'''{{monospace|And(IsEqual([artist],Mark W,8),IsEqual([People],Vada))}}''' |
|||
: Returns ''1'' for all files that satisfy both IsEqual expressions, and ''zero'' for all other files. |
|||
'''{{monospace|<nowiki>[=And(IsEqual([artist],Mark W,8),IsEqual([People],Vada))]=1</nowiki>}}''' |
|||
: Here, the first example has been formatted for use in the search bar. It will return all files (''think photos'') that show Vada on her own, taken by Mark W |
|||
'''{{monospace|If(And(IsEqual([artist],Mark W,8),IsEqual([People],Vada),IsEqual([Places],France)),Photos of Vada in France Taken by Mark W,Other Photos)}}''' |
|||
: If, and only if, artist contains "Mark W", people is only Vada, and places is only France, the result will be {{monospace|Photos of Vada in France Taken by Mark W}} for all other photos, the result will be {{monospace|Other Photos}} |
|||
}} |
|||
=== <span id="FirstNotEmpty">FirstNotEmpty(…)</span> === |
=== <span id="FirstNotEmpty">FirstNotEmpty(…)</span> === |
||
Line 18: | Line 35: | ||
Two or more arguments may be used, and the first non-empty argument is returned. With two arguments, is is functionally equivalent to the sequence such as {{monospace|if(!isempty(<i>value1</i>), <i>value1</i>, <i>value2</i>)}}. With more than two arguments, [[#FirstNotEmpty|FirstNotEmpty()]] avoids long nested [[#If|If()]] sequences that simply test for emptiness. |
Two or more arguments may be used, and the first non-empty argument is returned. With two arguments, is is functionally equivalent to the sequence such as {{monospace|if(!isempty(<i>value1</i>), <i>value1</i>, <i>value2</i>)}}. With more than two arguments, [[#FirstNotEmpty|FirstNotEmpty()]] avoids long nested [[#If|If()]] sequences that simply test for emptiness. |
||
| examples= |
| examples= |
||
'''{{monospace|firstnotempty([media sub type], |
'''{{monospace|firstnotempty([media sub type], Music Video)}}''' |
||
: Returns the value in {{monospace|media sub type}} if it is not empty, otherwise returns {{monospace|Music Video}}. |
: Returns the value in {{monospace|media sub type}} if it is not empty, otherwise returns {{monospace|Music Video}}. |
||
'''{{monospace|firstnotempty([series], [name], Tag your Videos!)}}''' |
'''{{monospace|firstnotempty([series], [name], Tag your Videos!)}}''' |
Revision as of 13:22, 21 June 2020
- See also: Expression Language and Function Index
The functions in this section test one or more arguments to produce either a true or false outcome, and execute specific actions depending upon that result.
The NOT operator ! (exclamation point) may be used in a conditional to invert the sense of the conditional test. Inverting the sense of a test can make reading expressions easier, or support better IfElse() sequences.
And(…)
- Tests a given set of values and returns 1 if all of them are true.
Description | And(value1, value2, valueN …)
The And() function tests value1, value2 through to valueN, and returns 1 if all of them are true, otherwise, returns zero. Two or more arguments may be used, separated by commas. Each Value will typically be a Test and Comparison Function or a Conditional Function, avoiding long nested sequences. |
---|---|
Examples | And(IsEqual([artist],Mark W,8),IsEqual([People],Vada))
[=And(IsEqual([artist],Mark W,8),IsEqual([People],Vada))]=1
If(And(IsEqual([artist],Mark W,8),IsEqual([People],Vada),IsEqual([Places],France)),Photos of Vada in France Taken by Mark W,Other Photos)
|
FirstNotEmpty(…)
- Returns the first non-empty argument.
Description | FirstNotEmpty(value1, value2, …)
The FirstNotEmpty() function acts as a conditional by returning the first argument from value1, value2, ... that is not empty. Two or more arguments may be used, and the first non-empty argument is returned. With two arguments, is is functionally equivalent to the sequence such as if(!isempty(value1), value1, value2). With more than two arguments, FirstNotEmpty() avoids long nested If() sequences that simply test for emptiness. |
---|---|
Examples | firstnotempty([media sub type], Music Video)
firstnotempty([series], [name], Tag your Videos!)
|
If(…)
- Conditional if-else evaluator.
Description | If(test expression, true expression, false expression)
The If() function is used to evaluate a test expression, and will output the result of the true expression or false expression, depending upon the evaluation result. The test expression is expected to return a 0 (false value) or a non-zero (true value). Nesting is allowed. If the test expression is preceded by the NOT operator (!, an exclamation point), the sense of the test is inverted. Non-zero values are inverted to 0, and 0 is inverted to 1. |
---|---|
Examples | if(isequal([artist], bob dylan, 1), Genius, Mediocre)
if(isequal([artist], bob dylan, 1), Genius, if(isequal([album], Joshua Tree, 8), Great Album, Mediocre))
if(!isempty([comment]), regex([comment], /#^(\\S+\\s+\\S+\\s+\\S+)#/, 1), *No Comment)
|
IfCase(…)
- Functions as a switch or select case statement.
Description | IfCase(primary, mode, secondary1, action1, secondary2, action2, secondary3, action3..... etc …)
The IfCase() function performs an IsEqual() operation against one primary operand and several secondary operands, with an action for each secondary operand. IfCase() honors the same modes as IsEqual. IfCase() acts on the first match, and if no match occurs returns null. This saves a lot of typing of nested Compare() or IsEqual() statements when matching things against a possible list of values, and makes for much more readable expressions. When constructing the tests, always test from longest/largest to shortest/smallest. Available mode values:
| ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Examples | IfCase([bitrate], 2, 320, High, 256, Medium, 128, Standard, 64, Low)
IfCase(Length([Name]), 5, 50, Wow this is super long, 30, This is a very long track name, 20, This is not so long)
IfCase([Oscar Awarded to], 8, Matt, Matt wins on his first acting job, meryl, The Oscar went to Meryl again, carrey, Unbelievable result)
|
IfElse(…)
- Conditional if-elseif evaluator.
Description | IfElse(test1, action1, test2, action2, test3, action3, …)
The IfElse() conditional provides a convenient mechanism for shortening and more clearly expressing nested conditionals into an alternating sequence of tests and actions. One or more test/action pairs may be specified. For example, consider a nested sequence of If() tests such as the following pseudo-code:
The IfElse() statement may be used to more cleanly express the flow of expression by removing the superfluous internal If() statements, converting the clumsy expression:
into the more elegant:
If any of the test expressions test1, etc. are preceded by the NOT operator (!, an exclamation point), the sense of that test is inverted. Non-zero values are inverted to 0, and 0 is inverted to 1. |
---|---|
Examples | ifelse(isequal([media type], Audio), Le Tunes, isequal([media type], Video), Flix)
ifelse(isequal([artist], Bob Dylan), Genius, isequal([album], Joshua Tree, 8), Great Album, 1, Mediocre)
|