more fixes
This commit is contained in:
@@ -839,7 +839,9 @@ public sealed class JiboInteractionService(
|
|||||||
|
|
||||||
private static string ResolveAmPm(string token)
|
private static string ResolveAmPm(string token)
|
||||||
{
|
{
|
||||||
return token.StartsWith("p", StringComparison.OrdinalIgnoreCase) ? "pm" : "am";
|
var normalized = token.Replace(" ", string.Empty, StringComparison.Ordinal)
|
||||||
|
.Replace(".", string.Empty, StringComparison.Ordinal);
|
||||||
|
return normalized.StartsWith("p", StringComparison.OrdinalIgnoreCase) ? "pm" : "am";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsTimerRequest(string loweredTranscript)
|
private static bool IsTimerRequest(string loweredTranscript)
|
||||||
@@ -971,11 +973,11 @@ public sealed class JiboInteractionService(
|
|||||||
private sealed record ClockAlarmValue(string Time, string AmPm);
|
private sealed record ClockAlarmValue(string Time, string AmPm);
|
||||||
|
|
||||||
private static readonly Regex SplitAlarmPattern = new(
|
private static readonly Regex SplitAlarmPattern = new(
|
||||||
@"\b(?<hour>\d{1,2}|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve)(?:[:\s-](?<minute>\d{2}|[a-z\-]+(?:\s+[a-z\-]+)?))?\s*(?<ampm>a\.?m\.?|p\.?m\.?)?\b",
|
@"\b(?<hour>\d{1,2}|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve)(?:[:\s-](?<minute>\d{2}|[a-z\-]+(?:\s+[a-z\-]+)?))?\s*(?<ampm>a[\s\.]*m\.?|p[\s\.]*m\.?)?\b",
|
||||||
RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
|
RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
|
||||||
|
|
||||||
private static readonly Regex CompactAlarmPattern = new(
|
private static readonly Regex CompactAlarmPattern = new(
|
||||||
@"\b(?<compact>\d{3,4})\s*(?<ampm>a\.?m\.?|p\.?m\.?)?\b",
|
@"\b(?<compact>\d{3,4})\s*(?<ampm>a[\s\.]*m\.?|p[\s\.]*m\.?)?\b",
|
||||||
RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
|
RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
|
||||||
|
|
||||||
private static readonly (string Phrase, string Station)[] RadioGenreAliases =
|
private static readonly (string Phrase, string Station)[] RadioGenreAliases =
|
||||||
|
|||||||
@@ -336,6 +336,38 @@ public sealed class JiboInteractionServiceTests
|
|||||||
Assert.Equal("am", decision.SkillPayload["ampm"]);
|
Assert.Equal("am", decision.SkillPayload["ampm"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task BuildDecisionAsync_SetAlarmForTenTwentyFivePm_ParsesPmSuffix()
|
||||||
|
{
|
||||||
|
var service = CreateService();
|
||||||
|
|
||||||
|
var decision = await service.BuildDecisionAsync(new TurnContext
|
||||||
|
{
|
||||||
|
RawTranscript = "set an alarm for 10:25 pm",
|
||||||
|
NormalizedTranscript = "set an alarm for 10:25 pm"
|
||||||
|
});
|
||||||
|
|
||||||
|
Assert.Equal("alarm_value", decision.IntentName);
|
||||||
|
Assert.Equal("10:25", decision.SkillPayload!["time"]);
|
||||||
|
Assert.Equal("pm", decision.SkillPayload["ampm"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task BuildDecisionAsync_SetAlarmForTenTwentyFiveSpacedPm_ParsesPmSuffix()
|
||||||
|
{
|
||||||
|
var service = CreateService();
|
||||||
|
|
||||||
|
var decision = await service.BuildDecisionAsync(new TurnContext
|
||||||
|
{
|
||||||
|
RawTranscript = "set an alarm for 10 25 p m",
|
||||||
|
NormalizedTranscript = "set an alarm for 10 25 p m"
|
||||||
|
});
|
||||||
|
|
||||||
|
Assert.Equal("alarm_value", decision.IntentName);
|
||||||
|
Assert.Equal("10:25", decision.SkillPayload!["time"]);
|
||||||
|
Assert.Equal("pm", decision.SkillPayload["ampm"]);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task BuildDecisionAsync_TimerValueFollowUp_ParsesBareDuration()
|
public async Task BuildDecisionAsync_TimerValueFollowUp_ParsesBareDuration()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -533,6 +533,34 @@ public sealed class JiboWebSocketServiceTests
|
|||||||
Assert.Equal("am", listenPayload.RootElement.GetProperty("data").GetProperty("nlu").GetProperty("entities").GetProperty("ampm").GetString());
|
Assert.Equal("am", listenPayload.RootElement.GetProperty("data").GetProperty("nlu").GetProperty("entities").GetProperty("ampm").GetString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ClientAsr_SetAlarmForTenTwentyFivePm_ParsesAlarmTimeWithPm()
|
||||||
|
{
|
||||||
|
await _service.HandleMessageAsync(new WebSocketMessageEnvelope
|
||||||
|
{
|
||||||
|
HostName = "neo-hub.jibo.com",
|
||||||
|
Path = "/listen",
|
||||||
|
Kind = "neo-hub-listen",
|
||||||
|
Token = "hub-clock-pm-alarm-token",
|
||||||
|
Text = """{"type":"LISTEN","transID":"trans-clock-pm-alarm","data":{"rules":["globals/global_commands_launch"]}}"""
|
||||||
|
});
|
||||||
|
|
||||||
|
var replies = await _service.HandleMessageAsync(new WebSocketMessageEnvelope
|
||||||
|
{
|
||||||
|
HostName = "neo-hub.jibo.com",
|
||||||
|
Path = "/listen",
|
||||||
|
Kind = "neo-hub-listen",
|
||||||
|
Token = "hub-clock-pm-alarm-token",
|
||||||
|
Text = """{"type":"CLIENT_ASR","transID":"trans-clock-pm-alarm","data":{"text":"set an alarm for 10:25 pm"}}"""
|
||||||
|
});
|
||||||
|
|
||||||
|
Assert.Equal(4, replies.Count);
|
||||||
|
|
||||||
|
using var listenPayload = JsonDocument.Parse(replies[0].Text!);
|
||||||
|
Assert.Equal("10:25", listenPayload.RootElement.GetProperty("data").GetProperty("nlu").GetProperty("entities").GetProperty("time").GetString());
|
||||||
|
Assert.Equal("pm", listenPayload.RootElement.GetProperty("data").GetProperty("nlu").GetProperty("entities").GetProperty("ampm").GetString());
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ClientAsr_TimerValueFollowUp_ParsesBareDurationIntoClockStartIntent()
|
public async Task ClientAsr_TimerValueFollowUp_ParsesBareDurationIntoClockStartIntent()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user