// Copyright Neil Ramsden 2004. All rights reserved.

// Suffix checker flowchart definition
// Neil Ramsden
// suffix.js
// 16 Jul 04 -> 27 Sep 04

//---------------------------------------------------------------------------

/* Global variables
*/

//advice constants

var /*const*/ _changeYToI = new Advice('change the <span class="letter-string">&lt;y&gt;</span>' +
              ' to <span class="letter-string">&lt;i&gt;</span> before you add the suffix');
var /*const*/ _doubleLastLetter = new Advice('double the last letter before you add the suffix');
var /*const*/ _justAddSuffix = new Advice('just add the suffix');
var /*const*/ _removeE = new Advice('remove the <span class="letter-string">&lt;e&gt;</span>' +
              ' and replace it with the suffix');
var /*const*/ _removeEchangeYToI = new Advice('remove the <span class="letter-string">&lt;e&gt;</span>' +
              ' AND change the <span class="letter-string">&lt;i&gt;</span>' +
              ' to <span class="letter-string">&lt;y&gt;</span> before you add the suffix');

var /*const*/ _holdingAction = new Advice('to be completed!');

//repeated choice constants

var /*const*/ _vowelPlusConsonant =
                new Choice(
                [
                  { text: 'the base or stem is a monosyllable',
                    action: _doubleLastLetter
                  },
                  { text: 'the last letter of the base or stem is <span class="letter-string">&lt;l&gt;</span>' +
                      ' and you are not writing US English',
                    action: _doubleLastLetter
                  },
                  { text: 'the stress is on the syllable just before the suffix in the finished word',
                    action: _doubleLastLetter
                  },
                  { text: 'the syllable just before the suffix in the finished word isn\'t stressed',
                    action: _justAddSuffix
                  }
                ]);

//flow chart

var /*const*/ flowChart = new Choice(
    [
      { text: 'the suffix begins with a consonant letter',
        action: new Choice(
        [
          /*consonant suffices
          */
          { text: 'the base or stem ends with <span class="letter-string">&lt;y&gt;</span>',
            action: new Choice(
            [
              { text: 'the letter before that <span class="letter-string">&lt;y&gt;</span> is a vowel',
                action: _justAddSuffix
              },
              { text: 'the letter before that <span class="letter-string">&lt;y&gt;</span> is a consonant',
                action: _changeYToI 
              }
            ])
          },
          { text: 'the base or stem doesn\'t end with <span class="letter-string">&lt;y&gt;</span>',
            action: _justAddSuffix
          }
        ])
      },
      { text: 'the suffix begins with a vowel letter (including <span class="letter-string">&lt;y&gt;</span>)',
        action: new Choice(
        [
          /*vowel suffices
          */
          { text: 'the base or stem ends with <span class="letter-string">&lt;w&gt;</span>' +
              ' or <span class="letter-string">&lt;x&gt;</span>',
            action: _justAddSuffix
          },
          { text: 'the base or stem ends with more than one consonant letter',
            action: _justAddSuffix
          },
          { text: 'the base or stem ends with just one consonant letter',
            action: new Choice(
            [
              { text: 'the base or stem ends with a single consonant letter AND there is only one vowel letter immediately before it',
                action: _vowelPlusConsonant
              },
              { text: 'the last four letters of the base or stem consist of the digraph' +
                  ' <span class="letter-string">&lt;qu&gt;</span> followed by a single vowel letter then' +
                  ' a single consonant letter, eg. <span class="letter-string">&lt;equal&gt;</span>' +
                  ' or <span class="letter-string">&lt;quit&gt;</span>',
                action: _vowelPlusConsonant
              },
              { text: 'the base or stem ends with a single consonant letter AND there is more than one vowel letter immediately before it',
                action: _justAddSuffix
              }
            ])
          },
          { text: 'the base or stem ends with a single silent <span class="letter-string">&lt;e&gt;</span>',
            action: new Choice(
            [
              { text: 'the suffix is <span class="letter-string">&lt;&minus;ing&gt;</span>',
                action: new Choice(
                [
                  { text: 'the base or stem ends with <span class="letter-string">&lt;ie&gt;</span>',
                    action: _removeEchangeYToI
                  },
                  { text: 'the base or stem ends with <span class="letter-string">&lt;ye&gt;</span>' +
                      ' or <span class="letter-string">&lt;oe&gt;</span>',
                    action: _justAddSuffix
                  },
                  { text: 'the base or stem doesn\'t end with <span class="letter-string">&lt;ie&gt;</span>,' +
                      ' <span class="letter-string">&lt;ye&gt;</span> or <span class="letter-string">&lt;oe&gt',
                    action: _removeE
                  }
                ])
              },
              { text: 'the suffix isn\'t <span class="letter-string">&lt;&minus;ing&gt;</span>',
                action: _removeE
              }
            ])
          },
          { text: 'the base or stem ends with a vowel letter (including <span class="letter-string">&lt;y&gt;</span>)',
            action: new Choice(
            [
              { text: 'the base or stem ends with <span class="letter-string">&lt;y&gt;</span>',
                action: new Choice(
                [
                  { text: 'there is a vowel letter before the final <span class="letter-string">&lt;y&gt;</span>' +
                      ' in the base or stem',
                    action: _justAddSuffix
                  },
                  { text: 'the suffix begins with <span class="letter-string">&lt;i&gt;</span>',
                    action: _justAddSuffix
                  },
                  { text: 'the suffix doesn\'t begin with <span class="letter-string">&lt;i&gt;</span>',
                    action: _changeYToI
                  }
                ])
              },
              { text: 'the base or stem doesn\'t end with <span class="letter-string">&lt;y&gt;</span>',
                action: _justAddSuffix
              }
            ])
          }
        ])
      }
    ]);
