Example #1
0
        public DiphoneRule(string[] symbol1, string[] symbol2, DiphoneRuleAction action, char negator)
        {
            NegSymbol1 = Array.IndexOf <string>(symbol1, "ALL") > -1;
            NegSymbol2 = Array.IndexOf <string>(symbol2, "ALL") > -1;
            foreach (string s in symbol1)
            {
                if (!(NegSymbol1 ^ (s[0] == negator)))
                {
                    if (s[0] == negator)
                    {
                        Symbol1.Add(s.Substring(1));
                    }
                    else
                    {
                        Symbol1.Add(s);
                    }
                }
            }

            foreach (string s in symbol2)
            {
                if (!(NegSymbol2 ^ (s[0] == negator)))
                {
                    if (s[0] == negator)
                    {
                        Symbol2.Add(s.Substring(1));
                    }
                    else
                    {
                        Symbol2.Add(s);
                    }
                }
            }
            _RuleAction = action;
        }
Example #2
0
        void AddElement(MBROLAElement e)
        {
            MidQueue.Add(e);
            Log("Add {0}", e.Symbol);
            MBROLAElement temp;

            while (MidQueue.Count > QueueSize)
            {
                temp = MidQueue[0];
                MidQueue.Remove(temp);
                Emit(temp);
                Log("Emit1 {0}", temp.Symbol);
            }

            for (int i = MidQueue.Count - 2; i >= 0; i--)
            {
                int               j = i + 1;
                MBROLAElement     e1 = MidQueue[i], e2 = MidQueue[j];
                DiphoneRuleAction action = ((MbrolaVoiceNew)(Voice.BackendVoice)).MatchRules(e1, e2);
                if (action.Action == DiphoneAction.None)
                {
                    continue;
                }
                string op;
                switch (action.Op)
                {
                case DiphoneOp.Symbol1:
                    op = e1.Symbol;
                    break;

                case DiphoneOp.Symbol2:
                    op = e2.Symbol;
                    break;

                case DiphoneOp.Value:
                default:
                    op = action.Value;
                    break;
                }
                switch (action.Action)
                {
                case DiphoneAction.Merge:
                    MidQueue.Remove(e1);
                    MidQueue.Remove(e2);
                    temp = MBROLAElement.CreateUnify(e1, e2, op);
                    MidQueue.Insert(i, temp);
                    Log("{0}-{1} => {2}", e1.Symbol, e2.Symbol, temp.Symbol);
                    break;

                case DiphoneAction.Delete:
                    switch (action.Op)
                    {
                    case DiphoneOp.Symbol1:
                        MidQueue.Remove(e1);
                        Log("{0}-{1} => (del)-{1}", e1.Symbol, e2.Symbol);
                        break;

                    case DiphoneOp.Symbol2:
                        MidQueue.Remove(e2);
                        Log("{0}-{1} => {0}-(del)", e1.Symbol, e2.Symbol);
                        break;
                    }
                    break;

                case DiphoneAction.Insert:
                    temp = MBROLAElement.CreateBuffer(e1, e2, op);
                    MidQueue.Insert(j, temp);
                    Log("{0}-{1} => {0}-{2}-{1}", e1.Symbol, e2.Symbol, temp.Symbol);
                    break;
                }
            }

            /*
             * if (curElement != null)
             * {
             *  MBROLAElement mbre = null;
             *  if (e != null)
             *      mbre = voice.Unify(curElement, e);
             *  if (mbre != null)
             *  {
             *      string pair = String.Format("/{0}{1}/", curElement.Symbol, e.Symbol);
             *      if (mbre.Symbol == "")
             *      {
             *          curElement = e;
             *          e = null;
             *          Log("{1} -> /{0}/", curElement.Symbol, pair);
             *      }
             *      else
             *      {
             *          curElement = mbre;
             *          e = null;
             *          Log("{1} -> /{0}/", curElement.Symbol, pair);
             *      }
             *  }
             *  else
             *  {
             *      Emit(curElement);
             *      curElement = e;
             *  }
             * }
             * else
             *  curElement = e;*/
        }