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


C# Tokenizer.Parse方法代码示例

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


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

示例1: MatchPatterns

        public IList<TokenResult<WhoisRecord>> MatchPatterns(WhoisRecord record)
        {
            var results = new List<TokenResult<WhoisRecord>>();

            var patterns = GetEmbeddedPatterns();

            foreach (var pattern in patterns)
            {
                var tokenizer = new Tokenizer();

                var clone = record.Clone() as WhoisRecord;

                var result = tokenizer.Parse(clone, pattern, record.Text);

                results.Add(result);
            }

            return results.OrderBy(r => r.Replacements.Count).ToList();
        }
开发者ID:bbqchickenrobot,项目名称:whois,代码行数:19,代码来源:PatternExtractorVisitor.cs

示例2: IsARedirectRecord

        /// <summary>
        /// Determines whether a WHOIS record is a redirect record to another WHOIS server.
        /// </summary>
        /// <param name="record">The record.</param>
        /// <param name="redirect">The redirect.</param>
        /// <returns></returns>
        public bool IsARedirectRecord(WhoisRecord record, out WhoisRedirect redirect)
        {
            var isARedirectRecord = false;

            redirect = null;

            if (record.Text.Contains("many different competing registrars"))
            {
                var reader = new EmbeddedPatternReader();
                var pattern = reader.Read(GetType().Assembly, "Whois.Patterns.Redirects.Iana.txt");

                var tokenizer = new Tokenizer();

                var text = record.Text;

                var tokenResult = tokenizer.Parse<WhoisRedirect>(pattern, text);

                redirect = tokenResult.Value;

                isARedirectRecord = true;
            }

            return isARedirectRecord;
        }
开发者ID:bbqchickenrobot,项目名称:whois,代码行数:30,代码来源:RedirectVisitor.cs

示例3: TestMapAndReduce

        public void TestMapAndReduce()
        {
            string xml = @"
            <MapReduce>
                <Map>
                    <MapRule Type = 'MapRuleOnT1IfTrue' />
                </Map>
             <Reduce>
                    <ReduceRule Type = 'ReduceRuleOnT1' />
                    <ReduceRule Type = 'AssignRuleOnT1' />
                </Reduce>
            </MapReduce>";
            XDocument _xDoc = _xDoc = XDocument.Parse(xml);
            XElement source = _xDoc.Element("MapReduce");
            IMatcher rule = new TerminalRuleMatcher(new Pattern("Rule", TokenType.RULE));
            IMatcher mapRule = new TerminalRuleMatcher(new Pattern("MapRule", TokenType.MAPRULE));
            IMatcher reduceRule = new TerminalRuleMatcher(new Pattern("ReduceRule", TokenType.REDUCERULE));
            IMatcher map = new ProductionMatcher(new Pattern("Map", TokenType.MAP));
            IMatcher reduce = new ProductionMatcher(new Pattern("Reduce", TokenType.REDUCE));
            IMatcher mapReduce = new ProductionMatcher(new Pattern("MapReduce", TokenType.MAPREDUCE));

            List<Token> results = new List<Token>();
            var t = new Tokenizer(source, results, rule, mapRule, reduceRule, map, reduce, mapReduce);
            t.Parse();
            Assert.AreEqual(TokenType.MAPREDUCE, results[0].TokenType);
            Assert.AreEqual(TokenType.MAP, results[1].TokenType);
            Assert.AreEqual(TokenType.MAPRULE, results[2].TokenType);
            Assert.AreEqual(TokenType.EOF, results[3].TokenType);
            Assert.AreEqual(TokenType.REDUCE, results[4].TokenType);
            Assert.AreEqual(TokenType.REDUCERULE, results[5].TokenType);
            Assert.AreEqual(TokenType.REDUCERULE, results[6].TokenType);
            Assert.AreEqual(TokenType.EOF, results[7].TokenType);
            Assert.AreEqual(TokenType.EOF, results[8].TokenType);
        }
开发者ID:barbarossia,项目名称:ConsoleApplication2,代码行数:34,代码来源:UnitTest1.cs

示例4: TestRule

        public void TestRule()
        {
            string xml = @"
             <Rule Type = 'IninValueOnT2' />";
            XDocument _xDoc = _xDoc = XDocument.Parse(xml);
            XElement source = _xDoc.Element("Rule");
            IMatcher rule = new TerminalRuleMatcher(new Pattern("Rule", TokenType.RULE));
            List<Token> results = new List<Token>();
            var t = new Tokenizer(source, results, rule);
            t.Parse();
            Assert.IsTrue(rule.IsMatch(t));

            Assert.AreEqual(TokenType.RULE, results[0].TokenType);
        }
开发者ID:barbarossia,项目名称:ConsoleApplication2,代码行数:14,代码来源:UnitTest1.cs

示例5: TestReduce

 public void TestReduce()
 {
     string xml = @"
             <Reduce>
     <ReduceRule Type = 'ReduceRuleOnT1' />
     <ReduceRule Type = 'AssignRuleOnT1' />
     </Reduce>";
     XDocument _xDoc = _xDoc = XDocument.Parse(xml);
     XElement source = _xDoc.Element("Reduce");
     IMatcher reduceRule = new TerminalRuleMatcher(new Pattern("ReduceRule", TokenType.REDUCERULE));
     IMatcher reduce = new ProductionMatcher(new Pattern("Reduce", TokenType.REDUCE));
     List<Token> results = new List<Token>();
     var t = new Tokenizer(source, results, reduceRule, reduce);
     t.Parse();
     Assert.AreEqual(TokenType.REDUCE, results[0].TokenType);
     Assert.AreEqual(TokenType.REDUCERULE, results[1].TokenType);
     Assert.AreEqual(TokenType.REDUCERULE, results[2].TokenType);
     Assert.AreEqual(TokenType.EOF, results[3].TokenType);
 }
开发者ID:barbarossia,项目名称:ConsoleApplication2,代码行数:19,代码来源:UnitTest1.cs

示例6: TestMapRulesTwoRules

 public void TestMapRulesTwoRules()
 {
     string xml = @"
         <Map>
             <Rule Type = 'IninValueOnT2' />
             <Rule Type = 'IninValueOnT2Add' />
         </Map>";
     XDocument _xDoc = _xDoc = XDocument.Parse(xml); XElement source = _xDoc.Element("Map");
     IMatcher rule = new TerminalRuleMatcher(new Pattern("Rule", TokenType.RULE));
     IMatcher map = new ProductionMatcher(new Pattern("Map", TokenType.MAP));
     List<Token> results = new List<Token>();
     var t = new Tokenizer(source, results, rule, map);
     t.Parse();
     Assert.AreEqual(TokenType.MAP, results[0].TokenType);
     Assert.AreEqual(TokenType.RULE, results[1].TokenType);
     Assert.AreEqual(TokenType.RULE, results[2].TokenType);
     Assert.AreEqual(TokenType.EOF, results[3].TokenType);
 }
开发者ID:barbarossia,项目名称:ConsoleApplication2,代码行数:18,代码来源:UnitTest1.cs

示例7: Lookup

        /// <summary>
        /// Lookups the WHOIS server for the specified domain.
        /// </summary>
        /// <param name="domain">The domain.</param>
        /// <returns></returns>
        public IWhoisServer Lookup(string domain)
        {
            var tld = GetTld(domain);

            var text = GetWhoisServerResponse(tld);

            var tokenizer = new Tokenizer();
            tokenizer.Options.ThrowExceptionOnMissingProperty = true;

            var record = tokenizer.Parse<WhoisServerRecord>(Pattern, text);

            record.Value.RawResponse = text;

            return record.Value;
        }
开发者ID:bbqchickenrobot,项目名称:whois,代码行数:20,代码来源:IanaServerLookup.cs


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