diff --git a/src/caoscrawler/conv_impl/spss.py b/src/caoscrawler/conv_impl/spss.py index 1643dfc8d4ff9bde73855c072b929840e7a83a1b..2b11ebe080cf6fa0adf1fec23df6399a0f3bc2a0 100644 --- a/src/caoscrawler/conv_impl/spss.py +++ b/src/caoscrawler/conv_impl/spss.py @@ -75,31 +75,49 @@ metadata: name: ColumnValue params: name: null + belongsto: BaseElement type: TextElement - parent: MyParent definition: ${name}: type: ${type} - match_name: ${name} + match_name: ^${name}$$ match_value: (?P<val>.*) records: - ${parent}: + ${belongsto}: ${name}: $$val + - !defmacro + # column value -> reference property + name: ColumnValueReference + params: + name: null + reftype: null # RecordType of the reference + belongsto: BaseElement + type: TextElement # References are always text, right? + definition: + ${name}: + type: ${type} + match_name: ^${name}$$ + match_value: (?P<val>.*) + records: + ${reftype}: + name: $$val + ${belongsto}: + ${name}: $$${reftype} - !defmacro # Same as "ColumnValue", but also give name of property. name: ColumnValuePropname params: name: null propname: null + belongsto: BaseElement type: TextElement - parent: MyParent definition: ${name}: type: ${type} - match_name: ${name} + match_name: ^${name}$$ match_value: (?P<val>.*) records: - ${parent}: + ${belongsto}: ${propname}: $$val --- directory: # corresponds to the directory given to the crawler @@ -117,7 +135,6 @@ directory: # corresponds to the directory given to the crawler records: MyParent: subtree: !macro - ColumnValue: """ enums: dict[str, list[str]] = {} @@ -185,7 +202,7 @@ DummyRT: description: Note: Change name and enter description. recommended_properties: """ - + " ".join(yaml.dump(properties, + + " ".join(yaml.dump(dict(properties), # from OrderedDict to dict allow_unicode=True, sort_keys=False).splitlines(keepends=True))) @@ -209,22 +226,36 @@ DummyRT: myfile.write(output) if cfood: - defs = [] - prefix = " " * 12 + defs_col_value: list[str] = [] + defs_col_value_ref: list[str] = [] + prefix = " " * 14 for name, propdef in properties.items(): + def_str = prefix + f"- name: {name}\n" dtype = None + reftype = None + defs = defs_col_value + # Which type? if propdef["datatype"] == "DOUBLE": dtype = "FloatElement" elif propdef["datatype"] == "TEXT": dtype = None else: - dtype = propdef["datatype"] + reftype = propdef["datatype"] + defs = defs_col_value_ref - new_def = prefix + f"- name: {name}\n" + # Append according to types: + if reftype: + def_str += prefix + f" reftype: {reftype}\n" if dtype: - new_def += prefix + f" type: {dtype}\n" - defs.append(new_def) - cfood_str += "".join(defs) + def_str += prefix + f" type: {dtype}\n" + + # Store result + defs.append(def_str) + del defs + + cfood_str += (prefix[2:] + "ColumnValue:\n" + "".join(defs_col_value) + + prefix[2:] + "ColumnValueReference:\n" + "".join(defs_col_value_ref) + ) with open(cfood, encoding="utf-8", mode="w") as myfile: myfile.write(cfood_str) diff --git a/unittests/test_issues.py b/unittests/test_issues.py index f123fb822c8cbc8d4bef14c3e6f9671a7aa429db..5e7685f5c2d1e08829d28afcc612a5c07eb585aa 100644 --- a/unittests/test_issues.py +++ b/unittests/test_issues.py @@ -24,7 +24,6 @@ from pytest import mark from caoscrawler.converters import replace_variables from caoscrawler.crawl import Crawler - from caoscrawler.structure_elements import DictElement from caoscrawler.stores import GeneralStore from caoscrawler.scanner import create_converter_registry, scan_structure_elements