Exemple #1
0
        /// <summary>
        /// For words or phrases in those reviews that can be categorized as a Person, Location, or Organization, identify whether they are a person, location, or organization.
        /// Print the phrase found in text and its category, e.g.Kurt Russell is a Person.
        /// </summary>
        /// <returns></returns>
        static async Task Task2()
        {
            var request   = client.GetEntitiesRequest();
            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): The cast here is subtle, note that ".ToString()" would do the wrong thing
                        // and wrap the value in quotes (since it returns a stringified JSON document).
                        switch ((string)entity["category"])
                        {
                        case "Person":
                        case "Location":
                        case "Organization":
                            Console.WriteLine($"Entity {entity["text"]} is a {entity["category"]}");
                            break;
                        }
                    }
                }
            }
            else
            {
                Console.Error.WriteLine(response.Body["error"]);
            }
        }
        /// <summary>
        /// For words or phrases in those reviews that can be categorized as a Person, Location, or Organization, identify whether they are a person, location, or organization.
        /// Print the phrase found in text and its category, e.g.Kurt Russell is a Person.
        /// </summary>
        /// <returns></returns>
        static async Task Task2()
        {
            var request   = client.GetEntitiesRequest();
            var documents = request.Body.SetEmptyArray("documents");

            int i = 0;

            foreach (string review in ReadReviewsFromJson().Take(5))
            {
                var document = documents.AddEmptyObject();
                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)
                    {
                        switch (entity["category"].ToString())
                        {
                        case "Person":
                        case "Location":
                        case "Organization":
                            Console.WriteLine($"Entity {entity["text"]} is a {entity["category"]}");
                            break;
                        }
                    }
                }
            }
            else
            {
                Console.Error.WriteLine(response.Body["error"]);
            }
        }