{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://wiki.minseong.co.kr/assets/ai/knowledge-schema.json",
  "title": "Minseong Korean Medicine Archive AI Knowledge Layer",
  "type": "object",
  "required": ["schema_version", "entities", "relations"],
  "properties": {
    "schema_version": {
      "const": "1.0"
    },
    "entities": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/entity"
      }
    },
    "relations": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/relation"
      }
    }
  },
  "$defs": {
    "entity": {
      "type": "object",
      "required": [
        "id",
        "type",
        "name",
        "url",
        "source_path",
        "language",
        "safety"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^km:"
        },
        "type": {
          "type": "string"
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "description": {
          "type": "string"
        },
        "url": {
          "type": "string",
          "pattern": "^https://wiki\\.minseong\\.co\\.kr/"
        },
        "source_path": {
          "type": "string",
          "pattern": "\\.md$"
        },
        "language": {
          "const": "ko-KR"
        },
        "aliases": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        },
        "keywords": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        },
        "codes": {
          "type": "object",
          "additionalProperties": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "uniqueItems": true
          }
        },
        "evidence_ids": {
          "type": "object",
          "properties": {
            "pmid": {
              "type": "array",
              "items": {
                "type": "string",
                "pattern": "^[0-9]+$"
              },
              "uniqueItems": true
            },
            "doi": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "uniqueItems": true
            }
          },
          "additionalProperties": false
        },
        "sections": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "safety": {
          "type": "object",
          "required": [
            "has_safety_section",
            "has_red_flag_section",
            "sections"
          ],
          "properties": {
            "has_safety_section": {
              "type": "boolean"
            },
            "has_red_flag_section": {
              "type": "boolean"
            },
            "sections": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "uniqueItems": true
            }
          },
          "additionalProperties": false
        },
        "status": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "relation": {
      "type": "object",
      "required": ["source", "relation", "target"],
      "properties": {
        "source": {
          "type": "string",
          "pattern": "^km:"
        },
        "relation": {
          "type": "string"
        },
        "target": {
          "type": "string",
          "pattern": "^km:"
        }
      },
      "additionalProperties": false
    }
  }
}
