{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Altrs Atlas query result v1",
  "type": "object",
  "required": [
    "schemaVersion",
    "query",
    "results"
  ],
  "properties": {
    "schemaVersion": {
      "const": 1
    },
    "query": {
      "type": "object",
      "required": [],
      "properties": {
        "site": {
          "enum": [
            "input",
            "representation",
            "state",
            "routing",
            "objective",
            "weights",
            "solver",
            "readout"
          ]
        },
        "dynamics": {
          "type": "array",
          "items": {
            "enum": [
              "select",
              "mix",
              "remember",
              "predict",
              "refine",
              "constrain",
              "adapt",
              "compress",
              "sample",
              "propagate"
            ]
          },
          "uniqueItems": true
        },
        "goal": {
          "type": "array",
          "items": {
            "enum": [
              "quality",
              "efficiency",
              "transfer",
              "stability",
              "generation",
              "control",
              "interpretability"
            ]
          },
          "uniqueItems": true
        },
        "q": {
          "type": "string",
          "minLength": 1
        },
        "family": {
          "type": "string",
          "minLength": 1
        },
        "ref": {
          "type": "string",
          "pattern": "^[A-Z][0-9]{2,}$"
        },
        "capability": {
          "uniqueItems": true,
          "type": "array",
          "items": {
            "enum": [
              "memory",
              "learned_codebook",
              "architecture_gene",
              "sparse_experts",
              "learned_gate",
              "teacher_free_ssl",
              "iterative_refinement"
            ]
          }
        },
        "baseline": {
          "type": "string",
          "minLength": 1
        },
        "factor": {
          "type": "string",
          "minLength": 1
        },
        "operation": {
          "type": "string",
          "minLength": 1
        },
        "inputFactor": {
          "type": "string",
          "minLength": 1
        },
        "outputFactor": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false
    },
    "results": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/record"
      }
    },
    "architecture": {
      "type": "object",
      "properties": {
        "version": {
          "const": 1
        },
        "factors": {
          "type": "object",
          "additionalProperties": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            },
            "minItems": 2,
            "maxItems": 2
          }
        },
        "baselines": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/baseline"
          }
        },
        "operations": {
          "type": "object",
          "additionalProperties": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            },
            "minItems": 2,
            "maxItems": 2
          }
        },
        "contexts": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/context"
          }
        }
      },
      "required": [
        "version",
        "factors",
        "baselines",
        "operations",
        "contexts"
      ],
      "additionalProperties": false
    }
  },
  "additionalProperties": false,
  "$defs": {
    "record": {
      "type": "object",
      "required": [
        "id",
        "name",
        "title",
        "family",
        "site",
        "dynamics",
        "goal",
        "task",
        "effect",
        "boundary",
        "mechanism",
        "paperClaim",
        "interface",
        "source",
        "references",
        "relatedReading",
        "graph",
        "capability"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Z][0-9]{2,}$"
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "title": {
          "type": "string",
          "minLength": 1
        },
        "family": {
          "type": "string",
          "minLength": 1
        },
        "site": {
          "enum": [
            "input",
            "representation",
            "state",
            "routing",
            "objective",
            "weights",
            "solver",
            "readout"
          ]
        },
        "dynamics": {
          "type": "array",
          "items": {
            "enum": [
              "select",
              "mix",
              "remember",
              "predict",
              "refine",
              "constrain",
              "adapt",
              "compress",
              "sample",
              "propagate"
            ]
          },
          "uniqueItems": true
        },
        "goal": {
          "type": "array",
          "items": {
            "enum": [
              "quality",
              "efficiency",
              "transfer",
              "stability",
              "generation",
              "control",
              "interpretability"
            ]
          },
          "uniqueItems": true
        },
        "task": {
          "type": "string",
          "minLength": 1
        },
        "effect": {
          "type": "string",
          "minLength": 1
        },
        "boundary": {
          "type": "string",
          "minLength": 1
        },
        "mechanism": {
          "type": "string",
          "minLength": 1
        },
        "paperClaim": {
          "type": [
            "string",
            "null"
          ]
        },
        "interface": {
          "type": [
            "string",
            "null"
          ]
        },
        "source": {
          "type": "object",
          "required": [
            "url",
            "locator"
          ],
          "properties": {
            "repository": {"type": "string", "format": "uri"},
            "modelCard": {"type": "string", "format": "uri"},
            "url": {
              "type": "string",
              "format": "uri"
            },
            "locator": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          "additionalProperties": false
        },
        "references": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[A-Z][0-9]{2,}$"
          }
        },
        "relatedReading": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[A-Z][0-9]{2,}$"
          }
        },
        "graph": {
          "type": "object",
          "required": [
            "nodes",
            "edges"
          ],
          "properties": {
            "nodes": {
              "type": "array",
              "items": {
                "type": "object",
                "required": [
                  "label"
                ],
                "properties": {
                  "label": {
                    "type": "string",
                    "minLength": 1
                  },
                  "type": {
                    "enum": [
                      "io",
                      "op",
                      "state"
                    ]
                  },
                  "x": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 100
                  },
                  "y": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 100
                  },
                  "note": {
                    "type": "string",
                    "minLength": 1
                  }
                },
                "additionalProperties": false
              },
              "minItems": 2
            },
            "edges": {
              "type": "array",
              "items": {
                "type": "array",
                "items": {
                  "type": "integer",
                  "minimum": 0
                },
                "minItems": 2,
                "maxItems": 2
              }
            }
          },
          "additionalProperties": false
        },
        "capability": {
          "uniqueItems": true,
          "type": "array",
          "items": {
            "enum": [
              "memory",
              "learned_codebook",
              "architecture_gene",
              "sparse_experts",
              "learned_gate",
              "teacher_free_ssl",
              "iterative_refinement"
            ]
          }
        },
        "plugin": {
          "$ref": "#/$defs/plugin"
        },
        "architectureEvidence": {
          "type": "object",
          "properties": {
            "note": {
              "type": "string",
              "minLength": 1
            },
            "scope": {
              "type": "string",
              "minLength": 1
            },
            "url": {
              "type": "string",
              "format": "uri"
            },
            "relatedSource": {
              "type": "object",
              "properties": {
                "title": {
                  "type": "string",
                  "minLength": 1
                },
                "url": {
                  "type": "string",
                  "format": "uri"
                }
              },
              "required": [
                "title",
                "url"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "note"
          ],
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "port": {
      "type": "object",
      "properties": {
        "factor": {
          "type": "string",
          "minLength": 1
        },
        "label": {
          "type": "string",
          "minLength": 1
        },
        "signal": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "factor",
        "label",
        "signal"
      ],
      "additionalProperties": false
    },
    "plugin": {
      "type": "object",
      "properties": {
        "baseline": {
          "type": "string",
          "minLength": 1
        },
        "hook": {
          "type": "string",
          "minLength": 1
        },
        "operation": {
          "type": "string",
          "minLength": 1
        },
        "input": {
          "$ref": "#/$defs/port"
        },
        "output": {
          "$ref": "#/$defs/port"
        }
      },
      "required": [
        "baseline",
        "hook",
        "operation",
        "input",
        "output"
      ],
      "additionalProperties": false
    },
    "baseline": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "scope": {
          "type": "string",
          "minLength": 1
        },
        "factors": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "edges": {
          "type": "array",
          "items": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            },
            "minItems": 2,
            "maxItems": 3
          }
        },
        "reading": {
          "type": "object",
          "properties": {
            "title": {
              "type": "string",
              "minLength": 1
            },
            "url": {
              "type": "string",
              "format": "uri"
            },
            "locator": {
              "type": "string",
              "minLength": 1
            }
          },
          "required": [
            "title",
            "url",
            "locator"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "name",
        "scope",
        "factors",
        "edges",
        "reading"
      ],
      "additionalProperties": false
    },
    "context": {
      "type": "object",
      "properties": {
        "focus": {"type":"string","minLength":1},
        "figure": {
          "type": "string",
          "minLength": 1
        },
        "page": {
          "type": "integer",
          "minimum": 1
        },
        "source": {
          "type": "string",
          "format": "uri"
        },
        "reuse": {
          "type": [
            "null",
            "string"
          ]
        },
        "nodes": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "properties": {
              "ref": {
                "type": "string",
                "minLength": 1
              },
              "label": {
                "type": "string",
                "minLength": 1
              },
              "note": {
                "type": "string",
                "minLength": 1
              }
            },
            "required": [
              "ref"
            ],
            "additionalProperties": false
          }
        },
        "edges": {
          "type": "array",
          "items": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            },
            "minItems": 3,
            "maxItems": 4
          }
        }
      },
      "required": [
        "figure",
        "reuse",
        "nodes",
        "edges"
      ],
      "anyOf": [{"required":["page"]},{"required":["source"]}],
      "additionalProperties": false
    }
  }
}
