Permalink
Browse files

pylint

  • Loading branch information...
1 parent 04f6ffe commit 6c2c70bc334aabbf1634bab99e2704e6baf7480b Jeroen Ketema committed Jul 29, 2011
View
@@ -46,7 +46,22 @@ def __init__(self):
self.rule_dir = osenviron["HOME"]
self.ubi = Ubigraph()
- self.reset_terms()
+
+ self.iterator = None
+ self.terms = {}
+ self.term_count = 0
+ self.cur_term = 0
+ self.reducts = []
+ self.reduct_count = 0
+ self.cur_reduct = 0
+ self.changed = False
+
+ self.ubi.clear()
+ self.set_vertex_style()
+ self.set_edge_style()
+
+ self.vertex = None
+ self.edge = None
def set_vertex_style(self):
self.vertex = self.ubi.newVertexStyle(shape = "sphere",
@@ -72,10 +87,10 @@ def reset_terms(self):
class MainWindow(wx.Frame):
- def __init__(self, parent = None, id = -1, title = ANAGAPOS):
+ def __init__(self, parent = None, ident = -1, title = ANAGAPOS):
style = wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX
- wx.Frame.__init__(self, parent, id, title, style = style)
+ wx.Frame.__init__(self, parent, ident, title, style = style)
self.state = State()
@@ -202,7 +217,7 @@ def __init__(self, parent = None, id = -1, title = ANAGAPOS):
# Give window its proper size
self.Fit()
- def OnAbout(self,event):
+ def OnAbout(self, _):
message = ANAGAPOS + " " + VERSION + "\n\n"
message += "URL: " + URL + "\n\n"
message += "Niels Bjoern Bugge Grathwohl\n"
@@ -245,7 +260,7 @@ def LoadRuleSet(self):
self.rule_name = rulename
- def SetRadioVal(self, event):
+ def SetRadioVal(self, _):
self.state.reset_terms()
if self.radio_lambda.GetValue():
@@ -268,10 +283,10 @@ def SetRadioVal(self, event):
def UpdateRuleInfo(self, text):
self.active_rule_file_text.SetLabel(RULE_SET_TEXT + text)
- def OnExit(self, event):
+ def OnExit(self, _):
self.Close(True)
- def TextChange(self, event):
+ def TextChange(self, _):
self.term_input.SetBackgroundColour("#FFFFFF")
self.state.changed = True
@@ -301,7 +316,7 @@ def ColorLatest(self):
else:
self.state.terms[self.state.cur_term].set(color = "#ff0000")
- def ResetGraph(self, event):
+ def ResetGraph(self, _):
self.state.reset_terms()
term_string = self.term_input.GetValue()
@@ -317,7 +332,7 @@ def ResetGraph(self, event):
term.addRuleSetForIter(self.rule_set)
self.state.iterator = iter(term)
- (term, number, previous, _) = self.state.iterator.next()
+ (term, number, _, _) = self.state.iterator.next()
vertex = self.state.ubi.newVertex(style = self.state.vertex)
self.state.terms[number] = vertex
self.state.term_count = 1
@@ -349,7 +364,7 @@ def GetReduct(self):
self.state.cur_reduct += 1
return (new_reduct, number, previous, new_dst)
- def Forward(self, event):
+ def Forward(self, _):
self.SetStatusText("")
reduct_count = self.forward_spinner.GetValue()
count = reduct_count
@@ -399,7 +414,7 @@ def Forward(self, event):
except StopIteration:
self.SetStatusText("Graph complete")
- def Backward(self, event):
+ def Backward(self, _):
self.SetStatusText("")
if self.state.iterator == None or self.state.changed:
self.ResetGraph(None)
@@ -440,20 +455,16 @@ def Backward(self, event):
self.SetStatusText("Removed " + str(count) + " steps")
- def StartCheck(self, event):
- if self.state.iterator == None:
- return
-
- self.ColorInitial()
+ def StartCheck(self, _):
+ if self.state.iterator != None:
+ self.ColorInitial()
- def NewCheck(self, event):
- if self.state.iterator == None:
- return
+ def NewCheck(self, _):
+ if self.state.iterator != None:
+ self.ColorLatest()
- self.ColorLatest()
-
- def Generate(self, event):
+ def Generate(self, _):
term_string = operation.random_term(self.signature)
self.term_input.SetValue(term_string)
self.state.changed = True
@@ -463,6 +474,3 @@ def Generate(self, event):
frame.Show(True)
app.MainLoop()
-
-del frame
-del app
@@ -21,10 +21,7 @@
class LambdaException(Exception):
pass
-class LambdaTerm:
- def __init__(self):
- raise LambdaException("Not implemented")
-
+class LambdaTerm(object):
def isAbs(self):
return False
@@ -84,6 +81,8 @@ def __iter__(self):
class LambdaAbs(LambdaTerm):
def __init__(self, subterm):
+ super(LambdaAbs, self).__init__()
+
self.subterm = subterm
def isAbs(self):
@@ -126,6 +125,8 @@ def toString(self):
class LambdaApp(LambdaTerm):
def __init__(self, left, right):
+ super(LambdaApp, self).__init__()
+
self.left = left
self.right = right
@@ -174,7 +175,7 @@ def reduce(self, position):
right = self.right.reduce(position[1:])
return LambdaApp(left, right)
else:
- raise lambdaException("Invalid operation")
+ raise LambdaException("Invalid operation")
def isEqual(self, term):
if not term.isApp():
@@ -192,6 +193,8 @@ def toString(self):
class LambdaVar(LambdaTerm):
def __init__(self, value):
+ super(LambdaVar, self).__init__()
+
self.value = value
def isVar(self):
@@ -38,34 +38,35 @@ def random_term(_):
freevars = 0
boundvars = 0
- def _node(p, boundlist):
+ def node(p, boundlist):
global freevars, boundvars
- r = random.uniform(0,1)
+ r = random.uniform(0, 1)
if r < p["abstraction"]:
- _p = {}
- _p["variable"] = p["variable"] + 0.09
- _p["abstraction"] = p["abstraction"] - 0.07
- _p["application"] = p["application"] + 0.02
+ p_new = {}
+ p_new["variable"] = p["variable"] + 0.09
+ p_new["abstraction"] = p["abstraction"] - 0.07
+ p_new["application"] = p["application"] + 0.02
b = "b" + str(boundvars)
boundvars += 1
term = Abstraction(Variable(b))
- term.setSubterm(_node(_p, boundlist + [b]))
+ term.setSubterm(node(p_new, boundlist + [b]))
elif r < p["abstraction"] + p["application"]:
- _lp = {}
- _lp["abstraction"] = p["abstraction"] + 0.04
- _lp["application"] = p["application"] - 0.06
- _lp["variable"] = p["variable"] + 0.02
- _rp = {}
- _rp["abstraction"] = p["abstraction"] + 0.02
- _rp["application"] = p["application"] - 0.02
- _rp["variable"] = p["variable"]
+ p_left = {}
+ p_left["abstraction"] = p["abstraction"] + 0.04
+ p_left["application"] = p["application"] - 0.06
+ p_left["variable"] = p["variable"] + 0.02
+ p_right = {}
+ p_right["abstraction"] = p["abstraction"] + 0.02
+ p_right["application"] = p["application"] - 0.02
+ p_right["variable"] = p["variable"]
- term = Application(_node(_lp, boundlist), _node(_rp, boundlist))
+ term = Application(node(p_left, boundlist), \
+ node(p_right, boundlist))
else:
- if random.uniform(0,1) < 0.95 and not len(boundlist) == 0:
+ if random.uniform(0, 1) < 0.95 and not len(boundlist) == 0:
name = boundlist[random.randint(0, len(boundlist) - 1)]
else:
name = "f" + str(freevars)
@@ -80,4 +81,4 @@ def _node(p, boundlist):
"variable" : 0.0
}
- return str(_node(p, []))
+ return str(node(p, []))
@@ -25,7 +25,7 @@
class LambdaTermParseException(Exception):
pass
-class Term:
+class Term(object):
def toString(self):
raise LambdaTermParseException("Not implemented")
@@ -40,6 +40,8 @@ def __str__(self):
class Application(Term):
def __init__(self, left, right):
+ super(Application, self).__init__()
+
self.left = left
self.right = right
@@ -58,6 +60,8 @@ def convert(self, free_vars):
class Abstraction(Term):
def __init__(self, var):
+ super(Abstraction, self).__init__()
+
self.variable = var
self.subterm = None
@@ -84,18 +88,20 @@ def convert(self, free_vars):
return LambdaAbs(self.subterm.convert(free_vars_new))
class Variable(Term):
- def __init__(self, string):
- self.string = string
+ def __init__(self, variable):
+ super(Variable, self).__init__()
+
+ self.variable = variable
def toString(self):
- return self.string
+ return self.variable
def getFreeVars(self):
- return set([self.string])
+ return set([self.variable])
def convert(self, free_vars):
- if self.string in free_vars:
- return LambdaVar(free_vars.index(self.string))
+ if self.variable in free_vars:
+ return LambdaVar(free_vars.index(self.variable))
else:
raise LambdaTermParseException("Non-convertible variable found")
@@ -110,8 +116,8 @@ def get_symbol():
position += 1
if position == len(string):
- symbol = '\0'
- return
+ symbol = '\0'
+ return
symbol = string[position]
position += 1
@@ -120,14 +126,14 @@ def variable():
if not (symbol >= 'a' and symbol <= 'z'):
raise LambdaTermParseException("Invalid symbol on input: " + symbol)
- string = symbol[:]
+ variable_string = symbol[:]
get_symbol() # consumes letter
while (symbol >= '0' and symbol <= '9'):
- string += symbol
+ variable_string += symbol
get_symbol() # consumes number
- var = Variable(string)
+ var = Variable(variable_string)
return var
def abstraction():
@@ -139,10 +145,10 @@ def abstraction():
top = bottom = Abstraction(var)
while symbol != '.':
- var = variable()
- ab = Abstraction(var)
- bottom.setSubterm(ab)
- bottom = ab
+ var = variable()
+ abstr = Abstraction(var)
+ bottom.setSubterm(abstr)
+ bottom = abstr
get_symbol() # consumes dot
subterm = term()
View
@@ -33,35 +33,39 @@
from lambda_terms.lambda_random_term import random_term as lambda_random_term
from trs_terms.trs_random_term import random_term as trs_random_term
-_mode = ""
+mode = ""
-def set_mode(mode):
+PARSER = None
+RULE_PARSER = None
+RANDOM_TERM = None
+
+def set_mode(mode_in):
'''
Set the mode, i.e. choose which parser and associated operations to use:
"trs" or "lambda".
'''
- global RANDOM_TERM, PARSER, RULE_PARSER, _mode
+ global mode, PARSER, RULE_PARSER, RANDOM_TERM
- if mode == "lambda":
+ if mode_in == "lambda":
PARSER = lambda_term_parser
RULE_PARSER = None
RANDOM_TERM = lambda_random_term
- elif mode == "trs":
+ elif mode_in == "trs":
PARSER = trs_term_parser
RULE_PARSER = trs_parser
RANDOM_TERM = trs_random_term
else:
- raise Exception("Unsupported mode: " + mode)
+ raise Exception("Unsupported mode: " + mode_in)
- _mode = mode
+ mode = mode_in
def get_mode():
- return _mode
+ return mode
def parse_rule_set(file_name):
if RULE_PARSER == None:
- raise Exception("Rule set parsing not supported in " + _mode + " mode")
+ raise Exception("Rule set parsing not supported in " + mode + " mode")
return RULE_PARSER(file_name)
Oops, something went wrong.

0 comments on commit 6c2c70b

Please sign in to comment.