import sys

# open the file generated by clingo with occurs'() predicates
# transforms the file into an array where each element is one occurs'() predicate
# occurs'() predicates will always be in the fifth line of the file and be seperated by a space
def read_occurs(path):
    with open(path, 'r') as file:
        for i, line in enumerate(file):
            if i == 4:
                return line.split()

# transform each occurs'() predicate
# the apostrophe will be removed
# a full stop will be added to the end of each element
def transform_occurs(array):
    for i in range(0, len(array)):
        array[i] = array[i][:6] + array[i][7:]
        array[i] = array[i] + '.'
    return array

# create a new file with the transformed occurs() predicates
# generate occurs() array through transform_occurs and read_occurs
# put each occurs() predicate into a new line
def create_plan(path):
    array = transform_occurs(read_occurs(path))
    with open('plan.lp', 'w') as file:
        for occur in array:
            file.write(occur + '\n')

create_plan(str(sys.argv[1]))
