def get_block_relation_features(self, block1: SimpleBlock, block2: SimpleBlock): features = [] # Add block 1 type features.extend([0] * BasicBlockType.block_type_count()) features[block1.get_block_type().get_best_type().id()] = 1 # Add block 2 type features.extend([0] * BasicBlockType.block_type_count()) features[block2.get_block_type().get_best_type().id() + BasicBlockType.block_type_count()] = 1 # Are 2 blocks adjacent features.append(block1.is_adjacent(block2)) # Are 2 blocks separated by 1 row/column features.append(block1.are_blocks_within_x_row_or_column(2, block2)) # Are 2 blocks separated by 4 rows/columns features.append(block1.are_blocks_within_x_row_or_column(5, block2)) # Are 2 blocks horizontal features.append(block1.are_blocks_horizontal(block2)) # Are 2 blocks vertical features.append(block1.are_blocks_vertical(block2)) # Do the blocks have a block in between # cannot compute with this input # TODO: Does the block have any adjacent blocks? Important? return features
def testSimpleBlockFunctions(self): b1 = SimpleBlock(BasicBlockType.HEADER, 0, 1, 0, 0) b2 = SimpleBlock(BasicBlockType.ATTRIBUTE, 0, 0, 1, 3) b3 = SimpleBlock(BasicBlockType.VALUE, 1, 1, 1, 3) b4 = SimpleBlock(BasicBlockType.VALUE, 0, 1, 4, 4) b5 = SimpleBlock(BasicBlockType.VALUE, 2, 3, 1, 1) b6 = SimpleBlock(BasicBlockType.EMPTY, 0, 1, 1, 1) assert b1.is_adjacent(b2) assert b2.is_adjacent(b1) assert b2.is_adjacent(b3) assert b3.is_adjacent(b2) assert b1.is_adjacent(b3) assert b3.is_adjacent(b1) assert b1.is_above(b6) assert not b2.is_above(b3) assert not b3.is_above(b2) assert not b1.is_adjacent(b4) assert not b4.is_adjacent(b1) assert not b1.is_adjacent(b5) assert not b5.is_adjacent(b1)
def split_7_shape(block_a: SimpleBlock, block_b: SimpleBlock): if not block_a.is_adjacent(block_b): return block_a, None, block_b b1, b2, b3 = None, None, None if block_a.right_col == block_b.right_col and block_a.left_col != block_b.left_col: if block_b.is_above(block_a): block_a, block_b = block_b, block_a b1 = SimpleBlock(block_a.block_type, block_a.left_col, block_b.left_col - 1, block_a.top_row, block_a.bottom_row) b2 = SimpleBlock(BlockTypePMF({BasicBlockType.HEADER: 1.0}), block_b.left_col, block_b.right_col, block_a.top_row, block_a.bottom_row) b3 = block_b if block_a.left_col == block_b.left_col and block_a.right_col != block_b.right_col: if block_b.is_above(block_a): block_a, block_b = block_b, block_a b1 = SimpleBlock(block_a.block_type, block_b.right_col + 1, block_a.right_col, block_a.top_row, block_a.bottom_row) b2 = SimpleBlock(BlockTypePMF({BasicBlockType.HEADER: 1.0}), block_b.left_col, block_b.right_col, block_a.top_row, block_a.bottom_row) b3 = block_b if block_a.top_row == block_b.top_row and block_a.bottom_row != block_b.bottom_row: if block_a.bottom_row > block_b.bottom_row: block_a, block_b = block_b, block_a b1 = block_a b2 = SimpleBlock(BlockTypePMF({BasicBlockType.HEADER: 1.0}), block_b.left_col, block_b.right_col, block_a.top_row, block_a.bottom_row) b3 = SimpleBlock(block_b.block_type, block_b.left_col, block_b.right_col, block_a.bottom_row + 1, block_b.bottom_row) return b1, b2, b3