def parse_attributes()

in modules/python/src/datapreprocessing/datacleaner.py [0:0]


    def parse_attributes(self, specification: str) -> str:
        """
        Parses product specifications from a string into a JSON string.

        Args:
            specification (str): A string containing the product specifications.

        Returns:
            str: A JSON string representing the parsed attributes, or None if the input is invalid or NaN.
        """
        spec_match_one = re.compile("(.*?)\\[(.*)\\](.*)")
        spec_match_two = re.compile('(.*?)=>"(.*?)"(.*?)=>"(.*?)"(.*)')
        if pd.isna(specification):
            return None
        m = spec_match_one.match(specification)
        out = {}
        if m is not None and m.group(2) is not None:
            phrase = ""
            for c in m.group(2):
                if c == "}":
                    m2 = spec_match_two.match(phrase)
                    if m2 and m2.group(2) is not None and m2.group(4) is not None:
                        out[m2.group(2)] = m2.group(4)
                    phrase = ""
                else:
                    phrase += c
        json_string = jsonpickle.encode(out)
        return json_string