main.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 = order_bounding_boxes_in_each_block.extract_isos(result)
  24. res = clustering_precomputed_dbscan.cluster_and_preprocess(result,eps)
  25. clean_arrays = read_from_clustered_merged.read("/home/bscheibel/PycharmProjects/dxf_reader/temporary/values_clusteredfrom_precomputed_dbscan.csv")
  26. tables = order_bounding_boxes_in_each_block.get_tables(clean_arrays)
  27. pretty = regex_clean_new.print_clean(clean_arrays)
  28. res, details_dict = organize_drawing_according_to_details_new.main_function(pretty, tables)
  29. #print(res)
  30. json_isos = json.dumps(isos)
  31. json_result = json.dumps(res)
  32. json_details =json.dumps(details_dict)
  33. write_redis(uuid+"dims", json_result, db)
  34. write_redis(uuid+"isos",json_isos, db)
  35. write_redis(uuid+"eps", str(number_blocks)+","+str(number_words), db)
  36. write_redis(uuid+"details",json_details ,db)
  37. #print(json_details)
  38. #print(redis.Redis('localhost').get(uuid+"dims"))
  39. #print(result)
  40. if __name__ == "__main__":
  41. uuid = sys.argv[1]
  42. filename = sys.argv[2]
  43. db = sys.argv[3]
  44. eps = sys.argv[4]
  45. main(uuid,filename, db, eps)
  46. #main("33333", "/home/bscheibel/PycharmProjects/dxf_reader/drawings/5152166_Rev04.pdf", "localhost",3)