use of com.amazonaws.services.textract.model.Relationship in project amplify-android by aws-amplify.
the class TextractResultTransformers method doForEachRelatedBlock.
private static void doForEachRelatedBlock(Block block, Map<String, Block> blockMap, Consumer<Block> forEach) {
if (block == null || block.getRelationships() == null) {
return;
}
for (Relationship relationship : block.getRelationships()) {
for (String id : relationship.getIds()) {
Block relatedBlock = blockMap.get(id);
if (relatedBlock == null) {
continue;
}
forEach.accept(relatedBlock);
}
}
}
use of com.amazonaws.services.textract.model.Relationship in project amplify-android by aws-amplify.
the class TextractResultTransformersTest method testTableConversion.
/**
* Tests that the graph of related blocks from Textract is properly
* converted to an Amplify table item.
*/
@Test
public void testTableConversion() {
Block cellTextBlock = new Block().withId(RandomString.string()).withText(RandomString.string());
Block cellSelectionBlock = new Block().withId(RandomString.string()).withSelectionStatus(SelectionStatus.SELECTED);
Block cellBlock = new Block().withId(RandomString.string()).withBlockType(BlockType.CELL).withConfidence(random.nextFloat()).withGeometry(randomGeometry()).withRowIndex(random.nextInt()).withColumnIndex(random.nextInt()).withRelationships(new Relationship().withIds(cellTextBlock.getId(), cellSelectionBlock.getId()));
Block tableBlock = new Block().withId(RandomString.string()).withBlockType(BlockType.TABLE).withConfidence(random.nextFloat()).withGeometry(randomGeometry()).withRelationships(new Relationship().withIds(cellBlock.getId()));
// Construct a map to act as a graph
Map<String, Block> blockMap = new HashMap<>();
Observable.fromArray(cellTextBlock, cellSelectionBlock, cellBlock, tableBlock).blockingForEach(block -> blockMap.put(block.getId(), block));
// Test table block conversion
Table table = TextractResultTransformers.fetchTable(tableBlock, blockMap);
assertEquals(1, table.getCells().size());
assertEquals(tableBlock.getConfidence(), table.getConfidence(), DELTA);
assertEquals(1, table.getRowSize());
assertEquals(1, table.getColumnSize());
// Test cell block conversion
Cell cell = table.getCells().iterator().next();
assertEquals(cellTextBlock.getText(), cell.getText());
assertEquals(cellBlock.getConfidence(), cell.getConfidence(), DELTA);
assertTrue(cell.isSelected());
assertEquals(cellBlock.getRowIndex() - 1, cell.getRow());
assertEquals(cellBlock.getColumnIndex() - 1, cell.getColumn());
}
use of com.amazonaws.services.textract.model.Relationship in project aws-doc-sdk-examples by awsdocs.
the class DocumentText method DisplayBlockInfo.
// Displays information from a block returned by text detection and text analysis
private void DisplayBlockInfo(Block block) {
System.out.println("Block Id : " + block.getId());
if (block.getText() != null)
System.out.println(" Detected text: " + block.getText());
System.out.println(" Type: " + block.getBlockType());
if (block.getBlockType().equals("PAGE") != true) {
System.out.println(" Confidence: " + block.getConfidence().toString());
}
if (block.getBlockType().equals("CELL")) {
System.out.println(" Cell information:");
System.out.println(" Column: " + block.getColumnIndex());
System.out.println(" Row: " + block.getRowIndex());
System.out.println(" Column span: " + block.getColumnSpan());
System.out.println(" Row span: " + block.getRowSpan());
}
System.out.println(" Relationships");
List<Relationship> relationships = block.getRelationships();
if (relationships != null) {
for (Relationship relationship : relationships) {
System.out.println(" Type: " + relationship.getType());
System.out.println(" IDs: " + relationship.getIds().toString());
}
} else {
System.out.println(" No related Blocks");
}
System.out.println(" Geometry");
System.out.println(" Bounding Box: " + block.getGeometry().getBoundingBox().toString());
System.out.println(" Polygon: " + block.getGeometry().getPolygon().toString());
List<String> entityTypes = block.getEntityTypes();
System.out.println(" Entity Types");
if (entityTypes != null) {
for (String entityType : entityTypes) {
System.out.println(" Entity Type: " + entityType);
}
} else {
System.out.println(" No entity type");
}
if (block.getPage() != null)
System.out.println(" Page: " + block.getPage());
System.out.println();
}
use of com.amazonaws.services.textract.model.Relationship in project aws-doc-sdk-examples by awsdocs.
the class AnalyzeDocument method DisplayBlockInfo.
// Displays information from a block returned by text detection and text analysis
private void DisplayBlockInfo(Block block) {
System.out.println("Block Id : " + block.getId());
if (block.getText() != null)
System.out.println(" Detected text: " + block.getText());
System.out.println(" Type: " + block.getBlockType());
if (block.getBlockType().equals("PAGE") != true) {
System.out.println(" Confidence: " + block.getConfidence().toString());
}
if (block.getBlockType().equals("CELL")) {
System.out.println(" Cell information:");
System.out.println(" Column: " + block.getColumnIndex());
System.out.println(" Row: " + block.getRowIndex());
System.out.println(" Column span: " + block.getColumnSpan());
System.out.println(" Row span: " + block.getRowSpan());
}
System.out.println(" Relationships");
List<Relationship> relationships = block.getRelationships();
if (relationships != null) {
for (Relationship relationship : relationships) {
System.out.println(" Type: " + relationship.getType());
System.out.println(" IDs: " + relationship.getIds().toString());
}
} else {
System.out.println(" No related Blocks");
}
System.out.println(" Geometry");
System.out.println(" Bounding Box: " + block.getGeometry().getBoundingBox().toString());
System.out.println(" Polygon: " + block.getGeometry().getPolygon().toString());
List<String> entityTypes = block.getEntityTypes();
System.out.println(" Entity Types");
if (entityTypes != null) {
for (String entityType : entityTypes) {
System.out.println(" Entity Type: " + entityType);
}
} else {
System.out.println(" No entity type");
}
if (block.getPage() != null)
System.out.println(" Page: " + block.getPage());
System.out.println();
}
use of com.amazonaws.services.textract.model.Relationship in project amplify-android by aws-amplify.
the class TextractResultTransformersTest method testKeyValueConversion.
/**
* Tests that the graph of related blocks from Textract is properly
* converted to an Amplify key-value pair item.
*/
@Test
public void testKeyValueConversion() {
Block valueTextBlock = new Block().withId(RandomString.string()).withText(RandomString.string());
Block keyTextBlock = new Block().withId(RandomString.string()).withText(RandomString.string());
Block valueBlock = new Block().withId(RandomString.string()).withBlockType(BlockType.KEY_VALUE_SET).withEntityTypes(EntityType.VALUE.toString()).withRelationships(new Relationship().withIds(valueTextBlock.getId()));
Block keyBlock = new Block().withId(RandomString.string()).withBlockType(BlockType.KEY_VALUE_SET).withEntityTypes(EntityType.KEY.toString()).withConfidence(random.nextFloat()).withGeometry(randomGeometry()).withRelationships(new Relationship().withIds(keyTextBlock.getId(), valueBlock.getId()));
// Construct a map to act as a graph
Map<String, Block> blockMap = new HashMap<>();
Observable.fromArray(valueTextBlock, keyTextBlock, valueBlock, keyBlock).blockingForEach(block -> blockMap.put(block.getId(), block));
// Test block conversion
BoundedKeyValue keyValue = TextractResultTransformers.fetchKeyValue(keyBlock, blockMap);
assertEquals(keyTextBlock.getText(), keyValue.getKey());
assertEquals(valueTextBlock.getText(), keyValue.getKeyValue());
assertEquals(keyBlock.getConfidence(), keyValue.getConfidence(), DELTA);
}
Aggregations