Read a CycL assertion dump — the s-expression form of an OpenCyc KB — as data.
This is the reader for a corpus that arrives already extracted as text;
vaelii.foreign.units reads the distribution's own binary dump, and both yield the
same maps. A CycL dump is a stream of ke-assert forms, one per assertion:
(ke-assert '(#$genls #$Dog #$Mammal) #$BiologyMt :monotonic :forward)
so each carries a formula, the microtheory it holds in, its strength
(:monotonic / :default — Cyc's own monotonic-vs-default truth value, which is
vaelii's assumption strength under another name) and its direction
(:forward / :backward / :code).
Nothing here interprets CycL: this namespace is the lexer, and
vaelii.foreign.cyc is the translation. Reading is separated because the
dump's syntax is Common Lisp, not EDN — #$Constant is not a reader tag, a
string may span lines, and a float prints as 1.0d0 — so clojure.edn/read
cannot be pointed at it.
How a CycL token comes back. Every kind of token maps to ordinary Clojure data, and the namespace of a symbol is what distinguishes the kinds that would otherwise collide:
| CycL | Clojure | why |
|---|---|---|
#$Dog | cyc/Dog | a KB constant — the only kind translated |
?X | ?X | a variable, already vaelii's spelling |
foo-bar | subl/foo-bar | a bare SubL symbol — executable code, never KB content |
"text" | "text" | |
:keyword | :keyword | |
12, 1.0d0 | 12, 1.0 | |
(a b) | (a b) |
A form the dumper could not resolve reads back as its own marker list —
(:nart 23227), (:unresolved-assertion 88) — and stays that way, for the
translation to reject.
The reader is a lazy seq over a Reader, so a 268 MB dump streams in constant
memory.
Read a CycL assertion dump — the s-expression form of an OpenCyc KB — as data.
This is the reader for a corpus that arrives already extracted as text;
`vaelii.foreign.units` reads the distribution's own binary dump, and both yield the
same maps. A CycL dump is a stream of `ke-assert` forms, one per assertion:
(ke-assert '(#$genls #$Dog #$Mammal) #$BiologyMt :monotonic :forward)
so each carries a **formula**, the **microtheory** it holds in, its **strength**
(`:monotonic` / `:default` — Cyc's own monotonic-vs-default truth value, which is
vaelii's assumption strength under another name) and its **direction**
(`:forward` / `:backward` / `:code`).
Nothing here interprets CycL: this namespace is the *lexer*, and
`vaelii.foreign.cyc` is the translation. Reading is separated because the
dump's syntax is Common Lisp, not EDN — `#$Constant` is not a reader tag, a
string may span lines, and a float prints as `1.0d0` — so `clojure.edn/read`
cannot be pointed at it.
**How a CycL token comes back.** Every kind of token maps to ordinary Clojure
data, and the *namespace* of a symbol is what distinguishes the kinds that would
otherwise collide:
| CycL | Clojure | why |
|----------------|------------------------|----------------------------------------|
| `#$Dog` | `cyc/Dog` | a KB constant — the only kind translated |
| `?X` | `?X` | a variable, already vaelii's spelling |
| `foo-bar` | `subl/foo-bar` | a bare SubL symbol — executable code, never KB content |
| `"text"` | `"text"` | |
| `:keyword` | `:keyword` | |
| `12`, `1.0d0` | `12`, `1.0` | |
| `(a b)` | `(a b)` | |
A form the dumper could not resolve reads back as its own marker list —
`(:nart 23227)`, `(:unresolved-assertion 88)` — and stays that way, for the
translation to reject.
The reader is a lazy seq over a `Reader`, so a 268 MB dump streams in constant
memory.(assertion form)The assertion a top-level (ke-assert FORMULA MT STRENGTH DIRECTION) form
states, as {:formula :mt :strength :direction} — or nil for any other form
(the dumper's license header reads as data too). :direction is nil when the
dump omitted it.
The assertion a top-level `(ke-assert FORMULA MT STRENGTH DIRECTION)` form
states, as `{:formula :mt :strength :direction}` — or nil for any other form
(the dumper's license header reads as data too). `:direction` is nil when the
dump omitted it.(assertions rdr)Every assertion rdr holds, as a lazy seq of assertion maps.
Every assertion `rdr` holds, as a lazy seq of assertion maps.
(constant? x)Is x a CycL constant — a #$Name from the dump?
Is `x` a CycL constant — a `#$Name` from the dump?
(cyc-name x)The Cyc-side name of a constant — cyc/Dog -> "Dog".
The Cyc-side name of a constant — `cyc/Dog` -> "Dog".
(forms rdr)Every top-level form of rdr, as a lazy seq. The reader is left open — the
caller owns it (with-open), because the seq is consumed lazily.
Every top-level form of `rdr`, as a lazy seq. The reader is left open — the caller owns it (`with-open`), because the seq is consumed lazily.
(subl? x)Is x a bare SubL symbol? Those name Lisp code, not knowledge.
Is `x` a bare SubL symbol? Those name Lisp code, not knowledge.
(with-assertions path f)Open the dump file at path, call (f assertions) on a lazy seq of its
assertions, and close the file after. The seq is only valid inside f — it reads
from the open stream — so a caller consumes it there rather than returning it.
Open the dump file at `path`, call `(f assertions)` on a lazy seq of its assertions, and close the file after. The seq is only valid inside `f` — it reads from the open stream — so a caller consumes it there rather than returning it.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |