Skip to content
Snippets Groups Projects
Commit 0f3cdfce authored by David Rouquet's avatar David Rouquet
Browse files

Add orginal method to create ontology

parent 20d01ea4
No related branches found
No related tags found
No related merge requests found
...@@ -110,7 +110,7 @@ def __serialize_factoid_graph(config, factoid_graph, out_file_path=None): ...@@ -110,7 +110,7 @@ def __serialize_factoid_graph(config, factoid_graph, out_file_path=None):
#============================================================================== #==============================================================================
# AMR Main Methods (to create an ontology) # AMR Main Methods (to create an ontology) - with one processing
#============================================================================== #==============================================================================
#@timed #@timed
...@@ -168,6 +168,76 @@ def create_ontology_from_amrld_file(amrld_file_path, ...@@ -168,6 +168,76 @@ def create_ontology_from_amrld_file(amrld_file_path,
return ontology_turtle_string return ontology_turtle_string
#@timed
def create_ontology_from_amrld_dir(amrld_dir_path,
base_ontology_path=None,
onto_prefix=None,
out_file_path=None,
technical_dir_path=None):
"""
Method to create an ontology (as Turtle String) from a transduction
analysis of an AMRLD file.
Parameters
----------
amrld_file_path: a path to an AMR-LD Turtle File.
base_ontology_path: a path to a Base Ontology Turtle File if defined.
onto_prefix: the target ontology prefix if defined (if not defined a prefix based on the amrld filename is used).
out_file_path: a file path where the output ontology is written if defined (the function still outputs the string).
technical_dir_path: a dir path where some technical and log files are written if defined.
Returns
-------
Dictionary [filename -> Ontology Turtle String].
Complete Ontology Turtle String (synthesis of all ontology)
"""
logger.info('[TENET] Extraction Processing')
# -- Process Initialization
logger.info('\n === Process Initialization === ')
__set_context()
if onto_prefix is None: onto_prefix = 'DefaultId'
base_output_dir = os.path.dirname(out_file_path) if out_file_path is not None else None
config = __set_config(OWL_CONFIG_FILE_PATH,
'amr', amrld_dir_path, onto_prefix,
base_output_dir, technical_dir_path)
assert os.path.exists(amrld_dir_path), f'input directory does not exists ({amrld_dir_path})'
__count_number_of_graph(config)
# -- Extraction Processing
logger.info('\n === Extraction Processing === ')
sentence_dir = config.source_sentence_file
sentence_count = 0
result_triple_list = []
for sentence_file in glob.glob(sentence_dir, recursive = True):
sentence_count += 1
logger.info(f' *** sentence {sentence_count} *** ')
config.sentence_output_dir = f'-{sentence_count}'
new_triple_list = __apply_extraction(config, sentence_file)
result_triple_list.extend(new_triple_list)
# -- Final Ontology Generation (factoid_graph)
logger.info('\n === Final Ontology Generation === ')
factoid_graph = __generate_final_ontology(result_triple_list)
ontology_turtle_string = __serialize_factoid_graph(config, factoid_graph, out_file_path)
# -- Done
logger.info('\n === Done === ')
if config.technical_dir_path is not None:
log_file_name = 'tenet.log'
dest_file_path = f'{config.technical_dir_path}{log_file_name}'
shutil.copy(log_file_name, dest_file_path)
return ontology_turtle_string
#==============================================================================
# AMR Main Methods (to create an ontology) - Multiprocessing
#==============================================================================
global result_triple_queue global result_triple_queue
global sentence_file_list global sentence_file_list
...@@ -197,7 +267,7 @@ def pool_function(arg_dic): ...@@ -197,7 +267,7 @@ def pool_function(arg_dic):
#@timed #@timed
def create_ontology_from_amrld_dir(amrld_dir_path, def create_ontology_from_amrld_dir_with_multiprocessing(amrld_dir_path,
base_ontology_path=None, base_ontology_path=None,
onto_prefix=None, onto_prefix=None,
out_file_path=None, out_file_path=None,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment