Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def make_ontology_from_local_file(file_name: str):
print("Creating ontology from file: " + file_name)
return ontobio.ontol_factory.OntologyFactory().create(file_name)
cp = subprocess.run(['owltools', file_name, '-o', '-f', 'json', temp_file_name])
# robot commented out because it is giving a NullPointerException on umls_semantictypes.owl
# cp = subprocess.run(['robot', 'convert', '--input', file_name, '--output', temp_file_name])
if cp.stdout is not None:
log_message(message="OWL convert result: " + cp.stdout, ontology_name=None, output_stream=sys.stdout)
if cp.stderr is not None:
log_message(message="OWL convert result: " + cp.stderr, ontology_name=None, output_stream=sys.stderr)
assert cp.returncode == 0
json_file = file_name_without_ext + ".json"
shutil.move(temp_file_name, json_file)
size = os.path.getsize(json_file)
log_message(message="Reading ontology JSON file: " + json_file + "; size: " + "{0:.2f}".format(size/1024) + " KiB",
ontology_name=None)
# if not USE_ONTOBIO_JSON_CACHE:
# delete_ontobio_cache_json(file_name)
ont_return = ontobio.ontol_factory.OntologyFactory().create(json_file, ignore_cache=True)
else:
size = os.path.getsize(file_name_with_pickle_ext)
log_message("Reading ontology file: " + file_name_with_pickle_ext + "; size: " + "{0:.2f}".format(size/1024) + " KiB", ontology_name=None)
ont_return = pickle.load(open(file_name_with_pickle_ext, "rb"))
return ont_return
# Once robot no longer gives a NullPointerException, we can use it like this:
# cp = subprocess.run(['robot', 'convert', '--input', file_name, '--output', temp_file_name])
if cp.stdout is not None:
kg2_util.log_message(message="OWL convert result: " + cp.stdout, ontology_name=None, output_stream=sys.stdout)
if cp.stderr is not None:
kg2_util.log_message(message="OWL convert result: " + cp.stderr, ontology_name=None, output_stream=sys.stderr)
assert cp.returncode == 0
json_file = file_name_without_ext + ".json"
shutil.move(temp_file_name, json_file)
else:
json_file = file_name
size = os.path.getsize(json_file)
kg2_util.log_message(message="Reading ontology JSON file: " + json_file + "; size: " + "{0:.2f}".format(size/1024) + " KiB",
ontology_name=None)
ont_return = ontobio.ontol_factory.OntologyFactory().create(json_file, ignore_cache=True)
else:
size = os.path.getsize(file_name_with_pickle_ext)
kg2_util.log_message("Reading ontology file: " + file_name_with_pickle_ext + "; size: " + "{0:.2f}".format(size/1024) + " KiB", ontology_name=None)
ont_return = pickle.load(open(file_name_with_pickle_ext, "rb"))
return ont_return
# Once robot no longer gives a NullPointerException, we can use it like this:
# cp = subprocess.run(['robot', 'convert', '--input', file_name, '--output', temp_file_name])
if cp.stdout is not None:
kg2_util.log_message(message="OWL convert result: " + cp.stdout, ontology_name=None, output_stream=sys.stdout)
if cp.stderr is not None:
kg2_util.log_message(message="OWL convert result: " + cp.stderr, ontology_name=None, output_stream=sys.stderr)
assert cp.returncode == 0
json_file = file_name_without_ext + ".json"
shutil.move(temp_file_name, json_file)
else:
json_file = file_name
size = os.path.getsize(json_file)
kg2_util.log_message(message="Reading ontology JSON file: " + json_file + "; size: " + "{0:.2f}".format(size/1024) + " KiB",
ontology_name=None)
ont_return = ontobio.ontol_factory.OntologyFactory().create(json_file, ignore_cache=True)
else:
size = os.path.getsize(file_name_with_pickle_ext)
kg2_util.log_message("Reading ontology file: " + file_name_with_pickle_ext + "; size: " + "{0:.2f}".format(size/1024) + " KiB", ontology_name=None)
ont_return = pickle.load(open(file_name_with_pickle_ext, "rb"))
return ont_return