{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://nesaraq.com/aodm/1.2/aodm-core-1.2.schema.json",
  "title": "AODM Core 1.2",
  "description": "JSON equivalent of the AODM 1.2 core ontology. Knowledge primitives: entity, relationship, fact, rule. Annotations: source, confidence, value. See AODM-1.2-SPECIFICATION.md.",
  "type": "object",
  "required": ["aodm_version"],
  "additionalProperties": false,
  "properties": {
    "aodm_version": { "const": "1.2" },
    "entities": { "type": "array", "items": { "$ref": "#/$defs/entity" } },
    "relationships": { "type": "array", "items": { "$ref": "#/$defs/relationship" } },
    "facts": { "type": "array", "items": { "$ref": "#/$defs/fact" } },
    "rules": { "type": "array", "items": { "$ref": "#/$defs/rule" } },
    "sources": { "type": "array", "items": { "$ref": "#/$defs/source" } }
  },
  "$defs": {
    "temporalPoint": {
      "type": "string",
      "anyOf": [
        { "format": "date" },
        { "format": "date-time" }
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}([T ].*)?$",
      "description": "ISO 8601 date or date-time."
    },
    "digest": {
      "type": "string",
      "pattern": "^[a-z0-9-]+:[0-9a-fA-F]{32,128}$",
      "description": "Self-describing content digest, '<algorithm>:<hex>', e.g. sha256:9f86d0..."
    },
    "polarity": {
      "enum": ["positive", "negative"],
      "default": "positive",
      "description": "Whether the assertion is affirmed or explicitly denied."
    },
    "confidence": {
      "type": "number",
      "minimum": 0.0,
      "maximum": 1.0
    },
    "derived_from": {
      "type": "array",
      "items": { "type": "string" },
      "description": "Ids of the rule and/or facts this item was inferred from."
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string" },
        "uri": { "type": "string", "format": "uri" },
        "title": { "type": "string" },
        "retrieved": { "$ref": "#/$defs/temporalPoint" },
        "asserted": { "$ref": "#/$defs/temporalPoint" },
        "text": { "type": "string" }
      }
    },
    "value": {
      "type": "object",
      "additionalProperties": false,
      "description": "Structured measurement. Either 'number' (optionally with 'tolerance') or both 'min' and 'max'. See VALIDATION-RULES.md M1-M3.",
      "properties": {
        "number": { "type": "number" },
        "min": { "type": "number" },
        "max": { "type": "number" },
        "tolerance": { "type": "number", "minimum": 0 },
        "unit": { "type": "string", "description": "SHOULD be a UCUM code (e.g. Cel, mm, kg, bar)." }
      },
      "oneOf": [
        { "required": ["number"], "not": { "anyOf": [ { "required": ["min"] }, { "required": ["max"] } ] } },
        { "required": ["min", "max"], "not": { "anyOf": [ { "required": ["number"] }, { "required": ["tolerance"] } ] } }
      ]
    },
    "entity": {
      "type": "object",
      "required": ["id", "type"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string" },
        "type": { "type": "string" },
        "label": { "type": "string" },
        "content": { "type": "string" },
        "hash": { "$ref": "#/$defs/digest" },
        "source": { "$ref": "#/$defs/source" },
        "confidence": { "$ref": "#/$defs/confidence" }
      }
    },
    "relationship": {
      "type": "object",
      "required": ["type", "subject", "predicate", "object"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string" },
        "type": { "type": "string" },
        "subject": { "type": "string", "description": "id of the subject entity" },
        "predicate": { "type": "string" },
        "object": { "type": "string", "description": "id of the object entity" },
        "polarity": { "$ref": "#/$defs/polarity" },
        "valid_from": { "$ref": "#/$defs/temporalPoint" },
        "valid_to": { "$ref": "#/$defs/temporalPoint" },
        "derived_from": { "$ref": "#/$defs/derived_from" },
        "source": { "$ref": "#/$defs/source" },
        "confidence": { "$ref": "#/$defs/confidence" }
      }
    },
    "fact": {
      "type": "object",
      "required": ["statement"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string" },
        "about": { "type": "string", "description": "id of the entity or relationship this fact describes" },
        "statement": { "type": "string" },
        "value": { "$ref": "#/$defs/value" },
        "polarity": { "$ref": "#/$defs/polarity" },
        "valid_from": { "$ref": "#/$defs/temporalPoint" },
        "valid_to": { "$ref": "#/$defs/temporalPoint" },
        "hash": { "$ref": "#/$defs/digest" },
        "derived_from": { "$ref": "#/$defs/derived_from" },
        "source": { "$ref": "#/$defs/source" },
        "confidence": { "$ref": "#/$defs/confidence" }
      }
    },
    "rule": {
      "type": "object",
      "required": ["conditions", "conclusion"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string" },
        "conditions": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": ["ref"],
            "additionalProperties": false,
            "properties": {
              "ref": { "type": "string", "description": "id of a fact or entity" },
              "polarity": { "$ref": "#/$defs/polarity" }
            }
          }
        },
        "conclusion": { "type": "string", "description": "id of a fact" },
        "valid_from": { "$ref": "#/$defs/temporalPoint" },
        "valid_to": { "$ref": "#/$defs/temporalPoint" },
        "source": { "$ref": "#/$defs/source" },
        "confidence": { "$ref": "#/$defs/confidence" }
      }
    }
  }
}
