Python
Predicate
Predicate class and public members in the unified Python API.| Used by | Engine.register_domain |
|---|
Class: Predicate
A Predicate names a relation, fixes its arity and declares its fact origin and query permission.
- constructor
Predicate(name, arity, flags)Creates an immutable predicate declaration from its name, arity and integer flags. Combine a fact origin with optional PRED_QUERY using |; engine.register_domain() validates and registers the declaration before rules are loaded.
- factory
Predicate.edb()Constructs a declaration for a predicate whose facts come from runtime request input. Creating this value does not register it with the engine.
- factory
Predicate.edb_query()Constructs a runtime-input predicate declaration with query permission, so callers may test its facts in a result.
- factory
Predicate.idb()Constructs a declaration for a predicate whose facts are derived by policy rules, without enabling public queries.
- factory
Predicate.idb_query()Constructs a derived-predicate declaration with query permission, so callers may inspect the relation after solving.
- factory
Predicate.policy_fact()Constructs a declaration for a predicate whose ground facts may be written directly in policy source.
- factory
Predicate.policy_fact_query()Constructs a policy-source fact declaration with query permission, so callers may test those facts in a result.
Constructor: Predicate()
Predicate(
name: str,
arity: int,
flags: int
) -> PredicatePredicateReturns an immutable Predicate declaration.
Factories
The six class methods below each construct a new immutable declaration. They do not register the domain.
Each factory has its own signature, arguments, return behavior and stable link.
Predicate.edb
Predicate.edb(
name: str,
arity: int
) -> PredicatePredicateReturns a new immutable Predicate with PRED_EDB; it does not register the domain.
predicate = Predicate.edb("owns", 2)
print(predicate)Predicate(name='owns', arity=2, flags=1)
Predicate.edb_query
Predicate.edb_query(
name: str,
arity: int
) -> PredicatePredicateReturns a new immutable Predicate with PRED_EDB | PRED_QUERY; it does not query or register anything.
predicate = Predicate.edb_query("owns", 2)
print(predicate)Predicate(name='owns', arity=2, flags=5)
Predicate.idb
Predicate.idb(
name: str,
arity: int
) -> PredicatePredicateReturns a new immutable Predicate with PRED_IDB; it does not evaluate rules.
predicate = Predicate.idb("allow", 2)
print(predicate)Predicate(name='allow', arity=2, flags=2)
Predicate.idb_query
Predicate.idb_query(
name: str,
arity: int
) -> PredicatePredicateReturns a new immutable Predicate with PRED_IDB | PRED_QUERY; it does not run a query.
predicate = Predicate.idb_query("allow", 2)
print(predicate)Predicate(name='allow', arity=2, flags=6)
Predicate.policy_fact
Predicate.policy_fact(
name: str,
arity: int
) -> PredicatePredicateReturns a new immutable Predicate with PRED_POLICY_FACT; it does not add a fact.
predicate = Predicate.policy_fact("trusted", 1)
print(predicate)Predicate(name='trusted', arity=1, flags=8)
Predicate.policy_fact_query
Predicate.policy_fact_query(
name: str,
arity: int
) -> PredicatePredicateReturns a new immutable Predicate with PRED_POLICY_FACT | PRED_QUERY; it does not add or query a fact.
predicate = Predicate.policy_fact_query("trusted", 1)
print(predicate)Predicate(name='trusted', arity=1, flags=12)
Constants
These integer constants come from the CFFI extension's public C constants; they are not callable builders. See the cards below for their values and roles, and the usage examples for explicit declarations and factories.
PRED_EDB · PRED_IDB · PRED_QUERY · PRED_POLICY_FACT.
PRED_EDB
Runtime input facts supplied in the EDB for one evaluation.
1 (int)
PRED_IDB
Facts derived by policy rules.
2 (int)
PRED_QUERY
Permission to observe a predicate through the query API; not a fact origin by itself.
4 (int)
PRED_POLICY_FACT
Base facts written in trusted policy source.
8 (int)