@aws-amplify/predictions 5.5.6-api-v6-models.b3abc9b.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/lib/Predictions.d.ts +11 -45
- package/lib/Predictions.js +24 -132
- package/lib/errors/PredictionsError.d.ts +4 -0
- package/lib/errors/PredictionsError.js +15 -0
- package/lib/errors/types/validation.d.ts +14 -0
- package/lib/errors/types/validation.js +50 -0
- package/lib/errors/utils/assertValidationError.d.ts +2 -0
- package/lib/errors/utils/assertValidationError.js +14 -0
- package/lib/index.d.ts +2 -4
- package/lib/index.js +2 -9
- package/{lib-esm/Providers → lib/providers}/AmazonAIConvertPredictionsProvider.d.ts +6 -7
- package/lib/providers/AmazonAIConvertPredictionsProvider.js +307 -0
- package/lib/{Providers → providers}/AmazonAIIdentifyPredictionsProvider.d.ts +5 -6
- package/lib/providers/AmazonAIIdentifyPredictionsProvider.js +334 -0
- package/lib/{Providers → providers}/AmazonAIInterpretPredictionsProvider.d.ts +3 -4
- package/lib/providers/AmazonAIInterpretPredictionsProvider.js +208 -0
- package/lib/providers/IdentifyTextUtils.d.ts +16 -0
- package/lib/{Providers → providers}/IdentifyTextUtils.js +97 -148
- package/lib/{Providers → providers}/Utils.d.ts +2 -2
- package/lib/{Providers → providers}/Utils.js +11 -12
- package/lib/{Providers → providers}/index.d.ts +1 -2
- package/lib/providers/index.js +11 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types/AWSTypes.d.ts +8 -9
- package/lib/types/AWSTypes.js +0 -1
- package/lib/types/Predictions.d.ts +63 -59
- package/lib/types/Predictions.js +41 -28
- package/lib/types/index.js +1 -2
- package/lib-esm/Predictions.d.ts +11 -45
- package/lib-esm/Predictions.js +23 -133
- package/lib-esm/errors/PredictionsError.d.ts +4 -0
- package/lib-esm/errors/PredictionsError.js +11 -0
- package/lib-esm/errors/types/validation.d.ts +14 -0
- package/lib-esm/errors/types/validation.js +47 -0
- package/lib-esm/errors/utils/assertValidationError.d.ts +2 -0
- package/lib-esm/errors/utils/assertValidationError.js +10 -0
- package/lib-esm/index.d.ts +2 -4
- package/lib-esm/index.js +1 -5
- package/{lib/Providers → lib-esm/providers}/AmazonAIConvertPredictionsProvider.d.ts +6 -7
- package/lib-esm/providers/AmazonAIConvertPredictionsProvider.js +303 -0
- package/lib-esm/{Providers → providers}/AmazonAIIdentifyPredictionsProvider.d.ts +5 -6
- package/lib-esm/providers/AmazonAIIdentifyPredictionsProvider.js +330 -0
- package/lib-esm/{Providers → providers}/AmazonAIInterpretPredictionsProvider.d.ts +3 -4
- package/lib-esm/providers/AmazonAIInterpretPredictionsProvider.js +204 -0
- package/lib-esm/providers/IdentifyTextUtils.d.ts +16 -0
- package/lib-esm/providers/IdentifyTextUtils.js +264 -0
- package/lib-esm/{Providers → providers}/Utils.d.ts +2 -2
- package/lib-esm/{Providers → providers}/Utils.js +10 -12
- package/lib-esm/{Providers → providers}/index.d.ts +1 -2
- package/lib-esm/{Providers → providers}/index.js +1 -3
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/lib-esm/types/AWSTypes.d.ts +8 -9
- package/lib-esm/types/AWSTypes.js +1 -1
- package/lib-esm/types/Predictions.d.ts +63 -59
- package/lib-esm/types/Predictions.js +34 -27
- package/lib-esm/types/index.js +0 -1
- package/package.json +39 -48
- package/src/Predictions.ts +33 -220
- package/src/errors/PredictionsError.ts +16 -0
- package/src/errors/types/validation.ts +51 -0
- package/src/errors/utils/assertValidationError.ts +18 -0
- package/src/index.ts +16 -16
- package/src/{Providers → providers}/AmazonAIConvertPredictionsProvider.ts +210 -171
- package/src/{Providers → providers}/AmazonAIIdentifyPredictionsProvider.ts +244 -246
- package/src/providers/AmazonAIInterpretPredictionsProvider.ts +293 -0
- package/src/{Providers → providers}/IdentifyTextUtils.ts +69 -52
- package/src/{Providers → providers}/Utils.ts +2 -2
- package/src/{Providers → providers}/index.ts +0 -2
- package/src/types/AWSTypes.ts +5 -6
- package/src/types/Predictions.ts +107 -62
- package/lib/.tsbuildinfo +0 -3
- package/lib/Predictions.js.map +0 -1
- package/lib/Providers/AmazonAIConvertPredictionsProvider.js +0 -377
- package/lib/Providers/AmazonAIConvertPredictionsProvider.js.map +0 -1
- package/lib/Providers/AmazonAIIdentifyPredictionsProvider.js +0 -441
- package/lib/Providers/AmazonAIIdentifyPredictionsProvider.js.map +0 -1
- package/lib/Providers/AmazonAIInterpretPredictionsProvider.js +0 -321
- package/lib/Providers/AmazonAIInterpretPredictionsProvider.js.map +0 -1
- package/lib/Providers/AmazonAIPredictionsProvider.d.ts +0 -14
- package/lib/Providers/AmazonAIPredictionsProvider.js +0 -43
- package/lib/Providers/AmazonAIPredictionsProvider.js.map +0 -1
- package/lib/Providers/IdentifyTextUtils.d.ts +0 -40
- package/lib/Providers/IdentifyTextUtils.js.map +0 -1
- package/lib/Providers/Utils.js.map +0 -1
- package/lib/Providers/index.js +0 -13
- package/lib/Providers/index.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/types/AWSTypes.js.map +0 -1
- package/lib/types/Predictions.js.map +0 -1
- package/lib/types/Providers/AbstractConvertPredictionsProvider.d.ts +0 -9
- package/lib/types/Providers/AbstractConvertPredictionsProvider.js +0 -44
- package/lib/types/Providers/AbstractConvertPredictionsProvider.js.map +0 -1
- package/lib/types/Providers/AbstractIdentifyPredictionsProvider.d.ts +0 -9
- package/lib/types/Providers/AbstractIdentifyPredictionsProvider.js +0 -44
- package/lib/types/Providers/AbstractIdentifyPredictionsProvider.js.map +0 -1
- package/lib/types/Providers/AbstractInterpretPredictionsProvider.d.ts +0 -7
- package/lib/types/Providers/AbstractInterpretPredictionsProvider.js +0 -27
- package/lib/types/Providers/AbstractInterpretPredictionsProvider.js.map +0 -1
- package/lib/types/Providers/AbstractPredictionsProvider.d.ts +0 -7
- package/lib/types/Providers/AbstractPredictionsProvider.js +0 -16
- package/lib/types/Providers/AbstractPredictionsProvider.js.map +0 -1
- package/lib/types/Providers/index.d.ts +0 -4
- package/lib/types/Providers/index.js +0 -10
- package/lib/types/Providers/index.js.map +0 -1
- package/lib/types/index.js.map +0 -1
- package/lib-esm/.tsbuildinfo +0 -3
- package/lib-esm/Predictions.js.map +0 -1
- package/lib-esm/Providers/AmazonAIConvertPredictionsProvider.js +0 -375
- package/lib-esm/Providers/AmazonAIConvertPredictionsProvider.js.map +0 -1
- package/lib-esm/Providers/AmazonAIIdentifyPredictionsProvider.js +0 -439
- package/lib-esm/Providers/AmazonAIIdentifyPredictionsProvider.js.map +0 -1
- package/lib-esm/Providers/AmazonAIInterpretPredictionsProvider.js +0 -319
- package/lib-esm/Providers/AmazonAIInterpretPredictionsProvider.js.map +0 -1
- package/lib-esm/Providers/AmazonAIPredictionsProvider.d.ts +0 -14
- package/lib-esm/Providers/AmazonAIPredictionsProvider.js +0 -41
- package/lib-esm/Providers/AmazonAIPredictionsProvider.js.map +0 -1
- package/lib-esm/Providers/IdentifyTextUtils.d.ts +0 -40
- package/lib-esm/Providers/IdentifyTextUtils.js +0 -313
- package/lib-esm/Providers/IdentifyTextUtils.js.map +0 -1
- package/lib-esm/Providers/Utils.js.map +0 -1
- package/lib-esm/Providers/index.js.map +0 -1
- package/lib-esm/index.js.map +0 -1
- package/lib-esm/types/AWSTypes.js.map +0 -1
- package/lib-esm/types/Predictions.js.map +0 -1
- package/lib-esm/types/Providers/AbstractConvertPredictionsProvider.d.ts +0 -9
- package/lib-esm/types/Providers/AbstractConvertPredictionsProvider.js +0 -42
- package/lib-esm/types/Providers/AbstractConvertPredictionsProvider.js.map +0 -1
- package/lib-esm/types/Providers/AbstractIdentifyPredictionsProvider.d.ts +0 -9
- package/lib-esm/types/Providers/AbstractIdentifyPredictionsProvider.js +0 -42
- package/lib-esm/types/Providers/AbstractIdentifyPredictionsProvider.js.map +0 -1
- package/lib-esm/types/Providers/AbstractInterpretPredictionsProvider.d.ts +0 -7
- package/lib-esm/types/Providers/AbstractInterpretPredictionsProvider.js +0 -25
- package/lib-esm/types/Providers/AbstractInterpretPredictionsProvider.js.map +0 -1
- package/lib-esm/types/Providers/AbstractPredictionsProvider.d.ts +0 -7
- package/lib-esm/types/Providers/AbstractPredictionsProvider.js +0 -14
- package/lib-esm/types/Providers/AbstractPredictionsProvider.js.map +0 -1
- package/lib-esm/types/Providers/index.d.ts +0 -4
- package/lib-esm/types/Providers/index.js +0 -7
- package/lib-esm/types/Providers/index.js.map +0 -1
- package/lib-esm/types/index.js.map +0 -1
- package/src/Providers/AmazonAIInterpretPredictionsProvider.ts +0 -281
- package/src/Providers/AmazonAIPredictionsProvider.ts +0 -69
- package/src/types/Providers/AbstractConvertPredictionsProvider.ts +0 -55
- package/src/types/Providers/AbstractIdentifyPredictionsProvider.ts +0 -57
- package/src/types/Providers/AbstractInterpretPredictionsProvider.ts +0 -26
- package/src/types/Providers/AbstractPredictionsProvider.ts +0 -20
- package/src/types/Providers/index.ts +0 -6
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { makeCamelCase, makeCamelCaseArray } from './Utils';
|
|
2
|
+
function getBoundingBox(geometry) {
|
|
3
|
+
return makeCamelCase(geometry?.BoundingBox);
|
|
4
|
+
}
|
|
5
|
+
function getPolygon(geometry) {
|
|
6
|
+
if (!geometry?.Polygon)
|
|
7
|
+
return undefined;
|
|
8
|
+
return makeCamelCaseArray(Array.from(geometry.Polygon));
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Organizes blocks from Rekognition API to each of the categories and and structures
|
|
12
|
+
* their data accordingly.
|
|
13
|
+
* @param {BlockList} source - Array containing blocks returned from Textract API.
|
|
14
|
+
* @return {IdentifyTextOutput} - Object that categorizes each block and its information.
|
|
15
|
+
*/
|
|
16
|
+
export function categorizeRekognitionBlocks(blocks) {
|
|
17
|
+
// Skeleton IdentifyText API response. We will populate it as we iterate through blocks.
|
|
18
|
+
const response = {
|
|
19
|
+
text: {
|
|
20
|
+
fullText: '',
|
|
21
|
+
words: [],
|
|
22
|
+
lines: [],
|
|
23
|
+
linesDetailed: [],
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
// We categorize each block by running a forEach loop through them.
|
|
27
|
+
blocks.forEach(block => {
|
|
28
|
+
switch (block.Type) {
|
|
29
|
+
case 'LINE':
|
|
30
|
+
if (block.DetectedText) {
|
|
31
|
+
response.text.lines.push(block.DetectedText);
|
|
32
|
+
}
|
|
33
|
+
response.text.linesDetailed.push({
|
|
34
|
+
text: block.DetectedText,
|
|
35
|
+
polygon: getPolygon(block.Geometry),
|
|
36
|
+
boundingBox: getBoundingBox(block.Geometry),
|
|
37
|
+
page: undefined, // rekognition doesn't have this info
|
|
38
|
+
});
|
|
39
|
+
break;
|
|
40
|
+
case 'WORD':
|
|
41
|
+
response.text.fullText += block.DetectedText + ' ';
|
|
42
|
+
response.text.words.push({
|
|
43
|
+
text: block.DetectedText,
|
|
44
|
+
polygon: getPolygon(block.Geometry),
|
|
45
|
+
boundingBox: getBoundingBox(block.Geometry),
|
|
46
|
+
});
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
// remove trailing space of fullText
|
|
51
|
+
response.text.fullText = response.text.fullText.substr(0, response.text.fullText.length - 1);
|
|
52
|
+
return response;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Organizes blocks from Textract API to each of the categories and and structures
|
|
56
|
+
* their data accordingly.
|
|
57
|
+
* @param {BlockList} source - Array containing blocks returned from Textract API.
|
|
58
|
+
* @return {IdentifyTextOutput} - Object that categorizes each block and its information.
|
|
59
|
+
*/
|
|
60
|
+
export function categorizeTextractBlocks(blocks) {
|
|
61
|
+
// Skeleton IdentifyText API response. We will populate it as we iterate through blocks.
|
|
62
|
+
const response = {
|
|
63
|
+
text: {
|
|
64
|
+
fullText: '',
|
|
65
|
+
words: [],
|
|
66
|
+
lines: [],
|
|
67
|
+
linesDetailed: [],
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
// if blocks is an empty array, ie. textract did not detect anything, return empty response.
|
|
71
|
+
if (blocks.length === 0)
|
|
72
|
+
return response;
|
|
73
|
+
/**
|
|
74
|
+
* We categorize each of the blocks by running a forEach loop through them.
|
|
75
|
+
*
|
|
76
|
+
* For complex structures such as Tables and KeyValue, we need to trasverse through their children. To do so,
|
|
77
|
+
* we will post-process them after the for each loop. We do this by storing table and keyvalues in arrays and
|
|
78
|
+
* mapping other blocks in `blockMap` (id to block) so we can reference them easily later.
|
|
79
|
+
*
|
|
80
|
+
* Note that we do not map `WORD` and `TABLE` in `blockMap` because they will not be referenced by any other
|
|
81
|
+
* block except the Page block.
|
|
82
|
+
*/
|
|
83
|
+
const tableBlocks = Array();
|
|
84
|
+
const keyValueBlocks = Array();
|
|
85
|
+
const blockMap = {};
|
|
86
|
+
blocks.forEach(block => {
|
|
87
|
+
switch (block.BlockType) {
|
|
88
|
+
case 'LINE':
|
|
89
|
+
if (block.Text) {
|
|
90
|
+
response.text.lines.push(block.Text);
|
|
91
|
+
}
|
|
92
|
+
response.text.linesDetailed.push({
|
|
93
|
+
text: block.Text,
|
|
94
|
+
polygon: getPolygon(block.Geometry),
|
|
95
|
+
boundingBox: getBoundingBox(block.Geometry),
|
|
96
|
+
page: block.Page,
|
|
97
|
+
});
|
|
98
|
+
break;
|
|
99
|
+
case 'WORD':
|
|
100
|
+
response.text.fullText += block.Text + ' ';
|
|
101
|
+
response.text.words.push({
|
|
102
|
+
text: block.Text,
|
|
103
|
+
polygon: getPolygon(block.Geometry),
|
|
104
|
+
boundingBox: getBoundingBox(block.Geometry),
|
|
105
|
+
});
|
|
106
|
+
if (block.Id) {
|
|
107
|
+
blockMap[block.Id] = block;
|
|
108
|
+
}
|
|
109
|
+
break;
|
|
110
|
+
case 'SELECTION_ELEMENT':
|
|
111
|
+
const selectionStatus = block.SelectionStatus === 'SELECTED' ? true : false;
|
|
112
|
+
if (!response.text.selections)
|
|
113
|
+
response.text.selections = [];
|
|
114
|
+
response.text.selections.push({
|
|
115
|
+
selected: selectionStatus,
|
|
116
|
+
polygon: getPolygon(block.Geometry),
|
|
117
|
+
boundingBox: getBoundingBox(block.Geometry),
|
|
118
|
+
});
|
|
119
|
+
if (block.Id) {
|
|
120
|
+
blockMap[block.Id] = block;
|
|
121
|
+
}
|
|
122
|
+
break;
|
|
123
|
+
case 'TABLE':
|
|
124
|
+
tableBlocks.push(block);
|
|
125
|
+
break;
|
|
126
|
+
case 'KEY_VALUE_SET':
|
|
127
|
+
keyValueBlocks.push(block);
|
|
128
|
+
if (block.Id) {
|
|
129
|
+
blockMap[block.Id] = block;
|
|
130
|
+
}
|
|
131
|
+
break;
|
|
132
|
+
default:
|
|
133
|
+
if (block.Id) {
|
|
134
|
+
blockMap[block.Id] = block;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
// remove trailing space in fullText
|
|
139
|
+
response.text.fullText = response.text.fullText.substr(0, response.text.fullText.length - 1);
|
|
140
|
+
// Post-process complex structures if they exist.
|
|
141
|
+
if (tableBlocks.length !== 0) {
|
|
142
|
+
const tableResponse = Array();
|
|
143
|
+
tableBlocks.forEach(table => {
|
|
144
|
+
tableResponse.push(constructTable(table, blockMap));
|
|
145
|
+
});
|
|
146
|
+
response.text.tables = tableResponse;
|
|
147
|
+
}
|
|
148
|
+
if (keyValueBlocks.length !== 0) {
|
|
149
|
+
const keyValueResponse = Array();
|
|
150
|
+
keyValueBlocks.forEach(keyValue => {
|
|
151
|
+
// We need the KeyValue blocks of EntityType = `KEY`, which has both key and value references.
|
|
152
|
+
if (keyValue.EntityTypes) {
|
|
153
|
+
const entityTypes = Array.from(keyValue.EntityTypes);
|
|
154
|
+
if (entityTypes.indexOf('KEY') !== -1) {
|
|
155
|
+
keyValueResponse.push(constructKeyValue(keyValue, blockMap));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
response.text.keyValues = keyValueResponse;
|
|
160
|
+
}
|
|
161
|
+
return response;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Constructs a table object using data from its children cells.
|
|
165
|
+
* @param {Block} table - Table block that has references (`Relationships`) to its cells
|
|
166
|
+
* @param {[id: string]: Block} blockMap - Maps block Ids to blocks.
|
|
167
|
+
*/
|
|
168
|
+
function constructTable(table, blockMap) {
|
|
169
|
+
let tableMatrix;
|
|
170
|
+
tableMatrix = [];
|
|
171
|
+
// visit each of the cell associated with the table's relationship.
|
|
172
|
+
for (const tableRelation of table.Relationships ?? []) {
|
|
173
|
+
for (const cellId of tableRelation.Ids ?? []) {
|
|
174
|
+
const cellBlock = blockMap[cellId];
|
|
175
|
+
if (cellBlock.RowIndex && cellBlock.ColumnIndex) {
|
|
176
|
+
const row = cellBlock.RowIndex - 1; // textract starts indexing at 1, so subtract it by 1.
|
|
177
|
+
const col = cellBlock.ColumnIndex - 1; // textract starts indexing at 1, so subtract it by 1.
|
|
178
|
+
// extract data contained inside the cell.
|
|
179
|
+
const content = extractContentsFromBlock(cellBlock, blockMap);
|
|
180
|
+
const cell = {
|
|
181
|
+
text: content.text,
|
|
182
|
+
boundingBox: getBoundingBox(cellBlock.Geometry),
|
|
183
|
+
polygon: getPolygon(cellBlock.Geometry),
|
|
184
|
+
selected: content.selected,
|
|
185
|
+
rowSpan: cellBlock.RowSpan,
|
|
186
|
+
columnSpan: cellBlock.ColumnSpan,
|
|
187
|
+
};
|
|
188
|
+
if (!tableMatrix[row])
|
|
189
|
+
tableMatrix[row] = [];
|
|
190
|
+
tableMatrix[row][col] = cell;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const rowSize = tableMatrix.length;
|
|
195
|
+
const columnSize = tableMatrix[0].length;
|
|
196
|
+
const boundingBox = getBoundingBox(table.Geometry);
|
|
197
|
+
const polygon = getPolygon(table.Geometry);
|
|
198
|
+
// Note that we leave spanned cells undefined for distinction
|
|
199
|
+
return {
|
|
200
|
+
size: { rows: rowSize, columns: columnSize },
|
|
201
|
+
table: tableMatrix,
|
|
202
|
+
boundingBox,
|
|
203
|
+
polygon,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Constructs a key value object from its children key and value blocks.
|
|
208
|
+
* @param {Block} KeyValue - KeyValue block that has references (`Relationships`) to its children.
|
|
209
|
+
* @param {[id: string]: Block} blockMap - Maps block Ids to blocks.
|
|
210
|
+
*/
|
|
211
|
+
function constructKeyValue(keyBlock, blockMap) {
|
|
212
|
+
let keyText = '';
|
|
213
|
+
let valueText = '';
|
|
214
|
+
let valueSelected = false;
|
|
215
|
+
for (const keyValueRelation of keyBlock.Relationships ?? []) {
|
|
216
|
+
if (keyValueRelation.Type === 'CHILD') {
|
|
217
|
+
// relation refers to key
|
|
218
|
+
const contents = extractContentsFromBlock(keyBlock, blockMap);
|
|
219
|
+
keyText = contents.text ?? '';
|
|
220
|
+
}
|
|
221
|
+
else if (keyValueRelation.Type === 'VALUE') {
|
|
222
|
+
// relation refers to value
|
|
223
|
+
for (const valueId of keyValueRelation.Ids ?? []) {
|
|
224
|
+
const valueBlock = blockMap[valueId];
|
|
225
|
+
const contents = extractContentsFromBlock(valueBlock, blockMap);
|
|
226
|
+
valueText = contents.text ?? '';
|
|
227
|
+
if (contents.selected != null)
|
|
228
|
+
valueSelected = contents.selected;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
key: keyText,
|
|
234
|
+
value: { text: valueText, selected: valueSelected },
|
|
235
|
+
polygon: getPolygon(keyBlock.Geometry),
|
|
236
|
+
boundingBox: getBoundingBox(keyBlock.Geometry),
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Extracts text and selection from input block's children.
|
|
241
|
+
* @param {Block}} block - Block that we want to extract contents from.
|
|
242
|
+
* @param {[id: string]: Block} blockMap - Maps block Ids to blocks.
|
|
243
|
+
*/
|
|
244
|
+
function extractContentsFromBlock(block, blockMap) {
|
|
245
|
+
let words = '';
|
|
246
|
+
let isSelected = false;
|
|
247
|
+
if (!block.Relationships) {
|
|
248
|
+
// some block might have no content
|
|
249
|
+
return { text: '', selected: undefined };
|
|
250
|
+
}
|
|
251
|
+
for (const relation of block.Relationships) {
|
|
252
|
+
for (const contentId of relation.Ids ?? []) {
|
|
253
|
+
const contentBlock = blockMap[contentId];
|
|
254
|
+
if (contentBlock.BlockType === 'WORD') {
|
|
255
|
+
words += contentBlock.Text + ' ';
|
|
256
|
+
}
|
|
257
|
+
else if (contentBlock.BlockType === 'SELECTION_ELEMENT') {
|
|
258
|
+
isSelected = contentBlock.SelectionStatus === 'SELECTED' ? true : false;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
words = words.substr(0, words.length - 1); // remove trailing space.
|
|
263
|
+
return { text: words, selected: isSelected };
|
|
264
|
+
}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* Changes object keys to camel case. If optional parameter `keys` is given, then we extract only the
|
|
3
3
|
* keys specified in `keys`.
|
|
4
4
|
*/
|
|
5
|
-
export declare function makeCamelCase(obj
|
|
5
|
+
export declare function makeCamelCase(obj?: any, keys?: string[]): {} | undefined;
|
|
6
6
|
/**
|
|
7
7
|
* Given an array of object, call makeCamelCase(...) on each option.
|
|
8
8
|
*/
|
|
9
|
-
export declare function makeCamelCaseArray(objArr
|
|
9
|
+
export declare function makeCamelCaseArray(objArr?: object[], keys?: string[]): ({} | undefined)[] | undefined;
|
|
10
10
|
/**
|
|
11
11
|
* Converts blob to array buffer
|
|
12
12
|
*/
|
|
@@ -7,14 +7,13 @@
|
|
|
7
7
|
export function makeCamelCase(obj, keys) {
|
|
8
8
|
if (!obj)
|
|
9
9
|
return undefined;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
keysToRename.forEach(
|
|
13
|
-
var _a;
|
|
10
|
+
const newObj = {};
|
|
11
|
+
const keysToRename = keys ? keys : Object.keys(obj);
|
|
12
|
+
keysToRename.forEach(key => {
|
|
14
13
|
if (obj.hasOwnProperty(key)) {
|
|
15
14
|
// change the key to camelcase.
|
|
16
|
-
|
|
17
|
-
Object.assign(newObj,
|
|
15
|
+
const camelCaseKey = key.charAt(0).toLowerCase() + key.substr(1);
|
|
16
|
+
Object.assign(newObj, { [camelCaseKey]: obj[key] });
|
|
18
17
|
}
|
|
19
18
|
});
|
|
20
19
|
return newObj;
|
|
@@ -25,18 +24,18 @@ export function makeCamelCase(obj, keys) {
|
|
|
25
24
|
export function makeCamelCaseArray(objArr, keys) {
|
|
26
25
|
if (!objArr)
|
|
27
26
|
return undefined;
|
|
28
|
-
return objArr.map(
|
|
27
|
+
return objArr.map(obj => makeCamelCase(obj, keys));
|
|
29
28
|
}
|
|
30
29
|
/**
|
|
31
30
|
* Converts blob to array buffer
|
|
32
31
|
*/
|
|
33
32
|
export function blobToArrayBuffer(blob) {
|
|
34
|
-
return new Promise(
|
|
35
|
-
|
|
36
|
-
reader.onload =
|
|
33
|
+
return new Promise((res, rej) => {
|
|
34
|
+
const reader = new FileReader();
|
|
35
|
+
reader.onload = _event => {
|
|
37
36
|
res(reader.result);
|
|
38
37
|
};
|
|
39
|
-
reader.onerror =
|
|
38
|
+
reader.onerror = err => {
|
|
40
39
|
rej(err);
|
|
41
40
|
};
|
|
42
41
|
try {
|
|
@@ -47,4 +46,3 @@ export function blobToArrayBuffer(blob) {
|
|
|
47
46
|
}
|
|
48
47
|
});
|
|
49
48
|
}
|
|
50
|
-
//# sourceMappingURL=Utils.js.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AmazonAIConvertPredictionsProvider } from './AmazonAIConvertPredictionsProvider';
|
|
2
2
|
import { AmazonAIIdentifyPredictionsProvider } from './AmazonAIIdentifyPredictionsProvider';
|
|
3
3
|
import { AmazonAIInterpretPredictionsProvider } from './AmazonAIInterpretPredictionsProvider';
|
|
4
|
-
|
|
5
|
-
export { AmazonAIConvertPredictionsProvider, AmazonAIIdentifyPredictionsProvider, AmazonAIInterpretPredictionsProvider, AmazonAIPredictionsProvider, };
|
|
4
|
+
export { AmazonAIConvertPredictionsProvider, AmazonAIIdentifyPredictionsProvider, AmazonAIInterpretPredictionsProvider, };
|
|
@@ -3,6 +3,4 @@
|
|
|
3
3
|
import { AmazonAIConvertPredictionsProvider } from './AmazonAIConvertPredictionsProvider';
|
|
4
4
|
import { AmazonAIIdentifyPredictionsProvider } from './AmazonAIIdentifyPredictionsProvider';
|
|
5
5
|
import { AmazonAIInterpretPredictionsProvider } from './AmazonAIInterpretPredictionsProvider';
|
|
6
|
-
|
|
7
|
-
export { AmazonAIConvertPredictionsProvider, AmazonAIIdentifyPredictionsProvider, AmazonAIInterpretPredictionsProvider, AmazonAIPredictionsProvider, };
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
|
6
|
+
export { AmazonAIConvertPredictionsProvider, AmazonAIIdentifyPredictionsProvider, AmazonAIInterpretPredictionsProvider, };
|