main.py 2.1 KB

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