def detect_paragraph_type(txt):
 txt = txt.replace('\r\n', '\n')
 txt = txt.replace('\r', '\n')
 txt_line_count = len(re.findall('(?mu)^\\s*.+$', txt))
 docanalysis = DocAnalysis('txt', txt)
 hardbreaks = docanalysis.line_histogram(0.55)
 if hardbreaks:
  tab_line_count = len(re.findall('(?mu)^( DCTB |\\s{2,}).+$', txt))
  print_percent = (tab_line_count / float(txt_line_count))
  empty_line_count = len(re.findall('(?mu)^\\s*$', txt))
  block_percent = (empty_line_count / float(txt_line_count))
  if (print_percent >= block_percent):
   if (0.15 <= print_percent <= 0.75):
    return 'print'
  elif (0.15 <= block_percent <= 0.75):
   return 'block'
  return 'unformatted'
 return 'single'

def detect_paragraph_type ( txt ) : txt = txt . replace ( '\r\n' , '\n' ) txt = txt . replace ( '\r' , '\n' ) txt_line_count = len ( re . findall ( '(?mu)^\\s*.+$' , txt ) ) docanalysis = DocAnalysis ( 'txt' , txt ) hardbreaks = docanalysis . line_histogram ( 0.55 ) if hardbreaks : tab_line_count = len ( re . findall ( '(?mu)^( DCTB |\\s{2,}).+$' , txt ) ) print_percent = ( tab_line_count / float ( txt_line_count ) ) empty_line_count = len ( re . findall ( '(?mu)^\\s*$' , txt ) ) block_percent = ( empty_line_count / float ( txt_line_count ) ) if ( print_percent >= block_percent ) : if ( 0.15 <= print_percent <= 0.75 ) : return 'print' elif ( 0.15 <= block_percent <= 0.75 ) : return 'block' return 'unformatted' return 'single'
tries to determine the paragraph type of the document .