forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathranges.js
More file actions
48 lines (41 loc) · 2.01 KB
/
ranges.js
File metadata and controls
48 lines (41 loc) · 2.01 KB
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
const Recognizers = require('@microsoft/recognizers-text-date-time');
module.exports.dateRange = () => {
// Run the recognizer.
var result = Recognizers.recognizeDateTime('Some time in the next two weeks.', Recognizers.Culture.English);
// We should find a single result in this example.
result.forEach((result) => {
// The resolution includes a single value because there is no ambiguity.
var distinctTimexExpressions = new Set();
var values = result.resolution['values'];
values.forEach((value) => {
// We are interested in the distinct set of TIMEX expressions.
var timex = value['timex'];
if (timex !== undefined) {
distinctTimexExpressions.add(timex);
}
});
// The TIMEX expression captures date ambiguity so there will be a single distinct expression for each result.
console.log(`${ result.text } ( ${ (Array.from(distinctTimexExpressions).join(',')) } )`);
});
};
module.exports.timeRange = () => {
// Run the recognizer.
var result = Recognizers.recognizeDateTime('Some time between 6pm and 6:30pm.', Recognizers.Culture.English);
// We should find a single result in this example.
result.forEach((result) => {
// The resolution includes a single value because there is no ambiguity.
var distinctTimexExpressions = new Set();
var values = result.resolution['values'];
values.forEach((value) => {
// We are interested in the distinct set of TIMEX expressions.
var timex = value['time'];
if (timex !== undefined) {
distinctTimexExpressions.add(timex);
}
});
// The TIMEX expression captures date ambiguity so there will be a single distinct expression for each result.
console.log(`${ result.text } ( ${ (Array.from(distinctTimexExpressions).join(',')) } )`);
});
};