Skip to content
Snippets Groups Projects
Verified Commit 43a23d05 authored by Daniel Hornung's avatar Daniel Hornung
Browse files

ENH: SPSS to cfood has macro for reference properties now.

parent c6b21904
No related branches found
No related tags found
2 merge requests!178FIX: #96 Better error output for crawl.py script.,!171sav/spss converter
Pipeline #51344 passed with warnings
......@@ -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)
......
......
......@@ -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
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment