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


C# Lexer.Symbol方法代码示例

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


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

示例1: matchMembers

    /// <summary>
    /// Count the number of words in this list that matches in the phrase
    /// </summary>
    /// <param name="lexer">The words to match</param>
    /// <param name="count">The number of words that match [out]</param>
    /// <returns>Score for the match: 0 if no match</returns>
    internal double matchMembers(Lexer lexer, out int count)
    {
        var cnt = 0  ; // The number of words that match
          var score=0.0; // The score to match

          // for each of the remaining words
          while (!lexer.EOF)
          {
         lexer.Preprocess();
         var word =lexer.Symbol();

         // See if it matches a modifier
         double score1 = matchMembers(word);

         // check for a minimum score
         if (score1 <= 0.0) break;

         // Update the tracking info
         cnt++;
         score += score1;
          }

          // return the results
          count = cnt;
          return score;
    }
开发者ID:randym32,项目名称:InteractiveText-CS,代码行数:32,代码来源:WordList-Match.cs

示例2: findVerbPhrase

   /// <summary>
   /// Finds a verb phrase that matches
   /// </summary>
   /// <param name="lex"></param>
   /// <param name="stateEndVerbPhrase"></param>
   /// <returns></returns>
   WordList findVerbPhrase(Lexer lex)
   {
      // First, make a list of all verb phrases
      var candidates = new List<WordList>();
      foreach (var item in verbs)
      {
         candidates.Add(item.Key);
      }

      // The words of the verb phrase
      var verbWords = new List<string>();
      var prevState = lex.Save();
      LexState stateEndVerbPhrase=prevState;

      // Next, get words from the lexer as long they match a phrase
      lex.Preprocess();
      while (!lex.EOF)
      {
         var word = lex.Symbol();
         lex.Preprocess();
         
         // See if the word matches any candidate
         var newCandidates = new List<WordList>();
         var numVerbWords = verbWords . Count;
         foreach (var candidate in candidates)
         {
            // Skip "shorter" phrases
            if (numVerbWords >= candidate.words.Length)
                continue;
            // Get the word for this far in
            var item = candidate.words[numVerbWords];

            // Is there a match?
            // Check for exact, but caseless match; or a partial
            if (item.Equals(word, StringComparison.CurrentCultureIgnoreCase)
               || ((word. Length < item.Length)
                     && item.Substring(0, word.Length).Equals(word, StringComparison.CurrentCultureIgnoreCase)))
            {
               // keep it
               newCandidates.Add(candidate);
            }
         }
         // Did anyone match?
         if (newCandidates . Count < 1)
            break;
         // Save the word and the matches
         candidates = newCandidates;
         verbWords.Add(word);
         stateEndVerbPhrase = lex.Save();
      }


      // Check to see if any matched
      if (candidates.Count < 1 || verbWords.Count < 1)
      {
         lex.Restore(prevState);
         return null;
      }

      // Jump back tot he end of the verb phrase
      lex.Restore(stateEndVerbPhrase);

      /// The words for the verb phrase
      WordList verbWordList = new WordList(verbWords.ToArray());

      // Rank the matched phrases, finding the best one
      var bestScore = 0.0;
      WordList bestCandidate = null;
      foreach (var candidate in candidates)
      {
         // Assign a score to the candidate.
         var score = candidate.score(verbWordList);
         // Is it a better match?
         if (score > bestScore)
         {
            // Keep it
            bestScore = score;
            bestCandidate=candidate;
         }
      }

      // Return the best matched phrase
      return bestCandidate;
   }
开发者ID:randym32,项目名称:InteractiveText-CS,代码行数:90,代码来源:InStory-verb.cs


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