FactBase
type (joe
)
A FactBase is an in-memory database of Nero Fact
values.
The database can be updated and queried using Nero
FactBase
values.
- factBase.add(fact) → this
- factBase.addAll(facts) → this
- factBase.all() → Set
- factBase.clear() → this
- factBase.filter(predicate) → Set
- factBase.isDebug() → Boolean
- factBase.isEmpty() → Boolean
- factBase.map(func) → Set
- factBase.relation(relation) → Set
- factBase.relations() → Set
- factBase.remove(fact) → this
- factBase.removeAll(facts) → this
- factBase.removeIf(predicate) → this
- factBase.removeRelation(name) → this
- factBase.renameRelation(oldName, newName) → this
- factBase.select(rules) → Set
- factBase.setDebug(flag) → this
- factBase.size() → Number
- factBase.toNero() → String
- factBase.toString() → String
- factBase.update(rules) → this
Input/Output
Subject to particular constraints, the contents of a FactBase can
be output as a Nero script via the
FactBase.asNero()
and toNero()
methods, and later read back in via the
FactBase.fromNero()
method.
The constraints are (currently) as follows:
- All facts must be ordered
- All field values must be scalar values representable as Joe literals.
Static Methods
FactBase.asNero()
FactBase.asNero(facts) → String
Given a set of facts, outputs the facts as a script of Nero axioms subject to certain constraints.
The facts value can be a FactBase or a collection of values
to be converted to facts. Throws an Error
if any value cannot
be used as a Fact
.
FactBase.fromNero()
FactBase.fromNero(script) → FactBase
Given a Nero script, executes the script and returns a FactBase containing all known facts.
FactBase Initializer
FactBase([facts]) → FactBase
Creates an FactBase, optionally populating it with the given facts.
The facts value can be a FactBase or a collection of values
to be converted to facts. Throws an Error
if any value cannot
be used as a Fact
.
Methods
factBase.add()
factBase.add(fact) → this
Adds a single value to the database as a Fact
. Throws an
Error
if the value cannot be used as a Fact
.
factBase.addAll()
factBase.addAll(facts) → this
Adds a collection of values to the database as Fact
values.
The facts value can be a FactBase or a collection of values
to be converted to facts. Throws an Error
if any value cannot
be used as a Fact
.
Note: adding the contents of another FactBase is much faster than adding an arbitrary collection.
factBase.all()
factBase.all() → Set
Returns a read-only Set
of all facts in the database.
factBase.clear()
factBase.clear() → this
Clears the database of all content.
factBase.filter()
factBase.filter(predicate) → Set
Returns a set containing the elements for which the filter predicate is true.
factBase.isDebug()
factBase.isDebug() → Boolean
Returns the database's debug flag.
factBase.isEmpty()
factBase.isEmpty() → Boolean
Returns true if the database is empty, and false otherwise.
factBase.map()
factBase.map(func) → Set
Returns a set containing the items that result from applying function func to each item in this set.
factBase.relation()
factBase.relation(relation) → Set
Returns a read-only Set
of all facts in the database that
have the given relation.
factBase.relations()
factBase.relations() → Set
Returns a read-only Set
of the names of the relations
of the facts in the database.
factBase.remove()
factBase.remove(fact) → this
Deletes a single Fact
from the database.
factBase.removeAll()
factBase.removeAll(facts) → this
Deletes a collection of facts from the database. The facts value can be a FactBase or a collection of values to be converted to facts.
factBase.removeIf()
factBase.removeIf(predicate) → this
Deletes facts matching the predicate from the database.
factBase.removeRelation()
factBase.removeRelation(name) → this
Deletes an entire relation from the database.
factBase.renameRelation()
factBase.renameRelation(oldName, newName) → this
Renames a relation, replacing any existing relation that has the new name.
factBase.select()
factBase.select(rules) → Set
Queries the database using the Nero rules and returns all inferred
facts. If the rule set contains export
directives then the relevant
facts will be exported as domain values. The database itself
is not modified.
factBase.setDebug()
factBase.setDebug(flag) → this
Sets the database's debug flag. If enabled,
update()
and
select()
will output a
detailed Nero execution trace.
factBase.size()
factBase.size() → Number
Returns the number of facts in the database.
factBase.toNero()
factBase.toNero() → String
Returns a Nero script containing the database items as Nero axioms.
factBase.toString()
factBase.toString() → String
Returns the value's string representation.
factBase.update()
factBase.update(rules) → this
Updates the database using the Nero rules. Inferred facts
are added to the database and then returned to the caller.
It is an error if the rule set contains export
directives.