main.py~ 2.1 KB

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