<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How-to guides on factgraph</title><link>http://factgraph.docs.symbolic-intelligence.de/docs/how-to/</link><description>Recent content in How-to guides on factgraph</description><generator>Hugo</generator><language>en-us</language><copyright>[© CC BY 4.0](https://creativecommons.org/licenses/by/4.0/legalcode)</copyright><atom:link href="http://factgraph.docs.symbolic-intelligence.de/docs/how-to/index.xml" rel="self" type="application/rss+xml"/><item><title>Define a schema</title><link>http://factgraph.docs.symbolic-intelligence.de/docs/how-to/define-a-schema/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>http://factgraph.docs.symbolic-intelligence.de/docs/how-to/define-a-schema/</guid><description>&lt;h1 id="how-to-define-a-schema"&gt;How to define a schema&lt;a class="anchor" href="#how-to-define-a-schema"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;This guide shows you how to declare entity types with identity and fields in Python and build a &lt;code&gt;FactGraph&lt;/code&gt; from them, which is the first step before you write or read any facts.&lt;/p&gt;
&lt;h2 id="prerequisites"&gt;Prerequisites&lt;a class="anchor" href="#prerequisites"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;factgraph&lt;/code&gt; package installed (v0.2.0).&lt;/li&gt;
&lt;li&gt;The public symbols &lt;code&gt;Entity&lt;/code&gt;, &lt;code&gt;Identity&lt;/code&gt;, &lt;code&gt;Field&lt;/code&gt;, and &lt;code&gt;FactGraph&lt;/code&gt;, all importable from &lt;code&gt;factgraph.sdk&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="steps"&gt;Steps&lt;a class="anchor" href="#steps"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Declare an entity type by subclassing &lt;code&gt;Entity&lt;/code&gt;. Annotate each member with a Python type and assign either an &lt;code&gt;Identity()&lt;/code&gt; or a &lt;code&gt;Field()&lt;/code&gt; descriptor. Every entity must declare at least one &lt;code&gt;Identity()&lt;/code&gt; member; the metaclass raises &lt;code&gt;SDKSchemaError&lt;/code&gt; with the message &lt;code&gt;Entity '&amp;lt;name&amp;gt;' must declare at least one Identity field&lt;/code&gt; otherwise.&lt;/p&gt;</description></item><item><title>Write and read facts</title><link>http://factgraph.docs.symbolic-intelligence.de/docs/how-to/write-and-read-facts/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>http://factgraph.docs.symbolic-intelligence.de/docs/how-to/write-and-read-facts/</guid><description>&lt;h1 id="how-to-write-and-read-facts"&gt;How to write and read facts&lt;a class="anchor" href="#how-to-write-and-read-facts"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;This guide shows you how to create an entity, write single- and multi-valued field facts onto it, and read those values back, either through an entity snapshot or directly by field. Use it once you have a schema and a &lt;code&gt;FactGraph&lt;/code&gt; instance and want to populate and inspect data.&lt;/p&gt;
&lt;h2 id="prerequisites"&gt;Prerequisites&lt;a class="anchor" href="#prerequisites"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;code&gt;FactGraph&lt;/code&gt; instance built from your schema classes. See &lt;a href="http://factgraph.docs.symbolic-intelligence.de/docs/how-to/define-a-schema/"&gt;How to define a schema&lt;/a&gt; and the &lt;a href="http://factgraph.docs.symbolic-intelligence.de/docs/reference/factgraph/"&gt;factgraph reference&lt;/a&gt; for constructor options.&lt;/li&gt;
&lt;li&gt;Each schema class declares at least one &lt;code&gt;Identity()&lt;/code&gt; field and zero or more &lt;code&gt;Field()&lt;/code&gt; fields. See the &lt;a href="http://factgraph.docs.symbolic-intelligence.de/docs/reference/schema/"&gt;schema reference&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The examples below use this schema:&lt;/p&gt;</description></item><item><title>Find and match entities</title><link>http://factgraph.docs.symbolic-intelligence.de/docs/how-to/find-and-match-entities/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>http://factgraph.docs.symbolic-intelligence.de/docs/how-to/find-and-match-entities/</guid><description>&lt;h1 id="how-to-find-and-match-entities"&gt;How to find and match entities&lt;a class="anchor" href="#how-to-find-and-match-entities"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;This guide shows you how to read entities back out of a &lt;code&gt;FactGraph&lt;/code&gt;: filter them by exact field values with &lt;code&gt;fg.entities.where&lt;/code&gt;, and select them by a rule or rule-expression pattern (with port constraints) using &lt;code&gt;fg.entities.match&lt;/code&gt;. Both return a tuple/list of read-only &lt;code&gt;EntitySnapshot&lt;/code&gt; objects.&lt;/p&gt;
&lt;h2 id="prerequisites"&gt;Prerequisites&lt;a class="anchor" href="#prerequisites"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;code&gt;FactGraph&lt;/code&gt; with a registered schema and some entities written to it. See &lt;a href="http://factgraph.docs.symbolic-intelligence.de/docs/how-to/define-a-schema/"&gt;How to define a schema&lt;/a&gt; and &lt;a href="http://factgraph.docs.symbolic-intelligence.de/docs/how-to/write-and-read-facts/"&gt;How to write and read facts&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;Entity&lt;/code&gt; subclasses you query with must be the same classes you registered.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Both verbs require an &lt;code&gt;Entity&lt;/code&gt; subclass as the first positional argument. Passing a string, a &lt;code&gt;Field&lt;/code&gt; descriptor, or any other type raises &lt;code&gt;SDKStoreError&lt;/code&gt; (the Layer 1 navigation key check, ADR-API §4.1.1).&lt;/p&gt;</description></item><item><title>Evaluate a rule and read the proof</title><link>http://factgraph.docs.symbolic-intelligence.de/docs/how-to/evaluate-a-rule-and-read-the-proof/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>http://factgraph.docs.symbolic-intelligence.de/docs/how-to/evaluate-a-rule-and-read-the-proof/</guid><description>&lt;h1 id="how-to-evaluate-a-rule-and-read-its-proof"&gt;How to evaluate a rule and read its proof&lt;a class="anchor" href="#how-to-evaluate-a-rule-and-read-its-proof"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;This guide shows you how to build a rule with &lt;code&gt;build_application_rule&lt;/code&gt;, run it against a graph, and read the proof behind each result row, for when you need both the answer and a human-readable account of why it holds.&lt;/p&gt;
&lt;h2 id="prerequisites"&gt;Prerequisites&lt;a class="anchor" href="#prerequisites"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;code&gt;FactGraph&lt;/code&gt; with the facts your rule body needs. Field atoms such as &lt;code&gt;User(u).status == &amp;quot;active&amp;quot;&lt;/code&gt; match field claims written by &lt;code&gt;fg.fields.set&lt;/code&gt;. See &lt;a href="http://factgraph.docs.symbolic-intelligence.de/docs/how-to/write-and-read-facts/"&gt;How to write and read facts&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Be aware of how existence atoms compile. An existence atom such as &lt;code&gt;User(u)&lt;/code&gt; lowers to the &lt;code&gt;User:exists&lt;/code&gt; predicate, and a field atom like &lt;code&gt;User(u).status == &amp;quot;active&amp;quot;&lt;/code&gt; lowers to &lt;em&gt;both&lt;/em&gt; the &lt;code&gt;User:exists&lt;/code&gt; predicate and the field predicate. So any rule body that mentions an entity variable carries an implicit &lt;code&gt;User:exists&lt;/code&gt; requirement. &lt;code&gt;fg.entities.create(...)&lt;/code&gt; emits only the entity&amp;rsquo;s identity claims; it does not emit a &lt;code&gt;:exists&lt;/code&gt; claim (the &lt;code&gt;:exists&lt;/code&gt; co-emission is transitional and not performed by the current write path, see the guard note in &lt;code&gt;factgraph.sdk.store&lt;/code&gt;). A rule body that relies on existence therefore will not match entities created through the SDK write path until a &lt;code&gt;:exists&lt;/code&gt; claim is present for them.&lt;/li&gt;
&lt;li&gt;The rule-authoring imports come from &lt;code&gt;factgraph.sdk.dsl&lt;/code&gt;. The schema base classes (&lt;code&gt;Entity&lt;/code&gt;, &lt;code&gt;Identity&lt;/code&gt;, &lt;code&gt;Field&lt;/code&gt;) come from &lt;code&gt;factgraph.sdk&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="steps"&gt;Steps&lt;a class="anchor" href="#steps"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Define a schema and create the entities the rule will match. &lt;code&gt;create&lt;/code&gt; emits the identity claims for the entity; &lt;code&gt;fg.fields.set&lt;/code&gt; adds field claims.&lt;/p&gt;</description></item><item><title>Choose a reasoning engine</title><link>http://factgraph.docs.symbolic-intelligence.de/docs/how-to/choose-a-reasoning-engine/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>http://factgraph.docs.symbolic-intelligence.de/docs/how-to/choose-a-reasoning-engine/</guid><description>&lt;h1 id="how-to-choose-a-reasoning-engine"&gt;How to choose a reasoning engine&lt;a class="anchor" href="#how-to-choose-a-reasoning-engine"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;This guide shows you how to pick and configure the engine that evaluates a rule, when the default boolean answer is not enough and you need a probabilistic or possibilistic verdict instead.&lt;/p&gt;
&lt;p&gt;You select the engine on the call, not on the graph: every &lt;code&gt;fg.eval.evaluate(...)&lt;/code&gt; and &lt;code&gt;fg.eval.explain(...)&lt;/code&gt; call takes an &lt;code&gt;engine=&lt;/code&gt; keyword, and the probabilistic and possibilistic engines additionally take a &lt;code&gt;config=&lt;/code&gt; wrapper. The same rule and the same facts can be evaluated under any supported engine.&lt;/p&gt;</description></item><item><title>Persist and reload a workspace</title><link>http://factgraph.docs.symbolic-intelligence.de/docs/how-to/persist-and-reload-a-workspace/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>http://factgraph.docs.symbolic-intelligence.de/docs/how-to/persist-and-reload-a-workspace/</guid><description>&lt;h1 id="how-to-persist-and-reload-a-workspace"&gt;How to persist and reload a workspace&lt;a class="anchor" href="#how-to-persist-and-reload-a-workspace"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;This guide shows you how to save a &lt;code&gt;FactGraph&lt;/code&gt; ledger to disk as a durable workspace and reload it later under the matching schema. Use it when a graph must outlive the process that built it, for example to hand a ledger to a separate read or evaluation step.&lt;/p&gt;
&lt;p&gt;A workspace is a directory holding the ledger (&lt;code&gt;ledger.db&lt;/code&gt;), a schema object under &lt;code&gt;db/&lt;/code&gt;, and a manifest (&lt;code&gt;factgraph_workspace.json&lt;/code&gt;). Reload validates the stored schema digest against the &lt;code&gt;Entity&lt;/code&gt; classes you supply, so the same classes that created the workspace must be available at load time. For the full surface and manifest layout, see &lt;a href="http://factgraph.docs.symbolic-intelligence.de/docs/reference/persistence/"&gt;Persistence: workspaces and attach&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Trace and audit a fact</title><link>http://factgraph.docs.symbolic-intelligence.de/docs/how-to/trace-and-audit-a-fact/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>http://factgraph.docs.symbolic-intelligence.de/docs/how-to/trace-and-audit-a-fact/</guid><description>&lt;h1 id="how-to-trace-and-audit-a-fact"&gt;How to trace and audit a fact&lt;a class="anchor" href="#how-to-trace-and-audit-a-fact"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;This guide shows you how to start from a fact you already hold (its assertion id or &lt;code&gt;AssertionRecord&lt;/code&gt;), read the provenance recorded on it, and inspect which value the runtime chose for that entity field cell, including when several active assertions compete.&lt;/p&gt;
&lt;h2 id="prerequisites"&gt;Prerequisites&lt;a class="anchor" href="#prerequisites"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;code&gt;FactGraph&lt;/code&gt; (alias &lt;code&gt;SDKStore&lt;/code&gt;) with a registered schema and at least one written field assertion.&lt;/li&gt;
&lt;li&gt;The assertion id of the fact, or an &lt;code&gt;AssertionRecord&lt;/code&gt; for it. Field writes return the assertion id: &lt;code&gt;fg.fields.set(...)&lt;/code&gt; and &lt;code&gt;fg.fields.add(...)&lt;/code&gt; both return a &lt;code&gt;str&lt;/code&gt; asrt_id. If you only have the entity and field, see step 1 for how to recover the id.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The examples use this schema and a single written cell:&lt;/p&gt;</description></item></channel></rss>