Skip to content

CLI: knowledge-mapper sparql — config-driven ANSWER/REACT KB backed by a SPARQL endpoint #19

@DaviddeBest-TNO

Description

@DaviddeBest-TNO

Goal

Add a knowledge-mapper sparql config.yaml subcommand that starts a Knowledge Base with auto-generated ANSWER and REACT handlers, where each handler queries a SPARQL endpoint defined in the config.

Motivation

Simple "read-only" knowledge bases that expose existing SPARQL data to the KE network should require zero Python code — just a config file and one command.

Usage

knowledge-mapper sparql config.yaml

Config structure (sketch)

knowledge_base:
  id: "http://example.org/my-kb"
  name: "my-kb"
  description: "..."
knowledge_engine_endpoint: "http://localhost:8280/rest"
sparql_endpoint: "http://localhost:7200/repositories/myrepo"

knowledge_interactions:
  - name: tree-answer-ki
    type: AnswerKnowledgeInteraction
    prefixes:
      ex: "http://example.org/"
    graph_pattern: "?tree ex:hasHeight ?height ; ex:hasName ?name ."
    sparql_query: "SELECT ?tree ?height ?name WHERE { ?tree a ex:Tree ; ex:hasHeight ?height ; ex:hasName ?name . }"
    # Optional explicit variable mapping (defaults to 1:1 by name):
    # variable_mapping:
    #   tree: tree
    #   height: height

Behaviour

  1. Load and validate the config file using KnowledgeBaseSettings (or a subclass).
  2. For each ANSWER/REACT KI in config: register it with an auto-generated handler that executes the configured SPARQL query, maps result variables to graph pattern variables (implicitly by name, or explicitly via variable_mapping), and returns the binding set.
  3. Register the KB and start the handling loop.
  4. On SIGINT/SIGTERM: unregister and exit cleanly.

Out of scope for this issue

  • ASK and POST interactions (no auto-handler, since they require knowing when to fire).
  • SQL and other data sources (separate issues when the time comes).

Implementation notes

  • Variable mapping: implicit (SPARQL var name == graph pattern var name) by default; explicit mapping optional per KI.
  • Use typer as the CLI framework (same as the run subcommand).
  • Connects to issue Create default handlers for POST and ASK interactions #15 (default handlers) — the auto-generated handler is essentially a default ANSWER/REACT handler backed by SPARQL.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions