main.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import organize_drawing_according_to_details_new
  2. import order_bounding_boxes_in_each_block
  3. import clustering_precomputed_dbscan
  4. import read_from_clustered_merged
  5. import regex_clean_new
  6. import organize_drawing_according_to_details_new
  7. import json
  8. import redis
  9. import sys
  10. def write_redis(uuid, result, db_params):
  11. #db = redis.Redis(unix_socket_path='/tmp/redis.sock',db=7)
  12. db = redis.Redis("localhost")
  13. #db = redis.Redis('localhost')
  14. db.set(uuid, result)
  15. def main(uuid, filepath, db, eps):
  16. #db = redis.ConnectionPool(connection_class=redis.UnixDomainSocketConnection, path="/tmp/redis.sock")
  17. #db = redis.Redis(unix_socket_path='/tmp/redis.sock')
  18. #path = "/home/centurio/Projects/engineering_drawings_extraction"
  19. path = "/home/bscheibel/PycharmProjects/engineering_drawings_extraction"
  20. filename = order_bounding_boxes_in_each_block.pdf_to_html(uuid, filepath, path)
  21. #print(filename)
  22. result, number_blocks, number_words= order_bounding_boxes_in_each_block.get_bound_box(filename) ##get coordinates+text out of html file into array of arrays
  23. print("words:" + str(number_words),"blocks:" + str(number_blocks))
  24. if eps == '0':
  25. if number_words > 500:
  26. eps = 7
  27. else:
  28. eps = 1
  29. #print(eps)
  30. isos, general_tol = order_bounding_boxes_in_each_block.extract_isos(result)
  31. print(general_tol)
  32. res = clustering_precomputed_dbscan.cluster_and_preprocess(result,eps, path)
  33. clean_arrays = read_from_clustered_merged.read(path+"/temporary/values_clusteredfrom_precomputed_dbscan.csv")
  34. tables = order_bounding_boxes_in_each_block.get_tables(clean_arrays)
  35. pretty = regex_clean_new.print_clean(clean_arrays)
  36. res, details_dict = organize_drawing_according_to_details_new.main_function(pretty, tables)
  37. #print(res)
  38. json_isos = json.dumps(isos)
  39. json_result = json.dumps(res)
  40. json_details =json.dumps(details_dict)
  41. write_redis(uuid+"tol", general_tol,db)
  42. write_redis(uuid+"dims", json_result, db)
  43. write_redis(uuid+"isos",json_isos, db)
  44. write_redis(uuid+"eps", str(number_blocks)+","+str(number_words), db)
  45. write_redis(uuid+"details",json_details ,db)
  46. #print(json_details)
  47. #print(redis.Redis('localhost').get(uuid+"dims"))
  48. #print(result)
  49. if __name__ == "__main__":
  50. uuid = sys.argv[1]
  51. filename = sys.argv[2]
  52. db = sys.argv[3]
  53. eps = sys.argv[4]
  54. #eps
  55. main(uuid,filename, db, eps)
  56. #main("33333", "/home/centurio/Projects/engineering_drawings_extraction/drawings/5152166_Rev04.pdf", "'/tmp/redis.sock', db=7",3)