Assets/Watson/Scripts/Services/AlchemyAPI/AlchemyAPI.cs
/// <summary>
/// Extracts the relations from a source.
/// </summary>
/// <returns><c>true</c>, if relations was gotten, <c>false</c> otherwise.</returns>
/// <param name="callback">Callback.</param>
/// <param name="source">HTML, URL or Text source.</param>
/// <param name="maxRetrieve">Max retrieve.</param>
/// <param name="includeKeywords">If set to <c>true</c> include keywords.</param>
/// <param name="includeEntities">If set to <c>true</c> include entities.</param>
/// <param name="requireEntities">If set to <c>true</c> require entities.</param>
/// <param name="resolveCoreferences">If set to <c>true</c> resolve coreferences.</param>
/// <param name="disambiguateEntities">If set to <c>true</c> disambiguate entities.</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="analyzeSentiment">If set to <c>true</c> analyze sentiment.</param>
/// <param name="excludeEntitiesInSentiment">If set to <c>true</c> exclude entities in sentiment.</param>
/// <param name="includeSourceText">If set to <c>true</c> include source text.</param>
/// <param name="customData">Custom data.</param>
Extracts the relations from a source.
Extracts the relations from a source .
public bool GetRelations(OnGetRelations callback, string source,
            int maxRetrieve = 50,
            bool includeKeywords = false,
            bool includeEntities = false,
            bool requireEntities = false,
            bool resolveCoreferences = true,
            bool disambiguateEntities = true,
            bool includeKnowledgeGraph = false,
            bool includeLinkedData = true,
            bool analyzeSentiment = false,
            bool excludeEntitiesInSentiment = false,
            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 GetRelations.");
            if (string.IsNullOrEmpty(mp_ApiKey))
                SetCredentials();
            GetRelationsRequest req = new GetRelationsRequest();
            req.Callback = callback;
            req.Data = string.IsNullOrEmpty(customData) ? source : customData;
            req.Parameters["apikey"] = mp_ApiKey;
            req.Parameters["outputMode"] = "json";
            req.Parameters["maxRetrieve"] = Convert.ToInt32(maxRetrieve).ToString();
            req.Parameters["keywords"] = Convert.ToInt32(includeKeywords).ToString();
            req.Parameters["entities"] = Convert.ToInt32(includeEntities).ToString();
            req.Parameters["requireEntities"] = Convert.ToInt32(requireEntities).ToString();
            req.Parameters["coreference"] = Convert.ToInt32(resolveCoreferences).ToString();
            req.Parameters["disambiguate"] = Convert.ToInt32(disambiguateEntities).ToString();
            req.Parameters["knowledgeGraph"] = Convert.ToInt32(includeKnowledgeGraph).ToString();
            req.Parameters["linkedData"] = Convert.ToInt32(includeLinkedData).ToString();
            req.Parameters["sentiment"] = Convert.ToInt32(analyzeSentiment).ToString();
            req.Parameters["sentimentExcludeEntities"] = Convert.ToInt32(excludeEntitiesInSentiment).ToString();
            req.Parameters["showSourceText"] = Convert.ToInt32(includeSourceText).ToString();
            req.Parameters["keywordExtractMode"] = "strict";
            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_RELATIONS_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_RELATIONS_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 GetRelations!");
            }
            else
            {
                service = SERVICE_GET_RELATIONS_TEXT;
                req.Forms["text"] = new RESTConnector.Form(source);
            }
            RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, service);
            if (connector == null)
                return false;
            req.OnResponse = OnGetRelationsResponse;
            return connector.Send(req);
        }
public bool GetRelations ( OnGetRelations callback , string source , int maxRetrieve = 50 , bool includeKeywords = false , bool includeEntities = false , bool requireEntities = false , bool resolveCoreferences = true , bool disambiguateEntities = true , bool includeKnowledgeGraph = false , bool includeLinkedData = true , bool analyzeSentiment = false , bool excludeEntitiesInSentiment = false , 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 ( ) ; GetRelationsRequest req = new GetRelationsRequest ( ) ; req . Callback = callback ; req . Data = string . IsNullOrEmpty ( customData ) ? source : customData ; req . Parameters [ " " ] = mp_ApiKey ; req . Parameters [ " " ] = " " ; req . Parameters [ " " ] = Convert . ToInt32 ( maxRetrieve ) . ToString ( ) ; req . Parameters [ " " ] = Convert . ToInt32 ( includeKeywords ) . ToString ( ) ; req . Parameters [ " " ] = Convert . ToInt32 ( includeEntities ) . ToString ( ) ; req . Parameters [ " " ] = Convert . ToInt32 ( requireEntities ) . ToString ( ) ; req . Parameters [ " " ] = Convert . ToInt32 ( resolveCoreferences ) . ToString ( ) ; req . Parameters [ " " ] = Convert . ToInt32 ( disambiguateEntities ) . ToString ( ) ; req . Parameters [ " " ] = Convert . ToInt32 ( includeKnowledgeGraph ) . ToString ( ) ; req . Parameters [ " " ] = Convert . ToInt32 ( includeLinkedData ) . ToString ( ) ; req . Parameters [ " " ] = Convert . ToInt32 ( analyzeSentiment ) . ToString ( ) ; req . Parameters [ " " ] = Convert . ToInt32 ( excludeEntitiesInSentiment ) . ToString ( ) ; req . Parameters [ " " ] = Convert . ToInt32 ( includeSourceText ) . ToString ( ) ; req . Parameters [ " " ] = " " ; req . Headers [ " " ] = " " ; req . Forms = new Dictionary < string , RESTConnector . Form > ( ) ; string service ; string normalizedSource = source . Trim ( ) . ToLower ( ) ; if ( normalizedSource . StartsWith ( " " ) || normalizedSource . StartsWith ( " " ) ) { service = SERVICE_GET_RELATIONS_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_RELATIONS_HTML ; string htmlData = default ( string ) ; htmlData = File . ReadAllText ( source ) ; req . Forms [ " " ] = new RESTConnector . Form ( htmlData ) ; } else throw new WatsonException ( " " ) ; } else { service = SERVICE_GET_RELATIONS_TEXT ; req . Forms [ " " ] = new RESTConnector . Form ( source ) ; } RESTConnector connector = RESTConnector . GetConnector ( SERVICE_ID , service ) ; if ( connector == null ) return false ; req . OnResponse = OnGetRelationsResponse ; return connector . Send ( req ) ; }
Extracts the relations from a source.
Extracts the relations from a source .
None
callback
OnGetRelations
None
source
string
HTML, URL or Text source.
HTML URL or Text source .
maxRetrieve
int
None
includeKeywords
bool
If set to true
If set to true
includeEntities
bool
If set to true
If set to true
requireEntities
bool
If set to true
If set to true
resolveCoreferences
bool
If set to true
If set to true
disambiguateEntities
bool
If set to true
If set to true
includeKnowledgeGraph
bool
If set to true
If set to true
includeLinkedData
bool
If set to true
If set to true
analyzeSentiment
bool
If set to true
If set to true
excludeEntitiesInSentiment
bool
If set to true
If set to true
includeSourceText
bool
If set to true
If set to true
customData
string
None