comparison Expressions

Thecomparisonexpression implements a simple conditional choice for expression sequences. It has the following general form:

 ... ... ... ... 

Notice that unlike other expressions, the arguments are identified by name rather than by position. The names are not optional, and the order of the arguments does not matter. All arguments/attributes are optional. Theexprattribute defaults to the string ‘=’, but all other attributes and arguments default to the empty string ““.

The meaning of thecomparisonexpression is to perform a simple conditional choice. The arguments/attributes ‘lhs’ and ‘rhs’ are abbreviations for ‘left-hand side’ and ‘right-hand side’. These two expressions are evaluated and compared. The comparison type is determined by the ‘expr’ attribute. If theexprattribute is ‘=’ and the comparison is true (that is, if the left hand side is equal to the right hand side), then thesuccessargument is evaluated and returned, otherwise thefailureargument is evaluated and returned. If the expr attribute is ‘!=’, for ‘not equal’, then the sense of the comparison is reversed; i.e. if the comparison is true, thenfailureis evaluated, otherwisesuccessis evaluated.

Note:This is not aflow-of-controlconditional expression, but rather simply chooses between expression arguments to evaluate.

The example below demonstrates a case in which news articles are tagged with their source language, ‘fr’ for ‘French’ and ‘en’ for English. Suppose that we want to extract all the author’s names, one per feature. But since the french word for ‘name’ is ‘nom’ (and ‘histoire’ for ‘story’), we want to selectively extract the author’s name based on the stories source language. We do this by assigning an attribute to a feature, and setting that attribute’s value as a comparison expression that chooses based on the ‘lang’ attribute.

Example

stories.xml

   Mark  ...    Jean-Sebastian  ...   

stories.xmp

        <!-- Here we check if the ‘lang’ attribute is equal to the string ‘Name’ and if it is, we extract the Name element. Otherwise, we extract the Nom element -->            
========================================== Features Constructed |INFORM|+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |INFORM|Feature Type: `entry' |INFORM|Attribute(string): `author' has value `Mark' |INFORM|Attribute(string): `xml_type' has value `xml_no_geom' |INFORM|Geometry Type: Unknown (0) |INFORM|============================================================= |INFORM|+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |INFORM|Feature Type: `entry' |INFORM|Attribute(string): `author' has value `Jean-Sebastian' |INFORM|Attribute(string): `xml_type' has value `xml_no_geom' |INFORM|Geometry Type: Unknown (0) |INFORM|=============================================================