Skip to content

Commit

Permalink
Ports to Python3
Browse files Browse the repository at this point in the history
  • Loading branch information
LSaldyt committed Jul 31, 2017
1 parent 318d0e2 commit bc848e8
Show file tree
Hide file tree
Showing 22 changed files with 158 additions and 92 deletions.
63 changes: 63 additions & 0 deletions copycat.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
object chosen = j from target string
destination: k
chosen bond facet: letterCategory
Source: j, destination: k
source descriptor: J
destination descriptor: K
proposing successor bond
urgency: 100.0, number: 1, bin: 7
object chosen = j from target string
destination: i
chosen bond facet: letterCategory
Source: j, destination: i
source descriptor: J
destination descriptor: I
proposing predecessor bond
object chosen = successor bond between j and k from other string
bond strength = 48 for successor bond between j and k
object chosen = a from initial string
destination: b
chosen bond facet: letterCategory
Source: a, destination: b
source descriptor: A
destination descriptor: B
proposing successor bond
object chosen = successor bond between a and b from other string
bond strength = 48 for successor bond between a and b
succeeded: posting bond-builder
object chosen = successor bond between a and b from other string
number of incompatibleBonds: 0
no incompatible bonds
no incompatible groups
building bond successor bond between a and b
object chosen = a from initial string
destination: b
chosen bond facet: letterCategory
Source: a, destination: b
source descriptor: A
destination descriptor: B
proposing successor bond
object chosen = a from initial string
destination: b
chosen bond facet: letterCategory
Source: a, destination: b
source descriptor: A
destination descriptor: B
proposing successor bond
Post top down: top-down-description-scout, with urgency: 5
posting bottom up codelets
object chosen = a from initial string
object chosen = j from target string
destination: i
chosen bond facet: letterCategory
Source: j, destination: i
source descriptor: J
destination descriptor: I
proposing predecessor bond
object chosen = a from initial string
destination: b
chosen bond facet: letterCategory
Source: a, destination: b
source descriptor: A
destination descriptor: B
proposing successor bond
2 changes: 1 addition & 1 deletion copycat/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from copycat import Copycat, Reporter # noqa
from .copycat import Copycat, Reporter # noqa
2 changes: 1 addition & 1 deletion copycat/bond.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from workspaceStructure import WorkspaceStructure
from .workspaceStructure import WorkspaceStructure


class Bond(WorkspaceStructure):
Expand Down
24 changes: 12 additions & 12 deletions copycat/codeletMethods.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import inspect
import logging

import formulas
from workspaceFormulas import chooseDirectedNeighbor
from workspaceFormulas import chooseNeighbor
from workspaceFormulas import chooseUnmodifiedObject
from workspaceObject import WorkspaceObject
from letter import Letter
from replacement import Replacement
from group import Group
from bond import Bond
from correspondence import Correspondence
from . import formulas
from .workspaceFormulas import chooseDirectedNeighbor
from .workspaceFormulas import chooseNeighbor
from .workspaceFormulas import chooseUnmodifiedObject
from .workspaceObject import WorkspaceObject
from .letter import Letter
from .replacement import Replacement
from .group import Group
from .bond import Bond
from .correspondence import Correspondence


def codelet(name):
Expand Down Expand Up @@ -804,7 +804,7 @@ def group_builder(ctx, codelet):
incompatible.break_the_structure()
# create new bonds
group.bondList = []
for i in xrange(1, len(group.objectList)):
for i in range(1, len(group.objectList)):
object1 = group.objectList[i - 1]
object2 = group.objectList[i]
if not object1.rightBond:
Expand Down Expand Up @@ -871,7 +871,7 @@ def rule_translator(ctx, codelet):
bondDensity = numberOfBonds / nearlyTotalLength
bondDensity = min(bondDensity, 1.0)
weights = __getCutoffWeights(bondDensity)
cutoff = 10.0 * random.weighted_choice(range(1, 11), weights)
cutoff = 10.0 * random.weighted_choice(list(range(1, 11)), weights)
if cutoff >= temperature.actual_value:
result = workspace.rule.buildTranslatedRule()
if result is not None:
Expand Down
20 changes: 10 additions & 10 deletions copycat/coderack.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import math
import logging

import codeletMethods
from bond import Bond
from codelet import Codelet
from correspondence import Correspondence
from description import Description
from group import Group
from rule import Rule
from . import codeletMethods
from .bond import Bond
from .codelet import Codelet
from .correspondence import Correspondence
from .description import Description
from .group import Group
from .rule import Rule


NUMBER_OF_BINS = 7
Expand Down Expand Up @@ -131,7 +131,7 @@ def postTopDownCodelets(self):
for codeletName in node.codelets:
probability = self.probabilityOfPosting(codeletName)
howMany = self.howManyToPost(codeletName)
for _ in xrange(howMany):
for _ in range(howMany):
if not random.coinFlip(probability):
continue
urgency = getUrgencyBin(
Expand Down Expand Up @@ -163,7 +163,7 @@ def __postBottomUpCodelets(self, codeletName):
urgency = 1
if temperature.value() < 25.0 and 'translator' in codeletName:
urgency = 5
for _ in xrange(howMany):
for _ in range(howMany):
if random.coinFlip(probability):
codelet = Codelet(codeletName, urgency, [], self.codeletsRun)
self.post(codelet)
Expand Down Expand Up @@ -272,7 +272,7 @@ def postInitialCodelets(self):
('bottom-up-correspondence-scout', 2 * n),
]
for name, count in codeletsToPost:
for _ in xrange(count):
for _ in range(count):
codelet = Codelet(name, 1, [], self.codeletsRun)
self.post(codelet)

Expand Down
14 changes: 7 additions & 7 deletions copycat/copycat.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from coderack import Coderack
from randomness import Randomness
from slipnet import Slipnet
from temperature import Temperature
from workspace import Workspace
from .coderack import Coderack
from .randomness import Randomness
from .slipnet import Slipnet
from .temperature import Temperature
from .workspace import Workspace


class Reporter(object):
Expand Down Expand Up @@ -69,7 +69,7 @@ def runTrial(self):
def run(self, initial, modified, target, iterations):
self.workspace.resetWithStrings(initial, modified, target)
answers = {}
for i in xrange(iterations):
for i in range(iterations):
answer = self.runTrial()
d = answers.setdefault(answer['answer'], {
'count': 0,
Expand All @@ -80,7 +80,7 @@ def run(self, initial, modified, target, iterations):
d['sumtemp'] += answer['temp']
d['sumtime'] += answer['time']

for answer, d in answers.iteritems():
for answer, d in answers.items():
d['avgtemp'] = d.pop('sumtemp') / d['count']
d['avgtime'] = d.pop('sumtime') / d['count']
return answers
Expand Down
14 changes: 7 additions & 7 deletions copycat/correspondence.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from conceptMapping import ConceptMapping
from group import Group
from letter import Letter
from workspaceStructure import WorkspaceStructure
import formulas
from .conceptMapping import ConceptMapping
from .group import Group
from .letter import Letter
from .workspaceStructure import WorkspaceStructure
from . import formulas


class Correspondence(WorkspaceStructure):
Expand Down Expand Up @@ -143,8 +143,8 @@ def updateExternalStrength(self):
def internallyCoherent(self):
"""Whether any pair of distinguishing mappings support each other"""
mappings = self.relevantDistinguishingConceptMappings()
for i in xrange(len(mappings)):
for j in xrange(len(mappings)):
for i in range(len(mappings)):
for j in range(len(mappings)):
if i != j:
if mappings[i].supports(mappings[j]):
return True
Expand Down
30 changes: 15 additions & 15 deletions copycat/curses_reporter.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import curses
import time

from copycat import Reporter
from bond import Bond
from correspondence import Correspondence
from description import Description
from group import Group
from letter import Letter
from rule import Rule
from .copycat import Reporter
from .bond import Bond
from .correspondence import Correspondence
from .description import Description
from .group import Group
from .letter import Letter
from .rule import Rule


class SafeSubwindow(object):
Expand Down Expand Up @@ -122,7 +122,7 @@ def represent(d):
d['answer'], d['count'], d['avgtime'], d['avgtemp'],
)

answersToPrint = sorted(self.answers.itervalues(), key=fitness, reverse=True)
answersToPrint = sorted(iter(self.answers.values()), key=fitness, reverse=True)

w = self.answersWindow
pageWidth = w.getmaxyx()[1]
Expand Down Expand Up @@ -175,7 +175,7 @@ def report_coderack(self, coderack):
# Sort the most common and highest-urgency codelets to the top.
entries = sorted(
(count, key[0], key[1])
for key, count in counts.iteritems()
for key, count in counts.items()
)

# Figure out how we'd like to render each codelet's name.
Expand All @@ -193,10 +193,10 @@ def report_coderack(self, coderack):
w.erase()
for u, string in printable_entries:
# Find the highest point on the page where we could place this entry.
start_column = (u - 1) * columnWidth
start_column = int((u - 1) * columnWidth)
end_column = start_column + len(string)
for r in range(pageHeight):
if all(w.is_vacant(r, c) for c in xrange(start_column, end_column+20)):
if all(w.is_vacant(r, c) for c in range(start_column, end_column+20)):
w.addstr(r, start_column, string)
break
w.refresh()
Expand Down Expand Up @@ -308,7 +308,7 @@ def depict_grouping_brace(self, w, firstrow, lastrow, column):
else:
w.addstr(firstrow, column, '\\', curses.A_NORMAL)
w.addstr(lastrow, column, '/', curses.A_NORMAL)
for r in xrange(firstrow + 1, lastrow):
for r in range(firstrow + 1, lastrow):
w.addstr(r, column, '|', curses.A_NORMAL)

def report_workspace(self, workspace):
Expand Down Expand Up @@ -410,12 +410,12 @@ def report_workspace(self, workspace):
end = endrow_for_group[group]
# Place this group's graphical depiction.
depiction_width = 3 + self.length_of_workspace_object_depiction(group, description_structures)
for firstcolumn in xrange(max_column, 1000):
for firstcolumn in range(max_column, 1000):
lastcolumn = firstcolumn + depiction_width
okay = all(
w.is_vacant(r, c)
for c in xrange(firstcolumn, lastcolumn + 1)
for r in xrange(start, end + 1)
for c in range(firstcolumn, lastcolumn + 1)
for r in range(start, end + 1)
)
if okay:
self.depict_grouping_brace(w, start, end, firstcolumn + 1)
Expand Down
2 changes: 1 addition & 1 deletion copycat/description.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from workspaceStructure import WorkspaceStructure
from .workspaceStructure import WorkspaceStructure


class Description(WorkspaceStructure):
Expand Down
2 changes: 1 addition & 1 deletion copycat/formulas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from conceptMapping import ConceptMapping
from .conceptMapping import ConceptMapping


def weightedAverage(values):
Expand Down
6 changes: 3 additions & 3 deletions copycat/group.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from description import Description
from workspaceObject import WorkspaceObject
import formulas
from .description import Description
from .workspaceObject import WorkspaceObject
from . import formulas


class Group(WorkspaceObject):
Expand Down
2 changes: 1 addition & 1 deletion copycat/letter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from workspaceObject import WorkspaceObject
from .workspaceObject import WorkspaceObject


class Letter(WorkspaceObject):
Expand Down
2 changes: 1 addition & 1 deletion copycat/replacement.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from workspaceStructure import WorkspaceStructure
from .workspaceStructure import WorkspaceStructure


class Replacement(WorkspaceStructure):
Expand Down
4 changes: 2 additions & 2 deletions copycat/rule.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging


from workspaceStructure import WorkspaceStructure
import formulas
from .workspaceStructure import WorkspaceStructure
from . import formulas


class Rule(WorkspaceStructure):
Expand Down
4 changes: 2 additions & 2 deletions copycat/slipnet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from slipnode import Slipnode
from sliplink import Sliplink
from .slipnode import Slipnode
from .sliplink import Sliplink


class Slipnet(object):
Expand Down
Loading

0 comments on commit bc848e8

Please sign in to comment.