public static async Task <TweetProcessingData> ProcessTweet(
            [OrchestrationTrigger] IDurableOrchestrationContext context,
            ILogger log)
        {
            TweetProcessingData tpd = context.GetInput <TweetProcessingData>();

            if (!context.IsReplaying)
            {
                log.LogInformation("P_ProcessTweet call A_GetBusinessLogicScore");
            }

            // The following function is not async, so it could be called directly rather than through the activity model.
            PublishLabel tmpLabelBL = PublishLabel.NotAssigned;

            (tpd.Score, tmpLabelBL, tpd.TextWithoutTagsHighlighted) = await
                                                                      context.CallActivityAsync <Tuple <double, PublishLabel, string> >("A_GetBusinessLogicScore", tpd.TextWithoutTags);

            tpd.LabelBL = (int)tmpLabelBL;

            if (tpd.LabelBL != (int)PublishLabel.Negative)
            {
                log.LogInformation("Minimum BL score exceeded, query ML filter.");

                var mlResult = await context.CallActivityAsync <MlResult>("A_GetMlScore", tpd.TextWithoutTags);

                tpd.ScoreML   = mlResult.Score;
                tpd.LabelML   = (int)mlResult.Label;
                tpd.VersionML = mlResult.MlVersion;

                if (!(tpd.VersionML is null))
                {
                    log.LogInformation(
                        $"ML-inference OK, label: {tpd.LabelML}, "
                        + $"score: {tpd.ScoreML.ToString("F", CultureInfo.InvariantCulture)}, "
                        + $"version: {tpd.VersionML}");
                }
                else
                {
                    // Did not get a reply from the ML function, therefore
                    // we fall back and continue according to the traditional
                    // logic's result; indicated by tpd.VersionML is null.
                    log.LogInformation("ML inference failed or did not reply, rely on conventional logic.");
                }
            }
Exemple #2
0
        public static Tuple <double, PublishLabel, string> GetBusinessLogicScore([ActivityTrigger] string textWithoutTags, ILogger log)
        {
            log.LogInformation("A_GetBusinessLogicScore: Start.");
            string highlightedText;
            double score = TweetAnalysis.ScoreTweet(textWithoutTags,
                                                    out highlightedText);
            double minScoreBL = TweetAnalysis.GetScoreFromEnv("AZTWITTERSAR_MINSCORE", log, 0.01f);

            PublishLabel label = PublishLabel.Negative;

            if (score > minScoreBL)
            {
                label = PublishLabel.Positive;
            }

            log.LogInformation("A_GetBusinessLogicScore: Done.");

            return(new Tuple <double, PublishLabel, string>(score, label, highlightedText));
        }