def loadFormulaWithSubstitution(self, old, bindings={}, why=None, cannon=False): """Load information from another formula, subsituting as we go returns number of statements added (roughly)""" total = 0 subWhy=Because('I said so #1', why) # May be being passed an Env... And copy won't work nicely with it. if hasattr(bindings, 'asDict') and callable(bindings.asDict): bindings2 = bindings.asDict() else: bindings2 = bindings.copy() bindings3 = {} for v in old.universals(): if v not in bindings: bindings3[v] = self.newUniversal(bindings.get(v, v)) for v in old.existentials(): self.declareExistential(bindings.get(v, v)) bindings2[old] = self if self.tms: if bindings: return {}, 0 for s in old.statements[:] : # Copy list! subj=s[SUBJ].substitution( bindings2, why=subWhy, cannon=cannon).substitution( bindings3, why=subWhy, cannon=cannon) ### Make sure we don't keep making copies of the same formula from running ## the same rule again and again if isTopLevel(self) and isinstance(subj, Formula) and not subj.reallyCanonical: subj = subj.reopen() subj = subj.canonicalize(cannon=True) if subj is not s[SUBJ]: bindings2[s[SUBJ]] = subj pred=s[PRED].substitution( bindings2, why=subWhy, cannon=cannon).substitution( bindings3, why=subWhy, cannon=cannon) if pred is not s[PRED]: bindings2[s[PRED]] = pred obj=s[OBJ].substitution( bindings2, why=subWhy, cannon=cannon).substitution( bindings3, why=subWhy, cannon=cannon) if isTopLevel(self) and isinstance(obj, Formula) and not obj.reallyCanonical: obj = obj.reopen() obj = obj.canonicalize(cannon=True) if obj is not s[OBJ]: ### Question to self: What is this doing? bindings2[s[OBJ]] = obj if self.tms: self.tms.getTriple(subj, pred, obj).justify(self.tms.formulaContents, [self.tms.getThing(old)]) total += 1 #This is bunk else: total += self.add(subj=subj, pred=pred, obj=obj, why=why) return bindings3, total
def loadFormulaWithSubstitution(self, old, bindings={}, why=None, cannon=False): """Load information from another formula, subsituting as we go returns number of statements added (roughly)""" total = 0 subWhy=Because('I said so #1', why) bindings2 = bindings.copy() bindings3 = {} for v in old.universals(): if v not in bindings: bindings3[v] = self.newUniversal(bindings.get(v, v)) for v in old.existentials(): self.declareExistential(bindings.get(v, v)) bindings2[old] = self realStatementList = [] for s in old.statements[:] : # Copy list! subj=s[SUBJ].substitution( bindings2, why=subWhy, cannon=cannon).substitution( bindings3, why=subWhy, cannon=cannon) ### Make sure we don't keep making copies of the same formula from running ## the same rule again and again if isTopLevel(self) and isinstance(subj, Formula) and not subj.reallyCanonical: subj = subj.reopen() subj = subj.canonicalize(cannon=True) if isinstance(subj, Formula): subj = subj.canonical if subj is not s[SUBJ]: bindings2[s[SUBJ]] = subj pred=s[PRED].substitution( bindings2, why=subWhy, cannon=cannon).substitution( bindings3, why=subWhy, cannon=cannon) if pred is not s[PRED]: bindings2[s[PRED]] = pred obj=s[OBJ].substitution( bindings2, why=subWhy, cannon=cannon).substitution( bindings3, why=subWhy, cannon=cannon) if isTopLevel(self) and isinstance(obj, Formula) and not obj.reallyCanonical: obj = obj.reopen() obj = obj.canonicalize(cannon=True) if isinstance(obj, Formula): obj = obj.canonical if obj is not s[OBJ]: ### Question to self: What is this doing? bindings2[s[OBJ]] = obj try: total += self.add(subj=subj, pred=pred, obj=obj, why=why) realStatementList.append((subj, pred, obj)) except AssertionError: print 'subj=%s' % subj.debugString() print 'oldSubj=%s' % (s[SUBJ].debugString(),) print 'subj.canonical=%s' % subj.canonical.debugString() raise if diag.chatty_flag > 80: def thing2string(x): if isinstance(x, (tuple, list)): return '[' + ', '.join([thing2string(y) for y in x]) + ']' if isinstance(x, List): return '(' + ' '.join([thing2string(y) for y in x]) + ')' else: return str(x) progress('We added the following triples: %s' % (''.join(['\n\t%s' % thing2string(x) for x in realStatementList]),)) return bindings3, total
def loadFormulaWithSubstitution(self, old, bindings={}, why=None, cannon=False): """Load information from another formula, subsituting as we go returns number of statements added (roughly)""" total = 0 subWhy = Because('I said so #1', why) bindings2 = bindings.copy() bindings3 = {} for v in old.universals(): if v not in bindings: bindings3[v] = self.newUniversal(bindings.get(v, v)) for v in old.existentials(): self.declareExistential(bindings.get(v, v)) bindings2[old] = self realStatementList = [] for s in old.statements[:]: # Copy list! subj = s[SUBJ].substitution(bindings2, why=subWhy, cannon=cannon).substitution( bindings3, why=subWhy, cannon=cannon) ### Make sure we don't keep making copies of the same formula from running ## the same rule again and again if isTopLevel(self) and isinstance( subj, Formula) and not subj.reallyCanonical: subj = subj.reopen() subj = subj.canonicalize(cannon=True) if isinstance(subj, Formula): subj = subj.canonical if subj is not s[SUBJ]: bindings2[s[SUBJ]] = subj pred = s[PRED].substitution(bindings2, why=subWhy, cannon=cannon).substitution( bindings3, why=subWhy, cannon=cannon) if pred is not s[PRED]: bindings2[s[PRED]] = pred obj = s[OBJ].substitution(bindings2, why=subWhy, cannon=cannon).substitution( bindings3, why=subWhy, cannon=cannon) if isTopLevel(self) and isinstance( obj, Formula) and not obj.reallyCanonical: obj = obj.reopen() obj = obj.canonicalize(cannon=True) if isinstance(obj, Formula): obj = obj.canonical if obj is not s[OBJ]: ### Question to self: What is this doing? bindings2[s[OBJ]] = obj try: total += self.add(subj=subj, pred=pred, obj=obj, why=why) realStatementList.append((subj, pred, obj)) except AssertionError: print 'subj=%s' % subj.debugString() print 'oldSubj=%s' % (s[SUBJ].debugString(), ) print 'subj.canonical=%s' % subj.canonical.debugString() raise if diag.chatty_flag > 80: def thing2string(x): if isinstance(x, (tuple, list)): return '[' + ', '.join([thing2string(y) for y in x]) + ']' if isinstance(x, List): return '(' + ' '.join([thing2string(y) for y in x]) + ')' else: return str(x) progress('We added the following triples: %s' % (''.join( ['\n\t%s' % thing2string(x) for x in realStatementList]), )) return bindings3, total