-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Parsing.cs
52 lines (46 loc) · 1.84 KB
/
Parsing.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using Microsoft.Recognizers.Text.DataTypes.TimexExpression;
namespace Microsoft.BotBuilderSamples
{
/// <summary>
/// The TimexProperty class takes a TIMEX expression as a string argument in its constructor.
/// This pulls all the component parts of the expression into properties on this object. You can
/// then manipulate the TIMEX expression via those properties.
/// The "Types" property infers a datetimeV2 type from the underlying set of properties.
/// If you take a TIMEX with date components and add time components you add the
/// inferred type datetime (its still a date).
/// Logic can be written against the inferred type, perhaps to have the bot ask the user for disambiguation.
/// </summary>
public static class Parsing
{
private static void Describe(TimexProperty t)
{
Console.Write($"{t.TimexValue} ");
if (t.Types.Contains(Constants.TimexTypes.Date))
{
if (t.Types.Contains(Constants.TimexTypes.Definite))
{
Console.Write("We have a definite calendar date. ");
}
else
{
Console.Write("We have a date but there is some ambiguity. ");
}
}
if (t.Types.Contains(Constants.TimexTypes.Time))
{
Console.Write("We have a time.");
}
Console.WriteLine();
}
public static void Examples()
{
Describe(new TimexProperty("2017-05-29"));
Describe(new TimexProperty("XXXX-WXX-6"));
Describe(new TimexProperty("XXXX-WXX-6T16"));
Describe(new TimexProperty("T12"));
}
}
}