From 864c28609c248bdec429a52702240ffe03eeeb55 Mon Sep 17 00:00:00 2001 From: Arthur O'Dwyer Date: Tue, 2 May 2017 11:14:32 -0700 Subject: [PATCH] Smartness update! A single letter is both "leftmost" and "rightmost". Before this change, Copycat was unable to formulate more than the empty rule for abc : abd :: f : f abc : dbc :: f : f abc : aac :: f : f After this change, Copycat strongly prefers abc : abd :: f : g ("Replace the rightmost letter with its successor") abc : dbc :: f : d ("Replace the leftmost letter with d") abc : aac :: f : e ("Replace the middle letter with its predecessor") --- copycat/letter.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/copycat/letter.py b/copycat/letter.py index 0b4fd48..624c222 100644 --- a/copycat/letter.py +++ b/copycat/letter.py @@ -15,17 +15,13 @@ class Letter(WorkspaceObject): def describe(self, position, length): slipnet = self.ctx.slipnet if length == 1: - self.addDescription(slipnet.stringPositionCategory, - slipnet.single) - if self.leftmost and length > 1: # ? why check length ? - self.addDescription(slipnet.stringPositionCategory, - slipnet.leftmost) - if self.rightmost and length > 1: # ? why check length ? - self.addDescription(slipnet.stringPositionCategory, - slipnet.rightmost) - if length > 2 and position * 2 == length + 1: - self.addDescription(slipnet.stringPositionCategory, - slipnet.middle) + self.addDescription(slipnet.stringPositionCategory, slipnet.single) + if self.leftmost: + self.addDescription(slipnet.stringPositionCategory, slipnet.leftmost) + if self.rightmost: + self.addDescription(slipnet.stringPositionCategory, slipnet.rightmost) + if position * 2 == length + 1: + self.addDescription(slipnet.stringPositionCategory, slipnet.middle) def __repr__(self): return '' % self.__str__()