40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
"""从 35 form baseline 提取所有 inputNumber 控件的 formData 真实样本.
|
|
inputNumber 控件判定: __config__.jnpfKey == 'inputNumber'.
|
|
含子表 (递归 children 字段) — Task 1.4 发现 inputNumber 仅在子表出现一次.
|
|
"""
|
|
import json, glob, os
|
|
|
|
OUT = "scripts/inputNumber-baseline-samples.jsonl"
|
|
samples = []
|
|
|
|
def walk(fields, source):
|
|
for f in fields:
|
|
if not isinstance(f, dict):
|
|
continue
|
|
cfg = f.get('__config__', {})
|
|
if isinstance(cfg, dict) and cfg.get('jnpfKey') == 'inputNumber':
|
|
samples.append({
|
|
"source": source,
|
|
"label": cfg.get('label'),
|
|
"formData": f
|
|
})
|
|
# 递归子表 children
|
|
children = cfg.get('children', []) if isinstance(cfg, dict) else []
|
|
if isinstance(children, list) and children:
|
|
walk(children, source)
|
|
|
|
for path in glob.glob("/home/ubuntu/ccWorkDir/baseline/*/form/*.json"):
|
|
try:
|
|
d = json.load(open(path))['data']
|
|
fd = json.loads(d['formData']) if isinstance(d.get('formData'), str) else {}
|
|
walk(fd.get('fields', []), os.path.basename(path))
|
|
except Exception as e:
|
|
pass
|
|
|
|
with open(OUT, 'w') as out:
|
|
for s in samples:
|
|
out.write(json.dumps(s, ensure_ascii=False) + "\n")
|
|
|
|
print(f"Extracted {len(samples)} inputNumber 控件 samples to {OUT}")
|