Skip to content

Commit

Permalink
fix(Predictions): rowIndex and columnIndex for cell (#704)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ruiguoamz authored Aug 11, 2020
1 parent 8b63b70 commit 11ed503
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Amplify/Categories/Predictions/Models/Table.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,25 @@ public extension Table {
public let polygon: Polygon

public let isSelected: Bool
public let rowIndex: Int
public let columnIndex: Int
public let rowSpan: Int
public let columnSpan: Int

public init(text: String,
boundingBox: CGRect,
polygon: Polygon,
isSelected: Bool,
rowIndex: Int,
columnIndex: Int,
rowSpan: Int,
columnSpan: Int) {
self.text = text
self.boundingBox = boundingBox
self.polygon = polygon
self.isSelected = isSelected
self.rowIndex = rowIndex
self.columnIndex = columnIndex
self.rowSpan = rowSpan
self.columnSpan = columnSpan
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ extension IdentifyTextResultTransformers {
static func constructTableCell(_ block: AWSTextractBlock, _ blockMap: [String: AWSTextractBlock]) -> Table.Cell? {
guard block.blockType == .cell,
let relationships = block.relationships,
let rowIndex = block.rowIndex,
let columnIndex = block.columnIndex,
let rowSpan = block.rowSpan,
let columnSpan = block.columnSpan,
let geometry = block.geometry,
Expand Down Expand Up @@ -115,10 +117,12 @@ extension IdentifyTextResultTransformers {
return nil
}

return Table.Cell(text: words,
return Table.Cell(text: words.trimmingCharacters(in: .whitespacesAndNewlines),
boundingBox: boundingBox,
polygon: polygon,
isSelected: isSelected,
rowIndex: Int(truncating: rowIndex),
columnIndex: Int(truncating: columnIndex),
rowSpan: Int(truncating: rowSpan),
columnSpan: Int(truncating: columnSpan))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ class IdentifyBasicIntegrationTests: AWSPredictionsPluginTestBase {

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

let operation = Amplify.Predictions.identify(type: .detectText(.table),
image: url,
options: PredictionsIdentifyRequest.Options()) { event in
let operation = Amplify.Predictions.identify(type: .detectText(.table),
image: url,
options: PredictionsIdentifyRequest.Options()) { event in
switch event {
case .success(let result):
guard let data = result as? IdentifyDocumentTextResult else {
Expand All @@ -304,6 +304,17 @@ class IdentifyBasicIntegrationTests: AWSPredictionsPluginTestBase {
XCTAssertEqual(data.identifiedLines.count, 3)
XCTAssertFalse(data.tables.isEmpty)
XCTAssertEqual(data.tables.count, 1)
XCTAssertFalse(data.tables[0].cells.isEmpty)
XCTAssertEqual(data.tables[0].cells.count, 3)
XCTAssertEqual(data.tables[0].cells[0].rowIndex, 1)
XCTAssertEqual(data.tables[0].cells[0].columnIndex, 1)
XCTAssertEqual(data.tables[0].cells[0].text, "Upper left")
XCTAssertEqual(data.tables[0].cells[1].rowIndex, 2)
XCTAssertEqual(data.tables[0].cells[1].columnIndex, 2)
XCTAssertEqual(data.tables[0].cells[1].text, "Middle")
XCTAssertEqual(data.tables[0].cells[2].rowIndex, 3)
XCTAssertEqual(data.tables[0].cells[2].columnIndex, 3)
XCTAssertEqual(data.tables[0].cells[2].text, "Bottom right")
completeInvoked.fulfill()
case .failure(let error):
XCTFail("Failed with \(error)")
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Bug Fixes

- **Predictions**: Add rowIndex and columnIndex to Cell struct ([#704](https://github.com/aws-amplify/amplify-ios/pull/704))

## 1.0.6 (2020-08-03)

### Bug Fixes
Expand Down

0 comments on commit 11ed503

Please sign in to comment.