main.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.set(uuid, result)
  13. def main(uuid, filepath, db, eps):
  14. #db = redis.ConnectionPool(connection_class=redis.UnixDomainSocketConnection, path="/tmp/redis.sock")
  15. #db = redis.Redis(unix_socket_path='/tmp/redis.sock')
  16. path = "/home/centurio/Projects/engineering_drawings_extraction"
  17. #path = "/home/bscheibel/PycharmProjects/dxf_reader"
  18. filename = order_bounding_boxes_in_each_block.pdf_to_html(uuid, filepath, path)
  19. #print(filename)
  20. 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
  21. if eps == '0':
  22. if number_words > 500:
  23. eps = 7
  24. else:
  25. eps = 1
  26. #print(eps)
  27. isos, general_tol = order_bounding_boxes_in_each_block.extract_isos(result)
  28. print(general_tol)
  29. res = clustering_precomputed_dbscan.cluster_and_preprocess(result,eps, path)
  30. clean_arrays = read_from_clustered_merged.read(path+"/temporary/values_clusteredfrom_precomputed_dbscan.csv")
  31. tables = order_bounding_boxes_in_each_block.get_tables(clean_arrays)
  32. pretty = regex_clean_new.print_clean(clean_arrays)
  33. res, details_dict = organize_drawing_according_to_details_new.main_function(pretty, tables)
  34. #print(res)
  35. json_isos = json.dumps(isos)
  36. json_result = json.dumps(res)
  37. json_details =json.dumps(details_dict)
  38. write_redis(uuid+"tol", general_tol,db)
  39. write_redis(uuid+"dims", json_result, db)
  40. write_redis(uuid+"isos",json_isos, db)
  41. write_redis(uuid+"eps", str(number_blocks)+","+str(number_words), db)
  42. write_redis(uuid+"details",json_details ,db)
  43. #print(json_details)
  44. #print(redis.Redis('localhost').get(uuid+"dims"))
  45. #print(result)
  46. """#if __name__ == "__main__":
  47. uuid = sys.argv[1]
  48. filename = sys.argv[2]
  49. db = sys.argv[3]
  50. eps = sys.argv[4]
  51. main(uuid,filename, db, eps)"""
  52. main("33333", "/home/centurio/Projects/engineering_drawings_extraction/drawings/5152166_Rev04.pdf", "'/tmp/redis.sock', db=7",3)