Source code for opyenxes.data_in.XUniversalParser

from opyenxes.data_in.XParserRegistry import XParserRegistry


[docs]class XUniversalParser: """This class implements a universal parser, using the parser registry to find an appropriate parser for extracting an XES model from any given file. May be used as a convenience method for applications. """
[docs] @staticmethod def can_parse(file): """Checks whether the given file can be parsed by any parser. :param file: path of the file to check against parser. :type file: str :return: Whether this parser can handle the given file. :rtype: bool """ for parse in XParserRegistry().get_available(): if parse.can_parse(file): return True return False
[docs] @staticmethod def parse(file): """Attempts to parse a collection of XES models from the given file, using all available parsers. :param file: file generated by the function 'open(path)', which is supposed to deliver an XES log in XML representation. :type file: _io.TextIOWrapper :return: The parsed list of logs. :rtype: list[`XLog`] """ for parse in XParserRegistry().get_available(): if parse.can_parse(file.name): try: result = parse.parse(file) return result except Exception as error: print(error) raise Exception("No suitable parser could be found!")