repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
emre/storm
storm/__main__.py
web
def web(port, debug=False, theme="modern", ssh_config=None): """Starts the web UI.""" from storm import web as _web _web.run(port, debug, theme, ssh_config)
python
def web(port, debug=False, theme="modern", ssh_config=None): """Starts the web UI.""" from storm import web as _web _web.run(port, debug, theme, ssh_config)
[ "def", "web", "(", "port", ",", "debug", "=", "False", ",", "theme", "=", "\"modern\"", ",", "ssh_config", "=", "None", ")", ":", "from", "storm", "import", "web", "as", "_web", "_web", ".", "run", "(", "port", ",", "debug", ",", "theme", ",", "ssh...
Starts the web UI.
[ "Starts", "the", "web", "UI", "." ]
c752defc1b718cfffbf0e0e15532fa1d7840bf6d
https://github.com/emre/storm/blob/c752defc1b718cfffbf0e0e15532fa1d7840bf6d/storm/__main__.py#L310-L313
train
diging/tethne
tethne/writers/collection.py
_strip_list_attributes
def _strip_list_attributes(graph_): """Converts lists attributes to strings for all nodes and edges in G.""" for n_ in graph_.nodes(data=True): for k,v in n_[1].iteritems(): if type(v) is list: graph_.node[n_[0]][k] = unicode(v) for e_ in graph_.edges(data=True): ...
python
def _strip_list_attributes(graph_): """Converts lists attributes to strings for all nodes and edges in G.""" for n_ in graph_.nodes(data=True): for k,v in n_[1].iteritems(): if type(v) is list: graph_.node[n_[0]][k] = unicode(v) for e_ in graph_.edges(data=True): ...
[ "def", "_strip_list_attributes", "(", "graph_", ")", ":", "for", "n_", "in", "graph_", ".", "nodes", "(", "data", "=", "True", ")", ":", "for", "k", ",", "v", "in", "n_", "[", "1", "]", ".", "iteritems", "(", ")", ":", "if", "type", "(", "v", "...
Converts lists attributes to strings for all nodes and edges in G.
[ "Converts", "lists", "attributes", "to", "strings", "for", "all", "nodes", "and", "edges", "in", "G", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/writers/collection.py#L189-L200
train
diging/tethne
tethne/writers/collection.py
_safe_type
def _safe_type(value): """Converts Python type names to XGMML-safe type names.""" if type(value) is str: dtype = 'string' if type(value) is unicode: dtype = 'string' if type(value) is int: dtype = 'integer' if type(value) is float: dtype = 'real' return dtype
python
def _safe_type(value): """Converts Python type names to XGMML-safe type names.""" if type(value) is str: dtype = 'string' if type(value) is unicode: dtype = 'string' if type(value) is int: dtype = 'integer' if type(value) is float: dtype = 'real' return dtype
[ "def", "_safe_type", "(", "value", ")", ":", "if", "type", "(", "value", ")", "is", "str", ":", "dtype", "=", "'string'", "if", "type", "(", "value", ")", "is", "unicode", ":", "dtype", "=", "'string'", "if", "type", "(", "value", ")", "is", "int",...
Converts Python type names to XGMML-safe type names.
[ "Converts", "Python", "type", "names", "to", "XGMML", "-", "safe", "type", "names", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/writers/collection.py#L202-L210
train
diging/tethne
tethne/readers/wos.py
read
def read(path, corpus=True, index_by='wosid', streaming=False, parse_only=None, corpus_class=Corpus, **kwargs): """ Parse one or more WoS field-tagged data files. Examples -------- .. code-block:: python >>> from tethne.readers import wos >>> corpus = wos.read("/path/to/some...
python
def read(path, corpus=True, index_by='wosid', streaming=False, parse_only=None, corpus_class=Corpus, **kwargs): """ Parse one or more WoS field-tagged data files. Examples -------- .. code-block:: python >>> from tethne.readers import wos >>> corpus = wos.read("/path/to/some...
[ "def", "read", "(", "path", ",", "corpus", "=", "True", ",", "index_by", "=", "'wosid'", ",", "streaming", "=", "False", ",", "parse_only", "=", "None", ",", "corpus_class", "=", "Corpus", ",", "*", "*", "kwargs", ")", ":", "if", "not", "os", ".", ...
Parse one or more WoS field-tagged data files. Examples -------- .. code-block:: python >>> from tethne.readers import wos >>> corpus = wos.read("/path/to/some/wos/data") >>> corpus <tethne.classes.corpus.Corpus object at 0x10057c2d0> Parameters ---------- path : s...
[ "Parse", "one", "or", "more", "WoS", "field", "-", "tagged", "data", "files", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/wos.py#L350-L401
train
diging/tethne
tethne/readers/wos.py
WoSParser.parse_author
def parse_author(self, value): """ Attempts to split an author name into last and first parts. """ tokens = tuple([t.upper().strip() for t in value.split(',')]) if len(tokens) == 1: tokens = value.split(' ') if len(tokens) > 0: if len(tokens) > 1: ...
python
def parse_author(self, value): """ Attempts to split an author name into last and first parts. """ tokens = tuple([t.upper().strip() for t in value.split(',')]) if len(tokens) == 1: tokens = value.split(' ') if len(tokens) > 0: if len(tokens) > 1: ...
[ "def", "parse_author", "(", "self", ",", "value", ")", ":", "tokens", "=", "tuple", "(", "[", "t", ".", "upper", "(", ")", ".", "strip", "(", ")", "for", "t", "in", "value", ".", "split", "(", "','", ")", "]", ")", "if", "len", "(", "tokens", ...
Attempts to split an author name into last and first parts.
[ "Attempts", "to", "split", "an", "author", "name", "into", "last", "and", "first", "parts", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/wos.py#L112-L129
train
diging/tethne
tethne/readers/wos.py
WoSParser.handle_CR
def handle_CR(self, value): """ Parses cited references. """ citation = self.entry_class() value = strip_tags(value) # First-author name and publication date. ptn = '([\w\s\W]+),\s([0-9]{4}),\s([\w\s]+)' ny_match = re.match(ptn, value, flags=re.U) ...
python
def handle_CR(self, value): """ Parses cited references. """ citation = self.entry_class() value = strip_tags(value) # First-author name and publication date. ptn = '([\w\s\W]+),\s([0-9]{4}),\s([\w\s]+)' ny_match = re.match(ptn, value, flags=re.U) ...
[ "def", "handle_CR", "(", "self", ",", "value", ")", ":", "citation", "=", "self", ".", "entry_class", "(", ")", "value", "=", "strip_tags", "(", "value", ")", "# First-author name and publication date.", "ptn", "=", "'([\\w\\s\\W]+),\\s([0-9]{4}),\\s([\\w\\s]+)'", "...
Parses cited references.
[ "Parses", "cited", "references", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/wos.py#L157-L227
train
diging/tethne
tethne/readers/wos.py
WoSParser.postprocess_WC
def postprocess_WC(self, entry): """ Parse WC keywords. Subject keywords are usually semicolon-delimited. """ if type(entry.WC) not in [str, unicode]: WC= u' '.join([unicode(k) for k in entry.WC]) else: WC= entry.WC entry.WC= [k.strip().u...
python
def postprocess_WC(self, entry): """ Parse WC keywords. Subject keywords are usually semicolon-delimited. """ if type(entry.WC) not in [str, unicode]: WC= u' '.join([unicode(k) for k in entry.WC]) else: WC= entry.WC entry.WC= [k.strip().u...
[ "def", "postprocess_WC", "(", "self", ",", "entry", ")", ":", "if", "type", "(", "entry", ".", "WC", ")", "not", "in", "[", "str", ",", "unicode", "]", ":", "WC", "=", "u' '", ".", "join", "(", "[", "unicode", "(", "k", ")", "for", "k", "in", ...
Parse WC keywords. Subject keywords are usually semicolon-delimited.
[ "Parse", "WC", "keywords", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/wos.py#L229-L240
train
diging/tethne
tethne/readers/wos.py
WoSParser.postprocess_subject
def postprocess_subject(self, entry): """ Parse subject keywords. Subject keywords are usually semicolon-delimited. """ if type(entry.subject) not in [str, unicode]: subject = u' '.join([unicode(k) for k in entry.subject]) else: subject = entry.s...
python
def postprocess_subject(self, entry): """ Parse subject keywords. Subject keywords are usually semicolon-delimited. """ if type(entry.subject) not in [str, unicode]: subject = u' '.join([unicode(k) for k in entry.subject]) else: subject = entry.s...
[ "def", "postprocess_subject", "(", "self", ",", "entry", ")", ":", "if", "type", "(", "entry", ".", "subject", ")", "not", "in", "[", "str", ",", "unicode", "]", ":", "subject", "=", "u' '", ".", "join", "(", "[", "unicode", "(", "k", ")", "for", ...
Parse subject keywords. Subject keywords are usually semicolon-delimited.
[ "Parse", "subject", "keywords", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/wos.py#L242-L253
train
diging/tethne
tethne/readers/wos.py
WoSParser.postprocess_authorKeywords
def postprocess_authorKeywords(self, entry): """ Parse author keywords. Author keywords are usually semicolon-delimited. """ if type(entry.authorKeywords) not in [str, unicode]: aK = u' '.join([unicode(k) for k in entry.authorKeywords]) else: aK ...
python
def postprocess_authorKeywords(self, entry): """ Parse author keywords. Author keywords are usually semicolon-delimited. """ if type(entry.authorKeywords) not in [str, unicode]: aK = u' '.join([unicode(k) for k in entry.authorKeywords]) else: aK ...
[ "def", "postprocess_authorKeywords", "(", "self", ",", "entry", ")", ":", "if", "type", "(", "entry", ".", "authorKeywords", ")", "not", "in", "[", "str", ",", "unicode", "]", ":", "aK", "=", "u' '", ".", "join", "(", "[", "unicode", "(", "k", ")", ...
Parse author keywords. Author keywords are usually semicolon-delimited.
[ "Parse", "author", "keywords", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/wos.py#L255-L266
train
diging/tethne
tethne/readers/wos.py
WoSParser.postprocess_keywordsPlus
def postprocess_keywordsPlus(self, entry): """ Parse WoS "Keyword Plus" keywords. Keyword Plus keywords are usually semicolon-delimited. """ if type(entry.keywordsPlus) in [str, unicode]: entry.keywordsPlus = [k.strip().upper() for k ...
python
def postprocess_keywordsPlus(self, entry): """ Parse WoS "Keyword Plus" keywords. Keyword Plus keywords are usually semicolon-delimited. """ if type(entry.keywordsPlus) in [str, unicode]: entry.keywordsPlus = [k.strip().upper() for k ...
[ "def", "postprocess_keywordsPlus", "(", "self", ",", "entry", ")", ":", "if", "type", "(", "entry", ".", "keywordsPlus", ")", "in", "[", "str", ",", "unicode", "]", ":", "entry", ".", "keywordsPlus", "=", "[", "k", ".", "strip", "(", ")", ".", "upper...
Parse WoS "Keyword Plus" keywords. Keyword Plus keywords are usually semicolon-delimited.
[ "Parse", "WoS", "Keyword", "Plus", "keywords", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/wos.py#L268-L277
train
diging/tethne
tethne/readers/wos.py
WoSParser.postprocess_funding
def postprocess_funding(self, entry): """ Separates funding agency from grant numbers. """ if type(entry.funding) not in [str, unicode]: return sources = [fu.strip() for fu in entry.funding.split(';')] sources_processed = [] for source in sources: ...
python
def postprocess_funding(self, entry): """ Separates funding agency from grant numbers. """ if type(entry.funding) not in [str, unicode]: return sources = [fu.strip() for fu in entry.funding.split(';')] sources_processed = [] for source in sources: ...
[ "def", "postprocess_funding", "(", "self", ",", "entry", ")", ":", "if", "type", "(", "entry", ".", "funding", ")", "not", "in", "[", "str", ",", "unicode", "]", ":", "return", "sources", "=", "[", "fu", ".", "strip", "(", ")", "for", "fu", "in", ...
Separates funding agency from grant numbers.
[ "Separates", "funding", "agency", "from", "grant", "numbers", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/wos.py#L279-L296
train
diging/tethne
tethne/readers/wos.py
WoSParser.postprocess_authors_full
def postprocess_authors_full(self, entry): """ If only a single author was found, ensure that ``authors_full`` is nonetheless a list. """ if type(entry.authors_full) is not list: entry.authors_full = [entry.authors_full]
python
def postprocess_authors_full(self, entry): """ If only a single author was found, ensure that ``authors_full`` is nonetheless a list. """ if type(entry.authors_full) is not list: entry.authors_full = [entry.authors_full]
[ "def", "postprocess_authors_full", "(", "self", ",", "entry", ")", ":", "if", "type", "(", "entry", ".", "authors_full", ")", "is", "not", "list", ":", "entry", ".", "authors_full", "=", "[", "entry", ".", "authors_full", "]" ]
If only a single author was found, ensure that ``authors_full`` is nonetheless a list.
[ "If", "only", "a", "single", "author", "was", "found", "ensure", "that", "authors_full", "is", "nonetheless", "a", "list", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/wos.py#L298-L304
train
diging/tethne
tethne/readers/wos.py
WoSParser.postprocess_authors_init
def postprocess_authors_init(self, entry): """ If only a single author was found, ensure that ``authors_init`` is nonetheless a list. """ if type(entry.authors_init) is not list: entry.authors_init = [entry.authors_init]
python
def postprocess_authors_init(self, entry): """ If only a single author was found, ensure that ``authors_init`` is nonetheless a list. """ if type(entry.authors_init) is not list: entry.authors_init = [entry.authors_init]
[ "def", "postprocess_authors_init", "(", "self", ",", "entry", ")", ":", "if", "type", "(", "entry", ".", "authors_init", ")", "is", "not", "list", ":", "entry", ".", "authors_init", "=", "[", "entry", ".", "authors_init", "]" ]
If only a single author was found, ensure that ``authors_init`` is nonetheless a list.
[ "If", "only", "a", "single", "author", "was", "found", "ensure", "that", "authors_init", "is", "nonetheless", "a", "list", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/wos.py#L306-L312
train
diging/tethne
tethne/readers/wos.py
WoSParser.postprocess_citedReferences
def postprocess_citedReferences(self, entry): """ If only a single cited reference was found, ensure that ``citedReferences`` is nonetheless a list. """ if type(entry.citedReferences) is not list: entry.citedReferences = [entry.citedReferences]
python
def postprocess_citedReferences(self, entry): """ If only a single cited reference was found, ensure that ``citedReferences`` is nonetheless a list. """ if type(entry.citedReferences) is not list: entry.citedReferences = [entry.citedReferences]
[ "def", "postprocess_citedReferences", "(", "self", ",", "entry", ")", ":", "if", "type", "(", "entry", ".", "citedReferences", ")", "is", "not", "list", ":", "entry", ".", "citedReferences", "=", "[", "entry", ".", "citedReferences", "]" ]
If only a single cited reference was found, ensure that ``citedReferences`` is nonetheless a list.
[ "If", "only", "a", "single", "cited", "reference", "was", "found", "ensure", "that", "citedReferences", "is", "nonetheless", "a", "list", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/wos.py#L314-L320
train
diging/tethne
tethne/plot/__init__.py
plot_burstness
def plot_burstness(corpus, B, **kwargs): """ Generate a figure depicting burstness profiles for ``feature``. Parameters ---------- B Returns ------- fig : :class:`matplotlib.figure.Figure` Examples -------- .. code-block:: python >>> from tethne.analyze.corpus imp...
python
def plot_burstness(corpus, B, **kwargs): """ Generate a figure depicting burstness profiles for ``feature``. Parameters ---------- B Returns ------- fig : :class:`matplotlib.figure.Figure` Examples -------- .. code-block:: python >>> from tethne.analyze.corpus imp...
[ "def", "plot_burstness", "(", "corpus", ",", "B", ",", "*", "*", "kwargs", ")", ":", "try", ":", "import", "matplotlib", ".", "pyplot", "as", "plt", "import", "matplotlib", ".", "patches", "as", "mpatches", "except", "ImportError", ":", "raise", "RuntimeEr...
Generate a figure depicting burstness profiles for ``feature``. Parameters ---------- B Returns ------- fig : :class:`matplotlib.figure.Figure` Examples -------- .. code-block:: python >>> from tethne.analyze.corpus import burstness >>> fig = plot_burstness(corpus,...
[ "Generate", "a", "figure", "depicting", "burstness", "profiles", "for", "feature", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/plot/__init__.py#L11-L97
train
diging/tethne
tethne/networks/helpers.py
simplify_multigraph
def simplify_multigraph(multigraph, time=False): """ Simplifies a graph by condensing multiple edges between the same node pair into a single edge, with a weight attribute equal to the number of edges. Parameters ---------- graph : networkx.MultiGraph E.g. a coauthorship graph. time...
python
def simplify_multigraph(multigraph, time=False): """ Simplifies a graph by condensing multiple edges between the same node pair into a single edge, with a weight attribute equal to the number of edges. Parameters ---------- graph : networkx.MultiGraph E.g. a coauthorship graph. time...
[ "def", "simplify_multigraph", "(", "multigraph", ",", "time", "=", "False", ")", ":", "graph", "=", "nx", ".", "Graph", "(", ")", "for", "node", "in", "multigraph", ".", "nodes", "(", "data", "=", "True", ")", ":", "u", "=", "node", "[", "0", "]", ...
Simplifies a graph by condensing multiple edges between the same node pair into a single edge, with a weight attribute equal to the number of edges. Parameters ---------- graph : networkx.MultiGraph E.g. a coauthorship graph. time : bool If True, will generate 'start' and 'end' attr...
[ "Simplifies", "a", "graph", "by", "condensing", "multiple", "edges", "between", "the", "same", "node", "pair", "into", "a", "single", "edge", "with", "a", "weight", "attribute", "equal", "to", "the", "number", "of", "edges", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/networks/helpers.py#L28-L81
train
diging/tethne
tethne/networks/helpers.py
citation_count
def citation_count(papers, key='ayjid', verbose=False): """ Generates citation counts for all of the papers cited by papers. Parameters ---------- papers : list A list of :class:`.Paper` instances. key : str Property to use as node key. Default is 'ayjid' (recommended). verb...
python
def citation_count(papers, key='ayjid', verbose=False): """ Generates citation counts for all of the papers cited by papers. Parameters ---------- papers : list A list of :class:`.Paper` instances. key : str Property to use as node key. Default is 'ayjid' (recommended). verb...
[ "def", "citation_count", "(", "papers", ",", "key", "=", "'ayjid'", ",", "verbose", "=", "False", ")", ":", "if", "verbose", ":", "print", "\"Generating citation counts for \"", "+", "unicode", "(", "len", "(", "papers", ")", ")", "+", "\" papers...\"", "cou...
Generates citation counts for all of the papers cited by papers. Parameters ---------- papers : list A list of :class:`.Paper` instances. key : str Property to use as node key. Default is 'ayjid' (recommended). verbose : bool If True, prints status messages. Returns ...
[ "Generates", "citation", "counts", "for", "all", "of", "the", "papers", "cited", "by", "papers", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/networks/helpers.py#L83-L111
train
diging/tethne
tethne/analyze/collection.py
connected
def connected(G, method_name, **kwargs): """ Performs analysis methods from networkx.connected on each graph in the collection. Parameters ---------- G : :class:`.GraphCollection` The :class:`.GraphCollection` to analyze. The specified method will be applied to each graph in ``G...
python
def connected(G, method_name, **kwargs): """ Performs analysis methods from networkx.connected on each graph in the collection. Parameters ---------- G : :class:`.GraphCollection` The :class:`.GraphCollection` to analyze. The specified method will be applied to each graph in ``G...
[ "def", "connected", "(", "G", ",", "method_name", ",", "*", "*", "kwargs", ")", ":", "warnings", ".", "warn", "(", "\"To be removed in 0.8. Use GraphCollection.analyze instead.\"", ",", "DeprecationWarning", ")", "return", "G", ".", "analyze", "(", "[", "'connecte...
Performs analysis methods from networkx.connected on each graph in the collection. Parameters ---------- G : :class:`.GraphCollection` The :class:`.GraphCollection` to analyze. The specified method will be applied to each graph in ``G``. method : string Name of method in net...
[ "Performs", "analysis", "methods", "from", "networkx", ".", "connected", "on", "each", "graph", "in", "the", "collection", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/analyze/collection.py#L72-L101
train
diging/tethne
tethne/analyze/collection.py
attachment_probability
def attachment_probability(G): """ Calculates the observed attachment probability for each node at each time-step. Attachment probability is calculated based on the observed new edges in the next time-step. So if a node acquires new edges at time t, this will accrue to the node's attac...
python
def attachment_probability(G): """ Calculates the observed attachment probability for each node at each time-step. Attachment probability is calculated based on the observed new edges in the next time-step. So if a node acquires new edges at time t, this will accrue to the node's attac...
[ "def", "attachment_probability", "(", "G", ")", ":", "warnings", ".", "warn", "(", "\"Removed in 0.8. Too domain-specific.\"", ")", "probs", "=", "{", "}", "G_", "=", "None", "k_", "=", "None", "for", "k", ",", "g", "in", "G", ".", "graphs", ".", "iterit...
Calculates the observed attachment probability for each node at each time-step. Attachment probability is calculated based on the observed new edges in the next time-step. So if a node acquires new edges at time t, this will accrue to the node's attachment probability at time t-1. Thus at a gi...
[ "Calculates", "the", "observed", "attachment", "probability", "for", "each", "node", "at", "each", "time", "-", "step", ".", "Attachment", "probability", "is", "calculated", "based", "on", "the", "observed", "new", "edges", "in", "the", "next", "time", "-", ...
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/analyze/collection.py#L104-L166
train
diging/tethne
tethne/analyze/graph.py
global_closeness_centrality
def global_closeness_centrality(g, node=None, normalize=True): """ Calculates global closeness centrality for one or all nodes in the network. See :func:`.node_global_closeness_centrality` for more information. Parameters ---------- g : networkx.Graph normalize : boolean If True, n...
python
def global_closeness_centrality(g, node=None, normalize=True): """ Calculates global closeness centrality for one or all nodes in the network. See :func:`.node_global_closeness_centrality` for more information. Parameters ---------- g : networkx.Graph normalize : boolean If True, n...
[ "def", "global_closeness_centrality", "(", "g", ",", "node", "=", "None", ",", "normalize", "=", "True", ")", ":", "if", "not", "node", ":", "C", "=", "{", "}", "for", "node", "in", "g", ".", "nodes", "(", ")", ":", "C", "[", "node", "]", "=", ...
Calculates global closeness centrality for one or all nodes in the network. See :func:`.node_global_closeness_centrality` for more information. Parameters ---------- g : networkx.Graph normalize : boolean If True, normalizes centrality based on the average shortest path length. Def...
[ "Calculates", "global", "closeness", "centrality", "for", "one", "or", "all", "nodes", "in", "the", "network", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/analyze/graph.py#L13-L49
train
diging/tethne
tethne/readers/dfr.py
ngrams
def ngrams(path, elem, ignore_hash=True): """ Yields N-grams from a JSTOR DfR dataset. Parameters ---------- path : string Path to unzipped JSTOR DfR folder containing N-grams. elem : string Name of subdirectory containing N-grams. (e.g. 'bigrams'). ignore_hash : bool ...
python
def ngrams(path, elem, ignore_hash=True): """ Yields N-grams from a JSTOR DfR dataset. Parameters ---------- path : string Path to unzipped JSTOR DfR folder containing N-grams. elem : string Name of subdirectory containing N-grams. (e.g. 'bigrams'). ignore_hash : bool ...
[ "def", "ngrams", "(", "path", ",", "elem", ",", "ignore_hash", "=", "True", ")", ":", "grams", "=", "GramGenerator", "(", "path", ",", "elem", ",", "ignore_hash", "=", "ignore_hash", ")", "return", "FeatureSet", "(", "{", "k", ":", "Feature", "(", "f",...
Yields N-grams from a JSTOR DfR dataset. Parameters ---------- path : string Path to unzipped JSTOR DfR folder containing N-grams. elem : string Name of subdirectory containing N-grams. (e.g. 'bigrams'). ignore_hash : bool If True, will exclude all N-grams that contain the h...
[ "Yields", "N", "-", "grams", "from", "a", "JSTOR", "DfR", "dataset", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/dfr.py#L294-L314
train
diging/tethne
tethne/readers/dfr.py
tokenize
def tokenize(ngrams, min_tf=2, min_df=2, min_len=3, apply_stoplist=False): """ Builds a vocabulary, and replaces words with vocab indices. Parameters ---------- ngrams : dict Keys are paper DOIs, values are lists of (Ngram, frequency) tuples. apply_stoplist : bool If True, will ...
python
def tokenize(ngrams, min_tf=2, min_df=2, min_len=3, apply_stoplist=False): """ Builds a vocabulary, and replaces words with vocab indices. Parameters ---------- ngrams : dict Keys are paper DOIs, values are lists of (Ngram, frequency) tuples. apply_stoplist : bool If True, will ...
[ "def", "tokenize", "(", "ngrams", ",", "min_tf", "=", "2", ",", "min_df", "=", "2", ",", "min_len", "=", "3", ",", "apply_stoplist", "=", "False", ")", ":", "vocab", "=", "{", "}", "vocab_", "=", "{", "}", "word_tf", "=", "Counter", "(", ")", "wo...
Builds a vocabulary, and replaces words with vocab indices. Parameters ---------- ngrams : dict Keys are paper DOIs, values are lists of (Ngram, frequency) tuples. apply_stoplist : bool If True, will exclude all N-grams that contain words in the NLTK stoplist. Returns -...
[ "Builds", "a", "vocabulary", "and", "replaces", "words", "with", "vocab", "indices", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/dfr.py#L317-L390
train
diging/tethne
tethne/readers/dfr.py
_handle_pagerange
def _handle_pagerange(pagerange): """ Yields start and end pages from DfR pagerange field. Parameters ---------- pagerange : str or unicode DfR-style pagerange, e.g. "pp. 435-444". Returns ------- start : str Start page. end : str End page. """ try:...
python
def _handle_pagerange(pagerange): """ Yields start and end pages from DfR pagerange field. Parameters ---------- pagerange : str or unicode DfR-style pagerange, e.g. "pp. 435-444". Returns ------- start : str Start page. end : str End page. """ try:...
[ "def", "_handle_pagerange", "(", "pagerange", ")", ":", "try", ":", "pr", "=", "re", ".", "compile", "(", "\"pp\\.\\s([0-9]+)\\-([0-9]+)\"", ")", "start", ",", "end", "=", "re", ".", "findall", "(", "pr", ",", "pagerange", ")", "[", "0", "]", "except", ...
Yields start and end pages from DfR pagerange field. Parameters ---------- pagerange : str or unicode DfR-style pagerange, e.g. "pp. 435-444". Returns ------- start : str Start page. end : str End page.
[ "Yields", "start", "and", "end", "pages", "from", "DfR", "pagerange", "field", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/dfr.py#L430-L453
train
diging/tethne
tethne/readers/dfr.py
_handle_authors
def _handle_authors(authors): """ Yields aulast and auinit lists from value of authors node. Parameters ---------- authors : list, str, or unicode Value or values of 'author' element in DfR XML. Returns ------- aulast : list A list of author surnames (string). auini...
python
def _handle_authors(authors): """ Yields aulast and auinit lists from value of authors node. Parameters ---------- authors : list, str, or unicode Value or values of 'author' element in DfR XML. Returns ------- aulast : list A list of author surnames (string). auini...
[ "def", "_handle_authors", "(", "authors", ")", ":", "aulast", "=", "[", "]", "auinit", "=", "[", "]", "if", "type", "(", "authors", ")", "is", "list", ":", "for", "author", "in", "authors", ":", "if", "type", "(", "author", ")", "is", "str", ":", ...
Yields aulast and auinit lists from value of authors node. Parameters ---------- authors : list, str, or unicode Value or values of 'author' element in DfR XML. Returns ------- aulast : list A list of author surnames (string). auinit : list A list of author first-in...
[ "Yields", "aulast", "and", "auinit", "lists", "from", "value", "of", "authors", "node", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/dfr.py#L462-L505
train
diging/tethne
tethne/readers/dfr.py
_handle_author
def _handle_author(author): """ Yields aulast and auinit from an author's full name. Parameters ---------- author : str or unicode Author fullname, e.g. "Richard L. Nixon". Returns ------- aulast : str Author surname. auinit : str Author first-initial. "...
python
def _handle_author(author): """ Yields aulast and auinit from an author's full name. Parameters ---------- author : str or unicode Author fullname, e.g. "Richard L. Nixon". Returns ------- aulast : str Author surname. auinit : str Author first-initial. "...
[ "def", "_handle_author", "(", "author", ")", ":", "lname", "=", "author", ".", "split", "(", "' '", ")", "try", ":", "auinit", "=", "lname", "[", "0", "]", "[", "0", "]", "final", "=", "lname", "[", "-", "1", "]", ".", "upper", "(", ")", "if", ...
Yields aulast and auinit from an author's full name. Parameters ---------- author : str or unicode Author fullname, e.g. "Richard L. Nixon". Returns ------- aulast : str Author surname. auinit : str Author first-initial.
[ "Yields", "aulast", "and", "auinit", "from", "an", "author", "s", "full", "name", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/dfr.py#L507-L536
train
diging/tethne
tethne/readers/dfr.py
GramGenerator._get
def _get(self, i): """ Retrieve data for the ith file in the dataset. """ with open(os.path.join(self.path, self.elem, self.files[i]), 'r') as f: # JSTOR hasn't always produced valid XML. contents = re.sub('(&)(?!amp;)', lambda match: '&amp;', f.read()) ...
python
def _get(self, i): """ Retrieve data for the ith file in the dataset. """ with open(os.path.join(self.path, self.elem, self.files[i]), 'r') as f: # JSTOR hasn't always produced valid XML. contents = re.sub('(&)(?!amp;)', lambda match: '&amp;', f.read()) ...
[ "def", "_get", "(", "self", ",", "i", ")", ":", "with", "open", "(", "os", ".", "path", ".", "join", "(", "self", ".", "path", ",", "self", ".", "elem", ",", "self", ".", "files", "[", "i", "]", ")", ",", "'r'", ")", "as", "f", ":", "# JSTO...
Retrieve data for the ith file in the dataset.
[ "Retrieve", "data", "for", "the", "ith", "file", "in", "the", "dataset", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/dfr.py#L175-L198
train
diging/tethne
tethne/model/corpus/mallet.py
LDAModel._generate_corpus
def _generate_corpus(self): """ Writes a corpus to disk amenable to MALLET topic modeling. """ target = self.temp + 'mallet' paths = write_documents(self.corpus, target, self.featureset_name, ['date', 'title']) self.corpus_path, self.metap...
python
def _generate_corpus(self): """ Writes a corpus to disk amenable to MALLET topic modeling. """ target = self.temp + 'mallet' paths = write_documents(self.corpus, target, self.featureset_name, ['date', 'title']) self.corpus_path, self.metap...
[ "def", "_generate_corpus", "(", "self", ")", ":", "target", "=", "self", ".", "temp", "+", "'mallet'", "paths", "=", "write_documents", "(", "self", ".", "corpus", ",", "target", ",", "self", ".", "featureset_name", ",", "[", "'date'", ",", "'title'", "]...
Writes a corpus to disk amenable to MALLET topic modeling.
[ "Writes", "a", "corpus", "to", "disk", "amenable", "to", "MALLET", "topic", "modeling", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/model/corpus/mallet.py#L151-L161
train
diging/tethne
tethne/model/corpus/mallet.py
LDAModel._export_corpus
def _export_corpus(self): """ Calls MALLET's `import-file` method. """ # bin/mallet import-file --input /Users/erickpeirson/mycorpus_docs.txt # --output mytopic-input.mallet --keep-sequence --remove-stopwords if not os.path.exists(self.mallet_bin): raise ...
python
def _export_corpus(self): """ Calls MALLET's `import-file` method. """ # bin/mallet import-file --input /Users/erickpeirson/mycorpus_docs.txt # --output mytopic-input.mallet --keep-sequence --remove-stopwords if not os.path.exists(self.mallet_bin): raise ...
[ "def", "_export_corpus", "(", "self", ")", ":", "# bin/mallet import-file --input /Users/erickpeirson/mycorpus_docs.txt", "# --output mytopic-input.mallet --keep-sequence --remove-stopwords", "if", "not", "os", ".", "path", ".", "exists", "(", "self", ".", "mallet_bin", ")"...
Calls MALLET's `import-file` method.
[ "Calls", "MALLET", "s", "import", "-", "file", "method", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/model/corpus/mallet.py#L163-L184
train
diging/tethne
tethne/model/corpus/mallet.py
LDAModel.run
def run(self, **kwargs): """ Calls MALLET's `train-topic` method. """ #$ bin/mallet train-topics --input mytopic-input.mallet #> --num-topics 100 #> --output-doc-topics /Users/erickpeirson/doc_top #> --word-topic-counts-file /Users/erickpeirson/word_top #>...
python
def run(self, **kwargs): """ Calls MALLET's `train-topic` method. """ #$ bin/mallet train-topics --input mytopic-input.mallet #> --num-topics 100 #> --output-doc-topics /Users/erickpeirson/doc_top #> --word-topic-counts-file /Users/erickpeirson/word_top #>...
[ "def", "run", "(", "self", ",", "*", "*", "kwargs", ")", ":", "#$ bin/mallet train-topics --input mytopic-input.mallet", "#> --num-topics 100", "#> --output-doc-topics /Users/erickpeirson/doc_top", "#> --word-topic-counts-file /Users/erickpeirson/word_top", "#> --output-topic-keys /Users...
Calls MALLET's `train-topic` method.
[ "Calls", "MALLET", "s", "train", "-", "topic", "method", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/model/corpus/mallet.py#L186-L241
train
diging/tethne
tethne/model/corpus/mallet.py
LDAModel.topics_in
def topics_in(self, d, topn=5): """ List the top ``topn`` topics in document ``d``. """ return self.theta.features[d].top(topn)
python
def topics_in(self, d, topn=5): """ List the top ``topn`` topics in document ``d``. """ return self.theta.features[d].top(topn)
[ "def", "topics_in", "(", "self", ",", "d", ",", "topn", "=", "5", ")", ":", "return", "self", ".", "theta", ".", "features", "[", "d", "]", ".", "top", "(", "topn", ")" ]
List the top ``topn`` topics in document ``d``.
[ "List", "the", "top", "topn", "topics", "in", "document", "d", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/model/corpus/mallet.py#L307-L311
train
diging/tethne
tethne/model/corpus/mallet.py
LDAModel.list_topic
def list_topic(self, k, Nwords=10): """ List the top ``topn`` words for topic ``k``. Examples -------- .. code-block:: python >>> model.list_topic(1, Nwords=5) [ 'opposed', 'terminates', 'trichinosis', 'cistus', 'acaule' ] """ return [(...
python
def list_topic(self, k, Nwords=10): """ List the top ``topn`` words for topic ``k``. Examples -------- .. code-block:: python >>> model.list_topic(1, Nwords=5) [ 'opposed', 'terminates', 'trichinosis', 'cistus', 'acaule' ] """ return [(...
[ "def", "list_topic", "(", "self", ",", "k", ",", "Nwords", "=", "10", ")", ":", "return", "[", "(", "self", ".", "vocabulary", "[", "w", "]", ",", "p", ")", "for", "w", ",", "p", "in", "self", ".", "phi", ".", "features", "[", "k", "]", ".", ...
List the top ``topn`` words for topic ``k``. Examples -------- .. code-block:: python >>> model.list_topic(1, Nwords=5) [ 'opposed', 'terminates', 'trichinosis', 'cistus', 'acaule' ]
[ "List", "the", "top", "topn", "words", "for", "topic", "k", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/model/corpus/mallet.py#L313-L329
train
diging/tethne
tethne/model/corpus/mallet.py
LDAModel.list_topics
def list_topics(self, Nwords=10): """ List the top ``Nwords`` words for each topic. """ return [(k, self.list_topic(k, Nwords)) for k in xrange(len(self.phi))]
python
def list_topics(self, Nwords=10): """ List the top ``Nwords`` words for each topic. """ return [(k, self.list_topic(k, Nwords)) for k in xrange(len(self.phi))]
[ "def", "list_topics", "(", "self", ",", "Nwords", "=", "10", ")", ":", "return", "[", "(", "k", ",", "self", ".", "list_topic", "(", "k", ",", "Nwords", ")", ")", "for", "k", "in", "xrange", "(", "len", "(", "self", ".", "phi", ")", ")", "]" ]
List the top ``Nwords`` words for each topic.
[ "List", "the", "top", "Nwords", "words", "for", "each", "topic", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/model/corpus/mallet.py#L331-L335
train
diging/tethne
tethne/model/corpus/mallet.py
LDAModel.print_topics
def print_topics(self, Nwords=10): """ Print the top ``Nwords`` words for each topic. """ print('Topic\tTop %i words' % Nwords) for k, words in self.list_topics(Nwords): print(unicode(k).ljust(3) + '\t' + ' '.join(list(zip(*words))[0]))
python
def print_topics(self, Nwords=10): """ Print the top ``Nwords`` words for each topic. """ print('Topic\tTop %i words' % Nwords) for k, words in self.list_topics(Nwords): print(unicode(k).ljust(3) + '\t' + ' '.join(list(zip(*words))[0]))
[ "def", "print_topics", "(", "self", ",", "Nwords", "=", "10", ")", ":", "print", "(", "'Topic\\tTop %i words'", "%", "Nwords", ")", "for", "k", ",", "words", "in", "self", ".", "list_topics", "(", "Nwords", ")", ":", "print", "(", "unicode", "(", "k", ...
Print the top ``Nwords`` words for each topic.
[ "Print", "the", "top", "Nwords", "words", "for", "each", "topic", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/model/corpus/mallet.py#L338-L344
train
diging/tethne
tethne/model/corpus/mallet.py
LDAModel.topic_over_time
def topic_over_time(self, k, mode='counts', slice_kwargs={}): """ Calculate the representation of topic ``k`` in the corpus over time. """ return self.corpus.feature_distribution('topics', k, mode=mode, **slice_kwargs)
python
def topic_over_time(self, k, mode='counts', slice_kwargs={}): """ Calculate the representation of topic ``k`` in the corpus over time. """ return self.corpus.feature_distribution('topics', k, mode=mode, **slice_kwargs)
[ "def", "topic_over_time", "(", "self", ",", "k", ",", "mode", "=", "'counts'", ",", "slice_kwargs", "=", "{", "}", ")", ":", "return", "self", ".", "corpus", ".", "feature_distribution", "(", "'topics'", ",", "k", ",", "mode", "=", "mode", ",", "*", ...
Calculate the representation of topic ``k`` in the corpus over time.
[ "Calculate", "the", "representation", "of", "topic", "k", "in", "the", "corpus", "over", "time", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/model/corpus/mallet.py#L347-L353
train
diging/tethne
tethne/classes/corpus.py
Corpus.distribution
def distribution(self, **slice_kwargs): """ Calculates the number of papers in each slice, as defined by ``slice_kwargs``. Examples -------- .. code-block:: python >>> corpus.distribution(step_size=1, window_size=1) [5, 5] Parameters ...
python
def distribution(self, **slice_kwargs): """ Calculates the number of papers in each slice, as defined by ``slice_kwargs``. Examples -------- .. code-block:: python >>> corpus.distribution(step_size=1, window_size=1) [5, 5] Parameters ...
[ "def", "distribution", "(", "self", ",", "*", "*", "slice_kwargs", ")", ":", "values", "=", "[", "]", "keys", "=", "[", "]", "for", "key", ",", "size", "in", "self", ".", "slice", "(", "count_only", "=", "True", ",", "*", "*", "slice_kwargs", ")", ...
Calculates the number of papers in each slice, as defined by ``slice_kwargs``. Examples -------- .. code-block:: python >>> corpus.distribution(step_size=1, window_size=1) [5, 5] Parameters ---------- slice_kwargs : kwargs Keyw...
[ "Calculates", "the", "number", "of", "papers", "in", "each", "slice", "as", "defined", "by", "slice_kwargs", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/classes/corpus.py#L595-L622
train
diging/tethne
tethne/classes/corpus.py
Corpus.feature_distribution
def feature_distribution(self, featureset_name, feature, mode='counts', **slice_kwargs): """ Calculates the distribution of a feature across slices of the corpus. Examples -------- .. code-block:: python >>> corpus.feature_distribution(fe...
python
def feature_distribution(self, featureset_name, feature, mode='counts', **slice_kwargs): """ Calculates the distribution of a feature across slices of the corpus. Examples -------- .. code-block:: python >>> corpus.feature_distribution(fe...
[ "def", "feature_distribution", "(", "self", ",", "featureset_name", ",", "feature", ",", "mode", "=", "'counts'", ",", "*", "*", "slice_kwargs", ")", ":", "values", "=", "[", "]", "keys", "=", "[", "]", "fset", "=", "self", ".", "features", "[", "featu...
Calculates the distribution of a feature across slices of the corpus. Examples -------- .. code-block:: python >>> corpus.feature_distribution(featureset_name='citations', \ ... feature='DOLE RJ 1965 CELL', \ ... ...
[ "Calculates", "the", "distribution", "of", "a", "feature", "across", "slices", "of", "the", "corpus", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/classes/corpus.py#L624-L685
train
diging/tethne
tethne/classes/corpus.py
Corpus.top_features
def top_features(self, featureset_name, topn=20, by='counts', perslice=False, slice_kwargs={}): """ Retrieves the top ``topn`` most numerous features in the corpus. Parameters ---------- featureset_name : str Name of a :class:`.FeatureSet` in the...
python
def top_features(self, featureset_name, topn=20, by='counts', perslice=False, slice_kwargs={}): """ Retrieves the top ``topn`` most numerous features in the corpus. Parameters ---------- featureset_name : str Name of a :class:`.FeatureSet` in the...
[ "def", "top_features", "(", "self", ",", "featureset_name", ",", "topn", "=", "20", ",", "by", "=", "'counts'", ",", "perslice", "=", "False", ",", "slice_kwargs", "=", "{", "}", ")", ":", "if", "perslice", ":", "return", "[", "(", "k", ",", "subcorp...
Retrieves the top ``topn`` most numerous features in the corpus. Parameters ---------- featureset_name : str Name of a :class:`.FeatureSet` in the :class:`.Corpus`\. topn : int (default: ``20``) Number of features to return. by : str (default:...
[ "Retrieves", "the", "top", "topn", "most", "numerous", "features", "in", "the", "corpus", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/classes/corpus.py#L687-L713
train
diging/tethne
tethne/analyze/corpus.py
feature_burstness
def feature_burstness(corpus, featureset_name, feature, k=5, normalize=True, s=1.1, gamma=1., **slice_kwargs): """ Estimate burstness profile for a feature over the ``'date'`` axis. Parameters ---------- corpus : :class:`.Corpus` feature : str Name of featureset in...
python
def feature_burstness(corpus, featureset_name, feature, k=5, normalize=True, s=1.1, gamma=1., **slice_kwargs): """ Estimate burstness profile for a feature over the ``'date'`` axis. Parameters ---------- corpus : :class:`.Corpus` feature : str Name of featureset in...
[ "def", "feature_burstness", "(", "corpus", ",", "featureset_name", ",", "feature", ",", "k", "=", "5", ",", "normalize", "=", "True", ",", "s", "=", "1.1", ",", "gamma", "=", "1.", ",", "*", "*", "slice_kwargs", ")", ":", "if", "featureset_name", "not"...
Estimate burstness profile for a feature over the ``'date'`` axis. Parameters ---------- corpus : :class:`.Corpus` feature : str Name of featureset in ``corpus``. E.g. ``'citations'``. findex : int Index of ``feature`` in ``corpus``. k : int (default: 5) Number of burst ...
[ "Estimate", "burstness", "profile", "for", "a", "feature", "over", "the", "date", "axis", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/analyze/corpus.py#L157-L224
train
diging/tethne
tethne/networks/papers.py
cocitation
def cocitation(corpus, min_weight=1, edge_attrs=['ayjid', 'date'], **kwargs): """ Generate a cocitation network. A **cocitation network** is a network in which vertices are papers, and edges indicate that two papers were cited by the same third paper. `CiteSpace <http://cluster.cis.drexel.edu/~...
python
def cocitation(corpus, min_weight=1, edge_attrs=['ayjid', 'date'], **kwargs): """ Generate a cocitation network. A **cocitation network** is a network in which vertices are papers, and edges indicate that two papers were cited by the same third paper. `CiteSpace <http://cluster.cis.drexel.edu/~...
[ "def", "cocitation", "(", "corpus", ",", "min_weight", "=", "1", ",", "edge_attrs", "=", "[", "'ayjid'", ",", "'date'", "]", ",", "*", "*", "kwargs", ")", ":", "return", "cooccurrence", "(", "corpus", ",", "'citations'", ",", "min_weight", "=", "min_weig...
Generate a cocitation network. A **cocitation network** is a network in which vertices are papers, and edges indicate that two papers were cited by the same third paper. `CiteSpace <http://cluster.cis.drexel.edu/~cchen/citespace/doc/jasist2006.pdf>`_ is a popular desktop application for co-citation...
[ "Generate", "a", "cocitation", "network", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/networks/papers.py#L43-L56
train
diging/tethne
tethne/classes/feature.py
StructuredFeature.context_chunk
def context_chunk(self, context, j): """ Retrieve the tokens in the ``j``th chunk of context ``context``. Parameters ---------- context : str Context name. j : int Index of a context chunk. Returns ------- chunk : list ...
python
def context_chunk(self, context, j): """ Retrieve the tokens in the ``j``th chunk of context ``context``. Parameters ---------- context : str Context name. j : int Index of a context chunk. Returns ------- chunk : list ...
[ "def", "context_chunk", "(", "self", ",", "context", ",", "j", ")", ":", "N_chunks", "=", "len", "(", "self", ".", "contexts", "[", "context", "]", ")", "start", "=", "self", ".", "contexts", "[", "context", "]", "[", "j", "]", "if", "j", "==", "...
Retrieve the tokens in the ``j``th chunk of context ``context``. Parameters ---------- context : str Context name. j : int Index of a context chunk. Returns ------- chunk : list List of tokens in the selected chunk.
[ "Retrieve", "the", "tokens", "in", "the", "j", "th", "chunk", "of", "context", "context", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/classes/feature.py#L108-L131
train
diging/tethne
tethne/classes/feature.py
StructuredFeature.add_context
def add_context(self, name, indices, level=None): """ Add a new context level to the hierarchy. By default, new contexts are added to the lowest level of the hierarchy. To insert the context elsewhere in the hierarchy, use the ``level`` argument. For example, ``level=0`` would i...
python
def add_context(self, name, indices, level=None): """ Add a new context level to the hierarchy. By default, new contexts are added to the lowest level of the hierarchy. To insert the context elsewhere in the hierarchy, use the ``level`` argument. For example, ``level=0`` would i...
[ "def", "add_context", "(", "self", ",", "name", ",", "indices", ",", "level", "=", "None", ")", ":", "self", ".", "_validate_context", "(", "(", "name", ",", "indices", ")", ")", "if", "level", "is", "None", ":", "level", "=", "len", "(", "self", "...
Add a new context level to the hierarchy. By default, new contexts are added to the lowest level of the hierarchy. To insert the context elsewhere in the hierarchy, use the ``level`` argument. For example, ``level=0`` would insert the context at the highest level of the hierarchy. ...
[ "Add", "a", "new", "context", "level", "to", "the", "hierarchy", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/classes/feature.py#L170-L195
train
diging/tethne
tethne/classes/graphcollection.py
GraphCollection.index
def index(self, name, graph): """ Index any new nodes in `graph`, and relabel the nodes in `graph` using the index. Parameters ---------- name : hashable Unique name used to identify the `graph`. graph : networkx.Graph Returns -------...
python
def index(self, name, graph): """ Index any new nodes in `graph`, and relabel the nodes in `graph` using the index. Parameters ---------- name : hashable Unique name used to identify the `graph`. graph : networkx.Graph Returns -------...
[ "def", "index", "(", "self", ",", "name", ",", "graph", ")", ":", "nodes", "=", "graph", ".", "nodes", "(", ")", "# Index new nodes.", "new_nodes", "=", "list", "(", "set", "(", "nodes", ")", "-", "set", "(", "self", ".", "node_index", ".", "values",...
Index any new nodes in `graph`, and relabel the nodes in `graph` using the index. Parameters ---------- name : hashable Unique name used to identify the `graph`. graph : networkx.Graph Returns ------- indexed_graph : networkx.Graph
[ "Index", "any", "new", "nodes", "in", "graph", "and", "relabel", "the", "nodes", "in", "graph", "using", "the", "index", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/classes/graphcollection.py#L159-L188
train
diging/tethne
tethne/networks/topics.py
terms
def terms(model, threshold=0.01, **kwargs): """ Two terms are coupled if the posterior probability for both terms is greather than ``threshold`` for the same topic. Parameters ---------- model : :class:`.LDAModel` threshold : float Default: 0.01 kwargs : kwargs Passed on...
python
def terms(model, threshold=0.01, **kwargs): """ Two terms are coupled if the posterior probability for both terms is greather than ``threshold`` for the same topic. Parameters ---------- model : :class:`.LDAModel` threshold : float Default: 0.01 kwargs : kwargs Passed on...
[ "def", "terms", "(", "model", ",", "threshold", "=", "0.01", ",", "*", "*", "kwargs", ")", ":", "select", "=", "lambda", "f", ",", "v", ",", "c", ",", "dc", ":", "v", ">", "threshold", "graph", "=", "cooccurrence", "(", "model", ".", "phi", ",", ...
Two terms are coupled if the posterior probability for both terms is greather than ``threshold`` for the same topic. Parameters ---------- model : :class:`.LDAModel` threshold : float Default: 0.01 kwargs : kwargs Passed on to :func:`.cooccurrence`\. Returns ------- ...
[ "Two", "terms", "are", "coupled", "if", "the", "posterior", "probability", "for", "both", "terms", "is", "greather", "than", "threshold", "for", "the", "same", "topic", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/networks/topics.py#L24-L50
train
diging/tethne
tethne/networks/topics.py
topic_coupling
def topic_coupling(model, threshold=None, **kwargs): """ Two papers are coupled if they both contain a shared topic above a ``threshold``. Parameters ---------- model : :class:`.LDAModel` threshold : float Default: ``3./model.Z`` kwargs : kwargs Passed on to :func:`.coup...
python
def topic_coupling(model, threshold=None, **kwargs): """ Two papers are coupled if they both contain a shared topic above a ``threshold``. Parameters ---------- model : :class:`.LDAModel` threshold : float Default: ``3./model.Z`` kwargs : kwargs Passed on to :func:`.coup...
[ "def", "topic_coupling", "(", "model", ",", "threshold", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "not", "threshold", ":", "threshold", "=", "3.", "/", "model", ".", "Z", "select", "=", "lambda", "f", ",", "v", ",", "c", ",", "dc", "...
Two papers are coupled if they both contain a shared topic above a ``threshold``. Parameters ---------- model : :class:`.LDAModel` threshold : float Default: ``3./model.Z`` kwargs : kwargs Passed on to :func:`.coupling`\. Returns ------- :ref:`networkx.Graph <networ...
[ "Two", "papers", "are", "coupled", "if", "they", "both", "contain", "a", "shared", "topic", "above", "a", "threshold", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/networks/topics.py#L53-L77
train
diging/tethne
tethne/analyze/features.py
kl_divergence
def kl_divergence(V_a, V_b): """ Calculate Kullback-Leibler distance. Uses the smoothing method described in `Bigi 2003 <http://lvk.cs.msu.su/~bruzz/articles/classification/Using%20Kullback-Leibler%20Distance%20for%20Text%20Categorization.pdf>`_ to facilitate better comparisons between vectors desc...
python
def kl_divergence(V_a, V_b): """ Calculate Kullback-Leibler distance. Uses the smoothing method described in `Bigi 2003 <http://lvk.cs.msu.su/~bruzz/articles/classification/Using%20Kullback-Leibler%20Distance%20for%20Text%20Categorization.pdf>`_ to facilitate better comparisons between vectors desc...
[ "def", "kl_divergence", "(", "V_a", ",", "V_b", ")", ":", "# Find shared features.", "Ndiff", "=", "_shared_features", "(", "V_a", ",", "V_b", ")", "# aprob and bprob should each sum to 1.0", "aprob", "=", "map", "(", "lambda", "v", ":", "float", "(", "v", ")"...
Calculate Kullback-Leibler distance. Uses the smoothing method described in `Bigi 2003 <http://lvk.cs.msu.su/~bruzz/articles/classification/Using%20Kullback-Leibler%20Distance%20for%20Text%20Categorization.pdf>`_ to facilitate better comparisons between vectors describing wordcounts. Parameters --...
[ "Calculate", "Kullback", "-", "Leibler", "distance", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/analyze/features.py#L18-L47
train
diging/tethne
tethne/analyze/features.py
_shared_features
def _shared_features(adense, bdense): """ Number of features in ``adense`` that are also in ``bdense``. """ a_indices = set(nonzero(adense)) b_indices = set(nonzero(bdense)) shared = list(a_indices & b_indices) diff = list(a_indices - b_indices) Ndiff = len(diff) return Ndiff
python
def _shared_features(adense, bdense): """ Number of features in ``adense`` that are also in ``bdense``. """ a_indices = set(nonzero(adense)) b_indices = set(nonzero(bdense)) shared = list(a_indices & b_indices) diff = list(a_indices - b_indices) Ndiff = len(diff) return Ndiff
[ "def", "_shared_features", "(", "adense", ",", "bdense", ")", ":", "a_indices", "=", "set", "(", "nonzero", "(", "adense", ")", ")", "b_indices", "=", "set", "(", "nonzero", "(", "bdense", ")", ")", "shared", "=", "list", "(", "a_indices", "&", "b_indi...
Number of features in ``adense`` that are also in ``bdense``.
[ "Number", "of", "features", "in", "adense", "that", "are", "also", "in", "bdense", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/analyze/features.py#L100-L111
train
diging/tethne
tethne/networks/base.py
cooccurrence
def cooccurrence(corpus_or_featureset, featureset_name=None, min_weight=1, edge_attrs=['ayjid', 'date'], filter=None): """ A network of feature elements linked by their joint occurrence in papers. """ if not filter: filter = lambda f, v, c, dc: dc >= min_weight...
python
def cooccurrence(corpus_or_featureset, featureset_name=None, min_weight=1, edge_attrs=['ayjid', 'date'], filter=None): """ A network of feature elements linked by their joint occurrence in papers. """ if not filter: filter = lambda f, v, c, dc: dc >= min_weight...
[ "def", "cooccurrence", "(", "corpus_or_featureset", ",", "featureset_name", "=", "None", ",", "min_weight", "=", "1", ",", "edge_attrs", "=", "[", "'ayjid'", ",", "'date'", "]", ",", "filter", "=", "None", ")", ":", "if", "not", "filter", ":", "filter", ...
A network of feature elements linked by their joint occurrence in papers.
[ "A", "network", "of", "feature", "elements", "linked", "by", "their", "joint", "occurrence", "in", "papers", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/networks/base.py#L39-L93
train
diging/tethne
tethne/networks/base.py
coupling
def coupling(corpus_or_featureset, featureset_name=None, min_weight=1, filter=lambda f, v, c, dc: True, node_attrs=[]): """ A network of papers linked by their joint posession of features. """ featureset = _get_featureset(corpus_or_featureset, featureset_name) c = lambda ...
python
def coupling(corpus_or_featureset, featureset_name=None, min_weight=1, filter=lambda f, v, c, dc: True, node_attrs=[]): """ A network of papers linked by their joint posession of features. """ featureset = _get_featureset(corpus_or_featureset, featureset_name) c = lambda ...
[ "def", "coupling", "(", "corpus_or_featureset", ",", "featureset_name", "=", "None", ",", "min_weight", "=", "1", ",", "filter", "=", "lambda", "f", ",", "v", ",", "c", ",", "dc", ":", "True", ",", "node_attrs", "=", "[", "]", ")", ":", "featureset", ...
A network of papers linked by their joint posession of features.
[ "A", "network", "of", "papers", "linked", "by", "their", "joint", "posession", "of", "features", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/networks/base.py#L97-L140
train
diging/tethne
tethne/networks/base.py
multipartite
def multipartite(corpus, featureset_names, min_weight=1, filters={}): """ A network of papers and one or more featuresets. """ pairs = Counter() node_type = {corpus._generate_index(p): {'type': 'paper'} for p in corpus.papers} for featureset_name in featureset_names: ft...
python
def multipartite(corpus, featureset_names, min_weight=1, filters={}): """ A network of papers and one or more featuresets. """ pairs = Counter() node_type = {corpus._generate_index(p): {'type': 'paper'} for p in corpus.papers} for featureset_name in featureset_names: ft...
[ "def", "multipartite", "(", "corpus", ",", "featureset_names", ",", "min_weight", "=", "1", ",", "filters", "=", "{", "}", ")", ":", "pairs", "=", "Counter", "(", ")", "node_type", "=", "{", "corpus", ".", "_generate_index", "(", "p", ")", ":", "{", ...
A network of papers and one or more featuresets.
[ "A", "network", "of", "papers", "and", "one", "or", "more", "featuresets", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/networks/base.py#L143-L167
train
diging/tethne
tethne/utilities.py
_strip_punctuation
def _strip_punctuation(s): """ Removes all punctuation characters from a string. """ if type(s) is str and not PYTHON_3: # Bytestring (default in Python 2.x). return s.translate(string.maketrans("",""), string.punctuation) else: # Unicode string (default in Python 3.x). ...
python
def _strip_punctuation(s): """ Removes all punctuation characters from a string. """ if type(s) is str and not PYTHON_3: # Bytestring (default in Python 2.x). return s.translate(string.maketrans("",""), string.punctuation) else: # Unicode string (default in Python 3.x). ...
[ "def", "_strip_punctuation", "(", "s", ")", ":", "if", "type", "(", "s", ")", "is", "str", "and", "not", "PYTHON_3", ":", "# Bytestring (default in Python 2.x).", "return", "s", ".", "translate", "(", "string", ".", "maketrans", "(", "\"\"", ",", "\"\"", "...
Removes all punctuation characters from a string.
[ "Removes", "all", "punctuation", "characters", "from", "a", "string", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/utilities.py#L115-L123
train
diging/tethne
tethne/utilities.py
overlap
def overlap(listA, listB): """ Return list of objects shared by listA, listB. """ if (listA is None) or (listB is None): return [] else: return list(set(listA) & set(listB))
python
def overlap(listA, listB): """ Return list of objects shared by listA, listB. """ if (listA is None) or (listB is None): return [] else: return list(set(listA) & set(listB))
[ "def", "overlap", "(", "listA", ",", "listB", ")", ":", "if", "(", "listA", "is", "None", ")", "or", "(", "listB", "is", "None", ")", ":", "return", "[", "]", "else", ":", "return", "list", "(", "set", "(", "listA", ")", "&", "set", "(", "listB...
Return list of objects shared by listA, listB.
[ "Return", "list", "of", "objects", "shared", "by", "listA", "listB", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/utilities.py#L174-L181
train
diging/tethne
tethne/utilities.py
subdict
def subdict(super_dict, keys): """ Returns a subset of the super_dict with the specified keys. """ sub_dict = {} valid_keys = super_dict.keys() for key in keys: if key in valid_keys: sub_dict[key] = super_dict[key] return sub_dict
python
def subdict(super_dict, keys): """ Returns a subset of the super_dict with the specified keys. """ sub_dict = {} valid_keys = super_dict.keys() for key in keys: if key in valid_keys: sub_dict[key] = super_dict[key] return sub_dict
[ "def", "subdict", "(", "super_dict", ",", "keys", ")", ":", "sub_dict", "=", "{", "}", "valid_keys", "=", "super_dict", ".", "keys", "(", ")", "for", "key", "in", "keys", ":", "if", "key", "in", "valid_keys", ":", "sub_dict", "[", "key", "]", "=", ...
Returns a subset of the super_dict with the specified keys.
[ "Returns", "a", "subset", "of", "the", "super_dict", "with", "the", "specified", "keys", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/utilities.py#L184-L194
train
diging/tethne
tethne/utilities.py
concat_list
def concat_list(listA, listB, delim=' '): """ Concatenate list elements pair-wise with the delim character Returns the concatenated list Raises index error if lists are not parallel """ # Lists must be of equal length. if len(listA) != len(listB): raise IndexError('Input lists are n...
python
def concat_list(listA, listB, delim=' '): """ Concatenate list elements pair-wise with the delim character Returns the concatenated list Raises index error if lists are not parallel """ # Lists must be of equal length. if len(listA) != len(listB): raise IndexError('Input lists are n...
[ "def", "concat_list", "(", "listA", ",", "listB", ",", "delim", "=", "' '", ")", ":", "# Lists must be of equal length.", "if", "len", "(", "listA", ")", "!=", "len", "(", "listB", ")", ":", "raise", "IndexError", "(", "'Input lists are not parallel.'", ")", ...
Concatenate list elements pair-wise with the delim character Returns the concatenated list Raises index error if lists are not parallel
[ "Concatenate", "list", "elements", "pair", "-", "wise", "with", "the", "delim", "character", "Returns", "the", "concatenated", "list", "Raises", "index", "error", "if", "lists", "are", "not", "parallel" ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/utilities.py#L212-L229
train
diging/tethne
tethne/utilities.py
strip_non_ascii
def strip_non_ascii(s): """ Returns the string without non-ASCII characters. Parameters ---------- string : string A string that may contain non-ASCII characters. Returns ------- clean_string : string A string that does not contain non-ASCII characters. """ str...
python
def strip_non_ascii(s): """ Returns the string without non-ASCII characters. Parameters ---------- string : string A string that may contain non-ASCII characters. Returns ------- clean_string : string A string that does not contain non-ASCII characters. """ str...
[ "def", "strip_non_ascii", "(", "s", ")", ":", "stripped", "=", "(", "c", "for", "c", "in", "s", "if", "0", "<", "ord", "(", "c", ")", "<", "127", ")", "clean_string", "=", "u''", ".", "join", "(", "stripped", ")", "return", "clean_string" ]
Returns the string without non-ASCII characters. Parameters ---------- string : string A string that may contain non-ASCII characters. Returns ------- clean_string : string A string that does not contain non-ASCII characters.
[ "Returns", "the", "string", "without", "non", "-", "ASCII", "characters", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/utilities.py#L231-L248
train
diging/tethne
tethne/utilities.py
dict_from_node
def dict_from_node(node, recursive=False): """ Converts ElementTree node to a dictionary. Parameters ---------- node : ElementTree node recursive : boolean If recursive=False, the value of any field with children will be the number of children. Returns ------- dict ...
python
def dict_from_node(node, recursive=False): """ Converts ElementTree node to a dictionary. Parameters ---------- node : ElementTree node recursive : boolean If recursive=False, the value of any field with children will be the number of children. Returns ------- dict ...
[ "def", "dict_from_node", "(", "node", ",", "recursive", "=", "False", ")", ":", "dict", "=", "{", "}", "for", "snode", "in", "node", ":", "if", "len", "(", "snode", ")", ">", "0", ":", "if", "recursive", ":", "# Will drill down until len(snode) <= 0.", "...
Converts ElementTree node to a dictionary. Parameters ---------- node : ElementTree node recursive : boolean If recursive=False, the value of any field with children will be the number of children. Returns ------- dict : nested dictionary. Tags as keys and values as...
[ "Converts", "ElementTree", "node", "to", "a", "dictionary", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/utilities.py#L255-L298
train
diging/tethne
tethne/utilities.py
MLStripper.feed
def feed(self, data): """ added this check as sometimes we are getting the data in integer format instead of string """ try: self.rawdata = self.rawdata + data except TypeError: data = unicode(data) self.rawdata = self.rawdata + data s...
python
def feed(self, data): """ added this check as sometimes we are getting the data in integer format instead of string """ try: self.rawdata = self.rawdata + data except TypeError: data = unicode(data) self.rawdata = self.rawdata + data s...
[ "def", "feed", "(", "self", ",", "data", ")", ":", "try", ":", "self", ".", "rawdata", "=", "self", ".", "rawdata", "+", "data", "except", "TypeError", ":", "data", "=", "unicode", "(", "data", ")", "self", ".", "rawdata", "=", "self", ".", "rawdat...
added this check as sometimes we are getting the data in integer format instead of string
[ "added", "this", "check", "as", "sometimes", "we", "are", "getting", "the", "data", "in", "integer", "format", "instead", "of", "string" ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/utilities.py#L50-L60
train
diging/tethne
tethne/serialize/paper.py
Serialize.serializePaper
def serializePaper(self): """ This method creates a fixture for the "django-tethne_paper" model. Returns ------- paper_details in JSON format, which can written to a file. """ pid = tethnedao.getMaxPaperID(); papers_details = [] for paper in sel...
python
def serializePaper(self): """ This method creates a fixture for the "django-tethne_paper" model. Returns ------- paper_details in JSON format, which can written to a file. """ pid = tethnedao.getMaxPaperID(); papers_details = [] for paper in sel...
[ "def", "serializePaper", "(", "self", ")", ":", "pid", "=", "tethnedao", ".", "getMaxPaperID", "(", ")", "papers_details", "=", "[", "]", "for", "paper", "in", "self", ".", "corpus", ":", "pid", "=", "pid", "+", "1", "paper_key", "=", "getattr", "(", ...
This method creates a fixture for the "django-tethne_paper" model. Returns ------- paper_details in JSON format, which can written to a file.
[ "This", "method", "creates", "a", "fixture", "for", "the", "django", "-", "tethne_paper", "model", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/serialize/paper.py#L108-L137
train
diging/tethne
tethne/serialize/paper.py
Serialize.serializeCitation
def serializeCitation(self): """ This method creates a fixture for the "django-tethne_citation" model. Returns ------- citation details which can be written to a file """ citation_details = [] citation_id = tethnedao.getMaxCitationID() for citati...
python
def serializeCitation(self): """ This method creates a fixture for the "django-tethne_citation" model. Returns ------- citation details which can be written to a file """ citation_details = [] citation_id = tethnedao.getMaxCitationID() for citati...
[ "def", "serializeCitation", "(", "self", ")", ":", "citation_details", "=", "[", "]", "citation_id", "=", "tethnedao", ".", "getMaxCitationID", "(", ")", "for", "citation", "in", "self", ".", "corpus", ".", "features", "[", "'citations'", "]", ".", "index", ...
This method creates a fixture for the "django-tethne_citation" model. Returns ------- citation details which can be written to a file
[ "This", "method", "creates", "a", "fixture", "for", "the", "django", "-", "tethne_citation", "model", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/serialize/paper.py#L210-L246
train
diging/tethne
tethne/serialize/paper.py
Serialize.serializeInstitution
def serializeInstitution(self): """ This method creates a fixture for the "django-tethne_citation_institution" model. Returns ------- institution details which can be written to a file """ institution_data = [] institution_instance_data = [] affi...
python
def serializeInstitution(self): """ This method creates a fixture for the "django-tethne_citation_institution" model. Returns ------- institution details which can be written to a file """ institution_data = [] institution_instance_data = [] affi...
[ "def", "serializeInstitution", "(", "self", ")", ":", "institution_data", "=", "[", "]", "institution_instance_data", "=", "[", "]", "affiliation_data", "=", "[", "]", "affiliation_id", "=", "tethnedao", ".", "getMaxAffiliationID", "(", ")", "institution_id", "=",...
This method creates a fixture for the "django-tethne_citation_institution" model. Returns ------- institution details which can be written to a file
[ "This", "method", "creates", "a", "fixture", "for", "the", "django", "-", "tethne_citation_institution", "model", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/serialize/paper.py#L289-L344
train
diging/tethne
tethne/serialize/paper.py
Serialize.get_details_from_inst_literal
def get_details_from_inst_literal(self, institute_literal, institution_id, institution_instance_id, paper_key): """ This method parses the institute literal to get the following 1. Department naame 2. Country 3. University name 4. ZIP, STATE AND CITY (Only if the country ...
python
def get_details_from_inst_literal(self, institute_literal, institution_id, institution_instance_id, paper_key): """ This method parses the institute literal to get the following 1. Department naame 2. Country 3. University name 4. ZIP, STATE AND CITY (Only if the country ...
[ "def", "get_details_from_inst_literal", "(", "self", ",", "institute_literal", ",", "institution_id", ",", "institution_instance_id", ",", "paper_key", ")", ":", "institute_details", "=", "institute_literal", ".", "split", "(", "','", ")", "institute_name", "=", "inst...
This method parses the institute literal to get the following 1. Department naame 2. Country 3. University name 4. ZIP, STATE AND CITY (Only if the country is USA. For other countries the standard may vary. So parsing these values becomes very difficult. However, the complete add...
[ "This", "method", "parses", "the", "institute", "literal", "to", "get", "the", "following", "1", ".", "Department", "naame", "2", ".", "Country", "3", ".", "University", "name", "4", ".", "ZIP", "STATE", "AND", "CITY", "(", "Only", "if", "the", "country"...
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/serialize/paper.py#L346-L424
train
diging/tethne
tethne/serialize/paper.py
Serialize.get_affiliation_details
def get_affiliation_details(self, value, affiliation_id, institute_literal): """ This method is used to map the Affiliation between an author and Institution. Parameters ---------- value - The author name affiliation_id - Primary key of the affiliation table inst...
python
def get_affiliation_details(self, value, affiliation_id, institute_literal): """ This method is used to map the Affiliation between an author and Institution. Parameters ---------- value - The author name affiliation_id - Primary key of the affiliation table inst...
[ "def", "get_affiliation_details", "(", "self", ",", "value", ",", "affiliation_id", ",", "institute_literal", ")", ":", "tokens", "=", "tuple", "(", "[", "t", ".", "upper", "(", ")", ".", "strip", "(", ")", "for", "t", "in", "value", ".", "split", "(",...
This method is used to map the Affiliation between an author and Institution. Parameters ---------- value - The author name affiliation_id - Primary key of the affiliation table institute_literal Returns ------- Affiliation details(JSON fixture) which ca...
[ "This", "method", "is", "used", "to", "map", "the", "Affiliation", "between", "an", "author", "and", "Institution", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/serialize/paper.py#L426-L464
train
diging/tethne
tethne/readers/base.py
IterParser.start
def start(self): """ Find the first data entry and prepare to parse. """ while not self.is_start(self.current_tag): self.next() self.new_entry()
python
def start(self): """ Find the first data entry and prepare to parse. """ while not self.is_start(self.current_tag): self.next() self.new_entry()
[ "def", "start", "(", "self", ")", ":", "while", "not", "self", ".", "is_start", "(", "self", ".", "current_tag", ")", ":", "self", ".", "next", "(", ")", "self", ".", "new_entry", "(", ")" ]
Find the first data entry and prepare to parse.
[ "Find", "the", "first", "data", "entry", "and", "prepare", "to", "parse", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/base.py#L129-L136
train
diging/tethne
tethne/readers/base.py
IterParser.handle
def handle(self, tag, data): """ Process a single line of data, and store the result. Parameters ---------- tag : str data : """ if self.is_end(tag): self.postprocess_entry() if self.is_start(tag): self.new_entry() ...
python
def handle(self, tag, data): """ Process a single line of data, and store the result. Parameters ---------- tag : str data : """ if self.is_end(tag): self.postprocess_entry() if self.is_start(tag): self.new_entry() ...
[ "def", "handle", "(", "self", ",", "tag", ",", "data", ")", ":", "if", "self", ".", "is_end", "(", "tag", ")", ":", "self", ".", "postprocess_entry", "(", ")", "if", "self", ".", "is_start", "(", "tag", ")", ":", "self", ".", "new_entry", "(", ")...
Process a single line of data, and store the result. Parameters ---------- tag : str data :
[ "Process", "a", "single", "line", "of", "data", "and", "store", "the", "result", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/base.py#L138-L183
train
diging/tethne
tethne/readers/base.py
FTParser.open
def open(self): """ Open the data file. """ if not os.path.exists(self.path): raise IOError("No such path: {0}".format(self.path)) with open(self.path, "rb") as f: msg = f.read() result = chardet.detect(msg) self.buffer = codecs.open(se...
python
def open(self): """ Open the data file. """ if not os.path.exists(self.path): raise IOError("No such path: {0}".format(self.path)) with open(self.path, "rb") as f: msg = f.read() result = chardet.detect(msg) self.buffer = codecs.open(se...
[ "def", "open", "(", "self", ")", ":", "if", "not", "os", ".", "path", ".", "exists", "(", "self", ".", "path", ")", ":", "raise", "IOError", "(", "\"No such path: {0}\"", ".", "format", "(", "self", ".", "path", ")", ")", "with", "open", "(", "self...
Open the data file.
[ "Open", "the", "data", "file", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/base.py#L206-L221
train
diging/tethne
tethne/readers/base.py
FTParser.next
def next(self): """ Get the next line of data. Returns ------- tag : str data : """ line = self.buffer.readline() while line == '\n': # Skip forward to the next line with content. line = self.buffer.readline() if line =...
python
def next(self): """ Get the next line of data. Returns ------- tag : str data : """ line = self.buffer.readline() while line == '\n': # Skip forward to the next line with content. line = self.buffer.readline() if line =...
[ "def", "next", "(", "self", ")", ":", "line", "=", "self", ".", "buffer", ".", "readline", "(", ")", "while", "line", "==", "'\\n'", ":", "# Skip forward to the next line with content.", "line", "=", "self", ".", "buffer", ".", "readline", "(", ")", "if", ...
Get the next line of data. Returns ------- tag : str data :
[ "Get", "the", "next", "line", "of", "data", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/base.py#L223-L247
train
diging/tethne
tethne/networks/authors.py
coauthors
def coauthors(corpus, min_weight=1, edge_attrs=['ayjid', 'date'], **kwargs): """ A graph describing joint authorship in ``corpus``. """ return cooccurrence(corpus, 'authors', min_weight=min_weight, edge_attrs=edge_attrs, **kwargs)
python
def coauthors(corpus, min_weight=1, edge_attrs=['ayjid', 'date'], **kwargs): """ A graph describing joint authorship in ``corpus``. """ return cooccurrence(corpus, 'authors', min_weight=min_weight, edge_attrs=edge_attrs, **kwargs)
[ "def", "coauthors", "(", "corpus", ",", "min_weight", "=", "1", ",", "edge_attrs", "=", "[", "'ayjid'", ",", "'date'", "]", ",", "*", "*", "kwargs", ")", ":", "return", "cooccurrence", "(", "corpus", ",", "'authors'", ",", "min_weight", "=", "min_weight"...
A graph describing joint authorship in ``corpus``.
[ "A", "graph", "describing", "joint", "authorship", "in", "corpus", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/networks/authors.py#L22-L27
train
diging/tethne
tethne/readers/zotero.py
extract_text
def extract_text(fpath): """ Extracts structured text content from a plain-text file at ``fpath``. Parameters ---------- fpath : str Path to the text file.. Returns ------- :class:`.StructuredFeature` A :class:`.StructuredFeature` that contains sentence context. """...
python
def extract_text(fpath): """ Extracts structured text content from a plain-text file at ``fpath``. Parameters ---------- fpath : str Path to the text file.. Returns ------- :class:`.StructuredFeature` A :class:`.StructuredFeature` that contains sentence context. """...
[ "def", "extract_text", "(", "fpath", ")", ":", "with", "codecs", ".", "open", "(", "fpath", ",", "'r'", ")", "as", "f", ":", "# Determine the encoding of the file.", "document", "=", "f", ".", "read", "(", ")", "encoding", "=", "chardet", ".", "detect", ...
Extracts structured text content from a plain-text file at ``fpath``. Parameters ---------- fpath : str Path to the text file.. Returns ------- :class:`.StructuredFeature` A :class:`.StructuredFeature` that contains sentence context.
[ "Extracts", "structured", "text", "content", "from", "a", "plain", "-", "text", "file", "at", "fpath", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/zotero.py#L86-L117
train
diging/tethne
tethne/readers/zotero.py
extract_pdf
def extract_pdf(fpath): """ Extracts structured text content from a PDF at ``fpath``. Parameters ---------- fpath : str Path to the PDF. Returns ------- :class:`.StructuredFeature` A :class:`.StructuredFeature` that contains page and sentence contexts. """ with...
python
def extract_pdf(fpath): """ Extracts structured text content from a PDF at ``fpath``. Parameters ---------- fpath : str Path to the PDF. Returns ------- :class:`.StructuredFeature` A :class:`.StructuredFeature` that contains page and sentence contexts. """ with...
[ "def", "extract_pdf", "(", "fpath", ")", ":", "with", "codecs", ".", "open", "(", "fpath", ",", "'r'", ")", "as", "f", ":", "# Determine the encoding of the file.", "document", "=", "slate", ".", "PDF", "(", "f", ")", "encoding", "=", "chardet", ".", "de...
Extracts structured text content from a PDF at ``fpath``. Parameters ---------- fpath : str Path to the PDF. Returns ------- :class:`.StructuredFeature` A :class:`.StructuredFeature` that contains page and sentence contexts.
[ "Extracts", "structured", "text", "content", "from", "a", "PDF", "at", "fpath", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/zotero.py#L120-L167
train
diging/tethne
tethne/readers/zotero.py
read
def read(path, corpus=True, index_by='uri', follow_links=False, **kwargs): """ Read bibliographic data from Zotero RDF. Examples -------- Assuming that the Zotero collection was exported to the directory ``/my/working/dir`` with the name ``myCollection``, a subdirectory should have been cre...
python
def read(path, corpus=True, index_by='uri', follow_links=False, **kwargs): """ Read bibliographic data from Zotero RDF. Examples -------- Assuming that the Zotero collection was exported to the directory ``/my/working/dir`` with the name ``myCollection``, a subdirectory should have been cre...
[ "def", "read", "(", "path", ",", "corpus", "=", "True", ",", "index_by", "=", "'uri'", ",", "follow_links", "=", "False", ",", "*", "*", "kwargs", ")", ":", "# TODO: is there a case where `from_dir` would make sense?", "parser", "=", "ZoteroParser", "(", "path",...
Read bibliographic data from Zotero RDF. Examples -------- Assuming that the Zotero collection was exported to the directory ``/my/working/dir`` with the name ``myCollection``, a subdirectory should have been created at ``/my/working/dir/myCollection``, and an RDF file should exist at ``/my/wor...
[ "Read", "bibliographic", "data", "from", "Zotero", "RDF", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/zotero.py#L391-L446
train
diging/tethne
tethne/readers/zotero.py
ZoteroParser.handle_date
def handle_date(self, value): """ Attempt to coerced date to ISO8601. """ try: return iso8601.parse_date(unicode(value)).year except iso8601.ParseError: for datefmt in ("%B %d, %Y", "%Y-%m", "%Y-%m-%d", "%m/%d/%Y"): try: ...
python
def handle_date(self, value): """ Attempt to coerced date to ISO8601. """ try: return iso8601.parse_date(unicode(value)).year except iso8601.ParseError: for datefmt in ("%B %d, %Y", "%Y-%m", "%Y-%m-%d", "%m/%d/%Y"): try: ...
[ "def", "handle_date", "(", "self", ",", "value", ")", ":", "try", ":", "return", "iso8601", ".", "parse_date", "(", "unicode", "(", "value", ")", ")", ".", "year", "except", "iso8601", ".", "ParseError", ":", "for", "datefmt", "in", "(", "\"%B %d, %Y\"",...
Attempt to coerced date to ISO8601.
[ "Attempt", "to", "coerced", "date", "to", "ISO8601", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/zotero.py#L242-L254
train
diging/tethne
tethne/readers/zotero.py
ZoteroParser.postprocess_link
def postprocess_link(self, entry): """ Attempt to load full-text content from resource. """ if not self.follow_links: return if type(entry.link) is not list: entry.link = [entry.link] for link in list(entry.link): if not os.path.exis...
python
def postprocess_link(self, entry): """ Attempt to load full-text content from resource. """ if not self.follow_links: return if type(entry.link) is not list: entry.link = [entry.link] for link in list(entry.link): if not os.path.exis...
[ "def", "postprocess_link", "(", "self", ",", "entry", ")", ":", "if", "not", "self", ".", "follow_links", ":", "return", "if", "type", "(", "entry", ".", "link", ")", "is", "not", "list", ":", "entry", ".", "link", "=", "[", "entry", ".", "link", "...
Attempt to load full-text content from resource.
[ "Attempt", "to", "load", "full", "-", "text", "content", "from", "resource", "." ]
ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f
https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/zotero.py#L351-L388
train
web-push-libs/pywebpush
pywebpush/__init__.py
webpush
def webpush(subscription_info, data=None, vapid_private_key=None, vapid_claims=None, content_encoding="aes128gcm", curl=False, timeout=None, ttl=0): """ One call solution to endcode and send `data` to the endpoint co...
python
def webpush(subscription_info, data=None, vapid_private_key=None, vapid_claims=None, content_encoding="aes128gcm", curl=False, timeout=None, ttl=0): """ One call solution to endcode and send `data` to the endpoint co...
[ "def", "webpush", "(", "subscription_info", ",", "data", "=", "None", ",", "vapid_private_key", "=", "None", ",", "vapid_claims", "=", "None", ",", "content_encoding", "=", "\"aes128gcm\"", ",", "curl", "=", "False", ",", "timeout", "=", "None", ",", "ttl", ...
One call solution to endcode and send `data` to the endpoint contained in `subscription_info` using optional VAPID auth headers. in example: .. code-block:: python from pywebpush import python webpush( subscription_info={ "endpoint": "https://push....
[ "One", "call", "solution", "to", "endcode", "and", "send", "data", "to", "the", "endpoint", "contained", "in", "subscription_info", "using", "optional", "VAPID", "auth", "headers", "." ]
2a23f45b7819e31bd030de9fe1357a1cf7dcfdc4
https://github.com/web-push-libs/pywebpush/blob/2a23f45b7819e31bd030de9fe1357a1cf7dcfdc4/pywebpush/__init__.py#L350-L435
train
web-push-libs/pywebpush
pywebpush/__init__.py
WebPusher.encode
def encode(self, data, content_encoding="aes128gcm"): """Encrypt the data. :param data: A serialized block of byte data (String, JSON, bit array, etc.) Make sure that whatever you send, your client knows how to understand it. :type data: str :param content_encodi...
python
def encode(self, data, content_encoding="aes128gcm"): """Encrypt the data. :param data: A serialized block of byte data (String, JSON, bit array, etc.) Make sure that whatever you send, your client knows how to understand it. :type data: str :param content_encodi...
[ "def", "encode", "(", "self", ",", "data", ",", "content_encoding", "=", "\"aes128gcm\"", ")", ":", "# Salt is a random 16 byte array.", "if", "not", "data", ":", "return", "if", "not", "self", ".", "auth_key", "or", "not", "self", ".", "receiver_key", ":", ...
Encrypt the data. :param data: A serialized block of byte data (String, JSON, bit array, etc.) Make sure that whatever you send, your client knows how to understand it. :type data: str :param content_encoding: The content_encoding type to use to encrypt the d...
[ "Encrypt", "the", "data", "." ]
2a23f45b7819e31bd030de9fe1357a1cf7dcfdc4
https://github.com/web-push-libs/pywebpush/blob/2a23f45b7819e31bd030de9fe1357a1cf7dcfdc4/pywebpush/__init__.py#L162-L224
train
web-push-libs/pywebpush
pywebpush/__init__.py
WebPusher.send
def send(self, data=None, headers=None, ttl=0, gcm_key=None, reg_id=None, content_encoding="aes128gcm", curl=False, timeout=None): """Encode and send the data to the Push Service. :param data: A serialized block of data (see encode() ). :type data: str :param headers: A dic...
python
def send(self, data=None, headers=None, ttl=0, gcm_key=None, reg_id=None, content_encoding="aes128gcm", curl=False, timeout=None): """Encode and send the data to the Push Service. :param data: A serialized block of data (see encode() ). :type data: str :param headers: A dic...
[ "def", "send", "(", "self", ",", "data", "=", "None", ",", "headers", "=", "None", ",", "ttl", "=", "0", ",", "gcm_key", "=", "None", ",", "reg_id", "=", "None", ",", "content_encoding", "=", "\"aes128gcm\"", ",", "curl", "=", "False", ",", "timeout"...
Encode and send the data to the Push Service. :param data: A serialized block of data (see encode() ). :type data: str :param headers: A dictionary containing any additional HTTP headers. :type headers: dict :param ttl: The Time To Live in seconds for this message if the ...
[ "Encode", "and", "send", "the", "data", "to", "the", "Push", "Service", "." ]
2a23f45b7819e31bd030de9fe1357a1cf7dcfdc4
https://github.com/web-push-libs/pywebpush/blob/2a23f45b7819e31bd030de9fe1357a1cf7dcfdc4/pywebpush/__init__.py#L256-L347
train
martijnvermaat/calmap
calmap/__init__.py
calendarplot
def calendarplot(data, how='sum', yearlabels=True, yearascending=True, yearlabel_kws=None, subplot_kws=None, gridspec_kws=None, fig_kws=None, **kwargs): """ Plot a timeseries as a calendar heatmap. Parameters ---------- data : Series Data for the plot. Must be indexed by a ...
python
def calendarplot(data, how='sum', yearlabels=True, yearascending=True, yearlabel_kws=None, subplot_kws=None, gridspec_kws=None, fig_kws=None, **kwargs): """ Plot a timeseries as a calendar heatmap. Parameters ---------- data : Series Data for the plot. Must be indexed by a ...
[ "def", "calendarplot", "(", "data", ",", "how", "=", "'sum'", ",", "yearlabels", "=", "True", ",", "yearascending", "=", "True", ",", "yearlabel_kws", "=", "None", ",", "subplot_kws", "=", "None", ",", "gridspec_kws", "=", "None", ",", "fig_kws", "=", "N...
Plot a timeseries as a calendar heatmap. Parameters ---------- data : Series Data for the plot. Must be indexed by a DatetimeIndex. how : string Method for resampling data by day. If `None`, assume data is already sampled by day and don't resample. Otherwise, this is passed to P...
[ "Plot", "a", "timeseries", "as", "a", "calendar", "heatmap", "." ]
83e2a9a0bdc773c9e48e05772fb412ac8deb8bae
https://github.com/martijnvermaat/calmap/blob/83e2a9a0bdc773c9e48e05772fb412ac8deb8bae/calmap/__init__.py#L233-L329
train
Frojd/wagtail-geo-widget
wagtailgeowidget/helpers.py
geosgeometry_str_to_struct
def geosgeometry_str_to_struct(value): ''' Parses a geosgeometry string into struct. Example: SRID=5432;POINT(12.0 13.0) Returns: >> [5432, 12.0, 13.0] ''' result = geos_ptrn.match(value) if not result: return None return { 'srid': result.group(1), ...
python
def geosgeometry_str_to_struct(value): ''' Parses a geosgeometry string into struct. Example: SRID=5432;POINT(12.0 13.0) Returns: >> [5432, 12.0, 13.0] ''' result = geos_ptrn.match(value) if not result: return None return { 'srid': result.group(1), ...
[ "def", "geosgeometry_str_to_struct", "(", "value", ")", ":", "result", "=", "geos_ptrn", ".", "match", "(", "value", ")", "if", "not", "result", ":", "return", "None", "return", "{", "'srid'", ":", "result", ".", "group", "(", "1", ")", ",", "'x'", ":"...
Parses a geosgeometry string into struct. Example: SRID=5432;POINT(12.0 13.0) Returns: >> [5432, 12.0, 13.0]
[ "Parses", "a", "geosgeometry", "string", "into", "struct", "." ]
3482891be8903293812738d9128b9bda03b9a2ba
https://github.com/Frojd/wagtail-geo-widget/blob/3482891be8903293812738d9128b9bda03b9a2ba/wagtailgeowidget/helpers.py#L8-L27
train
Frojd/wagtail-geo-widget
example/examplesite/settings/__init__.py
get_env
def get_env(name, default=None): """Get the environment variable or return exception""" if name in os.environ: return os.environ[name] if default is not None: return default error_msg = "Set the {} env variable".format(name) raise ImproperlyConfigured(error_msg)
python
def get_env(name, default=None): """Get the environment variable or return exception""" if name in os.environ: return os.environ[name] if default is not None: return default error_msg = "Set the {} env variable".format(name) raise ImproperlyConfigured(error_msg)
[ "def", "get_env", "(", "name", ",", "default", "=", "None", ")", ":", "if", "name", "in", "os", ".", "environ", ":", "return", "os", ".", "environ", "[", "name", "]", "if", "default", "is", "not", "None", ":", "return", "default", "error_msg", "=", ...
Get the environment variable or return exception
[ "Get", "the", "environment", "variable", "or", "return", "exception" ]
3482891be8903293812738d9128b9bda03b9a2ba
https://github.com/Frojd/wagtail-geo-widget/blob/3482891be8903293812738d9128b9bda03b9a2ba/example/examplesite/settings/__init__.py#L6-L15
train
newville/asteval
asteval/asteval.py
Interpreter.user_defined_symbols
def user_defined_symbols(self): """Return a set of symbols that have been added to symtable after construction. I.e., the symbols from self.symtable that are not in self.no_deepcopy. Returns ------- unique_symbols : set symbols in symtable that are n...
python
def user_defined_symbols(self): """Return a set of symbols that have been added to symtable after construction. I.e., the symbols from self.symtable that are not in self.no_deepcopy. Returns ------- unique_symbols : set symbols in symtable that are n...
[ "def", "user_defined_symbols", "(", "self", ")", ":", "sym_in_current", "=", "set", "(", "self", ".", "symtable", ".", "keys", "(", ")", ")", "sym_from_construction", "=", "set", "(", "self", ".", "no_deepcopy", ")", "unique_symbols", "=", "sym_in_current", ...
Return a set of symbols that have been added to symtable after construction. I.e., the symbols from self.symtable that are not in self.no_deepcopy. Returns ------- unique_symbols : set symbols in symtable that are not in self.no_deepcopy
[ "Return", "a", "set", "of", "symbols", "that", "have", "been", "added", "to", "symtable", "after", "construction", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L216-L232
train
newville/asteval
asteval/asteval.py
Interpreter.unimplemented
def unimplemented(self, node): """Unimplemented nodes.""" self.raise_exception(node, exc=NotImplementedError, msg="'%s' not supported" % (node.__class__.__name__))
python
def unimplemented(self, node): """Unimplemented nodes.""" self.raise_exception(node, exc=NotImplementedError, msg="'%s' not supported" % (node.__class__.__name__))
[ "def", "unimplemented", "(", "self", ",", "node", ")", ":", "self", ".", "raise_exception", "(", "node", ",", "exc", "=", "NotImplementedError", ",", "msg", "=", "\"'%s' not supported\"", "%", "(", "node", ".", "__class__", ".", "__name__", ")", ")" ]
Unimplemented nodes.
[ "Unimplemented", "nodes", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L234-L238
train
newville/asteval
asteval/asteval.py
Interpreter.raise_exception
def raise_exception(self, node, exc=None, msg='', expr=None, lineno=None): """Add an exception.""" if self.error is None: self.error = [] if expr is None: expr = self.expr if len(self.error) > 0 and not isinstance(node, ast.Module): ...
python
def raise_exception(self, node, exc=None, msg='', expr=None, lineno=None): """Add an exception.""" if self.error is None: self.error = [] if expr is None: expr = self.expr if len(self.error) > 0 and not isinstance(node, ast.Module): ...
[ "def", "raise_exception", "(", "self", ",", "node", ",", "exc", "=", "None", ",", "msg", "=", "''", ",", "expr", "=", "None", ",", "lineno", "=", "None", ")", ":", "if", "self", ".", "error", "is", "None", ":", "self", ".", "error", "=", "[", "...
Add an exception.
[ "Add", "an", "exception", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L240-L261
train
newville/asteval
asteval/asteval.py
Interpreter.run
def run(self, node, expr=None, lineno=None, with_raise=True): """Execute parsed Ast representation for an expression.""" # Note: keep the 'node is None' test: internal code here may run # run(None) and expect a None in return. if time.time() - self.start_time > self.max_time: ...
python
def run(self, node, expr=None, lineno=None, with_raise=True): """Execute parsed Ast representation for an expression.""" # Note: keep the 'node is None' test: internal code here may run # run(None) and expect a None in return. if time.time() - self.start_time > self.max_time: ...
[ "def", "run", "(", "self", ",", "node", ",", "expr", "=", "None", ",", "lineno", "=", "None", ",", "with_raise", "=", "True", ")", ":", "# Note: keep the 'node is None' test: internal code here may run", "# run(None) and expect a None in return.", "if", "time", "."...
Execute parsed Ast representation for an expression.
[ "Execute", "parsed", "Ast", "representation", "for", "an", "expression", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L279-L313
train
newville/asteval
asteval/asteval.py
Interpreter.eval
def eval(self, expr, lineno=0, show_errors=True): """Evaluate a single statement.""" self.lineno = lineno self.error = [] self.start_time = time.time() try: node = self.parse(expr) except: errmsg = exc_info()[1] if len(self.error) > 0: ...
python
def eval(self, expr, lineno=0, show_errors=True): """Evaluate a single statement.""" self.lineno = lineno self.error = [] self.start_time = time.time() try: node = self.parse(expr) except: errmsg = exc_info()[1] if len(self.error) > 0: ...
[ "def", "eval", "(", "self", ",", "expr", ",", "lineno", "=", "0", ",", "show_errors", "=", "True", ")", ":", "self", ".", "lineno", "=", "lineno", "self", ".", "error", "=", "[", "]", "self", ".", "start_time", "=", "time", ".", "time", "(", ")",...
Evaluate a single statement.
[ "Evaluate", "a", "single", "statement", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L319-L351
train
newville/asteval
asteval/asteval.py
Interpreter.on_module
def on_module(self, node): # ():('body',) """Module def.""" out = None for tnode in node.body: out = self.run(tnode) return out
python
def on_module(self, node): # ():('body',) """Module def.""" out = None for tnode in node.body: out = self.run(tnode) return out
[ "def", "on_module", "(", "self", ",", "node", ")", ":", "# ():('body',)", "out", "=", "None", "for", "tnode", "in", "node", ".", "body", ":", "out", "=", "self", ".", "run", "(", "tnode", ")", "return", "out" ]
Module def.
[ "Module", "def", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L378-L383
train
newville/asteval
asteval/asteval.py
Interpreter.on_assert
def on_assert(self, node): # ('test', 'msg') """Assert statement.""" if not self.run(node.test): self.raise_exception(node, exc=AssertionError, msg=node.msg) return True
python
def on_assert(self, node): # ('test', 'msg') """Assert statement.""" if not self.run(node.test): self.raise_exception(node, exc=AssertionError, msg=node.msg) return True
[ "def", "on_assert", "(", "self", ",", "node", ")", ":", "# ('test', 'msg')", "if", "not", "self", ".", "run", "(", "node", ".", "test", ")", ":", "self", ".", "raise_exception", "(", "node", ",", "exc", "=", "AssertionError", ",", "msg", "=", "node", ...
Assert statement.
[ "Assert", "statement", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L411-L415
train
newville/asteval
asteval/asteval.py
Interpreter.on_name
def on_name(self, node): # ('id', 'ctx') """Name node.""" ctx = node.ctx.__class__ if ctx in (ast.Param, ast.Del): return str(node.id) else: if node.id in self.symtable: return self.symtable[node.id] else: msg = "name...
python
def on_name(self, node): # ('id', 'ctx') """Name node.""" ctx = node.ctx.__class__ if ctx in (ast.Param, ast.Del): return str(node.id) else: if node.id in self.symtable: return self.symtable[node.id] else: msg = "name...
[ "def", "on_name", "(", "self", ",", "node", ")", ":", "# ('id', 'ctx')", "ctx", "=", "node", ".", "ctx", ".", "__class__", "if", "ctx", "in", "(", "ast", ".", "Param", ",", "ast", ".", "Del", ")", ":", "return", "str", "(", "node", ".", "id", ")"...
Name node.
[ "Name", "node", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L442-L452
train
newville/asteval
asteval/asteval.py
Interpreter.on_attribute
def on_attribute(self, node): # ('value', 'attr', 'ctx') """Extract attribute.""" ctx = node.ctx.__class__ if ctx == ast.Store: msg = "attribute for storage: shouldn't be here!" self.raise_exception(node, exc=RuntimeError, msg=msg) sym = self.run(node.value) ...
python
def on_attribute(self, node): # ('value', 'attr', 'ctx') """Extract attribute.""" ctx = node.ctx.__class__ if ctx == ast.Store: msg = "attribute for storage: shouldn't be here!" self.raise_exception(node, exc=RuntimeError, msg=msg) sym = self.run(node.value) ...
[ "def", "on_attribute", "(", "self", ",", "node", ")", ":", "# ('value', 'attr', 'ctx')", "ctx", "=", "node", ".", "ctx", ".", "__class__", "if", "ctx", "==", "ast", ".", "Store", ":", "msg", "=", "\"attribute for storage: shouldn't be here!\"", "self", ".", "r...
Extract attribute.
[ "Extract", "attribute", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L496-L519
train
newville/asteval
asteval/asteval.py
Interpreter.on_assign
def on_assign(self, node): # ('targets', 'value') """Simple assignment.""" val = self.run(node.value) for tnode in node.targets: self.node_assign(tnode, val) return
python
def on_assign(self, node): # ('targets', 'value') """Simple assignment.""" val = self.run(node.value) for tnode in node.targets: self.node_assign(tnode, val) return
[ "def", "on_assign", "(", "self", ",", "node", ")", ":", "# ('targets', 'value')", "val", "=", "self", ".", "run", "(", "node", ".", "value", ")", "for", "tnode", "in", "node", ".", "targets", ":", "self", ".", "node_assign", "(", "tnode", ",", "val", ...
Simple assignment.
[ "Simple", "assignment", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L521-L526
train
newville/asteval
asteval/asteval.py
Interpreter.on_augassign
def on_augassign(self, node): # ('target', 'op', 'value') """Augmented assign.""" return self.on_assign(ast.Assign(targets=[node.target], value=ast.BinOp(left=node.target, op=node.op, ...
python
def on_augassign(self, node): # ('target', 'op', 'value') """Augmented assign.""" return self.on_assign(ast.Assign(targets=[node.target], value=ast.BinOp(left=node.target, op=node.op, ...
[ "def", "on_augassign", "(", "self", ",", "node", ")", ":", "# ('target', 'op', 'value')", "return", "self", ".", "on_assign", "(", "ast", ".", "Assign", "(", "targets", "=", "[", "node", ".", "target", "]", ",", "value", "=", "ast", ".", "BinOp", "(", ...
Augmented assign.
[ "Augmented", "assign", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L528-L533
train
newville/asteval
asteval/asteval.py
Interpreter.on_slice
def on_slice(self, node): # ():('lower', 'upper', 'step') """Simple slice.""" return slice(self.run(node.lower), self.run(node.upper), self.run(node.step))
python
def on_slice(self, node): # ():('lower', 'upper', 'step') """Simple slice.""" return slice(self.run(node.lower), self.run(node.upper), self.run(node.step))
[ "def", "on_slice", "(", "self", ",", "node", ")", ":", "# ():('lower', 'upper', 'step')", "return", "slice", "(", "self", ".", "run", "(", "node", ".", "lower", ")", ",", "self", ".", "run", "(", "node", ".", "upper", ")", ",", "self", ".", "run", "(...
Simple slice.
[ "Simple", "slice", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L535-L539
train
newville/asteval
asteval/asteval.py
Interpreter.on_extslice
def on_extslice(self, node): # ():('dims',) """Extended slice.""" return tuple([self.run(tnode) for tnode in node.dims])
python
def on_extslice(self, node): # ():('dims',) """Extended slice.""" return tuple([self.run(tnode) for tnode in node.dims])
[ "def", "on_extslice", "(", "self", ",", "node", ")", ":", "# ():('dims',)", "return", "tuple", "(", "[", "self", ".", "run", "(", "tnode", ")", "for", "tnode", "in", "node", ".", "dims", "]", ")" ]
Extended slice.
[ "Extended", "slice", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L541-L543
train
newville/asteval
asteval/asteval.py
Interpreter.on_delete
def on_delete(self, node): # ('targets',) """Delete statement.""" for tnode in node.targets: if tnode.ctx.__class__ != ast.Del: break children = [] while tnode.__class__ == ast.Attribute: children.append(tnode.attr) t...
python
def on_delete(self, node): # ('targets',) """Delete statement.""" for tnode in node.targets: if tnode.ctx.__class__ != ast.Del: break children = [] while tnode.__class__ == ast.Attribute: children.append(tnode.attr) t...
[ "def", "on_delete", "(", "self", ",", "node", ")", ":", "# ('targets',)", "for", "tnode", "in", "node", ".", "targets", ":", "if", "tnode", ".", "ctx", ".", "__class__", "!=", "ast", ".", "Del", ":", "break", "children", "=", "[", "]", "while", "tnod...
Delete statement.
[ "Delete", "statement", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L559-L575
train
newville/asteval
asteval/asteval.py
Interpreter.on_unaryop
def on_unaryop(self, node): # ('op', 'operand') """Unary operator.""" return op2func(node.op)(self.run(node.operand))
python
def on_unaryop(self, node): # ('op', 'operand') """Unary operator.""" return op2func(node.op)(self.run(node.operand))
[ "def", "on_unaryop", "(", "self", ",", "node", ")", ":", "# ('op', 'operand')", "return", "op2func", "(", "node", ".", "op", ")", "(", "self", ".", "run", "(", "node", ".", "operand", ")", ")" ]
Unary operator.
[ "Unary", "operator", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L577-L579
train
newville/asteval
asteval/asteval.py
Interpreter.on_binop
def on_binop(self, node): # ('left', 'op', 'right') """Binary operator.""" return op2func(node.op)(self.run(node.left), self.run(node.right))
python
def on_binop(self, node): # ('left', 'op', 'right') """Binary operator.""" return op2func(node.op)(self.run(node.left), self.run(node.right))
[ "def", "on_binop", "(", "self", ",", "node", ")", ":", "# ('left', 'op', 'right')", "return", "op2func", "(", "node", ".", "op", ")", "(", "self", ".", "run", "(", "node", ".", "left", ")", ",", "self", ".", "run", "(", "node", ".", "right", ")", "...
Binary operator.
[ "Binary", "operator", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L581-L584
train
newville/asteval
asteval/asteval.py
Interpreter.on_boolop
def on_boolop(self, node): # ('op', 'values') """Boolean operator.""" val = self.run(node.values[0]) is_and = ast.And == node.op.__class__ if (is_and and val) or (not is_and and not val): for n in node.values[1:]: val = op2func(node.op)(val, self.run(n)) ...
python
def on_boolop(self, node): # ('op', 'values') """Boolean operator.""" val = self.run(node.values[0]) is_and = ast.And == node.op.__class__ if (is_and and val) or (not is_and and not val): for n in node.values[1:]: val = op2func(node.op)(val, self.run(n)) ...
[ "def", "on_boolop", "(", "self", ",", "node", ")", ":", "# ('op', 'values')", "val", "=", "self", ".", "run", "(", "node", ".", "values", "[", "0", "]", ")", "is_and", "=", "ast", ".", "And", "==", "node", ".", "op", ".", "__class__", "if", "(", ...
Boolean operator.
[ "Boolean", "operator", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L586-L595
train
newville/asteval
asteval/asteval.py
Interpreter._printer
def _printer(self, *out, **kws): """Generic print function.""" flush = kws.pop('flush', True) fileh = kws.pop('file', self.writer) sep = kws.pop('sep', ' ') end = kws.pop('sep', '\n') print(*out, file=fileh, sep=sep, end=end) if flush: fileh.flush()
python
def _printer(self, *out, **kws): """Generic print function.""" flush = kws.pop('flush', True) fileh = kws.pop('file', self.writer) sep = kws.pop('sep', ' ') end = kws.pop('sep', '\n') print(*out, file=fileh, sep=sep, end=end) if flush: fileh.flush()
[ "def", "_printer", "(", "self", ",", "*", "out", ",", "*", "*", "kws", ")", ":", "flush", "=", "kws", ".", "pop", "(", "'flush'", ",", "True", ")", "fileh", "=", "kws", ".", "pop", "(", "'file'", ",", "self", ".", "writer", ")", "sep", "=", "...
Generic print function.
[ "Generic", "print", "function", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L626-L635
train
newville/asteval
asteval/asteval.py
Interpreter.on_if
def on_if(self, node): # ('test', 'body', 'orelse') """Regular if-then-else statement.""" block = node.body if not self.run(node.test): block = node.orelse for tnode in block: self.run(tnode)
python
def on_if(self, node): # ('test', 'body', 'orelse') """Regular if-then-else statement.""" block = node.body if not self.run(node.test): block = node.orelse for tnode in block: self.run(tnode)
[ "def", "on_if", "(", "self", ",", "node", ")", ":", "# ('test', 'body', 'orelse')", "block", "=", "node", ".", "body", "if", "not", "self", ".", "run", "(", "node", ".", "test", ")", ":", "block", "=", "node", ".", "orelse", "for", "tnode", "in", "bl...
Regular if-then-else statement.
[ "Regular", "if", "-", "then", "-", "else", "statement", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L637-L643
train
newville/asteval
asteval/asteval.py
Interpreter.on_ifexp
def on_ifexp(self, node): # ('test', 'body', 'orelse') """If expressions.""" expr = node.orelse if self.run(node.test): expr = node.body return self.run(expr)
python
def on_ifexp(self, node): # ('test', 'body', 'orelse') """If expressions.""" expr = node.orelse if self.run(node.test): expr = node.body return self.run(expr)
[ "def", "on_ifexp", "(", "self", ",", "node", ")", ":", "# ('test', 'body', 'orelse')", "expr", "=", "node", ".", "orelse", "if", "self", ".", "run", "(", "node", ".", "test", ")", ":", "expr", "=", "node", ".", "body", "return", "self", ".", "run", "...
If expressions.
[ "If", "expressions", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L645-L650
train
newville/asteval
asteval/asteval.py
Interpreter.on_while
def on_while(self, node): # ('test', 'body', 'orelse') """While blocks.""" while self.run(node.test): self._interrupt = None for tnode in node.body: self.run(tnode) if self._interrupt is not None: break if isinsta...
python
def on_while(self, node): # ('test', 'body', 'orelse') """While blocks.""" while self.run(node.test): self._interrupt = None for tnode in node.body: self.run(tnode) if self._interrupt is not None: break if isinsta...
[ "def", "on_while", "(", "self", ",", "node", ")", ":", "# ('test', 'body', 'orelse')", "while", "self", ".", "run", "(", "node", ".", "test", ")", ":", "self", ".", "_interrupt", "=", "None", "for", "tnode", "in", "node", ".", "body", ":", "self", ".",...
While blocks.
[ "While", "blocks", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L652-L665
train
newville/asteval
asteval/asteval.py
Interpreter.on_for
def on_for(self, node): # ('target', 'iter', 'body', 'orelse') """For blocks.""" for val in self.run(node.iter): self.node_assign(node.target, val) self._interrupt = None for tnode in node.body: self.run(tnode) if self._interrupt is ...
python
def on_for(self, node): # ('target', 'iter', 'body', 'orelse') """For blocks.""" for val in self.run(node.iter): self.node_assign(node.target, val) self._interrupt = None for tnode in node.body: self.run(tnode) if self._interrupt is ...
[ "def", "on_for", "(", "self", ",", "node", ")", ":", "# ('target', 'iter', 'body', 'orelse')", "for", "val", "in", "self", ".", "run", "(", "node", ".", "iter", ")", ":", "self", ".", "node_assign", "(", "node", ".", "target", ",", "val", ")", "self", ...
For blocks.
[ "For", "blocks", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L667-L681
train
newville/asteval
asteval/asteval.py
Interpreter.on_listcomp
def on_listcomp(self, node): # ('elt', 'generators') """List comprehension.""" out = [] for tnode in node.generators: if tnode.__class__ == ast.comprehension: for val in self.run(tnode.iter): self.node_assign(tnode.target, val) ...
python
def on_listcomp(self, node): # ('elt', 'generators') """List comprehension.""" out = [] for tnode in node.generators: if tnode.__class__ == ast.comprehension: for val in self.run(tnode.iter): self.node_assign(tnode.target, val) ...
[ "def", "on_listcomp", "(", "self", ",", "node", ")", ":", "# ('elt', 'generators')", "out", "=", "[", "]", "for", "tnode", "in", "node", ".", "generators", ":", "if", "tnode", ".", "__class__", "==", "ast", ".", "comprehension", ":", "for", "val", "in", ...
List comprehension.
[ "List", "comprehension", "." ]
bb7d3a95079f96ead75ea55662014bbcc82f9b28
https://github.com/newville/asteval/blob/bb7d3a95079f96ead75ea55662014bbcc82f9b28/asteval/asteval.py#L683-L695
train