Пример #1
0
        // Initialize an SrgsDocument from an Srgs text source.
        internal void Load(XmlReader srgsGrammar)
        {
            // New grammar
            _grammar = new SrgsGrammar
            {
                // For SrgsGrammar, the default is IPA, for xml grammars, it is sapi.
                PhoneticAlphabet = AlphabetType.Sapi
            };

            // create an XMl Parser
            XmlParser srgsParser = new(srgsGrammar, null);

            // Creates SrgsDocument elements
            srgsParser.ElementFactory = new SrgsElementFactory(_grammar);

            // Do it
            srgsParser.Parse();

            // This provides the path the XML was loaded from.
            // {Note potentially this may also be overridden by an xml:base attribute in the XML itself.
            // But for this scenario that doesn't matter since this is used to calculate the correct base path.}
            if (!string.IsNullOrEmpty(srgsGrammar.BaseURI))
            {
                _baseUri = new Uri(srgsGrammar.BaseURI);
            }
        }
Пример #2
0
        // Validate the SRGS element.
        /// <summary>
        /// Validate each element and recurse through all the children srgs
        /// elements if any.
        /// </summary>
        internal void Validate(SrgsGrammar grammar)
        {
            bool fScript = HasCode || _onInit != null || _onParse != null || _onError != null || _onRecognition != null || _baseclass != null;

            grammar._fContainsCode   |= fScript;
            grammar.HasSapiExtension |= fScript;

            if (_dynamic != RuleDynamic.NotSet)
            {
                grammar.HasSapiExtension = true;
            }

            if (OnInit != null && Scope != SrgsRuleScope.Public)
            {
                XmlParser.ThrowSrgsException(SRID.OnInitOnPublicRule, "OnInit", Id);
            }

            if (OnRecognition != null && Scope != SrgsRuleScope.Public)
            {
                XmlParser.ThrowSrgsException(SRID.OnInitOnPublicRule, "OnRecognition", Id);
            }
            // Validate all the children
            foreach (SrgsElement element in _elements)
            {
                element.Validate(grammar);
            }
        }
Пример #3
0
 internal virtual void Validate(SrgsGrammar grammar)
 {
     SrgsElement[] children = Children;
     foreach (SrgsElement srgsElement in children)
     {
         srgsElement.Validate(grammar);
     }
 }
Пример #4
0
 // Validate the SRGS element.
 /// <summary>
 /// Validate each element and recurse through all the children srgs
 /// elements if any.
 /// Any derived class implementing this method must call the base class
 /// in order for the children to be processed.
 /// </summary>
 internal virtual void Validate(SrgsGrammar grammar)
 {
     foreach (SrgsElement element in Children)
     {
         // Child validation
         element.Validate(grammar);
     }
 }
Пример #5
0
        public SrgsDocument(GrammarBuilder builder)
        {
            Helpers.ThrowIfNull(builder, "builder");
            _grammar         = new SrgsGrammar();
            _grammar.Culture = builder.Culture;
            IElementFactory elementFactory = new SrgsElementFactory(_grammar);

            builder.CreateGrammar(elementFactory);
        }
Пример #6
0
 // Validate the SRGS element.
 /// <summary>
 /// Validate each element and recurse through all the children srgs
 /// elements if any.
 /// </summary>
 internal override void Validate(SrgsGrammar grammar)
 {
     if (grammar.TagFormat == SrgsTagFormat.Default)
     {
         grammar.TagFormat |= SrgsTagFormat.W3cV1;
     }
     else if (grammar.TagFormat == SrgsTagFormat.KeyValuePairs)
     {
         XmlParser.ThrowSrgsException(SRID.SapiPropertiesAndSemantics);
     }
 }
Пример #7
0
        internal void Load(XmlReader srgsGrammar)
        {
            _grammar = new SrgsGrammar();
            _grammar.PhoneticAlphabet = AlphabetType.Sapi;
            XmlParser xmlParser = new XmlParser(srgsGrammar, null);

            xmlParser.ElementFactory = new SrgsElementFactory(_grammar);
            xmlParser.Parse();
            if (!string.IsNullOrEmpty(srgsGrammar.BaseURI))
            {
                _baseUri = new Uri(srgsGrammar.BaseURI);
            }
        }
Пример #8
0
        void IElementFactory.AddScript(IGrammar grammar, string sRule, string code)
        {
            SrgsGrammar srgsGrammar = (SrgsGrammar)grammar;
            SrgsRule    srgsRule    = srgsGrammar.Rules[sRule];

            if (srgsRule != null)
            {
                srgsRule.Script += code;
            }
            else
            {
                srgsGrammar.AddScript(sRule, code);
            }
        }
Пример #9
0
        internal override void Validate(SrgsGrammar grammar)
        {
            switch (grammar.TagFormat)
            {
            case SrgsTagFormat.KeyValuePairs:
                break;

            case SrgsTagFormat.Default:
                grammar.TagFormat |= SrgsTagFormat.KeyValuePairs;
                break;

            default:
                XmlParser.ThrowSrgsException(SRID.SapiPropertiesAndSemantics);
                break;
            }
        }
Пример #10
0
        public SrgsDocument(GrammarBuilder builder)
        {
            Helpers.ThrowIfNull(builder, nameof(builder));

            // New grammar
            _grammar = new SrgsGrammar
            {
#pragma warning disable 56504 // The Culture property is the Grammar builder is already checked.
                Culture = builder.Culture
            };
#pragma warning restore 56504

            // Creates SrgsDocument elements
            IElementFactory elementFactory = new SrgsElementFactory(_grammar);

            // Do it
            builder.CreateGrammar(elementFactory);
        }
Пример #11
0
        internal override void Validate(SrgsGrammar grammar)
        {
            if (_pronunciation != null || _display != null)
            {
                grammar.HasPronunciation = true;
            }

            // Validate the pronunciation if any
            if (_pronunciation != null)
            {
                for (int iCurPron = 0, iDeliminator = 0; iCurPron < _pronunciation.Length; iCurPron = iDeliminator + 1)
                {
                    // Find semi-colon delimiter and replace with null
                    iDeliminator = _pronunciation.IndexOf(';', iCurPron);
                    if (iDeliminator == -1)
                    {
                        iDeliminator = _pronunciation.Length;
                    }

                    string subPronunciation = _pronunciation.Substring(iCurPron, iDeliminator - iCurPron);

                    // Convert the pronunciation, will throw if error
                    switch (grammar.PhoneticAlphabet)
                    {
                    case AlphabetType.Sapi:
                        PhonemeConverter.ConvertPronToId(subPronunciation, grammar.Culture.LCID);
                        break;

                    case AlphabetType.Ups:
                        PhonemeConverter.UpsConverter.ConvertPronToId(subPronunciation);
                        break;

                    case AlphabetType.Ipa:
                        PhonemeConverter.ValidateUpsIds(subPronunciation.ToCharArray());
                        break;
                    }
                }
            }

            base.Validate(grammar);
        }
Пример #12
0
        internal override void Validate(SrgsGrammar grammar)
        {
            if (_pronunciation != null || _display != null)
            {
                grammar.HasPronunciation = true;
            }
            if (_pronunciation != null)
            {
                int num  = 0;
                int num2 = 0;
                while (num < _pronunciation.Length)
                {
                    num2 = _pronunciation.IndexOf(';', num);
                    if (num2 == -1)
                    {
                        num2 = _pronunciation.Length;
                    }
                    string text = _pronunciation.Substring(num, num2 - num);
                    switch (grammar.PhoneticAlphabet)
                    {
                    case AlphabetType.Sapi:
                        PhonemeConverter.ConvertPronToId(text, grammar.Culture.LCID);
                        break;

                    case AlphabetType.Ups:
                        PhonemeConverter.UpsConverter.ConvertPronToId(text);
                        break;

                    case AlphabetType.Ipa:
                        PhonemeConverter.ValidateUpsIds(text.ToCharArray());
                        break;
                    }
                    num = num2 + 1;
                }
            }
            base.Validate(grammar);
        }
Пример #13
0
        internal override void Validate(SrgsGrammar grammar)
        {
            bool flag = _params != null || _semanticKey != null;

            grammar._fContainsCode   |= flag;
            grammar.HasSapiExtension |= flag;
            if (_uri != null)
            {
                string text = _uri.ToString();
                if (text[0] == '#')
                {
                    bool flag2 = false;
                    if (text.IndexOf("#grammar:dictation", StringComparison.Ordinal) == 0 || text.IndexOf("#grammar:dictation#spelling", StringComparison.Ordinal) == 0)
                    {
                        flag2 = true;
                    }
                    else
                    {
                        text = text.Substring(1);
                        foreach (SrgsRule rule in grammar.Rules)
                        {
                            if (rule.Id == text)
                            {
                                flag2 = true;
                                break;
                            }
                        }
                    }
                    if (!flag2)
                    {
                        XmlParser.ThrowSrgsException(SRID.UndefRuleRef, text);
                    }
                }
            }
            base.Validate(grammar);
        }
Пример #14
0
 internal SrgsElementFactory(SrgsGrammar grammar)
 {
     _grammar = grammar;
 }
Пример #15
0
        void IElementFactory.AddScript(IGrammar grammar, string script, string filename, int line)
        {
            SrgsGrammar srgsGrammar = (SrgsGrammar)grammar;

            srgsGrammar.AddScript(null, script);
        }
Пример #16
0
 internal override void Validate(SrgsGrammar grammar)
 {
     grammar.HasSapiExtension = true;
     base.Validate(grammar);
 }
Пример #17
0
 public SrgsDocument()
 {
     _grammar = new SrgsGrammar();
 }