本文整理匯總了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)
示例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__()
示例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))
示例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)
示例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]
示例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
示例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
示例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)
示例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
示例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")
示例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)
示例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]
示例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)
示例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)
示例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