Assets/Watson/Scripts/Services/AlchemyAPI/AlchemyAPI.cs
/// <summary>
/// Extracts text from a source.
/// </summary>
/// <returns><c>true</c>, if text was gotten, <c>false</c> otherwise.</returns>
/// <param name="callback">Callback.</param>
/// <param name="source">HTML or URL source.</param>
/// <param name="extractLinks">If set to <c>true</c> extract links.</param>
/// <param name="useMetadata">If set to <c>true</c> use metadata.</param>
/// <param name="customData">Custom data.</param>
Extracts text from a source.
Extracts text from a source .
public bool GetText(OnGetText callback, string source, bool extractLinks = false, bool useMetadata = true, string customData = default(string))
        {
            if (callback == null)
                throw new ArgumentNullException("callback");
            if (string.IsNullOrEmpty(source))
                throw new WatsonException("Please provide a source for GetText.");
            if (string.IsNullOrEmpty(mp_ApiKey))
                SetCredentials();
            GetTextRequest req = new GetTextRequest();
            req.Callback = callback;
            req.Data = string.IsNullOrEmpty(customData) ? source : customData;
            req.Parameters["apikey"] = mp_ApiKey;
            req.Parameters["outputMode"] = "json";
            req.Parameters["extractLinks"] = Convert.ToInt32(extractLinks).ToString();
            req.Parameters["useMetadata"] = Convert.ToInt32(useMetadata).ToString();
            req.Headers["Content-Type"] = "application/x-www-form-urlencoded";
            req.Forms = new Dictionary<string, RESTConnector.Form>();
            string service = "";
            string normalizedSource = source.Trim().ToLower();
            if (normalizedSource.StartsWith("http://") || normalizedSource.StartsWith("https://"))
            {
                service = SERVICE_GET_TEXT_URL;
                req.Forms["url"] = new RESTConnector.Form(source);
            }
            else if (source.StartsWith(Application.dataPath) && !normalizedSource.StartsWith("http://") && !normalizedSource.StartsWith("https://"))
            {
                if (Path.GetExtension(normalizedSource).EndsWith(".html"))
                {
                    service = SERVICE_GET_TEXT_HTML;
                    string htmlData = default(string);
                    htmlData = File.ReadAllText(source);
                    req.Forms["html"] = new RESTConnector.Form(htmlData);
                }
                else
                    throw new WatsonException("An HTML source is needed for GetText!");
            }
            else
            {
                Log.Error("Alchemy Language", "Either a URL or a html page source is required for GetText!");
                return false;
            }
            RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, service);
            if (connector == null)
                return false;
            req.OnResponse = OnGetTextResponse;
            return connector.Send(req);
        }
public bool GetText ( OnGetText callback , string source , bool extractLinks = false , bool useMetadata = true , string customData = default ( string ) ) { if ( callback == null ) throw new ArgumentNullException ( " " ) ; if ( string . IsNullOrEmpty ( source ) ) throw new WatsonException ( " " ) ; if ( string . IsNullOrEmpty ( mp_ApiKey ) ) SetCredentials ( ) ; GetTextRequest req = new GetTextRequest ( ) ; req . Callback = callback ; req . Data = string . IsNullOrEmpty ( customData ) ? source : customData ; req . Parameters [ " " ] = mp_ApiKey ; req . Parameters [ " " ] = " " ; req . Parameters [ " " ] = Convert . ToInt32 ( extractLinks ) . ToString ( ) ; req . Parameters [ " " ] = Convert . ToInt32 ( useMetadata ) . ToString ( ) ; req . Headers [ " " ] = " " ; req . Forms = new Dictionary < string , RESTConnector . Form > ( ) ; string service = " " ; string normalizedSource = source . Trim ( ) . ToLower ( ) ; if ( normalizedSource . StartsWith ( " " ) || normalizedSource . StartsWith ( " " ) ) { service = SERVICE_GET_TEXT_URL ; req . Forms [ " " ] = new RESTConnector . Form ( source ) ; } else if ( source . StartsWith ( Application . dataPath ) && ! normalizedSource . StartsWith ( " " ) && ! normalizedSource . StartsWith ( " " ) ) { if ( Path . GetExtension ( normalizedSource ) . EndsWith ( " " ) ) { service = SERVICE_GET_TEXT_HTML ; string htmlData = default ( string ) ; htmlData = File . ReadAllText ( source ) ; req . Forms [ " " ] = new RESTConnector . Form ( htmlData ) ; } else throw new WatsonException ( " " ) ; } else { Log . Error ( " " , " " ) ; return false ; } RESTConnector connector = RESTConnector . GetConnector ( SERVICE_ID , service ) ; if ( connector == null ) return false ; req . OnResponse = OnGetTextResponse ; return connector . Send ( req ) ; }
Extracts text from a source.
Extracts text from a source .
None
callback
OnGetText
None
source
string
HTML or URL source.
HTML or URL source .
extractLinks
bool
If set to true
If set to true
useMetadata
bool
If set to true
If set to true
customData
string
None