当前位置: 首页>>代码示例>>Python>>正文


Python Rule.Rule类代码示例

本文整理汇总了Python中Rule.Rule的典型用法代码示例。如果您正苦于以下问题:Python Rule类的具体用法?Python Rule怎么用?Python Rule使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Rule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: topDownInduction

def topDownInduction(tree, s, split=False, LabelDict=None):
    """
    Rule Generation
    """
    global INVALIDS, DELETES, EXCEPTIONS

    logging.info("string: {}".format(s))
    logging.info("tree: {}".format(tree))
    
    rules = set()
    treeBuffer = [(tree,'S!')]
    try:
        while treeBuffer:
        
            r = Rule()
            node, label = treeBuffer.pop()
            
            arguments = ['X'] * len(node.childNodes) if not split else [LabelDict[child.name] for child in node.childNodes]
            
            for idx,child in enumerate(node.childNodes):
                treeBuffer.append((child,arguments[idx]))
            #
            # create rule label
            #
            r.label = getLabel(label, node.idx, arguments)
            #
            # create string representation
            #
            logging.debug("node.interval:".format(node.interval))
            interval = node.interval
            for child in node.childNodes:
                interval = interval.without(child.interval)
            logging.debug("Interval:".format(interval))
            r.s = getStringRule(interval, s)
            #print r.s
            #
            # create meaning representation
            #
            r.t = getMeaningRule(node.name,len(node.childNodes))
            
            if len(node.childNodes) != interval.flatten().count(-1):
                logging.debug("Invalid number of arguments: child({}) interval({})".format(
                    len(node.childNodes),
                    interval.flatten().count(-1))
                )
                INVALIDS += 1
                return set()
            if r.s in ("?1", "*(?1,?2)"):
                logging.debug("Deleting homorphism: {}".format(r.s))
                DELETES += 1
                return set()
            
            rules.add(r)

    except Exception as e:
        logging.error(e)
        EXCEPTIONS += 1
        return set()

    return rules
开发者ID:Rene90,项目名称:grammar_induction,代码行数:60,代码来源:inductionMethods.py

示例2: newObject

 def newObject(self,e=''):
     """
     adds into the current ruleChain (starting a new Rule)
     """
     rule = Rule(e)
     rule.minZoom=float(self.scalepair[0])
     rule.maxZoom=float(self.scalepair[1])
     self.ruleChains.append(rule)
开发者ID:progserega,项目名称:kothic,代码行数:8,代码来源:StyleChooser.py

示例3: write_rules

    def write_rules(self,req):
        '''Get the posted rules and write them to the temporary session table.'''
        # read post values and save them. Intended as an Ajax call.

        form_vars = req.POST
            #print "Failed to open the rules file."
            # rule_file = open('/var/tmp/rules_list.dat','wb')

        rules = []
        try:
            try:
                rule_file = open('/var/tmp/rules_list.dat','rb')
            except:
                pass
            rules = pickle.load(rule_file)
            rule_file.close()
        except:
            rules = []
            #return "Failed to read the rules."

        try:
            command = form_vars['command']
            if command == 'clear':
                try:
                    rule_file = open('/var/tmp/rules_list.dat','wb')
                    rules = []
                    pickle.dump(rules,rule_file)
                    rule_file.close()
                except:
                    pass
                # self.session.cachestore['temp_rules'] = rules
                # self.session.save()
                return 'success'
        except KeyError:
            pass



        try:
            r = Rule()
            r.action = form_vars['action']
            r.content = 'children:' + form_vars['content']
            r.theme = 'children:' + form_vars['theme']
        except KeyError:
            return "failed"


        rules.append(r)
        try:
            rule_file = open('/var/tmp/rules_list.dat','wb')
            pickle.dump(rules,rule_file)
        except:
            return "Failed to Write rules"

        # self.session.cachestore['temp_rules'] = rules
        # self.session.save()
        return 'success'
开发者ID:macagua,项目名称:Motini,代码行数:57,代码来源:StartController.py

示例4: __init__

        def __init__ (self, refresh, refresh_header, vsrv, rule, apply):
            CTK.Container.__init__ (self)
            pre = 'vserver!%s!rule!%s!match' %(vsrv, rule)

            rule = Rule (pre)
            rule.bind ('changed',        refresh.JS_to_refresh() + refresh_header.JS_to_refresh())
            rule.bind ('submit_success', refresh.JS_to_refresh() + refresh_header.JS_to_refresh())

            self += CTK.RawHTML ("<h2>%s</h2>" % (_('Matching Rule')))
            self += CTK.Indenter (rule)
开发者ID:mdavid,项目名称:cherokee-webserver-svnclone,代码行数:10,代码来源:PageEntry.py

示例5: __init__

        def __init__ (self, refresh, refresh_header, vsrv, rule, apply):
            CTK.Container.__init__ (self)
            pre = 'vserver!%s!rule!%s!match' %(vsrv, rule)

            rule = Rule (pre)
            rule.bind ('changed',        refresh.JS_to_refresh() + refresh_header.JS_to_refresh())
            rule.bind ('submit_success', refresh.JS_to_refresh() + refresh_header.JS_to_refresh())

            self += CTK.RawHTML ("<h2>%s</h2>" % (_('Matching Rule')))
            self += CTK.Indenter (rule)

            # Trigger the 'update_rule_list' so the Rule list sibling
            # widget is updated.
            #
            rule.bind ('submit_success', rule.JS_to_trigger('update_rule_list'))
开发者ID:nuxleus,项目名称:cherokee-webserver,代码行数:15,代码来源:PageEntry.py

示例6: test_rule_txt_with_three_rules

 def test_rule_txt_with_three_rules(self):
     txt_rule = "L1>=20\n" \
                "L2=3\n" \
                "W<=90".splitlines()
     exp_result = [("L1", ">=", 20),
                   ("L2", "=", 3),
                   ("W", "<=", 90)]
     self.assertEqual(exp_result, Rule.parse(txt_rule))
开发者ID:zverxw13,项目名称:LearnMath,代码行数:8,代码来源:RuleTest.py

示例7: test_W_03

    def test_W_03(self):
        txt_rule = "L1>0\n" \
                   "L1<10\n" \
                   "L2>0\n" \
                   "L2<10\n" \
                   "W==90".splitlines()
        rules = Rule.parse(txt_rule)

        Equation.validate_rules_for_w(rules)
开发者ID:zverxw13,项目名称:LearnMath,代码行数:9,代码来源:RuleTest.py

示例8: newRule

 def newRule(self):
     name, ok = QInputDialog.getText(None, "Create new rule", "Enter new rule name:")
     if name is not None and ok:
         self.rule = Rule()
         self.rule.setName(name)
         self.ruleSet.addRule(self.rule)
     self.updateRuleList()
     self.changeCurrentRule(len(self.ruleSet.ruleList) - 1)
     self.ruleListWidget.setCurrentRow(len(self.ruleSet.ruleList) - 1)
开发者ID:offtirael,项目名称:WordChain,代码行数:9,代码来源:RuleEditor.py

示例9: get_ruleset

    def get_ruleset(self):
        ruleset = []

        pair_inclusion = []
        for bw in self.based_words:
            for ic in self.inclusion:
                pair = [bw, ic]
                pair_inclusion.append(pair)

        #Combine each pair in inclusion_list with exclusion_list
        for pair in pair_inclusion:
            for ew in self.exclusion:
                rule = Rule()
                rule.inc_keywords = pair
                rule.exc_keywords.append(ew)

                ruleset.append(rule)

        return ruleset
开发者ID:glorevenhite,项目名称:sentifi,代码行数:19,代码来源:SentifiMessage.py

示例10: test_W_01

    def test_W_01(self):
        txt_rule = "L1>0\n" \
                   "L1<10\n" \
                   "L2>0\n" \
                   "L2<10\n" \
                   "W<=90".splitlines()
        rules = Rule.parse(txt_rule)

        exceptions = (RuleException)
        with self.assertRaises(exceptions):
            Equation.validate_rules_for_w(rules)
开发者ID:zverxw13,项目名称:LearnMath,代码行数:11,代码来源:RuleTest.py

示例11: getRule

    def getRule(self, rid):
        dbRule = self.db.read("SELECT rid, name, enabled FROM rule r WHERE r.rid = :rid", { "rid": int(rid) })

        if dbRule == None:
            return False

        dbRule = dbRule.fetchone()

        if not dbRule:
            return False

        rule = Rule(dbRule['rid'], dbRule['name'], dbRule['enabled'])

        dbResConditions = self.db.read("SELECT c.cid, c.rule_rid, c.device_did, c.device_value_vid, c.operator, c.value, d.name FROM condition c LEFT JOIN device d ON d.did = c.device_did WHERE rule_rid = :rid", {"rid": rule.rid})

        for (cid, rule_rid, device_did, device_value_vid, operator, value, device_name) in dbResConditions.fetchall():
            rule.addCondition({
                "cid": cid,
                "rule_rid": rule_rid,
                "device_did": device_did,
                "device_name": device_name,
                "device_value_vid": device_value_vid,
                "operator": operator,
                "value": value
            })

        dbResActions = self.db.read("SELECT a.aid, a.rule_rid, a.device_did, a.device_action_aid, a.value, d.name FROM action a LEFT JOIN device d ON d.did = a.device_did WHERE a.rule_rid = :rid", {"rid": rule.rid})

        for (aid, rule_rid, device_did, device_action_aid, value, device_name) in dbResActions.fetchall():
            rule.addAction({
                "aid": aid,
                "rule_rid": rule_rid,
                "device_did": device_did,
                "device_name": device_name,
                "device_action_aid": device_action_aid,
                "value": value
            })

        return rule
开发者ID:theNailz,项目名称:drw,代码行数:39,代码来源:RuleManager.py

示例12: load

	def load(self, file, info = False):
		'''
			Loads employee data
			@param file: a file pointer open in "rb" mode
			@params info: T/F whether to print additional info while loading.
			@return True if load was successful, False if any error occured
		'''
		try:
			self.name = pickle.load(file)
			print("  Loading data for %s..."%self.name)
			self.priority = pickle.load(file)
			if info: print("    Read priority: %d"%self.priority)
			self.curShifts = pickle.load(file)
			if info: print("    Read number of shifts: %d"%self.curShifts)
			self.shiftsPerWeek = pickle.load(file)
			if info: print("    Read shifts per week: %s"%self.shiftsPerWeek)
			numRules = pickle.load(file)
			if info: print("    Read number of rules: %d"%numRules)

			print("    %d rules to load"%numRules)
			self.rules = []
			num = 0
			for i in range(0,numRules):
				r = Rule()
				if not r.load(file, num, info):
					print("\nError (%s): Loaded invalid rule, aborting..."%self.name)
					return False
				self.setRule(r)
				num += 1

		except Exception as e:
			print("\nError: %s while loading %s"%(str(e), self.name))
			return False

		if info: print("  Finished loading data for %s"%self.name)
		return True
开发者ID:calebawatts,项目名称:Shift-Scheduler,代码行数:36,代码来源:Employee.py

示例13: get_Rule

    def get_Rule(self, slist, bookmark, weight):
        def logged_match(m, file, variables):
            common.debug("Testing %s against %s rule (%s)" % (file, self.match_token[0], " ".join(slist)))
            return m(file, variables)

        r = Rule()
        match = self.get_match_function(slist, {"bookmark": bookmark, "weight": weight})
        if match is not None:
            r.bookmark = bookmark
            r.weight = weight
            r.text = " ".join(slist)
            r.match_func = lambda file, variables: logged_match(match, file, variables)
            r.match_token = self.match_token[0]
            return r
开发者ID:bspaans,项目名称:bookmark-tools,代码行数:14,代码来源:RuleParsers.py

示例14: test_rule_txt_with_missing_value

 def test_rule_txt_with_missing_value(self):
     exceptions = (RuleException)
     with self.assertRaises(exceptions):
         txt_rule = "L1>=".splitlines()
         Rule.parse(txt_rule)
开发者ID:zverxw13,项目名称:LearnMath,代码行数:5,代码来源:RuleTest.py

示例15: test_rule_txt_with_invalid_value_02

 def test_rule_txt_with_invalid_value_02(self):
     exceptions = (RuleException)
     with self.assertRaises(exceptions):
         txt_rule = "L1>=10.6".splitlines()
         Rule.parse(txt_rule)
开发者ID:zverxw13,项目名称:LearnMath,代码行数:5,代码来源:RuleTest.py


注:本文中的Rule.Rule类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。