def __init__(self, name, pl_id, board, rules = Kendall): self.name = name # string self.pl_id = pl_id # either 1 (white) or -1 (black) self.b = board # instance of Board class self.rules = rules(self.b) # ruleset
for i in range(len(tokens)): t = tokens[i] if type(t) == str: tokens[i] = symbol(t, t, (i,i+1)) return tokens rules = [ rule("start", ["sentence"]), rule("medium_query", bag( medium="medium", entity_clause=["medium_verb", opt("prep"), "entity"], time_clause=alt("from", "during", "at", "when"), about_clause=["about", "topic"])), rule("sentence", ["medium_query"]), rules("time_unit", ["weeks", "days", "hours"]), rule("time_point", ["integer", "time_unit", "ago"]), rules("time_span", [["before", "time_point"], ["between", "time_point", "and", "timepoint"], ["around", "time_point"]]), # tokens: rule("medium", ["email", "text", "im"]), rule("entity", ["alice", "bob"]), rule("medium_verb", ["between", "to", "from"]), rule("topic", ["concert", "rent", "movie"]) ] tokens = in_sequence(["emails", "to", "bob", "about", "movie"]) con = context() con.compile(flatten(rules))