diff --git a/copycat/__init__.py b/copycat/__init__.py index ae36718..fc24510 100644 --- a/copycat/__init__.py +++ b/copycat/__init__.py @@ -1 +1 @@ -from copycat import Copycat +from copycat import Copycat # noqa diff --git a/copycat/bond.py b/copycat/bond.py index 456aff6..ff57fa6 100644 --- a/copycat/bond.py +++ b/copycat/bond.py @@ -30,17 +30,20 @@ class Bond(WorkspaceStructure): def flippedVersion(self): slipnet = self.ctx.slipnet - return Bond(self.ctx, + return Bond( + self.ctx, self.destination, self.source, self.category.getRelatedNode(slipnet.opposite), - self.facet, self.destinationDescriptor, self.sourceDescriptor) + self.facet, self.destinationDescriptor, self.sourceDescriptor + ) def __repr__(self): return '' % self.__str__() def __str__(self): return '%s bond between %s and %s' % ( - self.category.name, self.leftObject, self.rightObject) + self.category.name, self.leftObject, self.rightObject, + ) def buildBond(self): workspace = self.ctx.workspace @@ -82,9 +85,10 @@ class Bond(WorkspaceStructure): else: objekt = self.leftObject.correspondence.objectFromInitial if objekt.leftmost and objekt.rightBond: - if (objekt.rightBond.directionCategory and - objekt.rightBond.directionCategory != - self.directionCategory): + if ( + objekt.rightBond.directionCategory and + objekt.rightBond.directionCategory != self.directionCategory + ): incompatibles += [correspondence] if self.rightObject.rightmost and self.rightObject.correspondence: correspondence = self.rightObject.correspondence @@ -93,9 +97,10 @@ class Bond(WorkspaceStructure): else: objekt = self.rightObject.correspondence.objectFromInitial if objekt.rightmost and objekt.leftBond: - if (objekt.leftBond.directionCategory and - objekt.leftBond.directionCategory != - self.directionCategory): + if ( + objekt.leftBond.directionCategory and + objekt.leftBond.directionCategory != self.directionCategory + ): incompatibles += [correspondence] return incompatibles @@ -160,9 +165,11 @@ class Bond(WorkspaceStructure): if object1.beside(object2): slotSum += 1.0 for bond in self.string.bonds: - if (bond != self and - self.sameCategories(bond) and - self.myEnds(object1, object2)): + if ( + bond != self and + self.sameCategories(bond) and + self.myEnds(object1, object2) + ): supportSum += 1.0 try: return 100.0 * supportSum / slotSum @@ -185,20 +192,23 @@ def possibleGroupBonds(bondCategory, directionCategory, bondFacet, bonds): result = [] for bond in bonds: slipnet = bond.ctx.slipnet - if (bond.category == bondCategory and - bond.directionCategory == directionCategory): + if ( + bond.category == bondCategory and + bond.directionCategory == directionCategory + ): result += [bond] else: # a modified bond might be made - if bondCategory == slipnet.sameness: + if bond.category == bondCategory: return None # a different bond cannot be made here - if (bond.category == bondCategory or - bond.directionCategory == directionCategory): + if bond.directionCategory == directionCategory: return None # a different bond cannot be made here - if bond.category == slipnet.sameness: + if slipnet.sameness in [bondCategory, bond.category]: return None - bond = Bond(bond.ctx, bond.destination, bond.source, bondCategory, - bondFacet, bond.destinationDescriptor, - bond.sourceDescriptor) + bond = Bond( + bond.ctx, bond.destination, bond.source, bondCategory, + bondFacet, bond.destinationDescriptor, + bond.sourceDescriptor + ) result += [bond] return result diff --git a/copycat/codeletMethods.py b/copycat/codeletMethods.py index aad3f8e..985a81c 100644 --- a/copycat/codeletMethods.py +++ b/copycat/codeletMethods.py @@ -356,17 +356,18 @@ def replacement_finder(ctx, codelet): position = letterOfInitialString.leftIndex moreLetters = [o for o in workspace.modified.objects if isinstance(o, Letter) and o.leftIndex == position] - letterOfModifiedString = moreLetters and moreLetters[0] or None - assert letterOfModifiedString - position -= 1 - initialAscii = ord(workspace.initialString[position]) - modifiedAscii = ord(workspace.modifiedString[position]) + if not moreLetters: + return + letterOfModifiedString = moreLetters[0] + initialAscii = ord(workspace.initialString[position - 1]) + modifiedAscii = ord(workspace.modifiedString[position - 1]) diff = initialAscii - modifiedAscii if abs(diff) < 2: relations = { 0: slipnet.sameness, -1: slipnet.successor, - 1: slipnet.predecessor} + 1: slipnet.predecessor + } relation = relations[diff] logging.info('Relation found: %s', relation.name) else: diff --git a/copycat/conceptMapping.py b/copycat/conceptMapping.py index dc15d32..34201f0 100644 --- a/copycat/conceptMapping.py +++ b/copycat/conceptMapping.py @@ -22,7 +22,7 @@ class ConceptMapping(object): self.__str__(), self.initialDescriptor, self.targetDescriptor) def __str__(self): - return self.label and self.label.name or 'anonymous' + return self.label.name if self.label else 'anonymous' def slippability(self): association = self.__degreeOfAssociation() @@ -125,9 +125,8 @@ class ConceptMapping(object): # means that letter->group supports letter->group, even though these # concept-mappings have no label. - if self.initialDescriptor == other.initialDescriptor: - if self.targetDescriptor == other.targetDescriptor: - return True + if self.sameDescriptors(other): + return True # if the descriptors are not related return false if not self.related(other): return False diff --git a/copycat/copycat.py b/copycat/copycat.py index bfeec9a..ee0e6dd 100644 --- a/copycat/copycat.py +++ b/copycat/copycat.py @@ -1,5 +1,3 @@ -import logging - from coderack import Coderack from randomness import Randomness from slipnet import Slipnet diff --git a/copycat/curses_main.py b/copycat/curses_main.py index a4e8d46..19bb441 100644 --- a/copycat/curses_main.py +++ b/copycat/curses_main.py @@ -1,7 +1,6 @@ import argparse import curses import logging -import sys from copycat import Copycat from curses_reporter import CursesReporter diff --git a/copycat/main.py b/copycat/main.py index 94fbc5c..27ab66c 100644 --- a/copycat/main.py +++ b/copycat/main.py @@ -1,6 +1,5 @@ import argparse import logging -import sys from copycat import Copycat, Reporter diff --git a/copycat/slipnet.py b/copycat/slipnet.py index 4a4713a..3478abf 100644 --- a/copycat/slipnet.py +++ b/copycat/slipnet.py @@ -7,23 +7,10 @@ from sliplink import Sliplink class Slipnet(object): # pylint: disable=too-many-instance-attributes def __init__(self): - logging.debug("Slipnet.__init__()") - self.slipnodes = [] - self.sliplinks = [] - self.bondFacets = [] - self.numberOfUpdates = 0 self.__addInitialNodes() self.__addInitialLinks() self.reset() - def __repr__(self): - return '' - - def setConceptualDepths(self, depth): - logging.debug('slipnet set all depths to %f', depth) - for node in self.slipnodes: - node.setConceptualDepth(depth) - def reset(self): logging.debug('slipnet.reset()') self.numberOfUpdates = 0 @@ -126,8 +113,10 @@ class Slipnet(object): self.bondFacet = self.__addNode('bondFacet', 90.0) # specify the descriptor types that bonds can form between - self.bondFacets += [self.letterCategory] - self.bondFacets += [self.length] + self.bondFacets = [ + self.letterCategory, + self.length, + ] # some factors are considered "very relevant" a priori self.initiallyClampedSlipnodes = [ diff --git a/copycat/workspace.py b/copycat/workspace.py index df357a9..913ea56 100644 --- a/copycat/workspace.py +++ b/copycat/workspace.py @@ -23,7 +23,8 @@ class Workspace(object): def __repr__(self): return '' % ( - self.initialString, self.modifiedString, self.targetString) + self.initialString, self.modifiedString, self.targetString, + ) def resetWithStrings(self, initial, modified, target): self.targetString = target @@ -136,11 +137,10 @@ class Workspace(object): def slippages(self): result = [] if self.changedObject and self.changedObject.correspondence: - result = [m for m in - self.changedObject.correspondence.conceptMappings] - for objekt in self.initial.objects: - if objekt.correspondence: - for mapping in objekt.correspondence.slippages(): + result = self.changedObject.correspondence.conceptMappings[:] + for o in self.initial.objects: + if o.correspondence: + for mapping in o.correspondence.slippages(): if not mapping.isNearlyContainedBy(result): result += [mapping] return result diff --git a/copycat/workspaceFormulas.py b/copycat/workspaceFormulas.py index 6a7ea8e..9c76474 100644 --- a/copycat/workspaceFormulas.py +++ b/copycat/workspaceFormulas.py @@ -1,5 +1,6 @@ import logging + def __chooseObjectFromList(ctx, objects, attribute): random = ctx.random temperature = ctx.temperature