{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://example.org/cascade_package.schema.json",
  "title": "Cascade package, spec version 0.1",
  "description": "Record definitions for the output of an adapter. Each file of a package is validated against one of the definitions in $defs: events.jsonl against event, entities.jsonl against entity, entity_relations.jsonl against entity_relation, links.jsonl against link, omitted.jsonl against omitted, manifest.json against manifest.",
  "$defs": {
    "id": {
      "type": "string",
      "minLength": 1
    },
    "isoTimeUtc": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$"
    },
    "sourceId": {
      "type": "object",
      "required": [
        "source",
        "id"
      ],
      "properties": {
        "source": {
          "$ref": "#/$defs/id"
        },
        "id": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false
    },
    "unit01": {
      "type": [
        "number",
        "null"
      ],
      "minimum": 0,
      "maximum": 1
    },
    "precision": {
      "enum": [
        "second",
        "minute",
        "hour",
        "day",
        "month",
        "year"
      ]
    },
    "time": {
      "type": "object",
      "required": [
        "start",
        "precision",
        "basis"
      ],
      "properties": {
        "start": {
          "$ref": "#/$defs/isoTimeUtc"
        },
        "end": {
          "oneOf": [
            {
              "$ref": "#/$defs/isoTimeUtc"
            },
            {
              "type": "null"
            }
          ]
        },
        "precision": {
          "$ref": "#/$defs/precision"
        },
        "basis": {
          "enum": [
            "recorded",
            "derived",
            "imputed"
          ]
        }
      },
      "additionalProperties": false
    },
    "eventProvenance": {
      "type": "object",
      "required": [
        "source_ids"
      ],
      "properties": {
        "source_ids": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/sourceId"
          }
        },
        "extraction": {
          "type": "object",
          "properties": {
            "method": {
              "type": "string"
            },
            "rule_ids": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/id"
              }
            }
          },
          "additionalProperties": false
        },
        "confidence": {
          "$ref": "#/$defs/unit01"
        },
        "merged_from": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false
    },
    "event": {
      "type": "object",
      "required": [
        "id",
        "kind",
        "title",
        "time",
        "refs",
        "provenance"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "kind": {
          "$ref": "#/$defs/id"
        },
        "title": {
          "type": "string",
          "minLength": 1
        },
        "url": {
          "type": "string"
        },
        "time": {
          "$ref": "#/$defs/time"
        },
        "refs": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "entity",
              "role"
            ],
            "properties": {
              "entity": {
                "$ref": "#/$defs/id"
              },
              "role": {
                "$ref": "#/$defs/id"
              }
            },
            "additionalProperties": false
          }
        },
        "label": {
          "type": "string"
        },
        "weight": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0
        },
        "weight_unit": {
          "type": "string"
        },
        "attrs": {
          "type": "object"
        },
        "provenance": {
          "$ref": "#/$defs/eventProvenance"
        },
        "flags": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "link_coverage": {
          "enum": [
            "complete",
            "partial",
            "none",
            "unknown"
          ]
        }
      },
      "dependentRequired": {
        "weight": [
          "weight_unit"
        ]
      },
      "additionalProperties": false
    },
    "entity": {
      "type": "object",
      "required": [
        "id",
        "type",
        "label",
        "provenance"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "$ref": "#/$defs/id"
        },
        "label": {
          "type": "string",
          "minLength": 1
        },
        "url": {
          "type": "string"
        },
        "attrs": {
          "type": "object"
        },
        "provenance": {
          "type": "object",
          "required": [
            "source_ids",
            "derived"
          ],
          "properties": {
            "source_ids": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/sourceId"
              }
            },
            "derived": {
              "type": "boolean"
            },
            "method": {
              "type": "string"
            }
          },
          "if": {
            "properties": {
              "derived": {
                "const": true
              }
            }
          },
          "then": {
            "required": [
              "method"
            ]
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "entity_relation": {
      "type": "object",
      "required": [
        "source",
        "target",
        "type",
        "directed",
        "provenance"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "source": {
          "$ref": "#/$defs/id"
        },
        "target": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "$ref": "#/$defs/id"
        },
        "directed": {
          "type": "boolean"
        },
        "attrs": {
          "type": "object"
        },
        "provenance": {
          "type": "object",
          "required": [
            "source_ids",
            "derived"
          ],
          "properties": {
            "source_ids": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/sourceId"
              }
            },
            "derived": {
              "type": "boolean"
            },
            "method": {
              "type": "string"
            }
          },
          "if": {
            "properties": {
              "derived": {
                "const": true
              }
            }
          },
          "then": {
            "required": [
              "method"
            ]
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "judge": {
      "type": "object",
      "required": [
        "type",
        "id",
        "date",
        "unit"
      ],
      "properties": {
        "type": {
          "enum": [
            "human",
            "model",
            "unspecified"
          ]
        },
        "id": {
          "$ref": "#/$defs/id"
        },
        "date": {
          "type": "string"
        },
        "unit": {
          "enum": [
            "link",
            "event",
            "group"
          ]
        }
      },
      "additionalProperties": false
    },
    "evidenceItem": {
      "type": "object",
      "required": [
        "level",
        "basis"
      ],
      "properties": {
        "level": {
          "enum": [
            "given",
            "rule",
            "model",
            "judged"
          ]
        },
        "basis": {
          "$ref": "#/$defs/id"
        },
        "text": {
          "type": "string"
        },
        "source_ref": {
          "$ref": "#/$defs/sourceId"
        },
        "rule_id": {
          "$ref": "#/$defs/id"
        },
        "model": {
          "type": "object",
          "required": [
            "id",
            "version"
          ],
          "properties": {
            "id": {
              "$ref": "#/$defs/id"
            },
            "version": {
              "type": "string"
            }
          },
          "additionalProperties": false
        },
        "strength": {
          "$ref": "#/$defs/unit01"
        },
        "judge": {
          "$ref": "#/$defs/judge"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "level": {
                "const": "given"
              }
            }
          },
          "then": {
            "required": [
              "source_ref"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "level": {
                "const": "rule"
              }
            }
          },
          "then": {
            "required": [
              "rule_id",
              "text"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "level": {
                "const": "model"
              }
            }
          },
          "then": {
            "required": [
              "model",
              "strength"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "level": {
                "const": "judged"
              }
            }
          },
          "then": {
            "required": [
              "judge",
              "text"
            ]
          }
        }
      ],
      "additionalProperties": false
    },
    "link": {
      "type": "object",
      "required": [
        "id",
        "from",
        "to",
        "kind",
        "propagates",
        "direction",
        "gap_seconds",
        "evidence"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "from": {
          "$ref": "#/$defs/id"
        },
        "to": {
          "$ref": "#/$defs/id"
        },
        "kind": {
          "$ref": "#/$defs/id"
        },
        "relation": {
          "type": "string"
        },
        "propagates": {
          "type": "boolean"
        },
        "direction": {
          "enum": [
            "time",
            "evidence"
          ]
        },
        "gap_seconds": {
          "type": "number",
          "minimum": 0
        },
        "strength": {
          "$ref": "#/$defs/unit01"
        },
        "evidence": {
          "type": "object",
          "required": [
            "existence"
          ],
          "properties": {
            "existence": {
              "$ref": "#/$defs/evidenceItem"
            },
            "relation": {
              "oneOf": [
                {
                  "$ref": "#/$defs/evidenceItem"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "additionalProperties": false
        },
        "attrs": {
          "type": "object"
        },
        "flags": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "lag_seconds": {
          "type": "number",
          "minimum": 0
        }
      },
      "additionalProperties": false
    },
    "omitted": {
      "type": "object",
      "required": [
        "item_type",
        "reason"
      ],
      "properties": {
        "item_type": {
          "enum": [
            "event",
            "link",
            "entity"
          ]
        },
        "reason": {
          "$ref": "#/$defs/id"
        },
        "id": {
          "type": "string"
        },
        "from": {
          "type": "string"
        },
        "to": {
          "type": "string"
        },
        "detail": {
          "type": "string"
        },
        "source_ref": {
          "$ref": "#/$defs/sourceId"
        }
      },
      "additionalProperties": false
    },
    "vocabEntry": {
      "type": "object",
      "required": [
        "id",
        "label",
        "description"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "label": {
          "type": "string"
        },
        "description": {
          "type": "string"
        }
      },
      "additionalProperties": true
    },
    "manifest": {
      "type": "object",
      "required": [
        "spec_version",
        "package_id",
        "created_at",
        "adapter",
        "domain",
        "sources",
        "observation_window",
        "coverage",
        "event_kinds",
        "entity_types",
        "entity_relation_types",
        "roles",
        "link_kinds",
        "evidence_bases",
        "parameters",
        "statistics",
        "warnings",
        "limitations",
        "files"
      ],
      "properties": {
        "spec_version": {
          "const": "0.1"
        },
        "package_id": {
          "$ref": "#/$defs/id"
        },
        "created_at": {
          "$ref": "#/$defs/isoTimeUtc"
        },
        "adapter": {
          "type": "object",
          "required": [
            "name",
            "version",
            "domain",
            "produced_by"
          ],
          "properties": {
            "name": {
              "type": "string"
            },
            "version": {
              "type": "string"
            },
            "domain": {
              "type": "string"
            },
            "code_ref": {
              "type": [
                "string",
                "null"
              ]
            },
            "produced_by": {
              "type": "string"
            }
          },
          "additionalProperties": false
        },
        "domain": {
          "type": "object",
          "required": [
            "event_definition",
            "entity_description"
          ],
          "properties": {
            "event_definition": {
              "type": "string",
              "minLength": 1
            },
            "entity_description": {
              "type": "string",
              "minLength": 1
            },
            "time_meaning": {
              "type": "string",
              "minLength": 1
            }
          },
          "additionalProperties": false
        },
        "sources": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "id",
              "name",
              "accessed_at",
              "license"
            ],
            "properties": {
              "id": {
                "$ref": "#/$defs/id"
              },
              "name": {
                "type": "string"
              },
              "url": {
                "type": "string"
              },
              "accessed_at": {
                "type": "string"
              },
              "version": {
                "type": "string"
              },
              "license": {
                "type": "string"
              },
              "notes": {
                "type": "string"
              }
            },
            "additionalProperties": false
          }
        },
        "observation_window": {
          "type": "object",
          "required": [
            "start",
            "end",
            "collected_at",
            "right_censored"
          ],
          "properties": {
            "start": {
              "type": "string"
            },
            "end": {
              "type": "string"
            },
            "collected_at": {
              "type": "string"
            },
            "right_censored": {
              "type": "boolean"
            }
          },
          "additionalProperties": false
        },
        "coverage": {
          "type": "object",
          "required": [
            "procedure",
            "description",
            "known_gaps"
          ],
          "properties": {
            "procedure": {
              "enum": [
                "full",
                "query",
                "snowball",
                "sample"
              ]
            },
            "description": {
              "type": "string"
            },
            "seeds": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "depth_limit": {
              "type": [
                "integer",
                "null"
              ]
            },
            "selection_rules": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/id"
              }
            },
            "known_gaps": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          "additionalProperties": false
        },
        "event_kinds": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/vocabEntry"
          }
        },
        "entity_types": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/vocabEntry"
          }
        },
        "entity_relation_types": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/vocabEntry"
          }
        },
        "roles": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/vocabEntry"
          }
        },
        "link_kinds": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "id",
              "core_kind",
              "description",
              "propagates_default",
              "default_window_seconds",
              "max_gap_seconds",
              "direction_rule",
              "levels"
            ],
            "properties": {
              "id": {
                "$ref": "#/$defs/id"
              },
              "core_kind": {
                "enum": [
                  "adjacency",
                  "hand_off",
                  "reference",
                  "dependency",
                  "coupling",
                  "diffusion_tie",
                  "other"
                ]
              },
              "label": {
                "type": "string"
              },
              "description": {
                "type": "string"
              },
              "relations": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "id",
                    "description",
                    "propagates_default"
                  ],
                  "properties": {
                    "id": {
                      "$ref": "#/$defs/id"
                    },
                    "description": {
                      "type": "string"
                    },
                    "propagates_default": {
                      "type": "boolean"
                    }
                  },
                  "additionalProperties": false
                }
              },
              "propagates_default": {
                "type": "boolean"
              },
              "default_window_seconds": {
                "type": [
                  "number",
                  "null"
                ],
                "minimum": 0
              },
              "max_gap_seconds": {
                "type": [
                  "number",
                  "null"
                ],
                "minimum": 0
              },
              "direction_rule": {
                "type": "string"
              },
              "levels": {
                "type": "array",
                "items": {
                  "enum": [
                    "given",
                    "rule",
                    "model",
                    "judged"
                  ]
                }
              },
              "lag": {
                "type": "object",
                "required": [
                  "source"
                ],
                "properties": {
                  "source": {
                    "enum": [
                      "timestamp",
                      "attr"
                    ]
                  },
                  "attr": {
                    "type": "string",
                    "minLength": 1
                  },
                  "unit": {
                    "enum": [
                      "second",
                      "minute",
                      "hour",
                      "day",
                      "year"
                    ]
                  }
                },
                "if": {
                  "properties": {
                    "source": {
                      "const": "attr"
                    }
                  }
                },
                "then": {
                  "required": [
                    "attr",
                    "unit"
                  ]
                },
                "additionalProperties": false
              }
            },
            "additionalProperties": false
          }
        },
        "evidence_bases": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/vocabEntry"
          }
        },
        "rules": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "id",
              "description",
              "applies_to"
            ],
            "properties": {
              "id": {
                "$ref": "#/$defs/id"
              },
              "description": {
                "type": "string"
              },
              "parameters": {
                "type": "object"
              },
              "applies_to": {
                "enum": [
                  "event",
                  "link",
                  "entity"
                ]
              }
            },
            "additionalProperties": false
          }
        },
        "parameters": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "required": [
              "value",
              "description"
            ],
            "properties": {
              "description": {
                "type": "string"
              }
            }
          }
        },
        "judges": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "id",
              "type",
              "description",
              "agreement"
            ],
            "properties": {
              "id": {
                "$ref": "#/$defs/id"
              },
              "type": {
                "enum": [
                  "human",
                  "model",
                  "unspecified"
                ]
              },
              "description": {
                "type": "string"
              },
              "agreement": {
                "type": "object",
                "required": [
                  "measured"
                ],
                "properties": {
                  "measured": {
                    "type": "boolean"
                  },
                  "method": {
                    "type": "string"
                  },
                  "value": {
                    "type": [
                      "number",
                      "null"
                    ]
                  }
                },
                "additionalProperties": false
              }
            },
            "additionalProperties": false
          }
        },
        "flags": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/vocabEntry"
          }
        },
        "statistics": {
          "type": "object",
          "required": [
            "events",
            "entities",
            "entity_relations",
            "links",
            "omitted",
            "events_without_links",
            "unreferenced_entities",
            "merged_duplicates"
          ],
          "properties": {
            "events": {
              "type": "integer",
              "minimum": 0
            },
            "entities": {
              "type": "integer",
              "minimum": 0
            },
            "entity_relations": {
              "type": "integer",
              "minimum": 0
            },
            "links": {
              "type": "object",
              "required": [
                "total",
                "propagating",
                "by_kind",
                "by_level"
              ],
              "properties": {
                "total": {
                  "type": "integer",
                  "minimum": 0
                },
                "propagating": {
                  "type": "integer",
                  "minimum": 0
                },
                "by_kind": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "integer"
                  }
                },
                "by_level": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "integer"
                  }
                },
                "by_relation": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "integer"
                  }
                }
              }
            },
            "omitted": {
              "type": "object",
              "required": [
                "by_reason"
              ],
              "properties": {
                "by_reason": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "integer"
                  }
                }
              }
            },
            "events_without_links": {
              "type": "integer",
              "minimum": 0
            },
            "unreferenced_entities": {
              "type": "integer",
              "minimum": 0
            },
            "merged_duplicates": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        "warnings": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "code",
              "message",
              "count"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "count": {
                "type": "integer",
                "minimum": 0
              }
            },
            "additionalProperties": false
          }
        },
        "limitations": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string"
          }
        },
        "notes": {
          "type": "string"
        },
        "files": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "required": [
              "records",
              "sha256"
            ],
            "properties": {
              "records": {
                "type": "integer",
                "minimum": 0
              },
              "sha256": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$"
              }
            },
            "additionalProperties": false
          }
        },
        "attribute_roles": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "id",
              "applies_to",
              "role",
              "attr"
            ],
            "properties": {
              "id": {
                "$ref": "#/$defs/id"
              },
              "applies_to": {
                "enum": [
                  "event",
                  "entity",
                  "link"
                ]
              },
              "role": {
                "enum": [
                  "time_of_day",
                  "position",
                  "impact",
                  "category"
                ]
              },
              "attr": {
                "oneOf": [
                  {
                    "type": "string",
                    "minLength": 1
                  },
                  {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "string",
                      "minLength": 1
                    }
                  }
                ]
              },
              "unit": {
                "type": "string"
              },
              "time_zone": {
                "type": "string"
              },
              "day_cut_minute": {
                "type": "integer",
                "minimum": 0,
                "maximum": 1439
              },
              "space": {
                "type": "object",
                "required": [
                  "id",
                  "kind"
                ],
                "properties": {
                  "id": {
                    "$ref": "#/$defs/id"
                  },
                  "kind": {
                    "enum": [
                      "geographic",
                      "layout"
                    ]
                  },
                  "description": {
                    "type": "string"
                  }
                },
                "additionalProperties": false
              },
              "basis": {
                "enum": [
                  "recorded",
                  "derived",
                  "scheduled",
                  "estimated"
                ]
              },
              "caveat": {
                "type": "string"
              }
            },
            "allOf": [
              {
                "if": {
                  "properties": {
                    "role": {
                      "const": "time_of_day"
                    }
                  }
                },
                "then": {
                  "required": [
                    "time_zone",
                    "basis"
                  ]
                }
              },
              {
                "if": {
                  "properties": {
                    "role": {
                      "const": "position"
                    }
                  }
                },
                "then": {
                  "required": [
                    "space"
                  ]
                }
              }
            ],
            "additionalProperties": false
          }
        }
      },
      "additionalProperties": false
    }
  }
}