Boolean Operations: Difference between revisions

From wiki.jriver.com
Jump to navigation Jump to search
No edit summary
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{see also|Expression Language}}
==Emulating ''AND'', ''OR'' and ''XOR''==


The [http://wiki.jriver.com/index.php/Media_Center_expression_language Media Center Expression Language] currently does not have AND, OR and XOR connectives. These can be emulated using either the Math() expression or by using nested If() statements.
The [[Expression Language]] does not have AND, OR and XOR [http://en.wikipedia.org/wiki/Logical_connective logical connectives]. However, these can be emulated using either the Math() expression or by using nested If() statements.


In the general forms shown below, ''test1'' and ''test2'' are Boolean expressions such as IsEmpty(...), IsEqual(...) or Regex(...). The TRUE and FALSE Booleans indicate the outcome of the connective test.
In the general forms shown below, ''test1'' and ''test2'' are Boolean expressions such as IsEmpty(...), IsEqual(...) or Regex(...). The TRUE and FALSE Booleans indicate the outcome of the connective test.


===OR===
== OR ==
The OR connective can be emulated using any of the constructs below:
The OR connective can be emulated using any of the constructs below:


Line 14: Line 14:
<tt>if(test1, TRUE,
<tt>if(test1, TRUE,
if(test2, TRUE, FALSE))</tt>
if(test2, TRUE, FALSE))</tt>
<tt>if(isequal(isempty([album gain]):isempty([replay gain]), 1, 7), at least one empty, all not empty)</tt>


Examples
Examples


if(math(isequal([artist], Nat King Cole) | isequal([artist], John Lee Hooker)), Legend, Other)
if(math(isequal([artist], Nat King Cole) | isequal([artist], John Lee Hooker)), Legend, Other)

if(isequal([artist], Nat King Cole), Legend,
if(isequal([artist], Nat King Cole), Legend,
if(isequal([artist], John Lee Hooker), Legend, Other))
if(isequal([artist], John Lee Hooker), Legend, Other))
Line 24: Line 26:
If the artist is either Nat King Cole or John Lee Hooker, output ''Legend'', otherwise output ''Other''.
If the artist is either Nat King Cole or John Lee Hooker, output ''Legend'', otherwise output ''Other''.


if(isequal(isempty([album gain]):isempty([replay gain]), 1, 7), at least one empty, all not empty)
===AND===

If any of album gain or replay gain is empty, output ''at least one empty'', otherwise output ''all not empty''. This works by using the concatenated output of the two isempty() functions, and using the sub-string search mode of isequal() to look for any true (''1'') value.

== AND ==
The AND connective can be emulated using any of the constructs below:
The AND connective can be emulated using any of the constructs below:


Line 51: Line 57:
If both album gain and replay gain are empty, output ''both empty'', otherwise output ''both not empty''. This works by concatenating the output of the two isempty() functions into a single string and comparing it to the desired true/true values as a string ''1:1''. This form can be used in a variety of ways.
If both album gain and replay gain are empty, output ''both empty'', otherwise output ''both not empty''. This works by concatenating the output of the two isempty() functions into a single string and comparing it to the desired true/true values as a string ''1:1''. This form can be used in a variety of ways.


===XOR===
== XOR ==
The XOR connective can be emulated using any of the constructs below:
The XOR connective can be emulated using any of the constructs below:


Line 69: Line 75:


If either artist, but not both, is Michael Jackson or Paul McCartney, output ''Play It'', otherwise output ''Skip It''. The example assumes a custom list field named Artists which has a list of relevant artists.
If either artist, but not both, is Michael Jackson or Paul McCartney, output ''Play It'', otherwise output ''Skip It''. The example assumes a custom list field named Artists which has a list of relevant artists.

[[Category:Expression Language]]

Revision as of 05:58, 24 January 2016

See also: {{#if:Expression Language |[[:Expression Language{{#if:||{{{l1}}}}}]] |Error: Template must be given at least one article name

}}{{#if:|{{#if:|, | and }} [[:{{{2}}}{{#if:||{{{l2}}}}}]] }}{{#if:|{{#if:|, |, and }} [[:{{{3}}}{{#if:||{{{l3}}}}}]] }}{{#if:|{{#if:|, |, and }} [[:{{{4}}}{{#if:||{{{l4}}}}}]] }}{{#if:|{{#if:|, |, and }} [[:{{{5}}}{{#if:||{{{l5}}}}}]] }}{{#if:|{{#if:|, |, and }} [[:{{{6}}}{{#if:||{{{l6}}}}}]] }}{{#if:|{{#if:|, |, and }} [[:{{{7}}}{{#if:||{{{l7}}}}}]] }}{{#if:|{{#if:|, |, and }} [[:{{{8}}}{{#if:||{{{l8}}}}}]] }}{{#if:|{{#if:|, |, and }} [[:{{{9}}}{{#if:||{{{l9}}}}}]] }}{{#if:|{{#if:|, |, and }} [[:{{{10}}}{{#if:||{{{l10}}}}}]] }}{{#if:|{{#if:|, |, and }} [[:{{{11}}}{{#if:||{{{l11}}}}}]] }}{{#if:|{{#if:|, |, and }} [[:{{{12}}}{{#if:||{{{l12}}}}}]] }}{{#if:|{{#if:|, |, and }} [[:{{{13}}}{{#if:||{{{l13}}}}}]] }}{{#if:|{{#if:|, |, and }} [[:{{{14}}}{{#if:||{{{l14}}}}}]] }}{{#if:|, and [[:{{{15}}}{{#if: || }}]] }}{{#if:| —
Error: Too many links specified (maximum is 15)

}}

The Expression Language does not have AND, OR and XOR logical connectives. However, these can be emulated using either the Math() expression or by using nested If() statements.

In the general forms shown below, test1 and test2 are Boolean expressions such as IsEmpty(...), IsEqual(...) or Regex(...). The TRUE and FALSE Booleans indicate the outcome of the connective test.

OR

The OR connective can be emulated using any of the constructs below:

  if(math(test1 | test2), TRUE, FALSE)

  if(math(test1 + test2), TRUE, FALSE)

  if(test1, TRUE,
     if(test2, TRUE, FALSE))

  if(isequal(isempty([album gain]):isempty([replay gain]), 1, 7), at least one empty, all not empty)

Examples

if(math(isequal([artist], Nat King Cole) | isequal([artist], John Lee Hooker)), Legend, Other)

if(isequal([artist], Nat King Cole), Legend,
     if(isequal([artist], John Lee Hooker), Legend, Other))

If the artist is either Nat King Cole or John Lee Hooker, output Legend, otherwise output Other.

if(isequal(isempty([album gain]):isempty([replay gain]), 1, 7), at least one empty, all not empty)

If any of album gain or replay gain is empty, output at least one empty, otherwise output all not empty. This works by using the concatenated output of the two isempty() functions, and using the sub-string search mode of isequal() to look for any true (1) value.

AND

The AND connective can be emulated using any of the constructs below:

  if(math(test1 & test2), TRUE, FALSE)

  if(math(test1 * test2), TRUE, FALSE)

  if(test1,
     if(test2, TRUE, FALSE),
     FALSE)

  if(isequal(test1:test2, 1:1), TRUE, FALSE)

Examples

if(math(isequal([artist], Elton John) & below([Year], 1976)), In Prime, Washed Up)
if(isequal([artist], Elton John),
  if(compare([year], <, 1976), In Prime, Washed Up),
  Unknown)

If the artist is Elton John and the year is prior to 1976, output In Prime, otherwise output Washed Up. If the artist is not Elton John, output Unknown.

 if(isequal(isempty([album gain]):isempty([replay gain]), 1:1), both empty, both not empty)

If both album gain and replay gain are empty, output both empty, otherwise output both not empty. This works by concatenating the output of the two isempty() functions into a single string and comparing it to the desired true/true values as a string 1:1. This form can be used in a variety of ways.

XOR

The XOR connective can be emulated using any of the constructs below:

  if(math(test1 - test2), TRUE, FALSE)

  if(test1,
     if(test2, FALSE, TRUE),
     if(test2, TRUE, FALSE))

Examples

 if(math(isequal([artists], Michael Jackson, 8) - isequal([artists], Paul McCartney, 8)), Play It, Skip It)
 if(regex([artists], /#\bMichael Jackson\b#/),
    if(regex([artists], /#\bPaul McCartney\b#/),  Skip It, Play It),
    if(regex([artists], /#\bPaul McCartney\b#/),  Play It, Skip It))

If either artist, but not both, is Michael Jackson or Paul McCartney, output Play It, otherwise output Skip It. The example assumes a custom list field named Artists which has a list of relevant artists.