# -*- coding: iso-8859-1 -*-
# Gradation.script

# Copyright (C) 2004  Lauri Karttunen
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.

# This script is a solution to the problem posed in the
# Finnish Consonant Gradation exercise.

define V [a | e | i | o | u | y | ä | ö];
define C [b | c | d | f | g | h | j | k | l | m | n | p | q | r | s |
          t | v | w | x | z];

define Coda [ C  [C | .#.] ];

# We state the general gradation rule using temporary auxiliary
# symbols, ^G, ^B, and ^D, for the weak grade of k, p, and t.
# The ultimate realization of ^G, ^B, and ^D is determined by
# the three specific rules WeakK, WeakP, and WeakT.

define WeakGrade k -> "^G", p -> "^B", t -> "^D" || \s _ V Coda;

define WeakK "^G"  -> ' || V a _ a, V e _ e, V i _ i, V o _ o,
                           V u _ u, V y _ y, V ä _ ä, V ö _ ö
                                         # raa'an, tiu'un
                     .o.
              "^G" -> j || r _ e         # kurjen
                     .o.
              "^G" -> v || u|y _ u|y     # puvun
                     .o.
              "^G" -> g || n _           # langan
                     .o.
              "^G" (->) k || h _         # nahkan ~ nahan
                     .o.
              "^G" -> k || t _           # matkan
                     .o.
              "^G" -> 0 || _  ;          # lian, tuen, tikan, etc.

define WeakP  "^B" -> m || m _           # kamman
                     .o.
              "^B" -> 0 || p _           # papin
                     .o.
              "^B" -> v ||   _  ;        # puvun, varvun, etc.

define WeakT  "^D" -> n || n _           # rinnan
                     .o.
              "^D" -> l || l _           # kullan
                     .o.
              "^D" -> r || r _           # parran
                     .o.
              "^D" -> 0 || t _           # katon
                     .o.
              "^D" -> d ||   _  ;        # sadan, vahdin, etc.
 

regex WeakGrade .o. WeakK .o. WeakP .o. WeakT ;

# The three auxiliary symbols have all been replaced in the
# network but they are still present in the sigma alphabet.
# The 'substitute symbol' commands remove them.

substitute symbol 0 for "^G"
substitute symbol 0 for "^B"
substitute symbol 0 for "^D"

define Gradation