Make possibleGroupBonds into a member function of Bond. NFC.

This commit is contained in:
Arthur O'Dwyer
2017-04-30 15:18:19 -07:00
parent 7947e955d7
commit c4e30f7399
2 changed files with 28 additions and 31 deletions

View File

@ -189,28 +189,27 @@ class Bond(WorkspaceStructure):
def set_source(self, value): def set_source(self, value):
self.source = value self.source = value
def possibleGroupBonds(self, bonds):
def possibleGroupBonds(bondCategory, directionCategory, bondFacet, bonds): result = []
result = [] slipnet = self.ctx.slipnet
for bond in bonds: for bond in bonds:
slipnet = bond.ctx.slipnet if (
if ( bond.category == self.category and
bond.category == bondCategory and bond.directionCategory == self.directionCategory
bond.directionCategory == directionCategory ):
): result += [bond]
result += [bond] else:
else: # a modified bond might be made
# a modified bond might be made if bond.category == self.category:
if bond.category == bondCategory: return [] # a different bond cannot be made here
return None # a different bond cannot be made here if bond.directionCategory == self.directionCategory:
if bond.directionCategory == directionCategory: return [] # a different bond cannot be made here
return None # a different bond cannot be made here if slipnet.sameness in [self.category, bond.category]:
if slipnet.sameness in [bondCategory, bond.category]: return []
return None bond = Bond(
bond = Bond( bond.ctx, bond.destination, bond.source, self.category,
bond.ctx, bond.destination, bond.source, bondCategory, self.facet, bond.destinationDescriptor,
bondFacet, bond.destinationDescriptor, bond.sourceDescriptor
bond.sourceDescriptor )
) result += [bond]
result += [bond] return result
return result

View File

@ -9,7 +9,6 @@ from letter import Letter
from replacement import Replacement from replacement import Replacement
from group import Group from group import Group
from bond import Bond from bond import Bond
from bond import possibleGroupBonds
from correspondence import Correspondence from correspondence import Correspondence
from workspaceFormulas import chooseUnmodifiedObject from workspaceFormulas import chooseUnmodifiedObject
from workspaceFormulas import chooseBondFacet from workspaceFormulas import chooseBondFacet
@ -698,14 +697,13 @@ def group_scout__whole_string(ctx, codelet):
assert leftmost.rightmost assert leftmost.rightmost
# choose a random bond from list # choose a random bond from list
chosenBond = random.choice(bonds) chosenBond = random.choice(bonds)
bonds = chosenBond.possibleGroupBonds(bonds)
assert bonds
category = chosenBond.category category = chosenBond.category
groupCategory = category.getRelatedNode(slipnet.groupCategory)
directionCategory = chosenBond.directionCategory directionCategory = chosenBond.directionCategory
bondFacet = chosenBond.facet bondFacet = chosenBond.facet
bonds = possibleGroupBonds(category, directionCategory, bondFacet, bonds) coderack.proposeGroup(objects, bonds, groupCategory, directionCategory, bondFacet)
assert bonds
groupCategory = category.getRelatedNode(slipnet.groupCategory)
coderack.proposeGroup(objects, bonds, groupCategory, directionCategory,
bondFacet)
@codelet('group-strength-tester') @codelet('group-strength-tester')