[Pyple-commits] SF.net SVN: pyple: [16] src/pyple.py
Status: Pre-Alpha
Brought to you by:
anseljh
From: <an...@us...> - 2007-03-01 02:31:17
|
Revision: 16 http://svn.sourceforge.net/pyple/?rev=16&view=rev Author: anseljh Date: 2007-02-28 18:31:09 -0800 (Wed, 28 Feb 2007) Log Message: ----------- v0.2.0 - complete rewrite w/ SQLObject Modified Paths: -------------- src/pyple.py Modified: src/pyple.py =================================================================== --- src/pyple.py 2007-01-25 01:03:27 UTC (rev 15) +++ src/pyple.py 2007-03-01 02:31:09 UTC (rev 16) @@ -2,7 +2,7 @@ """ PyPLE (say "pipple") -- the Python Persistent Logic Engine -pyple.py: All things PyPLE are in this file! +pyple.py: Main PyPLE class and simple test script Copyright (C) 2006-2007 Ansel Halliburton. All rights reserved. @@ -31,18 +31,19 @@ NOTES * PyPLE is lean and mean. Just say no to complexity! -* You can run this file to do some simple testing: python PyPLE.py +* You can run this file to do some simple testing: python pyple.py HISTORY v0.0.1 PyPLE was born in a flash of inspiration at L & L Hawaiian Barbecue in - Palo Alto, California on April 7, 2006. Version 0.1 was thrown together + Palo Alto, California on April 7, 2006. Version 0.0.1 was thrown together more or less that night with the assistance of Nine Inch Nails and the Komodo IDE. v0.1.0 Port to SQLObject for database persistence begun - 1/22/07 -v0.2.0 SQLObject version merged into one file for simplicity - 1/22/07 +v0.2.0 Complete rewrite of SQLObject version """ # Interesting tokens to look for in this source code: +# # #TODO: Items that need doing # #BUG: Identified bug # #NOTE: Note by author @@ -54,513 +55,409 @@ __release__ = (0,2,0,'alpha',0) PYPLE_TAGLINE = "PyPLE (say \"pipple\") -- the Python Persistent Logic Engine" -PYPLE_COPYRIGHT = "Copyright (c) 2006-2007 Ansel Halliburton." +PYPLE_COPYRIGHT = "Copyright (c) 2006-2007 Ansel Halliburton" ASTERISKS = 40 # number of asterisks to use as separator in debug/test output -RESERVED_OPERATORS = ['AND', 'OR', 'NOT', 'XOR', 'NAND'] -########################################################################################## - -from sqlobject import * # SQLObject ORM -from sqlobject.inheritance import InheritableSQLObject # Inheritance for Element, Expression classes -from datetime import datetime -import types import re +import types +from sqlobject import * # SQLObject ORM +from sqlobject.inheritance import InheritableSQLObject -########################################################################################## +DEBUG = 1 -class BasePyPLEType(InheritableSQLObject): - """ - Base class/interface for Element and Expression persistent types - """ +class Parameter(SQLObject): - # Meta - class sqlmeta: - table = "pyple_base_pyple_type" - - # Methods - def eval(self): - """ - Both Element and Expression should have eval() methods. - """ - pass + key = StringCol(length=100, notNone=False, default=None, dbName='param_key') + value = PickleCol(default=None, dbName='param_value') -########################################################################################## + #def __init__(self, key=None, value=None): + # self.key = key + # self.value = value -class Expression(BasePyPLEType): - """ - Expressions are composed of a left-hand-side (LHS), a right-hand-side (RHS), and - an Operator (op). LHS and RHS can be either an Element or an Expression. - """ +class Operator(InheritableSQLObject): - # Columns - operator = ForeignKey('Operator') - LHS = ForeignKey('BasePyPLEType') # can also be Expression! - RHS = ForeignKey('BasePyPLEType') # can also be Expression! + parameters = MultipleJoin('Parameter') - # Meta - class sqlmeta: - table = "pyple_expression" + #def __init__(self, parameters): + def _init(self, *args, **kw): + if DEBUG: print "*"*5, "Start of Operator._init" + if DEBUG: print "*"*5, "I'm a", self.sqlmeta.table + if 'params' in kw: + if DEBUG: print "*"*5, "Handling kw:", kw + if isinstance(kw['params'], types.ListType): + if DEBUG: print "*"*5, "It's a list with", len(kw['params']), "elements" + for p in kw['params']: + if DEBUG: print "*"*5, "Element:", p + if isinstance(p, Parameter): + if DEBUG: print "*"*5, "It's a Parameter already" + self.add_parameter(p) + else: + if DEBUG: print "*"*5, "Making it a Parameter..." + self.add_parameter(Parameter(value=p)) + else: + raise TypeError("params must be a list.") + else: + if DEBUG: + print "*"*5, "No params!" + print "*"*5, "KW:", kw + print "*"*5, "ARGS", args + + ##self.parameters = parameters + #self.parameters = [] + #for p in parameters: + # self.parameters.append(Parameter(value=p)) + + self.config = {} # misc storage + if DEBUG: print "*"*5, "End of Operator._init" - # Methods - def __str__(self): + def __getstate__(self): """ - Return string representation of an Expression + Allows for pickling of any Operator; stores class type (table) and row ID -- basically a pointer to the object in the DB. """ - return "Expression" #TODO: meaningful string representation + return dict(table=self.sqlmeta.table, id=self.id) - def eval(self): - #define temp vars - L = None - R = None + def __setstate__(self, d): + """ + Unpickler + """ + self = Operator.get(d['id']) + + def eval_fn(self, data): + pass # to be overloaded + + def eval(self, data): + #for param in parameters: + # pass + pass # to be overloaded + +class Regex(Operator): + def eval(self, data): - if type(self.LHS) is Expression: - L = self.LHS.eval() - elif type(self.LHS) is Element: - L = self.LHS - else: - raise TypeError("not an Element: %s" % str(L)) + # JIT regex compilation + if 'regex' not in self.config: + if 'case_sensitive' in self.config and self.config['case_sensitive'] is False: + self.config['regex'] = re.compile(self.parameters[0].value, re.IGNORECASE) + else: + self.config['regex'] = re.compile(self.parameters[0].value) - if type(self.RHS) is Expression: - R = self.RHS.eval() - elif type(self.RHS) is Element: - R = self.RHS - else: - raise TypeError("not an Element: %s" % str(R)) + # Run regex on data + result = self.config['regex'].search(data) - #perform operation and return Element - return self.operator.eval(L, R) + # Return True if match; else return False + if result: + return True + return False + class sqlmeta: + table = 'op_regex' -########################################################################################## +class CIRegex(Regex): + """Case-insensitive regex""" + #def __init__(self, parameters): + def _init(self, *args, **kw): + #Regex.__init__(self, parameters) + Regex._init(self, *args, **kw) + self.config['case_sensitive'] = False + class sqlmeta: + table = 'op_ci_regex' -class Element(BasePyPLEType): +class AND(Operator): + class sqlmeta: + table = 'op_and' + def eval(self, data): + for param in self.parameters: + if not param.value.eval(data): # + return False # + return True + + +class Action(SQLObject): # Columns + function = ForeignKey('ActionFunction') - types = ['element', 'expression', 'boolean', 'integer', 'string', 'datetime', 'null', 'float'] - - type = EnumCol(enumValues=types) - value = PickleCol(length=2**24) - - # Meta - class sqlmeta: - table = "pyple_element" - - # Methods - - def eval(self): + def invoke(self, data): + self.action_function.invoke(self.get_parameters(data), data) + + def get_parameters(self, data): """ - eval() on an Element returns a native Python object. + Pre-process data and generate list of parameters for invoke() method """ - - if self.type == 'expression': - return Expression.Expression(self.value) - elif self.type == 'boolean': - return types.BooleanType(self.value) - elif self.type == 'integer': - return int(self.value) - elif self.type == 'string': - return str(self.value) - elif self.type == 'datetime': - return datetime.datetime(self.value) - elif self.type == 'null': - return None - elif self.type == 'float': - return float(self.value) - else: - raise IndexError("Unknown type: %s" % self.type) - - @staticmethod - def create(o): - temp_t = type(o) - - #TODO: DRY this up: refactor out into to_pyple_type() helper function - if temp_t is Expression: - t = 'expression' - elif temp_t is types.BooleanType: - t = 'boolean' - elif temp_t is types.IntType: - t = 'integer' - elif temp_t is types.StringType: - t = 'string' - elif temp_t is datetime.datetime: - t = 'datetime' - elif temp_t is types.NoneType: - t = 'null' - elif temp_t is types.FloatType: - t = 'float' - else: - raise TypeError("Unknown type: %s" % str(temp_t)) - - return Element(type=t, value=o) - - def __str__(self): - """Return string representation of Element""" - return "PyPLE Element of type " + str(self.type) + "; value = " + str(self.value) + #TODO: stub + print "STUB: Action.get_parameters() called" -########################################################################################## - -class Operator(SQLObject): +class ActionFunction(SQLObject): + #TODO: stub - engines = ['internal', 'python', 'shell', 'perl'] + code = StringCol(notNone=False, default="print 'Default ActionFunction; len(str(data)) =', len(str(data))") - # Columns - name = StringCol(length=200) - engine = EnumCol(enumValues=engines, default='python') - code = ForeignKey('Code') - - # Meta - class sqlmeta: - table = "pyple_operator" - - # Methods - - def _get_function(self): + def invoke(self, parameters, data): try: - if self.fx is not None: - return self.fx - else: # no function set - #print "fx is None" - if self.code is not None: - self.fx = self.code.function - return self.fx - #print "* about to eval() Operator code..." - ##print "self.code is a:", str(type(self.code)) - #self.function = eval(self.code.content, {}, {}) - #return self.fx - else: - raise Exception("No function or Code set; don't know how to continue!") - except AttributeError: - #print "No fx" - if self.code is not None: - #print "* about to eval() Operator code... (no fx)" - #print "self.code is a:", str(type(self.code)) - self.fx = self.code.function - return self.fx + junk = self.evaled_code except: - raise Exception("Error in Operator._get_function()!!") - - #if self.fx is not None: - # return self.fx - #else: # no function set - # if self.code is not None: - # print "* about to eval() Operator code..." - # self.function = eval(self.code, {}, {}) - # else: - # raise Exception("No function or Code set; don't know how to continue!") + print "** about to eval() Python code: ", code + self.evaled_code = eval(code, {}, {}) #run Python eval() on code (in sandbox) + + +class RuleSet(SQLObject): + root_rule = ForeignKey('Operator') # e.g. AND rule at root of rule tree + actions = RelatedJoin('Action') + name = StringCol(length=100) - def _set_function(self, f): - print "Setting function for Operator %s" % self.name - self.fx = f + def eval(self, data): + """ + Evaluate rules against data; return True/False + """ + return self.root_rule.eval(data) - def eval(self, LHS=None, RHS=None): + def invoke(self, data): """ - Perform an operation on LHS and RHS + Invoke actions on data (does not evaluate rules) """ - #print "**Operator.eval() called." - if self.function is None: - raise Exception("no function set!") - else: - #fn = self.fn - #val = fn(LHS.eval(), RHS.eval()) #reduce elements to bare datatypes - #return Element.Element(val) - #return Element.Element(self.eval_function(LHS.eval(), RHS.eval())) - - left = None - right = None - - if type(LHS) in [Element, Expression]: - left = LHS.eval() - else: - left = LHS - - if type(RHS) in [Element, Expression]: - right = RHS.eval() - else: - right = RHS - - return self.function(left, right) + if root_rule.eval(data): + for action in actions: + action.invoke(data) + def eval_and_invoke(self, data): + """ + Evaluate rules against data, then invoke actions if result is True + """ + if self.eval(data): + self.invoke(data) - # Functions for internal operators - @staticmethod - def op_and(LHS, RHS): - """Internal AND operator""" - #print "** Internal AND operator called. LHS=",LHS,"; RHS=",RHS - return (LHS and RHS) - - @staticmethod - def op_or(LHS, RHS): - """Internal OR operator""" - return (LHS or RHS) - - @staticmethod - def op_not(LHS, RHS): - """Internal NOT operator""" - return (LHS and not RHS) - - @staticmethod - def op_xor(LHS, RHS): - """Internal XOR operator""" - return ( (LHS and not RHS) or (RHS and not LHS) ) - - @staticmethod - def op_nand(LHS, RHS): - """Internal NAND operator""" - #TODO: is this really what NAND is supposed to do? - if (LHS and RHS): - return False - else: - return True - + def get_by_name(name): + """ + Fetches a single RuleSet instance by name. + """ + return RuleSet.selectBy(name=name)[0] -########################################################################################## +PYPLE_TABLES = [Parameter, Operator, Regex, CIRegex, Action, ActionFunction, RuleSet, AND] -class Code(SQLObject): - - """ - Code for running Operators - """ - # Columns - name = StringCol(length=200) - content = StringCol() - type = EnumCol(enumValues=['interpreted','binary','pickled'], default='interpreted') - engine = EnumCol(enumValues=Operator.engines, default='python') #ForeignKey('Engine') - - # Meta - class sqlmeta: - table = "pyple_code" - - # Methods - #TODO: add methods, etc. - - def _get_function(self): - if self.type=='interpreted' and self.engine=='python': - #return eval(self.content, {}, {}) - return eval("lambda LHS, RHS: " + self.content) - else: - raise Exception("Non-Python function generation not yet implemented.") -########################################################################################## - class Engine: - """ - PyPLE engine class. - """ - def operator(self, name): - return list(Operator.selectBy(name=name))[0] - - def __init__(self, debug=0, dburi=None): - """ - PyPLE Engine constructor - """ + def __init__(self, debug=DEBUG): self.debuglevel = debug - self.connect_to_db(dburi) - - # Bind functions to internal operators - internal_operators = list(Operator.selectBy(engine='internal')) - internal_functions = { - 'AND': Operator.op_and, - 'OR': Operator.op_or, - 'NOT': Operator.op_not, - 'XOR': Operator.op_xor, - 'NAND': Operator.op_nand - } - for op in internal_operators: - op.function = internal_functions[op.name] + self.dbconnection = None - #def add_op_function(self, name, f, pid=None): - # """ - # Adds an operator based on an already extant function (no eval call) - # Parameters: - # name Name of operator (NOTE: Must be unique!) (string) - # f Function implementing logic of operator (method) - # [pid] Persistent ID used in database (int; mostly likely None if called directly) - # """ - # if name in self.functions['name']: - # raise Exception("Function with name '" + str(name) + "' already exists!") - # fid = self.next_f_id - # self.next_f_id = self.next_f_id + 1 - # self.functions['id'][fid] = f - # self.functions['name'][name] = f - # if pid is not None: self.functions['pid'][pid] = f - # - #def add_operator(self, name, o, pid=None): - # """Adds an operator to internal index""" - # self.operators['name'][name] = o - # if pid is not None: - # self.operators['pid'][pid] = o - # - #def evaluate_by_id(self, fid, LHS, RHS): - # """ - # MANUALLY evaluates an expression, looking up the function by id. - # Parameters: - # fid id of function (looked up in self.functions['id']) - # LHS left hand side of expression to be evaluated - # RHS right hand side of expression to be evaluated - # Returns: 2-tuple - # type Type of value returned (instance of Python built-in class Type) - # val Value of expression - # """ - # f = self.functions['id'][fid] - # val = f(LHS, RHS) - # return (type(val), val) - # - #def evaluate_by_name(self, name, LHS, RHS): - # """ - # MANUALLY evaluates an expression, looking up the function by name. - # Parameters: same as evaluate_by_id, except using name (string) instead of id (int) - # Returns: same as evaluate_by_id - # """ - # f = self.functions['name'][name] - # val = f(LHS, RHS) - # return (type(val), val) - @staticmethod def build_db_uri(d): - """ - Builds a SQLObject database connection URI from dictionary of connection parameters. - The dictionary should have the following keys: - dbtype e.g. 'mysql' - username - password - host - port - database - """ - uri = d['dbtype'] + "://" + d['username'] + ":" + d['password'] + "@" + d['host'] + ":" + str(d['port']) + "/" + d['database'] - return uri + """ + Build database connection URI from dictionary of connection parameters + """ + uri = "%s://%s:%s@%s:%d/%s" % (d['dbtype'], d['username'], d['password'], d['host'], d['port'], d['database']) + if DEBUG: + uri = uri + "?debug=1" + return uri def connect_to_db(self, uri): - if self.debuglevel > 0: - print "Connecting to DB with: %s" % uri - - self.dbconnection = connectionForURI(uri) - sqlhub.processConnection = self.dbconnection - - if self.debuglevel > 0: - print "Connected to DB: %s" % self.dbconnection - -########################################################################################## - -def create_tables(): - """ - Issue CREATE TABLE commands via SQLObject - """ + if self.debuglevel > 0: + print "Connecting to DB with: %s" % uri + + self.dbconnection = connectionForURI(uri) + sqlhub.processConnection = self.dbconnection + if self.debuglevel > 0: + print "Connected to DB: %s" % self.dbconnection - # Connect to DB (must have create table privileges on target DB) - import syck - dburi = Engine.build_db_uri(syck.load(open("root.yaml").read())) - sqlhub.processConnection = connectionForURI(dburi) + def create_tables(self): + for table in PYPLE_TABLES: + table.createTable() - # Create tables - BasePyPLEType.createTable() - Expression.createTable() - Element.createTable() - Operator.createTable() - Code.createTable() - print "CREATE TABLEs done." - - # Add internal operators - for opname in RESERVED_OPERATORS: - o = Operator(name=opname, engine='internal', code=None) - print "Added Operator %s" % o.name + def drop_tables(self): + for table in PYPLE_TABLES: + table.dropTable(ifExists=True) + if __name__ == "__main__": - print PYPLE_TAGLINE - print PYPLE_COPYRIGHT - print - #TODO: handle params; if "--create-tables", do create_tables() + import yaml #PyYAML: YAML parser/emitter - because its easy_install isn't b0rked like PySyck's: see http://pyyaml.org/ticket/44 + E = Engine() + E.connect_to_db(Engine.build_db_uri(yaml.load(open('pyple-db.yaml').read()))) + E.drop_tables() + E.create_tables() - print "-"*40 - print "Instantiating PyPLE Engine object: ", - import syck - dburi = Engine.build_db_uri(syck.load(open("mysql.yaml").read())) - P = Engine(debug=1, dburi=dburi) - print "Done." - print "-"*40 + andtf = AND(params=[True, False]) + print "andtf:", andtf + print "andtf.eval():", andtf.eval() - print "Test 0:" - l1 = Element.create(2) - r1 = Element.create(False) - and_op = P.operator('AND') #selectBy(name='AND') - print "and_op:", and_op - print "function0:", and_op.function - restult0 = and_op.eval(l1, r1) - print "Test 0 result:" - print result0 + txt = "ORDER, for the reasons set forth in the related Memoranda Opinions issued in this matter on 06/30/06 and 10/10/06, and for good cause, the final Markman definitions applicable to the disputed claim terms and phrases are as follows: (see Order for details). Signed by Judge T. S. Ellis III on 10/10/06. Copies mailed: yes (pmil) (Entered: 10/12/2006)" + ### Operator tests ### - print "*" * ASTERISKS - print "Testing 1: " - code1 = Code(name='always_true', content="True") - o_at = Operator(name='always_true', engine='python', code=code1) - print "function:", o_at.function - result1 = o_at.eval(l1, r1) - print "Test 1:", result1 + starts_with_order = Regex(params=["^ORDER"]) ### + print "starts_with_order:", starts_with_order.eval(txt) + contains_markman = CIRegex(params=["markman"]) + print "contains_markman:", contains_markman.eval(txt) + both = AND(params=[starts_with_order, contains_markman]) + print "both:", both.eval(txt) + not_matching = CIRegex(params=["foobar"]) + print "not_matching:", not_matching.eval(txt) + false_and = AND(params=[starts_with_order, not_matching]) + print "false_and:", false_and.eval(txt) + print "false_and (alt. data):", false_and.eval("ORDER re: foobar and stuff") - print "*" * ASTERISKS - print "Testing 2: " - code2 = "int(LHS) * int(RHS)" - l2 = 2 - r2 = 3 - o_mul = Operator.Operator(P, 'multiply_integers', Operator.ENGINE_PYTHON, None, code2) - result2 = P.evaluate_by_name('multiply_integers', l2, r2) - print result2 + ### RuleSet tests ### - print "*" * ASTERISKS - print "Testing AND: " - print P.evaluate_by_name('and', True, False) - - print "*" * ASTERISKS - print "Testing OR: " - print P.evaluate_by_name('or', True, False) - - print "*" * ASTERISKS - print "Testing NOT: " - print P.evaluate_by_name('not', True, False) - - print "*" * ASTERISKS - print "Testing XOR: " - print P.evaluate_by_name('xor', True, False) - - print "*" * ASTERISKS - print "Testing NAND(T,F): " - print P.evaluate_by_name('nand', True, False) - print "*" * ASTERISKS - print "Testing NAND(T,T): ", - print P.evaluate_by_name('nand', True, True) - - print "*" * ASTERISKS - print "Testing Expression.eval() [multiply_integers]" - op_multiply = P.operators['name']['multiply_integers'] - e1 = Element.Element(10) - print e1 - e2 = Element.Element(5) - print e2 - x = Expression.Expression(op_multiply, e1, e2) - rx = x.eval() - print rx - - print "*" * ASTERISKS - print "Testing Expression.eval() [and]" - op_and = P.operators['name']['and'] - e2_1 = Element.Element(True) - print e2_1 - e2_2 = Element.Element(False) - print e2_2 - x2 = Expression.Expression(op_and, e2_1, e2_2) - rx2 = x2.eval() - print rx2 - - print "*" * ASTERISKS - from pprint import pprint - pprint(P.operators) - - print "*" * ASTERISKS - - print "The End." + print "initializing RuleSet" + rs = RuletSet(name="test_ruleset") + rs.root_rule = both + actionfunction1 = ActionFunction() + action1 = Action(function=actionfunction1) + rs.addAction(action1) + print "rs.eval():", rs.eval(txt) + rs.eval_and_invoke(txt) -########################################################################################## \ No newline at end of file + +################################################################################################## +# v0.1.0 below... +################################################################################################## + +#class Operator: +# +# def __init__(self, arguments=None): +# if arguments is None: +# self.arguments = [] +# else: +# self.arguments = arguments +# +# def pre_eval(self, data): +# """ +# Runs eval() on any child Operators in arguments +# """ +# evaled_args = [] +# for arg in arguments: +# if isinstance(arg, Operator): +# evaled_args.append(arg.eval(data)) # pass data down the logic stack +# else: +# evaled_args.append(arg) +# return evaled_args +# +# def eval(self, data): +# return self.eval_function(data) +# +# +#class BooleanOperator(Operator): +# def __init__(self, arguments=None): +# Operator.__init__(self, arguments=arguments) +# +#class AND(BooleanOperator): +# def eval_function(self, data): +# for datum in data: +# if not datum: +# return False +# return True +# +#class OR(BooleanOperator): +# def eval_function(self, data): +# for datum in data: +# if datum: +# return True +# return False +# +#class NOT(BooleanOperator): +# def eval_function(self, data): +# if len(data) != 2: +# raise ValueError("wrong size data list (must be 2 elements long") #TODO: refactor to something like check_length(data, 2) +# return data[0] and not data[1] +# +#class XOR(BooleanOperator): +# def eval_function(self, data): +# if len(data) != 2: +# raise ValueError("wrong size data list (must be 2 elements long") #TODO: refactor to something like check_length(data, 2) +# return (data[0] or data[1]) and not (data[0] and data[1]) +# +#class NAND(BooleanOperator): +# def eval_function(self, data): +# if len(data) != 2: +# raise ValueError("wrong size data list (must be 2 elements long") #TODO: refactor to something like check_length(data, 2) +# if data[0] and data[1]: +# return False +# else: +# return True +# +#class MatchRegex(Operator): +# def __init__(self, arguments=None, case_sensitive=True): +# """ +# arguments should be a 1-element list string with the regex pattern as a string +# """ +# Operator.__init__(self, arguments=arguments) +# self.regexes = [] +# for arg in self.arguments: +# if case_sensitive: +# self.regexes.append(re.compile(arg)) +# else: +# self.regexes.append(re.compile(arg, re.IGNORECASE)) +# +# def eval_function(self, data): +# """ +# Data should be a string to match against +# """ +# for expr in self.regexes: +# result = expr.search(data) +# if result: +# return True +# return False +# +#class MatchRegexCI(MatchRegex): # case-insensitive +# def __init__(self, arguments=None): +# MatchRegex.__init__(self, arguments=arguments, case_sensitive=False) +# +# +#class Engine: +# @staticmethod +# def build_db_uri(self, d): +# """ +# Build database connection URI from dictionary of connection parameters +# """ +# uri = "%s://%s:%s@%s:%d/%s" % (d['dbtype'], d['username'], d['password'], d['host'], d['port'], d['database']) +# return uri +# +# def connect_to_db(self, uri): +# if self.debuglevel > 0: +# print "Connecting to DB with: %s" % uri +# +# self.dbconnection = sqlobject.connectionForURI(uri) +# if self.debuglevel > 0: +# print "Connected to DB: %s" % self.dbconnection +# +# def create_tables(self): +# for table in PYPLE_TABLES: +# table.createTable() +# +# +####### TEST CASES ###### +# +#if __name__ == "__main__": +# +# import syck # YAML parser +# dburi = Engine.build_db_uri(syck.load(open("pyple-db.yaml"))) +# E = Engine(debug=1, dburi=dburi) +# +# entries = {} +# entries[300] = "ORDER that Synthon's claims of infringement of the '738 Patent, as set forth in Count Two of its Complaint, are hereby DISMISSED with prejudice (see Order for details). Signed by Judge T. S. Ellis III on 08/31/06. Copies mailed: yes (pmil) (Entered: 09/01/2006)" +# entries[301] = "MEMORANDUM OPINION RE: Post-Verdict Markman Opinion. Signed by Judge T. S. Ellis III on 10/10/06. Copies mailed: yes (pmil) (Entered: 10/12/2006)" +# entries[302] = "ORDER, for the reasons set forth in the related Memoranda Opinions issued in this matter on 06/30/06 and 10/10/06, and for good cause, the final Markman definitions applicable to the disputed claim terms and phrases are as follows: (see Order for details). Signed by Judge T. S. Ellis III on 10/10/06. Copies mailed: yes (pmil) (Entered: 10/12/2006)" +# order_defs = ['order', 'opinion'] +# markman_defs = ['markman', 'claim.{0,3}constr'] +# excl = ['Minute Entry', 'ORDER ENLARGING TIME', 'MARKMAN HEARING', 'hearing is set', 'Motion for Leave', 'Motion to Seal', 'DEFERRING a Markman determination', 'Claim Construction Statement', 'in Limine', 'SCHEDULING ORDER', 'parties shall', 'Docket Control', 'page limit', 'page restriction', 'extend time', 'Show Cause'] +# +# starts_with_order = MatchRegex(["^ORDER"]) +# +# is_order = OR( [ MatchRegexCI([pattern]) for pattern in order_defs ] ) +# is_markman = OR( [ MatchRegexCI([pattern]) for pattern in markman_defs ] ) +# not_excluded = AND( [NOT(MatchRegexCI([pattern])) for pattern in excl] ) +# big_statement = AND([is_order, is_markman, not_excluded]) +# +# for key in entries: +# print "Entry #", key +# swo = starts_with_order.eval(entries[key]) +# if swo: +# print "Starts with 'ORDER'." +# else: +# print "Does not start with 'ORDER'." +# +# result = big_statement.eval([entries[key]]) +# print "Is #", key, "a Markman order???", result +# print "-"*40 +# +# print "The end." \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |