code: def simple_line_detection(
      layout: Iterable[BaseLayoutElement],
      x_tolerance: int = 10,
      y_tolerance: int = 10,
  ) -> List[BaseLayoutElement]:
      """Perform line detection based on connected component analysis.
  
      The is_line_wise_close is the scoring function, which returns True
      if the y-difference is smaller than the y_tolerance AND the
      x-difference (the horizontal gap between two boxes) is also smaller
      than the x_tolerance, and False otherwise.
  
      All the detected components will then be passed into aggregation_func,
      which returns the overall union box of all the elements, or the line
      box.
  
      Args:
          layout (Iterable):
              A list (or Layout) of BaseLayoutElement
          x_tolerance (int, optional):
              The value used for specifying the maximum allowed y-difference
              when considered whether two tokens are from the same line.
              Defaults to 10.
          y_tolerance (int, optional):
              The value used for specifying the maximum allowed horizontal gap
              when considered whether two tokens are from the same line.
              Defaults to 10.
  
      Returns:
          List[BaseLayoutElement]: A list of BaseLayoutElement, denoting the line boxes.
      """
  
      def is_line_wise_close(
          token_a, token_b, x_tolerance, y_tolerance
      ):
          y_a = token_a.block.center[1]
          y_b = token_b.block.center[1]
  
          a_left, a_right = token_a.block.coordinates[0::2]
          b_left, b_right = token_b.block.coordinates[0::2]
  
          return (
              abs(y_a - y_b) <= y_tolerance
              and min(abs(a_left - b_right), abs(a_right - b_left))
              <= x_tolerance
          )
          # If the y-difference is smaller than the y_tolerance AND
          # the x-difference (the horizontal gap between two boxes)
          # is also smaller than the x_tolerance threshold, then
          # these two tokens are considered as line-wise close.
  
      detected_lines = generalized_connected_component_analysis_1d(
          layout,
          scoring_func=partial(
              is_line_wise_close,
              y_tolerance=x_tolerance,
              x_tolerance=y_tolerance,
          ),
          aggregation_func=lambda seq: reduce(
              layout[0].__class__.union, seq
          ),
      )
  
      return detected_lines
  
file_path: layout-parser/src/layoutparser/tools/shape_operations.py
imports: from typing import List, Union, Any, Callable, Iterable
  from functools import partial, reduce
  import numpy
  from scipy.sparse import csr_matrix
  from scipy.sparse.csgraph import connected_components
  from ..elements import BaseLayoutElement, TextBlock
label_desc: Use image node_id 2 for calling a global function with example usage: simple_line_detection(layout, x_tolerance, y_tolerance) and returns: detected_lines, unknown