Assets/Watson/Scripts/Services/AlchemyAPI/AlchemyAPI.cs
/// <summary>
/// Extracts concepts from a source.
/// </summary>
/// <returns><c>true</c>, if ranked concepts was gotten, <c>false</c> otherwise.</returns>
/// <param name="callback">Callback.</param>
/// <param name="source">HTML, URL or Text Source.</param>
/// <param name="maxRetrieve">Maximum results retreived.</param>
/// <param name="includeKnowledgeGraph">If set to <c>true</c> include knowledge graph.</param>
/// <param name="includeLinkedData">If set to <c>true</c> include linked data.</param>
/// <param name="includeSourceText">If set to <c>true</c> include source text.</param>
/// <param name="customData">Custom data.</param>
Extracts concepts from a source.
Extracts concepts from a source .
public bool GetRankedConcepts(OnGetRankedConcepts callback, string source,
            int maxRetrieve = 8,
            bool includeKnowledgeGraph = false,
            bool includeLinkedData = true,
            bool includeSourceText = false,
            string customData = default(string))
        {
            if (callback == null)
                throw new ArgumentNullException("callback");
            if (string.IsNullOrEmpty(source))
                throw new WatsonException("Please provide a source for GetAuthors.");
            if (string.IsNullOrEmpty(mp_ApiKey))
                SetCredentials();
            GetRankedConceptsRequest req = new GetRankedConceptsRequest();
            req.Callback = callback;
            req.Data = string.IsNullOrEmpty(customData) ? source : customData;
            req.Parameters["apikey"] = mp_ApiKey;
            req.Parameters["outputMode"] = "json";
            req.Parameters["maxRetrieve"] = maxRetrieve;
            req.Parameters["knowledgeGraph"] = Convert.ToInt32(includeKnowledgeGraph).ToString();
            req.Parameters["linkedData"] = Convert.ToInt32(includeLinkedData).ToString();
            req.Parameters["showSourceText"] = Convert.ToInt32(includeSourceText).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_RANKED_CONCEPTS_URL;
                req.Forms["url"] = new RESTConnector.Form(source);
            }
            else if (!normalizedSource.StartsWith("http://") && !normalizedSource.StartsWith("https://") && source.StartsWith(Application.dataPath))
            {
                if (Path.GetExtension(normalizedSource).EndsWith(".html"))
                {
                    service = SERVICE_GET_RANKED_CONCEPTS_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 GetRankedConcepts");
            }
            else
            {
                service = SERVICE_GET_RANKED_CONCEPTS_TEXT;
                req.Forms["text"] = new RESTConnector.Form(source);
            }
            RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, service);
            if (connector == null)
                return false;
            req.OnResponse = OnGetRankedConceptsResponse;
            return connector.Send(req);
        }
public bool GetRankedConcepts ( OnGetRankedConcepts callback , string source , int maxRetrieve = 8 , bool includeKnowledgeGraph = false , bool includeLinkedData = true , bool includeSourceText = false , string customData = default ( string ) ) { if ( callback == null ) throw new ArgumentNullException ( " " ) ; if ( string . IsNullOrEmpty ( source ) ) throw new WatsonException ( " " ) ; if ( string . IsNullOrEmpty ( mp_ApiKey ) ) SetCredentials ( ) ; GetRankedConceptsRequest req = new GetRankedConceptsRequest ( ) ; req . Callback = callback ; req . Data = string . IsNullOrEmpty ( customData ) ? source : customData ; req . Parameters [ " " ] = mp_ApiKey ; req . Parameters [ " " ] = " " ; req . Parameters [ " " ] = maxRetrieve ; req . Parameters [ " " ] = Convert . ToInt32 ( includeKnowledgeGraph ) . ToString ( ) ; req . Parameters [ " " ] = Convert . ToInt32 ( includeLinkedData ) . ToString ( ) ; req . Parameters [ " " ] = Convert . ToInt32 ( includeSourceText ) . 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_RANKED_CONCEPTS_URL ; req . Forms [ " " ] = new RESTConnector . Form ( source ) ; } else if ( ! normalizedSource . StartsWith ( " " ) && ! normalizedSource . StartsWith ( " " ) && source . StartsWith ( Application . dataPath ) ) { if ( Path . GetExtension ( normalizedSource ) . EndsWith ( " " ) ) { service = SERVICE_GET_RANKED_CONCEPTS_HTML ; string htmlData = default ( string ) ; htmlData = File . ReadAllText ( source ) ; req . Forms [ " " ] = new RESTConnector . Form ( htmlData ) ; } else throw new WatsonException ( " " ) ; } else { service = SERVICE_GET_RANKED_CONCEPTS_TEXT ; req . Forms [ " " ] = new RESTConnector . Form ( source ) ; } RESTConnector connector = RESTConnector . GetConnector ( SERVICE_ID , service ) ; if ( connector == null ) return false ; req . OnResponse = OnGetRankedConceptsResponse ; return connector . Send ( req ) ; }
Extracts concepts from a source.
Extracts concepts from a source .
None
callback
OnGetRankedConcepts
None
source
string
HTML, URL or Text Source.
HTML URL or Text Source .
maxRetrieve
int
Maximum results retreived.
Maximum results retreived .
includeKnowledgeGraph
bool
If set to true
If set to true
includeLinkedData
bool
If set to true
If set to true
includeSourceText
bool
If set to true
If set to true
customData
string
None