internal void InitSpecialRuleRef(Backend backend, ParseElementCollection parent) { Rule rule = null; switch (_type) { case SpecialRuleRefType.Null: parent.AddArc(backend.EpsilonTransition(1f)); break; case SpecialRuleRefType.Void: rule = backend.FindRule("VOID"); if (rule == null) { rule = backend.CreateRule("VOID", (SPCFGRULEATTRIBUTES)0); ((IElement)rule).PostParse((IElement)parent); } parent.AddArc(backend.RuleTransition(rule, parent._rule, 1f)); break; case SpecialRuleRefType.Garbage: { OneOf oneOf = new OneOf(parent._rule, backend); oneOf.AddArc(backend.RuleTransition(CfgGrammar.SPRULETRANS_WILDCARD, parent._rule, 0.5f)); oneOf.AddArc(backend.EpsilonTransition(0.5f)); ((IElement)oneOf).PostParse((IElement)parent); break; } } }
public Subset(ParseElementCollection parent, Backend backend, string text, MatchMode mode) : base(parent._rule) { char[] achTrimChars = Helpers._achTrimChars; foreach (char c in achTrimChars) { if (c != ' ' && text.IndexOf(c) >= 0) { text = text.Replace(c, ' '); } } parent.AddArc(backend.SubsetTransition(text, mode)); }
internal RuleRef(ParseElementCollection parent, Backend backend, Uri uri, List <Rule> undefRules, string semanticKey, string initParameters) : base(parent._rule) { string originalString = uri.OriginalString; Rule rule = null; int num = originalString.IndexOf('#'); if (num == 0) { rule = GetRuleRef(backend, originalString.Substring(1), undefRules); } else { StringBuilder stringBuilder = new StringBuilder("URL:"); if (!string.IsNullOrEmpty(initParameters)) { stringBuilder.Append((num > 0) ? originalString.Substring(0, num) : originalString); stringBuilder.Append('>'); stringBuilder.Append(initParameters); if (num > 0) { stringBuilder.Append(originalString.Substring(num)); } } else { stringBuilder.Append(originalString); } string text = stringBuilder.ToString(); rule = backend.FindRule(text); if (rule == null) { rule = backend.CreateRule(text, SPCFGRULEATTRIBUTES.SPRAF_Import); } } Arc arc = backend.RuleTransition(rule, _rule, 1f); if (!string.IsNullOrEmpty(semanticKey)) { backend.AddPropertyTag(arc, arc, new CfgGrammar.CfgProperty { _pszName = "SemanticKey", _comValue = semanticKey, _comType = VarEnum.VT_EMPTY }); } parent.AddArc(arc); }
private void ParseToken(ParseElementCollection parent, string sToken, string pronunciation, string display, float reqConfidence) { int requiredConfidence = parent?._confidence ?? 0; sToken = Backend.NormalizeTokenWhiteSpace(sToken); if (string.IsNullOrEmpty(sToken)) { return; } parent._confidence = 0; if (reqConfidence < 0f || reqConfidence.Equals(0.5f)) { parent._confidence = 0; } else if ((double)reqConfidence < 0.5) { parent._confidence = -1; } else { parent._confidence = 1; } if (pronunciation != null || display != null) { string text = EscapeToken(sToken); string text2 = (display == null) ? text : EscapeToken(display); if (pronunciation != null) { OneOf oneOf = (pronunciation.IndexOf(';') >= 0) ? new OneOf(parent._rule, _backend) : null; int num = 0; int num2 = 0; while (num < pronunciation.Length) { num2 = pronunciation.IndexOf(';', num); if (num2 == -1) { num2 = pronunciation.Length; } string text3 = pronunciation.Substring(num, num2 - num); string text4 = null; switch (_backend.Alphabet) { case AlphabetType.Sapi: text4 = PhonemeConverter.ConvertPronToId(text3, _grammar.Backend.LangId); break; case AlphabetType.Ipa: text4 = text3; PhonemeConverter.ValidateUpsIds(text4); break; case AlphabetType.Ups: text4 = PhonemeConverter.UpsConverter.ConvertPronToId(text3); break; } string sWord = string.Format(CultureInfo.InvariantCulture, "/{0}/{1}/{2};", new object[3] { text2, text, text4 }); if (oneOf != null) { oneOf.AddArc(_backend.WordTransition(sWord, 1f, requiredConfidence)); } else { parent.AddArc(_backend.WordTransition(sWord, 1f, requiredConfidence)); } num = num2 + 1; } ((IElement)oneOf)?.PostParse((IElement)parent); } else { string sWord2 = string.Format(CultureInfo.InvariantCulture, "/{0}/{1};", new object[2] { text2, text }); parent.AddArc(_backend.WordTransition(sWord2, 1f, requiredConfidence)); } } else { parent.AddArc(_backend.WordTransition(sToken, 1f, requiredConfidence)); } }