main.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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(db_params)
  12. db.set(uuid, result)
  13. def main(uuid, filepath, db, eps):
  14. filename = order_bounding_boxes_in_each_block.pdf_to_html(uuid, filepath)
  15. #print(filename)
  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. if eps == '0':
  18. if number_words > 500:
  19. eps = 7
  20. else:
  21. eps = 1
  22. #print(eps)
  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)
  26. clean_arrays = read_from_clustered_merged.read("/home/bscheibel/PycharmProjects/dxf_reader/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. #print(res)
  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. #print(json_details)
  40. #print(redis.Redis('localhost').get(uuid+"dims"))
  41. #print(result)
  42. if __name__ == "__main__":
  43. uuid = sys.argv[1]
  44. filename = sys.argv[2]
  45. db = sys.argv[3]
  46. eps = sys.argv[4]
  47. main(uuid,filename, db, eps)
  48. #main("33333", "/home/bscheibel/PycharmProjects/dxf_reader/drawings/5152166_Rev04.pdf", "localhost",3)