Fix a bunch of flake8 spam. NFC.
This commit is contained in:
@ -1 +1 @@
|
||||
from copycat import Copycat
|
||||
from copycat import Copycat # noqa
|
||||
|
||||
@ -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 '<Bond: %s>' % 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
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
import logging
|
||||
|
||||
from coderack import Coderack
|
||||
from randomness import Randomness
|
||||
from slipnet import Slipnet
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import argparse
|
||||
import curses
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from copycat import Copycat
|
||||
from curses_reporter import CursesReporter
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import argparse
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from copycat import Copycat, Reporter
|
||||
|
||||
|
||||
@ -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 '<slipnet>'
|
||||
|
||||
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 = [
|
||||
|
||||
@ -23,7 +23,8 @@ class Workspace(object):
|
||||
|
||||
def __repr__(self):
|
||||
return '<Workspace trying %s:%s::%s:?>' % (
|
||||
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
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import logging
|
||||
|
||||
|
||||
def __chooseObjectFromList(ctx, objects, attribute):
|
||||
random = ctx.random
|
||||
temperature = ctx.temperature
|
||||
|
||||
Reference in New Issue
Block a user