partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
test | TaggerBatchTransform.shutdown | send SIGTERM to the tagger child process | streamcorpus_pipeline/_taggers.py | def shutdown(self):
'''
send SIGTERM to the tagger child process
'''
if self._child:
try:
self._child.terminate()
except OSError, exc:
if exc.errno == 3:
## child is already gone, possibly because it ran
... | def shutdown(self):
'''
send SIGTERM to the tagger child process
'''
if self._child:
try:
self._child.terminate()
except OSError, exc:
if exc.errno == 3:
## child is already gone, possibly because it ran
... | [
"send",
"SIGTERM",
"to",
"the",
"tagger",
"child",
"process"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_taggers.py#L763-L774 | [
"def",
"shutdown",
"(",
"self",
")",
":",
"if",
"self",
".",
"_child",
":",
"try",
":",
"self",
".",
"_child",
".",
"terminate",
"(",
")",
"except",
"OSError",
",",
"exc",
":",
"if",
"exc",
".",
"errno",
"==",
"3",
":",
"## child is already gone, possi... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | mult | Returns a Pattern that matches exactly n repetitions of Pattern p. | pe.py | def mult(p, n):
"""Returns a Pattern that matches exactly n repetitions of Pattern p.
"""
np = P()
while n >= 1:
if n % 2:
np = np + p
p = p + p
n = n // 2
return np | def mult(p, n):
"""Returns a Pattern that matches exactly n repetitions of Pattern p.
"""
np = P()
while n >= 1:
if n % 2:
np = np + p
p = p + p
n = n // 2
return np | [
"Returns",
"a",
"Pattern",
"that",
"matches",
"exactly",
"n",
"repetitions",
"of",
"Pattern",
"p",
"."
] | moreati/ppeg | python | https://github.com/moreati/ppeg/blob/946b1f75873eb52fa974606d85f576bfa0df9666/pe.py#L25-L34 | [
"def",
"mult",
"(",
"p",
",",
"n",
")",
":",
"np",
"=",
"P",
"(",
")",
"while",
"n",
">=",
"1",
":",
"if",
"n",
"%",
"2",
":",
"np",
"=",
"np",
"+",
"p",
"p",
"=",
"p",
"+",
"p",
"n",
"=",
"n",
"//",
"2",
"return",
"np"
] | 946b1f75873eb52fa974606d85f576bfa0df9666 |
test | fix_emails | Replace all angle bracket emails with a unique key. | streamcorpus_pipeline/emails.py | def fix_emails(text):
'''Replace all angle bracket emails with a unique key.'''
emails = bracket_emails.findall(text)
keys = []
for email in emails:
_email = email.replace("<","<").replace(">",">")
text = text.replace(email, _email)
return text | def fix_emails(text):
'''Replace all angle bracket emails with a unique key.'''
emails = bracket_emails.findall(text)
keys = []
for email in emails:
_email = email.replace("<","<").replace(">",">")
text = text.replace(email, _email)
return text | [
"Replace",
"all",
"angle",
"bracket",
"emails",
"with",
"a",
"unique",
"key",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/emails.py#L14-L23 | [
"def",
"fix_emails",
"(",
"text",
")",
":",
"emails",
"=",
"bracket_emails",
".",
"findall",
"(",
"text",
")",
"keys",
"=",
"[",
"]",
"for",
"email",
"in",
"emails",
":",
"_email",
"=",
"email",
".",
"replace",
"(",
"\"<\"",
",",
"\"<\"",
")",
"."... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | nltk_tokenizer._sentences | generate strings identified as sentences | streamcorpus_pipeline/_tokenizer.py | def _sentences(self, clean_visible):
'generate strings identified as sentences'
previous_end = 0
clean_visible = clean_visible.decode('utf8')
for start, end in self.sentence_tokenizer.span_tokenize(clean_visible):
# no need to check start, because the first byte of text
... | def _sentences(self, clean_visible):
'generate strings identified as sentences'
previous_end = 0
clean_visible = clean_visible.decode('utf8')
for start, end in self.sentence_tokenizer.span_tokenize(clean_visible):
# no need to check start, because the first byte of text
... | [
"generate",
"strings",
"identified",
"as",
"sentences"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_tokenizer.py#L51-L76 | [
"def",
"_sentences",
"(",
"self",
",",
"clean_visible",
")",
":",
"previous_end",
"=",
"0",
"clean_visible",
"=",
"clean_visible",
".",
"decode",
"(",
"'utf8'",
")",
"for",
"start",
",",
"end",
"in",
"self",
".",
"sentence_tokenizer",
".",
"span_tokenize",
"... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | nltk_tokenizer.make_label_index | make a sortedcollection on body.labels | streamcorpus_pipeline/_tokenizer.py | def make_label_index(self, stream_item):
'make a sortedcollection on body.labels'
labels = stream_item.body.labels.get(self.annotator_id)
if not labels:
labels = []
self.label_index = SortedCollection(
[l for l in labels if OffsetType.CHARS in l.offsets],
... | def make_label_index(self, stream_item):
'make a sortedcollection on body.labels'
labels = stream_item.body.labels.get(self.annotator_id)
if not labels:
labels = []
self.label_index = SortedCollection(
[l for l in labels if OffsetType.CHARS in l.offsets],
... | [
"make",
"a",
"sortedcollection",
"on",
"body",
".",
"labels"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_tokenizer.py#L78-L86 | [
"def",
"make_label_index",
"(",
"self",
",",
"stream_item",
")",
":",
"labels",
"=",
"stream_item",
".",
"body",
".",
"labels",
".",
"get",
"(",
"self",
".",
"annotator_id",
")",
"if",
"not",
"labels",
":",
"labels",
"=",
"[",
"]",
"self",
".",
"label_... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | nltk_tokenizer.make_sentences | assemble Sentence and Token objects | streamcorpus_pipeline/_tokenizer.py | def make_sentences(self, stream_item):
'assemble Sentence and Token objects'
self.make_label_index(stream_item)
sentences = []
token_num = 0
new_mention_id = 0
for sent_start, sent_end, sent_str in self._sentences(
stream_item.body.clean_visible):
... | def make_sentences(self, stream_item):
'assemble Sentence and Token objects'
self.make_label_index(stream_item)
sentences = []
token_num = 0
new_mention_id = 0
for sent_start, sent_end, sent_str in self._sentences(
stream_item.body.clean_visible):
... | [
"assemble",
"Sentence",
"and",
"Token",
"objects"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_tokenizer.py#L88-L137 | [
"def",
"make_sentences",
"(",
"self",
",",
"stream_item",
")",
":",
"self",
".",
"make_label_index",
"(",
"stream_item",
")",
"sentences",
"=",
"[",
"]",
"token_num",
"=",
"0",
"new_mention_id",
"=",
"0",
"for",
"sent_start",
",",
"sent_end",
",",
"sent_str"... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | html_entities_to_unicode | Convert any HTML, XML, or numeric entities in the attribute values.
For example '&' becomes '&'.
This is adapted from BeautifulSoup, which should be able to do the
same thing when called like this --- but this fails to convert
everything for some bug.
text = unicode(BeautifulStoneSoup(text, co... | streamcorpus_pipeline/convert_entities.py | def html_entities_to_unicode(text, space_padding=False, safe_only=False):
'''
Convert any HTML, XML, or numeric entities in the attribute values.
For example '&' becomes '&'.
This is adapted from BeautifulSoup, which should be able to do the
same thing when called like this --- but this fails t... | def html_entities_to_unicode(text, space_padding=False, safe_only=False):
'''
Convert any HTML, XML, or numeric entities in the attribute values.
For example '&' becomes '&'.
This is adapted from BeautifulSoup, which should be able to do the
same thing when called like this --- but this fails t... | [
"Convert",
"any",
"HTML",
"XML",
"or",
"numeric",
"entities",
"in",
"the",
"attribute",
"values",
".",
"For",
"example",
"&",
";",
"becomes",
"&",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/convert_entities.py#L30-L87 | [
"def",
"html_entities_to_unicode",
"(",
"text",
",",
"space_padding",
"=",
"False",
",",
"safe_only",
"=",
"False",
")",
":",
"def",
"convert_entities",
"(",
"match",
")",
":",
"'''\n comes from BeautifulSoup.Tag._convertEntities\n '''",
"x",
"=",
"match",... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | tps | :param text: tag-free UTF-8 string of free text
:returns string: 32-character md5 hash in hexadecimal
Python implementation of the TextProfileSignature provided in
SOLR. Unlike most other locality sensitive hashes, a TPS can be
indexed as a searchable property of each document that does not
requir... | streamcorpus_pipeline/text_profile_signature.py | def tps(text, min_token_len=2, quant_rate=0.01):
'''
:param text: tag-free UTF-8 string of free text
:returns string: 32-character md5 hash in hexadecimal
Python implementation of the TextProfileSignature provided in
SOLR. Unlike most other locality sensitive hashes, a TPS can be
indexed as a ... | def tps(text, min_token_len=2, quant_rate=0.01):
'''
:param text: tag-free UTF-8 string of free text
:returns string: 32-character md5 hash in hexadecimal
Python implementation of the TextProfileSignature provided in
SOLR. Unlike most other locality sensitive hashes, a TPS can be
indexed as a ... | [
":",
"param",
"text",
":",
"tag",
"-",
"free",
"UTF",
"-",
"8",
"string",
"of",
"free",
"text",
":",
"returns",
"string",
":",
"32",
"-",
"character",
"md5",
"hash",
"in",
"hexadecimal"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/text_profile_signature.py#L18-L48 | [
"def",
"tps",
"(",
"text",
",",
"min_token_len",
"=",
"2",
",",
"quant_rate",
"=",
"0.01",
")",
":",
"counts",
"=",
"Counter",
"(",
"ifilter",
"(",
"lambda",
"x",
":",
"len",
"(",
"x",
")",
">=",
"min_token_len",
",",
"imap",
"(",
"cleanse",
",",
"... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | make_cleansed_file | make a temp file of cleansed text | streamcorpus_pipeline/_run_lingpipe.py | def make_cleansed_file(i_chunk, tmp_cleansed_path):
'''make a temp file of cleansed text'''
tmp_cleansed = open(tmp_cleansed_path, 'wb')
for idx, si in enumerate(i_chunk):
tmp_cleansed.write('<FILENAME docid="%s">\n' % si.stream_id)
tmp_cleansed.write(si.body.cleansed)
## how to deal... | def make_cleansed_file(i_chunk, tmp_cleansed_path):
'''make a temp file of cleansed text'''
tmp_cleansed = open(tmp_cleansed_path, 'wb')
for idx, si in enumerate(i_chunk):
tmp_cleansed.write('<FILENAME docid="%s">\n' % si.stream_id)
tmp_cleansed.write(si.body.cleansed)
## how to deal... | [
"make",
"a",
"temp",
"file",
"of",
"cleansed",
"text"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_run_lingpipe.py#L48-L58 | [
"def",
"make_cleansed_file",
"(",
"i_chunk",
",",
"tmp_cleansed_path",
")",
":",
"tmp_cleansed",
"=",
"open",
"(",
"tmp_cleansed_path",
",",
"'wb'",
")",
"for",
"idx",
",",
"si",
"in",
"enumerate",
"(",
"i_chunk",
")",
":",
"tmp_cleansed",
".",
"write",
"(",... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | make_ner_file | run child process to get OWPL output | streamcorpus_pipeline/_run_lingpipe.py | def make_ner_file(tagger_id, tmp_cleansed_path, tmp_ner_path, pipeline_root):
'''run child process to get OWPL output'''
params = dict(INPUT_FILE=tmp_cleansed_path,
#RAW_OUTPUT_FILE=tmp_ner_raw_path,
OUTPUT_FILE=tmp_ner_path,
PIPELINE_ROOT=pipeline_root)
... | def make_ner_file(tagger_id, tmp_cleansed_path, tmp_ner_path, pipeline_root):
'''run child process to get OWPL output'''
params = dict(INPUT_FILE=tmp_cleansed_path,
#RAW_OUTPUT_FILE=tmp_ner_raw_path,
OUTPUT_FILE=tmp_ner_path,
PIPELINE_ROOT=pipeline_root)
... | [
"run",
"child",
"process",
"to",
"get",
"OWPL",
"output"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_run_lingpipe.py#L60-L100 | [
"def",
"make_ner_file",
"(",
"tagger_id",
",",
"tmp_cleansed_path",
",",
"tmp_ner_path",
",",
"pipeline_root",
")",
":",
"params",
"=",
"dict",
"(",
"INPUT_FILE",
"=",
"tmp_cleansed_path",
",",
"#RAW_OUTPUT_FILE=tmp_ner_raw_path,",
"OUTPUT_FILE",
"=",
"tmp_ner_path",
... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | cleanse | Convert a string of text into a lowercase string with no
punctuation and only spaces for whitespace.
:param span: string | streamcorpus_pipeline/_run_lingpipe.py | def cleanse(span):
'''Convert a string of text into a lowercase string with no
punctuation and only spaces for whitespace.
:param span: string
'''
try:
## attempt to force it to utf8, which might fail
span = span.encode('utf8', 'ignore')
except:
pass
## lowercase, st... | def cleanse(span):
'''Convert a string of text into a lowercase string with no
punctuation and only spaces for whitespace.
:param span: string
'''
try:
## attempt to force it to utf8, which might fail
span = span.encode('utf8', 'ignore')
except:
pass
## lowercase, st... | [
"Convert",
"a",
"string",
"of",
"text",
"into",
"a",
"lowercase",
"string",
"with",
"no",
"punctuation",
"and",
"only",
"spaces",
"for",
"whitespace",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_run_lingpipe.py#L107-L123 | [
"def",
"cleanse",
"(",
"span",
")",
":",
"try",
":",
"## attempt to force it to utf8, which might fail",
"span",
"=",
"span",
".",
"encode",
"(",
"'utf8'",
",",
"'ignore'",
")",
"except",
":",
"pass",
"## lowercase, strip punctuation, and shrink all whitespace",
"span",... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | align_chunk_with_ner | iterate through the i_chunk and tmp_ner_path to generate a new
Chunk with body.ner | streamcorpus_pipeline/_run_lingpipe.py | def align_chunk_with_ner(tmp_ner_path, i_chunk, tmp_done_path):
'''
iterate through the i_chunk and tmp_ner_path to generate a new
Chunk with body.ner
'''
o_chunk = Chunk()
input_iter = i_chunk.__iter__()
ner = ''
stream_id = None
all_ner = xml.dom.minidom.parse(open(tmp_ner_path))
... | def align_chunk_with_ner(tmp_ner_path, i_chunk, tmp_done_path):
'''
iterate through the i_chunk and tmp_ner_path to generate a new
Chunk with body.ner
'''
o_chunk = Chunk()
input_iter = i_chunk.__iter__()
ner = ''
stream_id = None
all_ner = xml.dom.minidom.parse(open(tmp_ner_path))
... | [
"iterate",
"through",
"the",
"i_chunk",
"and",
"tmp_ner_path",
"to",
"generate",
"a",
"new",
"Chunk",
"with",
"body",
".",
"ner"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_run_lingpipe.py#L126-L192 | [
"def",
"align_chunk_with_ner",
"(",
"tmp_ner_path",
",",
"i_chunk",
",",
"tmp_done_path",
")",
":",
"o_chunk",
"=",
"Chunk",
"(",
")",
"input_iter",
"=",
"i_chunk",
".",
"__iter__",
"(",
")",
"ner",
"=",
"''",
"stream_id",
"=",
"None",
"all_ner",
"=",
"xml... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | make_absolute_paths | given a config dict with streamcorpus_pipeline as a key, find all
keys under streamcorpus_pipeline that end with "_path" and if the
value of that key is a relative path, convert it to an absolute
path using the value provided by root_path | streamcorpus_pipeline/run.py | def make_absolute_paths(config):
'''given a config dict with streamcorpus_pipeline as a key, find all
keys under streamcorpus_pipeline that end with "_path" and if the
value of that key is a relative path, convert it to an absolute
path using the value provided by root_path
'''
if not 'streamcor... | def make_absolute_paths(config):
'''given a config dict with streamcorpus_pipeline as a key, find all
keys under streamcorpus_pipeline that end with "_path" and if the
value of that key is a relative path, convert it to an absolute
path using the value provided by root_path
'''
if not 'streamcor... | [
"given",
"a",
"config",
"dict",
"with",
"streamcorpus_pipeline",
"as",
"a",
"key",
"find",
"all",
"keys",
"under",
"streamcorpus_pipeline",
"that",
"end",
"with",
"_path",
"and",
"if",
"the",
"value",
"of",
"that",
"key",
"is",
"a",
"relative",
"path",
"conv... | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/run.py#L61-L95 | [
"def",
"make_absolute_paths",
"(",
"config",
")",
":",
"if",
"not",
"'streamcorpus_pipeline'",
"in",
"config",
":",
"logger",
".",
"critical",
"(",
"'bad config: %r'",
",",
"config",
")",
"raise",
"ConfigurationError",
"(",
"'missing \"streamcorpus_pipeline\" from confi... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | make_hash | Makes a hash from a dictionary, list, tuple or set to any level,
that contains only other hashable types (including any lists,
tuples, sets, and dictionaries). See second answer (not the
accepted answer):
http://stackoverflow.com/questions/5884066/hashing-a-python-dictionary | streamcorpus_pipeline/run.py | def make_hash(obj):
'''
Makes a hash from a dictionary, list, tuple or set to any level,
that contains only other hashable types (including any lists,
tuples, sets, and dictionaries). See second answer (not the
accepted answer):
http://stackoverflow.com/questions/5884066/hashing-a-python-dictio... | def make_hash(obj):
'''
Makes a hash from a dictionary, list, tuple or set to any level,
that contains only other hashable types (including any lists,
tuples, sets, and dictionaries). See second answer (not the
accepted answer):
http://stackoverflow.com/questions/5884066/hashing-a-python-dictio... | [
"Makes",
"a",
"hash",
"from",
"a",
"dictionary",
"list",
"tuple",
"or",
"set",
"to",
"any",
"level",
"that",
"contains",
"only",
"other",
"hashable",
"types",
"(",
"including",
"any",
"lists",
"tuples",
"sets",
"and",
"dictionaries",
")",
".",
"See",
"seco... | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/run.py#L97-L115 | [
"def",
"make_hash",
"(",
"obj",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"(",
"set",
",",
"tuple",
",",
"list",
")",
")",
":",
"return",
"tuple",
"(",
"[",
"make_hash",
"(",
"e",
")",
"for",
"e",
"in",
"obj",
"]",
")",
"elif",
"not",
"isi... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | instantiate_config | setup the config and load external modules
This updates 'config' as follows:
* All paths are replaced with absolute paths
* A hash and JSON dump of the config are stored in the config
* If 'pythonpath' is in the config, it is added to sys.path
* If 'setup_modules' is in the config, all modules nam... | streamcorpus_pipeline/run.py | def instantiate_config(config):
'''setup the config and load external modules
This updates 'config' as follows:
* All paths are replaced with absolute paths
* A hash and JSON dump of the config are stored in the config
* If 'pythonpath' is in the config, it is added to sys.path
* If 'setup_mod... | def instantiate_config(config):
'''setup the config and load external modules
This updates 'config' as follows:
* All paths are replaced with absolute paths
* A hash and JSON dump of the config are stored in the config
* If 'pythonpath' is in the config, it is added to sys.path
* If 'setup_mod... | [
"setup",
"the",
"config",
"and",
"load",
"external",
"modules"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/run.py#L117-L159 | [
"def",
"instantiate_config",
"(",
"config",
")",
":",
"make_absolute_paths",
"(",
"config",
")",
"pipeline_config",
"=",
"config",
"[",
"'streamcorpus_pipeline'",
"]",
"pipeline_config",
"[",
"'config_hash'",
"]",
"=",
"make_hash",
"(",
"config",
")",
"pipeline_conf... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | generate_john_smith_chunk | This _looks_ like a Chunk only in that it generates StreamItem
instances when iterated upon. | streamcorpus_pipeline/_john_smith.py | def generate_john_smith_chunk(path_to_original):
'''
This _looks_ like a Chunk only in that it generates StreamItem
instances when iterated upon.
'''
## Every StreamItem has a stream_time property. It usually comes
## from the document creation time. Here, we assume the JS corpus
## was cr... | def generate_john_smith_chunk(path_to_original):
'''
This _looks_ like a Chunk only in that it generates StreamItem
instances when iterated upon.
'''
## Every StreamItem has a stream_time property. It usually comes
## from the document creation time. Here, we assume the JS corpus
## was cr... | [
"This",
"_looks_",
"like",
"a",
"Chunk",
"only",
"in",
"that",
"it",
"generates",
"StreamItem",
"instances",
"when",
"iterated",
"upon",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_john_smith.py#L47-L117 | [
"def",
"generate_john_smith_chunk",
"(",
"path_to_original",
")",
":",
"## Every StreamItem has a stream_time property. It usually comes",
"## from the document creation time. Here, we assume the JS corpus",
"## was created at one moment at the end of 1998:",
"creation_time",
"=",
"'1998-12-... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | re_based_make_clean_visible | Takes an HTML-like binary string as input and returns a binary
string of the same length with all tags replaced by whitespace.
This also detects script and style tags, and replaces the text
between them with whitespace.
Pre-existing whitespace of any kind (newlines, tabs) is converted
to single spa... | streamcorpus_pipeline/_clean_visible.py | def re_based_make_clean_visible(html):
'''
Takes an HTML-like binary string as input and returns a binary
string of the same length with all tags replaced by whitespace.
This also detects script and style tags, and replaces the text
between them with whitespace.
Pre-existing whitespace of any k... | def re_based_make_clean_visible(html):
'''
Takes an HTML-like binary string as input and returns a binary
string of the same length with all tags replaced by whitespace.
This also detects script and style tags, and replaces the text
between them with whitespace.
Pre-existing whitespace of any k... | [
"Takes",
"an",
"HTML",
"-",
"like",
"binary",
"string",
"as",
"input",
"and",
"returns",
"a",
"binary",
"string",
"of",
"the",
"same",
"length",
"with",
"all",
"tags",
"replaced",
"by",
"whitespace",
".",
"This",
"also",
"detects",
"script",
"and",
"style"... | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_clean_visible.py#L36-L72 | [
"def",
"re_based_make_clean_visible",
"(",
"html",
")",
":",
"text",
"=",
"''",
"# Fix emails",
"html",
"=",
"fix_emails",
"(",
"html",
")",
"for",
"m",
"in",
"invisible",
".",
"finditer",
"(",
"html",
")",
":",
"text",
"+=",
"m",
".",
"group",
"(",
"'... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | make_clean_visible | Takes an HTML-like Unicode string as input and returns a UTF-8
encoded string with all tags replaced by whitespace. In particular,
all Unicode characters inside HTML are replaced with a single
whitespace character.
This does not detect comments, style, script, link. It also does
do anything with H... | streamcorpus_pipeline/_clean_visible.py | def make_clean_visible(_html, tag_replacement_char=' '):
'''
Takes an HTML-like Unicode string as input and returns a UTF-8
encoded string with all tags replaced by whitespace. In particular,
all Unicode characters inside HTML are replaced with a single
whitespace character.
This does not detec... | def make_clean_visible(_html, tag_replacement_char=' '):
'''
Takes an HTML-like Unicode string as input and returns a UTF-8
encoded string with all tags replaced by whitespace. In particular,
all Unicode characters inside HTML are replaced with a single
whitespace character.
This does not detec... | [
"Takes",
"an",
"HTML",
"-",
"like",
"Unicode",
"string",
"as",
"input",
"and",
"returns",
"a",
"UTF",
"-",
"8",
"encoded",
"string",
"with",
"all",
"tags",
"replaced",
"by",
"whitespace",
".",
"In",
"particular",
"all",
"Unicode",
"characters",
"inside",
"... | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_clean_visible.py#L75-L128 | [
"def",
"make_clean_visible",
"(",
"_html",
",",
"tag_replacement_char",
"=",
"' '",
")",
":",
"def",
"non_tag_chars",
"(",
"html",
")",
":",
"n",
"=",
"0",
"while",
"n",
"<",
"len",
"(",
"html",
")",
":",
"angle",
"=",
"html",
".",
"find",
"(",
"'<'"... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | non_tag_chars_from_raw | generator that yields clean visible as it transitions through
states in the raw `html` | streamcorpus_pipeline/_clean_visible.py | def non_tag_chars_from_raw(html):
'''generator that yields clean visible as it transitions through
states in the raw `html`
'''
n = 0
while n < len(html):
# find start of tag
angle = html.find('<', n)
if angle == -1:
yield html[n:]
n = len(html)
... | def non_tag_chars_from_raw(html):
'''generator that yields clean visible as it transitions through
states in the raw `html`
'''
n = 0
while n < len(html):
# find start of tag
angle = html.find('<', n)
if angle == -1:
yield html[n:]
n = len(html)
... | [
"generator",
"that",
"yields",
"clean",
"visible",
"as",
"it",
"transitions",
"through",
"states",
"in",
"the",
"raw",
"html"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_clean_visible.py#L133-L248 | [
"def",
"non_tag_chars_from_raw",
"(",
"html",
")",
":",
"n",
"=",
"0",
"while",
"n",
"<",
"len",
"(",
"html",
")",
":",
"# find start of tag",
"angle",
"=",
"html",
".",
"find",
"(",
"'<'",
",",
"n",
")",
"if",
"angle",
"==",
"-",
"1",
":",
"yield"... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | make_clean_visible_from_raw | Takes an HTML-like Unicode (or UTF-8 encoded) string as input and
returns a Unicode string with all tags replaced by whitespace. In
particular, all Unicode characters inside HTML are replaced with a
single whitespace character.
This *does* detect comments, style, script, link tags and replaces
them... | streamcorpus_pipeline/_clean_visible.py | def make_clean_visible_from_raw(_html, tag_replacement_char=' '):
'''Takes an HTML-like Unicode (or UTF-8 encoded) string as input and
returns a Unicode string with all tags replaced by whitespace. In
particular, all Unicode characters inside HTML are replaced with a
single whitespace character.
Th... | def make_clean_visible_from_raw(_html, tag_replacement_char=' '):
'''Takes an HTML-like Unicode (or UTF-8 encoded) string as input and
returns a Unicode string with all tags replaced by whitespace. In
particular, all Unicode characters inside HTML are replaced with a
single whitespace character.
Th... | [
"Takes",
"an",
"HTML",
"-",
"like",
"Unicode",
"(",
"or",
"UTF",
"-",
"8",
"encoded",
")",
"string",
"as",
"input",
"and",
"returns",
"a",
"Unicode",
"string",
"with",
"all",
"tags",
"replaced",
"by",
"whitespace",
".",
"In",
"particular",
"all",
"Unicod... | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_clean_visible.py#L252-L278 | [
"def",
"make_clean_visible_from_raw",
"(",
"_html",
",",
"tag_replacement_char",
"=",
"' '",
")",
":",
"if",
"not",
"isinstance",
"(",
"_html",
",",
"unicode",
")",
":",
"_html",
"=",
"unicode",
"(",
"_html",
",",
"'utf-8'",
")",
"#Strip tags with logic above",
... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | make_clean_visible_file | make a temp file of clean_visible text | streamcorpus_pipeline/_clean_visible.py | def make_clean_visible_file(i_chunk, clean_visible_path):
'''make a temp file of clean_visible text'''
_clean = open(clean_visible_path, 'wb')
_clean.write('<?xml version="1.0" encoding="UTF-8"?>')
_clean.write('<root>')
for idx, si in enumerate(i_chunk):
if si.stream_id is None:
... | def make_clean_visible_file(i_chunk, clean_visible_path):
'''make a temp file of clean_visible text'''
_clean = open(clean_visible_path, 'wb')
_clean.write('<?xml version="1.0" encoding="UTF-8"?>')
_clean.write('<root>')
for idx, si in enumerate(i_chunk):
if si.stream_id is None:
... | [
"make",
"a",
"temp",
"file",
"of",
"clean_visible",
"text"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_clean_visible.py#L338-L389 | [
"def",
"make_clean_visible_file",
"(",
"i_chunk",
",",
"clean_visible_path",
")",
":",
"_clean",
"=",
"open",
"(",
"clean_visible_path",
",",
"'wb'",
")",
"_clean",
".",
"write",
"(",
"'<?xml version=\"1.0\" encoding=\"UTF-8\"?>'",
")",
"_clean",
".",
"write",
"(",
... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | cleanse | Convert a unicode string into a lowercase string with no
punctuation and only spaces for whitespace.
Replace PennTreebank escaped brackets with ' ':
-LRB- -RRB- -RSB- -RSB- -LCB- -RCB-
(The acronyms stand for (Left|Right) (Round|Square|Curly) Bracket.)
http://www.cis.upenn.edu/~treebank/tokenization.html
:param span:... | streamcorpus_pipeline/_clean_visible.py | def cleanse(span, lower=True):
'''Convert a unicode string into a lowercase string with no
punctuation and only spaces for whitespace.
Replace PennTreebank escaped brackets with ' ':
-LRB- -RRB- -RSB- -RSB- -LCB- -RCB-
(The acronyms stand for (Left|Right) (Round|Square|Curly) Bracket.)
http://www.cis.upenn.edu/~tr... | def cleanse(span, lower=True):
'''Convert a unicode string into a lowercase string with no
punctuation and only spaces for whitespace.
Replace PennTreebank escaped brackets with ' ':
-LRB- -RRB- -RSB- -RSB- -LCB- -RCB-
(The acronyms stand for (Left|Right) (Round|Square|Curly) Bracket.)
http://www.cis.upenn.edu/~tr... | [
"Convert",
"a",
"unicode",
"string",
"into",
"a",
"lowercase",
"string",
"with",
"no",
"punctuation",
"and",
"only",
"spaces",
"for",
"whitespace",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_clean_visible.py#L397-L417 | [
"def",
"cleanse",
"(",
"span",
",",
"lower",
"=",
"True",
")",
":",
"assert",
"isinstance",
"(",
"span",
",",
"unicode",
")",
",",
"'got non-unicode string %r'",
"%",
"span",
"# lowercase, strip punctuation, and shrink all whitespace",
"span",
"=",
"penn_treebank_brac... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | main | manual test loop for make_clean_visible_from_raw | streamcorpus_pipeline/_clean_visible.py | def main():
'''manual test loop for make_clean_visible_from_raw
'''
import argparse
import sys
parser = argparse.ArgumentParser()
parser.add_argument('path')
args = parser.parse_args()
html = open(args.path).read()
html = html.decode('utf8')
cursor = 0
for s in non_tag_... | def main():
'''manual test loop for make_clean_visible_from_raw
'''
import argparse
import sys
parser = argparse.ArgumentParser()
parser.add_argument('path')
args = parser.parse_args()
html = open(args.path).read()
html = html.decode('utf8')
cursor = 0
for s in non_tag_... | [
"manual",
"test",
"loop",
"for",
"make_clean_visible_from_raw"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_clean_visible.py#L420-L439 | [
"def",
"main",
"(",
")",
":",
"import",
"argparse",
"import",
"sys",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
")",
"parser",
".",
"add_argument",
"(",
"'path'",
")",
"args",
"=",
"parser",
".",
"parse_args",
"(",
")",
"html",
"=",
"open",
... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | StageRegistry.tryload_stage | Try to load a stage into self, ignoring errors.
If loading a module fails because of some subordinate load
failure, just give a warning and move on. On success the
stage is added to the stage dictionary.
:param str moduleName: name of the Python module
:param str functionName:... | streamcorpus_pipeline/stages.py | def tryload_stage(self, moduleName, functionName, name=None):
'''Try to load a stage into self, ignoring errors.
If loading a module fails because of some subordinate load
failure, just give a warning and move on. On success the
stage is added to the stage dictionary.
:param s... | def tryload_stage(self, moduleName, functionName, name=None):
'''Try to load a stage into self, ignoring errors.
If loading a module fails because of some subordinate load
failure, just give a warning and move on. On success the
stage is added to the stage dictionary.
:param s... | [
"Try",
"to",
"load",
"a",
"stage",
"into",
"self",
"ignoring",
"errors",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/stages.py#L175-L201 | [
"def",
"tryload_stage",
"(",
"self",
",",
"moduleName",
",",
"functionName",
",",
"name",
"=",
"None",
")",
":",
"if",
"name",
"is",
"None",
":",
"name",
"=",
"functionName",
"try",
":",
"mod",
"=",
"__import__",
"(",
"moduleName",
",",
"globals",
"(",
... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | StageRegistry.load_external_stages | Add external stages from the Python module in `path`.
`path` must be a path to a Python module source that contains
a `Stages` dictionary, which is a map from stage name to callable.
:param str path: path to the module file | streamcorpus_pipeline/stages.py | def load_external_stages(self, path):
'''Add external stages from the Python module in `path`.
`path` must be a path to a Python module source that contains
a `Stages` dictionary, which is a map from stage name to callable.
:param str path: path to the module file
'''
m... | def load_external_stages(self, path):
'''Add external stages from the Python module in `path`.
`path` must be a path to a Python module source that contains
a `Stages` dictionary, which is a map from stage name to callable.
:param str path: path to the module file
'''
m... | [
"Add",
"external",
"stages",
"from",
"the",
"Python",
"module",
"in",
"path",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/stages.py#L203-L212 | [
"def",
"load_external_stages",
"(",
"self",
",",
"path",
")",
":",
"mod",
"=",
"imp",
".",
"load_source",
"(",
"''",
",",
"path",
")",
"self",
".",
"update",
"(",
"mod",
".",
"Stages",
")"
] | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | StageRegistry.load_module_stages | Add external stages from the Python module `mod`.
If `mod` is a string, then it will be interpreted as the name
of a module; otherwise it is an actual module object. The
module should exist somewhere in :data:`sys.path`. The module
must contain a `Stages` dictionary, which is a map fr... | streamcorpus_pipeline/stages.py | def load_module_stages(self, mod):
'''Add external stages from the Python module `mod`.
If `mod` is a string, then it will be interpreted as the name
of a module; otherwise it is an actual module object. The
module should exist somewhere in :data:`sys.path`. The module
must co... | def load_module_stages(self, mod):
'''Add external stages from the Python module `mod`.
If `mod` is a string, then it will be interpreted as the name
of a module; otherwise it is an actual module object. The
module should exist somewhere in :data:`sys.path`. The module
must co... | [
"Add",
"external",
"stages",
"from",
"the",
"Python",
"module",
"mod",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/stages.py#L214-L233 | [
"def",
"load_module_stages",
"(",
"self",
",",
"mod",
")",
":",
"if",
"isinstance",
"(",
"mod",
",",
"basestring",
")",
":",
"mod",
"=",
"__import__",
"(",
"mod",
",",
"globals",
"=",
"globals",
"(",
")",
",",
"locals",
"=",
"locals",
"(",
")",
",",
... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | StageRegistry.init_stage | Construct and configure a stage from known stages.
`name` must be the name of one of the stages in this. `config`
is the configuration dictionary of the containing object, and its `name`
member will be passed into the stage constructor.
:param str name: name of the stage
:para... | streamcorpus_pipeline/stages.py | def init_stage(self, name, config):
'''Construct and configure a stage from known stages.
`name` must be the name of one of the stages in this. `config`
is the configuration dictionary of the containing object, and its `name`
member will be passed into the stage constructor.
... | def init_stage(self, name, config):
'''Construct and configure a stage from known stages.
`name` must be the name of one of the stages in this. `config`
is the configuration dictionary of the containing object, and its `name`
member will be passed into the stage constructor.
... | [
"Construct",
"and",
"configure",
"a",
"stage",
"from",
"known",
"stages",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/stages.py#L235-L251 | [
"def",
"init_stage",
"(",
"self",
",",
"name",
",",
"config",
")",
":",
"subconfig",
"=",
"config",
".",
"get",
"(",
"name",
",",
"{",
"}",
")",
"ctor",
"=",
"self",
"[",
"name",
"]",
"return",
"ctor",
"(",
"subconfig",
")"
] | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | read_to | iterates through idx_bytes until a byte in stop_bytes or a byte
not in run_bytes.
:rtype (int, string): idx of last byte and all of bytes including
the terminal byte from stop_bytes or not in run_bytes | streamcorpus_pipeline/_hyperlink_labels.py | def read_to( idx_bytes, stop_bytes=None, run_bytes=None ):
'''
iterates through idx_bytes until a byte in stop_bytes or a byte
not in run_bytes.
:rtype (int, string): idx of last byte and all of bytes including
the terminal byte from stop_bytes or not in run_bytes
'''
idx = None
vals = ... | def read_to( idx_bytes, stop_bytes=None, run_bytes=None ):
'''
iterates through idx_bytes until a byte in stop_bytes or a byte
not in run_bytes.
:rtype (int, string): idx of last byte and all of bytes including
the terminal byte from stop_bytes or not in run_bytes
'''
idx = None
vals = ... | [
"iterates",
"through",
"idx_bytes",
"until",
"a",
"byte",
"in",
"stop_bytes",
"or",
"a",
"byte",
"not",
"in",
"run_bytes",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_hyperlink_labels.py#L28-L57 | [
"def",
"read_to",
"(",
"idx_bytes",
",",
"stop_bytes",
"=",
"None",
",",
"run_bytes",
"=",
"None",
")",
":",
"idx",
"=",
"None",
"vals",
"=",
"[",
"]",
"next_b",
"=",
"None",
"while",
"1",
":",
"try",
":",
"idx",
",",
"next_b",
"=",
"idx_bytes",
".... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | iter_attrs | called when idx_chars is just past "<a " inside an HTML anchor tag
generates tuple(end_idx, attr_name, attr_value) | streamcorpus_pipeline/_hyperlink_labels.py | def iter_attrs( idx_bytes ):
'''
called when idx_chars is just past "<a " inside an HTML anchor tag
generates tuple(end_idx, attr_name, attr_value)
'''
## read to the end of the "A" tag
while 1:
idx, attr_name, next_b = read_to(idx_bytes, ['=', '>'])
attr_vals = []
... | def iter_attrs( idx_bytes ):
'''
called when idx_chars is just past "<a " inside an HTML anchor tag
generates tuple(end_idx, attr_name, attr_value)
'''
## read to the end of the "A" tag
while 1:
idx, attr_name, next_b = read_to(idx_bytes, ['=', '>'])
attr_vals = []
... | [
"called",
"when",
"idx_chars",
"is",
"just",
"past",
"<a",
"inside",
"an",
"HTML",
"anchor",
"tag",
"generates",
"tuple",
"(",
"end_idx",
"attr_name",
"attr_value",
")"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_hyperlink_labels.py#L60-L87 | [
"def",
"iter_attrs",
"(",
"idx_bytes",
")",
":",
"## read to the end of the \"A\" tag",
"while",
"1",
":",
"idx",
",",
"attr_name",
",",
"next_b",
"=",
"read_to",
"(",
"idx_bytes",
",",
"[",
"'='",
",",
"'>'",
"]",
")",
"attr_vals",
"=",
"[",
"]",
"## stop... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | hyperlink_labels.href_filter | Test whether an href string meets criteria specified by
configuration parameters 'require_abs_url', which means "does
it look like it is probably an absolute URL?" and
'domain_substrings'. It searches for each of the
domain_substrings in the href individually, and if any match,
... | streamcorpus_pipeline/_hyperlink_labels.py | def href_filter(self, href):
'''
Test whether an href string meets criteria specified by
configuration parameters 'require_abs_url', which means "does
it look like it is probably an absolute URL?" and
'domain_substrings'. It searches for each of the
domain_substrings in ... | def href_filter(self, href):
'''
Test whether an href string meets criteria specified by
configuration parameters 'require_abs_url', which means "does
it look like it is probably an absolute URL?" and
'domain_substrings'. It searches for each of the
domain_substrings in ... | [
"Test",
"whether",
"an",
"href",
"string",
"meets",
"criteria",
"specified",
"by",
"configuration",
"parameters",
"require_abs_url",
"which",
"means",
"does",
"it",
"look",
"like",
"it",
"is",
"probably",
"an",
"absolute",
"URL?",
"and",
"domain_substrings",
".",
... | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_hyperlink_labels.py#L159-L189 | [
"def",
"href_filter",
"(",
"self",
",",
"href",
")",
":",
"if",
"self",
".",
"config",
"[",
"'require_abs_url'",
"]",
":",
"if",
"not",
"href",
".",
"lower",
"(",
")",
".",
"startswith",
"(",
"(",
"'http://'",
",",
"'https://'",
")",
")",
":",
"retur... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | hyperlink_labels.line_href_anchors | simple, regex-based extractor of anchor tags, so we can
compute LINE offsets for anchor texts and associate them with
their href.
Generates tuple(href_string, first_byte, byte_length, anchor_text)
Also, this mangles the body.clean_html so that LINE offsets
uniquely iden... | streamcorpus_pipeline/_hyperlink_labels.py | def line_href_anchors(self):
'''
simple, regex-based extractor of anchor tags, so we can
compute LINE offsets for anchor texts and associate them with
their href.
Generates tuple(href_string, first_byte, byte_length, anchor_text)
Also, this mangles the body.clea... | def line_href_anchors(self):
'''
simple, regex-based extractor of anchor tags, so we can
compute LINE offsets for anchor texts and associate them with
their href.
Generates tuple(href_string, first_byte, byte_length, anchor_text)
Also, this mangles the body.clea... | [
"simple",
"regex",
"-",
"based",
"extractor",
"of",
"anchor",
"tags",
"so",
"we",
"can",
"compute",
"LINE",
"offsets",
"for",
"anchor",
"texts",
"and",
"associate",
"them",
"with",
"their",
"href",
".",
"Generates",
"tuple",
"(",
"href_string",
"first_byte",
... | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_hyperlink_labels.py#L192-L248 | [
"def",
"line_href_anchors",
"(",
"self",
")",
":",
"idx",
"=",
"0",
"new_clean_html",
"=",
"''",
"newlines_added",
"=",
"0",
"## split doc up into pieces that end on an anchor tag",
"parts",
"=",
"self",
".",
"clean_html",
".",
"split",
"(",
"'</a>'",
")",
"assert... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | hyperlink_labels.byte_href_anchors | simple, regex-based extractor of anchor tags, so we can
compute BYTE offsets for anchor texts and associate them with
their href.
Generates tuple(href_string, first_byte, byte_length, anchor_text) | streamcorpus_pipeline/_hyperlink_labels.py | def byte_href_anchors(self, chars=False):
'''
simple, regex-based extractor of anchor tags, so we can
compute BYTE offsets for anchor texts and associate them with
their href.
Generates tuple(href_string, first_byte, byte_length, anchor_text)
'''
input_bu... | def byte_href_anchors(self, chars=False):
'''
simple, regex-based extractor of anchor tags, so we can
compute BYTE offsets for anchor texts and associate them with
their href.
Generates tuple(href_string, first_byte, byte_length, anchor_text)
'''
input_bu... | [
"simple",
"regex",
"-",
"based",
"extractor",
"of",
"anchor",
"tags",
"so",
"we",
"can",
"compute",
"BYTE",
"offsets",
"for",
"anchor",
"texts",
"and",
"associate",
"them",
"with",
"their",
"href",
".",
"Generates",
"tuple",
"(",
"href_string",
"first_byte",
... | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_hyperlink_labels.py#L254-L295 | [
"def",
"byte_href_anchors",
"(",
"self",
",",
"chars",
"=",
"False",
")",
":",
"input_buffer",
"=",
"self",
".",
"clean_html",
"if",
"chars",
":",
"input_buffer",
"=",
"input_buffer",
".",
"decode",
"(",
"'utf8'",
")",
"idx",
"=",
"0",
"## split doc up into ... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | hyperlink_labels.byte_href_anchors_state_machine | byte-based state machine extractor of anchor tags, so we can
compute byte offsets for anchor texts and associate them with
their href.
Generates tuple(href_string, first_byte, byte_length, anchor_text) | streamcorpus_pipeline/_hyperlink_labels.py | def byte_href_anchors_state_machine(self):
'''
byte-based state machine extractor of anchor tags, so we can
compute byte offsets for anchor texts and associate them with
their href.
Generates tuple(href_string, first_byte, byte_length, anchor_text)
'''
ta... | def byte_href_anchors_state_machine(self):
'''
byte-based state machine extractor of anchor tags, so we can
compute byte offsets for anchor texts and associate them with
their href.
Generates tuple(href_string, first_byte, byte_length, anchor_text)
'''
ta... | [
"byte",
"-",
"based",
"state",
"machine",
"extractor",
"of",
"anchor",
"tags",
"so",
"we",
"can",
"compute",
"byte",
"offsets",
"for",
"anchor",
"texts",
"and",
"associate",
"them",
"with",
"their",
"href",
".",
"Generates",
"tuple",
"(",
"href_string",
"fir... | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_hyperlink_labels.py#L297-L370 | [
"def",
"byte_href_anchors_state_machine",
"(",
"self",
")",
":",
"tag_depth",
"=",
"0",
"a_tag_depth",
"=",
"0",
"vals",
"=",
"[",
"]",
"href",
"=",
"None",
"idx_bytes",
"=",
"enumerate",
"(",
"self",
".",
"clean_html",
")",
"while",
"1",
":",
"end_idx",
... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | hyperlink_labels.make_labels | Make a list of Labels for 'author' and the filtered hrefs &
anchors | streamcorpus_pipeline/_hyperlink_labels.py | def make_labels(self, clean_html, clean_visible=None):
'''
Make a list of Labels for 'author' and the filtered hrefs &
anchors
'''
if self.offset_type == OffsetType.BYTES:
parser = self.byte_href_anchors
elif self.offset_type == OffsetType.CHARS:
... | def make_labels(self, clean_html, clean_visible=None):
'''
Make a list of Labels for 'author' and the filtered hrefs &
anchors
'''
if self.offset_type == OffsetType.BYTES:
parser = self.byte_href_anchors
elif self.offset_type == OffsetType.CHARS:
... | [
"Make",
"a",
"list",
"of",
"Labels",
"for",
"author",
"and",
"the",
"filtered",
"hrefs",
"&",
"anchors"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_hyperlink_labels.py#L373-L418 | [
"def",
"make_labels",
"(",
"self",
",",
"clean_html",
",",
"clean_visible",
"=",
"None",
")",
":",
"if",
"self",
".",
"offset_type",
"==",
"OffsetType",
".",
"BYTES",
":",
"parser",
"=",
"self",
".",
"byte_href_anchors",
"elif",
"self",
".",
"offset_type",
... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | paths | yield all file paths under input_dir | examples/john_smith_chunk_writer.py | def paths(input_dir):
'yield all file paths under input_dir'
for root, dirs, fnames in os.walk(input_dir):
for i_fname in fnames:
i_path = os.path.join(root, i_fname)
yield i_path | def paths(input_dir):
'yield all file paths under input_dir'
for root, dirs, fnames in os.walk(input_dir):
for i_fname in fnames:
i_path = os.path.join(root, i_fname)
yield i_path | [
"yield",
"all",
"file",
"paths",
"under",
"input_dir"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/examples/john_smith_chunk_writer.py#L20-L25 | [
"def",
"paths",
"(",
"input_dir",
")",
":",
"for",
"root",
",",
"dirs",
",",
"fnames",
"in",
"os",
".",
"walk",
"(",
"input_dir",
")",
":",
"for",
"i_fname",
"in",
"fnames",
":",
"i_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"root",
",",
"i... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | Cassa._create_column_family | Creates a column family of the name 'family' and sets any of
the names in the bytes_column list to have the BYTES_TYPE.
key_validation_class defaults to TIME_UUID_TYPE and could also
be ASCII_TYPE for md5 hash keys, like we use for 'inbound' | streamcorpus_pipeline/_pycassa_simple_table.py | def _create_column_family(self, family, bytes_columns=[],
key_validation_class=TIME_UUID_TYPE):
'''
Creates a column family of the name 'family' and sets any of
the names in the bytes_column list to have the BYTES_TYPE.
key_validation_class defaults to TIM... | def _create_column_family(self, family, bytes_columns=[],
key_validation_class=TIME_UUID_TYPE):
'''
Creates a column family of the name 'family' and sets any of
the names in the bytes_column list to have the BYTES_TYPE.
key_validation_class defaults to TIM... | [
"Creates",
"a",
"column",
"family",
"of",
"the",
"name",
"family",
"and",
"sets",
"any",
"of",
"the",
"names",
"in",
"the",
"bytes_column",
"list",
"to",
"have",
"the",
"BYTES_TYPE",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_pycassa_simple_table.py#L95-L112 | [
"def",
"_create_column_family",
"(",
"self",
",",
"family",
",",
"bytes_columns",
"=",
"[",
"]",
",",
"key_validation_class",
"=",
"TIME_UUID_TYPE",
")",
":",
"sm",
"=",
"SystemManager",
"(",
"random",
".",
"choice",
"(",
"self",
".",
"server_list",
")",
")"... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | Cassa._create_counter_column_family | Creates a column family of the name 'family' and sets any of
the names in the bytes_column list to have the BYTES_TYPE.
key_validation_class defaults to TIME_UUID_TYPE and could also
be ASCII_TYPE for md5 hash keys, like we use for 'inbound' | streamcorpus_pipeline/_pycassa_simple_table.py | def _create_counter_column_family(self, family, counter_columns=[],
key_validation_class=UTF8Type):
'''
Creates a column family of the name 'family' and sets any of
the names in the bytes_column list to have the BYTES_TYPE.
key_validation_class defaults to ... | def _create_counter_column_family(self, family, counter_columns=[],
key_validation_class=UTF8Type):
'''
Creates a column family of the name 'family' and sets any of
the names in the bytes_column list to have the BYTES_TYPE.
key_validation_class defaults to ... | [
"Creates",
"a",
"column",
"family",
"of",
"the",
"name",
"family",
"and",
"sets",
"any",
"of",
"the",
"names",
"in",
"the",
"bytes_column",
"list",
"to",
"have",
"the",
"BYTES_TYPE",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_pycassa_simple_table.py#L114-L131 | [
"def",
"_create_counter_column_family",
"(",
"self",
",",
"family",
",",
"counter_columns",
"=",
"[",
"]",
",",
"key_validation_class",
"=",
"UTF8Type",
")",
":",
"sm",
"=",
"SystemManager",
"(",
"random",
".",
"choice",
"(",
"self",
".",
"server_list",
")",
... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | Cassa.tasks | generate the data objects for every task | streamcorpus_pipeline/_pycassa_simple_table.py | def tasks(self, key_prefix=''):
'''
generate the data objects for every task
'''
for row in self._tasks.get_range():
logger.debug(row)
if not row[0].startswith(key_prefix):
continue
data = json.loads(row[1]['task_data'])
dat... | def tasks(self, key_prefix=''):
'''
generate the data objects for every task
'''
for row in self._tasks.get_range():
logger.debug(row)
if not row[0].startswith(key_prefix):
continue
data = json.loads(row[1]['task_data'])
dat... | [
"generate",
"the",
"data",
"objects",
"for",
"every",
"task"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_pycassa_simple_table.py#L133-L143 | [
"def",
"tasks",
"(",
"self",
",",
"key_prefix",
"=",
"''",
")",
":",
"for",
"row",
"in",
"self",
".",
"_tasks",
".",
"get_range",
"(",
")",
":",
"logger",
".",
"debug",
"(",
"row",
")",
"if",
"not",
"row",
"[",
"0",
"]",
".",
"startswith",
"(",
... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | Cassa.get_random_available | get a random key out of the first max_iter rows | streamcorpus_pipeline/_pycassa_simple_table.py | def get_random_available(self, max_iter=10000):
'''
get a random key out of the first max_iter rows
'''
c = 1
keeper = None
## note the ConsistencyLevel here. If we do not do this, and
## get all slick with things like column_count=0 and filter
## empty F... | def get_random_available(self, max_iter=10000):
'''
get a random key out of the first max_iter rows
'''
c = 1
keeper = None
## note the ConsistencyLevel here. If we do not do this, and
## get all slick with things like column_count=0 and filter
## empty F... | [
"get",
"a",
"random",
"key",
"out",
"of",
"the",
"first",
"max_iter",
"rows"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_pycassa_simple_table.py#L199-L240 | [
"def",
"get_random_available",
"(",
"self",
",",
"max_iter",
"=",
"10000",
")",
":",
"c",
"=",
"1",
"keeper",
"=",
"None",
"## note the ConsistencyLevel here. If we do not do this, and",
"## get all slick with things like column_count=0 and filter",
"## empty False, then we can ... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | files | Iterate over <FILENAME> XML-like tags and tokenize with nltk | streamcorpus_pipeline/_lingpipe.py | def files(text):
'''
Iterate over <FILENAME> XML-like tags and tokenize with nltk
'''
for f_match in filename_re.finditer(text):
yield f_match.group('stream_id'), f_match.group('tagged_doc') | def files(text):
'''
Iterate over <FILENAME> XML-like tags and tokenize with nltk
'''
for f_match in filename_re.finditer(text):
yield f_match.group('stream_id'), f_match.group('tagged_doc') | [
"Iterate",
"over",
"<FILENAME",
">",
"XML",
"-",
"like",
"tags",
"and",
"tokenize",
"with",
"nltk"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_lingpipe.py#L52-L57 | [
"def",
"files",
"(",
"text",
")",
":",
"for",
"f_match",
"in",
"filename_re",
".",
"finditer",
"(",
"text",
")",
":",
"yield",
"f_match",
".",
"group",
"(",
"'stream_id'",
")",
",",
"f_match",
".",
"group",
"(",
"'tagged_doc'",
")"
] | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | LingPipeParser.sentences | Iterate over <s> XML-like tags and tokenize with nltk | streamcorpus_pipeline/_lingpipe.py | def sentences(self):
'''
Iterate over <s> XML-like tags and tokenize with nltk
'''
for sentence_id, node in enumerate(self.ner_dom.childNodes):
## increment the char index with any text before the <s>
## tag. Crucial assumption here is that the LingPipe XML
... | def sentences(self):
'''
Iterate over <s> XML-like tags and tokenize with nltk
'''
for sentence_id, node in enumerate(self.ner_dom.childNodes):
## increment the char index with any text before the <s>
## tag. Crucial assumption here is that the LingPipe XML
... | [
"Iterate",
"over",
"<s",
">",
"XML",
"-",
"like",
"tags",
"and",
"tokenize",
"with",
"nltk"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_lingpipe.py#L81-L124 | [
"def",
"sentences",
"(",
"self",
")",
":",
"for",
"sentence_id",
",",
"node",
"in",
"enumerate",
"(",
"self",
".",
"ner_dom",
".",
"childNodes",
")",
":",
"## increment the char index with any text before the <s>",
"## tag. Crucial assumption here is that the LingPipe XML"... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | LingPipeParser._make_token | Instantiates a Token from self._input_string[start:end] | streamcorpus_pipeline/_lingpipe.py | def _make_token(self, start, end):
'''
Instantiates a Token from self._input_string[start:end]
'''
## all thfift strings must be encoded first
tok_string = self._input_string[start:end].encode('utf-8')
if only_whitespace.match(tok_string):
## drop any tokens w... | def _make_token(self, start, end):
'''
Instantiates a Token from self._input_string[start:end]
'''
## all thfift strings must be encoded first
tok_string = self._input_string[start:end].encode('utf-8')
if only_whitespace.match(tok_string):
## drop any tokens w... | [
"Instantiates",
"a",
"Token",
"from",
"self",
".",
"_input_string",
"[",
"start",
":",
"end",
"]"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_lingpipe.py#L126-L156 | [
"def",
"_make_token",
"(",
"self",
",",
"start",
",",
"end",
")",
":",
"## all thfift strings must be encoded first",
"tok_string",
"=",
"self",
".",
"_input_string",
"[",
"start",
":",
"end",
"]",
".",
"encode",
"(",
"'utf-8'",
")",
"if",
"only_whitespace",
"... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | LingPipeParser.tokens | Tokenize all the words and preserve NER labels from ENAMEX tags | streamcorpus_pipeline/_lingpipe.py | def tokens(self, sentence_dom):
'''
Tokenize all the words and preserve NER labels from ENAMEX tags
'''
## keep track of sentence position, which is reset for each
## sentence, and used above in _make_token
self.sent_pos = 0
## keep track of mention_id, so we... | def tokens(self, sentence_dom):
'''
Tokenize all the words and preserve NER labels from ENAMEX tags
'''
## keep track of sentence position, which is reset for each
## sentence, and used above in _make_token
self.sent_pos = 0
## keep track of mention_id, so we... | [
"Tokenize",
"all",
"the",
"words",
"and",
"preserve",
"NER",
"labels",
"from",
"ENAMEX",
"tags"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_lingpipe.py#L158-L232 | [
"def",
"tokens",
"(",
"self",
",",
"sentence_dom",
")",
":",
"## keep track of sentence position, which is reset for each",
"## sentence, and used above in _make_token",
"self",
".",
"sent_pos",
"=",
"0",
"## keep track of mention_id, so we can distinguish adjacent",
"## multi-token ... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | lingpipe.get_sentences | parse the sentences and tokens out of the XML | streamcorpus_pipeline/_lingpipe.py | def get_sentences(self, ner_dom):
'''parse the sentences and tokens out of the XML'''
lp_parser = LingPipeParser(self.config)
lp_parser.set(ner_dom)
sentences = list( lp_parser.sentences() )
return sentences, lp_parser.relations, lp_parser.attributes | def get_sentences(self, ner_dom):
'''parse the sentences and tokens out of the XML'''
lp_parser = LingPipeParser(self.config)
lp_parser.set(ner_dom)
sentences = list( lp_parser.sentences() )
return sentences, lp_parser.relations, lp_parser.attributes | [
"parse",
"the",
"sentences",
"and",
"tokens",
"out",
"of",
"the",
"XML"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_lingpipe.py#L249-L254 | [
"def",
"get_sentences",
"(",
"self",
",",
"ner_dom",
")",
":",
"lp_parser",
"=",
"LingPipeParser",
"(",
"self",
".",
"config",
")",
"lp_parser",
".",
"set",
"(",
"ner_dom",
")",
"sentences",
"=",
"list",
"(",
"lp_parser",
".",
"sentences",
"(",
")",
")",... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | recursive_glob_with_tree | generate a list of tuples(new_base, list(paths to put there)
where the files are found inside of old_base/treeroot. | setup.py | def recursive_glob_with_tree(new_base, old_base, treeroot, pattern):
'''generate a list of tuples(new_base, list(paths to put there)
where the files are found inside of old_base/treeroot.
'''
results = []
old_cwd = os.getcwd()
os.chdir(old_base)
for rel_base, dirs, files in os.walk(treeroot)... | def recursive_glob_with_tree(new_base, old_base, treeroot, pattern):
'''generate a list of tuples(new_base, list(paths to put there)
where the files are found inside of old_base/treeroot.
'''
results = []
old_cwd = os.getcwd()
os.chdir(old_base)
for rel_base, dirs, files in os.walk(treeroot)... | [
"generate",
"a",
"list",
"of",
"tuples",
"(",
"new_base",
"list",
"(",
"paths",
"to",
"put",
"there",
")",
"where",
"the",
"files",
"are",
"found",
"inside",
"of",
"old_base",
"/",
"treeroot",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/setup.py#L35-L49 | [
"def",
"recursive_glob_with_tree",
"(",
"new_base",
",",
"old_base",
",",
"treeroot",
",",
"pattern",
")",
":",
"results",
"=",
"[",
"]",
"old_cwd",
"=",
"os",
".",
"getcwd",
"(",
")",
"os",
".",
"chdir",
"(",
"old_base",
")",
"for",
"rel_base",
",",
"... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | _retry | Decorator for methods that need many retries, because of
intermittent failures, such as AWS calls via boto, which has a
non-back-off retry. | streamcorpus_pipeline/_s3_storage.py | def _retry(func):
'''
Decorator for methods that need many retries, because of
intermittent failures, such as AWS calls via boto, which has a
non-back-off retry.
'''
def retry_func(self, *args, **kwargs):
tries = 1
while True:
# If a handler allows execution to contin... | def _retry(func):
'''
Decorator for methods that need many retries, because of
intermittent failures, such as AWS calls via boto, which has a
non-back-off retry.
'''
def retry_func(self, *args, **kwargs):
tries = 1
while True:
# If a handler allows execution to contin... | [
"Decorator",
"for",
"methods",
"that",
"need",
"many",
"retries",
"because",
"of",
"intermittent",
"failures",
"such",
"as",
"AWS",
"calls",
"via",
"boto",
"which",
"has",
"a",
"non",
"-",
"back",
"-",
"off",
"retry",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_s3_storage.py#L56-L95 | [
"def",
"_retry",
"(",
"func",
")",
":",
"def",
"retry_func",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"tries",
"=",
"1",
"while",
"True",
":",
"# If a handler allows execution to continue, then",
"# fall through and do a back-off retry.",
... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | verify_md5 | return True if okay, raise Exception if not | streamcorpus_pipeline/_s3_storage.py | def verify_md5(md5_expected, data, other_errors=None):
"return True if okay, raise Exception if not" # O_o ?
md5_recv = hashlib.md5(data).hexdigest()
if md5_expected != md5_recv:
if other_errors is not None:
logger.critical('\n'.join(other_errors))
raise FailedVerification('orig... | def verify_md5(md5_expected, data, other_errors=None):
"return True if okay, raise Exception if not" # O_o ?
md5_recv = hashlib.md5(data).hexdigest()
if md5_expected != md5_recv:
if other_errors is not None:
logger.critical('\n'.join(other_errors))
raise FailedVerification('orig... | [
"return",
"True",
"if",
"okay",
"raise",
"Exception",
"if",
"not"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_s3_storage.py#L114-L122 | [
"def",
"verify_md5",
"(",
"md5_expected",
",",
"data",
",",
"other_errors",
"=",
"None",
")",
":",
"# O_o ?",
"md5_recv",
"=",
"hashlib",
".",
"md5",
"(",
"data",
")",
".",
"hexdigest",
"(",
")",
"if",
"md5_expected",
"!=",
"md5_recv",
":",
"if",
"other_... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | get_bucket | This function is mostly about managing configuration, and then
finally returns a boto.Bucket object.
AWS credentials come first from config keys
aws_access_key_id_path, aws_secret_access_key_path (paths to one
line files); secondly from environment variables
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY... | streamcorpus_pipeline/_s3_storage.py | def get_bucket(config, bucket_name=None):
'''This function is mostly about managing configuration, and then
finally returns a boto.Bucket object.
AWS credentials come first from config keys
aws_access_key_id_path, aws_secret_access_key_path (paths to one
line files); secondly from environment varia... | def get_bucket(config, bucket_name=None):
'''This function is mostly about managing configuration, and then
finally returns a boto.Bucket object.
AWS credentials come first from config keys
aws_access_key_id_path, aws_secret_access_key_path (paths to one
line files); secondly from environment varia... | [
"This",
"function",
"is",
"mostly",
"about",
"managing",
"configuration",
"and",
"then",
"finally",
"returns",
"a",
"boto",
".",
"Bucket",
"object",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_s3_storage.py#L125-L161 | [
"def",
"get_bucket",
"(",
"config",
",",
"bucket_name",
"=",
"None",
")",
":",
"if",
"not",
"bucket_name",
":",
"if",
"'bucket'",
"not",
"in",
"config",
":",
"raise",
"ConfigurationError",
"(",
"'The \"bucket\" parameter is required for the s3 stages.'",
")",
"bucke... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | from_s3_chunks._decode | Given the raw data from s3, return a generator for the items
contained in that data. A generator is necessary to support
chunk files, but non-chunk files can be provided by a generator
that yields exactly one item.
Decoding works by case analysis on the config option
``input_for... | streamcorpus_pipeline/_s3_storage.py | def _decode(self, data):
'''
Given the raw data from s3, return a generator for the items
contained in that data. A generator is necessary to support
chunk files, but non-chunk files can be provided by a generator
that yields exactly one item.
Decoding works by case anal... | def _decode(self, data):
'''
Given the raw data from s3, return a generator for the items
contained in that data. A generator is necessary to support
chunk files, but non-chunk files can be provided by a generator
that yields exactly one item.
Decoding works by case anal... | [
"Given",
"the",
"raw",
"data",
"from",
"s3",
"return",
"a",
"generator",
"for",
"the",
"items",
"contained",
"in",
"that",
"data",
".",
"A",
"generator",
"is",
"necessary",
"to",
"support",
"chunk",
"files",
"but",
"non",
"-",
"chunk",
"files",
"can",
"b... | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_s3_storage.py#L265-L294 | [
"def",
"_decode",
"(",
"self",
",",
"data",
")",
":",
"informat",
"=",
"self",
".",
"config",
"[",
"'input_format'",
"]",
".",
"lower",
"(",
")",
"if",
"informat",
"==",
"'spinn3r'",
":",
"return",
"_generate_stream_items",
"(",
"data",
")",
"elif",
"inf... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | from_s3_chunks.get_chunk | return Chunk object full of records
bucket_name may be None | streamcorpus_pipeline/_s3_storage.py | def get_chunk(self, bucket_name, key_path):
'''return Chunk object full of records
bucket_name may be None'''
bucket = get_bucket(self.config, bucket_name=bucket_name)
key = bucket.get_key(key_path)
if key is None:
raise FailedExtraction('Key "%s" does not exist.' % k... | def get_chunk(self, bucket_name, key_path):
'''return Chunk object full of records
bucket_name may be None'''
bucket = get_bucket(self.config, bucket_name=bucket_name)
key = bucket.get_key(key_path)
if key is None:
raise FailedExtraction('Key "%s" does not exist.' % k... | [
"return",
"Chunk",
"object",
"full",
"of",
"records",
"bucket_name",
"may",
"be",
"None"
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_s3_storage.py#L297-L351 | [
"def",
"get_chunk",
"(",
"self",
",",
"bucket_name",
",",
"key_path",
")",
":",
"bucket",
"=",
"get_bucket",
"(",
"self",
".",
"config",
",",
"bucket_name",
"=",
"bucket_name",
")",
"key",
"=",
"bucket",
".",
"get_key",
"(",
"key_path",
")",
"if",
"key",... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | stream_id_to_kvlayer_key | Convert a text stream ID to a kvlayer key.
The return tuple can be used directly as a key in the
:data:`STREAM_ITEMS_TABLE` table.
:param str stream_id: stream ID to convert
:return: :mod:`kvlayer` key tuple
:raise exceptions.KeyError: if `stream_id` is malformed | streamcorpus_pipeline/_kvlayer_table_names.py | def stream_id_to_kvlayer_key(stream_id):
'''Convert a text stream ID to a kvlayer key.
The return tuple can be used directly as a key in the
:data:`STREAM_ITEMS_TABLE` table.
:param str stream_id: stream ID to convert
:return: :mod:`kvlayer` key tuple
:raise exceptions.KeyError: if `stream_id`... | def stream_id_to_kvlayer_key(stream_id):
'''Convert a text stream ID to a kvlayer key.
The return tuple can be used directly as a key in the
:data:`STREAM_ITEMS_TABLE` table.
:param str stream_id: stream ID to convert
:return: :mod:`kvlayer` key tuple
:raise exceptions.KeyError: if `stream_id`... | [
"Convert",
"a",
"text",
"stream",
"ID",
"to",
"a",
"kvlayer",
"key",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_kvlayer_table_names.py#L148-L171 | [
"def",
"stream_id_to_kvlayer_key",
"(",
"stream_id",
")",
":",
"# Reminder: stream_id is 1234567890-123456789abcdef...0",
"# where the first part is the (decimal) epoch_ticks and the second",
"# part is the (hex) doc_id",
"parts",
"=",
"stream_id",
".",
"split",
"(",
"'-'",
")",
"i... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | kvlayer_key_to_stream_id | Convert a kvlayer key to a text stream ID.
`k` should be of the same form produced by
:func:`stream_id_to_kvlayer_key`.
:param k: :mod:`kvlayer` key tuple
:return: converted stream ID
:returntype str: | streamcorpus_pipeline/_kvlayer_table_names.py | def kvlayer_key_to_stream_id(k):
'''Convert a kvlayer key to a text stream ID.
`k` should be of the same form produced by
:func:`stream_id_to_kvlayer_key`.
:param k: :mod:`kvlayer` key tuple
:return: converted stream ID
:returntype str:
'''
abs_url_hash, epoch_ticks = k
return '{0... | def kvlayer_key_to_stream_id(k):
'''Convert a kvlayer key to a text stream ID.
`k` should be of the same form produced by
:func:`stream_id_to_kvlayer_key`.
:param k: :mod:`kvlayer` key tuple
:return: converted stream ID
:returntype str:
'''
abs_url_hash, epoch_ticks = k
return '{0... | [
"Convert",
"a",
"kvlayer",
"key",
"to",
"a",
"text",
"stream",
"ID",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_kvlayer_table_names.py#L174-L187 | [
"def",
"kvlayer_key_to_stream_id",
"(",
"k",
")",
":",
"abs_url_hash",
",",
"epoch_ticks",
"=",
"k",
"return",
"'{0}-{1}'",
".",
"format",
"(",
"epoch_ticks",
",",
"base64",
".",
"b16encode",
"(",
"abs_url_hash",
")",
".",
"lower",
"(",
")",
")"
] | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | key_for_stream_item | Get a kvlayer key from a stream item.
The return tuple can be used directly as a key in the
:data:`STREAM_ITEMS_TABLE` table. Note that this recalculates the
stream ID, and if the internal data on the stream item is inconsistent
then this could return a different result from
:func:`stream_id_to_kv... | streamcorpus_pipeline/_kvlayer_table_names.py | def key_for_stream_item(si):
'''Get a kvlayer key from a stream item.
The return tuple can be used directly as a key in the
:data:`STREAM_ITEMS_TABLE` table. Note that this recalculates the
stream ID, and if the internal data on the stream item is inconsistent
then this could return a different re... | def key_for_stream_item(si):
'''Get a kvlayer key from a stream item.
The return tuple can be used directly as a key in the
:data:`STREAM_ITEMS_TABLE` table. Note that this recalculates the
stream ID, and if the internal data on the stream item is inconsistent
then this could return a different re... | [
"Get",
"a",
"kvlayer",
"key",
"from",
"a",
"stream",
"item",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_kvlayer_table_names.py#L190-L205 | [
"def",
"key_for_stream_item",
"(",
"si",
")",
":",
"# get binary 16 byte digest",
"urlhash",
"=",
"hashlib",
".",
"md5",
"(",
"si",
".",
"abs_url",
")",
".",
"digest",
"(",
")",
"return",
"(",
"urlhash",
",",
"int",
"(",
"si",
".",
"stream_time",
".",
"e... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | main | Serve up some ponies. | httpony/server.py | def main(argv=sys.argv):
args = parse(argv)
"""Serve up some ponies."""
hostname = args.listen
port = args.port
print(
"Making all your dreams for a pony come true on http://{0}:{1}.\n"
"Press Ctrl+C to quit.\n".format(hostname, port))
# Hush, werkzeug.
logging.getLogger('we... | def main(argv=sys.argv):
args = parse(argv)
"""Serve up some ponies."""
hostname = args.listen
port = args.port
print(
"Making all your dreams for a pony come true on http://{0}:{1}.\n"
"Press Ctrl+C to quit.\n".format(hostname, port))
# Hush, werkzeug.
logging.getLogger('we... | [
"Serve",
"up",
"some",
"ponies",
"."
] | mblayman/httpony | python | https://github.com/mblayman/httpony/blob/5af404d647a8dac8a043b64ea09882589b3b5247/httpony/server.py#L13-L27 | [
"def",
"main",
"(",
"argv",
"=",
"sys",
".",
"argv",
")",
":",
"args",
"=",
"parse",
"(",
"argv",
")",
"hostname",
"=",
"args",
".",
"listen",
"port",
"=",
"args",
".",
"port",
"print",
"(",
"\"Making all your dreams for a pony come true on http://{0}:{1}.\\n\... | 5af404d647a8dac8a043b64ea09882589b3b5247 |
test | build_parser | Build the parser that will have all available commands and options. | httpony/server.py | def build_parser():
"""Build the parser that will have all available commands and options."""
description = (
'HTTPony (pronounced aych-tee-tee-pony) is a simple HTTP '
'server that pretty prints HTTP requests to a terminal. It '
'is a useful aide for developing clients that send HTTP '
... | def build_parser():
"""Build the parser that will have all available commands and options."""
description = (
'HTTPony (pronounced aych-tee-tee-pony) is a simple HTTP '
'server that pretty prints HTTP requests to a terminal. It '
'is a useful aide for developing clients that send HTTP '
... | [
"Build",
"the",
"parser",
"that",
"will",
"have",
"all",
"available",
"commands",
"and",
"options",
"."
] | mblayman/httpony | python | https://github.com/mblayman/httpony/blob/5af404d647a8dac8a043b64ea09882589b3b5247/httpony/server.py#L40-L55 | [
"def",
"build_parser",
"(",
")",
":",
"description",
"=",
"(",
"'HTTPony (pronounced aych-tee-tee-pony) is a simple HTTP '",
"'server that pretty prints HTTP requests to a terminal. It '",
"'is a useful aide for developing clients that send HTTP '",
"'requests. HTTPony acts as a sink for a cli... | 5af404d647a8dac8a043b64ea09882589b3b5247 |
test | add_xpaths_to_stream_item | Mutably tag tokens with xpath offsets.
Given some stream item, this will tag all tokens from all taggings
in the document that contain character offsets. Note that some
tokens may not have computable xpath offsets, so an xpath offset
for those tokens will not be set. (See the documentation and
comm... | streamcorpus_pipeline/offsets.py | def add_xpaths_to_stream_item(si):
'''Mutably tag tokens with xpath offsets.
Given some stream item, this will tag all tokens from all taggings
in the document that contain character offsets. Note that some
tokens may not have computable xpath offsets, so an xpath offset
for those tokens will not b... | def add_xpaths_to_stream_item(si):
'''Mutably tag tokens with xpath offsets.
Given some stream item, this will tag all tokens from all taggings
in the document that contain character offsets. Note that some
tokens may not have computable xpath offsets, so an xpath offset
for those tokens will not b... | [
"Mutably",
"tag",
"tokens",
"with",
"xpath",
"offsets",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/offsets.py#L290-L323 | [
"def",
"add_xpaths_to_stream_item",
"(",
"si",
")",
":",
"def",
"sentences_to_xpaths",
"(",
"sentences",
")",
":",
"tokens",
"=",
"sentences_to_char_tokens",
"(",
"sentences",
")",
"offsets",
"=",
"char_tokens_to_char_offsets",
"(",
"tokens",
")",
"return",
"char_of... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | sentences_to_char_tokens | Convert stream item sentences to character ``Offset``s. | streamcorpus_pipeline/offsets.py | def sentences_to_char_tokens(si_sentences):
'''Convert stream item sentences to character ``Offset``s.'''
for sentence in si_sentences:
for token in sentence.tokens:
if OffsetType.CHARS in token.offsets:
yield token | def sentences_to_char_tokens(si_sentences):
'''Convert stream item sentences to character ``Offset``s.'''
for sentence in si_sentences:
for token in sentence.tokens:
if OffsetType.CHARS in token.offsets:
yield token | [
"Convert",
"stream",
"item",
"sentences",
"to",
"character",
"Offset",
"s",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/offsets.py#L326-L331 | [
"def",
"sentences_to_char_tokens",
"(",
"si_sentences",
")",
":",
"for",
"sentence",
"in",
"si_sentences",
":",
"for",
"token",
"in",
"sentence",
".",
"tokens",
":",
"if",
"OffsetType",
".",
"CHARS",
"in",
"token",
".",
"offsets",
":",
"yield",
"token"
] | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | char_tokens_to_char_offsets | Convert character ``Offset``s to character ranges. | streamcorpus_pipeline/offsets.py | def char_tokens_to_char_offsets(si_tokens):
'''Convert character ``Offset``s to character ranges.'''
for token in si_tokens:
offset = token.offsets[OffsetType.CHARS]
yield offset.first, offset.first + offset.length | def char_tokens_to_char_offsets(si_tokens):
'''Convert character ``Offset``s to character ranges.'''
for token in si_tokens:
offset = token.offsets[OffsetType.CHARS]
yield offset.first, offset.first + offset.length | [
"Convert",
"character",
"Offset",
"s",
"to",
"character",
"ranges",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/offsets.py#L334-L338 | [
"def",
"char_tokens_to_char_offsets",
"(",
"si_tokens",
")",
":",
"for",
"token",
"in",
"si_tokens",
":",
"offset",
"=",
"token",
".",
"offsets",
"[",
"OffsetType",
".",
"CHARS",
"]",
"yield",
"offset",
".",
"first",
",",
"offset",
".",
"first",
"+",
"offs... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | char_offsets_to_xpaths | Converts HTML and a sequence of char offsets to xpath offsets.
Returns a generator of :class:`streamcorpus.XpathRange` objects
in correspondences with the sequence of ``char_offsets`` given.
Namely, each ``XpathRange`` should address precisely the same text
as that ``char_offsets`` (sans the HTML).
... | streamcorpus_pipeline/offsets.py | def char_offsets_to_xpaths(html, char_offsets):
'''Converts HTML and a sequence of char offsets to xpath offsets.
Returns a generator of :class:`streamcorpus.XpathRange` objects
in correspondences with the sequence of ``char_offsets`` given.
Namely, each ``XpathRange`` should address precisely the same... | def char_offsets_to_xpaths(html, char_offsets):
'''Converts HTML and a sequence of char offsets to xpath offsets.
Returns a generator of :class:`streamcorpus.XpathRange` objects
in correspondences with the sequence of ``char_offsets`` given.
Namely, each ``XpathRange`` should address precisely the same... | [
"Converts",
"HTML",
"and",
"a",
"sequence",
"of",
"char",
"offsets",
"to",
"xpath",
"offsets",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/offsets.py#L341-L425 | [
"def",
"char_offsets_to_xpaths",
"(",
"html",
",",
"char_offsets",
")",
":",
"html",
"=",
"uni",
"(",
"html",
")",
"parser",
"=",
"XpathTextCollector",
"(",
")",
"prev_end",
"=",
"0",
"prev_progress",
"=",
"True",
"for",
"start",
",",
"end",
"in",
"char_of... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | stream_item_roundtrip_xpaths | Roundtrip all Xpath offsets in the given stream item.
For every token that has both ``CHARS`` and ``XPATH_CHARS``
offsets, slice the ``clean_html`` with the ``XPATH_CHARS`` offset
and check that it matches slicing ``clean_visible`` with the
``CHARS`` offset.
If this passes without triggering an as... | streamcorpus_pipeline/offsets.py | def stream_item_roundtrip_xpaths(si, quick=False):
'''Roundtrip all Xpath offsets in the given stream item.
For every token that has both ``CHARS`` and ``XPATH_CHARS``
offsets, slice the ``clean_html`` with the ``XPATH_CHARS`` offset
and check that it matches slicing ``clean_visible`` with the
``CH... | def stream_item_roundtrip_xpaths(si, quick=False):
'''Roundtrip all Xpath offsets in the given stream item.
For every token that has both ``CHARS`` and ``XPATH_CHARS``
offsets, slice the ``clean_html`` with the ``XPATH_CHARS`` offset
and check that it matches slicing ``clean_visible`` with the
``CH... | [
"Roundtrip",
"all",
"Xpath",
"offsets",
"in",
"the",
"given",
"stream",
"item",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/offsets.py#L435-L533 | [
"def",
"stream_item_roundtrip_xpaths",
"(",
"si",
",",
"quick",
"=",
"False",
")",
":",
"def",
"debug",
"(",
"s",
")",
":",
"logger",
".",
"warning",
"(",
"s",
")",
"def",
"print_window",
"(",
"token",
",",
"size",
"=",
"200",
")",
":",
"coffset",
"=... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | DepthStackEntry.add_element | Record that `tag` has been seen at this depth.
If `tag` is :class:`TextElement`, it records a text node. | streamcorpus_pipeline/offsets.py | def add_element(self, tag):
'''Record that `tag` has been seen at this depth.
If `tag` is :class:`TextElement`, it records a text node.
'''
# Collapse adjacent text nodes
if tag is TextElement and self.last_tag is TextElement:
return
self.last_tag = tag
... | def add_element(self, tag):
'''Record that `tag` has been seen at this depth.
If `tag` is :class:`TextElement`, it records a text node.
'''
# Collapse adjacent text nodes
if tag is TextElement and self.last_tag is TextElement:
return
self.last_tag = tag
... | [
"Record",
"that",
"tag",
"has",
"been",
"seen",
"at",
"this",
"depth",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/offsets.py#L83-L96 | [
"def",
"add_element",
"(",
"self",
",",
"tag",
")",
":",
"# Collapse adjacent text nodes",
"if",
"tag",
"is",
"TextElement",
"and",
"self",
".",
"last_tag",
"is",
"TextElement",
":",
"return",
"self",
".",
"last_tag",
"=",
"tag",
"if",
"tag",
"not",
"in",
... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | DepthStackEntry.xpath_piece | Get an XPath fragment for this location.
It is of the form ``tag[n]`` where `tag` is the most recent
element added and n is its position. | streamcorpus_pipeline/offsets.py | def xpath_piece(self):
'''Get an XPath fragment for this location.
It is of the form ``tag[n]`` where `tag` is the most recent
element added and n is its position.
'''
if self.last_tag is TextElement:
return 'text()[{count}]'.format(count=self.text_index())
... | def xpath_piece(self):
'''Get an XPath fragment for this location.
It is of the form ``tag[n]`` where `tag` is the most recent
element added and n is its position.
'''
if self.last_tag is TextElement:
return 'text()[{count}]'.format(count=self.text_index())
... | [
"Get",
"an",
"XPath",
"fragment",
"for",
"this",
"location",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/offsets.py#L98-L109 | [
"def",
"xpath_piece",
"(",
"self",
")",
":",
"if",
"self",
".",
"last_tag",
"is",
"TextElement",
":",
"return",
"'text()[{count}]'",
".",
"format",
"(",
"count",
"=",
"self",
".",
"text_index",
"(",
")",
")",
"else",
":",
"return",
"'{tag}[{count}]'",
".",... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | DepthStackEntry.text_index | Returns the one-based index of the current text node. | streamcorpus_pipeline/offsets.py | def text_index(self):
'''Returns the one-based index of the current text node.'''
# This is the number of text nodes we've seen so far.
# If we are currently in a text node, great; if not then add
# one for the text node that's about to begin.
i = self.tags.get(TextElement, 0)
... | def text_index(self):
'''Returns the one-based index of the current text node.'''
# This is the number of text nodes we've seen so far.
# If we are currently in a text node, great; if not then add
# one for the text node that's about to begin.
i = self.tags.get(TextElement, 0)
... | [
"Returns",
"the",
"one",
"-",
"based",
"index",
"of",
"the",
"current",
"text",
"node",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/offsets.py#L111-L119 | [
"def",
"text_index",
"(",
"self",
")",
":",
"# This is the number of text nodes we've seen so far.",
"# If we are currently in a text node, great; if not then add",
"# one for the text node that's about to begin.",
"i",
"=",
"self",
".",
"tags",
".",
"get",
"(",
"TextElement",
",... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | XpathTextCollector.xpath_offset | Returns a tuple of ``(xpath, character offset)``.
The ``xpath`` returned *uniquely* identifies the end of the
text node most recently inserted. The character offsets
indicates where the text inside the node ends. (When the text
node is empty, the offset returned is `0`.) | streamcorpus_pipeline/offsets.py | def xpath_offset(self):
'''Returns a tuple of ``(xpath, character offset)``.
The ``xpath`` returned *uniquely* identifies the end of the
text node most recently inserted. The character offsets
indicates where the text inside the node ends. (When the text
node is empty, the offse... | def xpath_offset(self):
'''Returns a tuple of ``(xpath, character offset)``.
The ``xpath`` returned *uniquely* identifies the end of the
text node most recently inserted. The character offsets
indicates where the text inside the node ends. (When the text
node is empty, the offse... | [
"Returns",
"a",
"tuple",
"of",
"(",
"xpath",
"character",
"offset",
")",
"."
] | trec-kba/streamcorpus-pipeline | python | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/offsets.py#L167-L180 | [
"def",
"xpath_offset",
"(",
"self",
")",
":",
"datai",
"=",
"self",
".",
"depth_stack",
"[",
"-",
"1",
"]",
".",
"text_index",
"(",
")",
"xpath",
"=",
"(",
"u'/'",
"+",
"u'/'",
".",
"join",
"(",
"dse",
".",
"xpath_piece",
"(",
")",
"for",
"dse",
... | 8bb82ea1beb83c6b40ed03fa1659df2897c2292a |
test | descendants | Yields all the elements descendant of elem in document order | pylib/uxml/treeutil.py | def descendants(elem):
'''
Yields all the elements descendant of elem in document order
'''
for child in elem.xml_children:
if isinstance(child, element):
yield child
yield from descendants(child) | def descendants(elem):
'''
Yields all the elements descendant of elem in document order
'''
for child in elem.xml_children:
if isinstance(child, element):
yield child
yield from descendants(child) | [
"Yields",
"all",
"the",
"elements",
"descendant",
"of",
"elem",
"in",
"document",
"order"
] | uogbuji/amara3-xml | python | https://github.com/uogbuji/amara3-xml/blob/88c18876418cffc89bb85b4a3193e5002b6b39a6/pylib/uxml/treeutil.py#L11-L18 | [
"def",
"descendants",
"(",
"elem",
")",
":",
"for",
"child",
"in",
"elem",
".",
"xml_children",
":",
"if",
"isinstance",
"(",
"child",
",",
"element",
")",
":",
"yield",
"child",
"yield",
"from",
"descendants",
"(",
"child",
")"
] | 88c18876418cffc89bb85b4a3193e5002b6b39a6 |
test | select_elements | Yields all the elements from the source
source - if an element, yields all child elements in order; if any other iterator yields the elements from that iterator | pylib/uxml/treeutil.py | def select_elements(source):
'''
Yields all the elements from the source
source - if an element, yields all child elements in order; if any other iterator yields the elements from that iterator
'''
if isinstance(source, element):
source = source.xml_children
return filter(lambda x: isins... | def select_elements(source):
'''
Yields all the elements from the source
source - if an element, yields all child elements in order; if any other iterator yields the elements from that iterator
'''
if isinstance(source, element):
source = source.xml_children
return filter(lambda x: isins... | [
"Yields",
"all",
"the",
"elements",
"from",
"the",
"source",
"source",
"-",
"if",
"an",
"element",
"yields",
"all",
"child",
"elements",
"in",
"order",
";",
"if",
"any",
"other",
"iterator",
"yields",
"the",
"elements",
"from",
"that",
"iterator"
] | uogbuji/amara3-xml | python | https://github.com/uogbuji/amara3-xml/blob/88c18876418cffc89bb85b4a3193e5002b6b39a6/pylib/uxml/treeutil.py#L21-L28 | [
"def",
"select_elements",
"(",
"source",
")",
":",
"if",
"isinstance",
"(",
"source",
",",
"element",
")",
":",
"source",
"=",
"source",
".",
"xml_children",
"return",
"filter",
"(",
"lambda",
"x",
":",
"isinstance",
"(",
"x",
",",
"element",
")",
",",
... | 88c18876418cffc89bb85b4a3193e5002b6b39a6 |
test | select_name | Yields all the elements with the given name
source - if an element, starts with all child elements in order; can also be any other iterator
name - will yield only elements with this name | pylib/uxml/treeutil.py | def select_name(source, name):
'''
Yields all the elements with the given name
source - if an element, starts with all child elements in order; can also be any other iterator
name - will yield only elements with this name
'''
return filter(lambda x: x.xml_name == name, select_elements(source)) | def select_name(source, name):
'''
Yields all the elements with the given name
source - if an element, starts with all child elements in order; can also be any other iterator
name - will yield only elements with this name
'''
return filter(lambda x: x.xml_name == name, select_elements(source)) | [
"Yields",
"all",
"the",
"elements",
"with",
"the",
"given",
"name",
"source",
"-",
"if",
"an",
"element",
"starts",
"with",
"all",
"child",
"elements",
"in",
"order",
";",
"can",
"also",
"be",
"any",
"other",
"iterator",
"name",
"-",
"will",
"yield",
"on... | uogbuji/amara3-xml | python | https://github.com/uogbuji/amara3-xml/blob/88c18876418cffc89bb85b4a3193e5002b6b39a6/pylib/uxml/treeutil.py#L31-L37 | [
"def",
"select_name",
"(",
"source",
",",
"name",
")",
":",
"return",
"filter",
"(",
"lambda",
"x",
":",
"x",
".",
"xml_name",
"==",
"name",
",",
"select_elements",
"(",
"source",
")",
")"
] | 88c18876418cffc89bb85b4a3193e5002b6b39a6 |
test | select_name_pattern | Yields elements from the source whose name matches the given regular expression pattern
source - if an element, starts with all child elements in order; can also be any other iterator
pat - re.pattern object | pylib/uxml/treeutil.py | def select_name_pattern(source, pat):
'''
Yields elements from the source whose name matches the given regular expression pattern
source - if an element, starts with all child elements in order; can also be any other iterator
pat - re.pattern object
'''
return filter(lambda x: pat.match(x.xml_na... | def select_name_pattern(source, pat):
'''
Yields elements from the source whose name matches the given regular expression pattern
source - if an element, starts with all child elements in order; can also be any other iterator
pat - re.pattern object
'''
return filter(lambda x: pat.match(x.xml_na... | [
"Yields",
"elements",
"from",
"the",
"source",
"whose",
"name",
"matches",
"the",
"given",
"regular",
"expression",
"pattern",
"source",
"-",
"if",
"an",
"element",
"starts",
"with",
"all",
"child",
"elements",
"in",
"order",
";",
"can",
"also",
"be",
"any",... | uogbuji/amara3-xml | python | https://github.com/uogbuji/amara3-xml/blob/88c18876418cffc89bb85b4a3193e5002b6b39a6/pylib/uxml/treeutil.py#L40-L46 | [
"def",
"select_name_pattern",
"(",
"source",
",",
"pat",
")",
":",
"return",
"filter",
"(",
"lambda",
"x",
":",
"pat",
".",
"match",
"(",
"x",
".",
"xml_name",
")",
"is",
"not",
"None",
",",
"select_elements",
"(",
"source",
")",
")"
] | 88c18876418cffc89bb85b4a3193e5002b6b39a6 |
test | select_value | Yields elements from the source with the given value (accumulated child text)
source - if an element, starts with all child elements in order; can also be any other iterator
val - string value to match | pylib/uxml/treeutil.py | def select_value(source, val):
'''
Yields elements from the source with the given value (accumulated child text)
source - if an element, starts with all child elements in order; can also be any other iterator
val - string value to match
'''
if isinstance(source, element):
source = source... | def select_value(source, val):
'''
Yields elements from the source with the given value (accumulated child text)
source - if an element, starts with all child elements in order; can also be any other iterator
val - string value to match
'''
if isinstance(source, element):
source = source... | [
"Yields",
"elements",
"from",
"the",
"source",
"with",
"the",
"given",
"value",
"(",
"accumulated",
"child",
"text",
")",
"source",
"-",
"if",
"an",
"element",
"starts",
"with",
"all",
"child",
"elements",
"in",
"order",
";",
"can",
"also",
"be",
"any",
... | uogbuji/amara3-xml | python | https://github.com/uogbuji/amara3-xml/blob/88c18876418cffc89bb85b4a3193e5002b6b39a6/pylib/uxml/treeutil.py#L49-L57 | [
"def",
"select_value",
"(",
"source",
",",
"val",
")",
":",
"if",
"isinstance",
"(",
"source",
",",
"element",
")",
":",
"source",
"=",
"source",
".",
"xml_children",
"return",
"filter",
"(",
"lambda",
"x",
":",
"x",
".",
"xml_value",
"==",
"val",
",",... | 88c18876418cffc89bb85b4a3193e5002b6b39a6 |
test | select_attribute | Yields elements from the source having the given attrivute, optionally with the given attribute value
source - if an element, starts with all child elements in order; can also be any other iterator
name - attribute name to check
val - if None check only for the existence of the attribute, otherwise compare ... | pylib/uxml/treeutil.py | def select_attribute(source, name, val=None):
'''
Yields elements from the source having the given attrivute, optionally with the given attribute value
source - if an element, starts with all child elements in order; can also be any other iterator
name - attribute name to check
val - if None check o... | def select_attribute(source, name, val=None):
'''
Yields elements from the source having the given attrivute, optionally with the given attribute value
source - if an element, starts with all child elements in order; can also be any other iterator
name - attribute name to check
val - if None check o... | [
"Yields",
"elements",
"from",
"the",
"source",
"having",
"the",
"given",
"attrivute",
"optionally",
"with",
"the",
"given",
"attribute",
"value",
"source",
"-",
"if",
"an",
"element",
"starts",
"with",
"all",
"child",
"elements",
"in",
"order",
";",
"can",
"... | uogbuji/amara3-xml | python | https://github.com/uogbuji/amara3-xml/blob/88c18876418cffc89bb85b4a3193e5002b6b39a6/pylib/uxml/treeutil.py#L60-L72 | [
"def",
"select_attribute",
"(",
"source",
",",
"name",
",",
"val",
"=",
"None",
")",
":",
"def",
"check",
"(",
"x",
")",
":",
"if",
"val",
"is",
"None",
":",
"return",
"name",
"in",
"x",
".",
"xml_attributes",
"else",
":",
"return",
"name",
"in",
"... | 88c18876418cffc89bb85b4a3193e5002b6b39a6 |
test | following_siblings | Yields elements and text which have the same parent as elem, but come afterward in document order | pylib/uxml/treeutil.py | def following_siblings(elem):
'''
Yields elements and text which have the same parent as elem, but come afterward in document order
'''
it = itertools.dropwhile(lambda x: x != elem, elem.xml_parent.xml_children)
next(it) #Skip the element itself
return it | def following_siblings(elem):
'''
Yields elements and text which have the same parent as elem, but come afterward in document order
'''
it = itertools.dropwhile(lambda x: x != elem, elem.xml_parent.xml_children)
next(it) #Skip the element itself
return it | [
"Yields",
"elements",
"and",
"text",
"which",
"have",
"the",
"same",
"parent",
"as",
"elem",
"but",
"come",
"afterward",
"in",
"document",
"order"
] | uogbuji/amara3-xml | python | https://github.com/uogbuji/amara3-xml/blob/88c18876418cffc89bb85b4a3193e5002b6b39a6/pylib/uxml/treeutil.py#L74-L80 | [
"def",
"following_siblings",
"(",
"elem",
")",
":",
"it",
"=",
"itertools",
".",
"dropwhile",
"(",
"lambda",
"x",
":",
"x",
"!=",
"elem",
",",
"elem",
".",
"xml_parent",
".",
"xml_children",
")",
"next",
"(",
"it",
")",
"#Skip the element itself",
"return"... | 88c18876418cffc89bb85b4a3193e5002b6b39a6 |
test | select_pattern | Yield descendant nodes matching the given pattern specification
pattern - tuple of steps, each of which matches an element by name, with "*" acting like a wildcard, descending the tree in tuple order
sort of like a subset of XPath in Python tuple form
state - for internal use only
pattern e... | pylib/uxml/treeutil.py | def select_pattern(node, pattern, state=None):
'''
Yield descendant nodes matching the given pattern specification
pattern - tuple of steps, each of which matches an element by name, with "*" acting like a wildcard, descending the tree in tuple order
sort of like a subset of XPath in Python ... | def select_pattern(node, pattern, state=None):
'''
Yield descendant nodes matching the given pattern specification
pattern - tuple of steps, each of which matches an element by name, with "*" acting like a wildcard, descending the tree in tuple order
sort of like a subset of XPath in Python ... | [
"Yield",
"descendant",
"nodes",
"matching",
"the",
"given",
"pattern",
"specification",
"pattern",
"-",
"tuple",
"of",
"steps",
"each",
"of",
"which",
"matches",
"an",
"element",
"by",
"name",
"with",
"*",
"acting",
"like",
"a",
"wildcard",
"descending",
"the"... | uogbuji/amara3-xml | python | https://github.com/uogbuji/amara3-xml/blob/88c18876418cffc89bb85b4a3193e5002b6b39a6/pylib/uxml/treeutil.py#L139-L173 | [
"def",
"select_pattern",
"(",
"node",
",",
"pattern",
",",
"state",
"=",
"None",
")",
":",
"if",
"state",
"is",
"None",
":",
"state",
"=",
"_prep_pattern",
"(",
"pattern",
")",
"#for child in select_elements(elem):",
"if",
"isinstance",
"(",
"node",
",",
"el... | 88c18876418cffc89bb85b4a3193e5002b6b39a6 |
test | make_pretty | Add text nodes as possible to all descendants of an element for spacing & indentation
to make the MicroXML as printed easier for people to read. Will not modify the
value of any text node which is not already entirely whitespace.
Warning: even though this operaton avoids molesting text nodes which already ... | pylib/uxml/treeutil.py | def make_pretty(elem, depth=0, indent=' '):
'''
Add text nodes as possible to all descendants of an element for spacing & indentation
to make the MicroXML as printed easier for people to read. Will not modify the
value of any text node which is not already entirely whitespace.
Warning: even though... | def make_pretty(elem, depth=0, indent=' '):
'''
Add text nodes as possible to all descendants of an element for spacing & indentation
to make the MicroXML as printed easier for people to read. Will not modify the
value of any text node which is not already entirely whitespace.
Warning: even though... | [
"Add",
"text",
"nodes",
"as",
"possible",
"to",
"all",
"descendants",
"of",
"an",
"element",
"for",
"spacing",
"&",
"indentation",
"to",
"make",
"the",
"MicroXML",
"as",
"printed",
"easier",
"for",
"people",
"to",
"read",
".",
"Will",
"not",
"modify",
"the... | uogbuji/amara3-xml | python | https://github.com/uogbuji/amara3-xml/blob/88c18876418cffc89bb85b4a3193e5002b6b39a6/pylib/uxml/treeutil.py#L175-L236 | [
"def",
"make_pretty",
"(",
"elem",
",",
"depth",
"=",
"0",
",",
"indent",
"=",
"' '",
")",
":",
"depth",
"+=",
"1",
"updated_child_list",
"=",
"[",
"]",
"updated_child_ix",
"=",
"0",
"for",
"child",
"in",
"elem",
".",
"xml_children",
":",
"if",
"isins... | 88c18876418cffc89bb85b4a3193e5002b6b39a6 |
test | call_inkscape | Call inkscape CLI with arguments and returns its return value.
Parameters
----------
args_string: list of str
inkscape_binpath: str
Returns
-------
return_value
Inkscape command CLI call return value. | docstamp/inkscape.py | def call_inkscape(args_strings, inkscape_binpath=None):
"""Call inkscape CLI with arguments and returns its return value.
Parameters
----------
args_string: list of str
inkscape_binpath: str
Returns
-------
return_value
Inkscape command CLI call return value.
"""
log.d... | def call_inkscape(args_strings, inkscape_binpath=None):
"""Call inkscape CLI with arguments and returns its return value.
Parameters
----------
args_string: list of str
inkscape_binpath: str
Returns
-------
return_value
Inkscape command CLI call return value.
"""
log.d... | [
"Call",
"inkscape",
"CLI",
"with",
"arguments",
"and",
"returns",
"its",
"return",
"value",
"."
] | PythonSanSebastian/docstamp | python | https://github.com/PythonSanSebastian/docstamp/blob/b43808f2e15351b0b2f0b7eade9c7ef319c9e646/docstamp/inkscape.py#L21-L45 | [
"def",
"call_inkscape",
"(",
"args_strings",
",",
"inkscape_binpath",
"=",
"None",
")",
":",
"log",
".",
"debug",
"(",
"'Looking for the binary file for inkscape.'",
")",
"if",
"inkscape_binpath",
"is",
"None",
":",
"inkscape_binpath",
"=",
"get_inkscape_binpath",
"("... | b43808f2e15351b0b2f0b7eade9c7ef319c9e646 |
test | inkscape_export | Call Inkscape to export the input_file to output_file using the
specific export argument flag for the output file type.
Parameters
----------
input_file: str
Path to the input file
output_file: str
Path to the output file
export_flag: str
Inkscape CLI flag to indicate... | docstamp/inkscape.py | def inkscape_export(input_file, output_file, export_flag="-A", dpi=90, inkscape_binpath=None):
""" Call Inkscape to export the input_file to output_file using the
specific export argument flag for the output file type.
Parameters
----------
input_file: str
Path to the input file
outpu... | def inkscape_export(input_file, output_file, export_flag="-A", dpi=90, inkscape_binpath=None):
""" Call Inkscape to export the input_file to output_file using the
specific export argument flag for the output file type.
Parameters
----------
input_file: str
Path to the input file
outpu... | [
"Call",
"Inkscape",
"to",
"export",
"the",
"input_file",
"to",
"output_file",
"using",
"the",
"specific",
"export",
"argument",
"flag",
"for",
"the",
"output",
"file",
"type",
"."
] | PythonSanSebastian/docstamp | python | https://github.com/PythonSanSebastian/docstamp/blob/b43808f2e15351b0b2f0b7eade9c7ef319c9e646/docstamp/inkscape.py#L48-L84 | [
"def",
"inkscape_export",
"(",
"input_file",
",",
"output_file",
",",
"export_flag",
"=",
"\"-A\"",
",",
"dpi",
"=",
"90",
",",
"inkscape_binpath",
"=",
"None",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"input_file",
")",
":",
"log",
... | b43808f2e15351b0b2f0b7eade9c7ef319c9e646 |
test | svg2pdf | Transform SVG file to PDF file | docstamp/inkscape.py | def svg2pdf(svg_file_path, pdf_file_path, dpi=150, command_binpath=None, support_unicode=False):
""" Transform SVG file to PDF file
"""
if support_unicode:
return rsvg_export(svg_file_path, pdf_file_path, dpi=dpi, rsvg_binpath=command_binpath)
return inkscape_export(svg_file_path, pdf_file_pat... | def svg2pdf(svg_file_path, pdf_file_path, dpi=150, command_binpath=None, support_unicode=False):
""" Transform SVG file to PDF file
"""
if support_unicode:
return rsvg_export(svg_file_path, pdf_file_path, dpi=dpi, rsvg_binpath=command_binpath)
return inkscape_export(svg_file_path, pdf_file_pat... | [
"Transform",
"SVG",
"file",
"to",
"PDF",
"file"
] | PythonSanSebastian/docstamp | python | https://github.com/PythonSanSebastian/docstamp/blob/b43808f2e15351b0b2f0b7eade9c7ef319c9e646/docstamp/inkscape.py#L87-L95 | [
"def",
"svg2pdf",
"(",
"svg_file_path",
",",
"pdf_file_path",
",",
"dpi",
"=",
"150",
",",
"command_binpath",
"=",
"None",
",",
"support_unicode",
"=",
"False",
")",
":",
"if",
"support_unicode",
":",
"return",
"rsvg_export",
"(",
"svg_file_path",
",",
"pdf_fi... | b43808f2e15351b0b2f0b7eade9c7ef319c9e646 |
test | svg2png | Transform SVG file to PNG file | docstamp/inkscape.py | def svg2png(svg_file_path, png_file_path, dpi=150, inkscape_binpath=None):
""" Transform SVG file to PNG file
"""
return inkscape_export(svg_file_path, png_file_path, export_flag="-e",
dpi=dpi, inkscape_binpath=inkscape_binpath) | def svg2png(svg_file_path, png_file_path, dpi=150, inkscape_binpath=None):
""" Transform SVG file to PNG file
"""
return inkscape_export(svg_file_path, png_file_path, export_flag="-e",
dpi=dpi, inkscape_binpath=inkscape_binpath) | [
"Transform",
"SVG",
"file",
"to",
"PNG",
"file"
] | PythonSanSebastian/docstamp | python | https://github.com/PythonSanSebastian/docstamp/blob/b43808f2e15351b0b2f0b7eade9c7ef319c9e646/docstamp/inkscape.py#L98-L102 | [
"def",
"svg2png",
"(",
"svg_file_path",
",",
"png_file_path",
",",
"dpi",
"=",
"150",
",",
"inkscape_binpath",
"=",
"None",
")",
":",
"return",
"inkscape_export",
"(",
"svg_file_path",
",",
"png_file_path",
",",
"export_flag",
"=",
"\"-e\"",
",",
"dpi",
"=",
... | b43808f2e15351b0b2f0b7eade9c7ef319c9e646 |
test | get_environment_for | Return a Jinja2 environment for where file_path is.
Parameters
----------
file_path: str
Returns
-------
jinja_env: Jinja2.Environment | docstamp/template.py | def get_environment_for(file_path):
"""Return a Jinja2 environment for where file_path is.
Parameters
----------
file_path: str
Returns
-------
jinja_env: Jinja2.Environment
"""
work_dir = os.path.dirname(os.path.abspath(file_path))
if not os.path.exists(work_dir):
ra... | def get_environment_for(file_path):
"""Return a Jinja2 environment for where file_path is.
Parameters
----------
file_path: str
Returns
-------
jinja_env: Jinja2.Environment
"""
work_dir = os.path.dirname(os.path.abspath(file_path))
if not os.path.exists(work_dir):
ra... | [
"Return",
"a",
"Jinja2",
"environment",
"for",
"where",
"file_path",
"is",
"."
] | PythonSanSebastian/docstamp | python | https://github.com/PythonSanSebastian/docstamp/blob/b43808f2e15351b0b2f0b7eade9c7ef319c9e646/docstamp/template.py#L26-L48 | [
"def",
"get_environment_for",
"(",
"file_path",
")",
":",
"work_dir",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"os",
".",
"path",
".",
"abspath",
"(",
"file_path",
")",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"work_dir",
")",
":"... | b43808f2e15351b0b2f0b7eade9c7ef319c9e646 |
test | TextDocument._setup_template_file | Setup self.template
Parameters
----------
template_file_path: str
Document template file path. | docstamp/template.py | def _setup_template_file(self, template_file_path):
""" Setup self.template
Parameters
----------
template_file_path: str
Document template file path.
"""
try:
template_file = template_file_path
template_env = get_environment_for(templ... | def _setup_template_file(self, template_file_path):
""" Setup self.template
Parameters
----------
template_file_path: str
Document template file path.
"""
try:
template_file = template_file_path
template_env = get_environment_for(templ... | [
"Setup",
"self",
".",
"template"
] | PythonSanSebastian/docstamp | python | https://github.com/PythonSanSebastian/docstamp/blob/b43808f2e15351b0b2f0b7eade9c7ef319c9e646/docstamp/template.py#L100-L117 | [
"def",
"_setup_template_file",
"(",
"self",
",",
"template_file_path",
")",
":",
"try",
":",
"template_file",
"=",
"template_file_path",
"template_env",
"=",
"get_environment_for",
"(",
"template_file_path",
")",
"template",
"=",
"template_env",
".",
"get_template",
"... | b43808f2e15351b0b2f0b7eade9c7ef319c9e646 |
test | TextDocument.fill | Fill the content of the document with the information in doc_contents.
Parameters
----------
doc_contents: dict
Set of values to set the template document.
Returns
-------
filled_doc: str
The content of the document with the template information ... | docstamp/template.py | def fill(self, doc_contents):
""" Fill the content of the document with the information in doc_contents.
Parameters
----------
doc_contents: dict
Set of values to set the template document.
Returns
-------
filled_doc: str
The content of t... | def fill(self, doc_contents):
""" Fill the content of the document with the information in doc_contents.
Parameters
----------
doc_contents: dict
Set of values to set the template document.
Returns
-------
filled_doc: str
The content of t... | [
"Fill",
"the",
"content",
"of",
"the",
"document",
"with",
"the",
"information",
"in",
"doc_contents",
"."
] | PythonSanSebastian/docstamp | python | https://github.com/PythonSanSebastian/docstamp/blob/b43808f2e15351b0b2f0b7eade9c7ef319c9e646/docstamp/template.py#L119-L140 | [
"def",
"fill",
"(",
"self",
",",
"doc_contents",
")",
":",
"try",
":",
"filled_doc",
"=",
"self",
".",
"template",
".",
"render",
"(",
"*",
"*",
"doc_contents",
")",
"except",
":",
"log",
".",
"exception",
"(",
"'Error rendering Document '",
"'for {}.'",
"... | b43808f2e15351b0b2f0b7eade9c7ef319c9e646 |
test | TextDocument.save_content | Save the content of the .txt file in a text file.
Parameters
----------
file_path: str
Path to the output file. | docstamp/template.py | def save_content(self, file_path, encoding='utf-8'):
""" Save the content of the .txt file in a text file.
Parameters
----------
file_path: str
Path to the output file.
"""
if self.file_content_ is None:
msg = 'Template content has not been update... | def save_content(self, file_path, encoding='utf-8'):
""" Save the content of the .txt file in a text file.
Parameters
----------
file_path: str
Path to the output file.
"""
if self.file_content_ is None:
msg = 'Template content has not been update... | [
"Save",
"the",
"content",
"of",
"the",
".",
"txt",
"file",
"in",
"a",
"text",
"file",
"."
] | PythonSanSebastian/docstamp | python | https://github.com/PythonSanSebastian/docstamp/blob/b43808f2e15351b0b2f0b7eade9c7ef319c9e646/docstamp/template.py#L142-L163 | [
"def",
"save_content",
"(",
"self",
",",
"file_path",
",",
"encoding",
"=",
"'utf-8'",
")",
":",
"if",
"self",
".",
"file_content_",
"is",
"None",
":",
"msg",
"=",
"'Template content has not been updated. \\\n Please fill the template before rendering it.'... | b43808f2e15351b0b2f0b7eade9c7ef319c9e646 |
test | TextDocument.from_template_file | Factory function to create a specific document of the
class given by the `command` or the extension of `template_file_path`.
See get_doctype_by_command and get_doctype_by_extension.
Parameters
----------
template_file_path: str
command: str
Returns
---... | docstamp/template.py | def from_template_file(cls, template_file_path, command=None):
""" Factory function to create a specific document of the
class given by the `command` or the extension of `template_file_path`.
See get_doctype_by_command and get_doctype_by_extension.
Parameters
----------
... | def from_template_file(cls, template_file_path, command=None):
""" Factory function to create a specific document of the
class given by the `command` or the extension of `template_file_path`.
See get_doctype_by_command and get_doctype_by_extension.
Parameters
----------
... | [
"Factory",
"function",
"to",
"create",
"a",
"specific",
"document",
"of",
"the",
"class",
"given",
"by",
"the",
"command",
"or",
"the",
"extension",
"of",
"template_file_path",
"."
] | PythonSanSebastian/docstamp | python | https://github.com/PythonSanSebastian/docstamp/blob/b43808f2e15351b0b2f0b7eade9c7ef319c9e646/docstamp/template.py#L170-L197 | [
"def",
"from_template_file",
"(",
"cls",
",",
"template_file_path",
",",
"command",
"=",
"None",
")",
":",
"# get template file extension",
"ext",
"=",
"os",
".",
"path",
".",
"basename",
"(",
"template_file_path",
")",
".",
"split",
"(",
"'.'",
")",
"[",
"-... | b43808f2e15351b0b2f0b7eade9c7ef319c9e646 |
test | SVGDocument.fill | Fill the content of the document with the information in doc_contents.
This is different from the TextDocument fill function, because this will
check for symbools in the values of `doc_content` and replace them
to good XML codes before filling the template.
Parameters
----------... | docstamp/template.py | def fill(self, doc_contents):
""" Fill the content of the document with the information in doc_contents.
This is different from the TextDocument fill function, because this will
check for symbools in the values of `doc_content` and replace them
to good XML codes before filling the templa... | def fill(self, doc_contents):
""" Fill the content of the document with the information in doc_contents.
This is different from the TextDocument fill function, because this will
check for symbools in the values of `doc_content` and replace them
to good XML codes before filling the templa... | [
"Fill",
"the",
"content",
"of",
"the",
"document",
"with",
"the",
"information",
"in",
"doc_contents",
".",
"This",
"is",
"different",
"from",
"the",
"TextDocument",
"fill",
"function",
"because",
"this",
"will",
"check",
"for",
"symbools",
"in",
"the",
"value... | PythonSanSebastian/docstamp | python | https://github.com/PythonSanSebastian/docstamp/blob/b43808f2e15351b0b2f0b7eade9c7ef319c9e646/docstamp/template.py#L204-L223 | [
"def",
"fill",
"(",
"self",
",",
"doc_contents",
")",
":",
"for",
"key",
",",
"content",
"in",
"doc_contents",
".",
"items",
"(",
")",
":",
"doc_contents",
"[",
"key",
"]",
"=",
"replace_chars_for_svg_code",
"(",
"content",
")",
"return",
"super",
"(",
"... | b43808f2e15351b0b2f0b7eade9c7ef319c9e646 |
test | SVGDocument.render | Save the content of the .svg file in the chosen rendered format.
Parameters
----------
file_path: str
Path to the output file.
Kwargs
------
file_type: str
Choices: 'png', 'pdf', 'svg'
Default: 'pdf'
dpi: int
Dots... | docstamp/template.py | def render(self, file_path, **kwargs):
""" Save the content of the .svg file in the chosen rendered format.
Parameters
----------
file_path: str
Path to the output file.
Kwargs
------
file_type: str
Choices: 'png', 'pdf', 'svg'
... | def render(self, file_path, **kwargs):
""" Save the content of the .svg file in the chosen rendered format.
Parameters
----------
file_path: str
Path to the output file.
Kwargs
------
file_type: str
Choices: 'png', 'pdf', 'svg'
... | [
"Save",
"the",
"content",
"of",
"the",
".",
"svg",
"file",
"in",
"the",
"chosen",
"rendered",
"format",
"."
] | PythonSanSebastian/docstamp | python | https://github.com/PythonSanSebastian/docstamp/blob/b43808f2e15351b0b2f0b7eade9c7ef319c9e646/docstamp/template.py#L225-L264 | [
"def",
"render",
"(",
"self",
",",
"file_path",
",",
"*",
"*",
"kwargs",
")",
":",
"temp",
"=",
"get_tempfile",
"(",
"suffix",
"=",
"'.svg'",
")",
"self",
".",
"save_content",
"(",
"temp",
".",
"name",
")",
"file_type",
"=",
"kwargs",
".",
"get",
"("... | b43808f2e15351b0b2f0b7eade9c7ef319c9e646 |
test | LateXDocument.render | Save the content of the .text file in the PDF.
Parameters
----------
file_path: str
Path to the output file. | docstamp/template.py | def render(self, file_path, **kwargs):
""" Save the content of the .text file in the PDF.
Parameters
----------
file_path: str
Path to the output file.
"""
temp = get_tempfile(suffix='.tex')
self.save_content(temp.name)
try:
self.... | def render(self, file_path, **kwargs):
""" Save the content of the .text file in the PDF.
Parameters
----------
file_path: str
Path to the output file.
"""
temp = get_tempfile(suffix='.tex')
self.save_content(temp.name)
try:
self.... | [
"Save",
"the",
"content",
"of",
"the",
".",
"text",
"file",
"in",
"the",
"PDF",
"."
] | PythonSanSebastian/docstamp | python | https://github.com/PythonSanSebastian/docstamp/blob/b43808f2e15351b0b2f0b7eade9c7ef319c9e646/docstamp/template.py#L272-L287 | [
"def",
"render",
"(",
"self",
",",
"file_path",
",",
"*",
"*",
"kwargs",
")",
":",
"temp",
"=",
"get_tempfile",
"(",
"suffix",
"=",
"'.tex'",
")",
"self",
".",
"save_content",
"(",
"temp",
".",
"name",
")",
"try",
":",
"self",
".",
"_render_function",
... | b43808f2e15351b0b2f0b7eade9c7ef319c9e646 |
test | parse | Convert XML 1.0 to MicroXML
source - XML 1.0 input
handler - MicroXML events handler
Returns uxml, extras
uxml - MicroXML element extracted from the source
extras - information to be preserved but not part of MicroXML, e.g. namespaces | pylib/uxml/xml.py | def parse(source, handler):
'''
Convert XML 1.0 to MicroXML
source - XML 1.0 input
handler - MicroXML events handler
Returns uxml, extras
uxml - MicroXML element extracted from the source
extras - information to be preserved but not part of MicroXML, e.g. namespaces
'''
h = expat_... | def parse(source, handler):
'''
Convert XML 1.0 to MicroXML
source - XML 1.0 input
handler - MicroXML events handler
Returns uxml, extras
uxml - MicroXML element extracted from the source
extras - information to be preserved but not part of MicroXML, e.g. namespaces
'''
h = expat_... | [
"Convert",
"XML",
"1",
".",
"0",
"to",
"MicroXML"
] | uogbuji/amara3-xml | python | https://github.com/uogbuji/amara3-xml/blob/88c18876418cffc89bb85b4a3193e5002b6b39a6/pylib/uxml/xml.py#L81-L102 | [
"def",
"parse",
"(",
"source",
",",
"handler",
")",
":",
"h",
"=",
"expat_callbacks",
"(",
"handler",
")",
"p",
"=",
"xml",
".",
"parsers",
".",
"expat",
".",
"ParserCreate",
"(",
"namespace_separator",
"=",
"' '",
")",
"p",
".",
"StartElementHandler",
"... | 88c18876418cffc89bb85b4a3193e5002b6b39a6 |
test | Melody.search | Start the optimisation/search using the supplied optimisation
method with the supplied inputs for the supplied function | src/melody/main.py | def search(self):
'''Start the optimisation/search using the supplied optimisation
method with the supplied inputs for the supplied function'''
search = self._method(inputs=self._inputs, function=self._function,
state=self._state)
search.run() | def search(self):
'''Start the optimisation/search using the supplied optimisation
method with the supplied inputs for the supplied function'''
search = self._method(inputs=self._inputs, function=self._function,
state=self._state)
search.run() | [
"Start",
"the",
"optimisation",
"/",
"search",
"using",
"the",
"supplied",
"optimisation",
"method",
"with",
"the",
"supplied",
"inputs",
"for",
"the",
"supplied",
"function"
] | rupertford/melody | python | https://github.com/rupertford/melody/blob/d50459880a87fdd1802c6893f6e12b52d51b3b91/src/melody/main.py#L79-L84 | [
"def",
"search",
"(",
"self",
")",
":",
"search",
"=",
"self",
".",
"_method",
"(",
"inputs",
"=",
"self",
".",
"_inputs",
",",
"function",
"=",
"self",
".",
"_function",
",",
"state",
"=",
"self",
".",
"_state",
")",
"search",
".",
"run",
"(",
")"... | d50459880a87fdd1802c6893f6e12b52d51b3b91 |
test | parse | Parse an input source with HTML text into an Amara 3 tree
>>> from amara3.uxml import html5
>>> import urllib.request
>>> with urllib.request.urlopen('http://uche.ogbuji.net/') as response:
... html5.parse(response)
#Warning: if you pass a string, you must make sure it's a byte string, not a ... | pylib/uxml/html5.py | def parse(source, prefixes=None, model=None, encoding=None, use_xhtml_ns=False):
'''
Parse an input source with HTML text into an Amara 3 tree
>>> from amara3.uxml import html5
>>> import urllib.request
>>> with urllib.request.urlopen('http://uche.ogbuji.net/') as response:
... html5.parse(... | def parse(source, prefixes=None, model=None, encoding=None, use_xhtml_ns=False):
'''
Parse an input source with HTML text into an Amara 3 tree
>>> from amara3.uxml import html5
>>> import urllib.request
>>> with urllib.request.urlopen('http://uche.ogbuji.net/') as response:
... html5.parse(... | [
"Parse",
"an",
"input",
"source",
"with",
"HTML",
"text",
"into",
"an",
"Amara",
"3",
"tree"
] | uogbuji/amara3-xml | python | https://github.com/uogbuji/amara3-xml/blob/88c18876418cffc89bb85b4a3193e5002b6b39a6/pylib/uxml/html5.py#L230-L250 | [
"def",
"parse",
"(",
"source",
",",
"prefixes",
"=",
"None",
",",
"model",
"=",
"None",
",",
"encoding",
"=",
"None",
",",
"use_xhtml_ns",
"=",
"False",
")",
":",
"def",
"get_tree_instance",
"(",
"namespaceHTMLElements",
",",
"use_xhtml_ns",
"=",
"use_xhtml_... | 88c18876418cffc89bb85b4a3193e5002b6b39a6 |
test | markup_fragment | Parse a fragment if markup in HTML mode, and return a bindery node
Warning: if you pass a string, you must make sure it's a byte string, not a Unicode object. You might also want to wrap it with amara.lib.inputsource.text if it's not obviously XML or HTML (for example it could be confused with a file name)
f... | pylib/uxml/html5.py | def markup_fragment(source, encoding=None):
'''
Parse a fragment if markup in HTML mode, and return a bindery node
Warning: if you pass a string, you must make sure it's a byte string, not a Unicode object. You might also want to wrap it with amara.lib.inputsource.text if it's not obviously XML or HTML (f... | def markup_fragment(source, encoding=None):
'''
Parse a fragment if markup in HTML mode, and return a bindery node
Warning: if you pass a string, you must make sure it's a byte string, not a Unicode object. You might also want to wrap it with amara.lib.inputsource.text if it's not obviously XML or HTML (f... | [
"Parse",
"a",
"fragment",
"if",
"markup",
"in",
"HTML",
"mode",
"and",
"return",
"a",
"bindery",
"node"
] | uogbuji/amara3-xml | python | https://github.com/uogbuji/amara3-xml/blob/88c18876418cffc89bb85b4a3193e5002b6b39a6/pylib/uxml/html5.py#L253-L267 | [
"def",
"markup_fragment",
"(",
"source",
",",
"encoding",
"=",
"None",
")",
":",
"doc",
"=",
"parse",
"(",
"source",
",",
"encoding",
"=",
"encoding",
")",
"frag",
"=",
"doc",
".",
"html",
".",
"body",
"return",
"frag"
] | 88c18876418cffc89bb85b4a3193e5002b6b39a6 |
test | node.insertText | Insert data as text in the current node, positioned before the
start of node insertBefore or to the end of the node's text. | pylib/uxml/html5.py | def insertText(self, data, insertBefore=None):
"""Insert data as text in the current node, positioned before the
start of node insertBefore or to the end of the node's text.
"""
if insertBefore:
self.insertBefore(tree.text(data), insertBefore)
else:
self.x... | def insertText(self, data, insertBefore=None):
"""Insert data as text in the current node, positioned before the
start of node insertBefore or to the end of the node's text.
"""
if insertBefore:
self.insertBefore(tree.text(data), insertBefore)
else:
self.x... | [
"Insert",
"data",
"as",
"text",
"in",
"the",
"current",
"node",
"positioned",
"before",
"the",
"start",
"of",
"node",
"insertBefore",
"or",
"to",
"the",
"end",
"of",
"the",
"node",
"s",
"text",
"."
] | uogbuji/amara3-xml | python | https://github.com/uogbuji/amara3-xml/blob/88c18876418cffc89bb85b4a3193e5002b6b39a6/pylib/uxml/html5.py#L37-L44 | [
"def",
"insertText",
"(",
"self",
",",
"data",
",",
"insertBefore",
"=",
"None",
")",
":",
"if",
"insertBefore",
":",
"self",
".",
"insertBefore",
"(",
"tree",
".",
"text",
"(",
"data",
")",
",",
"insertBefore",
")",
"else",
":",
"self",
".",
"xml_appe... | 88c18876418cffc89bb85b4a3193e5002b6b39a6 |
test | node.insertBefore | Insert node as a child of the current node, before refNode in the
list of child nodes. Raises ValueError if refNode is not a child of
the current node | pylib/uxml/html5.py | def insertBefore(self, node, refNode):
"""Insert node as a child of the current node, before refNode in the
list of child nodes. Raises ValueError if refNode is not a child of
the current node"""
offset = self.xml_children.index(refNode)
self.xml_insert(node, offset) | def insertBefore(self, node, refNode):
"""Insert node as a child of the current node, before refNode in the
list of child nodes. Raises ValueError if refNode is not a child of
the current node"""
offset = self.xml_children.index(refNode)
self.xml_insert(node, offset) | [
"Insert",
"node",
"as",
"a",
"child",
"of",
"the",
"current",
"node",
"before",
"refNode",
"in",
"the",
"list",
"of",
"child",
"nodes",
".",
"Raises",
"ValueError",
"if",
"refNode",
"is",
"not",
"a",
"child",
"of",
"the",
"current",
"node"
] | uogbuji/amara3-xml | python | https://github.com/uogbuji/amara3-xml/blob/88c18876418cffc89bb85b4a3193e5002b6b39a6/pylib/uxml/html5.py#L46-L51 | [
"def",
"insertBefore",
"(",
"self",
",",
"node",
",",
"refNode",
")",
":",
"offset",
"=",
"self",
".",
"xml_children",
".",
"index",
"(",
"refNode",
")",
"self",
".",
"xml_insert",
"(",
"node",
",",
"offset",
")"
] | 88c18876418cffc89bb85b4a3193e5002b6b39a6 |
test | element.cloneNode | Return a shallow copy of the current node i.e. a node with the same
name and attributes but with no parent or child nodes | pylib/uxml/html5.py | def cloneNode(self):
"""Return a shallow copy of the current node i.e. a node with the same
name and attributes but with no parent or child nodes
"""
attrs = self.xml_attributes.copy()
return element(self.xml_name, attrs=attrs) | def cloneNode(self):
"""Return a shallow copy of the current node i.e. a node with the same
name and attributes but with no parent or child nodes
"""
attrs = self.xml_attributes.copy()
return element(self.xml_name, attrs=attrs) | [
"Return",
"a",
"shallow",
"copy",
"of",
"the",
"current",
"node",
"i",
".",
"e",
".",
"a",
"node",
"with",
"the",
"same",
"name",
"and",
"attributes",
"but",
"with",
"no",
"parent",
"or",
"child",
"nodes"
] | uogbuji/amara3-xml | python | https://github.com/uogbuji/amara3-xml/blob/88c18876418cffc89bb85b4a3193e5002b6b39a6/pylib/uxml/html5.py#L125-L130 | [
"def",
"cloneNode",
"(",
"self",
")",
":",
"attrs",
"=",
"self",
".",
"xml_attributes",
".",
"copy",
"(",
")",
"return",
"element",
"(",
"self",
".",
"xml_name",
",",
"attrs",
"=",
"attrs",
")"
] | 88c18876418cffc89bb85b4a3193e5002b6b39a6 |
test | execute | A script that melody calls with each valid set of options. This
script runs the required code and returns the results. | examples/shallow/execute.py | def execute(option):
'''A script that melody calls with each valid set of options. This
script runs the required code and returns the results.'''
namelist_option = []
makefile_option = []
flags = ""
for entry in option:
key = entry.keys()[0]
if key == "Problem Size":
... | def execute(option):
'''A script that melody calls with each valid set of options. This
script runs the required code and returns the results.'''
namelist_option = []
makefile_option = []
flags = ""
for entry in option:
key = entry.keys()[0]
if key == "Problem Size":
... | [
"A",
"script",
"that",
"melody",
"calls",
"with",
"each",
"valid",
"set",
"of",
"options",
".",
"This",
"script",
"runs",
"the",
"required",
"code",
"and",
"returns",
"the",
"results",
"."
] | rupertford/melody | python | https://github.com/rupertford/melody/blob/d50459880a87fdd1802c6893f6e12b52d51b3b91/examples/shallow/execute.py#L40-L109 | [
"def",
"execute",
"(",
"option",
")",
":",
"namelist_option",
"=",
"[",
"]",
"makefile_option",
"=",
"[",
"]",
"flags",
"=",
"\"\"",
"for",
"entry",
"in",
"option",
":",
"key",
"=",
"entry",
".",
"keys",
"(",
")",
"[",
"0",
"]",
"if",
"key",
"==",
... | d50459880a87fdd1802c6893f6e12b52d51b3b91 |
test | create_vcard3_str | Create a vCard3.0 string with the given parameters.
Reference: http://www.evenx.com/vcard-3-0-format-specification | docstamp/vcard.py | def create_vcard3_str(name, surname, displayname, email='', org='', title='', url='', note=''):
""" Create a vCard3.0 string with the given parameters.
Reference: http://www.evenx.com/vcard-3-0-format-specification
"""
vcard = []
vcard += ['BEGIN:VCARD']
vcard += ['VERSION:3.0']
if name and... | def create_vcard3_str(name, surname, displayname, email='', org='', title='', url='', note=''):
""" Create a vCard3.0 string with the given parameters.
Reference: http://www.evenx.com/vcard-3-0-format-specification
"""
vcard = []
vcard += ['BEGIN:VCARD']
vcard += ['VERSION:3.0']
if name and... | [
"Create",
"a",
"vCard3",
".",
"0",
"string",
"with",
"the",
"given",
"parameters",
".",
"Reference",
":",
"http",
":",
"//",
"www",
".",
"evenx",
".",
"com",
"/",
"vcard",
"-",
"3",
"-",
"0",
"-",
"format",
"-",
"specification"
] | PythonSanSebastian/docstamp | python | https://github.com/PythonSanSebastian/docstamp/blob/b43808f2e15351b0b2f0b7eade9c7ef319c9e646/docstamp/vcard.py#L6-L40 | [
"def",
"create_vcard3_str",
"(",
"name",
",",
"surname",
",",
"displayname",
",",
"email",
"=",
"''",
",",
"org",
"=",
"''",
",",
"title",
"=",
"''",
",",
"url",
"=",
"''",
",",
"note",
"=",
"''",
")",
":",
"vcard",
"=",
"[",
"]",
"vcard",
"+=",
... | b43808f2e15351b0b2f0b7eade9c7ef319c9e646 |
test | strval | XPath-like string value of node | pylib/uxml/tree.py | def strval(node, outermost=True):
'''
XPath-like string value of node
'''
if not isinstance(node, element):
return node.xml_value if outermost else [node.xml_value]
accumulator = []
for child in node.xml_children:
if isinstance(child, text):
accumulator.append(child.x... | def strval(node, outermost=True):
'''
XPath-like string value of node
'''
if not isinstance(node, element):
return node.xml_value if outermost else [node.xml_value]
accumulator = []
for child in node.xml_children:
if isinstance(child, text):
accumulator.append(child.x... | [
"XPath",
"-",
"like",
"string",
"value",
"of",
"node"
] | uogbuji/amara3-xml | python | https://github.com/uogbuji/amara3-xml/blob/88c18876418cffc89bb85b4a3193e5002b6b39a6/pylib/uxml/tree.py#L135-L148 | [
"def",
"strval",
"(",
"node",
",",
"outermost",
"=",
"True",
")",
":",
"if",
"not",
"isinstance",
"(",
"node",
",",
"element",
")",
":",
"return",
"node",
".",
"xml_value",
"if",
"outermost",
"else",
"[",
"node",
".",
"xml_value",
"]",
"accumulator",
"... | 88c18876418cffc89bb85b4a3193e5002b6b39a6 |
test | element.xml_insert | Append a node as the last child
child - the child to append. If a string, convert to a text node, for convenience | pylib/uxml/tree.py | def xml_insert(self, child, index=-1):
'''
Append a node as the last child
child - the child to append. If a string, convert to a text node, for convenience
'''
if isinstance(child, str):
child = text(child, parent=self)
else:
child._xml_parent = ... | def xml_insert(self, child, index=-1):
'''
Append a node as the last child
child - the child to append. If a string, convert to a text node, for convenience
'''
if isinstance(child, str):
child = text(child, parent=self)
else:
child._xml_parent = ... | [
"Append",
"a",
"node",
"as",
"the",
"last",
"child"
] | uogbuji/amara3-xml | python | https://github.com/uogbuji/amara3-xml/blob/88c18876418cffc89bb85b4a3193e5002b6b39a6/pylib/uxml/tree.py#L82-L96 | [
"def",
"xml_insert",
"(",
"self",
",",
"child",
",",
"index",
"=",
"-",
"1",
")",
":",
"if",
"isinstance",
"(",
"child",
",",
"str",
")",
":",
"child",
"=",
"text",
"(",
"child",
",",
"parent",
"=",
"self",
")",
"else",
":",
"child",
".",
"_xml_p... | 88c18876418cffc89bb85b4a3193e5002b6b39a6 |
test | parse_options | Commandline options arguments parsing. | notification_google_calendar.py | def parse_options():
"""
Commandline options arguments parsing.
"""
# build options and help
version = "%%prog {version}".format(version=__version__)
parser = OptionParser(version=version)
parser.add_option(
"-u", "--username", action="store", dest="username",
type="string",... | def parse_options():
"""
Commandline options arguments parsing.
"""
# build options and help
version = "%%prog {version}".format(version=__version__)
parser = OptionParser(version=version)
parser.add_option(
"-u", "--username", action="store", dest="username",
type="string",... | [
"Commandline",
"options",
"arguments",
"parsing",
"."
] | vint21h/nagios-notification-google-calendar | python | https://github.com/vint21h/nagios-notification-google-calendar/blob/ef2b58c939d9d55a69a54b4e6a3fd9b61bde50d4/notification_google_calendar.py#L55-L104 | [
"def",
"parse_options",
"(",
")",
":",
"# build options and help",
"version",
"=",
"\"%%prog {version}\"",
".",
"format",
"(",
"version",
"=",
"__version__",
")",
"parser",
"=",
"OptionParser",
"(",
"version",
"=",
"version",
")",
"parser",
".",
"add_option",
"(... | ef2b58c939d9d55a69a54b4e6a3fd9b61bde50d4 |
test | parse_config | Get settings from config file. | notification_google_calendar.py | def parse_config(options):
"""
Get settings from config file.
"""
if os.path.exists(options.config):
config = ConfigParser.ConfigParser()
try:
config.read(options.config)
except Exception, err:
if not options.quiet:
sys.stderr.write("ERROR... | def parse_config(options):
"""
Get settings from config file.
"""
if os.path.exists(options.config):
config = ConfigParser.ConfigParser()
try:
config.read(options.config)
except Exception, err:
if not options.quiet:
sys.stderr.write("ERROR... | [
"Get",
"settings",
"from",
"config",
"file",
"."
] | vint21h/nagios-notification-google-calendar | python | https://github.com/vint21h/nagios-notification-google-calendar/blob/ef2b58c939d9d55a69a54b4e6a3fd9b61bde50d4/notification_google_calendar.py#L107-L145 | [
"def",
"parse_config",
"(",
"options",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"options",
".",
"config",
")",
":",
"config",
"=",
"ConfigParser",
".",
"ConfigParser",
"(",
")",
"try",
":",
"config",
".",
"read",
"(",
"options",
".",
"c... | ef2b58c939d9d55a69a54b4e6a3fd9b61bde50d4 |
test | get_google_credentials | Get google API credentials for user. | notification_google_calendar.py | def get_google_credentials(options, config):
"""
Get google API credentials for user.
"""
try:
if options.get_google_credentials:
flow = flow_from_clientsecrets(config["secrets"], scope=SCOPE, redirect_uri="oob")
sys.stdout.write("Follow this URL: {url} and grant access ... | def get_google_credentials(options, config):
"""
Get google API credentials for user.
"""
try:
if options.get_google_credentials:
flow = flow_from_clientsecrets(config["secrets"], scope=SCOPE, redirect_uri="oob")
sys.stdout.write("Follow this URL: {url} and grant access ... | [
"Get",
"google",
"API",
"credentials",
"for",
"user",
"."
] | vint21h/nagios-notification-google-calendar | python | https://github.com/vint21h/nagios-notification-google-calendar/blob/ef2b58c939d9d55a69a54b4e6a3fd9b61bde50d4/notification_google_calendar.py#L148-L170 | [
"def",
"get_google_credentials",
"(",
"options",
",",
"config",
")",
":",
"try",
":",
"if",
"options",
".",
"get_google_credentials",
":",
"flow",
"=",
"flow_from_clientsecrets",
"(",
"config",
"[",
"\"secrets\"",
"]",
",",
"scope",
"=",
"SCOPE",
",",
"redirec... | ef2b58c939d9d55a69a54b4e6a3fd9b61bde50d4 |
test | create_event_datetimes | Create event start and end datetimes. | notification_google_calendar.py | def create_event_datetimes(options, config):
"""
Create event start and end datetimes.
"""
now = datetime.datetime.now()
return {
"start": {
"dateTime": (now + datetime.timedelta(minutes=int(config["start"]))).strftime(DT_FORMAT),
"timeZone": options.timezone,
... | def create_event_datetimes(options, config):
"""
Create event start and end datetimes.
"""
now = datetime.datetime.now()
return {
"start": {
"dateTime": (now + datetime.timedelta(minutes=int(config["start"]))).strftime(DT_FORMAT),
"timeZone": options.timezone,
... | [
"Create",
"event",
"start",
"and",
"end",
"datetimes",
"."
] | vint21h/nagios-notification-google-calendar | python | https://github.com/vint21h/nagios-notification-google-calendar/blob/ef2b58c939d9d55a69a54b4e6a3fd9b61bde50d4/notification_google_calendar.py#L173-L189 | [
"def",
"create_event_datetimes",
"(",
"options",
",",
"config",
")",
":",
"now",
"=",
"datetime",
".",
"datetime",
".",
"now",
"(",
")",
"return",
"{",
"\"start\"",
":",
"{",
"\"dateTime\"",
":",
"(",
"now",
"+",
"datetime",
".",
"timedelta",
"(",
"minut... | ef2b58c939d9d55a69a54b4e6a3fd9b61bde50d4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.