This Python script reads structured CSV files containing cybersecurity techniques, preconditions, and postconditions, then generates a Kumu-compatible JSON blueprint to build a semantic knowledge graph in the Kumu visualization tool.
The graph includes:
- Nodes for Techniques, Preconditions, and Postconditions
- Edges showing:
- Preconditions belonging to Techniques
- Techniques resulting in Postconditions
- Semantic relationships between Postconditions and linked Preconditions
The script requires three specifically formatted CSV files placed in the same directory:
Defines the core techniques with associated preconditions and postconditions.
| Tech ID | Tech Name | List of Precond | List of PostCond |
|---|---|---|---|
| D3-CIA | SomeTech | Precondition A; Precondition B | Postcondition X; Postcondition Y |
Contains a list of preconditions with IDs and descriptions.
| index | precondition |
|---|---|
| D3-CIA-I1 | System must be isolated |
Contains postconditions with linked precondition references.
| index | Postcondition | Matching Preconditions from ChatGPT |
|---|---|---|
| D3-CIA-C1 | Network traffic is encrypted | D3-CIA-I1, D3-CIA-I2 |
π‘ Note:
- Column headers must exactly match the above.
- The
indexcolumn inPrecondition.csvandPostcondition.csvis renamed during processing for clarity.
-
Read and Rename Columns
Loads and normalizes column names across the three CSV files for consistency. -
Map Data
Creates internal mappings:Technique_IDβTechnique_NamePrecondition_IDβPrecondition_DescriptionPostcondition_IDβPostcondition_Description
-
Construct Relationships
- Links preconditions to techniques
- Links techniques to postconditions
- Links postconditions to preconditions (semantic matching)
-
Generate Kumu Elements and Connections
Builds a list ofelementsandconnectionsusing:add_element()for node creationadd_connection()for edge creation with deduplication
-
Export JSON
The final structure is saved as:{ "elements": [...], "connections": [...] }
The script outputs a file named: kumu_graph_complete.json
{
"elements": [
{
"label": "D3-CIA(SomeTech)",
"type": "Technique",
"description": "SomeTech"
},
{
"label": "D3-CIA-I1",
"type": "Postcondition",
"description": "System must be isolated"
},
{
"label": "D3-CIA-C1P",
"type": "Precondition",
"description": "Network traffic is encrypted"
}
],
"connections": [
{
"from": "D3-CIA(SomeTech)",
"to": "D3-CIA-I1",
"type": "is_postcondition_for",
"direction": "directed"
},
{
"from": "D3-CIA-C1P",
"to": "D3-CIA(SomeTech)",
"type": "results_in_postcondition",
"direction": "directed"
},
{
"from": "D3-CIA-I1",
"to": "D3-CIA-C1P",
"type": "semantically_links_to",
"direction": "directed"
}
]
}Run the script from a terminal or notebook: python your_script_name.py
If all files are correctly formatted and available, it will output the JSON file: kumu_graph_complete.json You can now import this file into Kumu under the "Data" β "Import JSON Blueprint" section.
- All labels are validated to avoid duplication or invalid entries.
- Missing condition IDs or mismatches are logged with warnings but skipped to prevent failure.
- Elements are automatically deduplicated.
Ensure you have the following installed: pip install pandas
If using in a Jupyter environment, IPython.display is also required for DataFrame preview.