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


Python rule.Rule类代码示例

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


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

示例1: min

def min(brd, aa= -64, depth=10, best=()):
    if depth == 0:
        return ((), calc(brd))
    val = 64
    bestmove = ()
    moves = brd.getMove(brd.w)
    if len(moves) == 0:
       return (bestmove, 64) 
    if best:
        moves.append(best)
    for i in range(len(moves)-1, -1, -1):
        if best and i < len(moves)-1 and moves[i] == best:
            continue;
        w = move(moves[i][0], moves[i][1], brd.w)
        tmp = Brd(brd.b, w)
        Rule.refresh(moves[i][1], tmp.w, tmp.b, tmp)
        response = max(tmp, val, depth - 1, best=())[1]
        if response < aa:
            bestmove = moves[i]
            val = response
            break
        if response < val:
            bestmove = moves[i]
            val = response
    if val == 64: #white lose anyway
        bestmove = moves[0]
    return (bestmove, val)     
开发者ID:coolcooleric,项目名称:siding,代码行数:27,代码来源:value.py

示例2: p_rule_single

def p_rule_single(p):
    'rule_single : atom COLONDASH atoms PERIOD'
    global aux_index
    c = Rule(p[1], p[3], aux_index)
    aux_index = aux_index + 1
    rule_map.update(c.rule_map)
    p[0] = c.__str__()
开发者ID:jkoskela,项目名称:gddb,代码行数:7,代码来源:parsedlv.py

示例3: reply

    def reply(self, data, cb):
        info = data
        if not isinstance(data, Info):
            info = Info(data)

        if not self.config.get('keepBlank', False) and info.text:
            info.text = info.text.trim()

        rule_list = self.routes
        waiter = self.wait_rules.get(info.user, None)

        if waiter:
            rule_list = [].extend(waiter).extend(self.routes)
            self.last_wait_rules[info.user] = waiter
            self.wait_rules[info.user] = None

        for i in range(0, len(rule_list)):
            rule = rule_list[i]
            if Rule.is_match(info, rule):
                weixinlogger.info("match %s" % rule.name)
                conversationlogger.info("match %s" % rule.name)
                rule.count = i
                result = Rule.execute(info, rule, cb)
                if isinstance(result, (str, unicode)):
                    result = BuildConfig(MessageBuilder.TYPE_RAW_TEXT, None, result)
                if result:
                    if rule.replies:
                        self.wait(info.user, Rule.convert(rule.replies, rule.name))
                    return cb(None, result)

            else:
                logger.debug("not match %s" % rule.name)

        return cb('404', BuildConfig(MessageBuilder.TYPE_RAW_TEXT, None, self.get_status('404') + info.text))
开发者ID:,项目名称:,代码行数:34,代码来源:

示例4: max

def max(brd, bb=64, depth=10, best=()):
    if depth == 0:
        return ((), calc(brd))  
    bestmove = () 
    val = -64  
    moves = brd.getMove(brd.b)
    if len(moves) == 0:
       return (bestmove, -64) 
    if len(best) > 0:
        moves.append(best)
    for i in range(len(moves)-1, -1, -1):
        if best and i < len(moves)-1 and moves[i] == best:
            continue;
        b = move(moves[i][0], moves[i][1], brd.b)
        tmp = Brd(b, brd.w)
        Rule.refresh(moves[i][1], tmp.b, tmp.w, tmp)
        response = min(tmp, val, depth - 1, best=())[1]
        if response > bb:
            bestmove = moves[i]
            val = response
            break;
        if response > val:
            bestmove = moves[i]
            val = response
    if val == -64: #black lose anyway
        bestmove = moves[0]
    return (bestmove, val)
开发者ID:coolcooleric,项目名称:siding,代码行数:27,代码来源:value.py

示例5: __init__

    def __init__(self, d, sip, sp, dip, dp, p, i, action, style, ts=None, flag="None"):

        Rule.__init__(self, d, sip, sp, dip, dp, p, i, action, style, ts, flag)
        self.action = "block"
        self.numPortsScanned = len(self.dPorts.elements)
        sortedValues = self.dPorts.elements.values()
        sortedValues.sort()
        self.startPort = sortedValues[0]
        self.endPort = sortedValues[self.numPortsScanned-1]
开发者ID:constanze,项目名称:rulegen,代码行数:9,代码来源:portscanRule.py

示例6: make_grammar

 def make_grammar(self):
     grammar = Grammar()
     r1 = Rule(
         Symbol("NP", {"AGR": "?a"}), [
             Symbol("ART", {"AGR": "?a"}), Symbol("N", {"AGR": "?a"})])
     r1.set_variable_code("?a", -1L)
     # -1L should be default for any undefined variable
     # that is referenced while constructing
     grammar.add_rule(r1)
     return grammar
开发者ID:minopret,项目名称:topdown,代码行数:10,代码来源:sample_parser.py

示例7: parseRule

def parseRule(fp,dataset):
    """"""
    rule=Rule()      
    
    #rule name 
    name=geti(fp)   

    #for
    token=geti(fp)
    if token!='FOR':
        log.error('Rule has no FOR symbol, line %d'%common.counter)
        return

    #(
    token=geti(fp)
    if token!='(':
        log.error('Rule FOR has no ( symbol, line %d'%common.counter)
        return

    #for..
    token=geti(fp)
    rule.target=token

    #)
    token=geti(fp)
    if token!=')':
        log.error('Rule FOR brackets not match , line %d'%common.counter)
        return
    
    #;
    token=geti(fp)
    if token!=';':
        log.error('Rule FOR not end with ; , line %d'%common.counter)
        return

    #local
    parseLocal(fp,rule)

    #code
    parseCode(fp,rule)

    # where clause
    rule.where=parseWhere(fp)       

    #parse END_RULE
    token=geti(fp)
    if token!='END_RULE':
        log.error('RULE Defination has no END_RULE, line %d'%common.counter)
        return
    token=geti(fp)#skip ;   
    if token!=';':
        log.error('RULE Defination does not end with ;, line %d'%common.counter)
        return

    dataset.rules[name]=rule
开发者ID:chenxiaohui,项目名称:BimCenter,代码行数:55,代码来源:ruleparser.py

示例8: __init__

    def __init__(self):
        self.rules = []
        self.debug_info = []
        self.selected_rule_index = 0

        # Init rules, this domain is simple and known so we can define each one of the rules
        for last in range(1, 4):
            for second_to_last in range(1, 4):
                for consequent in range(1, 4):
                    rule = Rule()
                    rule.set(last, second_to_last, int(consequent))
                    self.rules.append(rule)
开发者ID:fivunlm,项目名称:spr-es,代码行数:12,代码来源:rule_manager.py

示例9: translate

    def translate(self, raw_rule):
        parser = EZRuleParser()
        ez_rule = parser.parse(raw_rule)

        if not EZTranslator._is_valid_rule(ez_rule):
           return None

        ios_rule = Rule()
        ios_rule.action = EZTranslator._action_from_ez(ez_rule)
        ios_rule.trigger = EZTranslator._trigger_from_ez(ez_rule)

        return ios_rule
开发者ID:remypanicker,项目名称:Antelope,代码行数:12,代码来源:ez_translator.py

示例10: test19

 def test19(self):
     r = Rule("/before/<int:x>/<alphanum:y>/<path:path>")
     
     s = r.test("/before/123/xyz123/some/file.jpg")
     self.assertTrue(s.match())
     self.assertEqual(s.param("x"), 123)
     self.assertEqual(s.param("y"), "xyz123")
     self.assertEqual(s.param("path"), "some/file.jpg")
     
     s = r.test("/before/456/qrs789/another/file.jpg")
     self.assertTrue(s.match())
     self.assertEqual(s.param("x"), 456)
     self.assertEqual(s.param("y"), "qrs789")
     self.assertEqual(s.param("path"), "another/file.jpg")
开发者ID:stereohead,项目名称:wsgi-cahin,代码行数:14,代码来源:tests.py

示例11: __init__

    def __init__(self, service_get_caps_uri):
        #
        #   Rule details
        #
        self.rule_id = 'web_service_name'
        self.rule_name = 'Web Service Name'
        self.rule_business_definition = 'The name is a summarised title (see above) of the service.\n' + \
            'The primary purpose of service name is to support machine-to-machine communications.\n' + \
            'Where possible, the service name should be meaningful to humans.\n' + \
            'The name should be a reflection of the service title (see above), sanitized to be machine readable.\n' + \
            'Describes the Service, not the data.\n' + \
            'Acronyms are allowed ONLY if they are a widely understood standard or an official name (e.g. DEM).\n' + \
            'New service names should be consistent with existing service names.\n' + \
            'Must not duplicate an existing GA web service name.\n'
        self.rule_authority = 'http://pid-dev.ga.gov.au/organisation/ga'
        self.rule_functional_definition = '120 character limit\n' +\
            'alphanumeric characters and underscores only\n' +\
            'machine-readable reflection of the web service title\n' + \
            'acronyms from controlled list only\n' + \
            'not a duplicate of existing name'
        self.component_name = 'string'
        self.passed = True
        self.fail_reasons = []
        self.components_total_count = 1
        self.components_failed_count = 0
        self.failed_components = None

        #
        #   Rule code
        #

        # get the name, from where?

        #
        #   Call the base Rule constructor
        #
        Rule.__init__(self,
                      self.rule_id,
                      self.rule_name,
                      self.rule_business_definition,
                      self.rule_authority,
                      self.rule_functional_definition,
                      self.component_name,
                      self.passed,
                      self.fail_reasons,
                      self.components_total_count,
                      self.components_failed_count,
                      self.failed_components)
开发者ID:nicholascar,项目名称:rules_ga_ogcws,代码行数:48,代码来源:ruleset_ga_ws_pub_stds.py

示例12: _crossover

    def _crossover(self, list_of_rules):
        """
        Crea cruces entre las reglas en la lista `list_of_rules`.

        TODO: A DEFINIRSE.
            - Parametros
            - Eleccion
            - Forma de cruzamiento
        """
        """
        Implementacion α. Suponiendo que se obtienen 4 reglas, y se quieren
        10 en total se crean hijos a partir de las combinaciones de 4 tomadas
        de a dos (6) y se lo suma a los padres para un total de 10.
        """
        if len(list_of_rules) > 1:
            combinations = [x for x in itertools.combinations(list_of_rules, 2)]
            # Uso itertools.combinations para crear sets de combinaciones de las reglas.
            while len(list_of_rules) < self.size_rule_generation:
                for rule1, rule2 in combinations:
                    new_rule = Rule.crossover(rule1['rule'], rule2['rule'])
                    rule_map = {'fitness': (0, 0), 'rule': new_rule}
                    list_of_rules.append(rule_map)
        else:
            print "Invalid number of rules to crossover (" + str(len(list_of_rules)) + ")."
            exit(0)

        return list_of_rules[:self.size_rule_generation]
开发者ID:vierja,项目名称:clasificacion-de-musica,代码行数:27,代码来源:classifier.py

示例13: __init__

 def __init__(self, *modifiers):
     self._rule = Rule()
     for modifier in modifiers:
         modifier(self._rule)
     self._fields = dict(self._rule.get_target_fields() or {})
     self.__dict__.update(self._fields)
     self._all_instances.append(self)
开发者ID:jhicks-camgian,项目名称:rulu,代码行数:7,代码来源:ruledef.py

示例14: proposeRule

    def proposeRule(self, facet, description, category, relation, oldCodelet):
        """Creates a proposed rule, and posts a rule-strength-tester codelet.

        The new codelet has urgency a function of the degree of conceptual-depth of the descriptions in the rule
        """
        from rule import Rule

        rule = Rule(facet, description, category, relation)
        rule.updateStrength()
        if description and relation:
            depths = description.conceptualDepth + relation.conceptualDepth
            depths /= 200.0
            urgency = math.sqrt(depths) * 100.0
        else:
            urgency = 0
        self.newCodelet('rule-strength-tester', oldCodelet, urgency, rule)
开发者ID:OrmesKD,项目名称:co.py.cat,代码行数:16,代码来源:coderack.py

示例15: fromString

 def fromString(self, string):
     policy=Policy()
     elements = Grammar.parsePolicy(string)
     for ruleElements in elements:
         rule = Rule.fromElements(ruleElements)
         policy.rules.append(rule)
     return policy
开发者ID:ptsankov,项目名称:bellog,代码行数:7,代码来源:policy.py


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