# =============================================================================
# ALHAZEN NOTEBOOK MODEL - TypeDB 3.x Schema
# =============================================================================
# A knowledge graph schema for agent memory systems aligned with Alhazen's
# Notebook Model: Collection -> Thing -> Artifact -> Fragment -> Note
# =============================================================================

define

# -----------------------------------------------------------------------------
# ATTRIBUTE TYPES - Core Properties
# -----------------------------------------------------------------------------

# Identity and naming
attribute id, value string;
attribute name, value string;
attribute description, value string;
attribute iri, value string;
attribute abstract-text, value string;

# Content and alh-representation
attribute content, value string;
attribute content-hash, value string;
attribute format, value string;
attribute token-count, value integer;

# Cache storage (for large alh-artifacts stored externally)
attribute cache-path, value string;      # Relative path in cache: "html/alh-artifact-abc123.html"
attribute mime-type, value string;       # MIME type: "text/html", "application/pdf"
attribute file-size, value integer;      # Size in bytes

# Temporal
attribute created-at, value datetime;
attribute updated-at, value datetime;
attribute publication-date, value datetime;
attribute valid-from, value datetime;
attribute valid-until, value datetime;

# Provenance
attribute provenance, value string;
attribute source-uri, value string;
attribute confidence, value double;
attribute license, value string;

# Fragment positioning
attribute offset, value integer;
attribute length, value integer;

# Collection semantics
attribute alh-logical-query, value string;
attribute alh-is-extensional, value boolean;

# Classification metadata
attribute alh-schema-org-uri, value string;
attribute alh-wikidata-qid, value string;
attribute alh-vocabulary-source, value string;

# Agent/provenance tracking
attribute alh-agent-id, value string;
attribute alh-agent-type, value string;
attribute alh-model-name, value string;
attribute alh-operation-type, value string;
attribute alh-operation-timestamp, value datetime;
attribute alh-operation-parameters, value string;

# Additional attributes
attribute alh-value-string, value string;
attribute alh-evidence-type-attr, value string;

# Person identity
attribute alh-given-name, value string;
attribute alh-family-name, value string;
attribute alh-email-address, value string;

# Person enrichment
attribute alh-linkedin-url, value string;
attribute alh-title, value string;
attribute alh-phone-number, value string;
attribute alh-bio, value string;

# Interaction tracking
attribute alh-interaction-type, value string;
attribute alh-interaction-date, value datetime;
attribute alh-outcome, value string;
attribute alh-follow-up-by, value datetime;
attribute alh-follow-up-status, value string;
attribute alh-participant-role, value string;

# Organization enrichment
attribute alh-company-url, value string;
attribute alh-location, value string;
attribute alh-industry, value string;

# Episode / session tracking
attribute alh-session-id, value string;
attribute alh-source-skill, value string;

# Memory claim notes
attribute alh-fact-type, value string;

# Role lifecycle (BFO/UFO role pattern)
attribute alh-role-status, value string;
attribute alh-role-started-on, value datetime;
attribute alh-role-ended-on, value datetime;


# ROLE-BEARING - A person bears a role (BFO inherence relation)
# Defined before entities so role names resolve in plays clauses.
relation alh-role-bearing,
    relates bearer,
    relates borne-role;


# -----------------------------------------------------------------------------
# ENTITY TYPES - Core Ontology (Alhazen's Notebook Model)
# -----------------------------------------------------------------------------

# Shared abstract root for all identifiable entities
# Provides identity, metadata, and cross-cutting concerns (alh-tagging, alh-classification, provenance)
entity alh-identifiable-entity @abstract,
    owns id @key,
    owns name,
    owns description,
    owns iri,
    owns created-at,
    owns updated-at,
    owns provenance,
    owns source-uri,
    owns license,
    owns valid-from,
    owns valid-until,
    plays alh-classification:classified-entity,
    plays alh-tagging:tagged-entity,
    plays alh-aboutness:subject,
    plays alh-collection-membership:member,
    plays alh-provenance-record:produced-entity,
    plays alh-provenance-record:source-entity,
    plays alh-property-assertion:subject-entity,
    plays alh-semantic-triple:triple-subject,
    plays alh-semantic-triple:triple-object,
    plays alh-episode-mention:subject;


# THING - Domain objects (papers, genes, diseases, jobs, agents, etc.)
# Concrete base type for real-world entities that are NOT information content
entity alh-domain-thing sub alh-identifiable-entity,
    plays alh-representation:referent,
    plays alh-citation-reference:citing-item,
    plays alh-citation-reference:cited-item;


# ROLE - Anti-rigid, externally-grounded entity that inheres in a person (BFO/UFO pattern)
# Role-specific data lives on the role, not on the person. Subtypes in skill schemas.
entity alh-role sub alh-domain-thing,
    owns alh-role-status,
    owns alh-role-started-on,
    owns alh-role-ended-on,
    plays alh-role-bearing:borne-role;


# COLLECTION - Organized groupings of Things
# Typed per domain namespace (scilit-corpus, jobhunt-search, apm-case-file, etc.)
entity alh-collection sub alh-identifiable-entity,
    owns alh-logical-query,
    owns alh-is-extensional,
    plays alh-collection-membership:collection,
    plays alh-collection-nesting:parent-collection,
    plays alh-collection-nesting:child-collection;


# INFORMATION-CONTENT-ENTITY - Content-bearing entities (alh-artifacts, alh-fragments, notes)
# Only ICEs carry actual content, cache paths, formats, etc.
entity alh-information-content-entity @abstract, sub alh-identifiable-entity,
    owns content,
    owns content-hash,
    owns format,
    owns token-count,
    owns cache-path,
    owns mime-type,
    owns file-size,
    plays alh-authorship:work,
    plays alh-derivation:derived-from-source,
    plays alh-derivation:derivative;


# ARTIFACT - Specific alh-representations of Things
entity alh-artifact sub alh-information-content-entity,
    plays alh-representation:alh-artifact,
    plays alh-fragmentation:whole;


# FRAGMENT - Parts of alh-artifacts
entity alh-fragment sub alh-information-content-entity,
    owns offset,
    owns length,
    plays alh-fragmentation:part,
    plays alh-quotation:quoted-alh-fragment,
    plays alh-quotation:quoting-alh-fragment;


# NOTE - Agent-generated annotations
entity alh-note sub alh-information-content-entity,
    owns confidence,
    plays alh-aboutness:note,
    plays alh-note-threading:parent-note,
    plays alh-note-threading:child-note,
    plays alh-evidence-chain:claim,
    plays alh-evidence-chain:evidence;


# EPISODE - Process account of a work session (4th ICE sibling)
# Distinct from note (semantic interpretation): records WHAT HAPPENED and WHICH ENTITIES were touched.
# Linked to entities via alh-episode-mention; linked to skilllog-session by shared alh-session-id.
entity alh-episode sub alh-information-content-entity,
    owns alh-session-id,
    owns alh-source-skill,
    plays alh-episode-mention:session;


# USER-QUESTION - Questions/instructions from users
entity alh-user-question sub alh-identifiable-entity;


# INFORMATION-RESOURCE - Databases, knowledgebases, APIs
entity alh-information-resource sub alh-identifiable-entity;


# -----------------------------------------------------------------------------
# ENTITY TYPES - Agents and Actors
# -----------------------------------------------------------------------------

# AGENT - Operational actor base (human or AI); creator of notes and content
entity alh-agent sub alh-domain-thing,
    owns alh-agent-type,
    owns alh-model-name,
    plays alh-authorship:author,
    plays alh-provenance-record:performing-agent;


# AI-AGENT - AI model instances (Claude, GPT-4, etc.)
entity alh-ai-agent sub alh-agent;


# PERSON - Real-world human actor (sub agent: can create notes, perform operations)
entity alh-person sub alh-agent,
    owns alh-given-name,
    owns alh-family-name,
    owns alh-email-address,
    owns alh-linkedin-url,
    owns alh-title,
    owns alh-phone-number,
    owns alh-bio,
    plays alh-interaction-participation:participant,
    plays alh-works-at:employee,
    plays alh-role-bearing:bearer,
    plays alh-authorship:publication-author,
    plays alh-affiliation:affiliated-agent;


# ORGANIZATION - Groups of persons/agents (sub alh-domain-thing for full alh-identifiable-entity hierarchy)
entity alh-organization sub alh-domain-thing,
    owns alh-linkedin-url,
    owns alh-company-url,
    owns alh-location,
    owns alh-industry,
    plays alh-affiliation:alh-organization,
    plays alh-works-at:employer;


# INTERACTION - A tracked alh-interaction between persons (meeting, call, email, interview)
entity alh-interaction sub alh-domain-thing,
    owns alh-interaction-type,
    owns alh-interaction-date,
    owns alh-outcome,
    owns alh-follow-up-by,
    owns alh-follow-up-status,
    plays alh-interaction-participation:alh-interaction;


# -----------------------------------------------------------------------------
# ENTITY TYPES - External Vocabulary Classification
# -----------------------------------------------------------------------------

# VOCABULARY - A alh-classification system (schema.org, Wikidata, UMLS, etc.)
entity alh-vocabulary,
    owns id @key,
    owns name,
    owns iri,
    owns description,
    plays alh-vocabulary-membership:vocab;


# VOCABULARY-TYPE - A type from an external vocabulary
entity alh-vocabulary-type,
    owns id @key,
    owns name,
    owns alh-schema-org-uri,
    owns alh-wikidata-qid,
    owns description,
    plays alh-vocabulary-membership:vocab-type,
    plays alh-type-hierarchy:subtype,
    plays alh-type-hierarchy:supertype,
    plays alh-classification:type-facet;


# VOCABULARY-PROPERTY - A property from an external vocabulary
entity alh-vocabulary-property,
    owns id @key,
    owns name,
    owns alh-schema-org-uri,
    owns description,
    plays alh-vocabulary-membership:vocab-type,
    plays alh-property-assertion:property-definition,
    plays alh-domain-range:property-def,
    plays alh-domain-range:domain-type,
    plays alh-domain-range:range-type,
    plays alh-semantic-triple:triple-predicate;


# TAG - Lightweight alh-classification without full vocabulary structure
entity alh-tag,
    owns id @key,
    owns name,
    owns description,
    plays alh-tagging:tag;


# -----------------------------------------------------------------------------
# RELATION TYPES - Core Relations (Alhazen's Notebook Model)
# -----------------------------------------------------------------------------

# ABOUTNESS - The fundamental "is about" relation (IAO:0000136)
relation alh-aboutness,
    relates note,
    relates subject;


# REPRESENTATION - Connects alh-artifacts to the things they represent
relation alh-representation,
    relates alh-artifact,
    relates referent;


# COLLECTION-MEMBERSHIP - Things belonging to collections
relation alh-collection-membership,
    owns created-at,
    owns provenance,
    relates collection,
    relates member;


# COLLECTION-NESTING - Hierarchical collection alh-organization
relation alh-collection-nesting,
    relates parent-collection,
    relates child-collection;


# FRAGMENTATION - Parts of alh-artifacts
relation alh-fragmentation,
    relates whole,
    relates part;


# AUTHORSHIP - Who created what (general)
relation alh-authorship,
    owns created-at,
    relates author,
    relates work,
    relates publication-author;


# AFFILIATION - Agent/Author membership in alh-organizations
relation alh-affiliation,
    owns valid-from,
    owns valid-until,
    relates affiliated-agent,
    relates alh-organization;


# WORKS-AT - Person employed at / associated with an alh-organization
relation alh-works-at,
    owns valid-from,
    owns valid-until,
    relates employee,
    relates employer;


# INTERACTION-PARTICIPATION - Links persons to alh-interactions with roles
relation alh-interaction-participation,
    owns alh-participant-role,
    relates alh-interaction,
    relates participant;


# CITATION-REFERENCE - References between Things (paper cites paper)
relation alh-citation-reference,
    owns provenance,
    owns created-at,
    relates citing-item,
    relates cited-item;


# QUOTATION - When a alh-fragment quotes another
relation alh-quotation,
    relates quoting-alh-fragment,
    relates quoted-alh-fragment;


# DERIVATION - Provenance chain for derived content
relation alh-derivation,
    owns provenance,
    owns created-at,
    relates derivative,
    relates derived-from-source;


# NOTE-THREADING - Hierarchical note alh-organization (replies, follow-ups)
relation alh-note-threading,
    relates parent-note,
    relates child-note;


# EPISODE-MENTION - Links an alh-episode to graph entities touched during the session
relation alh-episode-mention,
    relates session,
    relates subject;


# PROVENANCE-RECORD - Detailed tracking of who/what created entities
relation alh-provenance-record,
    owns alh-agent-id,
    owns alh-agent-type,
    owns alh-model-name,
    owns alh-operation-type,
    owns alh-operation-timestamp,
    owns alh-operation-parameters,
    relates produced-entity,
    relates source-entity,
    relates performing-agent;


# -----------------------------------------------------------------------------
# RELATION TYPES - Classification System
# -----------------------------------------------------------------------------

# CLASSIFICATION - Assigning vocabulary types to entities
relation alh-classification,
    owns confidence,
    owns provenance,
    owns created-at,
    relates classified-entity,
    relates type-facet;


# VOCABULARY-MEMBERSHIP - Types belonging to vocabularies
relation alh-vocabulary-membership,
    relates vocab,
    relates vocab-type;


# TYPE-HIERARCHY - Subtype relationships within vocabularies
relation alh-type-hierarchy,
    relates subtype,
    relates supertype;


# DOMAIN-RANGE - Property constraints from vocabularies
relation alh-domain-range,
    relates property-def,
    relates domain-type,
    relates range-type;


# TAGGING - Lightweight alh-classification
relation alh-tagging,
    owns created-at,
    owns provenance,
    relates tagged-entity,
    relates tag;


# PROPERTY-ASSERTION - Dynamic property assignment
relation alh-property-assertion,
    owns created-at,
    owns provenance,
    owns alh-value-string,
    relates subject-entity,
    relates property-definition;


# -----------------------------------------------------------------------------
# RELATION TYPES - N-ary Relations for Complex Assertions
# -----------------------------------------------------------------------------

# SEMANTIC-TRIPLE - For RDF-style assertions with provenance
relation alh-semantic-triple,
    owns confidence,
    owns provenance,
    owns created-at,
    owns source-uri,
    relates triple-subject,
    relates triple-predicate,
    relates triple-object;


# EVIDENCE-CHAIN - Linking claims to supporting evidence
relation alh-evidence-chain,
    owns confidence,
    owns alh-evidence-type-attr,
    relates claim,
    relates evidence;


# =============================================================================
# END SCHEMA
# =============================================================================
