# Difference between revisions of "Boolean Operations"

(Rewrite with new constructs; simplified and clarified.) |
|||

Line 1: | Line 1: | ||

− | == | + | ==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. | |

− | |||

− | |||

− | |||

− | + | 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: | ||

− | + | <tt>if(math(test1 | test2), TRUE, FALSE)</tt> | |

+ | |||

+ | <tt>if(math(test1 + test2), TRUE, FALSE)</tt> | ||

+ | |||

+ | <tt>if(test1, TRUE, | ||

+ | if(test2, TRUE, FALSE))</tt> | ||

− | + | 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''. | |

− | |||

− | ''' | ||

− | + | ===AND=== | |

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

− | + | <tt>if(math(test1 & test2), TRUE, FALSE)</tt> | |

− | + | ||

− | + | <tt>if(math(test1 * test2), TRUE, FALSE)</tt> | |

− | + | ||

+ | <tt>if(test1, | ||

+ | if(test2, TRUE, FALSE), | ||

+ | FALSE)</tt> | ||

− | + | 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''. | ||

− | === | + | ===XOR=== |

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

− | |||

− | |||

− | |||

+ | <tt>if(math(test1 - test2), TRUE, FALSE)</tt> | ||

+ | |||

+ | <tt>if(test1, | ||

+ | if(test2, FALSE, TRUE), | ||

+ | if(test2, TRUE, FALSE))</tt> | ||

− | + | 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. |

## Revision as of 21:51, 23 November 2011

## Contents

## Emulating *AND*, *OR* and *XOR*

The 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.

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))

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*.

### 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)

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*.

### 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.