@aspiresys/visor 1.1.0 → 1.1.1

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.
Files changed (2) hide show
  1. package/dist/text.js +37 -19
  2. package/package.json +1 -1
package/dist/text.js CHANGED
@@ -9,19 +9,29 @@ async function findText(text, region) {
9
9
  if (!tsv) {
10
10
  return null;
11
11
  }
12
- const lines = tsv.split("\n");
13
- const words = [];
14
- for (const line of lines) {
15
- const cols = line.split("\t");
16
- if (cols[0] !== "5")
12
+ const rows = tsv.split("\n");
13
+ const lineGroups = {};
14
+ for (const row of rows) {
15
+ const cols = row.split("\t");
16
+ if (cols[0] !== "5") {
17
17
  continue;
18
+ }
18
19
  const wordText = cols[11];
19
- if (!wordText)
20
+ if (!wordText) {
20
21
  continue;
22
+ }
21
23
  const confidence = Number(cols[10]);
22
- if (confidence < 40)
24
+ if (confidence < 40) {
23
25
  continue;
24
- words.push({
26
+ }
27
+ const blockNum = cols[2];
28
+ const parNum = cols[3];
29
+ const lineNum = cols[4];
30
+ const key = `${blockNum}-${parNum}-${lineNum}`;
31
+ if (!lineGroups[key]) {
32
+ lineGroups[key] = [];
33
+ }
34
+ lineGroups[key].push({
25
35
  text: wordText,
26
36
  x: Number(cols[6]),
27
37
  y: Number(cols[7]),
@@ -30,18 +40,26 @@ async function findText(text, region) {
30
40
  confidence
31
41
  });
32
42
  }
33
- //console.log(words);
34
- const match = words.find(w => w.text.toLowerCase().includes(text.toLowerCase()));
35
- if (!match) {
36
- return null;
43
+ for (const key in lineGroups) {
44
+ const words = lineGroups[key];
45
+ words.sort((a, b) => a.x - b.x);
46
+ const combinedText = words.map(w => w.text).join(" ");
47
+ if (combinedText.toLowerCase().includes(text.toLowerCase())) {
48
+ const minX = Math.min(...words.map(w => w.x));
49
+ const minY = Math.min(...words.map(w => w.y));
50
+ const maxX = Math.max(...words.map(w => w.x + w.width));
51
+ const maxY = Math.max(...words.map(w => w.y + w.height));
52
+ const avgConfidence = words.reduce((sum, w) => sum + w.confidence, 0) / words.length;
53
+ return {
54
+ x: minX,
55
+ y: minY,
56
+ width: maxX - minX,
57
+ height: maxY - minY,
58
+ confidence: avgConfidence
59
+ };
60
+ }
37
61
  }
38
- return {
39
- x: match.x,
40
- y: match.y,
41
- width: match.width,
42
- height: match.height,
43
- confidence: match.confidence
44
- };
62
+ return null;
45
63
  }
46
64
  async function existsText(text, region) {
47
65
  const match = await findText(text, region);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aspiresys/visor",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {