@searpent/react-image-annotate 2.0.1 → 2.0.4

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.
@@ -0,0 +1,40 @@
1
+ function labelAndTextFromResultText(resultText) {
2
+ if (!resultText) { return {} }
3
+ const parsedResultText = JSON.parse(resultText);
4
+ const label = parsedResultText[0].label;
5
+ const text = parsedResultText[0].text;
6
+ return { label, text }
7
+ }
8
+
9
+ function modelResultsToRegions(modelResults) {
10
+ return modelResults.map(r => {
11
+ const { label, text } = labelAndTextFromResultText(r.text);
12
+ return {
13
+ id: r.id,
14
+ type: "box",
15
+ visible: true,
16
+ cls: label,
17
+ highlighted: false,
18
+ groupHighlighted: false,
19
+ x: r.box.X1,
20
+ y: r.box.Y1,
21
+ w: r.box.X2 - r.box.X1,
22
+ h: r.box.Y2 - r.box.Y1,
23
+ groupId: r.groupId,
24
+ text: text,
25
+ }
26
+ })
27
+ }
28
+
29
+ function photosToImages(photos) {
30
+ return photos.map(photo => ({
31
+ id: photo.id,
32
+ src: photo.fullsize.key,
33
+ thumbnail: photo.thumbnail.key,
34
+ name: photo.fullsize.key,
35
+ regions: modelResultsToRegions(photo.modelResults.v1.filter(mr => mr.name === 'extraction-engine')[0].results),
36
+ metadata: photo.metadata
37
+ }))
38
+ }
39
+
40
+ export default photosToImages;
@@ -0,0 +1,14 @@
1
+ function regionsToBlocks(regions) {
2
+ return regions.map(r => ({
3
+ id: r.id,
4
+ type: "annotation",
5
+ data: {
6
+ text: r.text || '',
7
+ labelName: r.cls,
8
+ groupColor: r.groupColor,
9
+ groupId: r.groupId
10
+ }
11
+ }))
12
+ }
13
+
14
+ export default regionsToBlocks;