forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathambiguity.js
88 lines (75 loc) · 4.33 KB
/
ambiguity.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
const Recognizers = require('@microsoft/recognizers-text-date-time');
// TIMEX expressions are designed to represent ambiguous rather than definite dates.
// For example:
// "Monday" could be any Monday ever.
// "May 5th" could be any one of the possible May 5th in the past or the future.
// TIMEX does not represent ambiguous times. So if the natural language mentioned 4 o'clock
// it could be either 4AM or 4PM. For that the recognizer (and by extension LUIS) would return two TIMEX expressions.
// A TIMEX expression can include a date and time parts. So ambiguity of date can be combined with multiple results.
// Code that deals with TIMEX expressions is frequently dealing with sets of TIMEX expressions.
module.exports.dateAmbiguity = () => {
// Run the recognizer.
var result = Recognizers.recognizeDateTime('Either Saturday or Sunday would work.', Recognizers.Culture.English);
// We should find two results in this example.
result.forEach((result) => {
// The resolution includes two example values: going backwards and forwards from NOW in the calendar.
var distinctTimexExpressions = new Set();
var values = result.resolution['values'];
values.forEach((value) => {
// Each result includes a TIMEX expression that captures the inherent date but not time ambiguity.
// We are interested in the distinct set of TIMEX expressions.
var timex = value['timex'];
if (timex !== undefined) {
distinctTimexExpressions.add(timex);
}
// There is also either a "value" property on each value or "start" and "end".
// If you use ToString() on a TimeProperty object you will get same "value".
});
// 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.timeAmbiguity = () => {
// Run the recognizer.
var result = Recognizers.recognizeDateTime("We would like to arrive at 4 o'clock or 5 o'clock.", Recognizers.Culture.English);
// We should find two results in this example.
result.forEach((result) => {
// The resolution includes two example values: one for AM and one for PM.
var distinctTimexExpressions = new Set();
var values = result.resolution['values'];
values.forEach((value) => {
// Each result includes a TIMEX expression that captures the inherent date but not time ambiguity.
// We are interested in the distinct set of TIMEX expressions.
var timex = value['timex'];
if (timex !== undefined) {
distinctTimexExpressions.add(timex);
}
// There is also either a "value" property on each value or "start" and "end".
// If you use ToString() on a TimeProperty object you will get same "value".
});
// 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.dateTimeAmbiguity = () => {
// Run the recognizer.
var result = Recognizers.recognizeDateTime("It will be ready Wednesday at 5 o'clock.", Recognizers.Culture.English);
// We should find two results in this example.
result.forEach((result) => {
// The resolution includes four example values: backwards and forward in the calendar and then AM and PM.
var distinctTimexExpressions = new Set();
var values = result.resolution['values'];
values.forEach((value) => {
// Each result includes a TIMEX expression that captures the inherent date but not time ambiguity.
// We are interested in the distinct set of TIMEX expressions.
var timex = value['timex'];
if (timex !== undefined) {
distinctTimexExpressions.add(timex);
}
});
// TIMEX expressions don't capture time ambiguity so there will be two distinct expressions for each result.
console.log(`${ result.text } ( ${ (Array.from(distinctTimexExpressions).join(',')) } )`);
});
};