Assets/Watson/Scripts/Services/AlchemyAPI/AlchemyAPI.cs
/// <summary>
/// Extracts the entities from a source.
/// </summary>
/// <returns><c>true</c>, if entities was extracted, <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="resolveCoreference">If set to <c>true</c> resolve coreference.</param>
/// <param name="disambiguate">If set to <c>true</c> disambiguate.</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="includeQuotations">If set to <c>true</c> include quotations.</param>
/// <param name="analyzeSentiment">If set to <c>true</c> analyze sentiment.</param>
/// <param name="includeSourceText">If set to <c>true</c> include source text.</param>
/// <param name="extractStructuredEntities">If set to <c>true</c> extract structured entities.</param>
/// <param name="customData">Custom data.</param>
Extracts the entities from a source.
Extracts the entities from a source .
public bool ExtractEntities(OnGetEntities callback, string source,
            int maxRetrieve = 50,
            bool resolveCoreference = true,
            bool disambiguate = true,
            bool includeKnowledgeGraph = false,
            bool includeLinkedData = true,
            bool includeQuotations = false,
            bool analyzeSentiment = false,
            bool includeSourceText = false,
            bool extractStructuredEntities = true,
            string customData = default(string))
        {
            if (callback == null)
                throw new ArgumentNullException("callback");
            if (string.IsNullOrEmpty(source))
                throw new WatsonException("Please provide a source for ExtractEntities.");
            if (string.IsNullOrEmpty(mp_ApiKey))
                SetCredentials();
            GetEntitiesRequest req = new GetEntitiesRequest();
            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["coreference"] = Convert.ToInt32(resolveCoreference).ToString();
            req.Parameters["disambiguate"] = Convert.ToInt32(disambiguate).ToString();
            req.Parameters["knowledgeGraph"] = Convert.ToInt32(includeKnowledgeGraph).ToString();
            req.Parameters["linkedData"] = Convert.ToInt32(includeLinkedData).ToString();
            req.Parameters["quotations"] = Convert.ToInt32(includeQuotations).ToString();
            req.Parameters["sentiment"] = Convert.ToInt32(analyzeSentiment).ToString();
            req.Parameters["showSourceText"] = Convert.ToInt32(includeSourceText).ToString();
            req.Parameters["structuredEntities"] = Convert.ToInt32(extractStructuredEntities).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_ENTITY_EXTRACTION_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_ENTITY_EXTRACTION_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 ExtractEntities!");
            }
            else
            {
                service = SERVICE_GET_ENTITY_EXTRACTION_TEXT;
                req.Forms["text"] = new RESTConnector.Form(source);
            }
            RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, service);
            if (connector == null)
                return false;
            req.OnResponse = OnGetEntitiesResponse;
            return connector.Send(req);
        }
public bool ExtractEntities ( OnGetEntities callback , string source , int maxRetrieve = 50 , bool resolveCoreference = true , bool disambiguate = true , bool includeKnowledgeGraph = false , bool includeLinkedData = true , bool includeQuotations = false , bool analyzeSentiment = false , bool includeSourceText = false , bool extractStructuredEntities = true , string customData = default ( string ) ) { if ( callback == null ) throw new ArgumentNullException ( " " ) ; if ( string . IsNullOrEmpty ( source ) ) throw new WatsonException ( " " ) ; if ( string . IsNullOrEmpty ( mp_ApiKey ) ) SetCredentials ( ) ; GetEntitiesRequest req = new GetEntitiesRequest ( ) ; 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 ( resolveCoreference ) . ToString ( ) ; req . Parameters [ " " ] = Convert . ToInt32 ( disambiguate ) . ToString ( ) ; req . Parameters [ " " ] = Convert . ToInt32 ( includeKnowledgeGraph ) . ToString ( ) ; req . Parameters [ " " ] = Convert . ToInt32 ( includeLinkedData ) . ToString ( ) ; req . Parameters [ " " ] = Convert . ToInt32 ( includeQuotations ) . ToString ( ) ; req . Parameters [ " " ] = Convert . ToInt32 ( analyzeSentiment ) . ToString ( ) ; req . Parameters [ " " ] = Convert . ToInt32 ( includeSourceText ) . ToString ( ) ; req . Parameters [ " " ] = Convert . ToInt32 ( extractStructuredEntities ) . 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_ENTITY_EXTRACTION_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_ENTITY_EXTRACTION_HTML ; string htmlData = default ( string ) ; htmlData = File . ReadAllText ( source ) ; req . Forms [ " " ] = new RESTConnector . Form ( htmlData ) ; } else throw new WatsonException ( " " ) ; } else { service = SERVICE_GET_ENTITY_EXTRACTION_TEXT ; req . Forms [ " " ] = new RESTConnector . Form ( source ) ; } RESTConnector connector = RESTConnector . GetConnector ( SERVICE_ID , service ) ; if ( connector == null ) return false ; req . OnResponse = OnGetEntitiesResponse ; return connector . Send ( req ) ; }
Extracts the entities from a source.
Extracts the entities from a source .
None
callback
OnGetEntities
None
source
string
HTML, URL or Text source.
HTML URL or Text source .
maxRetrieve
int
Maximum results retreived.
Maximum results retreived .
resolveCoreference
bool
If set to true
If set to true
disambiguate
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
includeQuotations
bool
If set to true
If set to true
analyzeSentiment
bool
If set to true
If set to true
includeSourceText
bool
If set to true
If set to true
extractStructuredEntities
bool
If set to true
If set to true
customData
string
None