Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(predictions): TABLE, CELL & KEY_VALUE_SET blocks are not properly processed #660

Merged
merged 17 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,89 @@ class IdentifyResultTransformers {

}

static func processChildOfKeyValueSet(ids: [String],
blockMap: [String: AWSTextractBlock]) -> String {
var keyText = ""
for keyId in ids {
guard let keyBlock = blockMap[keyId],
let text = keyBlock.text,
case .word = keyBlock.blockType else {
continue
}
keyText += text + " "
}
return keyText.trimmingCharacters(in: .whitespacesAndNewlines)
}

static func processValueOfKeyValueSet(ids: [String],
blockMap: [String: AWSTextractBlock]) -> (String, Bool) {
var valueText = ""
var valueSelected = false

for valueId in ids {
let valueBlock = blockMap[valueId]
guard let valueBlockRelations = valueBlock?.relationships else {
continue
}
for valueBlockRelation in valueBlockRelations {
guard let wordBlockIds = valueBlockRelation.ids else {
break
}
for wordBlockId in wordBlockIds {
let wordBlock = blockMap[wordBlockId]
guard let wordValueBlockType = wordBlock?.blockType else {
continue
}
switch wordValueBlockType {
case .word:
if let text = wordBlock?.text {
valueText += text + " "
}
case .selectionElement:
valueSelected = wordBlock?.selectionStatus == .selected
ruiguoamz marked this conversation as resolved.
Show resolved Hide resolved
default: break
}
}
}
}
return (valueText.trimmingCharacters(in: .whitespacesAndNewlines), valueSelected)
}

static func processLineBlock(block: AWSTextractBlock) -> IdentifiedLine? {
guard let text = block.text,
let boundingBox = processBoundingBox(block.geometry?.boundingBox),
let polygon = processPolygon(block.geometry?.polygon) else {
return nil
}

return IdentifiedLine(text: text,
boundingBox: boundingBox,
polygon: polygon,
page: Int(truncating: block.page ?? 0))
}

static func processWordBlock(block: AWSTextractBlock) -> IdentifiedWord? {
guard let text = block.text,
let boundingBox = processBoundingBox(block.geometry?.boundingBox),
let polygon = processPolygon(block.geometry?.polygon) else {
return nil
}

return IdentifiedWord(text: text,
boundingBox: boundingBox,
polygon: polygon,
page: Int(truncating: block.page ?? 0))
}

static func processSelectionElementBlock(block: AWSTextractBlock) -> Selection? {
guard let boundingBox = processBoundingBox(block.geometry?.boundingBox),
let polygon = processPolygon(block.geometry?.polygon) else {
return nil
}
let selectionStatus = block.selectionStatus == .selected ? true : false
ruiguoamz marked this conversation as resolved.
Show resolved Hide resolved
return Selection(boundingBox: boundingBox, polygon: polygon, isSelected: selectionStatus)
}

ruiguoamz marked this conversation as resolved.
Show resolved Hide resolved
// swiftlint:disable cyclomatic_complexity
static func processLandmarks(_ rekognitionLandmarks: [AWSRekognitionLandmark]?) -> [Landmark] {
var landmarks = [Landmark]()
Expand Down
Loading