partition
stringclasses
3 values
func_name
stringlengths
1
134
docstring
stringlengths
1
46.9k
path
stringlengths
4
223
original_string
stringlengths
75
104k
code
stringlengths
75
104k
docstring_tokens
listlengths
1
1.97k
repo
stringlengths
7
55
language
stringclasses
1 value
url
stringlengths
87
315
code_tokens
listlengths
19
28.4k
sha
stringlengths
40
40
valid
Chart.scanner
For each edge expecting a word of this category here, extend the edge.
aima/nlp.py
def scanner(self, j, word): "For each edge expecting a word of this category here, extend the edge." for (i, j, A, alpha, Bb) in self.chart[j]: if Bb and self.grammar.isa(word, Bb[0]): self.add_edge([i, j+1, A, alpha + [(Bb[0], word)], Bb[1:]])
def scanner(self, j, word): "For each edge expecting a word of this category here, extend the edge." for (i, j, A, alpha, Bb) in self.chart[j]: if Bb and self.grammar.isa(word, Bb[0]): self.add_edge([i, j+1, A, alpha + [(Bb[0], word)], Bb[1:]])
[ "For", "each", "edge", "expecting", "a", "word", "of", "this", "category", "here", "extend", "the", "edge", "." ]
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/nlp.py#L160-L164
[ "def", "scanner", "(", "self", ",", "j", ",", "word", ")", ":", "for", "(", "i", ",", "j", ",", "A", ",", "alpha", ",", "Bb", ")", "in", "self", ".", "chart", "[", "j", "]", ":", "if", "Bb", "and", "self", ".", "grammar", ".", "isa", "(", ...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
Chart.predictor
Add to chart any rules for B that could help extend this edge.
aima/nlp.py
def predictor(self, (i, j, A, alpha, Bb)): "Add to chart any rules for B that could help extend this edge." B = Bb[0] if B in self.grammar.rules: for rhs in self.grammar.rewrites_for(B): self.add_edge([j, j, B, [], rhs])
def predictor(self, (i, j, A, alpha, Bb)): "Add to chart any rules for B that could help extend this edge." B = Bb[0] if B in self.grammar.rules: for rhs in self.grammar.rewrites_for(B): self.add_edge([j, j, B, [], rhs])
[ "Add", "to", "chart", "any", "rules", "for", "B", "that", "could", "help", "extend", "this", "edge", "." ]
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/nlp.py#L166-L171
[ "def", "predictor", "(", "self", ",", "(", "i", ",", "j", ",", "A", ",", "alpha", ",", "Bb", ")", ")", ":", "B", "=", "Bb", "[", "0", "]", "if", "B", "in", "self", ".", "grammar", ".", "rules", ":", "for", "rhs", "in", "self", ".", "grammar...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
Chart.extender
See what edges can be extended by this edge.
aima/nlp.py
def extender(self, edge): "See what edges can be extended by this edge." (j, k, B, _, _) = edge for (i, j, A, alpha, B1b) in self.chart[j]: if B1b and B == B1b[0]: self.add_edge([i, k, A, alpha + [edge], B1b[1:]])
def extender(self, edge): "See what edges can be extended by this edge." (j, k, B, _, _) = edge for (i, j, A, alpha, B1b) in self.chart[j]: if B1b and B == B1b[0]: self.add_edge([i, k, A, alpha + [edge], B1b[1:]])
[ "See", "what", "edges", "can", "be", "extended", "by", "this", "edge", "." ]
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/nlp.py#L173-L178
[ "def", "extender", "(", "self", ",", "edge", ")", ":", "(", "j", ",", "k", ",", "B", ",", "_", ",", "_", ")", "=", "edge", "for", "(", "i", ",", "j", ",", "A", ",", "alpha", ",", "B1b", ")", "in", "self", ".", "chart", "[", "j", "]", ":...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
settings
Adds a ``SettingDict`` object for the ``Setting`` model to the context as ``SETTINGS``. Automatically creates non-existent settings with an empty string as the default value.
model_settings/context_processors.py
def settings(request): """ Adds a ``SettingDict`` object for the ``Setting`` model to the context as ``SETTINGS``. Automatically creates non-existent settings with an empty string as the default value. """ settings = Setting.objects.all().as_dict(default='') context = { 'SETTINGS': s...
def settings(request): """ Adds a ``SettingDict`` object for the ``Setting`` model to the context as ``SETTINGS``. Automatically creates non-existent settings with an empty string as the default value. """ settings = Setting.objects.all().as_dict(default='') context = { 'SETTINGS': s...
[ "Adds", "a", "SettingDict", "object", "for", "the", "Setting", "model", "to", "the", "context", "as", "SETTINGS", ".", "Automatically", "creates", "non", "-", "existent", "settings", "with", "an", "empty", "string", "as", "the", "default", "value", "." ]
ixc/django-model-settings
python
https://github.com/ixc/django-model-settings/blob/654233bf7f13619e4531741f9158e7034eac031b/model_settings/context_processors.py#L3-L13
[ "def", "settings", "(", "request", ")", ":", "settings", "=", "Setting", ".", "objects", ".", "all", "(", ")", ".", "as_dict", "(", "default", "=", "''", ")", "context", "=", "{", "'SETTINGS'", ":", "settings", ",", "}", "return", "context" ]
654233bf7f13619e4531741f9158e7034eac031b
valid
SettingModelAdmin.get_child_models
Returns a list of ``(Model, ModelAdmin)`` tuples for ``base_model`` subclasses.
model_settings/admin.py
def get_child_models(self): """ Returns a list of ``(Model, ModelAdmin)`` tuples for ``base_model`` subclasses. """ child_models = [] # Loop through all models with FKs back to `base_model`. for related_object in get_all_related_objects(self.base_model._meta): ...
def get_child_models(self): """ Returns a list of ``(Model, ModelAdmin)`` tuples for ``base_model`` subclasses. """ child_models = [] # Loop through all models with FKs back to `base_model`. for related_object in get_all_related_objects(self.base_model._meta): ...
[ "Returns", "a", "list", "of", "(", "Model", "ModelAdmin", ")", "tuples", "for", "base_model", "subclasses", "." ]
ixc/django-model-settings
python
https://github.com/ixc/django-model-settings/blob/654233bf7f13619e4531741f9158e7034eac031b/model_settings/admin.py#L17-L35
[ "def", "get_child_models", "(", "self", ")", ":", "child_models", "=", "[", "]", "# Loop through all models with FKs back to `base_model`.", "for", "related_object", "in", "get_all_related_objects", "(", "self", ".", "base_model", ".", "_meta", ")", ":", "# Django 1.8 d...
654233bf7f13619e4531741f9158e7034eac031b
valid
DTAgentProgram
A decision-theoretic agent. [Fig. 13.1]
aima/probability.py
def DTAgentProgram(belief_state): "A decision-theoretic agent. [Fig. 13.1]" def program(percept): belief_state.observe(program.action, percept) program.action = argmax(belief_state.actions(), belief_state.expected_outcome_utility) return program.action ...
def DTAgentProgram(belief_state): "A decision-theoretic agent. [Fig. 13.1]" def program(percept): belief_state.observe(program.action, percept) program.action = argmax(belief_state.actions(), belief_state.expected_outcome_utility) return program.action ...
[ "A", "decision", "-", "theoretic", "agent", ".", "[", "Fig", ".", "13", ".", "1", "]" ]
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L10-L18
[ "def", "DTAgentProgram", "(", "belief_state", ")", ":", "def", "program", "(", "percept", ")", ":", "belief_state", ".", "observe", "(", "program", ".", "action", ",", "percept", ")", "program", ".", "action", "=", "argmax", "(", "belief_state", ".", "acti...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
event_values
Return a tuple of the values of variables vars in event. >>> event_values ({'A': 10, 'B': 9, 'C': 8}, ['C', 'A']) (8, 10) >>> event_values ((1, 2), ['C', 'A']) (1, 2)
aima/probability.py
def event_values(event, vars): """Return a tuple of the values of variables vars in event. >>> event_values ({'A': 10, 'B': 9, 'C': 8}, ['C', 'A']) (8, 10) >>> event_values ((1, 2), ['C', 'A']) (1, 2) """ if isinstance(event, tuple) and len(event) == len(vars): return event else:...
def event_values(event, vars): """Return a tuple of the values of variables vars in event. >>> event_values ({'A': 10, 'B': 9, 'C': 8}, ['C', 'A']) (8, 10) >>> event_values ((1, 2), ['C', 'A']) (1, 2) """ if isinstance(event, tuple) and len(event) == len(vars): return event else:...
[ "Return", "a", "tuple", "of", "the", "values", "of", "variables", "vars", "in", "event", ".", ">>>", "event_values", "(", "{", "A", ":", "10", "B", ":", "9", "C", ":", "8", "}", "[", "C", "A", "]", ")", "(", "8", "10", ")", ">>>", "event_values...
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L107-L117
[ "def", "event_values", "(", "event", ",", "vars", ")", ":", "if", "isinstance", "(", "event", ",", "tuple", ")", "and", "len", "(", "event", ")", "==", "len", "(", "vars", ")", ":", "return", "event", "else", ":", "return", "tuple", "(", "[", "even...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
enumerate_joint_ask
Return a probability distribution over the values of the variable X, given the {var:val} observations e, in the JointProbDist P. [Section 13.3] >>> P = JointProbDist(['X', 'Y']) >>> P[0,0] = 0.25; P[0,1] = 0.5; P[1,1] = P[2,1] = 0.125 >>> enumerate_joint_ask('X', dict(Y=1), P).show_approx() '0: 0.66...
aima/probability.py
def enumerate_joint_ask(X, e, P): """Return a probability distribution over the values of the variable X, given the {var:val} observations e, in the JointProbDist P. [Section 13.3] >>> P = JointProbDist(['X', 'Y']) >>> P[0,0] = 0.25; P[0,1] = 0.5; P[1,1] = P[2,1] = 0.125 >>> enumerate_joint_ask('X',...
def enumerate_joint_ask(X, e, P): """Return a probability distribution over the values of the variable X, given the {var:val} observations e, in the JointProbDist P. [Section 13.3] >>> P = JointProbDist(['X', 'Y']) >>> P[0,0] = 0.25; P[0,1] = 0.5; P[1,1] = P[2,1] = 0.125 >>> enumerate_joint_ask('X',...
[ "Return", "a", "probability", "distribution", "over", "the", "values", "of", "the", "variable", "X", "given", "the", "{", "var", ":", "val", "}", "observations", "e", "in", "the", "JointProbDist", "P", ".", "[", "Section", "13", ".", "3", "]", ">>>", "...
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L121-L134
[ "def", "enumerate_joint_ask", "(", "X", ",", "e", ",", "P", ")", ":", "assert", "X", "not", "in", "e", ",", "\"Query variable must be distinct from evidence\"", "Q", "=", "ProbDist", "(", "X", ")", "# probability distribution for X, initially empty", "Y", "=", "["...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
enumerate_joint
Return the sum of those entries in P consistent with e, provided vars is P's remaining variables (the ones not in e).
aima/probability.py
def enumerate_joint(vars, e, P): """Return the sum of those entries in P consistent with e, provided vars is P's remaining variables (the ones not in e).""" if not vars: return P[e] Y, rest = vars[0], vars[1:] return sum([enumerate_joint(rest, extend(e, Y, y), P) for y in P.v...
def enumerate_joint(vars, e, P): """Return the sum of those entries in P consistent with e, provided vars is P's remaining variables (the ones not in e).""" if not vars: return P[e] Y, rest = vars[0], vars[1:] return sum([enumerate_joint(rest, extend(e, Y, y), P) for y in P.v...
[ "Return", "the", "sum", "of", "those", "entries", "in", "P", "consistent", "with", "e", "provided", "vars", "is", "P", "s", "remaining", "variables", "(", "the", "ones", "not", "in", "e", ")", "." ]
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L136-L143
[ "def", "enumerate_joint", "(", "vars", ",", "e", ",", "P", ")", ":", "if", "not", "vars", ":", "return", "P", "[", "e", "]", "Y", ",", "rest", "=", "vars", "[", "0", "]", ",", "vars", "[", "1", ":", "]", "return", "sum", "(", "[", "enumerate_...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
enumeration_ask
Return the conditional probability distribution of variable X given evidence e, from BayesNet bn. [Fig. 14.9] >>> enumeration_ask('Burglary', dict(JohnCalls=T, MaryCalls=T), burglary ... ).show_approx() 'False: 0.716, True: 0.284
aima/probability.py
def enumeration_ask(X, e, bn): """Return the conditional probability distribution of variable X given evidence e, from BayesNet bn. [Fig. 14.9] >>> enumeration_ask('Burglary', dict(JohnCalls=T, MaryCalls=T), burglary ... ).show_approx() 'False: 0.716, True: 0.284'""" assert X not in e, "Query v...
def enumeration_ask(X, e, bn): """Return the conditional probability distribution of variable X given evidence e, from BayesNet bn. [Fig. 14.9] >>> enumeration_ask('Burglary', dict(JohnCalls=T, MaryCalls=T), burglary ... ).show_approx() 'False: 0.716, True: 0.284'""" assert X not in e, "Query v...
[ "Return", "the", "conditional", "probability", "distribution", "of", "variable", "X", "given", "evidence", "e", "from", "BayesNet", "bn", ".", "[", "Fig", ".", "14", ".", "9", "]", ">>>", "enumeration_ask", "(", "Burglary", "dict", "(", "JohnCalls", "=", "...
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L265-L275
[ "def", "enumeration_ask", "(", "X", ",", "e", ",", "bn", ")", ":", "assert", "X", "not", "in", "e", ",", "\"Query variable must be distinct from evidence\"", "Q", "=", "ProbDist", "(", "X", ")", "for", "xi", "in", "bn", ".", "variable_values", "(", "X", ...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
enumerate_all
Return the sum of those entries in P(vars | e{others}) consistent with e, where P is the joint distribution represented by bn, and e{others} means e restricted to bn's other variables (the ones other than vars). Parents must precede children in vars.
aima/probability.py
def enumerate_all(vars, e, bn): """Return the sum of those entries in P(vars | e{others}) consistent with e, where P is the joint distribution represented by bn, and e{others} means e restricted to bn's other variables (the ones other than vars). Parents must precede children in vars.""" if not vars...
def enumerate_all(vars, e, bn): """Return the sum of those entries in P(vars | e{others}) consistent with e, where P is the joint distribution represented by bn, and e{others} means e restricted to bn's other variables (the ones other than vars). Parents must precede children in vars.""" if not vars...
[ "Return", "the", "sum", "of", "those", "entries", "in", "P", "(", "vars", "|", "e", "{", "others", "}", ")", "consistent", "with", "e", "where", "P", "is", "the", "joint", "distribution", "represented", "by", "bn", "and", "e", "{", "others", "}", "me...
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L277-L290
[ "def", "enumerate_all", "(", "vars", ",", "e", ",", "bn", ")", ":", "if", "not", "vars", ":", "return", "1.0", "Y", ",", "rest", "=", "vars", "[", "0", "]", ",", "vars", "[", "1", ":", "]", "Ynode", "=", "bn", ".", "variable_node", "(", "Y", ...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
elimination_ask
Compute bn's P(X|e) by variable elimination. [Fig. 14.11] >>> elimination_ask('Burglary', dict(JohnCalls=T, MaryCalls=T), burglary ... ).show_approx() 'False: 0.716, True: 0.284
aima/probability.py
def elimination_ask(X, e, bn): """Compute bn's P(X|e) by variable elimination. [Fig. 14.11] >>> elimination_ask('Burglary', dict(JohnCalls=T, MaryCalls=T), burglary ... ).show_approx() 'False: 0.716, True: 0.284'""" assert X not in e, "Query variable must be distinct from evidence" factors = []...
def elimination_ask(X, e, bn): """Compute bn's P(X|e) by variable elimination. [Fig. 14.11] >>> elimination_ask('Burglary', dict(JohnCalls=T, MaryCalls=T), burglary ... ).show_approx() 'False: 0.716, True: 0.284'""" assert X not in e, "Query variable must be distinct from evidence" factors = []...
[ "Compute", "bn", "s", "P", "(", "X|e", ")", "by", "variable", "elimination", ".", "[", "Fig", ".", "14", ".", "11", "]", ">>>", "elimination_ask", "(", "Burglary", "dict", "(", "JohnCalls", "=", "T", "MaryCalls", "=", "T", ")", "burglary", "...", ")"...
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L294-L305
[ "def", "elimination_ask", "(", "X", ",", "e", ",", "bn", ")", ":", "assert", "X", "not", "in", "e", ",", "\"Query variable must be distinct from evidence\"", "factors", "=", "[", "]", "for", "var", "in", "reversed", "(", "bn", ".", "vars", ")", ":", "fac...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
make_factor
Return the factor for var in bn's joint distribution given e. That is, bn's full joint distribution, projected to accord with e, is the pointwise product of these factors for bn's variables.
aima/probability.py
def make_factor(var, e, bn): """Return the factor for var in bn's joint distribution given e. That is, bn's full joint distribution, projected to accord with e, is the pointwise product of these factors for bn's variables.""" node = bn.variable_node(var) vars = [X for X in [var] + node.parents if X ...
def make_factor(var, e, bn): """Return the factor for var in bn's joint distribution given e. That is, bn's full joint distribution, projected to accord with e, is the pointwise product of these factors for bn's variables.""" node = bn.variable_node(var) vars = [X for X in [var] + node.parents if X ...
[ "Return", "the", "factor", "for", "var", "in", "bn", "s", "joint", "distribution", "given", "e", ".", "That", "is", "bn", "s", "full", "joint", "distribution", "projected", "to", "accord", "with", "e", "is", "the", "pointwise", "product", "of", "these", ...
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L311-L319
[ "def", "make_factor", "(", "var", ",", "e", ",", "bn", ")", ":", "node", "=", "bn", ".", "variable_node", "(", "var", ")", "vars", "=", "[", "X", "for", "X", "in", "[", "var", "]", "+", "node", ".", "parents", "if", "X", "not", "in", "e", "]"...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
sum_out
Eliminate var from all factors by summing over its values.
aima/probability.py
def sum_out(var, factors, bn): "Eliminate var from all factors by summing over its values." result, var_factors = [], [] for f in factors: (var_factors if var in f.vars else result).append(f) result.append(pointwise_product(var_factors, bn).sum_out(var, bn)) return result
def sum_out(var, factors, bn): "Eliminate var from all factors by summing over its values." result, var_factors = [], [] for f in factors: (var_factors if var in f.vars else result).append(f) result.append(pointwise_product(var_factors, bn).sum_out(var, bn)) return result
[ "Eliminate", "var", "from", "all", "factors", "by", "summing", "over", "its", "values", "." ]
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L324-L330
[ "def", "sum_out", "(", "var", ",", "factors", ",", "bn", ")", ":", "result", ",", "var_factors", "=", "[", "]", ",", "[", "]", "for", "f", "in", "factors", ":", "(", "var_factors", "if", "var", "in", "f", ".", "vars", "else", "result", ")", ".", ...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
all_events
Yield every way of extending e with values for all vars.
aima/probability.py
def all_events(vars, bn, e): "Yield every way of extending e with values for all vars." if not vars: yield e else: X, rest = vars[0], vars[1:] for e1 in all_events(rest, bn, e): for x in bn.variable_values(X): yield extend(e1, X, x)
def all_events(vars, bn, e): "Yield every way of extending e with values for all vars." if not vars: yield e else: X, rest = vars[0], vars[1:] for e1 in all_events(rest, bn, e): for x in bn.variable_values(X): yield extend(e1, X, x)
[ "Yield", "every", "way", "of", "extending", "e", "with", "values", "for", "all", "vars", "." ]
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L364-L372
[ "def", "all_events", "(", "vars", ",", "bn", ",", "e", ")", ":", "if", "not", "vars", ":", "yield", "e", "else", ":", "X", ",", "rest", "=", "vars", "[", "0", "]", ",", "vars", "[", "1", ":", "]", "for", "e1", "in", "all_events", "(", "rest",...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
prior_sample
Randomly sample from bn's full joint distribution. The result is a {variable: value} dict. [Fig. 14.13]
aima/probability.py
def prior_sample(bn): """Randomly sample from bn's full joint distribution. The result is a {variable: value} dict. [Fig. 14.13]""" event = {} for node in bn.nodes: event[node.variable] = node.sample(event) return event
def prior_sample(bn): """Randomly sample from bn's full joint distribution. The result is a {variable: value} dict. [Fig. 14.13]""" event = {} for node in bn.nodes: event[node.variable] = node.sample(event) return event
[ "Randomly", "sample", "from", "bn", "s", "full", "joint", "distribution", ".", "The", "result", "is", "a", "{", "variable", ":", "value", "}", "dict", ".", "[", "Fig", ".", "14", ".", "13", "]" ]
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L387-L393
[ "def", "prior_sample", "(", "bn", ")", ":", "event", "=", "{", "}", "for", "node", "in", "bn", ".", "nodes", ":", "event", "[", "node", ".", "variable", "]", "=", "node", ".", "sample", "(", "event", ")", "return", "event" ]
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
rejection_sampling
Estimate the probability distribution of variable X given evidence e in BayesNet bn, using N samples. [Fig. 14.14] Raises a ZeroDivisionError if all the N samples are rejected, i.e., inconsistent with e. >>> seed(47) >>> rejection_sampling('Burglary', dict(JohnCalls=T, MaryCalls=T), ... burgl...
aima/probability.py
def rejection_sampling(X, e, bn, N): """Estimate the probability distribution of variable X given evidence e in BayesNet bn, using N samples. [Fig. 14.14] Raises a ZeroDivisionError if all the N samples are rejected, i.e., inconsistent with e. >>> seed(47) >>> rejection_sampling('Burglary', dic...
def rejection_sampling(X, e, bn, N): """Estimate the probability distribution of variable X given evidence e in BayesNet bn, using N samples. [Fig. 14.14] Raises a ZeroDivisionError if all the N samples are rejected, i.e., inconsistent with e. >>> seed(47) >>> rejection_sampling('Burglary', dic...
[ "Estimate", "the", "probability", "distribution", "of", "variable", "X", "given", "evidence", "e", "in", "BayesNet", "bn", "using", "N", "samples", ".", "[", "Fig", ".", "14", ".", "14", "]", "Raises", "a", "ZeroDivisionError", "if", "all", "the", "N", "...
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L397-L412
[ "def", "rejection_sampling", "(", "X", ",", "e", ",", "bn", ",", "N", ")", ":", "counts", "=", "dict", "(", "(", "x", ",", "0", ")", "for", "x", "in", "bn", ".", "variable_values", "(", "X", ")", ")", "# bold N in Fig. 14.14", "for", "j", "in", "...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
consistent_with
Is event consistent with the given evidence?
aima/probability.py
def consistent_with(event, evidence): "Is event consistent with the given evidence?" return every(lambda (k, v): evidence.get(k, v) == v, event.items())
def consistent_with(event, evidence): "Is event consistent with the given evidence?" return every(lambda (k, v): evidence.get(k, v) == v, event.items())
[ "Is", "event", "consistent", "with", "the", "given", "evidence?" ]
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L414-L417
[ "def", "consistent_with", "(", "event", ",", "evidence", ")", ":", "return", "every", "(", "lambda", "(", "k", ",", "v", ")", ":", "evidence", ".", "get", "(", "k", ",", "v", ")", "==", "v", ",", "event", ".", "items", "(", ")", ")" ]
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
likelihood_weighting
Estimate the probability distribution of variable X given evidence e in BayesNet bn. [Fig. 14.15] >>> seed(1017) >>> likelihood_weighting('Burglary', dict(JohnCalls=T, MaryCalls=T), ... burglary, 10000).show_approx() 'False: 0.702, True: 0.298'
aima/probability.py
def likelihood_weighting(X, e, bn, N): """Estimate the probability distribution of variable X given evidence e in BayesNet bn. [Fig. 14.15] >>> seed(1017) >>> likelihood_weighting('Burglary', dict(JohnCalls=T, MaryCalls=T), ... burglary, 10000).show_approx() 'False: 0.702, True: 0.298' ""...
def likelihood_weighting(X, e, bn, N): """Estimate the probability distribution of variable X given evidence e in BayesNet bn. [Fig. 14.15] >>> seed(1017) >>> likelihood_weighting('Burglary', dict(JohnCalls=T, MaryCalls=T), ... burglary, 10000).show_approx() 'False: 0.702, True: 0.298' ""...
[ "Estimate", "the", "probability", "distribution", "of", "variable", "X", "given", "evidence", "e", "in", "BayesNet", "bn", ".", "[", "Fig", ".", "14", ".", "15", "]", ">>>", "seed", "(", "1017", ")", ">>>", "likelihood_weighting", "(", "Burglary", "dict", ...
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L421-L433
[ "def", "likelihood_weighting", "(", "X", ",", "e", ",", "bn", ",", "N", ")", ":", "W", "=", "dict", "(", "(", "x", ",", "0", ")", "for", "x", "in", "bn", ".", "variable_values", "(", "X", ")", ")", "for", "j", "in", "xrange", "(", "N", ")", ...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
weighted_sample
Sample an event from bn that's consistent with the evidence e; return the event and its weight, the likelihood that the event accords to the evidence.
aima/probability.py
def weighted_sample(bn, e): """Sample an event from bn that's consistent with the evidence e; return the event and its weight, the likelihood that the event accords to the evidence.""" w = 1 event = dict(e) # boldface x in Fig. 14.15 for node in bn.nodes: Xi = node.variable if Xi...
def weighted_sample(bn, e): """Sample an event from bn that's consistent with the evidence e; return the event and its weight, the likelihood that the event accords to the evidence.""" w = 1 event = dict(e) # boldface x in Fig. 14.15 for node in bn.nodes: Xi = node.variable if Xi...
[ "Sample", "an", "event", "from", "bn", "that", "s", "consistent", "with", "the", "evidence", "e", ";", "return", "the", "event", "and", "its", "weight", "the", "likelihood", "that", "the", "event", "accords", "to", "the", "evidence", "." ]
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L435-L447
[ "def", "weighted_sample", "(", "bn", ",", "e", ")", ":", "w", "=", "1", "event", "=", "dict", "(", "e", ")", "# boldface x in Fig. 14.15", "for", "node", "in", "bn", ".", "nodes", ":", "Xi", "=", "node", ".", "variable", "if", "Xi", "in", "e", ":",...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
gibbs_ask
[Fig. 14.16] >>> seed(1017) >>> gibbs_ask('Burglary', dict(JohnCalls=T, MaryCalls=T), burglary, 1000 ... ).show_approx() 'False: 0.738, True: 0.262'
aima/probability.py
def gibbs_ask(X, e, bn, N): """[Fig. 14.16] >>> seed(1017) >>> gibbs_ask('Burglary', dict(JohnCalls=T, MaryCalls=T), burglary, 1000 ... ).show_approx() 'False: 0.738, True: 0.262' """ assert X not in e, "Query variable must be distinct from evidence" counts = dict((x, 0) for x in bn.var...
def gibbs_ask(X, e, bn, N): """[Fig. 14.16] >>> seed(1017) >>> gibbs_ask('Burglary', dict(JohnCalls=T, MaryCalls=T), burglary, 1000 ... ).show_approx() 'False: 0.738, True: 0.262' """ assert X not in e, "Query variable must be distinct from evidence" counts = dict((x, 0) for x in bn.var...
[ "[", "Fig", ".", "14", ".", "16", "]", ">>>", "seed", "(", "1017", ")", ">>>", "gibbs_ask", "(", "Burglary", "dict", "(", "JohnCalls", "=", "T", "MaryCalls", "=", "T", ")", "burglary", "1000", "...", ")", ".", "show_approx", "()", "False", ":", "0"...
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L451-L468
[ "def", "gibbs_ask", "(", "X", ",", "e", ",", "bn", ",", "N", ")", ":", "assert", "X", "not", "in", "e", ",", "\"Query variable must be distinct from evidence\"", "counts", "=", "dict", "(", "(", "x", ",", "0", ")", "for", "x", "in", "bn", ".", "varia...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
markov_blanket_sample
Return a sample from P(X | mb) where mb denotes that the variables in the Markov blanket of X take their values from event e (which must assign a value to each). The Markov blanket of X is X's parents, children, and children's parents.
aima/probability.py
def markov_blanket_sample(X, e, bn): """Return a sample from P(X | mb) where mb denotes that the variables in the Markov blanket of X take their values from event e (which must assign a value to each). The Markov blanket of X is X's parents, children, and children's parents.""" Xnode = bn.variable_n...
def markov_blanket_sample(X, e, bn): """Return a sample from P(X | mb) where mb denotes that the variables in the Markov blanket of X take their values from event e (which must assign a value to each). The Markov blanket of X is X's parents, children, and children's parents.""" Xnode = bn.variable_n...
[ "Return", "a", "sample", "from", "P", "(", "X", "|", "mb", ")", "where", "mb", "denotes", "that", "the", "variables", "in", "the", "Markov", "blanket", "of", "X", "take", "their", "values", "from", "event", "e", "(", "which", "must", "assign", "a", "...
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L470-L482
[ "def", "markov_blanket_sample", "(", "X", ",", "e", ",", "bn", ")", ":", "Xnode", "=", "bn", ".", "variable_node", "(", "X", ")", "Q", "=", "ProbDist", "(", "X", ")", "for", "xi", "in", "bn", ".", "variable_values", "(", "X", ")", ":", "ei", "=",...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
ProbDist.normalize
Make sure the probabilities of all values sum to 1. Returns the normalized distribution. Raises a ZeroDivisionError if the sum of the values is 0. >>> P = ProbDist('Flip'); P['H'], P['T'] = 35, 65 >>> P = P.normalize() >>> print '%5.3f %5.3f' % (P.prob['H'], P.prob['T']) ...
aima/probability.py
def normalize(self): """Make sure the probabilities of all values sum to 1. Returns the normalized distribution. Raises a ZeroDivisionError if the sum of the values is 0. >>> P = ProbDist('Flip'); P['H'], P['T'] = 35, 65 >>> P = P.normalize() >>> print '%5.3f %5.3f' % (P....
def normalize(self): """Make sure the probabilities of all values sum to 1. Returns the normalized distribution. Raises a ZeroDivisionError if the sum of the values is 0. >>> P = ProbDist('Flip'); P['H'], P['T'] = 35, 65 >>> P = P.normalize() >>> print '%5.3f %5.3f' % (P....
[ "Make", "sure", "the", "probabilities", "of", "all", "values", "sum", "to", "1", ".", "Returns", "the", "normalized", "distribution", ".", "Raises", "a", "ZeroDivisionError", "if", "the", "sum", "of", "the", "values", "is", "0", ".", ">>>", "P", "=", "Pr...
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L51-L64
[ "def", "normalize", "(", "self", ")", ":", "total", "=", "float", "(", "sum", "(", "self", ".", "prob", ".", "values", "(", ")", ")", ")", "if", "not", "(", "1.0", "-", "epsilon", "<", "total", "<", "1.0", "+", "epsilon", ")", ":", "for", "val"...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
ProbDist.show_approx
Show the probabilities rounded and sorted by key, for the sake of portable doctests.
aima/probability.py
def show_approx(self, numfmt='%.3g'): """Show the probabilities rounded and sorted by key, for the sake of portable doctests.""" return ', '.join([('%s: ' + numfmt) % (v, p) for (v, p) in sorted(self.prob.items())])
def show_approx(self, numfmt='%.3g'): """Show the probabilities rounded and sorted by key, for the sake of portable doctests.""" return ', '.join([('%s: ' + numfmt) % (v, p) for (v, p) in sorted(self.prob.items())])
[ "Show", "the", "probabilities", "rounded", "and", "sorted", "by", "key", "for", "the", "sake", "of", "portable", "doctests", "." ]
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L66-L70
[ "def", "show_approx", "(", "self", ",", "numfmt", "=", "'%.3g'", ")", ":", "return", "', '", ".", "join", "(", "[", "(", "'%s: '", "+", "numfmt", ")", "%", "(", "v", ",", "p", ")", "for", "(", "v", ",", "p", ")", "in", "sorted", "(", "self", ...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
BayesNet.add
Add a node to the net. Its parents must already be in the net, and its variable must not.
aima/probability.py
def add(self, node_spec): """Add a node to the net. Its parents must already be in the net, and its variable must not.""" node = BayesNode(*node_spec) assert node.variable not in self.vars assert every(lambda parent: parent in self.vars, node.parents) self.nodes.append(no...
def add(self, node_spec): """Add a node to the net. Its parents must already be in the net, and its variable must not.""" node = BayesNode(*node_spec) assert node.variable not in self.vars assert every(lambda parent: parent in self.vars, node.parents) self.nodes.append(no...
[ "Add", "a", "node", "to", "the", "net", ".", "Its", "parents", "must", "already", "be", "in", "the", "net", "and", "its", "variable", "must", "not", "." ]
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L156-L165
[ "def", "add", "(", "self", ",", "node_spec", ")", ":", "node", "=", "BayesNode", "(", "*", "node_spec", ")", "assert", "node", ".", "variable", "not", "in", "self", ".", "vars", "assert", "every", "(", "lambda", "parent", ":", "parent", "in", "self", ...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
BayesNet.variable_node
Return the node for the variable named var. >>> burglary.variable_node('Burglary').variable 'Burglary
aima/probability.py
def variable_node(self, var): """Return the node for the variable named var. >>> burglary.variable_node('Burglary').variable 'Burglary'""" for n in self.nodes: if n.variable == var: return n raise Exception("No such variable: %s" % var)
def variable_node(self, var): """Return the node for the variable named var. >>> burglary.variable_node('Burglary').variable 'Burglary'""" for n in self.nodes: if n.variable == var: return n raise Exception("No such variable: %s" % var)
[ "Return", "the", "node", "for", "the", "variable", "named", "var", ".", ">>>", "burglary", ".", "variable_node", "(", "Burglary", ")", ".", "variable", "Burglary" ]
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L167-L174
[ "def", "variable_node", "(", "self", ",", "var", ")", ":", "for", "n", "in", "self", ".", "nodes", ":", "if", "n", ".", "variable", "==", "var", ":", "return", "n", "raise", "Exception", "(", "\"No such variable: %s\"", "%", "var", ")" ]
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
BayesNode.p
Return the conditional probability P(X=value | parents=parent_values), where parent_values are the values of parents in event. (event must assign each parent a value.) >>> bn = BayesNode('X', 'Burglary', {T: 0.2, F: 0.625}) >>> bn.p(False, {'Burglary': False, 'Earthquake': True})...
aima/probability.py
def p(self, value, event): """Return the conditional probability P(X=value | parents=parent_values), where parent_values are the values of parents in event. (event must assign each parent a value.) >>> bn = BayesNode('X', 'Burglary', {T: 0.2, F: 0.625}) >>> bn.p(False, {'...
def p(self, value, event): """Return the conditional probability P(X=value | parents=parent_values), where parent_values are the values of parents in event. (event must assign each parent a value.) >>> bn = BayesNode('X', 'Burglary', {T: 0.2, F: 0.625}) >>> bn.p(False, {'...
[ "Return", "the", "conditional", "probability", "P", "(", "X", "=", "value", "|", "parents", "=", "parent_values", ")", "where", "parent_values", "are", "the", "values", "of", "parents", "in", "event", ".", "(", "event", "must", "assign", "each", "parent", ...
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L228-L238
[ "def", "p", "(", "self", ",", "value", ",", "event", ")", ":", "assert", "isinstance", "(", "value", ",", "bool", ")", "ptrue", "=", "self", ".", "cpt", "[", "event_values", "(", "event", ",", "self", ".", "parents", ")", "]", "return", "if_", "(",...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
Factor.pointwise_product
Multiply two factors, combining their variables.
aima/probability.py
def pointwise_product(self, other, bn): "Multiply two factors, combining their variables." vars = list(set(self.vars) | set(other.vars)) cpt = dict((event_values(e, vars), self.p(e) * other.p(e)) for e in all_events(vars, bn, {})) return Factor(vars, cpt)
def pointwise_product(self, other, bn): "Multiply two factors, combining their variables." vars = list(set(self.vars) | set(other.vars)) cpt = dict((event_values(e, vars), self.p(e) * other.p(e)) for e in all_events(vars, bn, {})) return Factor(vars, cpt)
[ "Multiply", "two", "factors", "combining", "their", "variables", "." ]
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L338-L343
[ "def", "pointwise_product", "(", "self", ",", "other", ",", "bn", ")", ":", "vars", "=", "list", "(", "set", "(", "self", ".", "vars", ")", "|", "set", "(", "other", ".", "vars", ")", ")", "cpt", "=", "dict", "(", "(", "event_values", "(", "e", ...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
Factor.sum_out
Make a factor eliminating var by summing over its values.
aima/probability.py
def sum_out(self, var, bn): "Make a factor eliminating var by summing over its values." vars = [X for X in self.vars if X != var] cpt = dict((event_values(e, vars), sum(self.p(extend(e, var, val)) for val in bn.variable_values(var))) ...
def sum_out(self, var, bn): "Make a factor eliminating var by summing over its values." vars = [X for X in self.vars if X != var] cpt = dict((event_values(e, vars), sum(self.p(extend(e, var, val)) for val in bn.variable_values(var))) ...
[ "Make", "a", "factor", "eliminating", "var", "by", "summing", "over", "its", "values", "." ]
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L345-L352
[ "def", "sum_out", "(", "self", ",", "var", ",", "bn", ")", ":", "vars", "=", "[", "X", "for", "X", "in", "self", ".", "vars", "if", "X", "!=", "var", "]", "cpt", "=", "dict", "(", "(", "event_values", "(", "e", ",", "vars", ")", ",", "sum", ...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
Factor.normalize
Return my probabilities; must be down to one variable.
aima/probability.py
def normalize(self): "Return my probabilities; must be down to one variable." assert len(self.vars) == 1 return ProbDist(self.vars[0], dict((k, v) for ((k,), v) in self.cpt.items()))
def normalize(self): "Return my probabilities; must be down to one variable." assert len(self.vars) == 1 return ProbDist(self.vars[0], dict((k, v) for ((k,), v) in self.cpt.items()))
[ "Return", "my", "probabilities", ";", "must", "be", "down", "to", "one", "variable", "." ]
hobson/aima
python
https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L354-L358
[ "def", "normalize", "(", "self", ")", ":", "assert", "len", "(", "self", ".", "vars", ")", "==", "1", "return", "ProbDist", "(", "self", ".", "vars", "[", "0", "]", ",", "dict", "(", "(", "k", ",", "v", ")", "for", "(", "(", "k", ",", ")", ...
3572b2fb92039b4a1abe384be8545560fbd3d470
valid
BaseMultiLevelChunker.next_chunk_boundaries
Computes the next chunk boundaries within `buf`. See :meth:`.BaseChunker.next_chunk_boundaries`.
fastchunking/__init__.py
def next_chunk_boundaries(self, buf, prepend_bytes=0): """Computes the next chunk boundaries within `buf`. See :meth:`.BaseChunker.next_chunk_boundaries`. """ return (boundary for boundary, _ in self.next_chunk_boundaries_levels(buf, prepend_bytes))
def next_chunk_boundaries(self, buf, prepend_bytes=0): """Computes the next chunk boundaries within `buf`. See :meth:`.BaseChunker.next_chunk_boundaries`. """ return (boundary for boundary, _ in self.next_chunk_boundaries_levels(buf, prepend_bytes))
[ "Computes", "the", "next", "chunk", "boundaries", "within", "buf", "." ]
netleibi/fastchunking
python
https://github.com/netleibi/fastchunking/blob/069b7689d26bc067120907f01d9453ab3d2efa74/fastchunking/__init__.py#L73-L78
[ "def", "next_chunk_boundaries", "(", "self", ",", "buf", ",", "prepend_bytes", "=", "0", ")", ":", "return", "(", "boundary", "for", "boundary", ",", "_", "in", "self", ".", "next_chunk_boundaries_levels", "(", "buf", ",", "prepend_bytes", ")", ")" ]
069b7689d26bc067120907f01d9453ab3d2efa74
valid
DefaultMultiLevelChunker.next_chunk_boundaries_levels
Computes the next chunk boundaries within `buf`. Similar to :meth:`.next_chunk_boundaries`, but information about which chunker led to a respective boundary is included in the returned value. Args: buf (bytes): The message that is to be chunked. prepend_bytes (Optional[...
fastchunking/__init__.py
def next_chunk_boundaries_levels(self, buf, prepend_bytes=0): """Computes the next chunk boundaries within `buf`. Similar to :meth:`.next_chunk_boundaries`, but information about which chunker led to a respective boundary is included in the returned value. Args: buf (bytes)...
def next_chunk_boundaries_levels(self, buf, prepend_bytes=0): """Computes the next chunk boundaries within `buf`. Similar to :meth:`.next_chunk_boundaries`, but information about which chunker led to a respective boundary is included in the returned value. Args: buf (bytes)...
[ "Computes", "the", "next", "chunk", "boundaries", "within", "buf", "." ]
netleibi/fastchunking
python
https://github.com/netleibi/fastchunking/blob/069b7689d26bc067120907f01d9453ab3d2efa74/fastchunking/__init__.py#L115-L138
[ "def", "next_chunk_boundaries_levels", "(", "self", ",", "buf", ",", "prepend_bytes", "=", "0", ")", ":", "boundaries", "=", "{", "}", "for", "level_index", ",", "chunker", "in", "enumerate", "(", "self", ".", "_chunkers", ")", ":", "boundaries", ".", "upd...
069b7689d26bc067120907f01d9453ab3d2efa74
valid
RabinKarpCDC.create_chunker
Create a chunker performing content-defined chunking (CDC) using Rabin Karp's rolling hash scheme with a specific, expected chunk size. Args: chunk_size (int): (Expected) target chunk size. Returns: BaseChunker: A chunker object.
fastchunking/__init__.py
def create_chunker(self, chunk_size): """Create a chunker performing content-defined chunking (CDC) using Rabin Karp's rolling hash scheme with a specific, expected chunk size. Args: chunk_size (int): (Expected) target chunk size. Returns: BaseChunker: A chunker...
def create_chunker(self, chunk_size): """Create a chunker performing content-defined chunking (CDC) using Rabin Karp's rolling hash scheme with a specific, expected chunk size. Args: chunk_size (int): (Expected) target chunk size. Returns: BaseChunker: A chunker...
[ "Create", "a", "chunker", "performing", "content", "-", "defined", "chunking", "(", "CDC", ")", "using", "Rabin", "Karp", "s", "rolling", "hash", "scheme", "with", "a", "specific", "expected", "chunk", "size", "." ]
netleibi/fastchunking
python
https://github.com/netleibi/fastchunking/blob/069b7689d26bc067120907f01d9453ab3d2efa74/fastchunking/__init__.py#L200-L212
[ "def", "create_chunker", "(", "self", ",", "chunk_size", ")", ":", "rolling_hash", "=", "_rabinkarprh", ".", "RabinKarpHash", "(", "self", ".", "window_size", ",", "self", ".", "_seed", ")", "rolling_hash", ".", "set_threshold", "(", "1.0", "/", "chunk_size", ...
069b7689d26bc067120907f01d9453ab3d2efa74
valid
RabinKarpCDC.create_multilevel_chunker
Create a multi-level chunker performing content-defined chunking (CDC) using Rabin Karp's rolling hash scheme with different specific, expected chunk sizes. Args: chunk_sizes (list): List of (expected) target chunk sizes. Warning: For performance reasons...
fastchunking/__init__.py
def create_multilevel_chunker(self, chunk_sizes): """Create a multi-level chunker performing content-defined chunking (CDC) using Rabin Karp's rolling hash scheme with different specific, expected chunk sizes. Args: chunk_sizes (list): List of (expected) target chunk sizes. ...
def create_multilevel_chunker(self, chunk_sizes): """Create a multi-level chunker performing content-defined chunking (CDC) using Rabin Karp's rolling hash scheme with different specific, expected chunk sizes. Args: chunk_sizes (list): List of (expected) target chunk sizes. ...
[ "Create", "a", "multi", "-", "level", "chunker", "performing", "content", "-", "defined", "chunking", "(", "CDC", ")", "using", "Rabin", "Karp", "s", "rolling", "hash", "scheme", "with", "different", "specific", "expected", "chunk", "sizes", "." ]
netleibi/fastchunking
python
https://github.com/netleibi/fastchunking/blob/069b7689d26bc067120907f01d9453ab3d2efa74/fastchunking/__init__.py#L214-L230
[ "def", "create_multilevel_chunker", "(", "self", ",", "chunk_sizes", ")", ":", "rolling_hash", "=", "_rabinkarprh", ".", "RabinKarpMultiThresholdHash", "(", "self", ".", "window_size", ",", "self", ".", "_seed", ",", "[", "1.0", "/", "chunk_size", "for", "chunk_...
069b7689d26bc067120907f01d9453ab3d2efa74
valid
brightness
Assumes level is out of 100
milight/rgbw.py
def brightness(level=100, group=0): """ Assumes level is out of 100 """ if level not in range(0,101): raise Exception("Brightness must be value between 0 and 100") b = int(floor(level / 4.0) + 2) #lights want values 2-27 return (COMMANDS['ON'][group], Command(0x4E, b))
def brightness(level=100, group=0): """ Assumes level is out of 100 """ if level not in range(0,101): raise Exception("Brightness must be value between 0 and 100") b = int(floor(level / 4.0) + 2) #lights want values 2-27 return (COMMANDS['ON'][group], Command(0x4E, b))
[ "Assumes", "level", "is", "out", "of", "100" ]
McSwindler/python-milight
python
https://github.com/McSwindler/python-milight/blob/4891b1d7d6a720901a27a64f7b0d0c208f0c291f/milight/rgbw.py#L57-L62
[ "def", "brightness", "(", "level", "=", "100", ",", "group", "=", "0", ")", ":", "if", "level", "not", "in", "range", "(", "0", ",", "101", ")", ":", "raise", "Exception", "(", "\"Brightness must be value between 0 and 100\"", ")", "b", "=", "int", "(", ...
4891b1d7d6a720901a27a64f7b0d0c208f0c291f
valid
strip_minidom_whitespace
Strips all whitespace from a minidom XML node and its children This operation is made in-place.
structlog_pretty/utils.py
def strip_minidom_whitespace(node): """Strips all whitespace from a minidom XML node and its children This operation is made in-place.""" for child in node.childNodes: if child.nodeType == Node.TEXT_NODE: if child.nodeValue: child.nodeValue = child.nodeValue.strip() ...
def strip_minidom_whitespace(node): """Strips all whitespace from a minidom XML node and its children This operation is made in-place.""" for child in node.childNodes: if child.nodeType == Node.TEXT_NODE: if child.nodeValue: child.nodeValue = child.nodeValue.strip() ...
[ "Strips", "all", "whitespace", "from", "a", "minidom", "XML", "node", "and", "its", "children" ]
underyx/structlog-pretty
python
https://github.com/underyx/structlog-pretty/blob/e87e1ce582b94b21e1b65b1c326d4edf87f8bef3/structlog_pretty/utils.py#L4-L13
[ "def", "strip_minidom_whitespace", "(", "node", ")", ":", "for", "child", "in", "node", ".", "childNodes", ":", "if", "child", ".", "nodeType", "==", "Node", ".", "TEXT_NODE", ":", "if", "child", ".", "nodeValue", ":", "child", ".", "nodeValue", "=", "ch...
e87e1ce582b94b21e1b65b1c326d4edf87f8bef3
valid
brightness
Assumes level is out of 100
milight/rgb.py
def brightness(level=100, group=0): """ Assumes level is out of 100 """ if level not in range(0,101): raise Exception("Brightness must be value between 0 and 100") b = int(floor(level / 10.0)) #lights have 10 levels of brightness commands = list(darkest(group)) for i in range(0, b): ...
def brightness(level=100, group=0): """ Assumes level is out of 100 """ if level not in range(0,101): raise Exception("Brightness must be value between 0 and 100") b = int(floor(level / 10.0)) #lights have 10 levels of brightness commands = list(darkest(group)) for i in range(0, b): ...
[ "Assumes", "level", "is", "out", "of", "100" ]
McSwindler/python-milight
python
https://github.com/McSwindler/python-milight/blob/4891b1d7d6a720901a27a64f7b0d0c208f0c291f/milight/rgb.py#L63-L71
[ "def", "brightness", "(", "level", "=", "100", ",", "group", "=", "0", ")", ":", "if", "level", "not", "in", "range", "(", "0", ",", "101", ")", ":", "raise", "Exception", "(", "\"Brightness must be value between 0 and 100\"", ")", "b", "=", "int", "(", ...
4891b1d7d6a720901a27a64f7b0d0c208f0c291f
valid
warmness
Assumes level is out of 100
milight/white.py
def warmness(level=100, group=0): """ Assumes level is out of 100 """ if level not in range(0,101): raise Exception("Warmness must be value between 0 and 100") b = int(floor(level / 10.0)) #lights have 10 levels of warmness commands = list(coolest(group)) for i in range(0, b): comman...
def warmness(level=100, group=0): """ Assumes level is out of 100 """ if level not in range(0,101): raise Exception("Warmness must be value between 0 and 100") b = int(floor(level / 10.0)) #lights have 10 levels of warmness commands = list(coolest(group)) for i in range(0, b): comman...
[ "Assumes", "level", "is", "out", "of", "100" ]
McSwindler/python-milight
python
https://github.com/McSwindler/python-milight/blob/4891b1d7d6a720901a27a64f7b0d0c208f0c291f/milight/white.py#L87-L95
[ "def", "warmness", "(", "level", "=", "100", ",", "group", "=", "0", ")", ":", "if", "level", "not", "in", "range", "(", "0", ",", "101", ")", ":", "raise", "Exception", "(", "\"Warmness must be value between 0 and 100\"", ")", "b", "=", "int", "(", "f...
4891b1d7d6a720901a27a64f7b0d0c208f0c291f
valid
color_from_hls
Takes a hls color and converts to proper hue Bulbs use a BGR order instead of RGB
milight/__init__.py
def color_from_hls(hue, light, sat): """ Takes a hls color and converts to proper hue Bulbs use a BGR order instead of RGB """ if light > 0.95: #too bright, let's just switch to white return 256 elif light < 0.05: #too dark, let's shut it off return -1 else: hue = (-hue ...
def color_from_hls(hue, light, sat): """ Takes a hls color and converts to proper hue Bulbs use a BGR order instead of RGB """ if light > 0.95: #too bright, let's just switch to white return 256 elif light < 0.05: #too dark, let's shut it off return -1 else: hue = (-hue ...
[ "Takes", "a", "hls", "color", "and", "converts", "to", "proper", "hue", "Bulbs", "use", "a", "BGR", "order", "instead", "of", "RGB" ]
McSwindler/python-milight
python
https://github.com/McSwindler/python-milight/blob/4891b1d7d6a720901a27a64f7b0d0c208f0c291f/milight/__init__.py#L7-L16
[ "def", "color_from_hls", "(", "hue", ",", "light", ",", "sat", ")", ":", "if", "light", ">", "0.95", ":", "#too bright, let's just switch to white", "return", "256", "elif", "light", "<", "0.05", ":", "#too dark, let's shut it off", "return", "-", "1", "else", ...
4891b1d7d6a720901a27a64f7b0d0c208f0c291f
valid
color_from_rgb
Takes your standard rgb color and converts it to a proper hue value
milight/__init__.py
def color_from_rgb(red, green, blue): """ Takes your standard rgb color and converts it to a proper hue value """ r = min(red, 255) g = min(green, 255) b = min(blue, 255) if r > 1 or g > 1 or b > 1: r = r / 255.0 g = g / 255.0 b = b / 255.0 return color_fro...
def color_from_rgb(red, green, blue): """ Takes your standard rgb color and converts it to a proper hue value """ r = min(red, 255) g = min(green, 255) b = min(blue, 255) if r > 1 or g > 1 or b > 1: r = r / 255.0 g = g / 255.0 b = b / 255.0 return color_fro...
[ "Takes", "your", "standard", "rgb", "color", "and", "converts", "it", "to", "a", "proper", "hue", "value" ]
McSwindler/python-milight
python
https://github.com/McSwindler/python-milight/blob/4891b1d7d6a720901a27a64f7b0d0c208f0c291f/milight/__init__.py#L18-L30
[ "def", "color_from_rgb", "(", "red", ",", "green", ",", "blue", ")", ":", "r", "=", "min", "(", "red", ",", "255", ")", "g", "=", "min", "(", "green", ",", "255", ")", "b", "=", "min", "(", "blue", ",", "255", ")", "if", "r", ">", "1", "or"...
4891b1d7d6a720901a27a64f7b0d0c208f0c291f
valid
color_from_hex
Takes an HTML hex code and converts it to a proper hue value
milight/__init__.py
def color_from_hex(value): """ Takes an HTML hex code and converts it to a proper hue value """ if "#" in value: value = value[1:] try: unhexed = bytes.fromhex(value) except: unhexed = binascii.unhexlify(value) # Fallback for 2.7 compatibility return color_from_r...
def color_from_hex(value): """ Takes an HTML hex code and converts it to a proper hue value """ if "#" in value: value = value[1:] try: unhexed = bytes.fromhex(value) except: unhexed = binascii.unhexlify(value) # Fallback for 2.7 compatibility return color_from_r...
[ "Takes", "an", "HTML", "hex", "code", "and", "converts", "it", "to", "a", "proper", "hue", "value" ]
McSwindler/python-milight
python
https://github.com/McSwindler/python-milight/blob/4891b1d7d6a720901a27a64f7b0d0c208f0c291f/milight/__init__.py#L32-L42
[ "def", "color_from_hex", "(", "value", ")", ":", "if", "\"#\"", "in", "value", ":", "value", "=", "value", "[", "1", ":", "]", "try", ":", "unhexed", "=", "bytes", ".", "fromhex", "(", "value", ")", "except", ":", "unhexed", "=", "binascii", ".", "...
4891b1d7d6a720901a27a64f7b0d0c208f0c291f
valid
LightBulb.wait
Wait for x seconds each wait command is 100ms
milight/__init__.py
def wait(self, sec=0.1): """ Wait for x seconds each wait command is 100ms """ sec = max(sec, 0) reps = int(floor(sec / 0.1)) commands = [] for i in range(0, reps): commands.append(Command(0x00, wait=True)) return tuple(commands)
def wait(self, sec=0.1): """ Wait for x seconds each wait command is 100ms """ sec = max(sec, 0) reps = int(floor(sec / 0.1)) commands = [] for i in range(0, reps): commands.append(Command(0x00, wait=True)) return tuple(commands)
[ "Wait", "for", "x", "seconds", "each", "wait", "command", "is", "100ms" ]
McSwindler/python-milight
python
https://github.com/McSwindler/python-milight/blob/4891b1d7d6a720901a27a64f7b0d0c208f0c291f/milight/__init__.py#L181-L189
[ "def", "wait", "(", "self", ",", "sec", "=", "0.1", ")", ":", "sec", "=", "max", "(", "sec", ",", "0", ")", "reps", "=", "int", "(", "floor", "(", "sec", "/", "0.1", ")", ")", "commands", "=", "[", "]", "for", "i", "in", "range", "(", "0", ...
4891b1d7d6a720901a27a64f7b0d0c208f0c291f
valid
toc
ex1) tic() # save start time - time1 toc() # print elapsed time from last calling tic() toc() # print elapsed time from last calling tic() ex2) t0 = tic() # simple t1 = tic() toc(t1) # print time from t1 toc(t0) # print time from t0 :param t: time: 시작 시간 (tic()의 리턴 값) :pa...
snipy/tictoc.py
def toc(t=None, name='tictoc'): """ ex1) tic() # save start time - time1 toc() # print elapsed time from last calling tic() toc() # print elapsed time from last calling tic() ex2) t0 = tic() # simple t1 = tic() toc(t1) # print time from t1 toc(t0) # print time from t0 ...
def toc(t=None, name='tictoc'): """ ex1) tic() # save start time - time1 toc() # print elapsed time from last calling tic() toc() # print elapsed time from last calling tic() ex2) t0 = tic() # simple t1 = tic() toc(t1) # print time from t1 toc(t0) # print time from t0 ...
[ "ex1", ")", "tic", "()", "#", "save", "start", "time", "-", "time1", "toc", "()", "#", "print", "elapsed", "time", "from", "last", "calling", "tic", "()", "toc", "()", "#", "print", "elapsed", "time", "from", "last", "calling", "tic", "()" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/tictoc.py#L29-L53
[ "def", "toc", "(", "t", "=", "None", ",", "name", "=", "'tictoc'", ")", ":", "try", ":", "t", "=", "t", "or", "tic", ".", "last_tic_time", "except", "AttributeError", ":", "# tic()부터 콜하세요", "logg", ".", "warn", "(", "'calling tic() need to use toc()'", ")"...
408520867179f99b3158b57520e2619f3fecd69b
valid
tictoc
with tictoc('any string or not'): print 'cool~~~' cool~~~ 2015-12-30 14:39:28,458 [INFO] tictoc Elapsed: 7.10487365723e-05 secs :param name: str
snipy/tictoc.py
def tictoc(name='tictoc'): """ with tictoc('any string or not'): print 'cool~~~' cool~~~ 2015-12-30 14:39:28,458 [INFO] tictoc Elapsed: 7.10487365723e-05 secs :param name: str """ t = time.time() yield logg.info('%s Elapsed: %s secs' % (name, time.time() - t))
def tictoc(name='tictoc'): """ with tictoc('any string or not'): print 'cool~~~' cool~~~ 2015-12-30 14:39:28,458 [INFO] tictoc Elapsed: 7.10487365723e-05 secs :param name: str """ t = time.time() yield logg.info('%s Elapsed: %s secs' % (name, time.time() - t))
[ "with", "tictoc", "(", "any", "string", "or", "not", ")", ":", "print", "cool~~~", "cool~~~", "2015", "-", "12", "-", "30", "14", ":", "39", ":", "28", "458", "[", "INFO", "]", "tictoc", "Elapsed", ":", "7", ".", "10487365723e", "-", "05", "secs", ...
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/tictoc.py#L57-L67
[ "def", "tictoc", "(", "name", "=", "'tictoc'", ")", ":", "t", "=", "time", ".", "time", "(", ")", "yield", "logg", ".", "info", "(", "'%s Elapsed: %s secs'", "%", "(", "name", ",", "time", ".", "time", "(", ")", "-", "t", ")", ")" ]
408520867179f99b3158b57520e2619f3fecd69b
valid
split_rand
data(1-ratio), data(with ratio) = split_rand(data_or_size, ratio, seed) :param data_or_size: data or count :param ratio: :param seed: :return:
snipy/train/crossvalidation_set.py
def split_rand(data_or_size, ratio, seed): """ data(1-ratio), data(with ratio) = split_rand(data_or_size, ratio, seed) :param data_or_size: data or count :param ratio: :param seed: :return: """ if not isinstance(data_or_size, int): sz = len(data_or_size) data = np.asarray...
def split_rand(data_or_size, ratio, seed): """ data(1-ratio), data(with ratio) = split_rand(data_or_size, ratio, seed) :param data_or_size: data or count :param ratio: :param seed: :return: """ if not isinstance(data_or_size, int): sz = len(data_or_size) data = np.asarray...
[ "data", "(", "1", "-", "ratio", ")", "data", "(", "with", "ratio", ")", "=", "split_rand", "(", "data_or_size", "ratio", "seed", ")", ":", "param", "data_or_size", ":", "data", "or", "count", ":", "param", "ratio", ":", ":", "param", "seed", ":", ":"...
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/train/crossvalidation_set.py#L6-L30
[ "def", "split_rand", "(", "data_or_size", ",", "ratio", ",", "seed", ")", ":", "if", "not", "isinstance", "(", "data_or_size", ",", "int", ")", ":", "sz", "=", "len", "(", "data_or_size", ")", "data", "=", "np", ".", "asarray", "(", "data_or_size", ")"...
408520867179f99b3158b57520e2619f3fecd69b
valid
kfolds
return train, valid [,test] testset if p_testset :param n: :param k: :param sz: :param p_testset: :param seed: :return:
snipy/train/crossvalidation_set.py
def kfolds(n, k, sz, p_testset=None, seed=7238): """ return train, valid [,test] testset if p_testset :param n: :param k: :param sz: :param p_testset: :param seed: :return: """ trains, tests = split_rand(sz, p_testset, seed) ntrain = len(trains) # np.random.seed(se...
def kfolds(n, k, sz, p_testset=None, seed=7238): """ return train, valid [,test] testset if p_testset :param n: :param k: :param sz: :param p_testset: :param seed: :return: """ trains, tests = split_rand(sz, p_testset, seed) ntrain = len(trains) # np.random.seed(se...
[ "return", "train", "valid", "[", "test", "]", "testset", "if", "p_testset", ":", "param", "n", ":", ":", "param", "k", ":", ":", "param", "sz", ":", ":", "param", "p_testset", ":", ":", "param", "seed", ":", ":", "return", ":" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/train/crossvalidation_set.py#L45-L76
[ "def", "kfolds", "(", "n", ",", "k", ",", "sz", ",", "p_testset", "=", "None", ",", "seed", "=", "7238", ")", ":", "trains", ",", "tests", "=", "split_rand", "(", "sz", ",", "p_testset", ",", "seed", ")", "ntrain", "=", "len", "(", "trains", ")",...
408520867179f99b3158b57520e2619f3fecd69b
valid
date_proc
An decorator checking whether date parameter is passing in or not. If not, default date value is all PTT data. Else, return PTT data with right date. Args: func: function you want to decorate. request: WSGI request parameter getten from django. Returns: date: a datetime variable, you can only give year, y...
djangoApiDec/djangoApiDec.py
def date_proc(func): """ An decorator checking whether date parameter is passing in or not. If not, default date value is all PTT data. Else, return PTT data with right date. Args: func: function you want to decorate. request: WSGI request parameter getten from django. Returns: date: a datetime variable,...
def date_proc(func): """ An decorator checking whether date parameter is passing in or not. If not, default date value is all PTT data. Else, return PTT data with right date. Args: func: function you want to decorate. request: WSGI request parameter getten from django. Returns: date: a datetime variable,...
[ "An", "decorator", "checking", "whether", "date", "parameter", "is", "passing", "in", "or", "not", ".", "If", "not", "default", "date", "value", "is", "all", "PTT", "data", ".", "Else", "return", "PTT", "data", "with", "right", "date", ".", "Args", ":", ...
Stufinite/djangoApiDec
python
https://github.com/Stufinite/djangoApiDec/blob/8b2d5776b3413b1b850df12a92f30526c05c0a46/djangoApiDec/djangoApiDec.py#L8-L36
[ "def", "date_proc", "(", "func", ")", ":", "@", "wraps", "(", "func", ")", "def", "wrapped", "(", "request", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "'date'", "in", "request", ".", "GET", "and", "request", ".", "GET", "[", "'da...
8b2d5776b3413b1b850df12a92f30526c05c0a46
valid
queryString_required
An decorator checking whether queryString key is valid or not Args: str: allowed queryString key Returns: if contains invalid queryString key, it will raise exception.
djangoApiDec/djangoApiDec.py
def queryString_required(strList): """ An decorator checking whether queryString key is valid or not Args: str: allowed queryString key Returns: if contains invalid queryString key, it will raise exception. """ def _dec(function): @wraps(function) def _wrap(request, *args, **kwargs): for i in strList: ...
def queryString_required(strList): """ An decorator checking whether queryString key is valid or not Args: str: allowed queryString key Returns: if contains invalid queryString key, it will raise exception. """ def _dec(function): @wraps(function) def _wrap(request, *args, **kwargs): for i in strList: ...
[ "An", "decorator", "checking", "whether", "queryString", "key", "is", "valid", "or", "not", "Args", ":", "str", ":", "allowed", "queryString", "key" ]
Stufinite/djangoApiDec
python
https://github.com/Stufinite/djangoApiDec/blob/8b2d5776b3413b1b850df12a92f30526c05c0a46/djangoApiDec/djangoApiDec.py#L38-L54
[ "def", "queryString_required", "(", "strList", ")", ":", "def", "_dec", "(", "function", ")", ":", "@", "wraps", "(", "function", ")", "def", "_wrap", "(", "request", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "for", "i", "in", "strList", ...
8b2d5776b3413b1b850df12a92f30526c05c0a46
valid
queryString_required_ClassVersion
An decorator checking whether queryString key is valid or not Args: str: allowed queryString key Returns: if contains invalid queryString key, it will raise exception.
djangoApiDec/djangoApiDec.py
def queryString_required_ClassVersion(strList): """ An decorator checking whether queryString key is valid or not Args: str: allowed queryString key Returns: if contains invalid queryString key, it will raise exception. """ def _dec(function): @wraps(function) def _wrap(classInstance, request, *args, **kw...
def queryString_required_ClassVersion(strList): """ An decorator checking whether queryString key is valid or not Args: str: allowed queryString key Returns: if contains invalid queryString key, it will raise exception. """ def _dec(function): @wraps(function) def _wrap(classInstance, request, *args, **kw...
[ "An", "decorator", "checking", "whether", "queryString", "key", "is", "valid", "or", "not", "Args", ":", "str", ":", "allowed", "queryString", "key" ]
Stufinite/djangoApiDec
python
https://github.com/Stufinite/djangoApiDec/blob/8b2d5776b3413b1b850df12a92f30526c05c0a46/djangoApiDec/djangoApiDec.py#L56-L72
[ "def", "queryString_required_ClassVersion", "(", "strList", ")", ":", "def", "_dec", "(", "function", ")", ":", "@", "wraps", "(", "function", ")", "def", "_wrap", "(", "classInstance", ",", "request", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":",...
8b2d5776b3413b1b850df12a92f30526c05c0a46
valid
getJsonFromApi
Return json from querying Web Api Args: view: django view function. request: http request object got from django. Returns: json format dictionary
djangoApiDec/djangoApiDec.py
def getJsonFromApi(view, request): """Return json from querying Web Api Args: view: django view function. request: http request object got from django. Returns: json format dictionary """ jsonText = view(request) jsonText = json.loads(jsonText.content.decode('utf-8')) return jsonText
def getJsonFromApi(view, request): """Return json from querying Web Api Args: view: django view function. request: http request object got from django. Returns: json format dictionary """ jsonText = view(request) jsonText = json.loads(jsonText.content.decode('utf-8')) return jsonText
[ "Return", "json", "from", "querying", "Web", "Api" ]
Stufinite/djangoApiDec
python
https://github.com/Stufinite/djangoApiDec/blob/8b2d5776b3413b1b850df12a92f30526c05c0a46/djangoApiDec/djangoApiDec.py#L101-L112
[ "def", "getJsonFromApi", "(", "view", ",", "request", ")", ":", "jsonText", "=", "view", "(", "request", ")", "jsonText", "=", "json", ".", "loads", "(", "jsonText", ".", "content", ".", "decode", "(", "'utf-8'", ")", ")", "return", "jsonText" ]
8b2d5776b3413b1b850df12a92f30526c05c0a46
valid
progress
프로그래스 bar for i in progress(10): print i for i in progress(iter): print i
snipy/progress.py
def progress(iter, **kwargs): """ 프로그래스 bar for i in progress(10): print i for i in progress(iter): print i """ if isinstance(iter, int): iter = xrange(iter) if hasattr(iter, '__len__') or 'target' in kwargs: cls = Progress else: cls = ProgressBas...
def progress(iter, **kwargs): """ 프로그래스 bar for i in progress(10): print i for i in progress(iter): print i """ if isinstance(iter, int): iter = xrange(iter) if hasattr(iter, '__len__') or 'target' in kwargs: cls = Progress else: cls = ProgressBas...
[ "프로그래스", "bar", "for", "i", "in", "progress", "(", "10", ")", ":", "print", "i" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/progress.py#L180-L196
[ "def", "progress", "(", "iter", ",", "*", "*", "kwargs", ")", ":", "if", "isinstance", "(", "iter", ",", "int", ")", ":", "iter", "=", "xrange", "(", "iter", ")", "if", "hasattr", "(", "iter", ",", "'__len__'", ")", "or", "'target'", "in", "kwargs"...
408520867179f99b3158b57520e2619f3fecd69b
valid
threaded
function decorator
snipy/concurrent.py
def threaded(f, *args, **kwargs): """function decorator """ if args or kwargs: return Threaded(f, *args, **kwargs) @wraps(f) def wrapped(*wargs, **wkwargs): return Threaded(f, *wargs, **wkwargs) return wrapped
def threaded(f, *args, **kwargs): """function decorator """ if args or kwargs: return Threaded(f, *args, **kwargs) @wraps(f) def wrapped(*wargs, **wkwargs): return Threaded(f, *wargs, **wkwargs) return wrapped
[ "function", "decorator" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/concurrent.py#L84-L94
[ "def", "threaded", "(", "f", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "args", "or", "kwargs", ":", "return", "Threaded", "(", "f", ",", "*", "args", ",", "*", "*", "kwargs", ")", "@", "wraps", "(", "f", ")", "def", "wrapped", ...
408520867179f99b3158b57520e2619f3fecd69b
valid
spawn
decorator
snipy/concurrent.py
def spawn(f, *args, **kwargs): """decorator """ if args or kwargs: return Spawn(f, *args, **kwargs) @wraps(f) def wrapped(*args, **kwargs): return Spawn(f, *args, **kwargs) return wrapped
def spawn(f, *args, **kwargs): """decorator """ if args or kwargs: return Spawn(f, *args, **kwargs) @wraps(f) def wrapped(*args, **kwargs): return Spawn(f, *args, **kwargs) return wrapped
[ "decorator" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/concurrent.py#L97-L107
[ "def", "spawn", "(", "f", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "args", "or", "kwargs", ":", "return", "Spawn", "(", "f", ",", "*", "args", ",", "*", "*", "kwargs", ")", "@", "wraps", "(", "f", ")", "def", "wrapped", "(",...
408520867179f99b3158b57520e2619f3fecd69b
valid
ODict.intersect
self와 other 키가 동일한 아이템의 dictobj :type other: dict :rtype: dictobj:
snipy/odict.py
def intersect(self, other): """ self와 other 키가 동일한 아이템의 dictobj :type other: dict :rtype: dictobj: """ return ODict((k, self[k]) for k in self if k in other)
def intersect(self, other): """ self와 other 키가 동일한 아이템의 dictobj :type other: dict :rtype: dictobj: """ return ODict((k, self[k]) for k in self if k in other)
[ "self와", "other", "키가", "동일한", "아이템의", "dictobj", ":", "type", "other", ":", "dict", ":", "rtype", ":", "dictobj", ":" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/odict.py#L80-L86
[ "def", "intersect", "(", "self", ",", "other", ")", ":", "return", "ODict", "(", "(", "k", ",", "self", "[", "k", "]", ")", "for", "k", "in", "self", "if", "k", "in", "other", ")" ]
408520867179f99b3158b57520e2619f3fecd69b
valid
ODict.from_dict
recursive dict to dictobj 컨버트 :param dic: :return:
snipy/odict.py
def from_dict(dic): """ recursive dict to dictobj 컨버트 :param dic: :return: """ return ODict((k, ODict.convert_ifdic(v)) for k, v in dic.items())
def from_dict(dic): """ recursive dict to dictobj 컨버트 :param dic: :return: """ return ODict((k, ODict.convert_ifdic(v)) for k, v in dic.items())
[ "recursive", "dict", "to", "dictobj", "컨버트", ":", "param", "dic", ":", ":", "return", ":" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/odict.py#L89-L95
[ "def", "from_dict", "(", "dic", ")", ":", "return", "ODict", "(", "(", "k", ",", "ODict", ".", "convert_ifdic", "(", "v", ")", ")", "for", "k", ",", "v", "in", "dic", ".", "items", "(", ")", ")" ]
408520867179f99b3158b57520e2619f3fecd69b
valid
plots
simple wrapper plot with labels and skip x :param yonly_or_xy: :param kwargs: :return:
snipy/plt/ploting.py
def plots(data, **kwargs): """ simple wrapper plot with labels and skip x :param yonly_or_xy: :param kwargs: :return: """ labels = kwargs.pop('labels', '') loc = kwargs.pop('loc', 1) # if len(yonly_or_xy) == 1: # x = range(len(yonly_or_xy)) # y = yonly_or_xy # el...
def plots(data, **kwargs): """ simple wrapper plot with labels and skip x :param yonly_or_xy: :param kwargs: :return: """ labels = kwargs.pop('labels', '') loc = kwargs.pop('loc', 1) # if len(yonly_or_xy) == 1: # x = range(len(yonly_or_xy)) # y = yonly_or_xy # el...
[ "simple", "wrapper", "plot", "with", "labels", "and", "skip", "x", ":", "param", "yonly_or_xy", ":", ":", "param", "kwargs", ":", ":", "return", ":" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/plt/ploting.py#L17-L37
[ "def", "plots", "(", "data", ",", "*", "*", "kwargs", ")", ":", "labels", "=", "kwargs", ".", "pop", "(", "'labels'", ",", "''", ")", "loc", "=", "kwargs", ".", "pop", "(", "'loc'", ",", "1", ")", "# if len(yonly_or_xy) == 1:", "# x = range(len(yonly...
408520867179f99b3158b57520e2619f3fecd69b
valid
imshow_grid
:param images: nhwc :return:
snipy/plt/ploting.py
def imshow_grid(images, grid=None, showfun=None, **opt): """ :param images: nhwc :return: """ # assert images.ndim == 4 or list showfun = showfun or plt.imshow count = len(images) grid = grid or grid_recommend(count, sorted(images[0].shape[:2])) res = [] for i, img in enumerate...
def imshow_grid(images, grid=None, showfun=None, **opt): """ :param images: nhwc :return: """ # assert images.ndim == 4 or list showfun = showfun or plt.imshow count = len(images) grid = grid or grid_recommend(count, sorted(images[0].shape[:2])) res = [] for i, img in enumerate...
[ ":", "param", "images", ":", "nhwc", ":", "return", ":" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/plt/ploting.py#L48-L64
[ "def", "imshow_grid", "(", "images", ",", "grid", "=", "None", ",", "showfun", "=", "None", ",", "*", "*", "opt", ")", ":", "# assert images.ndim == 4 or list", "showfun", "=", "showfun", "or", "plt", ".", "imshow", "count", "=", "len", "(", "images", "...
408520867179f99b3158b57520e2619f3fecd69b
valid
plt_range
for i in plot_range(n): plt.imshow(imgs[i]) left arrow yield prev value other key yield next value :param args: :return:
snipy/plt/ploting.py
def plt_range(*args, **kwargs): """ for i in plot_range(n): plt.imshow(imgs[i]) left arrow yield prev value other key yield next value :param args: :return: """ wait = kwargs.pop('wait', True) if not wait: # no interactive just pass range for i in progress(ra...
def plt_range(*args, **kwargs): """ for i in plot_range(n): plt.imshow(imgs[i]) left arrow yield prev value other key yield next value :param args: :return: """ wait = kwargs.pop('wait', True) if not wait: # no interactive just pass range for i in progress(ra...
[ "for", "i", "in", "plot_range", "(", "n", ")", ":", "plt", ".", "imshow", "(", "imgs", "[", "i", "]", ")" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/plt/ploting.py#L69-L134
[ "def", "plt_range", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "wait", "=", "kwargs", ".", "pop", "(", "'wait'", ",", "True", ")", "if", "not", "wait", ":", "# no interactive just pass range", "for", "i", "in", "progress", "(", "range", "(", ...
408520867179f99b3158b57520e2619f3fecd69b
valid
plot_pause
todo : add some example :param timeout: wait time. if None, blocking :param msg: :return:
snipy/plt/ploting.py
def plot_pause(timeout=None, msg=''): """ todo : add some example :param timeout: wait time. if None, blocking :param msg: :return: """ if timeout is not None: print(msg or 'Press key for continue in time {}'.format(timeout)) plt.waitforbuttonpress(timeout=timeout) r...
def plot_pause(timeout=None, msg=''): """ todo : add some example :param timeout: wait time. if None, blocking :param msg: :return: """ if timeout is not None: print(msg or 'Press key for continue in time {}'.format(timeout)) plt.waitforbuttonpress(timeout=timeout) r...
[ "todo", ":", "add", "some", "example", ":", "param", "timeout", ":", "wait", "time", ".", "if", "None", "blocking", ":", "param", "msg", ":", ":", "return", ":" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/plt/ploting.py#L141-L158
[ "def", "plot_pause", "(", "timeout", "=", "None", ",", "msg", "=", "''", ")", ":", "if", "timeout", "is", "not", "None", ":", "print", "(", "msg", "or", "'Press key for continue in time {}'", ".", "format", "(", "timeout", ")", ")", "plt", ".", "waitforb...
408520867179f99b3158b57520e2619f3fecd69b
valid
flat_images
convert batch image to flat image with margin inserted [B,h,w,c] => [H,W,c] :param images: :param grid: patch grid cell size of (Row, Col) :param bfill: board filling value :param bsz: int or (int, int) board size :return: flatted image
snipy/plt/ploting.py
def flat_images(images, grid=None, bfill=1.0, bsz=(1, 1)): """ convert batch image to flat image with margin inserted [B,h,w,c] => [H,W,c] :param images: :param grid: patch grid cell size of (Row, Col) :param bfill: board filling value :param bsz: int or (int, int) board size :return: fl...
def flat_images(images, grid=None, bfill=1.0, bsz=(1, 1)): """ convert batch image to flat image with margin inserted [B,h,w,c] => [H,W,c] :param images: :param grid: patch grid cell size of (Row, Col) :param bfill: board filling value :param bsz: int or (int, int) board size :return: fl...
[ "convert", "batch", "image", "to", "flat", "image", "with", "margin", "inserted", "[", "B", "h", "w", "c", "]", "=", ">", "[", "H", "W", "c", "]", ":", "param", "images", ":", ":", "param", "grid", ":", "patch", "grid", "cell", "size", "of", "(",...
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/plt/ploting.py#L169-L214
[ "def", "flat_images", "(", "images", ",", "grid", "=", "None", ",", "bfill", "=", "1.0", ",", "bsz", "=", "(", "1", ",", "1", ")", ")", ":", "if", "images", ".", "ndim", "==", "4", "and", "images", ".", "shape", "[", "-", "1", "]", "==", "1",...
408520867179f99b3158b57520e2619f3fecd69b
valid
imshow_flat
imshow after applying flat_images :param images: [bhwc] :param grid: None for auto grid :param showfun: plt.imshow :param bfill: color for board fill :param bsz: size of board :param opt: option for showfun :return:
snipy/plt/ploting.py
def imshow_flat(images, grid=None, showfun=None, bfill=1.0, bsz=(1,1), **opt): """ imshow after applying flat_images :param images: [bhwc] :param grid: None for auto grid :param showfun: plt.imshow :param bfill: color for board fill :param bsz: size of board :param opt: option for showfu...
def imshow_flat(images, grid=None, showfun=None, bfill=1.0, bsz=(1,1), **opt): """ imshow after applying flat_images :param images: [bhwc] :param grid: None for auto grid :param showfun: plt.imshow :param bfill: color for board fill :param bsz: size of board :param opt: option for showfu...
[ "imshow", "after", "applying", "flat_images", ":", "param", "images", ":", "[", "bhwc", "]", ":", "param", "grid", ":", "None", "for", "auto", "grid", ":", "param", "showfun", ":", "plt", ".", "imshow", ":", "param", "bfill", ":", "color", "for", "boar...
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/plt/ploting.py#L217-L236
[ "def", "imshow_flat", "(", "images", ",", "grid", "=", "None", ",", "showfun", "=", "None", ",", "bfill", "=", "1.0", ",", "bsz", "=", "(", "1", ",", "1", ")", ",", "*", "*", "opt", ")", ":", "showfun", "=", "showfun", "or", "plt", ".", "imshow...
408520867179f99b3158b57520e2619f3fecd69b
valid
matshow
imshow without interpolation like as matshow :param args: :param kwargs: :return:
snipy/plt/ploting.py
def matshow(*args, **kwargs): """ imshow without interpolation like as matshow :param args: :param kwargs: :return: """ kwargs['interpolation'] = kwargs.pop('interpolation', 'none') return plt.imshow(*args, **kwargs)
def matshow(*args, **kwargs): """ imshow without interpolation like as matshow :param args: :param kwargs: :return: """ kwargs['interpolation'] = kwargs.pop('interpolation', 'none') return plt.imshow(*args, **kwargs)
[ "imshow", "without", "interpolation", "like", "as", "matshow", ":", "param", "args", ":", ":", "param", "kwargs", ":", ":", "return", ":" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/plt/ploting.py#L279-L287
[ "def", "matshow", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "kwargs", "[", "'interpolation'", "]", "=", "kwargs", ".", "pop", "(", "'interpolation'", ",", "'none'", ")", "return", "plt", ".", "imshow", "(", "*", "args", ",", "*", "*", "k...
408520867179f99b3158b57520e2619f3fecd69b
valid
imbox
draw boundary box :param xy: start index xy (ji) :param w: width :param h: height :param angle: :param kwargs: :return:
snipy/plt/ploting.py
def imbox(xy, w, h, angle=0.0, **kwargs): """ draw boundary box :param xy: start index xy (ji) :param w: width :param h: height :param angle: :param kwargs: :return: """ from matplotlib.patches import Rectangle return imbound(Rectangle, xy, w, h, angle, **kwargs)
def imbox(xy, w, h, angle=0.0, **kwargs): """ draw boundary box :param xy: start index xy (ji) :param w: width :param h: height :param angle: :param kwargs: :return: """ from matplotlib.patches import Rectangle return imbound(Rectangle, xy, w, h, angle, **kwargs)
[ "draw", "boundary", "box", ":", "param", "xy", ":", "start", "index", "xy", "(", "ji", ")", ":", "param", "w", ":", "width", ":", "param", "h", ":", "height", ":", "param", "angle", ":", ":", "param", "kwargs", ":", ":", "return", ":" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/plt/ploting.py#L413-L424
[ "def", "imbox", "(", "xy", ",", "w", ",", "h", ",", "angle", "=", "0.0", ",", "*", "*", "kwargs", ")", ":", "from", "matplotlib", ".", "patches", "import", "Rectangle", "return", "imbound", "(", "Rectangle", ",", "xy", ",", "w", ",", "h", ",", "a...
408520867179f99b3158b57520e2619f3fecd69b
valid
imbound
:param clspatch: :param args: :param kwargs: :return:
snipy/plt/ploting.py
def imbound(clspatch, *args, **kwargs): """ :param clspatch: :param args: :param kwargs: :return: """ # todo : add example c = kwargs.pop('color', kwargs.get('edgecolor', None)) kwargs.update(facecolor='none', edgecolor=c) return impatch(clspatch, *args, **kwargs)
def imbound(clspatch, *args, **kwargs): """ :param clspatch: :param args: :param kwargs: :return: """ # todo : add example c = kwargs.pop('color', kwargs.get('edgecolor', None)) kwargs.update(facecolor='none', edgecolor=c) return impatch(clspatch, *args, **kwargs)
[ ":", "param", "clspatch", ":", ":", "param", "args", ":", ":", "param", "kwargs", ":", ":", "return", ":" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/plt/ploting.py#L433-L444
[ "def", "imbound", "(", "clspatch", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "# todo : add example", "c", "=", "kwargs", ".", "pop", "(", "'color'", ",", "kwargs", ".", "get", "(", "'edgecolor'", ",", "None", ")", ")", "kwargs", ".", "upda...
408520867179f99b3158b57520e2619f3fecd69b
valid
imslic
slic args : n_segments=100, compactness=10., max_iter=10, sigma=0, spacing=None, multichannel=True, convert2lab=None, enforce_connectivity=True, min_size_factor=0.5, max_size_factor=3, slic_zero=False mark_boundaries args: label_img, color=(1, 1, 0), outline_color=None, mode='outer', background...
snipy/plt/ploting.py
def imslic(img, n_segments=100, aspect=None): """ slic args : n_segments=100, compactness=10., max_iter=10, sigma=0, spacing=None, multichannel=True, convert2lab=None, enforce_connectivity=True, min_size_factor=0.5, max_size_factor=3, slic_zero=False mark_boundaries args: label_img, col...
def imslic(img, n_segments=100, aspect=None): """ slic args : n_segments=100, compactness=10., max_iter=10, sigma=0, spacing=None, multichannel=True, convert2lab=None, enforce_connectivity=True, min_size_factor=0.5, max_size_factor=3, slic_zero=False mark_boundaries args: label_img, col...
[ "slic", "args", ":", "n_segments", "=", "100", "compactness", "=", "10", ".", "max_iter", "=", "10", "sigma", "=", "0", "spacing", "=", "None", "multichannel", "=", "True", "convert2lab", "=", "None", "enforce_connectivity", "=", "True", "min_size_factor", "...
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/plt/ploting.py#L476-L509
[ "def", "imslic", "(", "img", ",", "n_segments", "=", "100", ",", "aspect", "=", "None", ")", ":", "from", "skimage", ".", "segmentation", "import", "(", "slic", ",", "mark_boundaries", ")", "from", "skimage", ".", "morphology", "import", "(", "dilation", ...
408520867179f99b3158b57520e2619f3fecd69b
valid
imslic2
slic args : n_segments=100, compactness=10., max_iter=10, sigma=0, spacing=None, multichannel=True, convert2lab=None, enforce_connectivity=True, min_size_factor=0.5, max_size_factor=3, slic_zero=False mark_boundaries args: label_img, color=(1, 1, 0), outline_color=None, mode='outer', background...
snipy/plt/ploting.py
def imslic2(img, n_segments=100, color=None, outline_color=None, mode='thick', **kwargs): """ slic args : n_segments=100, compactness=10., max_iter=10, sigma=0, spacing=None, multichannel=True, convert2lab=None, enforce_connectivity=True, min_size_factor=0.5, max_size_factor=3, slic_zero=False ...
def imslic2(img, n_segments=100, color=None, outline_color=None, mode='thick', **kwargs): """ slic args : n_segments=100, compactness=10., max_iter=10, sigma=0, spacing=None, multichannel=True, convert2lab=None, enforce_connectivity=True, min_size_factor=0.5, max_size_factor=3, slic_zero=False ...
[ "slic", "args", ":", "n_segments", "=", "100", "compactness", "=", "10", ".", "max_iter", "=", "10", "sigma", "=", "0", "spacing", "=", "None", "multichannel", "=", "True", "convert2lab", "=", "None", "enforce_connectivity", "=", "True", "min_size_factor", "...
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/plt/ploting.py#L512-L559
[ "def", "imslic2", "(", "img", ",", "n_segments", "=", "100", ",", "color", "=", "None", ",", "outline_color", "=", "None", ",", "mode", "=", "'thick'", ",", "*", "*", "kwargs", ")", ":", "from", "skimage", ".", "segmentation", "import", "(", "slic", ...
408520867179f99b3158b57520e2619f3fecd69b
valid
movie_saving
contextmanager for PlotMovieWriter Example: with movie_saving('output.mp4', dpi=100) as plot: for i in range(10): plot(data[i]) :param outfile: :param showfun: :param fig: :param tight: :param drawopt: :param dpi: :param movieopt: fps=5, codec=None, ...
snipy/plt/ploting.py
def movie_saving(outfile, showfun=imshow, fig=None, tight=True, drawopt=None, dpi=100, **movieopt): """ contextmanager for PlotMovieWriter Example: with movie_saving('output.mp4', dpi=100) as plot: for i in range(10): plot(data[i]) :param outfile: :param showfun...
def movie_saving(outfile, showfun=imshow, fig=None, tight=True, drawopt=None, dpi=100, **movieopt): """ contextmanager for PlotMovieWriter Example: with movie_saving('output.mp4', dpi=100) as plot: for i in range(10): plot(data[i]) :param outfile: :param showfun...
[ "contextmanager", "for", "PlotMovieWriter", "Example", ":" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/plt/ploting.py#L700-L726
[ "def", "movie_saving", "(", "outfile", ",", "showfun", "=", "imshow", ",", "fig", "=", "None", ",", "tight", "=", "True", ",", "drawopt", "=", "None", ",", "dpi", "=", "100", ",", "*", "*", "movieopt", ")", ":", "if", "tight", ":", "plot_writer", "...
408520867179f99b3158b57520e2619f3fecd69b
valid
put
put text on on screen a tuple as first argument tells absolute position for the text does not change TermCursor position args = list of optional position, formatting tokens and strings
snipy/term.py
def put(xy, *args): """ put text on on screen a tuple as first argument tells absolute position for the text does not change TermCursor position args = list of optional position, formatting tokens and strings """ cmd = [TermCursor.save, TermCursor.move(*xy), ''.join(args), TermCursor.restore...
def put(xy, *args): """ put text on on screen a tuple as first argument tells absolute position for the text does not change TermCursor position args = list of optional position, formatting tokens and strings """ cmd = [TermCursor.save, TermCursor.move(*xy), ''.join(args), TermCursor.restore...
[ "put", "text", "on", "on", "screen", "a", "tuple", "as", "first", "argument", "tells", "absolute", "position", "for", "the", "text", "does", "not", "change", "TermCursor", "position", "args", "=", "list", "of", "optional", "position", "formatting", "tokens", ...
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/term.py#L135-L143
[ "def", "put", "(", "xy", ",", "*", "args", ")", ":", "cmd", "=", "[", "TermCursor", ".", "save", ",", "TermCursor", ".", "move", "(", "*", "xy", ")", ",", "''", ".", "join", "(", "args", ")", ",", "TermCursor", ".", "restore", "]", "write", "("...
408520867179f99b3158b57520e2619f3fecd69b
valid
getpassword
get user input without echo
snipy/term.py
def getpassword(prompt="Password: "): """ get user input without echo """ fd = sys.stdin.fileno() old = termios.tcgetattr(fd) new = termios.tcgetattr(fd) new[3] &= ~termios.ECHO # lflags try: termios.tcsetattr(fd, termios.TCSADRAIN, new) passwd = raw_input(promp...
def getpassword(prompt="Password: "): """ get user input without echo """ fd = sys.stdin.fileno() old = termios.tcgetattr(fd) new = termios.tcgetattr(fd) new[3] &= ~termios.ECHO # lflags try: termios.tcsetattr(fd, termios.TCSADRAIN, new) passwd = raw_input(promp...
[ "get", "user", "input", "without", "echo" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/term.py#L146-L160
[ "def", "getpassword", "(", "prompt", "=", "\"Password: \"", ")", ":", "fd", "=", "sys", ".", "stdin", ".", "fileno", "(", ")", "old", "=", "termios", ".", "tcgetattr", "(", "fd", ")", "new", "=", "termios", ".", "tcgetattr", "(", "fd", ")", "new", ...
408520867179f99b3158b57520e2619f3fecd69b
valid
getch
get character. waiting for key
snipy/term.py
def getch(): """ get character. waiting for key """ try: termios.tcsetattr(_fd, termios.TCSANOW, _new_settings) ch = sys.stdin.read(1) finally: termios.tcsetattr(_fd, termios.TCSADRAIN, _old_settings) return ch
def getch(): """ get character. waiting for key """ try: termios.tcsetattr(_fd, termios.TCSANOW, _new_settings) ch = sys.stdin.read(1) finally: termios.tcsetattr(_fd, termios.TCSADRAIN, _old_settings) return ch
[ "get", "character", ".", "waiting", "for", "key" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/term.py#L163-L172
[ "def", "getch", "(", ")", ":", "try", ":", "termios", ".", "tcsetattr", "(", "_fd", ",", "termios", ".", "TCSANOW", ",", "_new_settings", ")", "ch", "=", "sys", ".", "stdin", ".", "read", "(", "1", ")", "finally", ":", "termios", ".", "tcsetattr", ...
408520867179f99b3158b57520e2619f3fecd69b
valid
getlogger
패키지 혹은 채널 로거 logging.getLogger(package_name) or logg.getLogger() :param pkg: str
snipy/ilogging.py
def getlogger(pkg='', handler=None): """ 패키지 혹은 채널 로거 logging.getLogger(package_name) or logg.getLogger() :param pkg: str """ from .caller import caller if not pkg: m = caller.modulename() s = m.split('.', 1) if len(s) > 1: pkg = s[0] if haslogger(pk...
def getlogger(pkg='', handler=None): """ 패키지 혹은 채널 로거 logging.getLogger(package_name) or logg.getLogger() :param pkg: str """ from .caller import caller if not pkg: m = caller.modulename() s = m.split('.', 1) if len(s) > 1: pkg = s[0] if haslogger(pk...
[ "패키지", "혹은", "채널", "로거", "logging", ".", "getLogger", "(", "package_name", ")", "or", "logg", ".", "getLogger", "()", ":", "param", "pkg", ":", "str" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/ilogging.py#L90-L111
[ "def", "getlogger", "(", "pkg", "=", "''", ",", "handler", "=", "None", ")", ":", "from", ".", "caller", "import", "caller", "if", "not", "pkg", ":", "m", "=", "caller", ".", "modulename", "(", ")", "s", "=", "m", ".", "split", "(", "'.'", ",", ...
408520867179f99b3158b57520e2619f3fecd69b
valid
basicConfig
logging의 로그를 한번 호출하면 basicConfig가 안먹으므로. 기존 핸들러 삭제후 재설정. http://stackoverflow.com/questions/1943747/python-logging-before-you-run-logging-basicconfig ex) basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG) :param filename: Specifies that a FileHandler be created, using the specified filen...
snipy/ilogging.py
def basicConfig(**kw): """logging의 로그를 한번 호출하면 basicConfig가 안먹으므로. 기존 핸들러 삭제후 재설정. http://stackoverflow.com/questions/1943747/python-logging-before-you-run-logging-basicconfig ex) basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG) :param filename: Specifies that a FileHandler be crea...
def basicConfig(**kw): """logging의 로그를 한번 호출하면 basicConfig가 안먹으므로. 기존 핸들러 삭제후 재설정. http://stackoverflow.com/questions/1943747/python-logging-before-you-run-logging-basicconfig ex) basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG) :param filename: Specifies that a FileHandler be crea...
[ "logging의", "로그를", "한번", "호출하면", "basicConfig가", "안먹으므로", ".", "기존", "핸들러", "삭제후", "재설정", ".", "http", ":", "//", "stackoverflow", ".", "com", "/", "questions", "/", "1943747", "/", "python", "-", "logging", "-", "before", "-", "you", "-", "run", "-", ...
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/ilogging.py#L176-L192
[ "def", "basicConfig", "(", "*", "*", "kw", ")", ":", "while", "len", "(", "logging", ".", "root", ".", "handlers", ")", ">", "0", ":", "logging", ".", "root", ".", "removeHandler", "(", "logging", ".", "root", ".", "handlers", "[", "-", "1", "]", ...
408520867179f99b3158b57520e2619f3fecd69b
valid
FormatterX.format
tweaked from source of base
snipy/ilogging.py
def format(self, record): """tweaked from source of base""" try: record.message = record.getMessage() except TypeError: # if error during msg = msg % self.args if record.args: if isinstance(record.args, collections.Mapping): ...
def format(self, record): """tweaked from source of base""" try: record.message = record.getMessage() except TypeError: # if error during msg = msg % self.args if record.args: if isinstance(record.args, collections.Mapping): ...
[ "tweaked", "from", "source", "of", "base" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/ilogging.py#L32-L61
[ "def", "format", "(", "self", ",", "record", ")", ":", "try", ":", "record", ".", "message", "=", "record", ".", "getMessage", "(", ")", "except", "TypeError", ":", "# if error during msg = msg % self.args", "if", "record", ".", "args", ":", "if", "isinstanc...
408520867179f99b3158b57520e2619f3fecd69b
valid
getProcessOwner
getProcessOwner - Get the process owner of a pid @param pid <int> - process id @return - None if process not found or can't be determined. Otherwise, a dict: { uid - Owner UID name - Owner name, or None if one cannot be determined }
ProcessMappingScanner/__init__.py
def getProcessOwner(pid): ''' getProcessOwner - Get the process owner of a pid @param pid <int> - process id @return - None if process not found or can't be determined. Otherwise, a dict: { uid - Owner UID name - Owner name, or None if one cann...
def getProcessOwner(pid): ''' getProcessOwner - Get the process owner of a pid @param pid <int> - process id @return - None if process not found or can't be determined. Otherwise, a dict: { uid - Owner UID name - Owner name, or None if one cann...
[ "getProcessOwner", "-", "Get", "the", "process", "owner", "of", "a", "pid" ]
kata198/ProcessMappingScanner
python
https://github.com/kata198/ProcessMappingScanner/blob/d1735fe6746493c51aaae213b982fa96f5c5b621/ProcessMappingScanner/__init__.py#L25-L50
[ "def", "getProcessOwner", "(", "pid", ")", ":", "try", ":", "ownerUid", "=", "os", ".", "stat", "(", "'/proc/'", "+", "str", "(", "pid", ")", ")", ".", "st_uid", "except", ":", "return", "None", "try", ":", "ownerName", "=", "pwd", ".", "getpwuid", ...
d1735fe6746493c51aaae213b982fa96f5c5b621
valid
getProcessOwnerStr
getProcessOwner - Get Process owner of a pid as a string instead of components (#getProcessOwner) @return - Returns username if it can be determined, otherwise uid, otherwise "unknown"
ProcessMappingScanner/__init__.py
def getProcessOwnerStr(pid): ''' getProcessOwner - Get Process owner of a pid as a string instead of components (#getProcessOwner) @return - Returns username if it can be determined, otherwise uid, otherwise "unknown" ''' ownerInfo = getProcessOwner(pid) if ownerInfo: if ownerIn...
def getProcessOwnerStr(pid): ''' getProcessOwner - Get Process owner of a pid as a string instead of components (#getProcessOwner) @return - Returns username if it can be determined, otherwise uid, otherwise "unknown" ''' ownerInfo = getProcessOwner(pid) if ownerInfo: if ownerIn...
[ "getProcessOwner", "-", "Get", "Process", "owner", "of", "a", "pid", "as", "a", "string", "instead", "of", "components", "(", "#getProcessOwner", ")" ]
kata198/ProcessMappingScanner
python
https://github.com/kata198/ProcessMappingScanner/blob/d1735fe6746493c51aaae213b982fa96f5c5b621/ProcessMappingScanner/__init__.py#L52-L67
[ "def", "getProcessOwnerStr", "(", "pid", ")", ":", "ownerInfo", "=", "getProcessOwner", "(", "pid", ")", "if", "ownerInfo", ":", "if", "ownerInfo", "[", "'name'", "]", ":", "owner", "=", "ownerInfo", "[", "'name'", "]", "else", ":", "owner", "=", "str", ...
d1735fe6746493c51aaae213b982fa96f5c5b621
valid
getProcessCommandLineStr
getProcessCommandLineStr - Gets a the commandline (program + arguments) of a given pid @param pid <int> - Process ID @return - None if process not found or can't be determined. Otherwise a string of commandline. @note Caution, args may have spaces in them, and you cannot surmise from this met...
ProcessMappingScanner/__init__.py
def getProcessCommandLineStr(pid): ''' getProcessCommandLineStr - Gets a the commandline (program + arguments) of a given pid @param pid <int> - Process ID @return - None if process not found or can't be determined. Otherwise a string of commandline. @note Caution, args may have s...
def getProcessCommandLineStr(pid): ''' getProcessCommandLineStr - Gets a the commandline (program + arguments) of a given pid @param pid <int> - Process ID @return - None if process not found or can't be determined. Otherwise a string of commandline. @note Caution, args may have s...
[ "getProcessCommandLineStr", "-", "Gets", "a", "the", "commandline", "(", "program", "+", "arguments", ")", "of", "a", "given", "pid" ]
kata198/ProcessMappingScanner
python
https://github.com/kata198/ProcessMappingScanner/blob/d1735fe6746493c51aaae213b982fa96f5c5b621/ProcessMappingScanner/__init__.py#L69-L84
[ "def", "getProcessCommandLineStr", "(", "pid", ")", ":", "try", ":", "with", "open", "(", "'/proc/%d/cmdline'", "%", "(", "int", "(", "pid", ")", ",", ")", ",", "'r'", ")", "as", "f", ":", "cmdline", "=", "f", ".", "read", "(", ")", "return", "cmdl...
d1735fe6746493c51aaae213b982fa96f5c5b621
valid
getProcessCommandLineList
getProcessCommandLineList - Gets the commandline (program + argumentS) of a given pid as a list. @param pid <int> - Process ID @return - None if process not found or can't be determined. Otherwise a list representing argv. First argument is process name, remainder are arguments. @note - Use t...
ProcessMappingScanner/__init__.py
def getProcessCommandLineList(pid): ''' getProcessCommandLineList - Gets the commandline (program + argumentS) of a given pid as a list. @param pid <int> - Process ID @return - None if process not found or can't be determined. Otherwise a list representing argv. First argument is process n...
def getProcessCommandLineList(pid): ''' getProcessCommandLineList - Gets the commandline (program + argumentS) of a given pid as a list. @param pid <int> - Process ID @return - None if process not found or can't be determined. Otherwise a list representing argv. First argument is process n...
[ "getProcessCommandLineList", "-", "Gets", "the", "commandline", "(", "program", "+", "argumentS", ")", "of", "a", "given", "pid", "as", "a", "list", "." ]
kata198/ProcessMappingScanner
python
https://github.com/kata198/ProcessMappingScanner/blob/d1735fe6746493c51aaae213b982fa96f5c5b621/ProcessMappingScanner/__init__.py#L87-L103
[ "def", "getProcessCommandLineList", "(", "pid", ")", ":", "try", ":", "with", "open", "(", "'/proc/%d/cmdline'", "%", "(", "int", "(", "pid", ")", ",", ")", ",", "'r'", ")", "as", "f", ":", "cmdline", "=", "f", ".", "read", "(", ")", "return", "cmd...
d1735fe6746493c51aaae213b982fa96f5c5b621
valid
scanProcessForCwd
scanProcessForCwd - Searches a given pid's cwd for a given pattern @param pid <int> - A running process ID on this system @param searchPortion <str> - Any portion of directory to search @param isExactMatch <bool> Default False - If match should be exact, otherwise a partial match is...
ProcessMappingScanner/__init__.py
def scanProcessForCwd(pid, searchPortion, isExactMatch=False): ''' scanProcessForCwd - Searches a given pid's cwd for a given pattern @param pid <int> - A running process ID on this system @param searchPortion <str> - Any portion of directory to search @param isExactMatc...
def scanProcessForCwd(pid, searchPortion, isExactMatch=False): ''' scanProcessForCwd - Searches a given pid's cwd for a given pattern @param pid <int> - A running process ID on this system @param searchPortion <str> - Any portion of directory to search @param isExactMatc...
[ "scanProcessForCwd", "-", "Searches", "a", "given", "pid", "s", "cwd", "for", "a", "given", "pattern" ]
kata198/ProcessMappingScanner
python
https://github.com/kata198/ProcessMappingScanner/blob/d1735fe6746493c51aaae213b982fa96f5c5b621/ProcessMappingScanner/__init__.py#L131-L194
[ "def", "scanProcessForCwd", "(", "pid", ",", "searchPortion", ",", "isExactMatch", "=", "False", ")", ":", "try", ":", "try", ":", "pid", "=", "int", "(", "pid", ")", "except", "ValueError", "as", "e", ":", "sys", ".", "stderr", ".", "write", "(", "'...
d1735fe6746493c51aaae213b982fa96f5c5b621
valid
scanAllProcessesForCwd
scanAllProcessesForCwd - Scans all processes on the system for a given search pattern. @param searchPortion <str> - Any portion of directory to search @param isExactMatch <bool> Default False - If match should be exact, otherwise a partial match is performed. @return - <dict> - A dicti...
ProcessMappingScanner/__init__.py
def scanAllProcessesForCwd(searchPortion, isExactMatch=False): ''' scanAllProcessesForCwd - Scans all processes on the system for a given search pattern. @param searchPortion <str> - Any portion of directory to search @param isExactMatch <bool> Default False - If match should be exa...
def scanAllProcessesForCwd(searchPortion, isExactMatch=False): ''' scanAllProcessesForCwd - Scans all processes on the system for a given search pattern. @param searchPortion <str> - Any portion of directory to search @param isExactMatch <bool> Default False - If match should be exa...
[ "scanAllProcessesForCwd", "-", "Scans", "all", "processes", "on", "the", "system", "for", "a", "given", "search", "pattern", "." ]
kata198/ProcessMappingScanner
python
https://github.com/kata198/ProcessMappingScanner/blob/d1735fe6746493c51aaae213b982fa96f5c5b621/ProcessMappingScanner/__init__.py#L196-L214
[ "def", "scanAllProcessesForCwd", "(", "searchPortion", ",", "isExactMatch", "=", "False", ")", ":", "pids", "=", "getAllRunningPids", "(", ")", "cwdResults", "=", "[", "scanProcessForCwd", "(", "pid", ",", "searchPortion", ",", "isExactMatch", ")", "for", "pid",...
d1735fe6746493c51aaae213b982fa96f5c5b621
valid
scanProcessForMapping
scanProcessForMapping - Searches a given pid's mappings for a certain pattern. @param pid <int> - A running process ID on this system @param searchPortion <str> - A mapping for which to search, example: libc or python or libz.so.1. Give empty string to return all mappings. @param is...
ProcessMappingScanner/__init__.py
def scanProcessForMapping(pid, searchPortion, isExactMatch=False, ignoreCase=False): ''' scanProcessForMapping - Searches a given pid's mappings for a certain pattern. @param pid <int> - A running process ID on this system @param searchPortion <str> - A mapping for which to search, ...
def scanProcessForMapping(pid, searchPortion, isExactMatch=False, ignoreCase=False): ''' scanProcessForMapping - Searches a given pid's mappings for a certain pattern. @param pid <int> - A running process ID on this system @param searchPortion <str> - A mapping for which to search, ...
[ "scanProcessForMapping", "-", "Searches", "a", "given", "pid", "s", "mappings", "for", "a", "certain", "pattern", "." ]
kata198/ProcessMappingScanner
python
https://github.com/kata198/ProcessMappingScanner/blob/d1735fe6746493c51aaae213b982fa96f5c5b621/ProcessMappingScanner/__init__.py#L216-L287
[ "def", "scanProcessForMapping", "(", "pid", ",", "searchPortion", ",", "isExactMatch", "=", "False", ",", "ignoreCase", "=", "False", ")", ":", "try", ":", "try", ":", "pid", "=", "int", "(", "pid", ")", "except", "ValueError", "as", "e", ":", "sys", "...
d1735fe6746493c51aaae213b982fa96f5c5b621
valid
scanAllProcessesForMapping
scanAllProcessesForMapping - Scans all processes on the system for a given search pattern. @param searchPortion <str> - A mapping for which to search, example: libc or python or libz.so.1. Give empty string to return all mappings. @param isExactMatch <bool> Default False - If match should be ex...
ProcessMappingScanner/__init__.py
def scanAllProcessesForMapping(searchPortion, isExactMatch=False, ignoreCase=False): ''' scanAllProcessesForMapping - Scans all processes on the system for a given search pattern. @param searchPortion <str> - A mapping for which to search, example: libc or python or libz.so.1. Give empty string...
def scanAllProcessesForMapping(searchPortion, isExactMatch=False, ignoreCase=False): ''' scanAllProcessesForMapping - Scans all processes on the system for a given search pattern. @param searchPortion <str> - A mapping for which to search, example: libc or python or libz.so.1. Give empty string...
[ "scanAllProcessesForMapping", "-", "Scans", "all", "processes", "on", "the", "system", "for", "a", "given", "search", "pattern", "." ]
kata198/ProcessMappingScanner
python
https://github.com/kata198/ProcessMappingScanner/blob/d1735fe6746493c51aaae213b982fa96f5c5b621/ProcessMappingScanner/__init__.py#L290-L309
[ "def", "scanAllProcessesForMapping", "(", "searchPortion", ",", "isExactMatch", "=", "False", ",", "ignoreCase", "=", "False", ")", ":", "pids", "=", "getAllRunningPids", "(", ")", "# Since processes could disappear, we run the scan as fast as possible here with a list comprehe...
d1735fe6746493c51aaae213b982fa96f5c5b621
valid
scanProcessForOpenFile
scanProcessForOpenFile - Scans open FDs for a given pid to see if any are the provided searchPortion @param searchPortion <str> - Filename to check @param isExactMatch <bool> Default True - If match should be exact, otherwise a partial match is performed. @param ignoreCase <bool> De...
ProcessMappingScanner/__init__.py
def scanProcessForOpenFile(pid, searchPortion, isExactMatch=True, ignoreCase=False): ''' scanProcessForOpenFile - Scans open FDs for a given pid to see if any are the provided searchPortion @param searchPortion <str> - Filename to check @param isExactMatch <bool> Default True - If m...
def scanProcessForOpenFile(pid, searchPortion, isExactMatch=True, ignoreCase=False): ''' scanProcessForOpenFile - Scans open FDs for a given pid to see if any are the provided searchPortion @param searchPortion <str> - Filename to check @param isExactMatch <bool> Default True - If m...
[ "scanProcessForOpenFile", "-", "Scans", "open", "FDs", "for", "a", "given", "pid", "to", "see", "if", "any", "are", "the", "provided", "searchPortion" ]
kata198/ProcessMappingScanner
python
https://github.com/kata198/ProcessMappingScanner/blob/d1735fe6746493c51aaae213b982fa96f5c5b621/ProcessMappingScanner/__init__.py#L315-L392
[ "def", "scanProcessForOpenFile", "(", "pid", ",", "searchPortion", ",", "isExactMatch", "=", "True", ",", "ignoreCase", "=", "False", ")", ":", "try", ":", "try", ":", "pid", "=", "int", "(", "pid", ")", "except", "ValueError", "as", "e", ":", "sys", "...
d1735fe6746493c51aaae213b982fa96f5c5b621
valid
scanAllProcessesForOpenFile
scanAllProcessessForOpenFile - Scans all processes on the system for a given filename @param searchPortion <str> - Filename to check @param isExactMatch <bool> Default True - If match should be exact, otherwise a partial match is performed. @param ignoreCase <bool> Default False - I...
ProcessMappingScanner/__init__.py
def scanAllProcessesForOpenFile(searchPortion, isExactMatch=True, ignoreCase=False): ''' scanAllProcessessForOpenFile - Scans all processes on the system for a given filename @param searchPortion <str> - Filename to check @param isExactMatch <bool> Default True - If match should be ...
def scanAllProcessesForOpenFile(searchPortion, isExactMatch=True, ignoreCase=False): ''' scanAllProcessessForOpenFile - Scans all processes on the system for a given filename @param searchPortion <str> - Filename to check @param isExactMatch <bool> Default True - If match should be ...
[ "scanAllProcessessForOpenFile", "-", "Scans", "all", "processes", "on", "the", "system", "for", "a", "given", "filename" ]
kata198/ProcessMappingScanner
python
https://github.com/kata198/ProcessMappingScanner/blob/d1735fe6746493c51aaae213b982fa96f5c5b621/ProcessMappingScanner/__init__.py#L395-L414
[ "def", "scanAllProcessesForOpenFile", "(", "searchPortion", ",", "isExactMatch", "=", "True", ",", "ignoreCase", "=", "False", ")", ":", "pids", "=", "getAllRunningPids", "(", ")", "# Since processes could disappear, we run the scan as fast as possible here with a list comprehe...
d1735fe6746493c51aaae213b982fa96f5c5b621
valid
enum
class buider
snipy/enum.py
def enum(name, *members, **withvalue): """class buider""" if len(members) == 1: if isinstance(members[0], str): members = members[0].split() elif isinstance(members[0], (list, tuple)): members = members[0] dic = {v: v for v in members} dic.update(withvalue) ...
def enum(name, *members, **withvalue): """class buider""" if len(members) == 1: if isinstance(members[0], str): members = members[0].split() elif isinstance(members[0], (list, tuple)): members = members[0] dic = {v: v for v in members} dic.update(withvalue) ...
[ "class", "buider" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/enum.py#L26-L37
[ "def", "enum", "(", "name", ",", "*", "members", ",", "*", "*", "withvalue", ")", ":", "if", "len", "(", "members", ")", "==", "1", ":", "if", "isinstance", "(", "members", "[", "0", "]", ",", "str", ")", ":", "members", "=", "members", "[", "0...
408520867179f99b3158b57520e2619f3fecd69b
valid
database
usage: with database('my_db') as conn: c = conn.cursor() .... database 커넥션 with 문과 같이 사용하고, 알아서 close하기 :param db: str: db스키마 :param kwargs: :return:
snipy/database.py
def database(db='', **kwargs): """ usage: with database('my_db') as conn: c = conn.cursor() .... database 커넥션 with 문과 같이 사용하고, 알아서 close하기 :param db: str: db스키마 :param kwargs: :return: """ db = kwargs.pop('db', db) arg = db_config(db) arg.update(kwargs) r...
def database(db='', **kwargs): """ usage: with database('my_db') as conn: c = conn.cursor() .... database 커넥션 with 문과 같이 사용하고, 알아서 close하기 :param db: str: db스키마 :param kwargs: :return: """ db = kwargs.pop('db', db) arg = db_config(db) arg.update(kwargs) r...
[ "usage", ":", "with", "database", "(", "my_db", ")", "as", "conn", ":", "c", "=", "conn", ".", "cursor", "()", "....", "database", "커넥션", "with", "문과", "같이", "사용하고", "알아서", "close하기", ":", "param", "db", ":", "str", ":", "db스키마", ":", "param", "kwa...
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/database.py#L23-L38
[ "def", "database", "(", "db", "=", "''", ",", "*", "*", "kwargs", ")", ":", "db", "=", "kwargs", ".", "pop", "(", "'db'", ",", "db", ")", "arg", "=", "db_config", "(", "db", ")", "arg", ".", "update", "(", "kwargs", ")", "return", "closing", "(...
408520867179f99b3158b57520e2619f3fecd69b
valid
connect
db 접속 공통 인자들 채워서 접속, schema만 넣으면 됩니다. db connection 객체 반환이지만 with 문과 같이 쓰이면 cursor임에 주의 (MySQLdb의 구현이 그렇습니다.) ex1) import snipy.database as db conn = db.connect('my_db') cursor = conn.cursor() ex2) import snipy.database as db with db.connect('my_db') as cursor: cursor.execut...
snipy/database.py
def connect(db='', **kwargs): """ db 접속 공통 인자들 채워서 접속, schema만 넣으면 됩니다. db connection 객체 반환이지만 with 문과 같이 쓰이면 cursor임에 주의 (MySQLdb의 구현이 그렇습니다.) ex1) import snipy.database as db conn = db.connect('my_db') cursor = conn.cursor() ex2) import snipy.database as db with db.connect...
def connect(db='', **kwargs): """ db 접속 공통 인자들 채워서 접속, schema만 넣으면 됩니다. db connection 객체 반환이지만 with 문과 같이 쓰이면 cursor임에 주의 (MySQLdb의 구현이 그렇습니다.) ex1) import snipy.database as db conn = db.connect('my_db') cursor = conn.cursor() ex2) import snipy.database as db with db.connect...
[ "db", "접속", "공통", "인자들", "채워서", "접속", "schema만", "넣으면", "됩니다", ".", "db", "connection", "객체", "반환이지만", "with", "문과", "같이", "쓰이면", "cursor임에", "주의", "(", "MySQLdb의", "구현이", "그렇습니다", ".", ")", "ex1", ")", "import", "snipy", ".", "database", "as", "db",...
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/database.py#L41-L62
[ "def", "connect", "(", "db", "=", "''", ",", "*", "*", "kwargs", ")", ":", "arg", "=", "db_config", "(", "db", ")", "arg", ".", "update", "(", "kwargs", ")", "return", "MySQLdb", ".", "connect", "(", "*", "*", "arg", ")" ]
408520867179f99b3158b57520e2619f3fecd69b
valid
_cursor_exit
cursor with문과 쓸수 있게 __exit__에 바인딩 :param cursor: :param exc_type: :param exc_value: :param traceback: :return:
snipy/database.py
def _cursor_exit(cursor, exc_type, exc_value, traceback): """ cursor with문과 쓸수 있게 __exit__에 바인딩 :param cursor: :param exc_type: :param exc_value: :param traceback: :return: """ if exc_type is not None: print(exc_value, traceback) cursor.connection.close()
def _cursor_exit(cursor, exc_type, exc_value, traceback): """ cursor with문과 쓸수 있게 __exit__에 바인딩 :param cursor: :param exc_type: :param exc_value: :param traceback: :return: """ if exc_type is not None: print(exc_value, traceback) cursor.connection.close()
[ "cursor", "with문과", "쓸수", "있게", "__exit__에", "바인딩", ":", "param", "cursor", ":", ":", "param", "exc_type", ":", ":", "param", "exc_value", ":", ":", "param", "traceback", ":", ":", "return", ":" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/database.py#L65-L76
[ "def", "_cursor_exit", "(", "cursor", ",", "exc_type", ",", "exc_value", ",", "traceback", ")", ":", "if", "exc_type", "is", "not", "None", ":", "print", "(", "exc_value", ",", "traceback", ")", "cursor", ".", "connection", ".", "close", "(", ")" ]
408520867179f99b3158b57520e2619f3fecd69b
valid
fetch
for record in fetch(query, args, **configs): print record :param args: :param db: str: db 스키마 :param query: 쿼리 스트링 :param kwargs: db connection 추가 인자. 보통 생략 :return: iterator
snipy/database.py
def fetch(query, args=None, **kwargs): """ for record in fetch(query, args, **configs): print record :param args: :param db: str: db 스키마 :param query: 쿼리 스트링 :param kwargs: db connection 추가 인자. 보통 생략 :return: iterator """ cur = execute(kwargs.pop('db', ''), query, args, **kwa...
def fetch(query, args=None, **kwargs): """ for record in fetch(query, args, **configs): print record :param args: :param db: str: db 스키마 :param query: 쿼리 스트링 :param kwargs: db connection 추가 인자. 보통 생략 :return: iterator """ cur = execute(kwargs.pop('db', ''), query, args, **kwa...
[ "for", "record", "in", "fetch", "(", "query", "args", "**", "configs", ")", ":", "print", "record", ":", "param", "args", ":", ":", "param", "db", ":", "str", ":", "db", "스키마", ":", "param", "query", ":", "쿼리", "스트링", ":", "param", "kwargs", ":", ...
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/database.py#L105-L120
[ "def", "fetch", "(", "query", ",", "args", "=", "None", ",", "*", "*", "kwargs", ")", ":", "cur", "=", "execute", "(", "kwargs", ".", "pop", "(", "'db'", ",", "''", ")", ",", "query", ",", "args", ",", "*", "*", "kwargs", ")", "for", "r", "in...
408520867179f99b3158b57520e2619f3fecd69b
valid
get_insert_query
format insert query :param table: str :param fields: list[str] :param field_count: int :return: str
snipy/database.py
def get_insert_query(table, fields=None, field_count=None): """ format insert query :param table: str :param fields: list[str] :param field_count: int :return: str """ if fields: q = 'insert into %s ({0}) values ({1});' % table l = len(fields) q = q.format(','.joi...
def get_insert_query(table, fields=None, field_count=None): """ format insert query :param table: str :param fields: list[str] :param field_count: int :return: str """ if fields: q = 'insert into %s ({0}) values ({1});' % table l = len(fields) q = q.format(','.joi...
[ "format", "insert", "query", ":", "param", "table", ":", "str", ":", "param", "fields", ":", "list", "[", "str", "]", ":", "param", "field_count", ":", "int", ":", "return", ":", "str" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/database.py#L145-L163
[ "def", "get_insert_query", "(", "table", ",", "fields", "=", "None", ",", "field_count", "=", "None", ")", ":", "if", "fields", ":", "q", "=", "'insert into %s ({0}) values ({1});'", "%", "table", "l", "=", "len", "(", "fields", ")", "q", "=", "q", ".", ...
408520867179f99b3158b57520e2619f3fecd69b
valid
insert
db에 레코드 집어넣기 ex) cursor.insert(table, v1, v2,...) ex) cursor.insert(table, id=v1, word=v2, commit=True) :param commit: :param cursor: :param table: :param args: :param field_values: :return:
snipy/database.py
def insert(cursor, table, *args, **field_values): """ db에 레코드 집어넣기 ex) cursor.insert(table, v1, v2,...) ex) cursor.insert(table, id=v1, word=v2, commit=True) :param commit: :param cursor: :param table: :param args: :param field_values: :return: """ commit = field_...
def insert(cursor, table, *args, **field_values): """ db에 레코드 집어넣기 ex) cursor.insert(table, v1, v2,...) ex) cursor.insert(table, id=v1, word=v2, commit=True) :param commit: :param cursor: :param table: :param args: :param field_values: :return: """ commit = field_...
[ "db에", "레코드", "집어넣기", "ex", ")", "cursor", ".", "insert", "(", "table", "v1", "v2", "...", ")", "ex", ")", "cursor", ".", "insert", "(", "table", "id", "=", "v1", "word", "=", "v2", "commit", "=", "True", ")", ":", "param", "commit", ":", ":", ...
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/database.py#L167-L195
[ "def", "insert", "(", "cursor", ",", "table", ",", "*", "args", ",", "*", "*", "field_values", ")", ":", "commit", "=", "field_values", ".", "pop", "(", "'commit'", ",", "True", ")", "q", ",", "a", "=", "None", ",", "None", "if", "args", "is", "n...
408520867179f99b3158b57520e2619f3fecd69b
valid
update
db update 쿼리 빌딩 및 실행, 단, commit은 :param cursor: 커서 :type cursor: Cursor :param table: 테이블 이름 :type table: str :param where_kv: 업데이트 where 조건 dictionary, key:field, value:equal condition only :type where_kv: dict :param field_values: kwarg 업데이트용 :type field_values: dict :param commit:...
snipy/database.py
def update(cursor, table, where_kv, commit=True, **field_values): """ db update 쿼리 빌딩 및 실행, 단, commit은 :param cursor: 커서 :type cursor: Cursor :param table: 테이블 이름 :type table: str :param where_kv: 업데이트 where 조건 dictionary, key:field, value:equal condition only :type where_kv: dict :p...
def update(cursor, table, where_kv, commit=True, **field_values): """ db update 쿼리 빌딩 및 실행, 단, commit은 :param cursor: 커서 :type cursor: Cursor :param table: 테이블 이름 :type table: str :param where_kv: 업데이트 where 조건 dictionary, key:field, value:equal condition only :type where_kv: dict :p...
[ "db", "update", "쿼리", "빌딩", "및", "실행", "단", "commit은", ":", "param", "cursor", ":", "커서", ":", "type", "cursor", ":", "Cursor", ":", "param", "table", ":", "테이블", "이름", ":", "type", "table", ":", "str", ":", "param", "where_kv", ":", "업데이트", "where...
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/database.py#L199-L227
[ "def", "update", "(", "cursor", ",", "table", ",", "where_kv", ",", "commit", "=", "True", ",", "*", "*", "field_values", ")", ":", "q", "=", "\"\"\"update %s \\nset {0} \\nwhere {1} \"\"\"", "%", "table", "fields", "=", "field_values", ".", "keys", "(", ")"...
408520867179f99b3158b57520e2619f3fecd69b
valid
insert_or_update
db update 쿼리 빌딩 및 실행, 단, commit은 :param cursor: 커서 :type cursor: Cursor :param table: 테이블이름 :type table: str :param commit: 커밋 여부 :type commit: bool :param field_values: insert 또는 업데이트 할 필드 및 값 dict pairs :type field_values:dict :return:
snipy/database.py
def insert_or_update(cursor, table, commit=True, **field_values): """ db update 쿼리 빌딩 및 실행, 단, commit은 :param cursor: 커서 :type cursor: Cursor :param table: 테이블이름 :type table: str :param commit: 커밋 여부 :type commit: bool :param field_values: insert 또는 업데이트 할 필드 및 값 dict pairs :type...
def insert_or_update(cursor, table, commit=True, **field_values): """ db update 쿼리 빌딩 및 실행, 단, commit은 :param cursor: 커서 :type cursor: Cursor :param table: 테이블이름 :type table: str :param commit: 커밋 여부 :type commit: bool :param field_values: insert 또는 업데이트 할 필드 및 값 dict pairs :type...
[ "db", "update", "쿼리", "빌딩", "및", "실행", "단", "commit은", ":", "param", "cursor", ":", "커서", ":", "type", "cursor", ":", "Cursor", ":", "param", "table", ":", "테이블이름", ":", "type", "table", ":", "str", ":", "param", "commit", ":", "커밋", "여부", ":", "...
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/database.py#L231-L258
[ "def", "insert_or_update", "(", "cursor", ",", "table", ",", "commit", "=", "True", ",", "*", "*", "field_values", ")", ":", "q", "=", "\"\"\"INSERT INTO %s ({0}) \\nVALUES ({1}) \\nON DUPLICATE KEY UPDATE {2} \"\"\"", "%", "table", "l", "=", "len", "(", "field_valu...
408520867179f99b3158b57520e2619f3fecd69b
valid
tojson
recursive implementation
snipy/jsonutil.py
def tojson(o): """ recursive implementation """ try: return json.encode(o) except json.EncodeError: pass try: return o.tojson() except AttributeError as e: pass t = type(o) if isinstance(o, list): return '[%s]' % ', '.join([tojson(e) for e in ...
def tojson(o): """ recursive implementation """ try: return json.encode(o) except json.EncodeError: pass try: return o.tojson() except AttributeError as e: pass t = type(o) if isinstance(o, list): return '[%s]' % ', '.join([tojson(e) for e in ...
[ "recursive", "implementation" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/jsonutil.py#L15-L40
[ "def", "tojson", "(", "o", ")", ":", "try", ":", "return", "json", ".", "encode", "(", "o", ")", "except", "json", ".", "EncodeError", ":", "pass", "try", ":", "return", "o", ".", "tojson", "(", ")", "except", "AttributeError", "as", "e", ":", "pas...
408520867179f99b3158b57520e2619f3fecd69b
valid
named
namedtuple with default values named('typename', fields | *fields, default=x, [**defaults]) :param typename: :param fieldnames: :param defaults: :return:
snipy/named.py
def named(typename, *fieldnames, **defaults): """ namedtuple with default values named('typename', fields | *fields, default=x, [**defaults]) :param typename: :param fieldnames: :param defaults: :return: """ if len(fieldnames) == 1: if isinstance(fieldnames[0], str): ...
def named(typename, *fieldnames, **defaults): """ namedtuple with default values named('typename', fields | *fields, default=x, [**defaults]) :param typename: :param fieldnames: :param defaults: :return: """ if len(fieldnames) == 1: if isinstance(fieldnames[0], str): ...
[ "namedtuple", "with", "default", "values", "named", "(", "typename", "fields", "|", "*", "fields", "default", "=", "x", "[", "**", "defaults", "]", ")", ":", "param", "typename", ":", ":", "param", "fieldnames", ":", ":", "param", "defaults", ":", ":", ...
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/named.py#L5-L33
[ "def", "named", "(", "typename", ",", "*", "fieldnames", ",", "*", "*", "defaults", ")", ":", "if", "len", "(", "fieldnames", ")", "==", "1", ":", "if", "isinstance", "(", "fieldnames", "[", "0", "]", ",", "str", ")", ":", "fieldnames", "=", "tuple...
408520867179f99b3158b57520e2619f3fecd69b
valid
np_seed
numpy random seed context :param seed: :return:
snipy/irandom.py
def np_seed(seed): """ numpy random seed context :param seed: :return: """ if seed is not None: state = np.random.get_state() np.random.seed(seed) yield np.random.set_state(state) else: yield
def np_seed(seed): """ numpy random seed context :param seed: :return: """ if seed is not None: state = np.random.get_state() np.random.seed(seed) yield np.random.set_state(state) else: yield
[ "numpy", "random", "seed", "context", ":", "param", "seed", ":", ":", "return", ":" ]
dade-ai/snipy
python
https://github.com/dade-ai/snipy/blob/408520867179f99b3158b57520e2619f3fecd69b/snipy/irandom.py#L7-L20
[ "def", "np_seed", "(", "seed", ")", ":", "if", "seed", "is", "not", "None", ":", "state", "=", "np", ".", "random", ".", "get_state", "(", ")", "np", ".", "random", ".", "seed", "(", "seed", ")", "yield", "np", ".", "random", ".", "set_state", "(...
408520867179f99b3158b57520e2619f3fecd69b
valid
Hub.connect
Create and connect to socket for TCP communication with hub.
yeelightsunflower/main.py
def connect(self): """Create and connect to socket for TCP communication with hub.""" try: self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._socket.settimeout(TIMEOUT_SECONDS) self._socket.connect((self._ip, self._port)) _LOGGER.debug(...
def connect(self): """Create and connect to socket for TCP communication with hub.""" try: self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._socket.settimeout(TIMEOUT_SECONDS) self._socket.connect((self._ip, self._port)) _LOGGER.debug(...
[ "Create", "and", "connect", "to", "socket", "for", "TCP", "communication", "with", "hub", "." ]
lindsaymarkward/python-yeelight-sunflower
python
https://github.com/lindsaymarkward/python-yeelight-sunflower/blob/4ec72d005ce307f832429620ba0bcbf6b236eead/yeelightsunflower/main.py#L40-L50
[ "def", "connect", "(", "self", ")", ":", "try", ":", "self", ".", "_socket", "=", "socket", ".", "socket", "(", "socket", ".", "AF_INET", ",", "socket", ".", "SOCK_STREAM", ")", "self", ".", "_socket", ".", "settimeout", "(", "TIMEOUT_SECONDS", ")", "s...
4ec72d005ce307f832429620ba0bcbf6b236eead
valid
Hub.send_command
Send TCP command to hub and return response.
yeelightsunflower/main.py
def send_command(self, command): """Send TCP command to hub and return response.""" # use lock to make TCP send/receive thread safe with self._lock: try: self._socket.send(command.encode("utf8")) result = self.receive() # hub may send "...
def send_command(self, command): """Send TCP command to hub and return response.""" # use lock to make TCP send/receive thread safe with self._lock: try: self._socket.send(command.encode("utf8")) result = self.receive() # hub may send "...
[ "Send", "TCP", "command", "to", "hub", "and", "return", "response", "." ]
lindsaymarkward/python-yeelight-sunflower
python
https://github.com/lindsaymarkward/python-yeelight-sunflower/blob/4ec72d005ce307f832429620ba0bcbf6b236eead/yeelightsunflower/main.py#L58-L75
[ "def", "send_command", "(", "self", ",", "command", ")", ":", "# use lock to make TCP send/receive thread safe", "with", "self", ".", "_lock", ":", "try", ":", "self", ".", "_socket", ".", "send", "(", "command", ".", "encode", "(", "\"utf8\"", ")", ")", "re...
4ec72d005ce307f832429620ba0bcbf6b236eead
valid
Hub.receive
Receive TCP response, looping to get whole thing or timeout.
yeelightsunflower/main.py
def receive(self): """Receive TCP response, looping to get whole thing or timeout.""" try: buffer = self._socket.recv(BUFFER_SIZE) except socket.timeout as error: # Something is wrong, assume it's offline temporarily _LOGGER.error("Error receiving: %s", error)...
def receive(self): """Receive TCP response, looping to get whole thing or timeout.""" try: buffer = self._socket.recv(BUFFER_SIZE) except socket.timeout as error: # Something is wrong, assume it's offline temporarily _LOGGER.error("Error receiving: %s", error)...
[ "Receive", "TCP", "response", "looping", "to", "get", "whole", "thing", "or", "timeout", "." ]
lindsaymarkward/python-yeelight-sunflower
python
https://github.com/lindsaymarkward/python-yeelight-sunflower/blob/4ec72d005ce307f832429620ba0bcbf6b236eead/yeelightsunflower/main.py#L77-L104
[ "def", "receive", "(", "self", ")", ":", "try", ":", "buffer", "=", "self", ".", "_socket", ".", "recv", "(", "BUFFER_SIZE", ")", "except", "socket", ".", "timeout", "as", "error", ":", "# Something is wrong, assume it's offline temporarily", "_LOGGER", ".", "...
4ec72d005ce307f832429620ba0bcbf6b236eead
valid
Hub.get_data
Get current light data as dictionary with light zids as keys.
yeelightsunflower/main.py
def get_data(self): """Get current light data as dictionary with light zids as keys.""" response = self.send_command(GET_LIGHTS_COMMAND) _LOGGER.debug("get_data response: %s", repr(response)) if not response: _LOGGER.debug("Empty response: %s", response) return {}...
def get_data(self): """Get current light data as dictionary with light zids as keys.""" response = self.send_command(GET_LIGHTS_COMMAND) _LOGGER.debug("get_data response: %s", repr(response)) if not response: _LOGGER.debug("Empty response: %s", response) return {}...
[ "Get", "current", "light", "data", "as", "dictionary", "with", "light", "zids", "as", "keys", "." ]
lindsaymarkward/python-yeelight-sunflower
python
https://github.com/lindsaymarkward/python-yeelight-sunflower/blob/4ec72d005ce307f832429620ba0bcbf6b236eead/yeelightsunflower/main.py#L106-L134
[ "def", "get_data", "(", "self", ")", ":", "response", "=", "self", ".", "send_command", "(", "GET_LIGHTS_COMMAND", ")", "_LOGGER", ".", "debug", "(", "\"get_data response: %s\"", ",", "repr", "(", "response", ")", ")", "if", "not", "response", ":", "_LOGGER"...
4ec72d005ce307f832429620ba0bcbf6b236eead
valid
Hub.get_lights
Get current light data, set and return as list of Bulb objects.
yeelightsunflower/main.py
def get_lights(self): """Get current light data, set and return as list of Bulb objects.""" # Throttle updates. Use cached data if within UPDATE_INTERVAL_SECONDS now = datetime.datetime.now() if (now - self._last_updated) < datetime.timedelta( seconds=UPDATE_INTERVAL_SECO...
def get_lights(self): """Get current light data, set and return as list of Bulb objects.""" # Throttle updates. Use cached data if within UPDATE_INTERVAL_SECONDS now = datetime.datetime.now() if (now - self._last_updated) < datetime.timedelta( seconds=UPDATE_INTERVAL_SECO...
[ "Get", "current", "light", "data", "set", "and", "return", "as", "list", "of", "Bulb", "objects", "." ]
lindsaymarkward/python-yeelight-sunflower
python
https://github.com/lindsaymarkward/python-yeelight-sunflower/blob/4ec72d005ce307f832429620ba0bcbf6b236eead/yeelightsunflower/main.py#L136-L166
[ "def", "get_lights", "(", "self", ")", ":", "# Throttle updates. Use cached data if within UPDATE_INTERVAL_SECONDS", "now", "=", "datetime", ".", "datetime", ".", "now", "(", ")", "if", "(", "now", "-", "self", ".", "_last_updated", ")", "<", "datetime", ".", "t...
4ec72d005ce307f832429620ba0bcbf6b236eead