#This script will parse the aircraft characteristic .xlxs file in to a suitable PSOA RuleML code# #Copyright (C) 2018 Theodoros Mitsikas, Sofia Almpani #Licensed under the Non-Profit Open Software License 3.0 (NPOSL-3.0). #You should have received a copy of the Non-Profit Open Software License 3.0 #along with this program. If not, see https://opensource.org/licenses/NPOSL-3.0. import xlrd # available in pip workbook = xlrd.open_workbook('requirements.xlsx') sheet = workbook.sheet_by_index(0) # read header values into the list keys = [sheet.cell(0, col_index).value for col_index in range(sheet.ncols)] # convert the excel in to a list of dictionaries dict_list = [] for row_index in range(2, sheet.nrows): d = {keys[col_index]: sheet.cell(row_index, col_index).value for col_index in range(sheet.ncols)} dict_list.append(d) #print(dict_list) list_of_facts = [] for item in dict_list: oid = item["# PSOA Predicates"] for key in item: if item[key] == oid: pass elif item[key] != '' and item[key] in ["Yes"]: fact = ":" + key + "(:" + oid + " :Checked)" list_of_facts.append(fact) #print(list_of_facts) with open('requirements.psoa', 'w') as fl: # erases previous files print("File requirements.psoa written, overwriting older versions") with open('requirements.psoa', 'a') as fl: for line in list_of_facts: fl.write(line + "\n")