Demagic everything except the formulas and workspaceFormulas. NFC.
This commit is contained in:
@ -26,10 +26,9 @@ def codelet(name):
|
|||||||
|
|
||||||
# some methods common to the codelets
|
# some methods common to the codelets
|
||||||
def __showWhichStringObjectIsFrom(structure):
|
def __showWhichStringObjectIsFrom(structure):
|
||||||
from context import context as ctx
|
|
||||||
workspace = ctx.workspace
|
|
||||||
if not structure:
|
if not structure:
|
||||||
return
|
return
|
||||||
|
workspace = structure.ctx.workspace
|
||||||
whence = 'other'
|
whence = 'other'
|
||||||
if isinstance(structure, WorkspaceObject):
|
if isinstance(structure, WorkspaceObject):
|
||||||
whence = 'target'
|
whence = 'target'
|
||||||
@ -38,9 +37,7 @@ def __showWhichStringObjectIsFrom(structure):
|
|||||||
#print 'object chosen = %s from %s string' % (structure, whence)
|
#print 'object chosen = %s from %s string' % (structure, whence)
|
||||||
|
|
||||||
|
|
||||||
def __getScoutSource(slipnode, relevanceMethod, typeName):
|
def __getScoutSource(workspace, slipnode, relevanceMethod, typeName):
|
||||||
from context import context as ctx
|
|
||||||
workspace = ctx.workspace
|
|
||||||
initialRelevance = relevanceMethod(workspace.initial, slipnode)
|
initialRelevance = relevanceMethod(workspace.initial, slipnode)
|
||||||
targetRelevance = relevanceMethod(workspace.target, slipnode)
|
targetRelevance = relevanceMethod(workspace.target, slipnode)
|
||||||
initialUnhappiness = workspace.initial.intraStringUnhappiness
|
initialUnhappiness = workspace.initial.intraStringUnhappiness
|
||||||
@ -79,7 +76,7 @@ def __getDescriptors(bondFacet, source, destination):
|
|||||||
|
|
||||||
|
|
||||||
def __structureVsStructure(structure1, weight1, structure2, weight2):
|
def __structureVsStructure(structure1, weight1, structure2, weight2):
|
||||||
from context import context as ctx
|
ctx = structure1.ctx
|
||||||
structure1.updateStrength()
|
structure1.updateStrength()
|
||||||
structure2.updateStrength()
|
structure2.updateStrength()
|
||||||
weightedStrength1 = formulas.temperatureAdjustedValue(ctx,
|
weightedStrength1 = formulas.temperatureAdjustedValue(ctx,
|
||||||
@ -116,8 +113,7 @@ def __fightIncompatibles(incompatibles, structure, name,
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def __slippability(conceptMappings):
|
def __slippability(ctx, conceptMappings):
|
||||||
from context import context as ctx
|
|
||||||
for mapping in conceptMappings:
|
for mapping in conceptMappings:
|
||||||
slippiness = mapping.slippability() / 100.0
|
slippiness = mapping.slippability() / 100.0
|
||||||
probabilityOfSlippage = formulas.temperatureAdjustedProbability(ctx,
|
probabilityOfSlippage = formulas.temperatureAdjustedProbability(ctx,
|
||||||
@ -363,9 +359,10 @@ def replacement_finder(ctx, codelet):
|
|||||||
def top_down_bond_scout__category(ctx, codelet):
|
def top_down_bond_scout__category(ctx, codelet):
|
||||||
coderack = ctx.coderack
|
coderack = ctx.coderack
|
||||||
slipnet = ctx.slipnet
|
slipnet = ctx.slipnet
|
||||||
|
workspace = ctx.workspace
|
||||||
logging.info('top_down_bond_scout__category')
|
logging.info('top_down_bond_scout__category')
|
||||||
category = codelet.arguments[0]
|
category = codelet.arguments[0]
|
||||||
source = __getScoutSource(category, formulas.localBondCategoryRelevance,
|
source = __getScoutSource(workspace, category, formulas.localBondCategoryRelevance,
|
||||||
'bond')
|
'bond')
|
||||||
destination = chooseNeighbor(source)
|
destination = chooseNeighbor(source)
|
||||||
logging.info('source: %s, destination: %s', source, destination)
|
logging.info('source: %s, destination: %s', source, destination)
|
||||||
@ -394,8 +391,9 @@ def top_down_bond_scout__category(ctx, codelet):
|
|||||||
def top_down_bond_scout__direction(ctx, codelet):
|
def top_down_bond_scout__direction(ctx, codelet):
|
||||||
coderack = ctx.coderack
|
coderack = ctx.coderack
|
||||||
slipnet = ctx.slipnet
|
slipnet = ctx.slipnet
|
||||||
|
workspace = ctx.workspace
|
||||||
direction = codelet.arguments[0]
|
direction = codelet.arguments[0]
|
||||||
source = __getScoutSource(
|
source = __getScoutSource(workspace,
|
||||||
direction, formulas.localDirectionCategoryRelevance, 'bond')
|
direction, formulas.localDirectionCategoryRelevance, 'bond')
|
||||||
destination = chooseDirectedNeighbor(source, direction)
|
destination = chooseDirectedNeighbor(source, direction)
|
||||||
assert destination
|
assert destination
|
||||||
@ -476,10 +474,11 @@ def bond_builder(ctx, codelet):
|
|||||||
def top_down_group_scout__category(ctx, codelet):
|
def top_down_group_scout__category(ctx, codelet):
|
||||||
coderack = ctx.coderack
|
coderack = ctx.coderack
|
||||||
slipnet = ctx.slipnet
|
slipnet = ctx.slipnet
|
||||||
|
workspace = ctx.workspace
|
||||||
groupCategory = codelet.arguments[0]
|
groupCategory = codelet.arguments[0]
|
||||||
category = groupCategory.getRelatedNode(slipnet.bondCategory)
|
category = groupCategory.getRelatedNode(slipnet.bondCategory)
|
||||||
assert category
|
assert category
|
||||||
source = __getScoutSource(category, formulas.localBondCategoryRelevance,
|
source = __getScoutSource(workspace, category, formulas.localBondCategoryRelevance,
|
||||||
'group')
|
'group')
|
||||||
assert source and not source.spansString()
|
assert source and not source.spansString()
|
||||||
if source.leftmost:
|
if source.leftmost:
|
||||||
@ -560,8 +559,9 @@ def top_down_group_scout__category(ctx, codelet):
|
|||||||
def top_down_group_scout__direction(ctx, codelet):
|
def top_down_group_scout__direction(ctx, codelet):
|
||||||
coderack = ctx.coderack
|
coderack = ctx.coderack
|
||||||
slipnet = ctx.slipnet
|
slipnet = ctx.slipnet
|
||||||
|
workspace = ctx.workspace
|
||||||
direction = codelet.arguments[0]
|
direction = codelet.arguments[0]
|
||||||
source = __getScoutSource(direction,
|
source = __getScoutSource(workspace, direction,
|
||||||
formulas.localDirectionCategoryRelevance,
|
formulas.localDirectionCategoryRelevance,
|
||||||
'direction')
|
'direction')
|
||||||
logging.info('source chosen = %s', source)
|
logging.info('source chosen = %s', source)
|
||||||
@ -862,7 +862,7 @@ def bottom_up_correspondence_scout(ctx, codelet):
|
|||||||
objectFromInitial, objectFromTarget,
|
objectFromInitial, objectFromTarget,
|
||||||
objectFromInitial.relevantDescriptions(),
|
objectFromInitial.relevantDescriptions(),
|
||||||
objectFromTarget.relevantDescriptions())
|
objectFromTarget.relevantDescriptions())
|
||||||
assert conceptMappings and __slippability(conceptMappings)
|
assert conceptMappings and __slippability(ctx, conceptMappings)
|
||||||
#find out if any are distinguishing
|
#find out if any are distinguishing
|
||||||
distinguishingMappings = [m for m in conceptMappings if m.distinguishing()]
|
distinguishingMappings = [m for m in conceptMappings if m.distinguishing()]
|
||||||
assert distinguishingMappings
|
assert distinguishingMappings
|
||||||
@ -916,7 +916,7 @@ def important_object_correspondence_scout(ctx, codelet):
|
|||||||
objectFromInitial, objectFromTarget,
|
objectFromInitial, objectFromTarget,
|
||||||
objectFromInitial.relevantDescriptions(),
|
objectFromInitial.relevantDescriptions(),
|
||||||
objectFromTarget.relevantDescriptions())
|
objectFromTarget.relevantDescriptions())
|
||||||
assert conceptMappings and __slippability(conceptMappings)
|
assert conceptMappings and __slippability(ctx, conceptMappings)
|
||||||
#find out if any are distinguishing
|
#find out if any are distinguishing
|
||||||
distinguishingMappings = [m for m in conceptMappings if m.distinguishing()]
|
distinguishingMappings = [m for m in conceptMappings if m.distinguishing()]
|
||||||
assert distinguishingMappings
|
assert distinguishingMappings
|
||||||
|
|||||||
@ -8,6 +8,7 @@ class ConceptMapping(object):
|
|||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments
|
||||||
logging.info('make a map: %s-%s', initialDescriptionType.get_name(),
|
logging.info('make a map: %s-%s', initialDescriptionType.get_name(),
|
||||||
targetDescriptionType.get_name())
|
targetDescriptionType.get_name())
|
||||||
|
self.slipnet = initialDescriptionType.slipnet
|
||||||
self.initialDescriptionType = initialDescriptionType
|
self.initialDescriptionType = initialDescriptionType
|
||||||
self.targetDescriptionType = targetDescriptionType
|
self.targetDescriptionType = targetDescriptionType
|
||||||
self.initialDescriptor = initialDescriptor
|
self.initialDescriptor = initialDescriptor
|
||||||
@ -51,8 +52,7 @@ class ConceptMapping(object):
|
|||||||
self.targetDescriptor.conceptualDepth) / 2.0
|
self.targetDescriptor.conceptualDepth) / 2.0
|
||||||
|
|
||||||
def distinguishing(self):
|
def distinguishing(self):
|
||||||
from context import context as ctx
|
slipnet = self.slipnet
|
||||||
slipnet = ctx.slipnet
|
|
||||||
if self.initialDescriptor == slipnet.whole:
|
if self.initialDescriptor == slipnet.whole:
|
||||||
if self.targetDescriptor == slipnet.whole:
|
if self.targetDescriptor == slipnet.whole:
|
||||||
return False
|
return False
|
||||||
@ -141,11 +141,8 @@ class ConceptMapping(object):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def slippage(self):
|
def slippage(self):
|
||||||
from context import context as ctx
|
slipnet = self.slipnet
|
||||||
slipnet = ctx.slipnet
|
return self.label not in [slipnet.sameness, slipnet.identity]
|
||||||
if self.label != slipnet.sameness:
|
|
||||||
return self.label != slipnet.identity
|
|
||||||
return False
|
|
||||||
|
|
||||||
def symmetricVersion(self):
|
def symmetricVersion(self):
|
||||||
if not self.slippage():
|
if not self.slippage():
|
||||||
|
|||||||
Reference in New Issue
Block a user