File size: 5,780 Bytes
5c2cb87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
"""
Generator utilities for creating JSON and Markdown outputs
"""

import json
from datetime import datetime

def generate_json_output(metadata, top_level, processes, generator_version):
    """
    Generate JSON output for the model card
    
    Args:
        metadata: Dictionary of metadata fields
        top_level: Dictionary of top-level elements (Figure 6)
        processes: Dictionary of data & process elements (Figure 7)
        generator_version: Version of the generator
    
    Returns:
        String containing JSON data ready for file download
    """
    output = {
        "df_model_card_metadata": metadata,
        "df_mc_0_top_level": {
            k: v for k, v in top_level.items() 
            if v.get("applicable") and v.get("description")
        },
        "df_mc_1_data_processes": {
            k: v for k, v in processes.items()
            if v.get("applicable") and v.get("description")
        },
        "generated_at": datetime.utcnow().isoformat() + "Z",
        "generator_version": generator_version,
        "schema_version": "1.0"
    }
    
    return json.dumps(output, indent=2)


def generate_markdown_output(metadata, top_level, processes, generator_version):
    """
    Generate Markdown README output for the model card
    
    Args:
        metadata: Dictionary of metadata fields
        top_level: Dictionary of top-level elements (Figure 6)
        processes: Dictionary of data & process elements (Figure 7)
        generator_version: Version of the generator
    
    Returns:
        String containing Markdown content ready for file download
    """
    
    md = []
    
    # Header
    md.append("# Digital Forensics Model Card\n")
    md.append(f"**Generated:** {datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')} UTC\n")
    md.append("---\n")
    
    # Metadata Section
    md.append("## Metadata\n")
    md.append(f"- **Identifier (MMCID):** {metadata.get('mmcid', 'Not specified')}")
    md.append(f"- **Version (MCV):** {metadata.get('version', 'N/A')}")
    md.append(f"- **Owner:** {metadata.get('owner', 'Not specified')}")
    md.append(f"- **Usage Context:** {metadata.get('use_context', 'Not specified')}")
    md.append(f"- **Layer/Stage (Ln):** {metadata.get('layer_n', 'N/A')}\n")
    
    # Case Statement
    if metadata.get('case_statement'):
        md.append("### Case Statement")
        md.append(f"{metadata['case_statement']}\n")
    
    # Hypothesis
    if metadata.get('hypothesis'):
        md.append("### Hypothesis")
        md.append(f"{metadata['hypothesis']}\n")
    
    # Classification
    if metadata.get('classification'):
        md.append("### Classification")
        for item in metadata['classification']:
            md.append(f"- {item}")
        md.append("")
    
    # Reasoning Type
    if metadata.get('reasoning_type'):
        md.append("### Type of Reasoning")
        for item in metadata['reasoning_type']:
            md.append(f"- {item}")
        md.append("")
    
    # Bias
    if metadata.get('bias'):
        md.append("### Identified Bias")
        for item in metadata['bias']:
            md.append(f"- {item}")
        md.append("")
        
        if metadata.get('cause_of_bias'):
            md.append("**Cause(s) of Bias:**")
            for item in metadata['cause_of_bias']:
                md.append(f"- {item}")
            md.append("")
    
    # Error
    if metadata.get('error'):
        md.append("### Error")
        md.append(f"{metadata['error']}\n")
        
        if metadata.get('cause_of_error'):
            md.append("**Cause(s) of Error:**")
            for item in metadata['cause_of_error']:
                md.append(f"- {item}")
            md.append("")
    
    md.append("---\n")
    
    # Top Level Elements (Figure 6)
    md.append("## Top Level Elements (DF MC 0)\n")
    md.append("*Based on Figure 6 - Top Level Elements*\n")
    
    applicable_top_level = {
        k: v for k, v in top_level.items() 
        if v.get("applicable") and v.get("description")
    }
    
    if applicable_top_level:
        for key, value in applicable_top_level.items():
            title = key.replace("_", " ").title()
            md.append(f"### {title}")
            md.append(f"{value['description']}\n")
    else:
        md.append("*No top-level elements specified.*\n")
    
    md.append("---\n")
    
    # Data & Processes (Figure 7)
    md.append("## Data Types and Analytical Processes (DF MC 1)\n")
    md.append("*Based on Figure 7 - DF Data types and analytical processes (Hargreaves et al., 2024)*\n")
    
    applicable_processes = {
        k: v for k, v in processes.items()
        if v.get("applicable") and v.get("description")
    }
    
    if applicable_processes:
        for key, value in applicable_processes.items():
            title = key.replace("_", " ").title()
            md.append(f"### {title}")
            md.append(f"{value['description']}\n")
    else:
        md.append("*No data processes specified.*\n")
    
    md.append("---\n")
    
    # References
    md.append("## References\n")
    md.append("This model card is based on the following works:\n")
    md.append("1. **Di Maio, P.** (2024). Towards Open Standards for Systemic Complexity in Digital Forensics. https://papers.cool/arxiv/2512.12970")
    md.append("2. **Hargreaves, C., Nelson, A., & Casey, E.** (2024). An abstract model for digital forensic analysis tools—A foundation for systematic error mitigation analysis. *Forensic Science International: Digital Investigation*, 48.\n")
    
    # Footer
    md.append("---\n")
    md.append(f"*Generated by [Digital Forensics Model Card Generator](https://huggingface.co/spaces/forensic-model-card-generator) v{generator_version}*")
    
    return "\n".join(md)