factgraph
| Kind | kit |
|---|---|
| Categories | data-structures domain-specific |
| Keywords | knowledge-graph facts rules validation data-modeling |
Knowledge graph for modeling facts, rules, and calculations in Kit
Files
| File | Description |
|---|---|
kit.toml | Package manifest with metadata and dependencies |
src/main.kit | Main module - exports all public functions and types |
tests/factgraph.test.kit | Tests for dictionaries, paths, and validation |
examples/basic.kit | Person schema with get/set and paths |
examples/fact-graph.kit | Tax form modeling with nested paths |
LICENSE | MIT license file |
Dependencies
No Kit package dependencies.
Installation
kit add gitlab.com/kit-lang/packages/kit-factgraph.gitUsage
import Kit.FactgraphLicense
MIT License - see LICENSE for details.
Exported Functions & Types
empty-dictionary
Create an empty fact dictionary with metadata
a -> {meta: a, types: Map, facts: Map, calcs: Map}
dict = FactGraph.empty-dictionary {name: "Tax Form", version: "1.0"}empty
Create an empty fact graph with a dictionary
a -> {dict: a, data: Map, errors: List}
graph = FactGraph.empty dictmake-type
Create a type definition
String -> String -> TypeDef
int-type = FactGraph.make-type "PositiveInt" "Int"add-type
Add a type definition to a dictionary
{meta: a, types: Map, facts: Map, calcs: Map} -> String -> TypeDef -> {meta: a, types: Map, facts: Map, calcs: Map}
dict = dict |> FactGraph.add-type "Money" (FactGraph.make-type "Money" "Float")make-fact
Create a required fact definition
String -> FactDef
age-fact = FactGraph.make-fact "Int"make-optional-fact
Create an optional fact
String -> FactDef
status-fact = FactGraph.make-optional-fact "String"add-fact
Add a fact definition to a dictionary
{meta: a, types: Map, facts: Map, calcs: Map} -> String -> FactDef -> {meta: a, types: Map, facts: Map, calcs: Map}
dict = dict |> FactGraph.add-fact "/person/age" age-factadd-calculation
Add a calculation (derived fact) to a dictionary
{meta: a, types: Map, facts: Map, calcs: Map} -> String -> (b -> c) -> {meta: a, types: Map, facts: Map, calcs: Map}
dict = dict |> FactGraph.add-calculation "/total" (fn(graph) => ...)is-calculated?
Check if a path is a calculated fact
{calcs: Map, ..} -> String -> Bool
is-calc = FactGraph.is-calculated? dict "/total"split-path
Split a path like "/person/age" into parts ["person", "age"]
String -> List String
parts = FactGraph.split-path "/person/age"
# parts = ["person", "age"]get
Get a value from the fact graph at the given path
{data: Map, ..} -> String -> a
age = FactGraph.get graph "/person/age"set
Set a value in the fact graph at the given path
{dict: a, data: Map, errors: List} -> String -> b -> {dict: a, data: Map, errors: List}
graph = FactGraph.set graph "/person/age" 30get-at-path
Get a value at a nested path in a map
Map String a -> String -> a
set-at-path
Set a value at a nested path in a map
Map String a -> String -> a -> Map String a
paths
Get all paths in the fact graph data
{data: Map, ..} -> List String
all-paths = FactGraph.paths graphdictionary
Get the dictionary from a fact graph
{dict: a, ..} -> a
dict = FactGraph.dictionary graphdata
Get the data map from a fact graph
{data: a, ..} -> a
data = FactGraph.data graphhas-errors?
Check if the fact graph has validation errors
{errors: List, ..} -> Bool
has-errors = FactGraph.has-errors? graphget-errors
Get all validation errors from the fact graph
{errors: a, ..} -> a
errors = FactGraph.get-errors graphto-map
Convert fact graph data to a plain map (for serialization)
{data: a, ..} -> a
map = FactGraph.to-map graphfrom-map
Create a fact graph from a dictionary and a plain map
a -> Map -> {dict: a, data: Map, errors: List}
graph = FactGraph.from-map dict saved-datais-valid-type?
Check if a value matches a type definition
String -> a -> Bool
valid = FactGraph.is-valid-type? "Int" 42is-valid-fact?
Check if a fact value is valid against its definition in the graph
{dict: {facts: Map, ..}, ..} -> String -> a -> Bool
result = FactGraph.is-valid-fact? graph "/person/age" 30