diff --git a/Orange/data/io_base.py b/Orange/data/io_base.py index 6b74e72a953..4b0b74e0218 100644 --- a/Orange/data/io_base.py +++ b/Orange/data/io_base.py @@ -169,17 +169,27 @@ def _header1(cls, headers: List[List[str]]) -> Tuple[List, List, List]: e.g. d#sex,c#age,cC#IQ """ - def is_flag(x): - return bool(cls._type_from_flag([x])[0] and - _RE_TYPES.match(cls._type_from_flag([x])[0]) or - Flags.RE_ALL.match(cls._flag_from_flag([x])[0])) - - flags, names = zip(*[i.split(cls.HEADER1_FLAG_SEP, 1) - if cls.HEADER1_FLAG_SEP in i and - is_flag(i.split(cls.HEADER1_FLAG_SEP)[0]) - else ('', i) - for i in headers[0]]) - names = list(names) + roles = "".join([f for f in Flags.ALL.values() if len(f) == 1]) # cimw + types = "".join([t for t in flatten(getattr(vartype, 'TYPE_HEADERS') + for vartype in Variable.registry.values()) + if len(t) == 1]).upper() # CNDST + + res = ('^((?P' + f'[{roles}{types}]|' + f'([{roles}][{types}])|' + f'([{types}][{roles}])' + ')#)?(?P.*)') + + header1_re = re.compile(res) + + flags = [] + names = [] + for i in headers[0]: + m = header1_re.match(i) + f, n = m.group("flags", "name") + flags.append('' if f is None else f) + names.append(n) + return names, cls._type_from_flag(flags), cls._flag_from_flag(flags) @classmethod diff --git a/Orange/data/tests/test_io_base.py b/Orange/data/tests/test_io_base.py index ba272c4d6a0..f0912051deb 100644 --- a/Orange/data/tests/test_io_base.py +++ b/Orange/data/tests/test_io_base.py @@ -70,6 +70,18 @@ def test_get_header_data_1_flags2(self): self.assertListEqual(types, types_) self.assertListEqual(flags, flags_) + def test_get_header_data_1_hashes(self): + names, types, flags = _TableHeader.create_header_data( + [["Some long text#and here", "vd#Invalid spec", "C#Valid spec", + "m#Meta", "cD#Discrete class", "Si#Ignored string"]]) + names_ = ["Some long text#and here", "vd#Invalid spec", "Valid spec", + "Meta", "Discrete class", "Ignored string"] + types_ = ["", "", "c", "", "d", "s"] + flags_ = ["", "", "", "m", "c", "i"] + self.assertListEqual(names, names_) + self.assertListEqual(types, types_) + self.assertListEqual(flags, flags_) + def test_get_header_data_3(self): names, types, flags = _TableHeader.create_header_data(self.header3[:3]) self.assertListEqual(names, ["a", "b", "c", "d", "w", "e", "f", "g"]) diff --git a/i18n/si/msgs.jaml b/i18n/si/msgs.jaml index c8d819fe7ff..c95d30fe77f 100644 --- a/i18n/si/msgs.jaml +++ b/i18n/si/msgs.jaml @@ -1155,6 +1155,15 @@ data/io_base.py: ^\s*( |{}|)*\s*$: false class `_TableHeader`: '#': false + def `_header1`: + TYPE_HEADERS: false + ^((?P: false + [{roles}{types}]|: false + ([{roles}][{types}])|: false + ([{types}][{roles}]): false + )#)?(?P.*): false + flags: false + name: false class `_TableBuilder`: def `__init__`: 'Feature ': false