Current-graph ontology adapters

The explicit adapter gestaltdb.reasoning.adapters.graph projects one verifiable mutable-state read snapshot. It never reads temporal claims and does not alter Cypher planning, stored labels/edges, typed adjacency or sampler arrays. The Datalog engine imports none of these integrations.

For indexed goal-directed reads over this same mapping and snapshot contract, see Indexed demand over current property graphs. Full projection remains available below. For complete projection with shared generation pins and explicit executor admission, see Current-graph generation admission and execution.

Standalone example. Choose the capability-qualified installation tab below.

Current-graph ontology projection requires an authenticated current snapshot.

1python -m pip install "gestaltdb[lmdb]"
 1from tempfile import TemporaryDirectory
 2from gestaltdb.graphdb import GraphDB, Node, Edge
 3from gestaltdb.ontology import Ontology, SubPropertyOf, compile_ontology
 4from gestaltdb.reasoning import ReasoningLimits
 5from gestaltdb.reasoning.adapters.graph import GraphMapping, PinnedGraphSource
 6
 7plan = compile_ontology(Ontology("relations", [SubPropertyOf("knows", "related")]))
 8with TemporaryDirectory() as directory:
 9    graph = GraphDB.create(directory, backend='lmdb', serializer='json')
10    try:
11        graph.put_nodes([Node("a"), Node("b")])
12        graph.put_edge(Edge("ab", "a", "b", {"type": "KNOWS"}))
13        with graph.current_read_view(require_verifiable=True) as view:
14            with PinnedGraphSource(view, mapping=GraphMapping(
15                edge_types=[("KNOWS", "knows")],
16            )) as source:
17                scoped = source.evaluate(plan, limits=ReasoningLimits())
18        assert scoped.sample_neighbors("a", predicate="related", direction="out",
19                                       fanout=10, seed=1) == ("b",)
20    finally:
21        graph.close()

Mapping and query semantics

GraphMapping(labels=[(label, class_iri)], edge_types=[(type, predicate)], node_properties=[(property_key, predicate)]) is an allowlist. Unmapped fields are ignored. Property values must be single nonempty entity-ID strings; literal coercion, list expansion and edge-attribute statements are not implicit. Node and endpoint IDs remain unchanged. Named labels become RDF type facts. Dangling endpoint IDs are logical constants, not automatically created graph nodes.

scoped.match(...) filters complete logical triples, not graph entities or Cypher rows. scoped.result.explain(fact) works if proofs were collected. The immutable result can outlive its read view; extraction cannot. Keep the view open through evaluation and close sources explicitly. Unsupported backend snapshot identities fail closed. GraphSourceLimits.max_records bounds source records; kernel bounds independently constrain projected facts/closure. Neither bounds the full-state snapshot authentication cost.

Expanded-relation fanout

sample_neighbors requires an explicit derived predicate and direction. It first selects distinct logical endpoints from the completed closure, then samples uniformly without replacement with a local seeded RNG. Parallel edges, multiple inheritance routes and independent proofs do not multiply weights. Fanout zero returns no endpoints; fanout above population returns all endpoints. Self loops can appear if logically entailed. Results are sorted external IDs, not compact sampler IDs, physical edge IDs or paths. A caller can use selected IDs as seeds for a separate asserted-graph sampler, but that sampler’s next hop does not automatically use inferred relations. There is no implicit multi-hop, weighted sampling or Cypher clause rewrite. Use explicit mappings and hierarchy objects where the relevant traversal or query API supports them.

Typed n-ary projection

gestaltdb.reasoning.adapters.typed_graph projects the same snapshot contract to TypedFact values for the generic engine. Beyond the v1 entity-only fields, TypedGraphMapping coerces scalar attributes to Literal values (str/int/float/bool; anything else fails closed), expands list values element-wise under TypedSourceLimits (one fact per element; overruns fail closed, never truncate), and projects edge attributes as n-ary predicate(source, target, value) facts. node_identity=[(label, property)] renames node subjects to a property value; edge endpoints resolve through the same record-to-subject map inside PinnedTypedGraphSource. Two distinct records mapping to one subject is an identity collision: the default identity_collision="error" fails closed and names both records. Pass identity_collision="merge" only for intentional entity resolution; facts then merge, while each projected assertion keeps its own source reference and no logical equivalence is asserted. Every projected fact carries an unambiguous JSON reference such as typed:node-attribute:["a","name"] (list elements append an index); because components are encoded separately, IDs and property names containing : cannot alias. source.context(revision) pins the v3 mapping_id, including the collision policy, so a mapping change yields a new generation token and stale caches cannot match.

Standalone example. Choose the capability-qualified installation tab below.

Property-bearing current-graph projection requires a verifiable mutable snapshot and compatible value encoding.

1python -m pip install "gestaltdb[lmdb]"
 1from gestaltdb.graphdb import GraphDB, Node, Edge
 2from gestaltdb.reasoning import ReasoningLimits
 3from gestaltdb.reasoning.adapters.typed_graph import PinnedTypedGraphSource, TypedGraphMapping
 4from gestaltdb.reasoning.terms import Literal
 5from gestaltdb.reasoning.typed import TypedFact
 6from tempfile import TemporaryDirectory
 7
 8mapping = TypedGraphMapping(edge_types=[("PAYS", "pays")],
 9                            node_attributes=[("age", "age")],
10                            edge_attributes=[("amount", "amount")])
11with TemporaryDirectory() as directory:
12    graph = GraphDB.create(directory, backend='lmdb', serializer='json')
13    try:
14        graph.put_nodes([Node("a", properties={"age": 30}), Node("b")])
15        graph.put_edge(Edge("ab", "a", "b", {"type": "PAYS", "amount": 5}))
16        with graph.current_read_view(require_verifiable=True) as view:
17            with PinnedTypedGraphSource(view, mapping=mapping) as source:
18                evidence = list(source.iter_evidence())
19        facts = [item.fact for item in evidence]
20        assert TypedFact("age", ["a", Literal("integer", 30)]) in facts
21        assert TypedFact("amount", ["a", "b", Literal("integer", 5)]) in facts
22    finally:
23        graph.close()