def rule_scout(codelet): assert workspace.numberOfUnreplacedObjects() == 0 changedObjects = [o for o in workspace.initial.objects if o.changed] #assert len(changedObjects) < 2 # if there are no changed objects, propose a rule with no changes if not changedObjects: return coderack.proposeRule(None, None, None, None, codelet) changed = changedObjects[-1] # generate a list of distinguishing descriptions for the first object # ie. string-position (left-,right-most,middle or whole) or letter category # if it is the only one of its type in the string objectList = [] position = changed.getDescriptor(slipnet.stringPositionCategory) if position: objectList += [position] letter = changed.getDescriptor(slipnet.letterCategory) otherObjectsOfSameLetter = [o for o in workspace.initial.objects if not o != changed and o.getDescriptionType(letter)] if not len(otherObjectsOfSameLetter): objectList += [letter] # if this object corresponds to another object in the workspace # objectList = the union of this and the distingushing descriptors if changed.correspondence: targetObject = changed.correspondence.objectFromTarget newList = [] slippages = workspace.slippages() for node in objectList: node = node.applySlippages(slippages) if targetObject.described(node): if targetObject.distinguishingDescriptor(node): newList += [node] objectList = newList # surely this should be += # "union of this and distinguishing descriptors" assert objectList and len(objectList) # use conceptual depth to choose a description valueList = [] for node in objectList: depth = node.conceptualDepth value = formulas.temperatureAdjustedValue(depth) valueList += [value] i = formulas.selectListPosition(valueList) descriptor = objectList[i] # choose the relation (change the letmost object to "successor" or "d" objectList = [] if changed.replacement.relation: objectList += [changed.replacement.relation] objectList += [changed.replacement.objectFromModified.getDescriptor( slipnet.letterCategory)] # use conceptual depth to choose a relation valueList = [] for node in objectList: depth = node.conceptualDepth value = formulas.temperatureAdjustedValue(depth) valueList += [value] i = formulas.selectListPosition(valueList) relation = objectList[i] coderack.proposeRule(slipnet.letterCategory, descriptor, slipnet.letter, relation, codelet)
def rule_scout(codelet): assert workspace.numberOfUnreplacedObjects() == 0 changedObjects = [o for o in workspace.initial.objects if o.changed] # assert len(changedObjects) < 2 # if there are no changed objects, propose a rule with no changes if not changedObjects: return coderack.proposeRule(None, None, None, None, codelet) changed = changedObjects[-1] # generate a list of distinguishing descriptions for the first object # ie. string-position (left-,right-most,middle or whole) or letter category # if it is the only one of its type in the string objectList = [] position = changed.getDescriptor(slipnet.stringPositionCategory) if position: objectList += [position] letter = changed.getDescriptor(slipnet.letterCategory) otherObjectsOfSameLetter = [o for o in workspace.initial.objects if not o != changed and o.getDescriptionType(letter)] if not len(otherObjectsOfSameLetter): objectList += [letter] # if this object corresponds to another object in the workspace # objectList = the union of this and the distingushing descriptors if changed.correspondence: targetObject = changed.correspondence.objectFromTarget newList = [] slippages = workspace.slippages() for node in objectList: node = node.applySlippages(slippages) if targetObject.described(node): if targetObject.distinguishingDescriptor(node): newList += [node] objectList = newList # should this be += ?? assert objectList # use conceptual depth to choose a description valueList = [] for node in objectList: depth = node.conceptualDepth value = formulas.temperatureAdjustedValue(depth) valueList += [value] i = formulas.selectListPosition(valueList) descriptor = objectList[i] # choose the relation (change the letmost object to "successor" or "d" objectList = [] if changed.replacement.relation: objectList += [changed.replacement.relation] objectList += [changed.replacement.objectFromModified.getDescriptor( slipnet.letterCategory)] # use conceptual depth to choose a relation valueList = [] for node in objectList: depth = node.conceptualDepth value = formulas.temperatureAdjustedValue(depth) valueList += [value] i = formulas.selectListPosition(valueList) relation = objectList[i] coderack.proposeRule(slipnet.letterCategory, descriptor, slipnet.letter, relation, codelet)
def __structureVsStructure(structure1, weight1, structure2, weight2): structure1.updateStrength() structure2.updateStrength() weightedStrength1 = formulas.temperatureAdjustedValue( structure1.totalStrength * weight1) weightedStrength2 = formulas.temperatureAdjustedValue( structure2.totalStrength * weight2) rhs = (weightedStrength1 + weightedStrength2) * random.random() logging.info('%d > %d', weightedStrength1, rhs) return weightedStrength1 > rhs