Skip to content

Commit 11ed503

Browse files
authored
fix(Predictions): rowIndex and columnIndex for cell (#704)
* Added rowIndex & columnIndex in cell struct, updated integration test * do two more checks for table.cell * Update CHANGELOG.md Added description for rowIndex and columnIndex bug fix * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md
1 parent 8b63b70 commit 11ed503

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

Amplify/Categories/Predictions/Models/Table.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,25 @@ public extension Table {
3232
public let polygon: Polygon
3333

3434
public let isSelected: Bool
35+
public let rowIndex: Int
36+
public let columnIndex: Int
3537
public let rowSpan: Int
3638
public let columnSpan: Int
3739

3840
public init(text: String,
3941
boundingBox: CGRect,
4042
polygon: Polygon,
4143
isSelected: Bool,
44+
rowIndex: Int,
45+
columnIndex: Int,
4246
rowSpan: Int,
4347
columnSpan: Int) {
4448
self.text = text
4549
self.boundingBox = boundingBox
4650
self.polygon = polygon
4751
self.isSelected = isSelected
52+
self.rowIndex = rowIndex
53+
self.columnIndex = columnIndex
4854
self.rowSpan = rowSpan
4955
self.columnSpan = columnSpan
5056
}

AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Utils/IdentifyTextResultTransformers+Tables.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ extension IdentifyTextResultTransformers {
6767
static func constructTableCell(_ block: AWSTextractBlock, _ blockMap: [String: AWSTextractBlock]) -> Table.Cell? {
6868
guard block.blockType == .cell,
6969
let relationships = block.relationships,
70+
let rowIndex = block.rowIndex,
71+
let columnIndex = block.columnIndex,
7072
let rowSpan = block.rowSpan,
7173
let columnSpan = block.columnSpan,
7274
let geometry = block.geometry,
@@ -115,10 +117,12 @@ extension IdentifyTextResultTransformers {
115117
return nil
116118
}
117119

118-
return Table.Cell(text: words,
120+
return Table.Cell(text: words.trimmingCharacters(in: .whitespacesAndNewlines),
119121
boundingBox: boundingBox,
120122
polygon: polygon,
121123
isSelected: isSelected,
124+
rowIndex: Int(truncating: rowIndex),
125+
columnIndex: Int(truncating: columnIndex),
122126
rowSpan: Int(truncating: rowSpan),
123127
columnSpan: Int(truncating: columnSpan))
124128
}

AmplifyPlugins/Predictions/AWSPredictionsPluginIntegrationTests/IdentifyBasicIntegrationTests.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,9 @@ class IdentifyBasicIntegrationTests: AWSPredictionsPluginTestBase {
286286

287287
let completeInvoked = expectation(description: "Completed is invoked")
288288

289-
let operation = Amplify.Predictions.identify(type: .detectText(.table),
290-
image: url,
291-
options: PredictionsIdentifyRequest.Options()) { event in
289+
let operation = Amplify.Predictions.identify(type: .detectText(.table),
290+
image: url,
291+
options: PredictionsIdentifyRequest.Options()) { event in
292292
switch event {
293293
case .success(let result):
294294
guard let data = result as? IdentifyDocumentTextResult else {
@@ -304,6 +304,17 @@ class IdentifyBasicIntegrationTests: AWSPredictionsPluginTestBase {
304304
XCTAssertEqual(data.identifiedLines.count, 3)
305305
XCTAssertFalse(data.tables.isEmpty)
306306
XCTAssertEqual(data.tables.count, 1)
307+
XCTAssertFalse(data.tables[0].cells.isEmpty)
308+
XCTAssertEqual(data.tables[0].cells.count, 3)
309+
XCTAssertEqual(data.tables[0].cells[0].rowIndex, 1)
310+
XCTAssertEqual(data.tables[0].cells[0].columnIndex, 1)
311+
XCTAssertEqual(data.tables[0].cells[0].text, "Upper left")
312+
XCTAssertEqual(data.tables[0].cells[1].rowIndex, 2)
313+
XCTAssertEqual(data.tables[0].cells[1].columnIndex, 2)
314+
XCTAssertEqual(data.tables[0].cells[1].text, "Middle")
315+
XCTAssertEqual(data.tables[0].cells[2].rowIndex, 3)
316+
XCTAssertEqual(data.tables[0].cells[2].columnIndex, 3)
317+
XCTAssertEqual(data.tables[0].cells[2].text, "Bottom right")
307318
completeInvoked.fulfill()
308319
case .failure(let error):
309320
XCTFail("Failed with \(error)")

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Bug Fixes
6+
7+
- **Predictions**: Add rowIndex and columnIndex to Cell struct ([#704](https://github.com/aws-amplify/amplify-ios/pull/704))
8+
39
## 1.0.6 (2020-08-03)
410

511
### Bug Fixes

0 commit comments

Comments
 (0)