{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Attributed Latin prose annotation v3",
  "type": "object",
  "required": [
    "schema",
    "engineVersion",
    "id",
    "created",
    "source",
    "target",
    "inputs",
    "inputsSha256",
    "analysis",
    "reviewVersion",
    "sourceVersionId",
    "parentId",
    "baseline",
    "reviewStatus",
    "sha256",
    "review"
  ],
  "properties": {
    "schema": {
      "const": "magalia.clausulae.annotation/3"
    },
    "engineVersion": {
      "const": "0.2.0"
    },
    "id": {
      "type": "string",
      "minLength": 1
    },
    "created": {
      "type": "string",
      "format": "date-time"
    },
    "source": {
      "type": "object",
      "required": [
        "documentId",
        "text",
        "language",
        "sha256"
      ],
      "properties": {
        "language": {
          "const": "lat"
        },
        "text": {
          "type": "string",
          "minLength": 1
        },
        "sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        }
      }
    },
    "target": {
      "type": "object",
      "required": [
        "start",
        "end",
        "coordinate",
        "exact"
      ],
      "properties": {
        "start": {
          "type": "integer",
          "minimum": 0
        },
        "end": {
          "type": "integer",
          "minimum": 1
        },
        "coordinate": {
          "const": "unicode-code-points"
        },
        "exact": {
          "type": "string"
        }
      }
    },
    "inputs": {
      "type": "object",
      "required": [
        "options",
        "resource"
      ]
    },
    "inputsSha256": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "analysis": {
      "type": "object",
      "required": [
        "profile",
        "scheme",
        "basis",
        "reviewStatus",
        "sequence",
        "syllables",
        "alternatives",
        "alternativesComplete",
        "matches",
        "classificationStatus",
        "tokens",
        "exclusions"
      ],
      "properties": {
        "profile": {
          "const": "latin-prose-pilot/1"
        },
        "scheme": {
          "const": "cltk-2016-table/1"
        },
        "basis": {
          "const": "automatic-latin-prosody"
        },
        "reviewStatus": {
          "const": "unreviewed"
        },
        "sequence": {
          "type": "string",
          "pattern": "^[HL?]*$"
        },
        "alternativesComplete": {
          "type": "boolean"
        },
        "syllables": {
          "type": "array"
        },
        "alternatives": {
          "type": "array"
        },
        "matches": {
          "type": "array"
        }
      }
    },
    "reviewVersion": {
      "const": "0.1.0"
    },
    "sourceVersionId": {
      "type": "string",
      "minLength": 1
    },
    "parentId": {
      "type": [
        "string",
        "null"
      ]
    },
    "baseline": {
      "$ref": "automatic-annotation.schema.json"
    },
    "reviewStatus": {
      "const": "user-attributed"
    },
    "sha256": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "review": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "boundary",
        "words",
        "quantities"
      ],
      "properties": {
        "boundary": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "decision",
            "evidence"
          ],
          "properties": {
            "decision": {
              "enum": [
                "accepted",
                "rejected",
                "uncertain"
              ]
            },
            "evidence": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "reviewer",
                "reason",
                "source",
                "location"
              ],
              "properties": {
                "reviewer": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 2000
                },
                "reason": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 2000
                },
                "source": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 2000
                },
                "location": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 2000
                }
              }
            }
          }
        },
        "words": {
          "type": "array",
          "maxItems": 256,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "span",
              "kind",
              "reading",
              "evidence"
            ],
            "properties": {
              "span": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "start",
                  "end",
                  "exact"
                ],
                "properties": {
                  "start": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "end": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "exact": {
                    "type": "string"
                  }
                }
              },
              "kind": {
                "enum": [
                  "lexical",
                  "supplied"
                ]
              },
              "reading": {
                "oneOf": [
                  {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  },
                  {
                    "type": "object",
                    "required": [
                      "marked"
                    ],
                    "properties": {
                      "marked": {
                        "type": "string",
                        "minLength": 1
                      }
                    }
                  }
                ]
              },
              "evidence": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "reviewer",
                  "reason",
                  "source",
                  "location"
                ],
                "properties": {
                  "reviewer": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000
                  },
                  "source": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000
                  },
                  "location": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000
                  }
                }
              }
            }
          }
        },
        "quantities": {
          "type": "array",
          "maxItems": 512,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "span",
              "value",
              "evidence"
            ],
            "properties": {
              "span": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "start",
                  "end",
                  "exact"
                ],
                "properties": {
                  "start": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "end": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "exact": {
                    "type": "string"
                  }
                }
              },
              "value": {
                "enum": [
                  "H",
                  "L",
                  "?"
                ]
              },
              "evidence": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "reviewer",
                  "reason",
                  "source",
                  "location"
                ],
                "properties": {
                  "reviewer": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000
                  },
                  "source": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000
                  },
                  "location": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "$comment": "Runtime validation replays every source, resource and decision. User attribution is not independent scholarly verification. Existing v1/v2 records are not rewritten.",
  "additionalProperties": false
}
