Skip to main content

Crate gollum_kb_oc

Crate gollum_kb_oc 

Source
Expand description

gollum-kb-oc — OpenCypher / GQLite knowledge-base backend for Gollum.

Implements gollum_kb::KnowledgeBase and gollum_kb::FactProvider on top of GQLite, an embeddable graph database that speaks OpenCypher.

§Schema

Each Gollum predicate name/N is stored as a labelled node:

CREATE (:parent {_arity: 2, arg0: 'alice', arg1: 'bob'})

Reasoning metadata (probability, temporal interval, modal annotation, …) is stored as additional reserved properties prefixed with _. See translator for the full schema reference.

§Example

use gollum_ir::{IrClause, IrQuery, IrTerm};
use gollum_kb::KnowledgeBase;
use gollum_kb_oc::GqliteKb;
use futures::StreamExt as _;

let mut kb = GqliteKb::new_in_memory()?;

// Store a fact: parent(alice, bob)
kb.assert_fact(IrClause {
    head: IrTerm::Structure {
        name: "parent".into(),
        args: vec![IrTerm::Atom("alice".into()), IrTerm::Atom("bob".into())],
    },
    body: vec![],
    metadata: None,
}).await?;

// Query: parent(X, bob)
let mut stream = kb.query(&IrQuery {
    goal: IrTerm::Structure {
        name: "parent".into(),
        args: vec![IrTerm::Var("X".into()), IrTerm::Atom("bob".into())],
    },
    metadata: None,
}).await?;

while let Some(Ok(sol)) = stream.next().await {
    println!("X = {:?}", sol.get("X"));
}

Re-exports§

pub use async_pred::GqliteAsyncPredicate;
pub use error::OcError;
pub use kb::GqliteKb;
pub use translator::SchemaMode;

Modules§

async_pred
AsyncPredicate adapter that wraps a single name/arity stored in a GqliteKb and exposes it to the WAM interpreter.
error
Error type for the OpenCypher / GQLite knowledge-base backend.
kb
GqliteKb — a KnowledgeBase + FactProvider backed by GQLite.
mapper
Conversion from GQLite graphcore::Value and Table to Gollum IR types.
translator
IrClause / IrTerm → Cypher string generation.