;
; active-query.scm
;
; ACTIVE INFORMATION SEEKING:
; The system doesn't just search existing context -
; it generates TARGETED QUERIES to find what it needs.
;
; Key insight: Reverse PMI tells us WHAT to ask for.
;
(use-modules (srfi srfi-1))
(use-modules (ice-9 format))
(display "═══════════════════════════════════════════════════════════════════\n")
(display " ACTIVE QUERY GENERATION FOR DISAMBIGUATION \n")
(display "═══════════════════════════════════════════════════════════════════\n\n")
;; ═══════════════════════════════════════════════════════════════════
;; THE KEY INSIGHT
;; ═══════════════════════════════════════════════════════════════════
(display "THE INSIGHT: Don't just search - ASK TARGETED QUESTIONS\n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display " Passive search: Look for 'river' or 'money' in nearby text\n")
(display " Active query: Generate questions that would disambiguate\n\n")
(display " The system knows WHAT INFORMATION IT NEEDS.\n")
(display " It can formulate queries to GET that information.\n\n")
;; ═══════════════════════════════════════════════════════════════════
;; DISCRIMINATOR DATABASE (what distinguishes senses)
;; ═══════════════════════════════════════════════════════════════════
(define discriminators '(
;; For 'bank': what questions would distinguish senses?
(bank
(FINANCIAL
(questions
"Does this involve money or financial transactions?"
"Is there an ATM, teller, or account involved?"
"Is someone depositing, withdrawing, or transferring?")
(probe-words "money" "deposit" "withdraw" "account" "ATM" "teller" "loan")
(probe-properties "is-building" "has-interior" "processes-money"))
(GEOGRAPHIC
(questions
"Is this near water, a river, or a lake?"
"Is someone swimming, fishing, or walking along the edge?"
"Is this an outdoor natural setting?")
(probe-words "river" "water" "shore" "swim" "fish" "mud" "sand")
(probe-properties "is-outdoor" "near-water" "is-surface")))
;; For 'ran': what distinguishes senses?
(ran
(MOVED-QUICKLY
(questions
"Did someone physically move from one place to another?"
"Was this locomotion using legs?")
(probe-words "fast" "quickly" "away" "toward" "legs" "sprint"))
(OPERATED
(questions
"Did a machine or program execute?"
"Was software or equipment running?")
(probe-words "machine" "program" "computer" "software" "executed"))
(MANAGED
(questions
"Did someone manage or lead something?"
"Was this about running an organization?")
(probe-words "business" "company" "organization" "managed")))
))
;; ═══════════════════════════════════════════════════════════════════
;; QUERY GENERATION ALGORITHM
;; ═══════════════════════════════════════════════════════════════════
(display "═══════════════════════════════════════════════════════════════════\n")
(display "QUERY GENERATION ALGORITHM\n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display "STEP 1: Identify ambiguity and compute what's missing\n")
(display "────────────────────────────────────────────────────────────────\n")
(display " Input: 'I went to the bank'\n")
(display " Ambiguous word: 'bank'\n")
(display " Senses: FINANCIAL (0.75), GEOGRAPHIC (0.20)\n")
(display " Current evidence: ~0 (vagueness HIGH)\n")
(display " Needed: discriminating information\n\n")
(display "STEP 2: Generate discriminating queries\n")
(display "────────────────────────────────────────────────────────────────\n\n")
(display " The system asks itself: 'What would distinguish these senses?'\n\n")
(display " From reverse PMI, it knows:\n")
(display " - If FINANCIAL: should find money/deposit/ATM nearby\n")
(display " - If GEOGRAPHIC: should find river/water/shore nearby\n\n")
(display " So it generates PROBE QUERIES:\n\n")
(display " ┌─────────────────────────────────────────────────────────────┐\n")
(display " │ QUERY 1: Is there mention of money, deposits, or ATMs? │\n")
(display " │ QUERY 2: Is there mention of river, water, or swimming? │\n")
(display " │ QUERY 3: Is this indoor (building) or outdoor (nature)? │\n")
(display " │ QUERY 4: What was the PURPOSE of going to the bank? │\n")
(display " └─────────────────────────────────────────────────────────────┘\n\n")
(display "STEP 3: Execute queries against available sources\n")
(display "────────────────────────────────────────────────────────────────\n\n")
(display " SOURCE 1: Surrounding text (local context)\n")
(display " Execute: GREP for probe-words in ±3 sentences\n")
(display " Result: Found 'river' in previous sentence → GEOGRAPHIC +4.5\n\n")
(display " SOURCE 2: Document metadata\n")
(display " Execute: CHECK document topic/title\n")
(display " Result: Document is 'Nature Walk Journal' → GEOGRAPHIC +2.0\n\n")
(display " SOURCE 3: Knowledge base (if available)\n")
(display " Execute: QUERY 'What do people do at banks by rivers?'\n")
(display " Result: 'sit', 'fish', 'swim', 'picnic' → GEOGRAPHIC frame\n\n")
(display " SOURCE 4: User (if interactive)\n")
(display " Execute: ASK 'Did you go to withdraw money or enjoy nature?'\n")
(display " Result: User says 'to cool my feet in the water' → GEOGRAPHIC\n\n")
;; ═══════════════════════════════════════════════════════════════════
;; QUERY TYPES
;; ═══════════════════════════════════════════════════════════════════
(display "═══════════════════════════════════════════════════════════════════\n")
(display "TYPES OF QUERIES THE SYSTEM CAN GENERATE\n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display "TYPE 1: LEXICAL PROBE\n")
(display "────────────────────────────────────────────────────────────────\n")
(display " Query: 'Are any of these words present: {money, deposit, ATM}?'\n")
(display " Target: Surrounding text, conversation history\n")
(display " Return: Boolean + location of matches\n\n")
(display "TYPE 2: PROPERTY PROBE\n")
(display "────────────────────────────────────────────────────────────────\n")
(display " Query: 'Is the location indoor or outdoor?'\n")
(display " Target: Knowledge base, common sense reasoning\n")
(display " Return: Property value + confidence\n\n")
(display "TYPE 3: FRAME ACTIVATION PROBE\n")
(display "────────────────────────────────────────────────────────────────\n")
(display " Query: 'Which frame is active: FINANCIAL or GEOGRAPHIC?'\n")
(display " Target: Aggregate evidence from all sources\n")
(display " Return: Frame + activation strength\n\n")
(display "TYPE 4: CAUSAL/PURPOSE PROBE\n")
(display "────────────────────────────────────────────────────────────────\n")
(display " Query: 'What was the purpose/reason for going to the bank?'\n")
(display " Target: User, inference from context\n")
(display " Return: Purpose description → maps to sense\n\n")
(display "TYPE 5: CLARIFYING QUESTION (to user)\n")
(display "────────────────────────────────────────────────────────────────\n")
(display " Query: 'When you said bank, did you mean X or Y?'\n")
(display " Target: User/speaker\n")
(display " Return: Direct answer → definitive sense\n\n")
(display "TYPE 6: HYPOTHETICAL PROBE\n")
(display "────────────────────────────────────────────────────────────────\n")
(display " Query: 'If bank=FINANCIAL, what else would we expect to see?'\n")
(display " Target: Knowledge base → generate predictions\n")
(display " Return: Predicted co-occurrences → check against reality\n\n")
;; ═══════════════════════════════════════════════════════════════════
;; WORKED EXAMPLE: ACTIVE QUERY CHAIN
;; ═══════════════════════════════════════════════════════════════════
(display "═══════════════════════════════════════════════════════════════════\n")
(display "WORKED EXAMPLE: Active Query Chain\n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display "INPUT: 'I went to the bank.' (isolated, no context)\n")
(display "VAGUENESS: 0.50 (HIGH) → initiate active query\n\n")
(display "QUERY CHAIN:\n\n")
(display " Q1: LEXICAL PROBE on surrounding text\n")
(display " ────────────────────────────────────────\n")
(display " Execute: Search [-3,+3] sentences for {money,river,deposit,water}\n")
(display " Result: NO MATCHES\n")
(display " Status: Still ambiguous, escalate query\n\n")
(display " Q2: DOCUMENT CONTEXT PROBE\n")
(display " ────────────────────────────────────────\n")
(display " Execute: What is document type/topic?\n")
(display " Result: Document type = 'personal diary', topic = UNKNOWN\n")
(display " Status: Still ambiguous, escalate query\n\n")
(display " Q3: TEMPORAL/ACTIVITY PROBE\n")
(display " ────────────────────────────────────────\n")
(display " Execute: What activities happened before/after?\n")
(display " Result: Before='finished work', After='went home'\n")
(display " Status: 'finished work' slightly favors FINANCIAL (errands)\n")
(display " Evidence: FINANCIAL +1.0 (weak)\n\n")
(display " Q4: HYPOTHETICAL PREDICTION\n")
(display " ────────────────────────────────────────\n")
(display " IF bank=FINANCIAL THEN expect: money, transaction, receipt, balance\n")
(display " IF bank=GEOGRAPHIC THEN expect: water, nature, walking, sitting\n")
(display " Execute: Search for ANY of these in document\n")
(display " Result: Found 'walked' later → slight GEOGRAPHIC signal\n")
(display " Status: Evidence is CONFLICTING, escalate to user\n\n")
(display " Q5: CLARIFYING QUESTION (final escalation)\n")
(display " ────────────────────────────────────────\n")
(display " Generate: 'In this diary entry, when you wrote \"went to the bank\",\n")
(display " did you mean a financial institution or a riverbank?'\n\n")
(display " OR generate MULTIPLE-CHOICE:\n")
(display " 'What kind of bank did you go to?'\n")
(display " (A) A financial bank (to manage money)\n")
(display " (B) A riverbank (to be near water)\n")
(display " (C) Something else\n\n")
;; ═══════════════════════════════════════════════════════════════════
;; THE QUERY GENERATION FORMULA
;; ═══════════════════════════════════════════════════════════════════
(display "═══════════════════════════════════════════════════════════════════\n")
(display "THE QUERY GENERATION FORMULA\n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display " Given: Ambiguous word W with senses S1, S2, ..., Sn\n")
(display " \n")
(display " For each sense Si:\n")
(display " Find words with HIGH PMI to Si but LOW PMI to other senses\n")
(display " These are DISCRIMINATING WORDS for Si\n")
(display " \n")
(display " Generate queries:\n")
(display " 1. LEXICAL: 'Is {discriminating words for S1} present?'\n")
(display " 2. LEXICAL: 'Is {discriminating words for S2} present?'\n")
(display " 3. PROPERTY: 'What properties would Si imply?'\n")
(display " 4. CAUSAL: 'What purpose would make sense for Si?'\n")
(display " \n")
(display " Execute queries in order of COST:\n")
(display " Cheap: Search local context (instant)\n")
(display " Medium: Search knowledge base (fast)\n")
(display " Expensive: Ask user (requires interaction)\n")
(display " \n")
(display " Stop when:\n")
(display " Evidence for one sense >> others (threshold reached)\n")
(display " OR\n")
(display " All queries exhausted → use prior OR maintain ambiguity\n\n")
;; ═══════════════════════════════════════════════════════════════════
;; ATOMSPACE REPRESENTATION
;; ═══════════════════════════════════════════════════════════════════
(display "═══════════════════════════════════════════════════════════════════\n")
(display "ATOMSPACE REPRESENTATION OF QUERIES\n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display "; Store what discriminates sense A from sense B\n")
(display "(Evaluation\n")
(display " (Predicate \"discriminates\")\n")
(display " (List\n")
(display " (Word \"money\") ; This word\n")
(display " (Concept \"bank#fin\") ; discriminates FOR this sense\n")
(display " (Concept \"bank#geo\") ; AGAINST this sense\n")
(display " (Number 7.2))) ; by this much (D-power)\n\n")
(display "; Store query templates\n")
(display "(Define (DefinedSchema \"lexical-probe\")\n")
(display " (Lambda (Variable \"$sense\")\n")
(display " ; Get all discriminating words for this sense\n")
(display " (Bind\n")
(display " (Variable \"$word\")\n")
(display " (Evaluation (Predicate \"discriminates\")\n")
(display " (List (Variable \"$word\") (Variable \"$sense\") ...))\n")
(display " ; Search context for these words\n")
(display " (Evaluation (Predicate \"present-in-context\")\n")
(display " (Variable \"$word\")))))\n\n")
(display "; Execute query and aggregate results\n")
(display "(Define (DefinedSchema \"active-disambiguate\")\n")
(display " (Lambda (Variable \"$ambiguous-word\")\n")
(display " (SequentialOr ; Try queries in order, stop when resolved\n")
(display " ; Try lexical probe first (cheap)\n")
(display " (ExecutionOutput (DefinedSchema \"lexical-probe\") ...)\n")
(display " ; Try knowledge base query (medium cost)\n")
(display " (ExecutionOutput (DefinedSchema \"kb-query\") ...)\n")
(display " ; Generate user question (expensive, last resort)\n")
(display " (ExecutionOutput (DefinedSchema \"generate-question\") ...))))\n\n")
;; ═══════════════════════════════════════════════════════════════════
;; THE BIG PICTURE
;; ═══════════════════════════════════════════════════════════════════
(display "═══════════════════════════════════════════════════════════════════\n")
(display "THE BIG PICTURE: Active Information Seeking\n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display " ┌─────────────────────────────────────────────────────────────┐\n")
(display " │ │\n")
(display " │ The system doesn't just PROCESS text passively. │\n")
(display " │ │\n")
(display " │ It KNOWS WHAT IT DOESN'T KNOW. │\n")
(display " │ │\n")
(display " │ It can GENERATE TARGETED QUERIES to fill gaps. │\n")
(display " │ │\n")
(display " │ The queries are DERIVED from the knowledge structure: │\n")
(display " │ - What distinguishes sense A from sense B? │\n")
(display " │ - What evidence would confirm/deny each hypothesis? │\n")
(display " │ - What's the cheapest way to get that evidence? │\n")
(display " │ │\n")
(display " │ This is ACTIVE LEARNING / ACTIVE PERCEPTION: │\n")
(display " │ The structure tells you where to look. │\n")
(display " │ │\n")
(display " └─────────────────────────────────────────────────────────────┘\n\n")
(display " This is how the system becomes an AGENT:\n")
(display " - It has GOALS (understand the sentence)\n")
(display " - It has BELIEFS (current evidence for each sense)\n")
(display " - It has ACTIONS (generate queries, search, ask)\n")
(display " - It selects actions to achieve goals given beliefs\n\n")
(display " The disambiguation problem becomes a PLANNING problem:\n")
(display " What's the best sequence of queries to resolve ambiguity?\n\n")