/// <summary> /// Classifies the given text, invokes the callback with the results. /// </summary> /// <param name="classifierId">The ID of the classifier to use.</param> /// <param name="text">The text to classify.</param> /// <param name="callback">The callback to invoke with the results.</param> /// <returns>Returns false if we failed to submit the request.</returns> public bool Classify(string classifierId, string text, OnClassify callback) { if (string.IsNullOrEmpty(classifierId)) { throw new ArgumentNullException("classifierId"); } if (string.IsNullOrEmpty(text)) { throw new ArgumentNullException("text"); } if (callback == null) { throw new ArgumentNullException("callback"); } string textId = Utility.GetMD5(text); if (!DisableCache) { DataCache cache = null; if (!m_ClassifyCache.TryGetValue(classifierId, out cache)) { cache = new DataCache("NaturalLanguageClassifier_" + classifierId); m_ClassifyCache[classifierId] = cache; } byte[] cached = cache.Find(textId); if (cached != null) { ClassifyResult res = ProcessClassifyResult(cached); if (res != null) { callback(res); return(true); } } } RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, "/v1/classifiers"); if (connector == null) { return(false); } ClassifyReq req = new ClassifyReq(); req.TextId = textId; req.ClassiferId = classifierId; req.Callback = callback; req.OnResponse = OnClassifyResp; req.Function = "/" + classifierId + "/classify"; req.Headers["Content-Type"] = "application/json"; Dictionary <string, object> body = new Dictionary <string, object>(); body["text"] = text; req.Send = Encoding.UTF8.GetBytes(Json.Serialize(body)); return(connector.Send(req)); }