Skip to content

Commit 995d20d

Browse files
author
Henry van der Vegte
authored
Text analytics + ARM changes, cleanup (#858)
* text analytics + arm changes, cleanup * remove bom
1 parent b425737 commit 995d20d

File tree

9 files changed

+391
-233
lines changed

9 files changed

+391
-233
lines changed

samples/batch/transcription-enabled-storage/Connector/CostEstimation.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Connector
77
{
88
using System;
9+
using Connector.Enums;
910

1011
public static class CostEstimation
1112
{
@@ -20,18 +21,18 @@ public static double GetCostEstimation(
2021
TimeSpan timeSpan,
2122
int numberOfChannels,
2223
bool isCustomModel,
23-
bool sentimentAnalysisAdded,
24-
bool entityRedactionAdded)
24+
SentimentAnalysisSetting sentimentSetting,
25+
EntityRedactionSetting entityRedactionSetting)
2526
{
2627
double costPerHour = isCustomModel ? STTCustomModelCostPerHour : STTCostPerHour;
2728
var price = timeSpan.TotalHours * costPerHour;
2829

29-
if (sentimentAnalysisAdded)
30+
if (sentimentSetting != SentimentAnalysisSetting.None)
3031
{
3132
price += timeSpan.TotalHours * TextAnalyticsCostPerHour;
3233
}
3334

34-
if (entityRedactionAdded)
35+
if (entityRedactionSetting != EntityRedactionSetting.None)
3536
{
3637
price += timeSpan.TotalHours * TextAnalyticsCostPerHour;
3738
}

samples/batch/transcription-enabled-storage/Connector/DatabaseConnector.cs

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -107,29 +107,23 @@ private async Task StoreCombinedRecognizedPhrasesAsync(Guid transcriptionId, int
107107

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

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

113113
using (var command = new SqlCommand(query, Connection))
114114
{
115115
command.Parameters.AddWithValue("@id", combinedRecognizedPhraseID);
116116
command.Parameters.AddWithValue("@transcriptionID", transcriptionId);
117117
command.Parameters.AddWithValue("@channel", channel);
118118

119-
if (combinedPhrases != null)
120-
{
121-
command.Parameters.AddWithValue("@lexical", combinedPhrases.Lexical);
122-
command.Parameters.AddWithValue("@itn", combinedPhrases.ITN);
123-
command.Parameters.AddWithValue("@maskedItn", combinedPhrases.MaskedITN);
124-
command.Parameters.AddWithValue("@display", combinedPhrases.Display);
125-
}
126-
else
127-
{
128-
command.Parameters.AddWithValue("@lexical", string.Empty);
129-
command.Parameters.AddWithValue("@itn", string.Empty);
130-
command.Parameters.AddWithValue("@maskedItn", string.Empty);
131-
command.Parameters.AddWithValue("@display", string.Empty);
132-
}
119+
command.Parameters.AddWithValue("@lexical", combinedPhrases.Lexical ?? string.Empty);
120+
command.Parameters.AddWithValue("@itn", combinedPhrases.ITN ?? string.Empty);
121+
command.Parameters.AddWithValue("@maskedItn", combinedPhrases.MaskedITN ?? string.Empty);
122+
command.Parameters.AddWithValue("@display", combinedPhrases.Display ?? string.Empty);
123+
124+
command.Parameters.AddWithValue("@sentimentPositive", combinedPhrases?.Sentiment?.Positive ?? 0f);
125+
command.Parameters.AddWithValue("@sentimentNeutral", combinedPhrases?.Sentiment?.Neutral ?? 0f);
126+
command.Parameters.AddWithValue("@sentimentNegative", combinedPhrases?.Sentiment?.Negative ?? 0f);
133127

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

@@ -194,18 +188,10 @@ private async Task StoreNBestAsync(Guid recognizedPhraseID, NBest nBest)
194188
command.Parameters.AddWithValue("@itn", nBest.ITN);
195189
command.Parameters.AddWithValue("@maskedItn", nBest.MaskedITN);
196190
command.Parameters.AddWithValue("@display", nBest.Display);
197-
if (nBest.Sentiment != null)
198-
{
199-
command.Parameters.AddWithValue("@sentimentNegative", nBest.Sentiment.Negative);
200-
command.Parameters.AddWithValue("@sentimentNeutral", nBest.Sentiment.Neutral);
201-
command.Parameters.AddWithValue("@sentimentPositive", nBest.Sentiment.Positive);
202-
}
203-
else
204-
{
205-
command.Parameters.AddWithValue("@sentimentNegative", 0f);
206-
command.Parameters.AddWithValue("@sentimentNeutral", 0f);
207-
command.Parameters.AddWithValue("@sentimentPositive", 0f);
208-
}
191+
192+
command.Parameters.AddWithValue("@sentimentNegative", nBest?.Sentiment?.Negative ?? 0f);
193+
command.Parameters.AddWithValue("@sentimentNeutral", nBest?.Sentiment?.Neutral ?? 0f);
194+
command.Parameters.AddWithValue("@sentimentPositive", nBest?.Sentiment?.Positive ?? 0f);
209195

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// <copyright file="EntityRedactionSetting.cs" company="Microsoft Corporation">
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
4+
// </copyright>
5+
6+
namespace Connector.Enums
7+
{
8+
public enum EntityRedactionSetting
9+
{
10+
None,
11+
UtteranceLevel
12+
}
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// <copyright file="SentimentAnalysisSetting.cs" company="Microsoft Corporation">
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
4+
// </copyright>
5+
6+
namespace Connector.Enums
7+
{
8+
public enum SentimentAnalysisSetting
9+
{
10+
None,
11+
UtteranceLevel,
12+
AudioLevel
13+
}
14+
}

samples/batch/transcription-enabled-storage/Connector/Serializable/TranscriptionResult/CombinedRecognizedPhrase.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ namespace Connector
99

1010
public class CombinedRecognizedPhrase
1111
{
12-
public CombinedRecognizedPhrase(int channel, string lexical, string itn, string maskedItn, string display)
12+
public CombinedRecognizedPhrase(int channel, string lexical, string itn, string maskedItn, string display, Sentiment sentiment)
1313
{
1414
Channel = channel;
1515
Lexical = lexical;
1616
ITN = itn;
1717
MaskedITN = maskedItn;
1818
Display = display;
19+
Sentiment = sentiment;
1920
}
2021

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

3334
[JsonProperty("display")]
3435
public string Display { get; set; }
36+
37+
[JsonProperty("sentiment")]
38+
public Sentiment Sentiment { get; set; }
3539
}
3640
}

samples/batch/transcription-enabled-storage/FetchTranscription/FetchTranscriptionEnvironmentVariables.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
namespace FetchTranscriptionFunction
77
{
88
using System;
9+
using Connector.Enums;
910
using Connector.Extensions;
1011

1112
public static class FetchTranscriptionEnvironmentVariables
1213
{
13-
public static readonly bool AddEntityRedaction = bool.TryParse(Environment.GetEnvironmentVariable(nameof(AddEntityRedaction), EnvironmentVariableTarget.Process), out AddEntityRedaction) && AddEntityRedaction;
14+
public static readonly SentimentAnalysisSetting SentimentAnalysisSetting = Enum.TryParse(Environment.GetEnvironmentVariable(nameof(SentimentAnalysisSetting), EnvironmentVariableTarget.Process), out SentimentAnalysisSetting) ? SentimentAnalysisSetting : SentimentAnalysisSetting.None;
1415

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

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

0 commit comments

Comments
 (0)