Ejemplo n.º 1
0
        public static void Run(
            [ServiceBusTrigger("newreview", "entity", Connection = "topicConnectionString")] string topicMessage,
            ILogger log,
            [Blob("reviewentity", FileAccess.Read, Connection = "storageConnectionString")] CloudBlobContainer blobContainer
            )
        {
            DecoratedReviewerMessage decoratedMessage = JsonConvert.DeserializeObject <DecoratedReviewerMessage>(topicMessage);
            CloudBlockBlob           blob             = blobContainer.GetBlockBlobReference($"{decoratedMessage.MessageProperties.RequestCorrelationId}.json");
            ITextAnalyticsClient     client           = new TextAnalyticsClient(new ApiKeyServiceClientCredentials())
            {
                Endpoint = Environment.GetEnvironmentVariable("textAnalyticsEndpoint")
            };

            log.LogInformation($"[Request Correlation ID: {decoratedMessage.MessageProperties.RequestCorrelationId}] :: Beginning entity extraction");

            EntitiesBatchResult entityResult = client.EntitiesAsync(false,
                                                                    new MultiLanguageBatchInput(
                                                                        new List <MultiLanguageInput>()
            {
                new MultiLanguageInput("en", "0", decoratedMessage.verbatim)
            })).Result;
            string entitiesJson = JsonConvert.SerializeObject(entityResult.Documents[0].Entities);

            try {
                blob.UploadTextAsync(entitiesJson);
                log.LogInformation($"[Request Correlation ID: {decoratedMessage.MessageProperties.RequestCorrelationId}] :: Completed entity extraction :: TBC items extracted");
            } catch (Exception ex) {
                log.LogInformation($"[Request Correlation ID: {decoratedMessage.MessageProperties.RequestCorrelationId}] :: Incomplete entity extraction :: {ex.Message}");
            }
        }
Ejemplo n.º 2
0
        public static void Run(
            [ServiceBusTrigger("newreview", "sentiment", Connection = "topicConnectionString")] string topicMessage,
            ILogger log,
            [Blob("reviewsentiment", FileAccess.Read, Connection = "storageConnectionString")] CloudBlobContainer blobContainer
            )
        {
            DecoratedReviewerMessage decoratedMessage = JsonConvert.DeserializeObject <DecoratedReviewerMessage>(topicMessage);

            CloudBlockBlob       blob   = blobContainer.GetBlockBlobReference($"{decoratedMessage.MessageProperties.RequestCorrelationId}.json");
            ITextAnalyticsClient client = new TextAnalyticsClient(new ApiKeyServiceClientCredentials())
            {
                Endpoint = Environment.GetEnvironmentVariable("textAnalyticsEndpoint")
            };


            SentimentBatchResult sentimentResult = client.SentimentAsync(false,
                                                                         new MultiLanguageBatchInput(
                                                                             new List <MultiLanguageInput>()
            {
                new MultiLanguageInput("en", "0", decoratedMessage.verbatim)
            }
                                                                             )
                                                                         ).Result;

            try {
                blob.UploadTextAsync(JsonConvert.SerializeObject(sentimentResult.Documents[0].Score));
                log.LogInformation($"[Request Correlation ID: {decoratedMessage.MessageProperties.RequestCorrelationId}] :: Sentiment score submitted :: Score of {sentimentResult.Documents[0].Score:0.000}");
            } catch (Exception ex) {
                log.LogInformation($"[Request Correlation ID: {decoratedMessage.MessageProperties.RequestCorrelationId}] :: Incomplete Sentiment Score Analysis :: {ex.Message}");
            }
        }
Ejemplo n.º 3
0
        public static async void Run(
            [ServiceBusTrigger("newreview", "aggregator", Connection = "topicConnectionString")] string topicMessage,
            ILogger log,
            [Blob("reviewsentiment", FileAccess.Read, Connection = "storageConnectionString")] CloudBlobContainer sentimentBlobContainer,
            [Blob("reviewentity", FileAccess.Read, Connection = "storageConnectionString")] CloudBlobContainer entityBlobContainer,
            [CosmosDB(databaseName: "theatreers", collectionName: "items", ConnectionStringSetting = "cosmosConnectionString")] IAsyncCollector <DecoratedReviewerMessage> reviewOutput
            )
        {
            DecoratedReviewerMessage decoratedMessage = JsonConvert.DeserializeObject <DecoratedReviewerMessage>(topicMessage);
            string         filename      = $"{decoratedMessage.MessageProperties.RequestCorrelationId}.json";
            CloudBlockBlob entityBlob    = entityBlobContainer.GetBlockBlobReference(filename);
            CloudBlockBlob sentimentBlob = sentimentBlobContainer.GetBlockBlobReference(filename);
            int            backoff       = 300;

            IList <EntityRecord> entitiesObject = await findBlob <IList <EntityRecord> >(entityBlob, backoff);

            string sentimentObject = await findBlob <string>(sentimentBlob, backoff);

            decoratedMessage.entities  = entitiesObject;
            decoratedMessage.sentiment = sentimentObject;
            decoratedMessage.doctype   = "review";

            log.LogInformation($"[Request Correlation ID: {decoratedMessage.MessageProperties.RequestCorrelationId}] :: entity downloaded :: {entitiesObject.FirstOrDefault().ToString()}");
            log.LogInformation($"[Request Correlation ID: {decoratedMessage.MessageProperties.RequestCorrelationId}] :: entity downloaded :: {sentimentObject}");

            try
            {
                await reviewOutput.AddAsync(decoratedMessage);

                await entityBlob.DeleteAsync();

                await sentimentBlob.DeleteAsync();

                log.LogInformation($"[Request Correlation ID: {decoratedMessage.MessageProperties.RequestCorrelationId}] :: Upload Complete {reviewOutput.ToString()}");
                log.LogInformation($"[Request Correlation ID: {decoratedMessage.MessageProperties.RequestCorrelationId}] :: Aggregation Clean-up Complete");
            }
            catch (Exception ex)
            {
                log.LogInformation($"[Request Correlation ID: {decoratedMessage.MessageProperties.RequestCorrelationId}] :: Aggregation Clean-up Incomplete :: {ex.Message}");
            }
        }