check (version Id: check.py,v 1.59 2007/06/26 02:36:15 syosi Exp )
index
/Users/yosi/CVSROOT/WWW/2000/10/swap/check.py

Check a proof
 
This is a simple proof checker.  It hasn't itself been proved,
and there are probably lots of ways to fool it especially as a deliberate
malicious attack. That is because there are simple things I may have forgotten
to check.
 
Command line options for debug:
 -v50   Set verbosity to 50 (range is 0 -100)
 -c50   Set verbosity for inference done by cwm code to 50
 -p50   Set verobsity when parsing top 50    
 
@@for more command line options, see main() in source

 
Modules
       
swap.diag
swap
sys

 
Classes
       
__builtin__.object
FormulaCache
Checker
Policy
AllPremises
Assumption
ParsingOK
exceptions.Exception
InvalidProof
LogicalFallacy
PolicyViolation

 
class AllPremises(Policy)
    A useful testing policy is to accept all premises and no sources.
 
 
Method resolution order:
AllPremises
Policy
__builtin__.object

Methods defined here:
__init__(self)
assumes(self, f)
documentOK(self, f)

Data and other attributes inherited from Policy:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Policy' objects>
list of weak references to the object (if defined)

 
class Assumption(Policy)
    
Method resolution order:
Assumption
Policy
__builtin__.object

Methods defined here:
__init__(self, premise)
assumes(self, f)
documentOK(self, u)

Data and other attributes inherited from Policy:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Policy' objects>
list of weak references to the object (if defined)

 
class Checker(FormulaCache)
    
Method resolution order:
Checker
FormulaCache
__builtin__.object

Methods defined here:
__init__(self, proof)
proof   is the formula which contains the proof
checkParsing(self, r, f, policy, level)
conjecture(self)
return the formula that is claimed to be proved and
the main justification step.
report(self, out, f=None, step=None)
result(self, r, policy, level=0)
Get the result of a proof step.
 
r       is the step to be checked; in the case of the root reason,
        proof.the(pred=rdf.type, obj=reason.Proof),
        as from `proofStep()`
 
level   is just the nesting level for diagnostic output
 
Returns the formula proved
raises InvalidProof (perhaps IOError, others)

Methods inherited from FormulaCache:
get(self, uri)

Data and other attributes inherited from FormulaCache:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'FormulaCache' objects>
list of weak references to the object (if defined)

 
class FormulaCache(__builtin__.object)
     Methods defined here:
__init__(self)
get(self, uri)

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'FormulaCache' objects>
list of weak references to the object (if defined)

 
class InvalidProof(exceptions.Exception)
     Methods defined here:
__init__(self, s, level=0)
__str__(self)

Methods inherited from exceptions.Exception:
__getitem__(...)

 
class LogicalFallacy(InvalidProof)
    
Method resolution order:
LogicalFallacy
InvalidProof
exceptions.Exception

Methods inherited from InvalidProof:
__init__(self, s, level=0)
__str__(self)

Methods inherited from exceptions.Exception:
__getitem__(...)

 
class ParsingOK(Policy)
    When run from the command-line, the policy is that
all Parsing's are OK.
 
Hmm... shouldn't it be only those that are mentioned
in the CommandLine step?
 
 
Method resolution order:
ParsingOK
Policy
__builtin__.object

Methods defined here:
assumes(self, f)
documentOK(self, u)

Data and other attributes inherited from Policy:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Policy' objects>
list of weak references to the object (if defined)

 
class Policy(__builtin__.object)
    a proof-checking policy
 
  Methods defined here:
assumes(self, f)
Check whether a formula is an axiom.
 
Hmm... move checkBuiltin here?
documentOK(self, u)

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Policy' objects>
list of weak references to the object (if defined)

 
class PolicyViolation(InvalidProof)
    
Method resolution order:
PolicyViolation
InvalidProof
exceptions.Exception

Methods inherited from InvalidProof:
__init__(self, s, level=0)
__str__(self)

Methods inherited from exceptions.Exception:
__getitem__(...)

 
Functions
       
atomicFormulaTerms(f)
Check that a formula is atomic and return the p, s, o terms.
 
>>> atomicFormulaTerms(_s2f("<#sky> <#color> <#blue>.",
...                         "http://example/stuff"))
(color, sky, blue)
checkBuiltin(r, f, checker, policy, level=0)
Check a built-in step.
@@hmm... integrate with Policy more?
 
>>> soc = Namespace("http://example/socrates#")
>>> pf = _s2f(_TestBuiltinStep % '"a" list:in ("b" "a" "c")',
...           "http://example/socrates")
>>> f = checkBuiltin(soc.step1,
...                 pf.the(subj=soc.step1, pred=reason.gives),
...                 Checker(pf), AllPremises())
>>> len(f)
1
 
>>> pf = _s2f(_TestBuiltinStep % '"abc" str:startsWith "a"',
...           "http://example/socrates")
>>> f = checkBuiltin(soc.step1,
...                 pf.the(subj=soc.step1, pred=reason.gives),
...                 Checker(pf), AllPremises())
>>> len(f)
1
 
 
>>> pf = _s2f(_TestBuiltinStep % '"abc" str:startsWith "b"',
...           "http://example/socrates")
>>> f = checkBuiltin(soc.step1,
...                 pf.the(subj=soc.step1, pred=reason.gives),
...                 Checker(pf), AllPremises())
Traceback (most recent call last):
    ...
LogicalFallacy: Built-in fact does not give correct results: predicate: abc subject: str:startsWith object: b result: None
checkConjunction(r, f, checker, policy, level)
checkExtraction(r, f, checker, policy, level=0)
check an Extraction step.
 
>>> soc = Namespace("http://example/socrates#")
>>> pf = _s2f(_TestCEstep, "http://example/socrates")
>>> checkExtraction(soc.step1,
...                 pf.the(subj=soc.step1, pred=reason.gives),
...                 Checker(pf), AllPremises())
{soc:socrates type soc:Man}
checkGMP(r, f, checker, policy, level=0)
check a generalized modus ponens step.
 
>>> soc = Namespace("http://example/socrates#")
>>> pf = _s2f(_TestGMPStep, "http://example/socrates")
>>> f = checkGMP(soc.step1, None, Checker(pf), AllPremises())
>>> f.n3String().strip()
u'@prefix : <http://example/socrates#> .\n    \n    :socrates     a :Mortal .'
checkSupports(r, f, checker, policy, level)
fyi(str, level=0, thresh=50)
getSymbol(proof, x)
De-reify a symbol: get the informatuion identifying it from the proof
getTerm(proof, x)
De-reify a term: get the informatuion about it from the proof
main(argv)
n3Entails(f, g, skipIncludes=0, level=0)
Does f N3-entail g?
 
First try indexed graph match algorithm, and if that fails,
unification.
topLevelLoad(uri=None, flags='')
usage()

 
Data
        OBJ = 3
PRED = 1
SUBJ = 2
__version__ = 'Id: check.py,v 1.59 2007/06/26 02:36:15 syosi Exp '
chatty = 0
debugLevelForInference = 0
debugLevelForParsing = 0
knownReasons = set([Premise, Parsing, Inference, Conjunction, Fact, Extraction, ...])
log = <swap.myStore.Namespace object>
nameBlankNodes = 0
proofSteps = 0
rdf = <swap.myStore.Namespace object>
reason = <swap.myStore.Namespace object>
rei = <swap.myStore.Namespace object>