当前位置: 首页>>代码示例>>C#>>正文


C# Rule.AddWatcher方法代码示例

本文整理汇总了C#中Rule.AddWatcher方法的典型用法代码示例。如果您正苦于以下问题:C# Rule.AddWatcher方法的具体用法?C# Rule.AddWatcher怎么用?C# Rule.AddWatcher使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rule的用法示例。


在下文中一共展示了Rule.AddWatcher方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestEngine

        public static void TestEngine()
        {
            TagReplacementWatchers watchers;
              DataLookupTag dlt;
              Rule rule;
              RuleSet rules = new RuleSet();

              rule = new Rule("root");
              rule.Priority = 2; rule.MinPriority = 1;
              rule.Output = new Content();
              rule.Output.Add("Hello. ");
              rule.Output.Add(new Tag("cats"));
              rule.Expression = Expression.Parse("value? 2 >=");
              rules.Add(rule);
              Console.WriteLine(rule.ToString());

              rule = new Rule("cats");
              rule.Output = new Content();
              dlt = new DataLookupTag("value");
              dlt.AddWatcher(new CardinalFilter());
              rule.Output.Add(dlt);
              rule.Output.Add(" (");
              rule.Output.Add(new DataLookupTag("value"));
              rule.Output.Add(") cat");
              dlt = new DataLookupTag("value");
              dlt.AddWatcher(new PluraliseFilter());
              rule.Output.Add(dlt);
              rule.Output.Add(" in a bag, here is the ");
              dlt = new DataLookupTag("value");
              dlt.AddWatcher(new OrdinalFilter());
              rule.Output.Add(dlt);
              rule.Output.Add(" (");
              dlt = new DataLookupTag("value");
              dlt.AddWatcher(new OrdinalSuffixFilter());
              rule.Output.Add(dlt);
              rule.Output.Add(")");
              rule.AddWatcher(new SentenceFilter());
              rules.Add(rule);
              Console.WriteLine(rule.ToString());

              rule = new Rule("root");
              rule.Frequency = 2;
              rule.Output = new Content();
              rule.Output.Add("Hi ");
              watchers = new TagReplacementWatchers();
              watchers.Add(new AsClause("name"));
              rule.Output.Add(new Tag("nickname", watchers));
              rule.Output.Add("! Do you mind if I call you '");
              rule.Output.Add(new DataLookupTag("name"));
              rule.Output.Add("'?");
              rules.Add(rule);
              Console.WriteLine(rule.ToString());

              rule = new Rule("nickname");
              rule.Output = new Content();
              rule.Output.Add("mate");
              rules.Add(rule);
              Console.WriteLine(rule.ToString());

              rule = new Rule("nickname");
              rule.Output = new Content();
              rule.Output.Add("buddy");
              rules.Add(rule);
              Console.WriteLine(rule.ToString());

              rule = new Rule("nickname");
              rule.Output = new Content();
              rule.Output.Add("dude");
              rules.Add(rule);
              Console.WriteLine(rule.ToString());

              rule = new Rule("nickname");
              rule.Output = new Content();
              rule.Output.Add("man");
              rules.Add(rule);
              Console.WriteLine(rule.ToString());

              rule = new Rule("nickname");
              rule.Output = new Content();
              rule.Output.Add("friendo");
              rules.Add(rule);
              Console.WriteLine(rule.ToString());

              Engine engine = new Engine(rules);
              Namespace data = new Namespace();
              data.Set("value", 2);
              string result = engine.Run("root", data);

              Console.WriteLine("........................................................................");
              Console.WriteLine(result);
              Console.WriteLine("........................................................................");
              Console.WriteLine("Final data:");
              Console.WriteLine(data.ToString("  "));
        }
开发者ID:Mofangbao,项目名称:gnoam,代码行数:94,代码来源:Main.cs


注:本文中的Rule.AddWatcher方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。