Skip to content

Commit

Permalink
Text analytics + ARM changes, cleanup (#858)
Browse files Browse the repository at this point in the history
* text analytics + arm changes, cleanup

* remove bom
  • Loading branch information
Henry van der Vegte authored Nov 10, 2020
1 parent b425737 commit 995d20d
Show file tree
Hide file tree
Showing 9 changed files with 391 additions and 233 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Connector
{
using System;
using Connector.Enums;

public static class CostEstimation
{
Expand All @@ -20,18 +21,18 @@ public static double GetCostEstimation(
TimeSpan timeSpan,
int numberOfChannels,
bool isCustomModel,
bool sentimentAnalysisAdded,
bool entityRedactionAdded)
SentimentAnalysisSetting sentimentSetting,
EntityRedactionSetting entityRedactionSetting)
{
double costPerHour = isCustomModel ? STTCustomModelCostPerHour : STTCostPerHour;
var price = timeSpan.TotalHours * costPerHour;

if (sentimentAnalysisAdded)
if (sentimentSetting != SentimentAnalysisSetting.None)
{
price += timeSpan.TotalHours * TextAnalyticsCostPerHour;
}

if (entityRedactionAdded)
if (entityRedactionSetting != EntityRedactionSetting.None)
{
price += timeSpan.TotalHours * TextAnalyticsCostPerHour;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,29 +107,23 @@ private async Task StoreCombinedRecognizedPhrasesAsync(Guid transcriptionId, int

var combinedPhrases = speechTranscript.CombinedRecognizedPhrases.Where(t => t.Channel == channel).FirstOrDefault();

var query = "INSERT INTO dbo.CombinedRecognizedPhrases (ID, TranscriptionID, Channel, Lexical, Itn, MaskedItn, Display)" +
" VALUES (@id, @transcriptionID, @channel, @lexical, @itn, @maskedItn, @display)";
var query = "INSERT INTO dbo.CombinedRecognizedPhrases (ID, TranscriptionID, Channel, Lexical, Itn, MaskedItn, Display, SentimentPositive, SentimentNeutral, SentimentNegative)" +
" VALUES (@id, @transcriptionID, @channel, @lexical, @itn, @maskedItn, @display, @sentimentPositive, @sentimentNeutral, @sentimentNegative)";

using (var command = new SqlCommand(query, Connection))
{
command.Parameters.AddWithValue("@id", combinedRecognizedPhraseID);
command.Parameters.AddWithValue("@transcriptionID", transcriptionId);
command.Parameters.AddWithValue("@channel", channel);

if (combinedPhrases != null)
{
command.Parameters.AddWithValue("@lexical", combinedPhrases.Lexical);
command.Parameters.AddWithValue("@itn", combinedPhrases.ITN);
command.Parameters.AddWithValue("@maskedItn", combinedPhrases.MaskedITN);
command.Parameters.AddWithValue("@display", combinedPhrases.Display);
}
else
{
command.Parameters.AddWithValue("@lexical", string.Empty);
command.Parameters.AddWithValue("@itn", string.Empty);
command.Parameters.AddWithValue("@maskedItn", string.Empty);
command.Parameters.AddWithValue("@display", string.Empty);
}
command.Parameters.AddWithValue("@lexical", combinedPhrases.Lexical ?? string.Empty);
command.Parameters.AddWithValue("@itn", combinedPhrases.ITN ?? string.Empty);
command.Parameters.AddWithValue("@maskedItn", combinedPhrases.MaskedITN ?? string.Empty);
command.Parameters.AddWithValue("@display", combinedPhrases.Display ?? string.Empty);

command.Parameters.AddWithValue("@sentimentPositive", combinedPhrases?.Sentiment?.Positive ?? 0f);
command.Parameters.AddWithValue("@sentimentNeutral", combinedPhrases?.Sentiment?.Neutral ?? 0f);
command.Parameters.AddWithValue("@sentimentNegative", combinedPhrases?.Sentiment?.Negative ?? 0f);

var result = await command.ExecuteNonQueryAsync().ConfigureAwait(false);

Expand Down Expand Up @@ -194,18 +188,10 @@ private async Task StoreNBestAsync(Guid recognizedPhraseID, NBest nBest)
command.Parameters.AddWithValue("@itn", nBest.ITN);
command.Parameters.AddWithValue("@maskedItn", nBest.MaskedITN);
command.Parameters.AddWithValue("@display", nBest.Display);
if (nBest.Sentiment != null)
{
command.Parameters.AddWithValue("@sentimentNegative", nBest.Sentiment.Negative);
command.Parameters.AddWithValue("@sentimentNeutral", nBest.Sentiment.Neutral);
command.Parameters.AddWithValue("@sentimentPositive", nBest.Sentiment.Positive);
}
else
{
command.Parameters.AddWithValue("@sentimentNegative", 0f);
command.Parameters.AddWithValue("@sentimentNeutral", 0f);
command.Parameters.AddWithValue("@sentimentPositive", 0f);
}

command.Parameters.AddWithValue("@sentimentNegative", nBest?.Sentiment?.Negative ?? 0f);
command.Parameters.AddWithValue("@sentimentNeutral", nBest?.Sentiment?.Neutral ?? 0f);
command.Parameters.AddWithValue("@sentimentPositive", nBest?.Sentiment?.Positive ?? 0f);

var result = await command.ExecuteNonQueryAsync().ConfigureAwait(false);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// <copyright file="EntityRedactionSetting.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
// </copyright>

namespace Connector.Enums
{
public enum EntityRedactionSetting
{
None,
UtteranceLevel
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// <copyright file="SentimentAnalysisSetting.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
// </copyright>

namespace Connector.Enums
{
public enum SentimentAnalysisSetting
{
None,
UtteranceLevel,
AudioLevel
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ namespace Connector

public class CombinedRecognizedPhrase
{
public CombinedRecognizedPhrase(int channel, string lexical, string itn, string maskedItn, string display)
public CombinedRecognizedPhrase(int channel, string lexical, string itn, string maskedItn, string display, Sentiment sentiment)
{
Channel = channel;
Lexical = lexical;
ITN = itn;
MaskedITN = maskedItn;
Display = display;
Sentiment = sentiment;
}

[JsonProperty("channel")]
Expand All @@ -32,5 +33,8 @@ public CombinedRecognizedPhrase(int channel, string lexical, string itn, string

[JsonProperty("display")]
public string Display { get; set; }

[JsonProperty("sentiment")]
public Sentiment Sentiment { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
namespace FetchTranscriptionFunction
{
using System;
using Connector.Enums;
using Connector.Extensions;

public static class FetchTranscriptionEnvironmentVariables
{
public static readonly bool AddEntityRedaction = bool.TryParse(Environment.GetEnvironmentVariable(nameof(AddEntityRedaction), EnvironmentVariableTarget.Process), out AddEntityRedaction) && AddEntityRedaction;
public static readonly SentimentAnalysisSetting SentimentAnalysisSetting = Enum.TryParse(Environment.GetEnvironmentVariable(nameof(SentimentAnalysisSetting), EnvironmentVariableTarget.Process), out SentimentAnalysisSetting) ? SentimentAnalysisSetting : SentimentAnalysisSetting.None;

public static readonly bool AddSentimentAnalysis = bool.TryParse(Environment.GetEnvironmentVariable(nameof(AddSentimentAnalysis), EnvironmentVariableTarget.Process), out AddSentimentAnalysis) && AddSentimentAnalysis;
public static readonly EntityRedactionSetting EntityRedactionSetting = Enum.TryParse(Environment.GetEnvironmentVariable(nameof(EntityRedactionSetting), EnvironmentVariableTarget.Process), out EntityRedactionSetting) ? EntityRedactionSetting : EntityRedactionSetting.None;

public static readonly bool CreateHtmlResultFile = bool.TryParse(Environment.GetEnvironmentVariable(nameof(CreateHtmlResultFile), EnvironmentVariableTarget.Process), out CreateHtmlResultFile) && CreateHtmlResultFile;

Expand Down
Loading

0 comments on commit 995d20d

Please sign in to comment.