forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ranges.js
44 lines (35 loc) · 1.82 KB
/
ranges.js
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
// 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.
const 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.
// We are interested in the distinct set of TIMEX expressions.
const distinctTimexExpressions = new Set(
result.resolution.values
.filter(({ timex }) => timex !== undefined)
.map(({ timex }) => 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.
const 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.
// We are interested in the distinct set of TIMEX expressions.
const distinctTimexExpressions = new Set(
result.resolution.values
.filter(({ timex }) => timex !== undefined)
.map(({ timex }) => 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(',') } )`);
});
};