| |
- CyclicSetOfRules
- exceptions.Exception
-
- BuiltInFailed
- InferenceTask
- Query
- Rule
- formula.StoredStatement
-
- QueryItem
class CyclicSetOfRules |
|
A set of rules which are connected |
|
Methods defined here:
- __getitem__(self, i)
- __init__(self, rules)
- __repr__(self)
- run(self)
- Run a cyclic subset of the rules
Data and non-method functions defined here:
- __doc__ = 'A set of rules which are connected\n '
- __module__ = 'query'
|
class InferenceTask |
|
A task of applying rules or filters to information |
|
Methods defined here:
- __init__(self, workingContext, ruleFormula=None, targetContext=None, universals=[], mode='', why=None, repeat=0)
- Apply rules in one context to the same or another
A rule here is defined by log:implies, which associates the template (premise, precondidtion,
antecedent) to the conclusion (postcondition).
- gatherQueries(self, ruleFormula)
- Find a set of rules in N3QL
- gatherRules(self, ruleFormula)
- run(self)
- Perform task.
Return number of new facts
- runLaborious(self)
- Perform task.
Return number of new facts.
Start again if new rule mayhave been generated.
- runSmart(self)
- Run the rules by mapping rule interactions first
Data and non-method functions defined here:
- __doc__ = 'A task of applying rules or filters to information'
- __module__ = 'query'
|
class Query |
|
A query holds a hypothesis/antecedent/template which is being matched aginst (unified with)
the knowledge base. |
|
Methods defined here:
- __init__(self, store, unmatched=[], template=None, variables=[], existentials=[], workingContext=None, conclusion=None, targetContext=None, already=None, rule=None, smartIn=[], justOne=0, mode='', meta=None)
- checkRedirectsInAlready(self)
- Kludge
- conclude(self, bindings, evidence=[])
- When a match found in a query, add conclusions to target formula.
Returns the number of statements added.
- redirect(self, redirections)
- remoteQuery(query, items)
- Perform remote query as client on remote store
Currently this only goes to an SQL store, but should later use RDFQL/DAMLQL etc
in remote HTTP/SOAP call.
- resolve(self)
- unify(query, queue, variables, existentials, bindings={}, newBindings={}, evidence=[])
- Iterate on the remaining query items
bindings collected matches already found
newBindings matches found and not yet applied - used in recursion
You probably really need the state diagram to understand this
http://www.w3.org/2000/10/swap/doc/states.svg
even if it is a bit out of date.
Data and non-method functions defined here:
- __doc__ = 'A query holds a hypothesis/antecedent/template w...hed aginst (unified with)\n the knowledge base.'
- __module__ = 'query'
|
class QueryItem(formula.StoredStatement) |
|
One line in a query being resolved.
To a large extent, each line can keep track of its own state.
When a remote query is done, query lines to the same server have to be coordinated again. |
|
Methods defined here:
- __init__(self, query, quad)
- __repr__(self)
- Diagnostic string only
- bindNew(self, newBindings)
- Take into account new bindings from query processing to date
The search may get easier, and builtins may become ready to run.
Lists may either be matched against store by searching,
and/or may turn out to be bound and therefore ready to run.
Return:
0 No way can this item ever complete.
None Binding done, see item.state
- canRun(self)
- Is this built-in ready to run?
- clone(self)
- Take a copy when for iterating on a query
- searchDone(self)
- Search has been done: figure out next state.
- setup(self, allvars, unmatched, smartIn=[], mode='')
- Check how many variables in this term,
and how long it would take to search
Returns, [] normally or 0 if there is no way this query will work.
Only called on virgin query item.
The mode is a set of character flags about how we think.
- tryBuiltin(self, queue, bindings, heavy, evidence)
- Check for built-in functions to see whether it will resolve.
Return codes: 0 - give up;
[] - success, no new bindings, (action has been called)
[...] list of binding lists, each a pair of bindings and reason.
- tryDeepSearch(self)
- Search the store, matching nested compound structures
Returns lists of list of bindings, attempting if necessary to unify
any nested compound terms. Added 20030810, not sure whether it is worth the
execution time in practice. It could be left to a special magic built-in like "matches"
or something if it is only occasionnaly used.
Used in state S_NEED_DEEP
Data and non-method functions defined here:
- __doc__ = 'One line in a query being resolved.\n \n To ...he same server have to be coordinated again.\n '
- __module__ = 'query'
Methods inherited from formula.StoredStatement:
- __getitem__(self, i)
- __len__(self)
- asFormula(self, why=None)
- The formula which contains only a statement like this.
When we split the statement up, we lose information in any existentials which are
shared with other statements. So we introduce a skolem constant to tie the
statements together. We don't have access to any enclosing formula
so we can't express its quantification. This @@ not ideal.
This extends the StoredStatement class with functionality we only need with "why" module.
- comparePredObj(self, other)
- Just compare P and OBJ, others the same
- compareSubjPredObj(self, other)
- Just compare SUBJ, Pred and OBJ, others the same
Avoid loops by spotting reference to containing formula
- context(self)
- Return the context of the statement
- object(self)
- Return the object of the statement
- predicate(self)
- Return the predicate of the statement
- spo(self)
- statements(self)
- subject(self)
- Return the subject of the statement
|
class Rule |
|
|
|
Methods defined here:
- __init__(self, task, antecedent, consequent, statement, variables)
- Try a rule
Beware lists are corrupted. Already list is updated if present.
The idea is that, for a rule which may be tried many times, the constant
processing is done in this rather than in Query().
- __repr__(self)
- compareByAffects(other)
- once(self)
- traceForward(self, r1)
Data and non-method functions defined here:
- __doc__ = None
- __module__ = 'query'
| |