public NLPActionResult UserEnteredANumericExpression(TokenExpression tne)
 {
     if (tne.Type == typeof(double))
     {
         var result = tne.ToDouble();
         if (result != null)
         {
             st.Say("Hmmm .. a puzzle, I love puzzles...");
         }
         Thread.Sleep(250);
         st.Say("...");
         Thread.Sleep(250);
         st.Say("I think the answer is " + result);
     }
     else if (tne is TemporalSet)
     {
         throw new System.Exception("Check the relative priority of this rule and UserEnteredATemporalExpression");
     }
     else
     {
         st.Say($"You entered an expression {tne.Describe(true)}");
         st.Say($"You can serialize a token expression {tne.Serialize()}");
         st.Say($"You can get the unbound variables on it {tne.UnboundVariables}");
         st.Say($"To create variables, add a TokenExpressionVariableAcces to the Lexeme store using the words you want.");
         st.Say($"You can evaluate a TokenExpression in the context of an environment containing variable values.");
         st.Say($"You can also convert it to a LINQ Expression or to a SQL Query.");
     }
     return(NLPActionResult.None);
 }
コード例 #2
0
 [Priority(500, probability: 0.5)]  // lower probability
 public NLPActionResult UserEnteredANumericExpression(TokenExpression tne)
 {
     if (tne.Type == typeof(double))
     {
         var result = tne.ToDouble();
         if (result != null)
         {
             st.Say("Hmmm .. a puzzle, I love puzzles...");
         }
         Thread.Sleep(250);
         st.Say("...");
         Thread.Sleep(250);
         st.Say("I think the answer is " + result);
     }
     else if (tne is TemporalSet)
     {
         // The other rule should have fired first because it has a higher probability
         return(NLPActionResult.Continue);
     }
     else
     {
         st.Say($"You entered an expression {tne.Describe(true)}");
         st.Say($"You can serialize a token expression {tne.Serialize()}");
         st.Say($"You can get the unbound variables on it {string.Join(",", tne.UnboundVariables)}");
         st.Say($"To create variables, add a TokenExpressionVariableAcces to the Lexeme store using the words you want.");
         st.Say($"You can evaluate a TokenExpression in the context of an environment containing variable values.");
         st.Say($"You can also convert it to a LINQ Expression or to a SQL Query.");
     }
     return(NLPActionResult.None);
 }