forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ranges.cs
66 lines (59 loc) · 2.62 KB
/
Ranges.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using Microsoft.Recognizers.Text;
using Microsoft.Recognizers.Text.DateTime;
namespace Microsoft.BotBuilderSamples
{
public static class Ranges
{
/// <summary>
/// TIMEX expressions can represent date and time ranges. Here are a couple of examples.
/// </summary>
public static void DateRange()
{
// Run the recognizer.
var results = DateTimeRecognizer.RecognizeDateTime("Some time in the next two weeks.", Culture.English);
// We should find a single result in this example.
foreach (var result in results)
{
// The resolution includes a single value because there is no ambiguity.
var distinctTimexExpressions = new HashSet<string>();
var values = (List<Dictionary<string, string>>)result.Resolution["values"];
foreach (var value in values)
{
// We are interested in the distinct set of TIMEX expressions.
if (value.TryGetValue("timex", out var timex))
{
distinctTimexExpressions.Add(timex);
}
}
// The TIMEX expression can also capture the notion of range.
Console.WriteLine($"{result.Text} ( {string.Join(',', distinctTimexExpressions)} )");
}
}
public static void TimeRange()
{
// Run the recognizer.
var results = DateTimeRecognizer.RecognizeDateTime("Some time between 6pm and 6:30pm.", Culture.English);
// We should find a single result in this example.
foreach (var result in results)
{
// The resolution includes a single value because there is no ambiguity.
var distinctTimexExpressions = new HashSet<string>();
var values = (List<Dictionary<string, string>>)result.Resolution["values"];
foreach (var value in values)
{
// We are interested in the distinct set of TIMEX expressions.
if (value.TryGetValue("timex", out var timex))
{
distinctTimexExpressions.Add(timex);
}
}
// The TIMEX expression can also capture the notion of range.
Console.WriteLine($"{result.Text} ( {string.Join(',', distinctTimexExpressions)} )");
}
}
}
}