TXTML

The markup language for Subversive (Mobile) Storytelling

conditions : if-input


DESCRIPTION

<if-input> tests the against either a pattern, a user variable, or a supplied value. If relation is supplied, <if-input> will compare the values as numbers according to the relation (except with pattern, on which relation has no effect); otherwise they are tested for equivalency. If more than one of pattern, var, or value are present, <if> will evaluate to true if any condition matches.

If <if-input> is evaluated outside of an <input> handler, it will return false.


PARAMETERS

pattern (optional) - list of pattern tokens
var (optional) - user variable
value (optional) - supplied string
relation (optional, =|>|<|>=|<=) - value relationship


PATTERN - NATURAL LANGUAGE PROCESSING

<if-input>'s pattern parameter invokes a library of rudimental natural language processing functions. pattern takes a list of tokens, separated by commas, such as pattern="token1,token2". For each token specified, <if-input> will search the user's input for a matching token. Prior to the comparison, several preprocessing steps are taken on the input:

  • lowercased
  • emoticons converted to words (eg, ':-)' converted to 'happy')
  • possessives eliminated
  • punctuation removed or substituted by words (eg, '+' converted to 'and')
  • natural language numbers converted to numeric values (eg, 'forty' converted to '40)
  • negated values converted to an antonym, if available (eg, 'not good' converted to 'bad')

Additionally, a token does not have to match exactly, but within a given tolerance, as described by the Levenshtein algorithm. In this case, the tolerance is one-third the length of the token.

No punctuation maye be used with pattern; however, there are three signifiers for special meaning:

  • ! used in front of a token will cause <if-input> to return true only if the token is not found
  • * used in front of a token will compare the input to not only the token but a list of its synonyms (eg, pattern="*yes" matches against "yeah", "ok", "absolutely", etc). Synonyms are defined in the language dictionaries.
  • ? used as a token will match any phrase that is in the form of a question (eg, pattern="?")


Finally, tokens may be compound, consisting of two or more words separated by the + symbol. With compound tokens, all of the composite terms must match somewhere in the input. ?, *, and ! may be used freely within compounds.

Please see extending for more information on langauge lists.


EXAMPLES

<state name="yanks">
     <enter>
          <txt>
               Are you a Yankees fan?
          </txt>
     </enter>
     <input>
          <if-input pattern="*yes">
               <send state="yes" />
               <else>
                    <send state="no" />
               </else>
          </if-input>
     </input>
</state>


...
     <input>
          <if-input pattern="rock+roll">
               "rock and roll" matches. "rock" or "roll" does not.
          <if-input>
          <if-input pattern="rock,roll">
               "rock and roll" matches. so does "rock", and also "roll".
          </if-input>
     </input>
...

introduction
installation
authoring txtml
definition
event handlers
flow control
conditions
variables
content
math
other
feeds
requestors
formats
admin interface
extending