# Path: PW_explorer/Input_Parsers/Clingo_Parser/clingo_parser.py
# def parse_clingo_output_from_file(fname, silent=False, print_parse_tree=False):
# 
#     input_stream = FileStream(fname)
#     return __parse_clingo_output__(input_stream, silent, print_parse_tree)
# 
# def parse_clingo_output_from_string(clingo_output_string, silent=False, print_parse_tree=False):
# 
#     input_stream = InputStream(clingo_output_string)
#     return __parse_clingo_output__(input_stream, silent, print_parse_tree)
# 
# Path: PW_explorer/Input_Parsers/DLV_Parser/dlv_parser.py
# def parse_dlv_output_from_file(fname, silent=False, print_parse_tree=False):
#     input_stream = FileStream(fname)
#     return __parse_dlv_output__(input_stream, silent, print_parse_tree)
# 
# def parse_dlv_output_from_string(dlv_output_string, silent=False, print_parse_tree=False):
#     input_stream = InputStream(dlv_output_string)
#     return __parse_dlv_output__(input_stream, silent, print_parse_tree)
# 
# Path: PW_explorer/Input_Parsers/Telingo_Parser/telingo_parser.py
# def parse_telingo_output_from_file(fname, silent=False, print_parse_tree=False):
# 
#     input_stream = FileStream(fname)
#     return __parse_telingo_output__(input_stream, silent, print_parse_tree)
# 
# def parse_telingo_output_from_string(telingo_output_string, silent=False, print_parse_tree=False):
# 
#     input_stream = InputStream(telingo_output_string)
#     return __parse_telingo_output__(input_stream, silent, print_parse_tree)
# 
# Path: PW_explorer/helper.py
# def rel_id_from_rel_name(rel_name, relations):
#     for i, rel in enumerate(relations):
#         if rel.relation_name == rel_name:
#             if i != rel.r_id:
#                 print("Relations not in order")
#             return rel.r_id
#     return None
# 
# def turn_list_into_str(l):
# 
#     if isinstance(l, (list,set,frozenset)):
#         if len(l) > 1:
#             l_ = [turn_list_into_str(l1) for l1 in l[1:]]
#             return "{}({})".format(l[0], ",".join(l_))
#         elif len(l) == 1:
#             return "{}".format(l[0])
#         else:
#             return ""
#     else:
#         return l
# 
# Path: PW_explorer/Input_Parsers/Meta_Data_Parser/meta_data_parser.py
# META_DATA_ATTRIBUTE_DEF_KEYWORD = 'attr_def'
# 
# META_DATA_TEMPORAL_DEC_KEYWORD = 'temporal_dec'


from .Input_Parsers.Clingo_Parser.clingo_parser import (
    parse_clingo_output_from_file,
    parse_clingo_output_from_string,
)
from .Input_Parsers.DLV_Parser.dlv_parser import (
    parse_dlv_output_from_file,
    parse_dlv_output_from_string,
)
from .Input_Parsers.Telingo_Parser.telingo_parser import (
    parse_telingo_output_from_file,
    parse_telingo_output_from_string,
)
from .helper import (
    rel_id_from_rel_name,
    turn_list_into_str,
)
from .Input_Parsers.Meta_Data_Parser.meta_data_parser import (
    META_DATA_ATTRIBUTE_DEF_KEYWORD,
    META_DATA_TEMPORAL_DEC_KEYWORD,
)
import pandas as pd



def parse_solution(data, file_or_string='string', meta_data: dict=None, reasoner='clingo', silent=False,
                   print_parse_tree=False, internal_facts_as_string=True):
    """
    :param data:
    :param file_or_string: If 'file' then 'data' must be a filename, if 'string' then 'data' must be a string.
                           Default: 'string'
    :param meta_data:
    :param reasoner:
    :param silent:
    :param print_parse_tree:
    :param internal_facts_as_string: If true, the facts inside facts are turned into string.
    They are stored as list within lists otherwise. Default: True.
    :return:
    """

    if not meta_data:
        meta_data = {}

    reasoner_parser_map = {}
    # reasoner_output_preprocessor_map = {}

    if file_or_string == 'string':

# Path: PW_explorer/Input_Parsers/Clingo_Parser/clingo_parser.py
# def parse_clingo_output_from_file(fname, silent=False, print_parse_tree=False):
# 
#     input_stream = FileStream(fname)
#     return __parse_clingo_output__(input_stream, silent, print_parse_tree)
# 
# def parse_clingo_output_from_string(clingo_output_string, silent=False, print_parse_tree=False):
# 
#     input_stream = InputStream(clingo_output_string)
#     return __parse_clingo_output__(input_stream, silent, print_parse_tree)
# 
# Path: PW_explorer/Input_Parsers/DLV_Parser/dlv_parser.py
# def parse_dlv_output_from_file(fname, silent=False, print_parse_tree=False):
#     input_stream = FileStream(fname)
#     return __parse_dlv_output__(input_stream, silent, print_parse_tree)
# 
# def parse_dlv_output_from_string(dlv_output_string, silent=False, print_parse_tree=False):
#     input_stream = InputStream(dlv_output_string)
#     return __parse_dlv_output__(input_stream, silent, print_parse_tree)
# 
# Path: PW_explorer/Input_Parsers/Telingo_Parser/telingo_parser.py
# def parse_telingo_output_from_file(fname, silent=False, print_parse_tree=False):
# 
#     input_stream = FileStream(fname)
#     return __parse_telingo_output__(input_stream, silent, print_parse_tree)
# 
# def parse_telingo_output_from_string(telingo_output_string, silent=False, print_parse_tree=False):
# 
#     input_stream = InputStream(telingo_output_string)
#     return __parse_telingo_output__(input_stream, silent, print_parse_tree)
# 
# Path: PW_explorer/helper.py
# def rel_id_from_rel_name(rel_name, relations):
#     for i, rel in enumerate(relations):
#         if rel.relation_name == rel_name:
#             if i != rel.r_id:
#                 print("Relations not in order")
#             return rel.r_id
#     return None
# 
# def turn_list_into_str(l):
# 
#     if isinstance(l, (list,set,frozenset)):
#         if len(l) > 1:
#             l_ = [turn_list_into_str(l1) for l1 in l[1:]]
#             return "{}({})".format(l[0], ",".join(l_))
#         elif len(l) == 1:
#             return "{}".format(l[0])
#         else:
#             return ""
#     else:
#         return l
# 
# Path: PW_explorer/Input_Parsers/Meta_Data_Parser/meta_data_parser.py
# META_DATA_ATTRIBUTE_DEF_KEYWORD = 'attr_def'
# 
# META_DATA_TEMPORAL_DEC_KEYWORD = 'temporal_dec'


# Path: PW_explorer/load_worlds.py
from .Input_Parsers.Clingo_Parser.clingo_parser import (
    parse_clingo_output_from_file,
    parse_clingo_output_from_string,
)
from .Input_Parsers.DLV_Parser.dlv_parser import (
    parse_dlv_output_from_file,
    parse_dlv_output_from_string,
)
from .Input_Parsers.Telingo_Parser.telingo_parser import (
    parse_telingo_output_from_file,
    parse_telingo_output_from_string,
)
from .helper import (
    rel_id_from_rel_name,
    turn_list_into_str,
)
from .Input_Parsers.Meta_Data_Parser.meta_data_parser import (
    META_DATA_ATTRIBUTE_DEF_KEYWORD,
    META_DATA_TEMPORAL_DEC_KEYWORD,
)
import pandas as pd




def parse_solution(data, file_or_string='string', meta_data: dict=None, reasoner='clingo', silent=False,
                   print_parse_tree=False, internal_facts_as_string=True):
    """
    :param data:
    :param file_or_string: If 'file' then 'data' must be a filename, if 'string' then 'data' must be a string.
                           Default: 'string'
    :param meta_data:
    :param reasoner:
    :param silent:
    :param print_parse_tree:
    :param internal_facts_as_string: If true, the facts inside facts are turned into string.
    They are stored as list within lists otherwise. Default: True.
    :return:
    """

    if not meta_data:
        meta_data = {}

    reasoner_parser_map = {}
    # reasoner_output_preprocessor_map = {}

    if file_or_string == 'string':

        reasoner_parser_map = {'clingo': parse_clingo_output_from_string, 'dlv': parse_dlv_output_from_string,