<commit_before>from subprocess import call
from sys import stderr
from os import path

def image_to_text(image_name, image_dir='uploads'):
    image_path = path.join(image_dir, image_name)
    text_path = path.join('/tmp', image_name)
    call(['tesseract', image_path, text_path], stdout=stderr)
    with open(text_path + '.txt') as t:
        print('Converted %s' % image_path)
        return t.read()

def should_be_period(index,line):
  return (index < len(line)-3 and index > 1 and 
  ord("0") <= ord(line[index-1]) and ord(line[index-1]) <= ord("9") and
  ord("0") <= ord(line[index+1]) and ord(line[index+1]) <= ord("9") and
  ord("0") <= ord(line[index+2]) and ord(line[index+2]) <= ord("9"))


def parse_receipt(image_name):
  receipt_text = image_to_text(image_name)
  receipt_lines = receipt_text.split("\n")
  needed_lines = []
  for line in receipt_lines:
    hasint = False
    haschar = False
    hasperiod = False
    for index in xrange(len(line)):
      if ord(line[index]) == ord("."):
        hasperiod = True
      if should_be_period(index,line):
        line = line[0:index] + "." + line[index+1:]
        hasperiod = True
      elif ord("0") <= ord(line[index]) and ord(line[index]) <= ord("9"):
        hasint = True
      elif (ord("a") <= ord(line[index]) and ord(line[index]) <= ord("z") or
           ord("A") <= ord(line[index]) and ord(line[index]) <= ord("Z")):
        haschar = True<commit_msg>Added Recognition of Switching S with 5<commit_after>from subprocess import call
from sys import stderr
from os import path

def image_to_text(image_name, image_dir='uploads'):
    image_path = path.join(image_dir, image_name)
    text_path = path.join('/tmp', image_name)
    call(['tesseract', image_path, text_path], stdout=stderr)
    with open(text_path + '.txt') as t:
        print('Converted %s' % image_path)
        return t.read()

def should_be_period(index,line):
  return (index < len(line)-2 and index > 1 and 
  ord("0") <= ord(line[index-1]) and ord(line[index-1]) <= ord("9") and
  ord("0") <= ord(line[index+1]) and ord(line[index+1]) <= ord("9"))

def replace_s(index,line):
  if not (ord(line[index]) == ord('s') or ord(line[index]) == ord('S')):
    return False
  if index == len(line)-1:
    return ord("0") <= ord(line[index-1]) and ord(line[index-1]) <= ord("9")
  elif index == 0:
    ord("0") <= ord(line[index+1]) and ord(line[index+1]) <= ord("9")
  else:
    return ((ord("0") <= ord(line[index-1]) and ord(line[index-1]) <= ord("9"))
        or (ord("0") <= ord(line[index+1]) and ord(line[index+1]) <= ord("9")))

def parse_receipt(image_name):
  receipt_text = image_to_text(image_name)
  receipt_lines = receipt_text.split("\n")
  needed_lines = []
  for line in receipt_lines:
    hasint = False
    haschar = False
    hasperiod = False
    for index in xrange(len(line)):
      if ord(line[index]) == ord("."):
        hasperiod = True
      if should_be_period(index,line):
        line = line[0:index] + "." + line[index+1:]
        hasperiod = True
      if replace_s(index,line):
        line = line[0:index] + "5" + line[index+1:]
        hasint = True
      elif ord("0") <= ord(line[index]) and ord(line[index]) <= ord("9"):
        hasint = True
      elif (ord("a") <= ord(line[index]) and ord(line[index]) <= ord("z") or
           ord("A") <= ord(line[index]) and ord(line[index]) <= ord("Z")):
        haschar = True
{'fraction_non_alphanumeric': 0.18326458456098998, 'fraction_numerical': 0.015910430170889805, 'mean_word_length': 3.6443228454172365, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4064796', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1192, 'n_words': 280}