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: ...@@ -75,31 +75,49 @@ metadata:
name: ColumnValue name: ColumnValue
params: params:
name: null name: null
belongsto: BaseElement
type: TextElement type: TextElement
parent: MyParent
definition: definition:
${name}: ${name}:
type: ${type} type: ${type}
match_name: ${name} match_name: ^${name}$$
match_value: (?P<val>.*) match_value: (?P<val>.*)
records: records:
${parent}: ${belongsto}:
${name}: $$val ${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 - !defmacro
# Same as "ColumnValue", but also give name of property. # Same as "ColumnValue", but also give name of property.
name: ColumnValuePropname name: ColumnValuePropname
params: params:
name: null name: null
propname: null propname: null
belongsto: BaseElement
type: TextElement type: TextElement
parent: MyParent
definition: definition:
${name}: ${name}:
type: ${type} type: ${type}
match_name: ${name} match_name: ^${name}$$
match_value: (?P<val>.*) match_value: (?P<val>.*)
records: records:
${parent}: ${belongsto}:
${propname}: $$val ${propname}: $$val
--- ---
directory: # corresponds to the directory given to the crawler directory: # corresponds to the directory given to the crawler
...@@ -117,7 +135,6 @@ directory: # corresponds to the directory given to the crawler ...@@ -117,7 +135,6 @@ directory: # corresponds to the directory given to the crawler
records: records:
MyParent: MyParent:
subtree: !macro subtree: !macro
ColumnValue:
""" """
enums: dict[str, list[str]] = {} enums: dict[str, list[str]] = {}
...@@ -185,7 +202,7 @@ DummyRT: ...@@ -185,7 +202,7 @@ DummyRT:
description: Note: Change name and enter description. description: Note: Change name and enter description.
recommended_properties: recommended_properties:
""" """
+ " ".join(yaml.dump(properties, + " ".join(yaml.dump(dict(properties), # from OrderedDict to dict
allow_unicode=True, allow_unicode=True,
sort_keys=False).splitlines(keepends=True))) sort_keys=False).splitlines(keepends=True)))
...@@ -209,22 +226,36 @@ DummyRT: ...@@ -209,22 +226,36 @@ DummyRT:
myfile.write(output) myfile.write(output)
if cfood: if cfood:
defs = [] defs_col_value: list[str] = []
prefix = " " * 12 defs_col_value_ref: list[str] = []
prefix = " " * 14
for name, propdef in properties.items(): for name, propdef in properties.items():
def_str = prefix + f"- name: {name}\n"
dtype = None dtype = None
reftype = None
defs = defs_col_value
# Which type?
if propdef["datatype"] == "DOUBLE": if propdef["datatype"] == "DOUBLE":
dtype = "FloatElement" dtype = "FloatElement"
elif propdef["datatype"] == "TEXT": elif propdef["datatype"] == "TEXT":
dtype = None dtype = None
else: 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: if dtype:
new_def += prefix + f" type: {dtype}\n" def_str += prefix + f" type: {dtype}\n"
defs.append(new_def)
cfood_str += "".join(defs) # 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: with open(cfood, encoding="utf-8", mode="w") as myfile:
myfile.write(cfood_str) myfile.write(cfood_str)
......
...@@ -24,7 +24,6 @@ from pytest import mark ...@@ -24,7 +24,6 @@ from pytest import mark
from caoscrawler.converters import replace_variables from caoscrawler.converters import replace_variables
from caoscrawler.crawl import Crawler from caoscrawler.crawl import Crawler
from caoscrawler.structure_elements import DictElement from caoscrawler.structure_elements import DictElement
from caoscrawler.stores import GeneralStore from caoscrawler.stores import GeneralStore
from caoscrawler.scanner import create_converter_registry, scan_structure_elements 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