コード例 #1
0
        /**
         * Set the enabled state of the listed rule.
         *
         * @param ruleName
         *            the name of the rule.
         * @param enabled
         *            the new enabled state.
         */
        public void SetEnabled(String ruleName, bool enabled)
        {
            JSGFRuleState state = Rules.Get(ruleName);

            if (state._isEnabled != enabled)
            {
                state._isEnabled = enabled;
            }
        }
コード例 #2
0
        public bool IsEnabled(String ruleName)
        {
            JSGFRuleState state = Rules.Get(ruleName);

            if (state != null)
            {
                return(state._isEnabled);
            }
            return(false);
        }
コード例 #3
0
        /**
         * Test whether the specified rule is public.
         *
         * @param ruleName
         *            the name of the rule.
         */
        public bool IsRulePublic(String ruleName)
        {
            JSGFRuleState state = Rules.Get(ruleName);

            if (state == null)
            {
                return(false);
            }
            return(state.IsPublic);
        }
コード例 #4
0
        /**
         * Return the data structure for the named rule.
         *
         * @param ruleName
         *            the name of the rule.
         */
        public JSGFRule GetRule(String ruleName)
        {
            JSGFRuleState state = Rules.Get(ruleName);

            if (state == null)
            {
                return(null);
            }
            return(state.rule);
        }
コード例 #5
0
        /**
         * Gets the Rule with the given name after it has been stripped, or throws
         * an Exception if it is unknown.
         */
        private JSGFRule GetKnownRule(String ruleName)
        {
            JSGFRuleState state = Rules.Get(ruleName);

            if (state == null)
            {
                throw new ArgumentException("Unknown Rule: " + ruleName);
            }
            return(state.rule);
        }
コード例 #6
0
        /**
         * add a sample sentence to the list of sample sentences that go with the
         * specified rule
         */
        public void AddSampleSentence(String ruleName, String sample)
        {
            JSGFRuleState state = Rules.Get(ruleName);

            if (state == null)
            {
                return;
            }
            state.Samples.Add(sample);
        }
コード例 #7
0
        /**
         * Returns a string containing the specification for this grammar.
         *
         * @return specification for this grammar.
         */

        public override String ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("#JSGF V1.0;").Append(_lineSeparator);
            sb.Append(_lineSeparator);
            sb.Append(FormatComment(_grammarDocComment));
            sb.Append(_lineSeparator);
            sb.Append("grammar ").Append(_name).Append(';').Append(_lineSeparator);
            sb.Append(_lineSeparator);
            // Set of comment keys (The import such comment belongs to).
            var docComments = _importDocComments.keySet();

            for (int i = 0; i < Imports.Count; i++)
            {
                String curImport = '<' + Imports[i].GetRuleName() + '>';
                if (docComments.Contains(curImport))
                {
                    sb.Append(FormatComment(_importDocComments.get(curImport)));
                    sb.Append(_lineSeparator);
                    sb.Append("import ").Append(curImport + ';').Append(_lineSeparator);
                    sb.Append(_lineSeparator);
                }
            }
            docComments = _ruleDocComments.keySet();
            foreach (var entry in Rules)
            {
                var rule = entry.Key;
                if ((docComments.Count > 0) && docComments.Contains(rule))
                {
                    sb.Append(FormatComment(_ruleDocComments.get(rule))).Append(_lineSeparator);
                }
                JSGFRuleState state = entry.Value;
                if (state.IsPublic)
                {
                    sb.Append("public ");
                }
                sb.Append('<').Append(rule).Append("> = ").Append(state.rule).Append(';').Append(_lineSeparator);
                sb.Append(_lineSeparator);
            }
            return(sb.ToString());
        }
コード例 #8
0
        public void SetRuleChanged(String ruleName, bool changed)
        {
            JSGFRuleState state = Rules.Get(ruleName);

            state.IsChanged = changed;
        }
コード例 #9
0
        public bool IsRuleChanged(String ruleName)
        {
            JSGFRuleState state = Rules.Get(ruleName);

            return(state.IsChanged);
        }
コード例 #10
0
        /**
         * Set a rule in the grammar either by creating a new rule or updating an
         * existing rule.
         *
         * @param ruleName
         *            the name of the rule.
         * @param rule
         *            the definition of the rule.
         * @param isPublic
         *            whether this rule is public or not.
         */
        public void SetRule(String ruleName, JSGFRule rule, bool isPublic)
        {
            JSGFRuleState state = new JSGFRuleState(rule, true, isPublic);

            Rules.Put(ruleName, state);
        }