def preprocess_clif_file(self): # add the standard ending for CLIF files to the module name self.clif_file_name = filemgt.get_full_path(self.module_name, ending=filemgt.read_config( 'cl', 'ending')) #print self.clif_file_name self.clif_processed_file_name = filemgt.get_full_path( self.module_name, folder=filemgt.read_config('converters', 'tempfolder'), ending=filemgt.read_config('cl', 'ending')) logging.getLogger(__name__).debug("Clif file name = " + self.clif_file_name) logging.getLogger(__name__).debug("Clif preprocessed file name = " + self.clif_processed_file_name) clif.remove_all_comments(self.clif_file_name, self.clif_processed_file_name) self.imports = clif.get_imports(self.clif_processed_file_name) logging.getLogger(__name__).debug("imports detected in " + self.module_name + ": " + str(self.imports)) self.nonlogical_symbols = clif.get_all_nonlogical_symbols( self.clif_processed_file_name)
def get_lemma_files_from_sentences(lemmas_name, sentences): sentences_files = [] sentences_names = [] import math # determine maximal number of digits digits = int(math.ceil(math.log10(len(sentences)))) i = 1 for lemma in sentences: name = lemmas_name + '_goal' + ('{0:0' + str(digits) + 'd}').format(i) filename = filemgt.get_full_path( name, folder=filemgt.read_config('ladr', 'folder'), ending=filemgt.read_config('ladr', 'ending')) output_file = open(filename, 'w') output_file.write('formulas(goals).\n') output_file.write(lemma + '\n') output_file.write('end_of_list.\n') output_file.close() sentences_files.append(filename) sentences_names.append(name) i += 1 return (sentences_names, sentences_files)
def convert_single_clif_file(ontology, output, resolve, loc=default_dir, prefix=default_prefix): logging.getLogger(__name__).info("Converting " + ontology.name + " to " + output + " format") if (output == tptp_output): results = ontology.to_tptp(resolve) elif (output == ladr_output): results = ontology.to_ladr(resolve) # the following assumes that the names of the configuration sections are the same as the names of the output (tptp/ladr) if resolve: ending = Filemgt.read_config(output, 'all_ending') else: ending = "" ending = ending + Filemgt.read_config(output, 'ending') output_file_name = Filemgt.get_full_path(ontology.name, folder=Filemgt.read_config( 'tptp', 'folder'), ending=ending) #ontology.get_all_modules() with open(output_file_name, "w") as f: for sentence in results: print(sentence) f.write(sentence + "\n") f.close() return output_file_name
def get_p9_file_name(self): """get the filename of the LADR translation of the module and translate the ClifModule if not yet done so.""" if not self.p9_file_name: # do the translation self.p9_file_name = filemgt.get_full_path( self.module_name, folder=filemgt.read_config('ladr', 'folder'), ending=filemgt.read_config('ladr', 'ending')) self.get_translated_file(self.p9_file_name, "LADR") logging.getLogger(__name__).info("CREATED LADR TRANSLATION: " + self.p9_file_name) return self.p9_file_name
def get_tptp_file_name(self): """get the filename of the TPTP translation of the module and translate the ClifModule if not yet done so. This version does not rely on the clif to ladr translation, but does a direct translation.""" if not self.tptp_file_name: self.tptp_file_name = filemgt.get_full_path( self.module_name, folder=filemgt.read_config('tptp', 'folder'), ending=filemgt.read_config('tptp', 'ending')) self.get_translated_file(self.tptp_file_name, "TPTP") logging.getLogger(__name__).info("CREATED TPTP TRANSLATION: " + self.tptp_file_name) return self.tptp_file_name
def get_output_filename(ontology, resolve, output_type): # the following assumes that the names of the configuration sections # are the same as the names of the output (tptp/ladr/owl) if resolve: ending = Filemgt.read_config(output_type, 'all_ending') else: ending = "" ending = ending + Filemgt.read_config(output_type, 'ending') output_filename = Filemgt.get_full_path(ontology.name, folder=Filemgt.read_config(output_type,'folder'), ending=ending) return output_filename
def run_module_consistency_check(self, module): """check a single module for consistency.""" outfile_stem = filemgt.get_full_path(module.module_name, folder=filemgt.read_config( 'output', 'folder')) reasoners = ReasonerSet() reasoners.constructAllCommands([module]) logging.getLogger(__name__).info("USING " + str(len(reasoners)) + " REASONERS: " + str([r.name for r in reasoners])) # run provers and modelfinders simultaneously and wait until one returns reasoners = process.raceProcesses(reasoners) (return_value, _) = self.consolidate_results(reasoners) self.pretty_print_result(module.module_name, return_value) return return_value
def constructCommand(self, ontology): import os """Return the command (includes constructing it if necessary) to invoke the reasoner.""" self.args = commands.get_system_command(self.name, ontology) ending = None if ontology.resolve: ending = Filemgt.read_config(self.name, 'all_ending') if ending is None: ending = "" ending = ending + Filemgt.read_config(self.name, 'ending') self.output_file = Filemgt.get_full_path(ontology.name, folder=Filemgt.read_config( 'output', 'folder'), ending=ending) self.ontology = ontology logging.getLogger(__name__).debug('Reasoner command: ' + str(self.args)) return self.args