From c4e30f73991d6bbbd848966488576e887072ad1c Mon Sep 17 00:00:00 2001 From: Arthur O'Dwyer Date: Sun, 30 Apr 2017 15:18:19 -0700 Subject: [PATCH] Make `possibleGroupBonds` into a member function of `Bond`. NFC. --- copycat/bond.py | 49 +++++++++++++++++++-------------------- copycat/codeletMethods.py | 10 ++++---- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/copycat/bond.py b/copycat/bond.py index c11c403..aec2787 100644 --- a/copycat/bond.py +++ b/copycat/bond.py @@ -189,28 +189,27 @@ class Bond(WorkspaceStructure): def set_source(self, value): self.source = value - -def possibleGroupBonds(bondCategory, directionCategory, bondFacet, bonds): - result = [] - for bond in bonds: - slipnet = bond.ctx.slipnet - if ( - bond.category == bondCategory and - bond.directionCategory == directionCategory - ): - result += [bond] - else: - # a modified bond might be made - if bond.category == bondCategory: - return None # a different bond cannot be made here - if bond.directionCategory == directionCategory: - return None # a different bond cannot be made here - if slipnet.sameness in [bondCategory, bond.category]: - return None - bond = Bond( - bond.ctx, bond.destination, bond.source, bondCategory, - bondFacet, bond.destinationDescriptor, - bond.sourceDescriptor - ) - result += [bond] - return result + def possibleGroupBonds(self, bonds): + result = [] + slipnet = self.ctx.slipnet + for bond in bonds: + if ( + bond.category == self.category and + bond.directionCategory == self.directionCategory + ): + result += [bond] + else: + # a modified bond might be made + if bond.category == self.category: + return [] # a different bond cannot be made here + if bond.directionCategory == self.directionCategory: + return [] # a different bond cannot be made here + if slipnet.sameness in [self.category, bond.category]: + return [] + bond = Bond( + bond.ctx, bond.destination, bond.source, self.category, + self.facet, bond.destinationDescriptor, + bond.sourceDescriptor + ) + result += [bond] + return result diff --git a/copycat/codeletMethods.py b/copycat/codeletMethods.py index af63e0e..e7d6a0a 100644 --- a/copycat/codeletMethods.py +++ b/copycat/codeletMethods.py @@ -9,7 +9,6 @@ from letter import Letter from replacement import Replacement from group import Group from bond import Bond -from bond import possibleGroupBonds from correspondence import Correspondence from workspaceFormulas import chooseUnmodifiedObject from workspaceFormulas import chooseBondFacet @@ -698,14 +697,13 @@ def group_scout__whole_string(ctx, codelet): assert leftmost.rightmost # choose a random bond from list chosenBond = random.choice(bonds) + bonds = chosenBond.possibleGroupBonds(bonds) + assert bonds category = chosenBond.category + groupCategory = category.getRelatedNode(slipnet.groupCategory) directionCategory = chosenBond.directionCategory bondFacet = chosenBond.facet - bonds = possibleGroupBonds(category, directionCategory, bondFacet, bonds) - assert bonds - groupCategory = category.getRelatedNode(slipnet.groupCategory) - coderack.proposeGroup(objects, bonds, groupCategory, directionCategory, - bondFacet) + coderack.proposeGroup(objects, bonds, groupCategory, directionCategory, bondFacet) @codelet('group-strength-tester')