Assets/Watson/Scripts/Services/DeepQA/DeepQA.cs
/// <summary>
/// Ask a question using the given pipeline.
/// </summary>
/// <param name="question">The text of the question.</param>
/// <param name="callback">The callback to receive the response.</param>
/// <returns>Returns true if the request was submitted.</returns>
Ask a question using the given pipeline.
Ask a question using the given pipeline .
public bool AskQuestion(string question, OnQuestion callback, int evidenceItems = 1, bool useCache = true)
        {
            if (string.IsNullOrEmpty(question))
                throw new ArgumentNullException("question");
            if (callback == null)
                throw new ArgumentNullException("callback");
            string questionId = Utility.GetMD5(question);
            if (!DisableCache && useCache)
            {
                Question q = FindQuestion(questionId);
                if (q != null)
                {
                    callback(q);
                    return true;
                }
            }
            RESTConnector connector = RESTConnector.GetConnector(m_ServiceId, ASK_QUESTION);
            if (connector == null)
                return false;
            Dictionary<string, object> questionJson = new Dictionary<string, object>();
            questionJson["question"] = new Dictionary<string, object>() {
                { "questionText", question },
                { "formattedAnswer", "true" },
                { "evidenceRequest", new Dictionary<string,object>() {
                    { "items", evidenceItems },
                    { "profile", "NO" }
                } }
            };
            string json = MiniJSON.Json.Serialize(questionJson);
            AskQuestionReq req = new AskQuestionReq();
            req.QuestionID = questionId;
            req.Callback = callback;
            req.Headers["Content-Type"] = "application/json";
            req.Headers["X-Synctimeout"] = "-1";
            req.Send = Encoding.UTF8.GetBytes(json);
            req.OnResponse = OnAskQuestionResp;
            return connector.Send(req);
        }
public bool AskQuestion ( string question , OnQuestion callback , int evidenceItems = 1 , bool useCache = true ) { if ( string . IsNullOrEmpty ( question ) ) throw new ArgumentNullException ( " " ) ; if ( callback == null ) throw new ArgumentNullException ( " " ) ; string questionId = Utility . GetMD5 ( question ) ; if ( ! DisableCache && useCache ) { Question q = FindQuestion ( questionId ) ; if ( q != null ) { callback ( q ) ; return true ; } } RESTConnector connector = RESTConnector . GetConnector ( m_ServiceId , ASK_QUESTION ) ; if ( connector == null ) return false ; Dictionary < string , object > questionJson = new Dictionary < string , object > ( ) ; questionJson [ " " ] = new Dictionary < string , object > ( ) { { " " , question } , { " " , " " } , { " " , new Dictionary < string , object > ( ) { { " " , evidenceItems } , { " " , " " } } } } ; string json = MiniJSON . Json . Serialize ( questionJson ) ; AskQuestionReq req = new AskQuestionReq ( ) ; req . QuestionID = questionId ; req . Callback = callback ; req . Headers [ " " ] = " " ; req . Headers [ " " ] = " " ; req . Send = Encoding . UTF8 . GetBytes ( json ) ; req . OnResponse = OnAskQuestionResp ; return connector . Send ( req ) ; }
Ask a question using the given pipeline.
Ask a question using the given pipeline .
Returns true if the request was submitted.
Returns true if the request was submitted .
question
string
The text of the question.
The text of the question .
callback
OnQuestion
The callback to receive the response.
The callback to receive the response .
evidenceItems
int
useCache
bool