{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://open-memory-interchange.example/schema/0.1/omi-l0.schema.json",
  "title": "Open Memory Interchange 0.1 L0 Core",
  "type": "object",
  "required": [
    "format",
    "version",
    "memories"
  ],
  "properties": {
    "format": {
      "const": "open-memory-interchange"
    },
    "version": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+$"
    },
    "serialization": {
      "enum": [
        "json"
      ]
    },
    "subject": {
      "$ref": "#/$defs/subject"
    },
    "id_namespace": {
      "type": "string",
      "minLength": 1
    },
    "generated_at": {
      "$ref": "#/$defs/dateTime"
    },
    "generator": {
      "type": "string"
    },
    "memories": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/record"
      }
    },
    "ext": {
      "type": "object"
    }
  },
  "$defs": {
    "date": {
      "type": "string",
      "format": "date",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
    },
    "dateTime": {
      "type": "string",
      "format": "date-time",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})$"
    },
    "dateOrDateTime": {
      "anyOf": [
        {
          "$ref": "#/$defs/date"
        },
        {
          "$ref": "#/$defs/dateTime"
        }
      ]
    },
    "dateOrDateTimeOrNull": {
      "anyOf": [
        {
          "$ref": "#/$defs/date"
        },
        {
          "$ref": "#/$defs/dateTime"
        },
        {
          "type": "null"
        }
      ]
    },
    "subject": {
      "type": "object",
      "required": [
        "id"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "type": {
          "type": "string",
          "minLength": 1
        },
        "label": {
          "type": "string"
        }
      },
      "additionalProperties": true
    },
    "source": {
      "type": "object",
      "properties": {
        "platform": {
          "type": "string"
        },
        "ref": {
          "type": "string"
        },
        "method": {
          "type": "string"
        }
      },
      "additionalProperties": true
    },
    "entity": {
      "type": "object",
      "required": [
        "id"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "label": {
          "type": "string"
        },
        "type": {
          "type": "string"
        }
      },
      "additionalProperties": true
    },
    "relation": {
      "type": "object",
      "required": [
        "type",
        "target"
      ],
      "properties": {
        "type": {
          "type": "string",
          "minLength": 1
        },
        "target": {
          "type": "string",
          "minLength": 1
        },
        "label": {
          "type": "string"
        }
      },
      "additionalProperties": true
    },
    "record": {
      "type": "object",
      "required": [
        "id",
        "content",
        "created"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "subject": {
          "$ref": "#/$defs/subject"
        },
        "content": {
          "type": "string"
        },
        "type": {
          "type": "string"
        },
        "created": {
          "$ref": "#/$defs/dateTime"
        },
        "updated": {
          "$ref": "#/$defs/dateTime"
        },
        "confidence": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "lang": {
          "type": "string",
          "pattern": "^[A-Za-z]{2,8}(-[A-Za-z0-9]{1,8})*$"
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "source": {
          "$ref": "#/$defs/source"
        },
        "valid_from": {
          "$ref": "#/$defs/dateOrDateTime"
        },
        "valid_to": {
          "$ref": "#/$defs/dateOrDateTimeOrNull"
        },
        "entities": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/entity"
          }
        },
        "relations": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/relation"
          }
        },
        "ext": {
          "type": "object"
        }
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": true
}
