repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/commands/list_.py | _get_package_status | def _get_package_status(package):
"""Get the status for a package."""
status = package["status_str"] or "Unknown"
stage = package["stage_str"] or "Unknown"
if stage == "Fully Synchronised":
return status
return "%(status)s / %(stage)s" % {"status": status, "stage": stage} | python | def _get_package_status(package):
"""Get the status for a package."""
status = package["status_str"] or "Unknown"
stage = package["stage_str"] or "Unknown"
if stage == "Fully Synchronised":
return status
return "%(status)s / %(stage)s" % {"status": status, "stage": stage} | [
"def",
"_get_package_status",
"(",
"package",
")",
":",
"status",
"=",
"package",
"[",
"\"status_str\"",
"]",
"or",
"\"Unknown\"",
"stage",
"=",
"package",
"[",
"\"stage_str\"",
"]",
"or",
"\"Unknown\"",
"if",
"stage",
"==",
"\"Fully Synchronised\"",
":",
"retur... | Get the status for a package. | [
"Get",
"the",
"status",
"for",
"a",
"package",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/commands/list_.py#L292-L298 |
kalefranz/auxlib | auxlib/type_coercion.py | boolify | def boolify(value, nullable=False, return_string=False):
"""Convert a number, string, or sequence type into a pure boolean.
Args:
value (number, string, sequence): pretty much anything
Returns:
bool: boolean representation of the given value
Examples:
>>> [boolify(x) for x in ... | python | def boolify(value, nullable=False, return_string=False):
"""Convert a number, string, or sequence type into a pure boolean.
Args:
value (number, string, sequence): pretty much anything
Returns:
bool: boolean representation of the given value
Examples:
>>> [boolify(x) for x in ... | [
"def",
"boolify",
"(",
"value",
",",
"nullable",
"=",
"False",
",",
"return_string",
"=",
"False",
")",
":",
"# cast number types naturally",
"if",
"isinstance",
"(",
"value",
",",
"BOOL_COERCEABLE_TYPES",
")",
":",
"return",
"bool",
"(",
"value",
")",
"# try ... | Convert a number, string, or sequence type into a pure boolean.
Args:
value (number, string, sequence): pretty much anything
Returns:
bool: boolean representation of the given value
Examples:
>>> [boolify(x) for x in ('yes', 'no')]
[True, False]
>>> [boolify(x) for... | [
"Convert",
"a",
"number",
"string",
"or",
"sequence",
"type",
"into",
"a",
"pure",
"boolean",
"."
] | train | https://github.com/kalefranz/auxlib/blob/6ff2d6b57d128d0b9ed8f01ad83572e938da064f/auxlib/type_coercion.py#L126-L169 |
kalefranz/auxlib | auxlib/type_coercion.py | typify | def typify(value, type_hint=None):
"""Take a primitive value, usually a string, and try to make a more relevant type out of it.
An optional type_hint will try to coerce the value to that type.
Args:
value (Any): Usually a string, not a sequence
type_hint (type or Tuple[type]):
Examples... | python | def typify(value, type_hint=None):
"""Take a primitive value, usually a string, and try to make a more relevant type out of it.
An optional type_hint will try to coerce the value to that type.
Args:
value (Any): Usually a string, not a sequence
type_hint (type or Tuple[type]):
Examples... | [
"def",
"typify",
"(",
"value",
",",
"type_hint",
"=",
"None",
")",
":",
"# value must be a string, or there at least needs to be a type hint",
"if",
"isinstance",
"(",
"value",
",",
"string_types",
")",
":",
"value",
"=",
"value",
".",
"strip",
"(",
")",
"elif",
... | Take a primitive value, usually a string, and try to make a more relevant type out of it.
An optional type_hint will try to coerce the value to that type.
Args:
value (Any): Usually a string, not a sequence
type_hint (type or Tuple[type]):
Examples:
>>> typify('32')
32
... | [
"Take",
"a",
"primitive",
"value",
"usually",
"a",
"string",
"and",
"try",
"to",
"make",
"a",
"more",
"relevant",
"type",
"out",
"of",
"it",
".",
"An",
"optional",
"type_hint",
"will",
"try",
"to",
"coerce",
"the",
"value",
"to",
"that",
"type",
"."
] | train | https://github.com/kalefranz/auxlib/blob/6ff2d6b57d128d0b9ed8f01ad83572e938da064f/auxlib/type_coercion.py#L185-L251 |
kalefranz/auxlib | auxlib/type_coercion.py | listify | def listify(val, return_type=tuple):
"""
Examples:
>>> listify('abc', return_type=list)
['abc']
>>> listify(None)
()
>>> listify(False)
(False,)
>>> listify(('a', 'b', 'c'), return_type=list)
['a', 'b', 'c']
"""
# TODO: flatlistify((1, 2, 3... | python | def listify(val, return_type=tuple):
"""
Examples:
>>> listify('abc', return_type=list)
['abc']
>>> listify(None)
()
>>> listify(False)
(False,)
>>> listify(('a', 'b', 'c'), return_type=list)
['a', 'b', 'c']
"""
# TODO: flatlistify((1, 2, 3... | [
"def",
"listify",
"(",
"val",
",",
"return_type",
"=",
"tuple",
")",
":",
"# TODO: flatlistify((1, 2, 3), 4, (5, 6, 7))",
"if",
"val",
"is",
"None",
":",
"return",
"return_type",
"(",
")",
"elif",
"isiterable",
"(",
"val",
")",
":",
"return",
"return_type",
"(... | Examples:
>>> listify('abc', return_type=list)
['abc']
>>> listify(None)
()
>>> listify(False)
(False,)
>>> listify(('a', 'b', 'c'), return_type=list)
['a', 'b', 'c'] | [
"Examples",
":",
">>>",
"listify",
"(",
"abc",
"return_type",
"=",
"list",
")",
"[",
"abc",
"]",
">>>",
"listify",
"(",
"None",
")",
"()",
">>>",
"listify",
"(",
"False",
")",
"(",
"False",
")",
">>>",
"listify",
"((",
"a",
"b",
"c",
")",
"return_t... | train | https://github.com/kalefranz/auxlib/blob/6ff2d6b57d128d0b9ed8f01ad83572e938da064f/auxlib/type_coercion.py#L273-L291 |
visualfabriq/bquery | bquery/toplevel.py | open | def open(rootdir, mode='a'):
# ----------------------------------------------------------------------
# https://github.com/Blosc/bcolz/blob/master/bcolz/toplevel.py#L104-L132
# ----------------------------------------------------------------------
"""
open(rootdir, mode='a')
Open a disk-based c... | python | def open(rootdir, mode='a'):
# ----------------------------------------------------------------------
# https://github.com/Blosc/bcolz/blob/master/bcolz/toplevel.py#L104-L132
# ----------------------------------------------------------------------
"""
open(rootdir, mode='a')
Open a disk-based c... | [
"def",
"open",
"(",
"rootdir",
",",
"mode",
"=",
"'a'",
")",
":",
"# ----------------------------------------------------------------------",
"# https://github.com/Blosc/bcolz/blob/master/bcolz/toplevel.py#L104-L132",
"# ----------------------------------------------------------------------"... | open(rootdir, mode='a')
Open a disk-based carray/ctable.
This function could be used to open bcolz objects as bquery objects to
perform queries on them.
Parameters
----------
rootdir : pathname (string)
The directory hosting the carray/ctable object.
mode : the open mode (string)
... | [
"open",
"(",
"rootdir",
"mode",
"=",
"a",
")"
] | train | https://github.com/visualfabriq/bquery/blob/3702e974696e22876944a3339affad2f29e1ee06/bquery/toplevel.py#L8-L41 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/commands/delete.py | delete | def delete(ctx, opts, owner_repo_package, yes):
"""
Delete a package from a repository.
- OWNER/REPO/PACKAGE: Specify the OWNER namespace (i.e. user or org), the
REPO name where the package is stored, and the PACKAGE name (slug) of the
package itself. All separated by a slash.
Example: 'your... | python | def delete(ctx, opts, owner_repo_package, yes):
"""
Delete a package from a repository.
- OWNER/REPO/PACKAGE: Specify the OWNER namespace (i.e. user or org), the
REPO name where the package is stored, and the PACKAGE name (slug) of the
package itself. All separated by a slash.
Example: 'your... | [
"def",
"delete",
"(",
"ctx",
",",
"opts",
",",
"owner_repo_package",
",",
"yes",
")",
":",
"owner",
",",
"repo",
",",
"slug",
"=",
"owner_repo_package",
"delete_args",
"=",
"{",
"\"owner\"",
":",
"click",
".",
"style",
"(",
"owner",
",",
"bold",
"=",
"... | Delete a package from a repository.
- OWNER/REPO/PACKAGE: Specify the OWNER namespace (i.e. user or org), the
REPO name where the package is stored, and the PACKAGE name (slug) of the
package itself. All separated by a slash.
Example: 'your-org/awesome-repo/better-pkg'. | [
"Delete",
"a",
"package",
"from",
"a",
"repository",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/commands/delete.py#L32-L63 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/commands/entitlements.py | validate_owner_repo_identifier | def validate_owner_repo_identifier(ctx, param, value):
"""Ensure that owner/repo/identifier is formatted correctly."""
# pylint: disable=unused-argument
form = "OWNER/REPO/IDENTIFIER"
return validators.validate_slashes(param, value, minimum=3, maximum=3, form=form) | python | def validate_owner_repo_identifier(ctx, param, value):
"""Ensure that owner/repo/identifier is formatted correctly."""
# pylint: disable=unused-argument
form = "OWNER/REPO/IDENTIFIER"
return validators.validate_slashes(param, value, minimum=3, maximum=3, form=form) | [
"def",
"validate_owner_repo_identifier",
"(",
"ctx",
",",
"param",
",",
"value",
")",
":",
"# pylint: disable=unused-argument",
"form",
"=",
"\"OWNER/REPO/IDENTIFIER\"",
"return",
"validators",
".",
"validate_slashes",
"(",
"param",
",",
"value",
",",
"minimum",
"=",
... | Ensure that owner/repo/identifier is formatted correctly. | [
"Ensure",
"that",
"owner",
"/",
"repo",
"/",
"identifier",
"is",
"formatted",
"correctly",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/commands/entitlements.py#L17-L21 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/commands/entitlements.py | common_entitlements_options | def common_entitlements_options(f):
"""Add common options for entitlement commands."""
@click.option(
"--show-tokens",
default=False,
is_flag=True,
help="Show entitlement token string contents in output.",
)
@click.pass_context
@functools.wraps(f)
def wrapper(ctx... | python | def common_entitlements_options(f):
"""Add common options for entitlement commands."""
@click.option(
"--show-tokens",
default=False,
is_flag=True,
help="Show entitlement token string contents in output.",
)
@click.pass_context
@functools.wraps(f)
def wrapper(ctx... | [
"def",
"common_entitlements_options",
"(",
"f",
")",
":",
"@",
"click",
".",
"option",
"(",
"\"--show-tokens\"",
",",
"default",
"=",
"False",
",",
"is_flag",
"=",
"True",
",",
"help",
"=",
"\"Show entitlement token string contents in output.\"",
",",
")",
"@",
... | Add common options for entitlement commands. | [
"Add",
"common",
"options",
"for",
"entitlement",
"commands",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/commands/entitlements.py#L24-L39 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/commands/entitlements.py | list_entitlements_options | def list_entitlements_options(f):
"""Options for list entitlements subcommand."""
@common_entitlements_options
@decorators.common_cli_config_options
@decorators.common_cli_list_options
@decorators.common_cli_output_options
@decorators.common_api_auth_options
@decorators.initialise_api
@... | python | def list_entitlements_options(f):
"""Options for list entitlements subcommand."""
@common_entitlements_options
@decorators.common_cli_config_options
@decorators.common_cli_list_options
@decorators.common_cli_output_options
@decorators.common_api_auth_options
@decorators.initialise_api
@... | [
"def",
"list_entitlements_options",
"(",
"f",
")",
":",
"@",
"common_entitlements_options",
"@",
"decorators",
".",
"common_cli_config_options",
"@",
"decorators",
".",
"common_cli_list_options",
"@",
"decorators",
".",
"common_cli_output_options",
"@",
"decorators",
".",... | Options for list entitlements subcommand. | [
"Options",
"for",
"list",
"entitlements",
"subcommand",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/commands/entitlements.py#L56-L74 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/commands/entitlements.py | list_entitlements | def list_entitlements(ctx, opts, owner_repo, page, page_size, show_tokens):
"""
List entitlements for a repository.
- OWNER/REPO: Specify the OWNER namespace (i.e. user or org), and the REPO
name where you want to list entitlements for. All separated by a slash.
Example: 'your-org/your-repo'... | python | def list_entitlements(ctx, opts, owner_repo, page, page_size, show_tokens):
"""
List entitlements for a repository.
- OWNER/REPO: Specify the OWNER namespace (i.e. user or org), and the REPO
name where you want to list entitlements for. All separated by a slash.
Example: 'your-org/your-repo'... | [
"def",
"list_entitlements",
"(",
"ctx",
",",
"opts",
",",
"owner_repo",
",",
"page",
",",
"page_size",
",",
"show_tokens",
")",
":",
"owner",
",",
"repo",
"=",
"owner_repo",
"# Use stderr for messages if the output is something else (e.g. # JSON)",
"use_stderr",
"=",
... | List entitlements for a repository.
- OWNER/REPO: Specify the OWNER namespace (i.e. user or org), and the REPO
name where you want to list entitlements for. All separated by a slash.
Example: 'your-org/your-repo'
Full CLI example:
$ cloudsmith ents list your-org/your-repo | [
"List",
"entitlements",
"for",
"a",
"repository",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/commands/entitlements.py#L77-L115 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/commands/entitlements.py | print_entitlements | def print_entitlements(opts, data, page_info=None, show_list_info=True):
"""Print entitlements as a table or output in another format."""
if utils.maybe_print_as_json(opts, data, page_info):
return
headers = ["Name", "Token", "Created / Updated", "Identifier"]
rows = []
for entitlement in ... | python | def print_entitlements(opts, data, page_info=None, show_list_info=True):
"""Print entitlements as a table or output in another format."""
if utils.maybe_print_as_json(opts, data, page_info):
return
headers = ["Name", "Token", "Created / Updated", "Identifier"]
rows = []
for entitlement in ... | [
"def",
"print_entitlements",
"(",
"opts",
",",
"data",
",",
"page_info",
"=",
"None",
",",
"show_list_info",
"=",
"True",
")",
":",
"if",
"utils",
".",
"maybe_print_as_json",
"(",
"opts",
",",
"data",
",",
"page_info",
")",
":",
"return",
"headers",
"=",
... | Print entitlements as a table or output in another format. | [
"Print",
"entitlements",
"as",
"a",
"table",
"or",
"output",
"in",
"another",
"format",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/commands/entitlements.py#L126-L161 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/commands/entitlements.py | create | def create(ctx, opts, owner_repo, show_tokens, name, token):
"""
Create a new entitlement in a repository.
- OWNER/REPO: Specify the OWNER namespace (i.e. user or org), and the REPO
name where you want to create an entitlement. All separated by a slash.
Example: 'your-org/your-repo'
Ful... | python | def create(ctx, opts, owner_repo, show_tokens, name, token):
"""
Create a new entitlement in a repository.
- OWNER/REPO: Specify the OWNER namespace (i.e. user or org), and the REPO
name where you want to create an entitlement. All separated by a slash.
Example: 'your-org/your-repo'
Ful... | [
"def",
"create",
"(",
"ctx",
",",
"opts",
",",
"owner_repo",
",",
"show_tokens",
",",
"name",
",",
"token",
")",
":",
"owner",
",",
"repo",
"=",
"owner_repo",
"# Use stderr for messages if the output is something else (e.g. # JSON)",
"use_stderr",
"=",
"opts",
".",... | Create a new entitlement in a repository.
- OWNER/REPO: Specify the OWNER namespace (i.e. user or org), and the REPO
name where you want to create an entitlement. All separated by a slash.
Example: 'your-org/your-repo'
Full CLI example:
$ cloudsmith ents create your-org/your-repo --name ... | [
"Create",
"a",
"new",
"entitlement",
"in",
"a",
"repository",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/commands/entitlements.py#L189-L227 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/commands/entitlements.py | delete | def delete(ctx, opts, owner_repo_identifier, yes):
"""
Delete an entitlement from a repository.
- OWNER/REPO/IDENTIFIER: Specify the OWNER namespace (i.e. user or org),
and the REPO name that has an entitlement identified by IDENTIFIER. All
separated by a slash.
Example: 'your-org/your... | python | def delete(ctx, opts, owner_repo_identifier, yes):
"""
Delete an entitlement from a repository.
- OWNER/REPO/IDENTIFIER: Specify the OWNER namespace (i.e. user or org),
and the REPO name that has an entitlement identified by IDENTIFIER. All
separated by a slash.
Example: 'your-org/your... | [
"def",
"delete",
"(",
"ctx",
",",
"opts",
",",
"owner_repo_identifier",
",",
"yes",
")",
":",
"owner",
",",
"repo",
",",
"identifier",
"=",
"owner_repo_identifier",
"delete_args",
"=",
"{",
"\"identifier\"",
":",
"click",
".",
"style",
"(",
"identifier",
","... | Delete an entitlement from a repository.
- OWNER/REPO/IDENTIFIER: Specify the OWNER namespace (i.e. user or org),
and the REPO name that has an entitlement identified by IDENTIFIER. All
separated by a slash.
Example: 'your-org/your-repo/abcdef123456'
Full CLI example:
$ cloudsmith ... | [
"Delete",
"an",
"entitlement",
"from",
"a",
"repository",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/commands/entitlements.py#L248-L287 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/commands/entitlements.py | update | def update(ctx, opts, owner_repo_identifier, show_tokens, name, token):
"""
Update (set) a entitlement in a repository.
- OWNER/REPO/IDENTIFIER: Specify the OWNER namespace (i.e. user or org),
and the REPO name that has an entitlement identified by IDENTIFIER. All
separated by a slash.
... | python | def update(ctx, opts, owner_repo_identifier, show_tokens, name, token):
"""
Update (set) a entitlement in a repository.
- OWNER/REPO/IDENTIFIER: Specify the OWNER namespace (i.e. user or org),
and the REPO name that has an entitlement identified by IDENTIFIER. All
separated by a slash.
... | [
"def",
"update",
"(",
"ctx",
",",
"opts",
",",
"owner_repo_identifier",
",",
"show_tokens",
",",
"name",
",",
"token",
")",
":",
"owner",
",",
"repo",
",",
"identifier",
"=",
"owner_repo_identifier",
"# Use stderr for messages if the output is something else (e.g. # JS... | Update (set) a entitlement in a repository.
- OWNER/REPO/IDENTIFIER: Specify the OWNER namespace (i.e. user or org),
and the REPO name that has an entitlement identified by IDENTIFIER. All
separated by a slash.
Example: 'your-org/your-repo/abcdef123456'
Full CLI example:
$ cloudsmi... | [
"Update",
"(",
"set",
")",
"a",
"entitlement",
"in",
"a",
"repository",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/commands/entitlements.py#L316-L360 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/commands/entitlements.py | refresh | def refresh(ctx, opts, owner_repo_identifier, show_tokens, yes):
"""
Refresh an entitlement in a repository.
Note that this changes the token associated with the entitlement.
- OWNER/REPO/IDENTIFIER: Specify the OWNER namespace (i.e. user or org),
and the REPO name that has an entitlement identi... | python | def refresh(ctx, opts, owner_repo_identifier, show_tokens, yes):
"""
Refresh an entitlement in a repository.
Note that this changes the token associated with the entitlement.
- OWNER/REPO/IDENTIFIER: Specify the OWNER namespace (i.e. user or org),
and the REPO name that has an entitlement identi... | [
"def",
"refresh",
"(",
"ctx",
",",
"opts",
",",
"owner_repo_identifier",
",",
"show_tokens",
",",
"yes",
")",
":",
"owner",
",",
"repo",
",",
"identifier",
"=",
"owner_repo_identifier",
"refresh_args",
"=",
"{",
"\"identifier\"",
":",
"click",
".",
"style",
... | Refresh an entitlement in a repository.
Note that this changes the token associated with the entitlement.
- OWNER/REPO/IDENTIFIER: Specify the OWNER namespace (i.e. user or org),
and the REPO name that has an entitlement identified by IDENTIFIER. All
separated by a slash.
Example: 'your-o... | [
"Refresh",
"an",
"entitlement",
"in",
"a",
"repository",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/commands/entitlements.py#L382-L431 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/commands/entitlements.py | sync | def sync(ctx, opts, owner_repo, show_tokens, source, yes):
"""
Sync entitlements from another repository.
***WARNING*** This will DELETE ALL of the existing entitlements in the
repository and replace them with entitlements from the source repository.
- OWNER/REPO: Specify the OWNER namespace (i.e.... | python | def sync(ctx, opts, owner_repo, show_tokens, source, yes):
"""
Sync entitlements from another repository.
***WARNING*** This will DELETE ALL of the existing entitlements in the
repository and replace them with entitlements from the source repository.
- OWNER/REPO: Specify the OWNER namespace (i.e.... | [
"def",
"sync",
"(",
"ctx",
",",
"opts",
",",
"owner_repo",
",",
"show_tokens",
",",
"source",
",",
"yes",
")",
":",
"owner",
",",
"repo",
"=",
"owner_repo",
"sync_args",
"=",
"{",
"\"source\"",
":",
"click",
".",
"style",
"(",
"source",
",",
"bold",
... | Sync entitlements from another repository.
***WARNING*** This will DELETE ALL of the existing entitlements in the
repository and replace them with entitlements from the source repository.
- OWNER/REPO: Specify the OWNER namespace (i.e. user or org), and the REPO
name where you want to sync entitleme... | [
"Sync",
"entitlements",
"from",
"another",
"repository",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/commands/entitlements.py#L452-L517 |
visualfabriq/bquery | bquery/benchmarks/bench_pos.py | ctime | def ctime(message=None):
"Counts the time spent in some context"
t = time.time()
yield
if message:
print message + ":\t",
print round(time.time() - t, 4), "sec" | python | def ctime(message=None):
"Counts the time spent in some context"
t = time.time()
yield
if message:
print message + ":\t",
print round(time.time() - t, 4), "sec" | [
"def",
"ctime",
"(",
"message",
"=",
"None",
")",
":",
"t",
"=",
"time",
".",
"time",
"(",
")",
"yield",
"if",
"message",
":",
"print",
"message",
"+",
"\":\\t\"",
",",
"print",
"round",
"(",
"time",
".",
"time",
"(",
")",
"-",
"t",
",",
"4",
"... | Counts the time spent in some context | [
"Counts",
"the",
"time",
"spent",
"in",
"some",
"context"
] | train | https://github.com/visualfabriq/bquery/blob/3702e974696e22876944a3339affad2f29e1ee06/bquery/benchmarks/bench_pos.py#L14-L20 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/ratelimits.py | maybe_rate_limit | def maybe_rate_limit(client, headers, atexit=False):
"""Optionally pause the process based on suggested rate interval."""
# pylint: disable=fixme
# pylint: disable=global-statement
# FIXME: Yes, I know this is not great. We'll fix it later. :-)
global LAST_CLIENT, LAST_HEADERS
if LAST_CLIENT an... | python | def maybe_rate_limit(client, headers, atexit=False):
"""Optionally pause the process based on suggested rate interval."""
# pylint: disable=fixme
# pylint: disable=global-statement
# FIXME: Yes, I know this is not great. We'll fix it later. :-)
global LAST_CLIENT, LAST_HEADERS
if LAST_CLIENT an... | [
"def",
"maybe_rate_limit",
"(",
"client",
",",
"headers",
",",
"atexit",
"=",
"False",
")",
":",
"# pylint: disable=fixme",
"# pylint: disable=global-statement",
"# FIXME: Yes, I know this is not great. We'll fix it later. :-)",
"global",
"LAST_CLIENT",
",",
"LAST_HEADERS",
"if... | Optionally pause the process based on suggested rate interval. | [
"Optionally",
"pause",
"the",
"process",
"based",
"on",
"suggested",
"rate",
"interval",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/ratelimits.py#L85-L97 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/ratelimits.py | rate_limit | def rate_limit(client, headers, atexit=False):
"""Pause the process based on suggested rate interval."""
if not client or not headers:
return False
if not getattr(client.config, "rate_limit", False):
return False
rate_info = RateLimitsInfo.from_headers(headers)
if not rate_info or ... | python | def rate_limit(client, headers, atexit=False):
"""Pause the process based on suggested rate interval."""
if not client or not headers:
return False
if not getattr(client.config, "rate_limit", False):
return False
rate_info = RateLimitsInfo.from_headers(headers)
if not rate_info or ... | [
"def",
"rate_limit",
"(",
"client",
",",
"headers",
",",
"atexit",
"=",
"False",
")",
":",
"if",
"not",
"client",
"or",
"not",
"headers",
":",
"return",
"False",
"if",
"not",
"getattr",
"(",
"client",
".",
"config",
",",
"\"rate_limit\"",
",",
"False",
... | Pause the process based on suggested rate interval. | [
"Pause",
"the",
"process",
"based",
"on",
"suggested",
"rate",
"interval",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/ratelimits.py#L100-L117 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/api/status.py | get_status | def get_status(with_version=False):
"""Retrieve status (and optionally) version from the API."""
client = get_status_api()
with catch_raise_api_exception():
data, _, headers = client.status_check_basic_with_http_info()
ratelimits.maybe_rate_limit(client, headers)
if with_version:
... | python | def get_status(with_version=False):
"""Retrieve status (and optionally) version from the API."""
client = get_status_api()
with catch_raise_api_exception():
data, _, headers = client.status_check_basic_with_http_info()
ratelimits.maybe_rate_limit(client, headers)
if with_version:
... | [
"def",
"get_status",
"(",
"with_version",
"=",
"False",
")",
":",
"client",
"=",
"get_status_api",
"(",
")",
"with",
"catch_raise_api_exception",
"(",
")",
":",
"data",
",",
"_",
",",
"headers",
"=",
"client",
".",
"status_check_basic_with_http_info",
"(",
")"... | Retrieve status (and optionally) version from the API. | [
"Retrieve",
"status",
"(",
"and",
"optionally",
")",
"version",
"from",
"the",
"API",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/api/status.py#L17-L29 |
kalefranz/auxlib | auxlib/collection.py | first | def first(seq, key=lambda x: bool(x), default=None, apply=lambda x: x):
"""Give the first value that satisfies the key test.
Args:
seq (iterable):
key (callable): test for each element of iterable
default: returned when all elements fail test
apply (callable): applied to element... | python | def first(seq, key=lambda x: bool(x), default=None, apply=lambda x: x):
"""Give the first value that satisfies the key test.
Args:
seq (iterable):
key (callable): test for each element of iterable
default: returned when all elements fail test
apply (callable): applied to element... | [
"def",
"first",
"(",
"seq",
",",
"key",
"=",
"lambda",
"x",
":",
"bool",
"(",
"x",
")",
",",
"default",
"=",
"None",
",",
"apply",
"=",
"lambda",
"x",
":",
"x",
")",
":",
"return",
"next",
"(",
"(",
"apply",
"(",
"x",
")",
"for",
"x",
"in",
... | Give the first value that satisfies the key test.
Args:
seq (iterable):
key (callable): test for each element of iterable
default: returned when all elements fail test
apply (callable): applied to element before return, but not to default value
Returns: first element in seq tha... | [
"Give",
"the",
"first",
"value",
"that",
"satisfies",
"the",
"key",
"test",
"."
] | train | https://github.com/kalefranz/auxlib/blob/6ff2d6b57d128d0b9ed8f01ad83572e938da064f/auxlib/collection.py#L87-L117 |
kalefranz/auxlib | auxlib/collection.py | call_each | def call_each(seq):
"""Calls each element of sequence to invoke the side effect.
Args:
seq:
Returns: None
"""
try:
reduce(lambda _, y: y(), seq)
except TypeError as e:
if text_type(e) != "reduce() of empty sequence with no initial value":
raise | python | def call_each(seq):
"""Calls each element of sequence to invoke the side effect.
Args:
seq:
Returns: None
"""
try:
reduce(lambda _, y: y(), seq)
except TypeError as e:
if text_type(e) != "reduce() of empty sequence with no initial value":
raise | [
"def",
"call_each",
"(",
"seq",
")",
":",
"try",
":",
"reduce",
"(",
"lambda",
"_",
",",
"y",
":",
"y",
"(",
")",
",",
"seq",
")",
"except",
"TypeError",
"as",
"e",
":",
"if",
"text_type",
"(",
"e",
")",
"!=",
"\"reduce() of empty sequence with no init... | Calls each element of sequence to invoke the side effect.
Args:
seq:
Returns: None | [
"Calls",
"each",
"element",
"of",
"sequence",
"to",
"invoke",
"the",
"side",
"effect",
"."
] | train | https://github.com/kalefranz/auxlib/blob/6ff2d6b57d128d0b9ed8f01ad83572e938da064f/auxlib/collection.py#L128-L141 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/validators.py | transform_api_header_authorization | def transform_api_header_authorization(param, value):
"""Transform a username:password value into a base64 string."""
try:
username, password = value.split(":", 1)
except ValueError:
raise click.BadParameter(
"Authorization header needs to be Authorization=username:password",
... | python | def transform_api_header_authorization(param, value):
"""Transform a username:password value into a base64 string."""
try:
username, password = value.split(":", 1)
except ValueError:
raise click.BadParameter(
"Authorization header needs to be Authorization=username:password",
... | [
"def",
"transform_api_header_authorization",
"(",
"param",
",",
"value",
")",
":",
"try",
":",
"username",
",",
"password",
"=",
"value",
".",
"split",
"(",
"\":\"",
",",
"1",
")",
"except",
"ValueError",
":",
"raise",
"click",
".",
"BadParameter",
"(",
"\... | Transform a username:password value into a base64 string. | [
"Transform",
"a",
"username",
":",
"password",
"value",
"into",
"a",
"base64",
"string",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/validators.py#L14-L26 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/validators.py | validate_api_headers | def validate_api_headers(param, value):
"""Validate that API headers is a CSV of k=v pairs."""
# pylint: disable=unused-argument
if not value:
return None
headers = {}
for kv in value.split(","):
try:
k, v = kv.split("=", 1)
k = k.strip()
for bad... | python | def validate_api_headers(param, value):
"""Validate that API headers is a CSV of k=v pairs."""
# pylint: disable=unused-argument
if not value:
return None
headers = {}
for kv in value.split(","):
try:
k, v = kv.split("=", 1)
k = k.strip()
for bad... | [
"def",
"validate_api_headers",
"(",
"param",
",",
"value",
")",
":",
"# pylint: disable=unused-argument",
"if",
"not",
"value",
":",
"return",
"None",
"headers",
"=",
"{",
"}",
"for",
"kv",
"in",
"value",
".",
"split",
"(",
"\",\"",
")",
":",
"try",
":",
... | Validate that API headers is a CSV of k=v pairs. | [
"Validate",
"that",
"API",
"headers",
"is",
"a",
"CSV",
"of",
"k",
"=",
"v",
"pairs",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/validators.py#L32-L61 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/validators.py | validate_slashes | def validate_slashes(param, value, minimum=2, maximum=None, form=None):
"""Ensure that parameter has slashes and minimum parts."""
try:
value = value.split("/")
except ValueError:
value = None
if value:
if len(value) < minimum:
value = None
elif maximum and l... | python | def validate_slashes(param, value, minimum=2, maximum=None, form=None):
"""Ensure that parameter has slashes and minimum parts."""
try:
value = value.split("/")
except ValueError:
value = None
if value:
if len(value) < minimum:
value = None
elif maximum and l... | [
"def",
"validate_slashes",
"(",
"param",
",",
"value",
",",
"minimum",
"=",
"2",
",",
"maximum",
"=",
"None",
",",
"form",
"=",
"None",
")",
":",
"try",
":",
"value",
"=",
"value",
".",
"split",
"(",
"\"/\"",
")",
"except",
"ValueError",
":",
"value"... | Ensure that parameter has slashes and minimum parts. | [
"Ensure",
"that",
"parameter",
"has",
"slashes",
"and",
"minimum",
"parts",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/validators.py#L64-L87 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/validators.py | validate_owner_repo | def validate_owner_repo(ctx, param, value):
"""Ensure that owner/repo is formatted correctly."""
# pylint: disable=unused-argument
form = "OWNER/REPO"
return validate_slashes(param, value, minimum=2, maximum=2, form=form) | python | def validate_owner_repo(ctx, param, value):
"""Ensure that owner/repo is formatted correctly."""
# pylint: disable=unused-argument
form = "OWNER/REPO"
return validate_slashes(param, value, minimum=2, maximum=2, form=form) | [
"def",
"validate_owner_repo",
"(",
"ctx",
",",
"param",
",",
"value",
")",
":",
"# pylint: disable=unused-argument",
"form",
"=",
"\"OWNER/REPO\"",
"return",
"validate_slashes",
"(",
"param",
",",
"value",
",",
"minimum",
"=",
"2",
",",
"maximum",
"=",
"2",
",... | Ensure that owner/repo is formatted correctly. | [
"Ensure",
"that",
"owner",
"/",
"repo",
"is",
"formatted",
"correctly",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/validators.py#L90-L94 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/validators.py | validate_owner_repo_package | def validate_owner_repo_package(ctx, param, value):
"""Ensure that owner/repo/package is formatted correctly."""
# pylint: disable=unused-argument
form = "OWNER/REPO/PACKAGE"
return validate_slashes(param, value, minimum=3, maximum=3, form=form) | python | def validate_owner_repo_package(ctx, param, value):
"""Ensure that owner/repo/package is formatted correctly."""
# pylint: disable=unused-argument
form = "OWNER/REPO/PACKAGE"
return validate_slashes(param, value, minimum=3, maximum=3, form=form) | [
"def",
"validate_owner_repo_package",
"(",
"ctx",
",",
"param",
",",
"value",
")",
":",
"# pylint: disable=unused-argument",
"form",
"=",
"\"OWNER/REPO/PACKAGE\"",
"return",
"validate_slashes",
"(",
"param",
",",
"value",
",",
"minimum",
"=",
"3",
",",
"maximum",
... | Ensure that owner/repo/package is formatted correctly. | [
"Ensure",
"that",
"owner",
"/",
"repo",
"/",
"package",
"is",
"formatted",
"correctly",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/validators.py#L97-L101 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/validators.py | validate_owner_repo_distro | def validate_owner_repo_distro(ctx, param, value):
"""Ensure that owner/repo/distro/version is formatted correctly."""
# pylint: disable=unused-argument
form = "OWNER/REPO/DISTRO[/RELEASE]"
return validate_slashes(param, value, minimum=3, maximum=4, form=form) | python | def validate_owner_repo_distro(ctx, param, value):
"""Ensure that owner/repo/distro/version is formatted correctly."""
# pylint: disable=unused-argument
form = "OWNER/REPO/DISTRO[/RELEASE]"
return validate_slashes(param, value, minimum=3, maximum=4, form=form) | [
"def",
"validate_owner_repo_distro",
"(",
"ctx",
",",
"param",
",",
"value",
")",
":",
"# pylint: disable=unused-argument",
"form",
"=",
"\"OWNER/REPO/DISTRO[/RELEASE]\"",
"return",
"validate_slashes",
"(",
"param",
",",
"value",
",",
"minimum",
"=",
"3",
",",
"maxi... | Ensure that owner/repo/distro/version is formatted correctly. | [
"Ensure",
"that",
"owner",
"/",
"repo",
"/",
"distro",
"/",
"version",
"is",
"formatted",
"correctly",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/validators.py#L104-L108 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/validators.py | validate_page | def validate_page(ctx, param, value):
"""Ensure that a valid value for page is chosen."""
# pylint: disable=unused-argument
if value == 0:
raise click.BadParameter(
"Page is not zero-based, please set a value to 1 or higher.", param=param
)
return value | python | def validate_page(ctx, param, value):
"""Ensure that a valid value for page is chosen."""
# pylint: disable=unused-argument
if value == 0:
raise click.BadParameter(
"Page is not zero-based, please set a value to 1 or higher.", param=param
)
return value | [
"def",
"validate_page",
"(",
"ctx",
",",
"param",
",",
"value",
")",
":",
"# pylint: disable=unused-argument",
"if",
"value",
"==",
"0",
":",
"raise",
"click",
".",
"BadParameter",
"(",
"\"Page is not zero-based, please set a value to 1 or higher.\"",
",",
"param",
"=... | Ensure that a valid value for page is chosen. | [
"Ensure",
"that",
"a",
"valid",
"value",
"for",
"page",
"is",
"chosen",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/validators.py#L111-L118 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/validators.py | validate_page_size | def validate_page_size(ctx, param, value):
"""Ensure that a valid value for page size is chosen."""
# pylint: disable=unused-argument
if value == 0:
raise click.BadParameter("Page size must be non-zero or unset.", param=param)
return value | python | def validate_page_size(ctx, param, value):
"""Ensure that a valid value for page size is chosen."""
# pylint: disable=unused-argument
if value == 0:
raise click.BadParameter("Page size must be non-zero or unset.", param=param)
return value | [
"def",
"validate_page_size",
"(",
"ctx",
",",
"param",
",",
"value",
")",
":",
"# pylint: disable=unused-argument",
"if",
"value",
"==",
"0",
":",
"raise",
"click",
".",
"BadParameter",
"(",
"\"Page size must be non-zero or unset.\"",
",",
"param",
"=",
"param",
"... | Ensure that a valid value for page size is chosen. | [
"Ensure",
"that",
"a",
"valid",
"value",
"for",
"page",
"size",
"is",
"chosen",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/validators.py#L121-L126 |
yagays/pybitflyer | pybitflyer/pybitflyer.py | API.getbalance | def getbalance(self, **params):
"""Get Account Asset Balance
API Type
--------
HTTP Private API
Docs
----
https://lightning.bitflyer.jp/docs?lang=en#get-account-asset-balance
"""
if not all([self.api_key, self.api_secret]):
raise Auth... | python | def getbalance(self, **params):
"""Get Account Asset Balance
API Type
--------
HTTP Private API
Docs
----
https://lightning.bitflyer.jp/docs?lang=en#get-account-asset-balance
"""
if not all([self.api_key, self.api_secret]):
raise Auth... | [
"def",
"getbalance",
"(",
"self",
",",
"*",
"*",
"params",
")",
":",
"if",
"not",
"all",
"(",
"[",
"self",
".",
"api_key",
",",
"self",
".",
"api_secret",
"]",
")",
":",
"raise",
"AuthException",
"(",
")",
"endpoint",
"=",
"\"/v1/me/getbalance\"",
"ret... | Get Account Asset Balance
API Type
--------
HTTP Private API
Docs
----
https://lightning.bitflyer.jp/docs?lang=en#get-account-asset-balance | [
"Get",
"Account",
"Asset",
"Balance"
] | train | https://github.com/yagays/pybitflyer/blob/05858240e5f9e0367b0a397d96b4ced5e55150d9/pybitflyer/pybitflyer.py#L188-L203 |
willthames/ansible-inventory-grapher | lib/ansibleinventorygrapher/__init__.py | tidy_all_the_variables | def tidy_all_the_variables(host, inventory_mgr):
''' removes all overridden and inherited variables from hosts
and groups '''
global _vars
_vars = dict()
_vars[host] = inventory_mgr.inventory.get_host_vars(host)
for group in host.get_groups():
remove_inherited_and_overridden_vars(_va... | python | def tidy_all_the_variables(host, inventory_mgr):
''' removes all overridden and inherited variables from hosts
and groups '''
global _vars
_vars = dict()
_vars[host] = inventory_mgr.inventory.get_host_vars(host)
for group in host.get_groups():
remove_inherited_and_overridden_vars(_va... | [
"def",
"tidy_all_the_variables",
"(",
"host",
",",
"inventory_mgr",
")",
":",
"global",
"_vars",
"_vars",
"=",
"dict",
"(",
")",
"_vars",
"[",
"host",
"]",
"=",
"inventory_mgr",
".",
"inventory",
".",
"get_host_vars",
"(",
"host",
")",
"for",
"group",
"in"... | removes all overridden and inherited variables from hosts
and groups | [
"removes",
"all",
"overridden",
"and",
"inherited",
"variables",
"from",
"hosts",
"and",
"groups"
] | train | https://github.com/willthames/ansible-inventory-grapher/blob/018908594776486a317ef9ed9293a9ef391fe3e9/lib/ansibleinventorygrapher/__init__.py#L90-L99 |
willthames/ansible-inventory-grapher | lib/ansibleinventorygrapher/inventory.py | Inventory24._plugins_inventory | def _plugins_inventory(self, entities):
import os
from ansible.plugins.loader import vars_loader
from ansible.utils.vars import combine_vars
''' merges all entities by inventory source '''
data = {}
for inventory_dir in self.variable_manager._inventory._sources:
... | python | def _plugins_inventory(self, entities):
import os
from ansible.plugins.loader import vars_loader
from ansible.utils.vars import combine_vars
''' merges all entities by inventory source '''
data = {}
for inventory_dir in self.variable_manager._inventory._sources:
... | [
"def",
"_plugins_inventory",
"(",
"self",
",",
"entities",
")",
":",
"import",
"os",
"from",
"ansible",
".",
"plugins",
".",
"loader",
"import",
"vars_loader",
"from",
"ansible",
".",
"utils",
".",
"vars",
"import",
"combine_vars",
"data",
"=",
"{",
"}",
"... | merges all entities by inventory source | [
"merges",
"all",
"entities",
"by",
"inventory",
"source"
] | train | https://github.com/willthames/ansible-inventory-grapher/blob/018908594776486a317ef9ed9293a9ef391fe3e9/lib/ansibleinventorygrapher/inventory.py#L121-L135 |
thelabnyc/wagtail_blog | blog/management/commands/wordpress_to_wagtail.py | Command.handle | def handle(self, *args, **options):
"""gets data from WordPress site"""
# TODO: refactor these with .get
if 'username' in options:
self.username = options['username']
else:
self.username = None
if 'password' in options:
self.password = options[... | python | def handle(self, *args, **options):
"""gets data from WordPress site"""
# TODO: refactor these with .get
if 'username' in options:
self.username = options['username']
else:
self.username = None
if 'password' in options:
self.password = options[... | [
"def",
"handle",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"options",
")",
":",
"# TODO: refactor these with .get",
"if",
"'username'",
"in",
"options",
":",
"self",
".",
"username",
"=",
"options",
"[",
"'username'",
"]",
"else",
":",
"self",
".",
"... | gets data from WordPress site | [
"gets",
"data",
"from",
"WordPress",
"site"
] | train | https://github.com/thelabnyc/wagtail_blog/blob/7e092c02d10ec427c9a2c4b5dcbe910d88c628cf/blog/management/commands/wordpress_to_wagtail.py#L64-L99 |
thelabnyc/wagtail_blog | blog/management/commands/wordpress_to_wagtail.py | Command.create_images_from_urls_in_content | def create_images_from_urls_in_content(self, body):
"""create Image objects and transfer image files to media root"""
soup = BeautifulSoup(body, "html5lib")
for img in soup.findAll('img'):
old_url = img['src']
if 'width' in img:
width = img['width']
... | python | def create_images_from_urls_in_content(self, body):
"""create Image objects and transfer image files to media root"""
soup = BeautifulSoup(body, "html5lib")
for img in soup.findAll('img'):
old_url = img['src']
if 'width' in img:
width = img['width']
... | [
"def",
"create_images_from_urls_in_content",
"(",
"self",
",",
"body",
")",
":",
"soup",
"=",
"BeautifulSoup",
"(",
"body",
",",
"\"html5lib\"",
")",
"for",
"img",
"in",
"soup",
".",
"findAll",
"(",
"'img'",
")",
":",
"old_url",
"=",
"img",
"[",
"'src'",
... | create Image objects and transfer image files to media root | [
"create",
"Image",
"objects",
"and",
"transfer",
"image",
"files",
"to",
"media",
"root"
] | train | https://github.com/thelabnyc/wagtail_blog/blob/7e092c02d10ec427c9a2c4b5dcbe910d88c628cf/blog/management/commands/wordpress_to_wagtail.py#L159-L194 |
thelabnyc/wagtail_blog | blog/management/commands/wordpress_to_wagtail.py | Command.lookup_comment_by_wordpress_id | def lookup_comment_by_wordpress_id(self, comment_id, comments):
""" Returns Django comment object with this wordpress id """
for comment in comments:
if comment.wordpress_id == comment_id:
return comment | python | def lookup_comment_by_wordpress_id(self, comment_id, comments):
""" Returns Django comment object with this wordpress id """
for comment in comments:
if comment.wordpress_id == comment_id:
return comment | [
"def",
"lookup_comment_by_wordpress_id",
"(",
"self",
",",
"comment_id",
",",
"comments",
")",
":",
"for",
"comment",
"in",
"comments",
":",
"if",
"comment",
".",
"wordpress_id",
"==",
"comment_id",
":",
"return",
"comment"
] | Returns Django comment object with this wordpress id | [
"Returns",
"Django",
"comment",
"object",
"with",
"this",
"wordpress",
"id"
] | train | https://github.com/thelabnyc/wagtail_blog/blob/7e092c02d10ec427c9a2c4b5dcbe910d88c628cf/blog/management/commands/wordpress_to_wagtail.py#L223-L227 |
thelabnyc/wagtail_blog | blog/management/commands/wordpress_to_wagtail.py | Command.create_blog_pages | def create_blog_pages(self, posts, blog_index, *args, **options):
"""create Blog post entries from wordpress data"""
for post in posts:
post_id = post.get('ID')
title = post.get('title')
if title:
new_title = self.convert_html_entities(title)
... | python | def create_blog_pages(self, posts, blog_index, *args, **options):
"""create Blog post entries from wordpress data"""
for post in posts:
post_id = post.get('ID')
title = post.get('title')
if title:
new_title = self.convert_html_entities(title)
... | [
"def",
"create_blog_pages",
"(",
"self",
",",
"posts",
",",
"blog_index",
",",
"*",
"args",
",",
"*",
"*",
"options",
")",
":",
"for",
"post",
"in",
"posts",
":",
"post_id",
"=",
"post",
".",
"get",
"(",
"'ID'",
")",
"title",
"=",
"post",
".",
"get... | create Blog post entries from wordpress data | [
"create",
"Blog",
"post",
"entries",
"from",
"wordpress",
"data"
] | train | https://github.com/thelabnyc/wagtail_blog/blob/7e092c02d10ec427c9a2c4b5dcbe910d88c628cf/blog/management/commands/wordpress_to_wagtail.py#L327-L388 |
thelabnyc/wagtail_blog | blog/utils.py | unique_slugify | def unique_slugify(instance, value, slug_field_name='slug', queryset=None,
slug_separator='-'):
"""
Calculates and stores a unique slug of ``value`` for an instance.
``slug_field_name`` should be a string matching the name of the field to
store the slug in (and the field to check aga... | python | def unique_slugify(instance, value, slug_field_name='slug', queryset=None,
slug_separator='-'):
"""
Calculates and stores a unique slug of ``value`` for an instance.
``slug_field_name`` should be a string matching the name of the field to
store the slug in (and the field to check aga... | [
"def",
"unique_slugify",
"(",
"instance",
",",
"value",
",",
"slug_field_name",
"=",
"'slug'",
",",
"queryset",
"=",
"None",
",",
"slug_separator",
"=",
"'-'",
")",
":",
"slug_field",
"=",
"instance",
".",
"_meta",
".",
"get_field",
"(",
"slug_field_name",
"... | Calculates and stores a unique slug of ``value`` for an instance.
``slug_field_name`` should be a string matching the name of the field to
store the slug in (and the field to check against for uniqueness).
``queryset`` usually doesn't need to be explicitly provided - it'll default
to using the ``.all(... | [
"Calculates",
"and",
"stores",
"a",
"unique",
"slug",
"of",
"value",
"for",
"an",
"instance",
"."
] | train | https://github.com/thelabnyc/wagtail_blog/blob/7e092c02d10ec427c9a2c4b5dcbe910d88c628cf/blog/utils.py#L6-L48 |
thelabnyc/wagtail_blog | blog/utils.py | _slug_strip | def _slug_strip(value, separator='-'):
"""
Cleans up a slug by removing slug separator characters that occur at the
beginning or end of a slug.
If an alternate separator is used, it will also replace any instances of
the default '-' separator with the new separator.
"""
separator = separato... | python | def _slug_strip(value, separator='-'):
"""
Cleans up a slug by removing slug separator characters that occur at the
beginning or end of a slug.
If an alternate separator is used, it will also replace any instances of
the default '-' separator with the new separator.
"""
separator = separato... | [
"def",
"_slug_strip",
"(",
"value",
",",
"separator",
"=",
"'-'",
")",
":",
"separator",
"=",
"separator",
"or",
"''",
"if",
"separator",
"==",
"'-'",
"or",
"not",
"separator",
":",
"re_sep",
"=",
"'-'",
"else",
":",
"re_sep",
"=",
"'(?:-|%s)'",
"%",
"... | Cleans up a slug by removing slug separator characters that occur at the
beginning or end of a slug.
If an alternate separator is used, it will also replace any instances of
the default '-' separator with the new separator. | [
"Cleans",
"up",
"a",
"slug",
"by",
"removing",
"slug",
"separator",
"characters",
"that",
"occur",
"at",
"the",
"beginning",
"or",
"end",
"of",
"a",
"slug",
"."
] | train | https://github.com/thelabnyc/wagtail_blog/blob/7e092c02d10ec427c9a2c4b5dcbe910d88c628cf/blog/utils.py#L51-L73 |
thelabnyc/wagtail_blog | blog/abstract.py | limit_author_choices | def limit_author_choices():
""" Limit choices in blog author field based on config settings """
LIMIT_AUTHOR_CHOICES = getattr(settings, 'BLOG_LIMIT_AUTHOR_CHOICES_GROUP', None)
if LIMIT_AUTHOR_CHOICES:
if isinstance(LIMIT_AUTHOR_CHOICES, str):
limit = Q(groups__name=LIMIT_AUTHOR_CHOICES... | python | def limit_author_choices():
""" Limit choices in blog author field based on config settings """
LIMIT_AUTHOR_CHOICES = getattr(settings, 'BLOG_LIMIT_AUTHOR_CHOICES_GROUP', None)
if LIMIT_AUTHOR_CHOICES:
if isinstance(LIMIT_AUTHOR_CHOICES, str):
limit = Q(groups__name=LIMIT_AUTHOR_CHOICES... | [
"def",
"limit_author_choices",
"(",
")",
":",
"LIMIT_AUTHOR_CHOICES",
"=",
"getattr",
"(",
"settings",
",",
"'BLOG_LIMIT_AUTHOR_CHOICES_GROUP'",
",",
"None",
")",
"if",
"LIMIT_AUTHOR_CHOICES",
":",
"if",
"isinstance",
"(",
"LIMIT_AUTHOR_CHOICES",
",",
"str",
")",
":... | Limit choices in blog author field based on config settings | [
"Limit",
"choices",
"in",
"blog",
"author",
"field",
"based",
"on",
"config",
"settings"
] | train | https://github.com/thelabnyc/wagtail_blog/blob/7e092c02d10ec427c9a2c4b5dcbe910d88c628cf/blog/abstract.py#L95-L109 |
thelabnyc/wagtail_blog | blog/models.py | get_blog_context | def get_blog_context(context):
""" Get context data useful on all blog related pages """
context['authors'] = get_user_model().objects.filter(
owned_pages__live=True,
owned_pages__content_type__model='blogpage'
).annotate(Count('owned_pages')).order_by('-owned_pages__count')
context['all... | python | def get_blog_context(context):
""" Get context data useful on all blog related pages """
context['authors'] = get_user_model().objects.filter(
owned_pages__live=True,
owned_pages__content_type__model='blogpage'
).annotate(Count('owned_pages')).order_by('-owned_pages__count')
context['all... | [
"def",
"get_blog_context",
"(",
"context",
")",
":",
"context",
"[",
"'authors'",
"]",
"=",
"get_user_model",
"(",
")",
".",
"objects",
".",
"filter",
"(",
"owned_pages__live",
"=",
"True",
",",
"owned_pages__content_type__model",
"=",
"'blogpage'",
")",
".",
... | Get context data useful on all blog related pages | [
"Get",
"context",
"data",
"useful",
"on",
"all",
"blog",
"related",
"pages"
] | train | https://github.com/thelabnyc/wagtail_blog/blob/7e092c02d10ec427c9a2c4b5dcbe910d88c628cf/blog/models.py#L118-L132 |
thelabnyc/wagtail_blog | blog/wp_xml_parser.py | XML_parser.remove_xmlns | def remove_xmlns(xml_string):
"""
changes the xmlns (XML namespace) so that values are
replaced with the string representation of their key
this makes the import process for portable
>>> xp = XML_parser
>>> test_xmlns = r'<rss version="2.0" xmlns:excerpt="http://wordpres... | python | def remove_xmlns(xml_string):
"""
changes the xmlns (XML namespace) so that values are
replaced with the string representation of their key
this makes the import process for portable
>>> xp = XML_parser
>>> test_xmlns = r'<rss version="2.0" xmlns:excerpt="http://wordpres... | [
"def",
"remove_xmlns",
"(",
"xml_string",
")",
":",
"# splitting xml into sections, pre_chan is preamble before <channel>",
"pre_chan",
",",
"chan",
",",
"post_chan",
"=",
"xml_string",
".",
"partition",
"(",
"'<channel>'",
")",
"# replace xmlns statements on preamble",
"pre_... | changes the xmlns (XML namespace) so that values are
replaced with the string representation of their key
this makes the import process for portable
>>> xp = XML_parser
>>> test_xmlns = r'<rss version="2.0" xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/">'
>>> xp.remove... | [
"changes",
"the",
"xmlns",
"(",
"XML",
"namespace",
")",
"so",
"that",
"values",
"are",
"replaced",
"with",
"the",
"string",
"representation",
"of",
"their",
"key",
"this",
"makes",
"the",
"import",
"process",
"for",
"portable"
] | train | https://github.com/thelabnyc/wagtail_blog/blob/7e092c02d10ec427c9a2c4b5dcbe910d88c628cf/blog/wp_xml_parser.py#L69-L87 |
thelabnyc/wagtail_blog | blog/wp_xml_parser.py | XML_parser.item_dict | def item_dict(self, item):
"""
create a default dict of values, including
category and tag lookup
"""
# mocking wierd JSON structure
ret_dict = {"terms":{"category":[],"post_tag":[]}}
for e in item:
# is it a category or tag??
if "category"... | python | def item_dict(self, item):
"""
create a default dict of values, including
category and tag lookup
"""
# mocking wierd JSON structure
ret_dict = {"terms":{"category":[],"post_tag":[]}}
for e in item:
# is it a category or tag??
if "category"... | [
"def",
"item_dict",
"(",
"self",
",",
"item",
")",
":",
"# mocking wierd JSON structure",
"ret_dict",
"=",
"{",
"\"terms\"",
":",
"{",
"\"category\"",
":",
"[",
"]",
",",
"\"post_tag\"",
":",
"[",
"]",
"}",
"}",
"for",
"e",
"in",
"item",
":",
"# is it a ... | create a default dict of values, including
category and tag lookup | [
"create",
"a",
"default",
"dict",
"of",
"values",
"including",
"category",
"and",
"tag",
"lookup"
] | train | https://github.com/thelabnyc/wagtail_blog/blob/7e092c02d10ec427c9a2c4b5dcbe910d88c628cf/blog/wp_xml_parser.py#L93-L129 |
thelabnyc/wagtail_blog | blog/wp_xml_parser.py | XML_parser.convert_date | def convert_date(d, custom_date_string=None, fallback=None):
"""
for whatever reason, sometimes WP XML has unintelligible
datetime strings for pubDate.
In this case default to custom_date_string or today
Use fallback in case a secondary date string is available.
Incident... | python | def convert_date(d, custom_date_string=None, fallback=None):
"""
for whatever reason, sometimes WP XML has unintelligible
datetime strings for pubDate.
In this case default to custom_date_string or today
Use fallback in case a secondary date string is available.
Incident... | [
"def",
"convert_date",
"(",
"d",
",",
"custom_date_string",
"=",
"None",
",",
"fallback",
"=",
"None",
")",
":",
"if",
"d",
"==",
"'Mon, 30 Nov -0001 00:00:00 +0000'",
"and",
"fallback",
":",
"d",
"=",
"fallback",
"try",
":",
"date",
"=",
"time",
".",
"str... | for whatever reason, sometimes WP XML has unintelligible
datetime strings for pubDate.
In this case default to custom_date_string or today
Use fallback in case a secondary date string is available.
Incidentally, somehow the string 'Mon, 30 Nov -0001 00:00:00 +0000'
shows up.
... | [
"for",
"whatever",
"reason",
"sometimes",
"WP",
"XML",
"has",
"unintelligible",
"datetime",
"strings",
"for",
"pubDate",
".",
"In",
"this",
"case",
"default",
"to",
"custom_date_string",
"or",
"today",
"Use",
"fallback",
"in",
"case",
"a",
"secondary",
"date",
... | train | https://github.com/thelabnyc/wagtail_blog/blob/7e092c02d10ec427c9a2c4b5dcbe910d88c628cf/blog/wp_xml_parser.py#L132-L153 |
thelabnyc/wagtail_blog | blog/wp_xml_parser.py | XML_parser.translate_item | def translate_item(self, item_dict):
"""cleanup item keys to match API json format"""
if not item_dict.get('title'):
return None
# Skip attachments
if item_dict.get('{wp}post_type', None) == 'attachment':
return None
ret_dict = {}
# slugify post ti... | python | def translate_item(self, item_dict):
"""cleanup item keys to match API json format"""
if not item_dict.get('title'):
return None
# Skip attachments
if item_dict.get('{wp}post_type', None) == 'attachment':
return None
ret_dict = {}
# slugify post ti... | [
"def",
"translate_item",
"(",
"self",
",",
"item_dict",
")",
":",
"if",
"not",
"item_dict",
".",
"get",
"(",
"'title'",
")",
":",
"return",
"None",
"# Skip attachments",
"if",
"item_dict",
".",
"get",
"(",
"'{wp}post_type'",
",",
"None",
")",
"==",
"'attac... | cleanup item keys to match API json format | [
"cleanup",
"item",
"keys",
"to",
"match",
"API",
"json",
"format"
] | train | https://github.com/thelabnyc/wagtail_blog/blob/7e092c02d10ec427c9a2c4b5dcbe910d88c628cf/blog/wp_xml_parser.py#L155-L178 |
thelabnyc/wagtail_blog | blog/wp_xml_parser.py | XML_parser.translate_wp_comment | def translate_wp_comment(self, e):
"""
<wp:comment>
<wp:comment_id>1234</wp:comment_id>
<wp:comment_author><![CDATA[John Doe]]></wp:comment_author>
<wp:comment_author_email><![CDATA[info@adsasd.com]]></wp:comment_author_email>
<wp:comment_author_url>http://myhomepage.com/</wp:c... | python | def translate_wp_comment(self, e):
"""
<wp:comment>
<wp:comment_id>1234</wp:comment_id>
<wp:comment_author><![CDATA[John Doe]]></wp:comment_author>
<wp:comment_author_email><![CDATA[info@adsasd.com]]></wp:comment_author_email>
<wp:comment_author_url>http://myhomepage.com/</wp:c... | [
"def",
"translate_wp_comment",
"(",
"self",
",",
"e",
")",
":",
"comment_dict",
"=",
"{",
"}",
"comment_dict",
"[",
"'ID'",
"]",
"=",
"e",
".",
"find",
"(",
"'./{wp}comment_id'",
")",
".",
"text",
"comment_dict",
"[",
"'date'",
"]",
"=",
"e",
".",
"fin... | <wp:comment>
<wp:comment_id>1234</wp:comment_id>
<wp:comment_author><![CDATA[John Doe]]></wp:comment_author>
<wp:comment_author_email><![CDATA[info@adsasd.com]]></wp:comment_author_email>
<wp:comment_author_url>http://myhomepage.com/</wp:comment_author_url>
<wp:comment_author_IP><![CD... | [
"<wp",
":",
"comment",
">",
"<wp",
":",
"comment_id",
">",
"1234<",
"/",
"wp",
":",
"comment_id",
">",
"<wp",
":",
"comment_author",
">",
"<!",
"[",
"CDATA",
"[",
"John",
"Doe",
"]]",
">",
"<",
"/",
"wp",
":",
"comment_author",
">",
"<wp",
":",
"co... | train | https://github.com/thelabnyc/wagtail_blog/blob/7e092c02d10ec427c9a2c4b5dcbe910d88c628cf/blog/wp_xml_parser.py#L181-L208 |
thelabnyc/wagtail_blog | blog/wp_xml_parser.py | XML_parser.get_posts_data | def get_posts_data(self):
"""
given a WordPress xml export file, will return list
of dictionaries with keys that match
the expected json keys of a wordpress API call
>>> xp = XML_parser('example_export.xml')
>>> json_vals = {"slug","ID", "title","description", "content", ... | python | def get_posts_data(self):
"""
given a WordPress xml export file, will return list
of dictionaries with keys that match
the expected json keys of a wordpress API call
>>> xp = XML_parser('example_export.xml')
>>> json_vals = {"slug","ID", "title","description", "content", ... | [
"def",
"get_posts_data",
"(",
"self",
")",
":",
"items",
"=",
"self",
".",
"chan",
".",
"findall",
"(",
"\"item\"",
")",
"#(e for e in chan.getchildren() if e.tag=='item')",
"# turn item element into a generic dict",
"item_dict_gen",
"=",
"(",
"self",
".",
"item_dict",
... | given a WordPress xml export file, will return list
of dictionaries with keys that match
the expected json keys of a wordpress API call
>>> xp = XML_parser('example_export.xml')
>>> json_vals = {"slug","ID", "title","description", "content", "author", "terms", "date", }
>>> data ... | [
"given",
"a",
"WordPress",
"xml",
"export",
"file",
"will",
"return",
"list",
"of",
"dictionaries",
"with",
"keys",
"that",
"match",
"the",
"expected",
"json",
"keys",
"of",
"a",
"wordpress",
"API",
"call",
">>>",
"xp",
"=",
"XML_parser",
"(",
"example_expor... | train | https://github.com/thelabnyc/wagtail_blog/blob/7e092c02d10ec427c9a2c4b5dcbe910d88c628cf/blog/wp_xml_parser.py#L211-L226 |
thelabnyc/wagtail_blog | blog/wp_xml_parser.py | XML_parser.get_comments_data | def get_comments_data(self, slug):
"""
Returns a flat list of all comments in XML dump. Formatted as the JSON
output from Wordpress API.
Keys:
('content', 'slug', 'date', 'status', 'author', 'ID', 'parent')
date format: '%Y-%m-%dT%H:%M:%S'
... | python | def get_comments_data(self, slug):
"""
Returns a flat list of all comments in XML dump. Formatted as the JSON
output from Wordpress API.
Keys:
('content', 'slug', 'date', 'status', 'author', 'ID', 'parent')
date format: '%Y-%m-%dT%H:%M:%S'
... | [
"def",
"get_comments_data",
"(",
"self",
",",
"slug",
")",
":",
"all_the_data",
"=",
"[",
"]",
"for",
"item",
"in",
"self",
".",
"chan",
".",
"findall",
"(",
"\"item\"",
")",
":",
"if",
"not",
"item",
".",
"find",
"(",
"'{wp}post_name'",
")",
".",
"t... | Returns a flat list of all comments in XML dump. Formatted as the JSON
output from Wordpress API.
Keys:
('content', 'slug', 'date', 'status', 'author', 'ID', 'parent')
date format: '%Y-%m-%dT%H:%M:%S'
author: {'username': 'Name', 'URL': ''} | [
"Returns",
"a",
"flat",
"list",
"of",
"all",
"comments",
"in",
"XML",
"dump",
".",
"Formatted",
"as",
"the",
"JSON",
"output",
"from",
"Wordpress",
"API",
".",
"Keys",
":",
"(",
"content",
"slug",
"date",
"status",
"author",
"ID",
"parent",
")",
"date",
... | train | https://github.com/thelabnyc/wagtail_blog/blob/7e092c02d10ec427c9a2c4b5dcbe910d88c628cf/blog/wp_xml_parser.py#L229-L253 |
ajenhl/tacl | tacl/highlighter.py | HighlightReport._format_content | def _format_content(self, content):
"""Returns `content` with consecutive spaces converted to non-break
spaces, and linebreak converted into HTML br elements.
:param content: text to format
:type content: `str`
:rtype: `str`
"""
content = re.sub(r'\n', '<br/>\n'... | python | def _format_content(self, content):
"""Returns `content` with consecutive spaces converted to non-break
spaces, and linebreak converted into HTML br elements.
:param content: text to format
:type content: `str`
:rtype: `str`
"""
content = re.sub(r'\n', '<br/>\n'... | [
"def",
"_format_content",
"(",
"self",
",",
"content",
")",
":",
"content",
"=",
"re",
".",
"sub",
"(",
"r'\\n'",
",",
"'<br/>\\n'",
",",
"content",
")",
"content",
"=",
"re",
".",
"sub",
"(",
"r' '",
",",
"'  '",
",",
"content",
")",
"conte... | Returns `content` with consecutive spaces converted to non-break
spaces, and linebreak converted into HTML br elements.
:param content: text to format
:type content: `str`
:rtype: `str` | [
"Returns",
"content",
"with",
"consecutive",
"spaces",
"converted",
"to",
"non",
"-",
"break",
"spaces",
"and",
"linebreak",
"converted",
"into",
"HTML",
"br",
"elements",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/highlighter.py#L24-L36 |
ajenhl/tacl | tacl/highlighter.py | HighlightReport._prepare_text | def _prepare_text(self, text):
"""Returns `text` with each consituent token wrapped in HTML markup
for later match annotation.
:param text: text to be marked up
:type text: `str`
:rtype: `str`
"""
# Remove characters that should be escaped for XML input (but
... | python | def _prepare_text(self, text):
"""Returns `text` with each consituent token wrapped in HTML markup
for later match annotation.
:param text: text to be marked up
:type text: `str`
:rtype: `str`
"""
# Remove characters that should be escaped for XML input (but
... | [
"def",
"_prepare_text",
"(",
"self",
",",
"text",
")",
":",
"# Remove characters that should be escaped for XML input (but",
"# which cause problems when escaped, since they become",
"# tokens).",
"text",
"=",
"re",
".",
"sub",
"(",
"r'[<>&]'",
",",
"''",
",",
"text",
")"... | Returns `text` with each consituent token wrapped in HTML markup
for later match annotation.
:param text: text to be marked up
:type text: `str`
:rtype: `str` | [
"Returns",
"text",
"with",
"each",
"consituent",
"token",
"wrapped",
"in",
"HTML",
"markup",
"for",
"later",
"match",
"annotation",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/highlighter.py#L52-L66 |
ajenhl/tacl | tacl/highlighter.py | NgramHighlightReport.generate | def generate(self, output_dir, work, ngrams, labels, minus_ngrams):
"""Generates HTML reports for each witness to `work`, showing its text
with the n-grams in `ngrams` highlighted.
Any n-grams in `minus_ngrams` have any highlighting of them
(or subsets of them) removed.
:param ... | python | def generate(self, output_dir, work, ngrams, labels, minus_ngrams):
"""Generates HTML reports for each witness to `work`, showing its text
with the n-grams in `ngrams` highlighted.
Any n-grams in `minus_ngrams` have any highlighting of them
(or subsets of them) removed.
:param ... | [
"def",
"generate",
"(",
"self",
",",
"output_dir",
",",
"work",
",",
"ngrams",
",",
"labels",
",",
"minus_ngrams",
")",
":",
"template",
"=",
"self",
".",
"_get_template",
"(",
")",
"colours",
"=",
"generate_colours",
"(",
"len",
"(",
"ngrams",
")",
")",... | Generates HTML reports for each witness to `work`, showing its text
with the n-grams in `ngrams` highlighted.
Any n-grams in `minus_ngrams` have any highlighting of them
(or subsets of them) removed.
:param output_dir: directory to write report to
:type output_dir: `str`
... | [
"Generates",
"HTML",
"reports",
"for",
"each",
"witness",
"to",
"work",
"showing",
"its",
"text",
"with",
"the",
"n",
"-",
"grams",
"in",
"ngrams",
"highlighted",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/highlighter.py#L94-L127 |
ajenhl/tacl | tacl/highlighter.py | NgramHighlightReport._highlight | def _highlight(self, content, ngrams, highlight):
"""Returns `content` with its n-grams from `ngrams` highlighted (if
`add_class` is True) or unhighlighted.
:param content: text to be modified
:type content: `str`
:param ngrams: n-grams to modify
:type ngrams: `list` of ... | python | def _highlight(self, content, ngrams, highlight):
"""Returns `content` with its n-grams from `ngrams` highlighted (if
`add_class` is True) or unhighlighted.
:param content: text to be modified
:type content: `str`
:param ngrams: n-grams to modify
:type ngrams: `list` of ... | [
"def",
"_highlight",
"(",
"self",
",",
"content",
",",
"ngrams",
",",
"highlight",
")",
":",
"self",
".",
"_add_highlight",
"=",
"highlight",
"for",
"ngram",
"in",
"ngrams",
":",
"pattern",
"=",
"self",
".",
"_get_regexp_pattern",
"(",
"ngram",
")",
"conte... | Returns `content` with its n-grams from `ngrams` highlighted (if
`add_class` is True) or unhighlighted.
:param content: text to be modified
:type content: `str`
:param ngrams: n-grams to modify
:type ngrams: `list` of `str`
:param highlight: whether to highlight or unhig... | [
"Returns",
"content",
"with",
"its",
"n",
"-",
"grams",
"from",
"ngrams",
"highlighted",
"(",
"if",
"add_class",
"is",
"True",
")",
"or",
"unhighlighted",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/highlighter.py#L129-L147 |
ajenhl/tacl | tacl/highlighter.py | ResultsHighlightReport.generate | def generate(self, output_dir, work, matches_filename):
"""Generates HTML reports showing the text of each witness to `work`
with its matches in `matches` highlighted.
:param output_dir: directory to write report to
:type output_dir: `str`
:param work: name of work to highlight
... | python | def generate(self, output_dir, work, matches_filename):
"""Generates HTML reports showing the text of each witness to `work`
with its matches in `matches` highlighted.
:param output_dir: directory to write report to
:type output_dir: `str`
:param work: name of work to highlight
... | [
"def",
"generate",
"(",
"self",
",",
"output_dir",
",",
"work",
",",
"matches_filename",
")",
":",
"template",
"=",
"self",
".",
"_get_template",
"(",
")",
"matches",
"=",
"pd",
".",
"read_csv",
"(",
"matches_filename",
")",
"for",
"siglum",
"in",
"self",
... | Generates HTML reports showing the text of each witness to `work`
with its matches in `matches` highlighted.
:param output_dir: directory to write report to
:type output_dir: `str`
:param work: name of work to highlight
:type text_name: `str`
:param matches_filename: fil... | [
"Generates",
"HTML",
"reports",
"showing",
"the",
"text",
"of",
"each",
"witness",
"to",
"work",
"with",
"its",
"matches",
"in",
"matches",
"highlighted",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/highlighter.py#L175-L199 |
SuperCowPowers/chains | chains/links/packet_meta.py | PacketMeta.packet_meta_data | def packet_meta_data(self):
"""Pull out the metadata about each packet from the input_stream
Args:
None
Returns:
generator (dictionary): a generator that contains packet meta data in the form of a dictionary"""
# For each packet in the pcap process th... | python | def packet_meta_data(self):
"""Pull out the metadata about each packet from the input_stream
Args:
None
Returns:
generator (dictionary): a generator that contains packet meta data in the form of a dictionary"""
# For each packet in the pcap process th... | [
"def",
"packet_meta_data",
"(",
"self",
")",
":",
"# For each packet in the pcap process the contents",
"for",
"item",
"in",
"self",
".",
"input_stream",
":",
"# Output object",
"output",
"=",
"{",
"}",
"# Grab the fields I need",
"timestamp",
"=",
"item",
"[",
"'time... | Pull out the metadata about each packet from the input_stream
Args:
None
Returns:
generator (dictionary): a generator that contains packet meta data in the form of a dictionary | [
"Pull",
"out",
"the",
"metadata",
"about",
"each",
"packet",
"from",
"the",
"input_stream",
"Args",
":",
"None",
"Returns",
":",
"generator",
"(",
"dictionary",
")",
":",
"a",
"generator",
"that",
"contains",
"packet",
"meta",
"data",
"in",
"the",
"form",
... | train | https://github.com/SuperCowPowers/chains/blob/b0227847b0c43083b456f0bae52daee0b62a3e03/chains/links/packet_meta.py#L23-L87 |
SuperCowPowers/chains | chains/links/flows.py | print_flow_info | def print_flow_info(flow):
"""Print a summary of the flow information"""
print('Flow %s (%s)-- Packets:%d Bytes:%d Payload: %s...' % (flow['flow_id'], flow['direction'], len(flow['packet_list']),
len(flow['payload']), repr(flow['payload'])[:30])) | python | def print_flow_info(flow):
"""Print a summary of the flow information"""
print('Flow %s (%s)-- Packets:%d Bytes:%d Payload: %s...' % (flow['flow_id'], flow['direction'], len(flow['packet_list']),
len(flow['payload']), repr(flow['payload'])[:30])) | [
"def",
"print_flow_info",
"(",
"flow",
")",
":",
"print",
"(",
"'Flow %s (%s)-- Packets:%d Bytes:%d Payload: %s...'",
"%",
"(",
"flow",
"[",
"'flow_id'",
"]",
",",
"flow",
"[",
"'direction'",
"]",
",",
"len",
"(",
"flow",
"[",
"'packet_list'",
"]",
")",
",",
... | Print a summary of the flow information | [
"Print",
"a",
"summary",
"of",
"the",
"flow",
"information"
] | train | https://github.com/SuperCowPowers/chains/blob/b0227847b0c43083b456f0bae52daee0b62a3e03/chains/links/flows.py#L52-L55 |
SuperCowPowers/chains | chains/links/flows.py | Flows.packets_to_flows | def packets_to_flows(self):
"""Combine packets into flows"""
# For each packet, place it into either an existing flow or a new flow
for packet in self.input_stream:
# Compute flow tuple and add the packet to the flow
flow_id = flow_utils.flow_tuple(packet)
s... | python | def packets_to_flows(self):
"""Combine packets into flows"""
# For each packet, place it into either an existing flow or a new flow
for packet in self.input_stream:
# Compute flow tuple and add the packet to the flow
flow_id = flow_utils.flow_tuple(packet)
s... | [
"def",
"packets_to_flows",
"(",
"self",
")",
":",
"# For each packet, place it into either an existing flow or a new flow",
"for",
"packet",
"in",
"self",
".",
"input_stream",
":",
"# Compute flow tuple and add the packet to the flow",
"flow_id",
"=",
"flow_utils",
".",
"flow_t... | Combine packets into flows | [
"Combine",
"packets",
"into",
"flows"
] | train | https://github.com/SuperCowPowers/chains/blob/b0227847b0c43083b456f0bae52daee0b62a3e03/chains/links/flows.py#L30-L50 |
ajenhl/tacl | tacl/report.py | Report._copy_static_assets | def _copy_static_assets(self, output_dir):
"""Copy assets for the report to `output_dir`.
:param output_dir: directory to output assets to
:type output_dir: `str`
"""
base_directory = 'assets/{}'.format(self._report_name)
for asset in resource_listdir(self._package_name... | python | def _copy_static_assets(self, output_dir):
"""Copy assets for the report to `output_dir`.
:param output_dir: directory to output assets to
:type output_dir: `str`
"""
base_directory = 'assets/{}'.format(self._report_name)
for asset in resource_listdir(self._package_name... | [
"def",
"_copy_static_assets",
"(",
"self",
",",
"output_dir",
")",
":",
"base_directory",
"=",
"'assets/{}'",
".",
"format",
"(",
"self",
".",
"_report_name",
")",
"for",
"asset",
"in",
"resource_listdir",
"(",
"self",
".",
"_package_name",
",",
"base_directory"... | Copy assets for the report to `output_dir`.
:param output_dir: directory to output assets to
:type output_dir: `str` | [
"Copy",
"assets",
"for",
"the",
"report",
"to",
"output_dir",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/report.py#L29-L40 |
ajenhl/tacl | tacl/report.py | Report._get_template | def _get_template(self):
"""Returns a template for this report.
:rtype: `jinja2.Template`
"""
loader = PackageLoader(self._package_name, 'assets/templates')
env = Environment(extensions=['jinja2.ext.with_'], loader=loader)
return env.get_template('{}.html'.format(self._... | python | def _get_template(self):
"""Returns a template for this report.
:rtype: `jinja2.Template`
"""
loader = PackageLoader(self._package_name, 'assets/templates')
env = Environment(extensions=['jinja2.ext.with_'], loader=loader)
return env.get_template('{}.html'.format(self._... | [
"def",
"_get_template",
"(",
"self",
")",
":",
"loader",
"=",
"PackageLoader",
"(",
"self",
".",
"_package_name",
",",
"'assets/templates'",
")",
"env",
"=",
"Environment",
"(",
"extensions",
"=",
"[",
"'jinja2.ext.with_'",
"]",
",",
"loader",
"=",
"loader",
... | Returns a template for this report.
:rtype: `jinja2.Template` | [
"Returns",
"a",
"template",
"for",
"this",
"report",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/report.py#L46-L54 |
ajenhl/tacl | tacl/report.py | Report._write | def _write(self, context, report_dir, report_name, assets_dir=None,
template=None):
"""Writes the data in `context` in the report's template to
`report_name` in `report_dir`.
If `assets_dir` is supplied, copies all assets for this report
to the specified directory.
... | python | def _write(self, context, report_dir, report_name, assets_dir=None,
template=None):
"""Writes the data in `context` in the report's template to
`report_name` in `report_dir`.
If `assets_dir` is supplied, copies all assets for this report
to the specified directory.
... | [
"def",
"_write",
"(",
"self",
",",
"context",
",",
"report_dir",
",",
"report_name",
",",
"assets_dir",
"=",
"None",
",",
"template",
"=",
"None",
")",
":",
"if",
"template",
"is",
"None",
":",
"template",
"=",
"self",
".",
"_get_template",
"(",
")",
"... | Writes the data in `context` in the report's template to
`report_name` in `report_dir`.
If `assets_dir` is supplied, copies all assets for this report
to the specified directory.
If `template` is supplied, uses that template instead of
automatically finding it. This is useful i... | [
"Writes",
"the",
"data",
"in",
"context",
"in",
"the",
"report",
"s",
"template",
"to",
"report_name",
"in",
"report_dir",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/report.py#L56-L87 |
SuperCowPowers/chains | chains/sinks/packet_summary.py | PacketSummary.pull | def pull(self):
"""Print out summary information about each packet from the input_stream"""
# For each packet in the pcap process the contents
for item in self.input_stream:
# Print out the timestamp in UTC
print('%s -' % item['timestamp'], end='')
# Transp... | python | def pull(self):
"""Print out summary information about each packet from the input_stream"""
# For each packet in the pcap process the contents
for item in self.input_stream:
# Print out the timestamp in UTC
print('%s -' % item['timestamp'], end='')
# Transp... | [
"def",
"pull",
"(",
"self",
")",
":",
"# For each packet in the pcap process the contents",
"for",
"item",
"in",
"self",
".",
"input_stream",
":",
"# Print out the timestamp in UTC",
"print",
"(",
"'%s -'",
"%",
"item",
"[",
"'timestamp'",
"]",
",",
"end",
"=",
"'... | Print out summary information about each packet from the input_stream | [
"Print",
"out",
"summary",
"information",
"about",
"each",
"packet",
"from",
"the",
"input_stream"
] | train | https://github.com/SuperCowPowers/chains/blob/b0227847b0c43083b456f0bae52daee0b62a3e03/chains/sinks/packet_summary.py#L17-L50 |
SuperCowPowers/chains | chains/sinks/packet_printer.py | PacketPrinter.pull | def pull(self):
"""Print out information about each packet from the input_stream"""
# For each packet in the pcap process the contents
for item in self.input_stream:
# Print out the timestamp in UTC
print('Timestamp: %s' % item['timestamp'])
# Unpack the Et... | python | def pull(self):
"""Print out information about each packet from the input_stream"""
# For each packet in the pcap process the contents
for item in self.input_stream:
# Print out the timestamp in UTC
print('Timestamp: %s' % item['timestamp'])
# Unpack the Et... | [
"def",
"pull",
"(",
"self",
")",
":",
"# For each packet in the pcap process the contents",
"for",
"item",
"in",
"self",
".",
"input_stream",
":",
"# Print out the timestamp in UTC",
"print",
"(",
"'Timestamp: %s'",
"%",
"item",
"[",
"'timestamp'",
"]",
")",
"# Unpack... | Print out information about each packet from the input_stream | [
"Print",
"out",
"information",
"about",
"each",
"packet",
"from",
"the",
"input_stream"
] | train | https://github.com/SuperCowPowers/chains/blob/b0227847b0c43083b456f0bae52daee0b62a3e03/chains/sinks/packet_printer.py#L21-L76 |
peeringdb/django-peeringdb | django_peeringdb/client_adaptor/load.py | load_backend | def load_backend(**orm_config):
"""
Load the client adaptor module of django_peeringdb
Assumes config is valid.
"""
settings = {}
settings['SECRET_KEY'] = orm_config.get('secret_key', '')
db_config = orm_config['database']
if db_config:
settings['DATABASES'] = {
'def... | python | def load_backend(**orm_config):
"""
Load the client adaptor module of django_peeringdb
Assumes config is valid.
"""
settings = {}
settings['SECRET_KEY'] = orm_config.get('secret_key', '')
db_config = orm_config['database']
if db_config:
settings['DATABASES'] = {
'def... | [
"def",
"load_backend",
"(",
"*",
"*",
"orm_config",
")",
":",
"settings",
"=",
"{",
"}",
"settings",
"[",
"'SECRET_KEY'",
"]",
"=",
"orm_config",
".",
"get",
"(",
"'secret_key'",
",",
"''",
")",
"db_config",
"=",
"orm_config",
"[",
"'database'",
"]",
"if... | Load the client adaptor module of django_peeringdb
Assumes config is valid. | [
"Load",
"the",
"client",
"adaptor",
"module",
"of",
"django_peeringdb",
"Assumes",
"config",
"is",
"valid",
"."
] | train | https://github.com/peeringdb/django-peeringdb/blob/2a32aae8a7e1c11ab6e5a873bb19619c641098c8/django_peeringdb/client_adaptor/load.py#L22-L46 |
ajenhl/tacl | tacl/results.py | Results.add_label_count | def add_label_count(self):
"""Adds to each result row a count of the number of occurrences of
that n-gram across all works within the label.
This count uses the highest witness count for each work.
"""
self._logger.info('Adding label count')
def add_label_count(df):
... | python | def add_label_count(self):
"""Adds to each result row a count of the number of occurrences of
that n-gram across all works within the label.
This count uses the highest witness count for each work.
"""
self._logger.info('Adding label count')
def add_label_count(df):
... | [
"def",
"add_label_count",
"(",
"self",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Adding label count'",
")",
"def",
"add_label_count",
"(",
"df",
")",
":",
"# For each n-gram and label pair, we need the maximum count",
"# among all witnesses to each work, and the... | Adds to each result row a count of the number of occurrences of
that n-gram across all works within the label.
This count uses the highest witness count for each work. | [
"Adds",
"to",
"each",
"result",
"row",
"a",
"count",
"of",
"the",
"number",
"of",
"occurrences",
"of",
"that",
"n",
"-",
"gram",
"across",
"all",
"works",
"within",
"the",
"label",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L58-L84 |
ajenhl/tacl | tacl/results.py | Results.add_label_work_count | def add_label_work_count(self):
"""Adds to each result row a count of the number of works within the
label contain that n-gram.
This counts works that have at least one witness carrying the
n-gram.
This correctly handles cases where an n-gram has only zero
counts for a ... | python | def add_label_work_count(self):
"""Adds to each result row a count of the number of works within the
label contain that n-gram.
This counts works that have at least one witness carrying the
n-gram.
This correctly handles cases where an n-gram has only zero
counts for a ... | [
"def",
"add_label_work_count",
"(",
"self",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Adding label work count'",
")",
"def",
"add_label_text_count",
"(",
"df",
")",
":",
"work_maxima",
"=",
"df",
".",
"groupby",
"(",
"constants",
".",
"WORK_FIELDNA... | Adds to each result row a count of the number of works within the
label contain that n-gram.
This counts works that have at least one witness carrying the
n-gram.
This correctly handles cases where an n-gram has only zero
counts for a given work (possible with zero-fill followe... | [
"Adds",
"to",
"each",
"result",
"row",
"a",
"count",
"of",
"the",
"number",
"of",
"works",
"within",
"the",
"label",
"contain",
"that",
"n",
"-",
"gram",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L88-L116 |
ajenhl/tacl | tacl/results.py | Results._annotate_bifurcated_extend_data | def _annotate_bifurcated_extend_data(self, row, smaller, larger, tokenize,
join):
"""Returns `row` annotated with whether it should be deleted or not.
An n-gram is marked for deletion if:
* its label count is 1 and its constituent (n-1)-grams also
... | python | def _annotate_bifurcated_extend_data(self, row, smaller, larger, tokenize,
join):
"""Returns `row` annotated with whether it should be deleted or not.
An n-gram is marked for deletion if:
* its label count is 1 and its constituent (n-1)-grams also
... | [
"def",
"_annotate_bifurcated_extend_data",
"(",
"self",
",",
"row",
",",
"smaller",
",",
"larger",
",",
"tokenize",
",",
"join",
")",
":",
"lcf",
"=",
"constants",
".",
"LABEL_COUNT_FIELDNAME",
"nf",
"=",
"constants",
".",
"NGRAM_FIELDNAME",
"ngram",
"=",
"row... | Returns `row` annotated with whether it should be deleted or not.
An n-gram is marked for deletion if:
* its label count is 1 and its constituent (n-1)-grams also
have a label count of 1; or
* there is a containing (n+1)-gram that has the same label
count.
:param ... | [
"Returns",
"row",
"annotated",
"with",
"whether",
"it",
"should",
"be",
"deleted",
"or",
"not",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L118-L161 |
ajenhl/tacl | tacl/results.py | Results.bifurcated_extend | def bifurcated_extend(self, corpus, max_size):
"""Replaces the results with those n-grams that contain any of the
original n-grams, and that represent points at which an n-gram
is a constituent of multiple larger n-grams with a lower label
count.
:param corpus: corpus of works t... | python | def bifurcated_extend(self, corpus, max_size):
"""Replaces the results with those n-grams that contain any of the
original n-grams, and that represent points at which an n-gram
is a constituent of multiple larger n-grams with a lower label
count.
:param corpus: corpus of works t... | [
"def",
"bifurcated_extend",
"(",
"self",
",",
"corpus",
",",
"max_size",
")",
":",
"temp_fd",
",",
"temp_path",
"=",
"tempfile",
".",
"mkstemp",
"(",
"text",
"=",
"True",
")",
"try",
":",
"self",
".",
"_prepare_bifurcated_extend_data",
"(",
"corpus",
",",
... | Replaces the results with those n-grams that contain any of the
original n-grams, and that represent points at which an n-gram
is a constituent of multiple larger n-grams with a lower label
count.
:param corpus: corpus of works to which results belong
:type corpus: `Corpus`
... | [
"Replaces",
"the",
"results",
"with",
"those",
"n",
"-",
"grams",
"that",
"contain",
"any",
"of",
"the",
"original",
"n",
"-",
"grams",
"and",
"that",
"represent",
"points",
"at",
"which",
"an",
"n",
"-",
"gram",
"is",
"a",
"constituent",
"of",
"multiple... | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L166-L189 |
ajenhl/tacl | tacl/results.py | Results.collapse_witnesses | def collapse_witnesses(self):
"""Groups together witnesses for the same n-gram and work that has the
same count, and outputs a single row for each group.
This output replaces the siglum field with a sigla field that
provides a comma separated list of the witness sigla. Due to
th... | python | def collapse_witnesses(self):
"""Groups together witnesses for the same n-gram and work that has the
same count, and outputs a single row for each group.
This output replaces the siglum field with a sigla field that
provides a comma separated list of the witness sigla. Due to
th... | [
"def",
"collapse_witnesses",
"(",
"self",
")",
":",
"# In order to allow for additional columns to be present in",
"# the input data (such as label count), copy the siglum",
"# information into a new final column, then put the sigla",
"# information into the siglum field and finally rename it.",
... | Groups together witnesses for the same n-gram and work that has the
same count, and outputs a single row for each group.
This output replaces the siglum field with a sigla field that
provides a comma separated list of the witness sigla. Due to
this, it is not necessarily possible to run... | [
"Groups",
"together",
"witnesses",
"for",
"the",
"same",
"n",
"-",
"gram",
"and",
"work",
"that",
"has",
"the",
"same",
"count",
"and",
"outputs",
"a",
"single",
"row",
"for",
"each",
"group",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L222-L266 |
ajenhl/tacl | tacl/results.py | Results.csv | def csv(self, fh):
"""Writes the results data to `fh` in CSV format and returns `fh`.
:param fh: file to write data to
:type fh: file object
:rtype: file object
"""
self._matches.to_csv(fh, encoding='utf-8', float_format='%d',
index=False)
... | python | def csv(self, fh):
"""Writes the results data to `fh` in CSV format and returns `fh`.
:param fh: file to write data to
:type fh: file object
:rtype: file object
"""
self._matches.to_csv(fh, encoding='utf-8', float_format='%d',
index=False)
... | [
"def",
"csv",
"(",
"self",
",",
"fh",
")",
":",
"self",
".",
"_matches",
".",
"to_csv",
"(",
"fh",
",",
"encoding",
"=",
"'utf-8'",
",",
"float_format",
"=",
"'%d'",
",",
"index",
"=",
"False",
")",
"return",
"fh"
] | Writes the results data to `fh` in CSV format and returns `fh`.
:param fh: file to write data to
:type fh: file object
:rtype: file object | [
"Writes",
"the",
"results",
"data",
"to",
"fh",
"in",
"CSV",
"format",
"and",
"returns",
"fh",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L268-L278 |
ajenhl/tacl | tacl/results.py | Results.excise | def excise(self, ngram):
"""Removes all rows whose n-gram contains `ngram`.
This operation uses simple string containment matching. For
tokens that consist of multiple characters, this means that
`ngram` may be part of one or two tokens; eg, "he m" would
match on "she may".
... | python | def excise(self, ngram):
"""Removes all rows whose n-gram contains `ngram`.
This operation uses simple string containment matching. For
tokens that consist of multiple characters, this means that
`ngram` may be part of one or two tokens; eg, "he m" would
match on "she may".
... | [
"def",
"excise",
"(",
"self",
",",
"ngram",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Excising results containing \"{}\"'",
".",
"format",
"(",
"ngram",
")",
")",
"if",
"not",
"ngram",
":",
"return",
"self",
".",
"_matches",
"=",
"self",
".",... | Removes all rows whose n-gram contains `ngram`.
This operation uses simple string containment matching. For
tokens that consist of multiple characters, this means that
`ngram` may be part of one or two tokens; eg, "he m" would
match on "she may".
:param ngram: n-gram to remove ... | [
"Removes",
"all",
"rows",
"whose",
"n",
"-",
"gram",
"contains",
"ngram",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L281-L297 |
ajenhl/tacl | tacl/results.py | Results.extend | def extend(self, corpus):
"""Adds rows for all longer forms of n-grams in the results that are
present in the witnesses.
This works with both diff and intersect results.
:param corpus: corpus of works to which results belong
:type corpus: `Corpus`
"""
self._log... | python | def extend(self, corpus):
"""Adds rows for all longer forms of n-grams in the results that are
present in the witnesses.
This works with both diff and intersect results.
:param corpus: corpus of works to which results belong
:type corpus: `Corpus`
"""
self._log... | [
"def",
"extend",
"(",
"self",
",",
"corpus",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Extending results'",
")",
"if",
"self",
".",
"_matches",
".",
"empty",
":",
"return",
"highest_n",
"=",
"self",
".",
"_matches",
"[",
"constants",
".",
"... | Adds rows for all longer forms of n-grams in the results that are
present in the witnesses.
This works with both diff and intersect results.
:param corpus: corpus of works to which results belong
:type corpus: `Corpus` | [
"Adds",
"rows",
"for",
"all",
"longer",
"forms",
"of",
"n",
"-",
"grams",
"in",
"the",
"results",
"that",
"are",
"present",
"in",
"the",
"witnesses",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L302-L349 |
ajenhl/tacl | tacl/results.py | Results._generate_extended_matches | def _generate_extended_matches(self, extended_ngrams, highest_n, work,
siglum, label):
"""Returns extended match data derived from `extended_ngrams`.
This extended match data are the counts for all intermediate
n-grams within each extended n-gram.
:pa... | python | def _generate_extended_matches(self, extended_ngrams, highest_n, work,
siglum, label):
"""Returns extended match data derived from `extended_ngrams`.
This extended match data are the counts for all intermediate
n-grams within each extended n-gram.
:pa... | [
"def",
"_generate_extended_matches",
"(",
"self",
",",
"extended_ngrams",
",",
"highest_n",
",",
"work",
",",
"siglum",
",",
"label",
")",
":",
"# Add data for each n-gram within each extended n-gram. Since",
"# this treats each extended piece of text separately, the same",
"# n-... | Returns extended match data derived from `extended_ngrams`.
This extended match data are the counts for all intermediate
n-grams within each extended n-gram.
:param extended_ngrams: extended n-grams
:type extended_ngrams: `list` of `str`
:param highest_n: the highest degree of ... | [
"Returns",
"extended",
"match",
"data",
"derived",
"from",
"extended_ngrams",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L351-L403 |
ajenhl/tacl | tacl/results.py | Results._generate_extended_ngrams | def _generate_extended_ngrams(self, matches, work, siglum, label, corpus,
highest_n):
"""Returns the n-grams of the largest size that exist in `siglum`
witness to `work` under `label`, generated from adding
together overlapping n-grams in `matches`.
:pa... | python | def _generate_extended_ngrams(self, matches, work, siglum, label, corpus,
highest_n):
"""Returns the n-grams of the largest size that exist in `siglum`
witness to `work` under `label`, generated from adding
together overlapping n-grams in `matches`.
:pa... | [
"def",
"_generate_extended_ngrams",
"(",
"self",
",",
"matches",
",",
"work",
",",
"siglum",
",",
"label",
",",
"corpus",
",",
"highest_n",
")",
":",
"# For large result sets, this method may involve a lot of",
"# processing within the for loop, so optimise even small",
"# th... | Returns the n-grams of the largest size that exist in `siglum`
witness to `work` under `label`, generated from adding
together overlapping n-grams in `matches`.
:param matches: n-gram matches
:type matches: `pandas.DataFrame`
:param work: name of work whose results are being pro... | [
"Returns",
"the",
"n",
"-",
"grams",
"of",
"the",
"largest",
"size",
"that",
"exist",
"in",
"siglum",
"witness",
"to",
"work",
"under",
"label",
"generated",
"from",
"adding",
"together",
"overlapping",
"n",
"-",
"grams",
"in",
"matches",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L405-L498 |
ajenhl/tacl | tacl/results.py | Results._generate_filter_ngrams | def _generate_filter_ngrams(self, data, min_size):
"""Returns the n-grams in `data` that do not contain any other n-gram
in `data`.
:param data: n-gram results data
:type data: `pandas.DataFrame`
:param min_size: minimum n-gram size in `data`
:type min_size: `int`
... | python | def _generate_filter_ngrams(self, data, min_size):
"""Returns the n-grams in `data` that do not contain any other n-gram
in `data`.
:param data: n-gram results data
:type data: `pandas.DataFrame`
:param min_size: minimum n-gram size in `data`
:type min_size: `int`
... | [
"def",
"_generate_filter_ngrams",
"(",
"self",
",",
"data",
",",
"min_size",
")",
":",
"max_size",
"=",
"data",
"[",
"constants",
".",
"SIZE_FIELDNAME",
"]",
".",
"max",
"(",
")",
"kept_ngrams",
"=",
"list",
"(",
"data",
"[",
"data",
"[",
"constants",
".... | Returns the n-grams in `data` that do not contain any other n-gram
in `data`.
:param data: n-gram results data
:type data: `pandas.DataFrame`
:param min_size: minimum n-gram size in `data`
:type min_size: `int`
:rtype: `list` of `str` | [
"Returns",
"the",
"n",
"-",
"grams",
"in",
"data",
"that",
"do",
"not",
"contain",
"any",
"other",
"n",
"-",
"gram",
"in",
"data",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L500-L521 |
ajenhl/tacl | tacl/results.py | Results._generate_substrings | def _generate_substrings(self, ngram, size):
"""Returns a list of all substrings of `ngram`.
:param ngram: n-gram to generate substrings of
:type ngram: `str`
:param size: size of `ngram`
:type size: `int`
:rtype: `list`
"""
text = Text(ngram, self._toke... | python | def _generate_substrings(self, ngram, size):
"""Returns a list of all substrings of `ngram`.
:param ngram: n-gram to generate substrings of
:type ngram: `str`
:param size: size of `ngram`
:type size: `int`
:rtype: `list`
"""
text = Text(ngram, self._toke... | [
"def",
"_generate_substrings",
"(",
"self",
",",
"ngram",
",",
"size",
")",
":",
"text",
"=",
"Text",
"(",
"ngram",
",",
"self",
".",
"_tokenizer",
")",
"substrings",
"=",
"[",
"]",
"for",
"sub_size",
",",
"ngrams",
"in",
"text",
".",
"get_ngrams",
"("... | Returns a list of all substrings of `ngram`.
:param ngram: n-gram to generate substrings of
:type ngram: `str`
:param size: size of `ngram`
:type size: `int`
:rtype: `list` | [
"Returns",
"a",
"list",
"of",
"all",
"substrings",
"of",
"ngram",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L523-L538 |
ajenhl/tacl | tacl/results.py | Results.group_by_ngram | def group_by_ngram(self, labels):
"""Groups result rows by n-gram and label, providing a single summary
field giving the range of occurrences across each work's
witnesses. Results are sorted by n-gram then by label (in the
order given in `labels`).
:param labels: labels to order... | python | def group_by_ngram(self, labels):
"""Groups result rows by n-gram and label, providing a single summary
field giving the range of occurrences across each work's
witnesses. Results are sorted by n-gram then by label (in the
order given in `labels`).
:param labels: labels to order... | [
"def",
"group_by_ngram",
"(",
"self",
",",
"labels",
")",
":",
"if",
"self",
".",
"_matches",
".",
"empty",
":",
"# Ensure that the right columns are used, even though the",
"# results are empty.",
"self",
".",
"_matches",
"=",
"pd",
".",
"DataFrame",
"(",
"{",
"}... | Groups result rows by n-gram and label, providing a single summary
field giving the range of occurrences across each work's
witnesses. Results are sorted by n-gram then by label (in the
order given in `labels`).
:param labels: labels to order on
:type labels: `list` of `str` | [
"Groups",
"result",
"rows",
"by",
"n",
"-",
"gram",
"and",
"label",
"providing",
"a",
"single",
"summary",
"field",
"giving",
"the",
"range",
"of",
"occurrences",
"across",
"each",
"work",
"s",
"witnesses",
".",
"Results",
"are",
"sorted",
"by",
"n",
"-",
... | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L551-L608 |
ajenhl/tacl | tacl/results.py | Results.group_by_witness | def group_by_witness(self):
"""Groups results by witness, providing a single summary field giving
the n-grams found in it, a count of their number, and the count of
their combined occurrences."""
if self._matches.empty:
# Ensure that the right columns are used, even though th... | python | def group_by_witness(self):
"""Groups results by witness, providing a single summary field giving
the n-grams found in it, a count of their number, and the count of
their combined occurrences."""
if self._matches.empty:
# Ensure that the right columns are used, even though th... | [
"def",
"group_by_witness",
"(",
"self",
")",
":",
"if",
"self",
".",
"_matches",
".",
"empty",
":",
"# Ensure that the right columns are used, even though the",
"# results are empty.",
"self",
".",
"_matches",
"=",
"pd",
".",
"DataFrame",
"(",
"{",
"}",
",",
"colu... | Groups results by witness, providing a single summary field giving
the n-grams found in it, a count of their number, and the count of
their combined occurrences. | [
"Groups",
"results",
"by",
"witness",
"providing",
"a",
"single",
"summary",
"field",
"giving",
"the",
"n",
"-",
"grams",
"found",
"in",
"it",
"a",
"count",
"of",
"their",
"number",
"and",
"the",
"count",
"of",
"their",
"combined",
"occurrences",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L613-L648 |
ajenhl/tacl | tacl/results.py | Results._is_intersect_results | def _is_intersect_results(results):
"""Returns False if `results` has an n-gram that exists in only one
label, True otherwise.
:param results: results to analyze
:type results: `pandas.DataFrame`
:rtype: `bool`
"""
sample = results.iloc[0]
ngram = sample... | python | def _is_intersect_results(results):
"""Returns False if `results` has an n-gram that exists in only one
label, True otherwise.
:param results: results to analyze
:type results: `pandas.DataFrame`
:rtype: `bool`
"""
sample = results.iloc[0]
ngram = sample... | [
"def",
"_is_intersect_results",
"(",
"results",
")",
":",
"sample",
"=",
"results",
".",
"iloc",
"[",
"0",
"]",
"ngram",
"=",
"sample",
"[",
"constants",
".",
"NGRAM_FIELDNAME",
"]",
"label",
"=",
"sample",
"[",
"constants",
".",
"LABEL_FIELDNAME",
"]",
"r... | Returns False if `results` has an n-gram that exists in only one
label, True otherwise.
:param results: results to analyze
:type results: `pandas.DataFrame`
:rtype: `bool` | [
"Returns",
"False",
"if",
"results",
"has",
"an",
"n",
"-",
"gram",
"that",
"exists",
"in",
"only",
"one",
"label",
"True",
"otherwise",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L651-L665 |
ajenhl/tacl | tacl/results.py | Results.prune_by_ngram | def prune_by_ngram(self, ngrams):
"""Removes results rows whose n-gram is in `ngrams`.
:param ngrams: n-grams to remove
:type ngrams: `list` of `str`
"""
self._logger.info('Pruning results by n-gram')
self._matches = self._matches[
~self._matches[constants.N... | python | def prune_by_ngram(self, ngrams):
"""Removes results rows whose n-gram is in `ngrams`.
:param ngrams: n-grams to remove
:type ngrams: `list` of `str`
"""
self._logger.info('Pruning results by n-gram')
self._matches = self._matches[
~self._matches[constants.N... | [
"def",
"prune_by_ngram",
"(",
"self",
",",
"ngrams",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Pruning results by n-gram'",
")",
"self",
".",
"_matches",
"=",
"self",
".",
"_matches",
"[",
"~",
"self",
".",
"_matches",
"[",
"constants",
".",
... | Removes results rows whose n-gram is in `ngrams`.
:param ngrams: n-grams to remove
:type ngrams: `list` of `str` | [
"Removes",
"results",
"rows",
"whose",
"n",
"-",
"gram",
"is",
"in",
"ngrams",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L704-L713 |
ajenhl/tacl | tacl/results.py | Results.prune_by_ngram_count | def prune_by_ngram_count(self, minimum=None, maximum=None, label=None):
"""Removes results rows whose total n-gram count (across all
works bearing this n-gram) is outside the range specified by
`minimum` and `maximum`.
For each text, the count used as part of the sum across all
... | python | def prune_by_ngram_count(self, minimum=None, maximum=None, label=None):
"""Removes results rows whose total n-gram count (across all
works bearing this n-gram) is outside the range specified by
`minimum` and `maximum`.
For each text, the count used as part of the sum across all
... | [
"def",
"prune_by_ngram_count",
"(",
"self",
",",
"minimum",
"=",
"None",
",",
"maximum",
"=",
"None",
",",
"label",
"=",
"None",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Pruning results by n-gram count'",
")",
"def",
"calculate_total",
"(",
"gro... | Removes results rows whose total n-gram count (across all
works bearing this n-gram) is outside the range specified by
`minimum` and `maximum`.
For each text, the count used as part of the sum across all
works is the maximum count across the witnesses for that work.
If `label` ... | [
"Removes",
"results",
"rows",
"whose",
"total",
"n",
"-",
"gram",
"count",
"(",
"across",
"all",
"works",
"bearing",
"this",
"n",
"-",
"gram",
")",
"is",
"outside",
"the",
"range",
"specified",
"by",
"minimum",
"and",
"maximum",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L717-L768 |
ajenhl/tacl | tacl/results.py | Results.prune_by_ngram_count_per_work | def prune_by_ngram_count_per_work(self, minimum=None, maximum=None,
label=None):
"""Removes results rows if the n-gram count for all works bearing that
n-gram is outside the range specified by `minimum` and
`maximum`.
That is, if a single witness of... | python | def prune_by_ngram_count_per_work(self, minimum=None, maximum=None,
label=None):
"""Removes results rows if the n-gram count for all works bearing that
n-gram is outside the range specified by `minimum` and
`maximum`.
That is, if a single witness of... | [
"def",
"prune_by_ngram_count_per_work",
"(",
"self",
",",
"minimum",
"=",
"None",
",",
"maximum",
"=",
"None",
",",
"label",
"=",
"None",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Pruning results by n-gram count per work'",
")",
"matches",
"=",
"se... | Removes results rows if the n-gram count for all works bearing that
n-gram is outside the range specified by `minimum` and
`maximum`.
That is, if a single witness of a single work has an n-gram
count that falls within the specified range, all result rows
for that n-gram are kept... | [
"Removes",
"results",
"rows",
"if",
"the",
"n",
"-",
"gram",
"count",
"for",
"all",
"works",
"bearing",
"that",
"n",
"-",
"gram",
"is",
"outside",
"the",
"range",
"specified",
"by",
"minimum",
"and",
"maximum",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L771-L811 |
ajenhl/tacl | tacl/results.py | Results.prune_by_ngram_size | def prune_by_ngram_size(self, minimum=None, maximum=None):
"""Removes results rows whose n-gram size is outside the
range specified by `minimum` and `maximum`.
:param minimum: minimum n-gram size
:type minimum: `int`
:param maximum: maximum n-gram size
:type maximum: `in... | python | def prune_by_ngram_size(self, minimum=None, maximum=None):
"""Removes results rows whose n-gram size is outside the
range specified by `minimum` and `maximum`.
:param minimum: minimum n-gram size
:type minimum: `int`
:param maximum: maximum n-gram size
:type maximum: `in... | [
"def",
"prune_by_ngram_size",
"(",
"self",
",",
"minimum",
"=",
"None",
",",
"maximum",
"=",
"None",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Pruning results by n-gram size'",
")",
"if",
"minimum",
":",
"self",
".",
"_matches",
"=",
"self",
".... | Removes results rows whose n-gram size is outside the
range specified by `minimum` and `maximum`.
:param minimum: minimum n-gram size
:type minimum: `int`
:param maximum: maximum n-gram size
:type maximum: `int` | [
"Removes",
"results",
"rows",
"whose",
"n",
"-",
"gram",
"size",
"is",
"outside",
"the",
"range",
"specified",
"by",
"minimum",
"and",
"maximum",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L814-L830 |
ajenhl/tacl | tacl/results.py | Results.prune_by_work_count | def prune_by_work_count(self, minimum=None, maximum=None, label=None):
"""Removes results rows for n-grams that are not attested in a
number of works in the range specified by `minimum` and
`maximum`.
Work here encompasses all witnesses, so that the same n-gram
appearing in mult... | python | def prune_by_work_count(self, minimum=None, maximum=None, label=None):
"""Removes results rows for n-grams that are not attested in a
number of works in the range specified by `minimum` and
`maximum`.
Work here encompasses all witnesses, so that the same n-gram
appearing in mult... | [
"def",
"prune_by_work_count",
"(",
"self",
",",
"minimum",
"=",
"None",
",",
"maximum",
"=",
"None",
",",
"label",
"=",
"None",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Pruning results by work count'",
")",
"count_fieldname",
"=",
"'tmp_count'",
... | Removes results rows for n-grams that are not attested in a
number of works in the range specified by `minimum` and
`maximum`.
Work here encompasses all witnesses, so that the same n-gram
appearing in multiple witnesses of the same work are counted
as a single work.
If ... | [
"Removes",
"results",
"rows",
"for",
"n",
"-",
"grams",
"that",
"are",
"not",
"attested",
"in",
"a",
"number",
"of",
"works",
"in",
"the",
"range",
"specified",
"by",
"minimum",
"and",
"maximum",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L834-L871 |
ajenhl/tacl | tacl/results.py | Results.reciprocal_remove | def reciprocal_remove(self):
"""Removes results rows for which the n-gram is not present in
at least one text in each labelled set of texts."""
self._logger.info(
'Removing n-grams that are not attested in all labels')
self._matches = self._reciprocal_remove(self._matches) | python | def reciprocal_remove(self):
"""Removes results rows for which the n-gram is not present in
at least one text in each labelled set of texts."""
self._logger.info(
'Removing n-grams that are not attested in all labels')
self._matches = self._reciprocal_remove(self._matches) | [
"def",
"reciprocal_remove",
"(",
"self",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Removing n-grams that are not attested in all labels'",
")",
"self",
".",
"_matches",
"=",
"self",
".",
"_reciprocal_remove",
"(",
"self",
".",
"_matches",
")"
] | Removes results rows for which the n-gram is not present in
at least one text in each labelled set of texts. | [
"Removes",
"results",
"rows",
"for",
"which",
"the",
"n",
"-",
"gram",
"is",
"not",
"present",
"in",
"at",
"least",
"one",
"text",
"in",
"each",
"labelled",
"set",
"of",
"texts",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L875-L880 |
ajenhl/tacl | tacl/results.py | Results.reduce | def reduce(self):
"""Removes results rows whose n-grams are contained in larger
n-grams."""
self._logger.info('Reducing the n-grams')
# This does not make use of any pandas functionality; it
# probably could, and if so ought to.
data = {}
labels = {}
# Der... | python | def reduce(self):
"""Removes results rows whose n-grams are contained in larger
n-grams."""
self._logger.info('Reducing the n-grams')
# This does not make use of any pandas functionality; it
# probably could, and if so ought to.
data = {}
labels = {}
# Der... | [
"def",
"reduce",
"(",
"self",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Reducing the n-grams'",
")",
"# This does not make use of any pandas functionality; it",
"# probably could, and if so ought to.",
"data",
"=",
"{",
"}",
"labels",
"=",
"{",
"}",
"# Der... | Removes results rows whose n-grams are contained in larger
n-grams. | [
"Removes",
"results",
"rows",
"whose",
"n",
"-",
"grams",
"are",
"contained",
"in",
"larger",
"n",
"-",
"grams",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L892-L930 |
ajenhl/tacl | tacl/results.py | Results._reduce_by_ngram | def _reduce_by_ngram(self, data, ngram):
"""Lowers the counts of all n-grams in `data` that are
substrings of `ngram` by `ngram`\'s count.
Modifies `data` in place.
:param data: row data dictionary for the current text
:type data: `dict`
:param ngram: n-gram being reduc... | python | def _reduce_by_ngram(self, data, ngram):
"""Lowers the counts of all n-grams in `data` that are
substrings of `ngram` by `ngram`\'s count.
Modifies `data` in place.
:param data: row data dictionary for the current text
:type data: `dict`
:param ngram: n-gram being reduc... | [
"def",
"_reduce_by_ngram",
"(",
"self",
",",
"data",
",",
"ngram",
")",
":",
"# Find all substrings of `ngram` and reduce their count by the",
"# count of `ngram`. Substrings may not exist in `data`.",
"count",
"=",
"data",
"[",
"ngram",
"]",
"[",
"'count'",
"]",
"for",
"... | Lowers the counts of all n-grams in `data` that are
substrings of `ngram` by `ngram`\'s count.
Modifies `data` in place.
:param data: row data dictionary for the current text
:type data: `dict`
:param ngram: n-gram being reduced
:type ngram: `str` | [
"Lowers",
"the",
"counts",
"of",
"all",
"n",
"-",
"grams",
"in",
"data",
"that",
"are",
"substrings",
"of",
"ngram",
"by",
"ngram",
"\\",
"s",
"count",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L932-L953 |
ajenhl/tacl | tacl/results.py | Results.relabel | def relabel(self, catalogue):
"""Relabels results rows according to `catalogue`.
A row whose work is labelled in the catalogue will have its
label set to the label in the catalogue. Rows whose works are
not labelled in the catalogue will be unchanged.
:param catalogue: mapping ... | python | def relabel(self, catalogue):
"""Relabels results rows according to `catalogue`.
A row whose work is labelled in the catalogue will have its
label set to the label in the catalogue. Rows whose works are
not labelled in the catalogue will be unchanged.
:param catalogue: mapping ... | [
"def",
"relabel",
"(",
"self",
",",
"catalogue",
")",
":",
"for",
"work",
",",
"label",
"in",
"catalogue",
".",
"items",
"(",
")",
":",
"self",
".",
"_matches",
".",
"loc",
"[",
"self",
".",
"_matches",
"[",
"constants",
".",
"WORK_FIELDNAME",
"]",
"... | Relabels results rows according to `catalogue`.
A row whose work is labelled in the catalogue will have its
label set to the label in the catalogue. Rows whose works are
not labelled in the catalogue will be unchanged.
:param catalogue: mapping of work names to labels
:type cat... | [
"Relabels",
"results",
"rows",
"according",
"to",
"catalogue",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L956-L969 |
ajenhl/tacl | tacl/results.py | Results.remove_label | def remove_label(self, label):
"""Removes all results rows associated with `label`.
:param label: label to filter results on
:type label: `str`
"""
self._logger.info('Removing label "{}"'.format(label))
count = self._matches[constants.LABEL_FIELDNAME].value_counts().get... | python | def remove_label(self, label):
"""Removes all results rows associated with `label`.
:param label: label to filter results on
:type label: `str`
"""
self._logger.info('Removing label "{}"'.format(label))
count = self._matches[constants.LABEL_FIELDNAME].value_counts().get... | [
"def",
"remove_label",
"(",
"self",
",",
"label",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Removing label \"{}\"'",
".",
"format",
"(",
"label",
")",
")",
"count",
"=",
"self",
".",
"_matches",
"[",
"constants",
".",
"LABEL_FIELDNAME",
"]",
... | Removes all results rows associated with `label`.
:param label: label to filter results on
:type label: `str` | [
"Removes",
"all",
"results",
"rows",
"associated",
"with",
"label",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L972-L984 |
ajenhl/tacl | tacl/results.py | Results.sort | def sort(self):
"""Sorts all results rows.
Sorts by: size (descending), n-gram, count (descending), label,
text name, siglum.
"""
self._matches.sort_values(
by=[constants.SIZE_FIELDNAME, constants.NGRAM_FIELDNAME,
constants.COUNT_FIELDNAME, constants... | python | def sort(self):
"""Sorts all results rows.
Sorts by: size (descending), n-gram, count (descending), label,
text name, siglum.
"""
self._matches.sort_values(
by=[constants.SIZE_FIELDNAME, constants.NGRAM_FIELDNAME,
constants.COUNT_FIELDNAME, constants... | [
"def",
"sort",
"(",
"self",
")",
":",
"self",
".",
"_matches",
".",
"sort_values",
"(",
"by",
"=",
"[",
"constants",
".",
"SIZE_FIELDNAME",
",",
"constants",
".",
"NGRAM_FIELDNAME",
",",
"constants",
".",
"COUNT_FIELDNAME",
",",
"constants",
".",
"LABEL_FIEL... | Sorts all results rows.
Sorts by: size (descending), n-gram, count (descending), label,
text name, siglum. | [
"Sorts",
"all",
"results",
"rows",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L989-L1000 |
ajenhl/tacl | tacl/results.py | Results.zero_fill | def zero_fill(self, corpus):
"""Adds rows to the results to ensure that, for every n-gram that is
attested in at least one witness, every witness for that text
has a row, with added rows having a count of zero.
:param corpus: corpus containing the texts appearing in the results
... | python | def zero_fill(self, corpus):
"""Adds rows to the results to ensure that, for every n-gram that is
attested in at least one witness, every witness for that text
has a row, with added rows having a count of zero.
:param corpus: corpus containing the texts appearing in the results
... | [
"def",
"zero_fill",
"(",
"self",
",",
"corpus",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Zero-filling results'",
")",
"zero_rows",
"=",
"[",
"]",
"work_sigla",
"=",
"{",
"}",
"grouping_cols",
"=",
"[",
"constants",
".",
"LABEL_FIELDNAME",
",",... | Adds rows to the results to ensure that, for every n-gram that is
attested in at least one witness, every witness for that text
has a row, with added rows having a count of zero.
:param corpus: corpus containing the texts appearing in the results
:type corpus: `Corpus` | [
"Adds",
"rows",
"to",
"the",
"results",
"to",
"ensure",
"that",
"for",
"every",
"n",
"-",
"gram",
"that",
"is",
"attested",
"in",
"at",
"least",
"one",
"witness",
"every",
"witness",
"for",
"that",
"text",
"has",
"a",
"row",
"with",
"added",
"rows",
"h... | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/results.py#L1005-L1036 |
SuperCowPowers/chains | chains/utils/log_utils.py | get_logger | def get_logger():
"""Setup logging output defaults"""
# Grab the logger
if not hasattr(get_logger, 'logger'):
# Setup the default logging config
get_logger.logger = logging.getLogger('chains')
format_str = '%(asctime)s [%(levelname)s] - %(module)s: %(message)s'
logging.basi... | python | def get_logger():
"""Setup logging output defaults"""
# Grab the logger
if not hasattr(get_logger, 'logger'):
# Setup the default logging config
get_logger.logger = logging.getLogger('chains')
format_str = '%(asctime)s [%(levelname)s] - %(module)s: %(message)s'
logging.basi... | [
"def",
"get_logger",
"(",
")",
":",
"# Grab the logger",
"if",
"not",
"hasattr",
"(",
"get_logger",
",",
"'logger'",
")",
":",
"# Setup the default logging config",
"get_logger",
".",
"logger",
"=",
"logging",
".",
"getLogger",
"(",
"'chains'",
")",
"format_str",
... | Setup logging output defaults | [
"Setup",
"logging",
"output",
"defaults"
] | train | https://github.com/SuperCowPowers/chains/blob/b0227847b0c43083b456f0bae52daee0b62a3e03/chains/utils/log_utils.py#L7-L19 |
SuperCowPowers/chains | chains/sources/packet_streamer.py | PacketStreamer.read_interface | def read_interface(self):
"""Read Packets from the packet capture interface"""
# Spin up the packet capture
if self._iface_is_file():
self.pcap = pcapy.open_offline(self.iface_name)
else:
try:
# self.pcap = pcap.pcap(name=self.iface_name, promisc=... | python | def read_interface(self):
"""Read Packets from the packet capture interface"""
# Spin up the packet capture
if self._iface_is_file():
self.pcap = pcapy.open_offline(self.iface_name)
else:
try:
# self.pcap = pcap.pcap(name=self.iface_name, promisc=... | [
"def",
"read_interface",
"(",
"self",
")",
":",
"# Spin up the packet capture",
"if",
"self",
".",
"_iface_is_file",
"(",
")",
":",
"self",
".",
"pcap",
"=",
"pcapy",
".",
"open_offline",
"(",
"self",
".",
"iface_name",
")",
"else",
":",
"try",
":",
"# sel... | Read Packets from the packet capture interface | [
"Read",
"Packets",
"from",
"the",
"packet",
"capture",
"interface"
] | train | https://github.com/SuperCowPowers/chains/blob/b0227847b0c43083b456f0bae52daee0b62a3e03/chains/sources/packet_streamer.py#L64-L114 |
ajenhl/tacl | tacl/__main__.py | generate_parser | def generate_parser():
"""Returns a parser configured with sub-commands and arguments."""
parser = argparse.ArgumentParser(
description=constants.TACL_DESCRIPTION,
formatter_class=ParagraphFormatter)
subparsers = parser.add_subparsers(title='subcommands')
generate_align_subparser(subpars... | python | def generate_parser():
"""Returns a parser configured with sub-commands and arguments."""
parser = argparse.ArgumentParser(
description=constants.TACL_DESCRIPTION,
formatter_class=ParagraphFormatter)
subparsers = parser.add_subparsers(title='subcommands')
generate_align_subparser(subpars... | [
"def",
"generate_parser",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"constants",
".",
"TACL_DESCRIPTION",
",",
"formatter_class",
"=",
"ParagraphFormatter",
")",
"subparsers",
"=",
"parser",
".",
"add_subparsers",
"(... | Returns a parser configured with sub-commands and arguments. | [
"Returns",
"a",
"parser",
"configured",
"with",
"sub",
"-",
"commands",
"and",
"arguments",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/__main__.py#L73-L95 |
ajenhl/tacl | tacl/__main__.py | generate_align_subparser | def generate_align_subparser(subparsers):
"""Adds a sub-command parser to `subparsers` to generate aligned
sequences from a set of results."""
parser = subparsers.add_parser(
'align', description=constants.ALIGN_DESCRIPTION,
epilog=constants.ALIGN_EPILOG,
formatter_class=ParagraphFor... | python | def generate_align_subparser(subparsers):
"""Adds a sub-command parser to `subparsers` to generate aligned
sequences from a set of results."""
parser = subparsers.add_parser(
'align', description=constants.ALIGN_DESCRIPTION,
epilog=constants.ALIGN_EPILOG,
formatter_class=ParagraphFor... | [
"def",
"generate_align_subparser",
"(",
"subparsers",
")",
":",
"parser",
"=",
"subparsers",
".",
"add_parser",
"(",
"'align'",
",",
"description",
"=",
"constants",
".",
"ALIGN_DESCRIPTION",
",",
"epilog",
"=",
"constants",
".",
"ALIGN_EPILOG",
",",
"formatter_cl... | Adds a sub-command parser to `subparsers` to generate aligned
sequences from a set of results. | [
"Adds",
"a",
"sub",
"-",
"command",
"parser",
"to",
"subparsers",
"to",
"generate",
"aligned",
"sequences",
"from",
"a",
"set",
"of",
"results",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/__main__.py#L98-L113 |
ajenhl/tacl | tacl/__main__.py | generate_catalogue | def generate_catalogue(args, parser):
"""Generates and saves a catalogue file."""
catalogue = tacl.Catalogue()
catalogue.generate(args.corpus, args.label)
catalogue.save(args.catalogue) | python | def generate_catalogue(args, parser):
"""Generates and saves a catalogue file."""
catalogue = tacl.Catalogue()
catalogue.generate(args.corpus, args.label)
catalogue.save(args.catalogue) | [
"def",
"generate_catalogue",
"(",
"args",
",",
"parser",
")",
":",
"catalogue",
"=",
"tacl",
".",
"Catalogue",
"(",
")",
"catalogue",
".",
"generate",
"(",
"args",
".",
"corpus",
",",
"args",
".",
"label",
")",
"catalogue",
".",
"save",
"(",
"args",
".... | Generates and saves a catalogue file. | [
"Generates",
"and",
"saves",
"a",
"catalogue",
"file",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/__main__.py#L116-L120 |
ajenhl/tacl | tacl/__main__.py | generate_catalogue_subparser | def generate_catalogue_subparser(subparsers):
"""Adds a sub-command parser to `subparsers` to generate and save
a catalogue file."""
parser = subparsers.add_parser(
'catalogue', description=constants.CATALOGUE_DESCRIPTION,
epilog=constants.CATALOGUE_EPILOG,
formatter_class=ParagraphF... | python | def generate_catalogue_subparser(subparsers):
"""Adds a sub-command parser to `subparsers` to generate and save
a catalogue file."""
parser = subparsers.add_parser(
'catalogue', description=constants.CATALOGUE_DESCRIPTION,
epilog=constants.CATALOGUE_EPILOG,
formatter_class=ParagraphF... | [
"def",
"generate_catalogue_subparser",
"(",
"subparsers",
")",
":",
"parser",
"=",
"subparsers",
".",
"add_parser",
"(",
"'catalogue'",
",",
"description",
"=",
"constants",
".",
"CATALOGUE_DESCRIPTION",
",",
"epilog",
"=",
"constants",
".",
"CATALOGUE_EPILOG",
",",... | Adds a sub-command parser to `subparsers` to generate and save
a catalogue file. | [
"Adds",
"a",
"sub",
"-",
"command",
"parser",
"to",
"subparsers",
"to",
"generate",
"and",
"save",
"a",
"catalogue",
"file",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/__main__.py#L123-L136 |
ajenhl/tacl | tacl/__main__.py | generate_counts_subparser | def generate_counts_subparser(subparsers):
"""Adds a sub-command parser to `subparsers` to make a counts
query."""
parser = subparsers.add_parser(
'counts', description=constants.COUNTS_DESCRIPTION,
epilog=constants.COUNTS_EPILOG, formatter_class=ParagraphFormatter,
help=constants.CO... | python | def generate_counts_subparser(subparsers):
"""Adds a sub-command parser to `subparsers` to make a counts
query."""
parser = subparsers.add_parser(
'counts', description=constants.COUNTS_DESCRIPTION,
epilog=constants.COUNTS_EPILOG, formatter_class=ParagraphFormatter,
help=constants.CO... | [
"def",
"generate_counts_subparser",
"(",
"subparsers",
")",
":",
"parser",
"=",
"subparsers",
".",
"add_parser",
"(",
"'counts'",
",",
"description",
"=",
"constants",
".",
"COUNTS_DESCRIPTION",
",",
"epilog",
"=",
"constants",
".",
"COUNTS_EPILOG",
",",
"formatte... | Adds a sub-command parser to `subparsers` to make a counts
query. | [
"Adds",
"a",
"sub",
"-",
"command",
"parser",
"to",
"subparsers",
"to",
"make",
"a",
"counts",
"query",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/__main__.py#L139-L150 |
ajenhl/tacl | tacl/__main__.py | generate_diff_subparser | def generate_diff_subparser(subparsers):
"""Adds a sub-command parser to `subparsers` to make a diff
query."""
parser = subparsers.add_parser(
'diff', description=constants.DIFF_DESCRIPTION,
epilog=constants.DIFF_EPILOG, formatter_class=ParagraphFormatter,
help=constants.DIFF_HELP)
... | python | def generate_diff_subparser(subparsers):
"""Adds a sub-command parser to `subparsers` to make a diff
query."""
parser = subparsers.add_parser(
'diff', description=constants.DIFF_DESCRIPTION,
epilog=constants.DIFF_EPILOG, formatter_class=ParagraphFormatter,
help=constants.DIFF_HELP)
... | [
"def",
"generate_diff_subparser",
"(",
"subparsers",
")",
":",
"parser",
"=",
"subparsers",
".",
"add_parser",
"(",
"'diff'",
",",
"description",
"=",
"constants",
".",
"DIFF_DESCRIPTION",
",",
"epilog",
"=",
"constants",
".",
"DIFF_EPILOG",
",",
"formatter_class"... | Adds a sub-command parser to `subparsers` to make a diff
query. | [
"Adds",
"a",
"sub",
"-",
"command",
"parser",
"to",
"subparsers",
"to",
"make",
"a",
"diff",
"query",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/__main__.py#L153-L167 |
ajenhl/tacl | tacl/__main__.py | generate_excise_subparser | def generate_excise_subparser(subparsers):
"""Adds a sub-command parser to `subparsers` to excise n-grams from
witnesses."""
parser = subparsers.add_parser(
'excise', description=constants.EXCISE_DESCRIPTION,
help=constants.EXCISE_HELP)
parser.set_defaults(func=excise)
utils.add_comm... | python | def generate_excise_subparser(subparsers):
"""Adds a sub-command parser to `subparsers` to excise n-grams from
witnesses."""
parser = subparsers.add_parser(
'excise', description=constants.EXCISE_DESCRIPTION,
help=constants.EXCISE_HELP)
parser.set_defaults(func=excise)
utils.add_comm... | [
"def",
"generate_excise_subparser",
"(",
"subparsers",
")",
":",
"parser",
"=",
"subparsers",
".",
"add_parser",
"(",
"'excise'",
",",
"description",
"=",
"constants",
".",
"EXCISE_DESCRIPTION",
",",
"help",
"=",
"constants",
".",
"EXCISE_HELP",
")",
"parser",
"... | Adds a sub-command parser to `subparsers` to excise n-grams from
witnesses. | [
"Adds",
"a",
"sub",
"-",
"command",
"parser",
"to",
"subparsers",
"to",
"excise",
"n",
"-",
"grams",
"from",
"witnesses",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/__main__.py#L170-L186 |
ajenhl/tacl | tacl/__main__.py | generate_highlight_subparser | def generate_highlight_subparser(subparsers):
"""Adds a sub-command parser to `subparsers` to highlight a witness'
text with its matches in a result."""
parser = subparsers.add_parser(
'highlight', description=constants.HIGHLIGHT_DESCRIPTION,
epilog=constants.HIGHLIGHT_EPILOG, formatter_clas... | python | def generate_highlight_subparser(subparsers):
"""Adds a sub-command parser to `subparsers` to highlight a witness'
text with its matches in a result."""
parser = subparsers.add_parser(
'highlight', description=constants.HIGHLIGHT_DESCRIPTION,
epilog=constants.HIGHLIGHT_EPILOG, formatter_clas... | [
"def",
"generate_highlight_subparser",
"(",
"subparsers",
")",
":",
"parser",
"=",
"subparsers",
".",
"add_parser",
"(",
"'highlight'",
",",
"description",
"=",
"constants",
".",
"HIGHLIGHT_DESCRIPTION",
",",
"epilog",
"=",
"constants",
".",
"HIGHLIGHT_EPILOG",
",",... | Adds a sub-command parser to `subparsers` to highlight a witness'
text with its matches in a result. | [
"Adds",
"a",
"sub",
"-",
"command",
"parser",
"to",
"subparsers",
"to",
"highlight",
"a",
"witness",
"text",
"with",
"its",
"matches",
"in",
"a",
"result",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/__main__.py#L189-L211 |
ajenhl/tacl | tacl/__main__.py | generate_intersect_subparser | def generate_intersect_subparser(subparsers):
"""Adds a sub-command parser to `subparsers` to make an
intersection query."""
parser = subparsers.add_parser(
'intersect', description=constants.INTERSECT_DESCRIPTION,
epilog=constants.INTERSECT_EPILOG, formatter_class=ParagraphFormatter,
... | python | def generate_intersect_subparser(subparsers):
"""Adds a sub-command parser to `subparsers` to make an
intersection query."""
parser = subparsers.add_parser(
'intersect', description=constants.INTERSECT_DESCRIPTION,
epilog=constants.INTERSECT_EPILOG, formatter_class=ParagraphFormatter,
... | [
"def",
"generate_intersect_subparser",
"(",
"subparsers",
")",
":",
"parser",
"=",
"subparsers",
".",
"add_parser",
"(",
"'intersect'",
",",
"description",
"=",
"constants",
".",
"INTERSECT_DESCRIPTION",
",",
"epilog",
"=",
"constants",
".",
"INTERSECT_EPILOG",
",",... | Adds a sub-command parser to `subparsers` to make an
intersection query. | [
"Adds",
"a",
"sub",
"-",
"command",
"parser",
"to",
"subparsers",
"to",
"make",
"an",
"intersection",
"query",
"."
] | train | https://github.com/ajenhl/tacl/blob/b8a343248e77f1c07a5a4ac133a9ad6e0b4781c2/tacl/__main__.py#L214-L225 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.