Esempio n. 1
0
        /// <summary>
        ///  Detect Person entities that may have entries in the Wikipedia and print all associated hyperlinks to the console
        /// </summary>
        /// <returns></returns>
        static async Task Task3()
        {
            var request   = client.GetLinkedEntitiesRequest();
            var documents = request.Body.SetEmptyArray("documents");

            int i = 0;

            foreach (string review in ReadReviewsFromJson().Take(5))
            {
                var document = documents.AddEmptyObjet();
                document["id"]   = (++i).ToString();
                document["text"] = review;
            }

            DynamicResponse response = await request.SendAsync();

            if (response.Status == 200)
            {
                foreach (var document in response.Body["documents"].Items)
                {
                    foreach (var entity in document["entities"].Items)
                    {
                        // NOTE(ellismg): Would be nice if we overloaded == against a string here.
                        if ((string)entity["dataSource"] == "Wikipedia")
                        {
                            Console.WriteLine($"Learn more about {entity["text"]} on ${entity["dataSource"]} ({entity["url"]})");
                        }
                    }
                }
            }
            else
            {
                Console.Error.WriteLine(response.Body["error"]);
            }
        }