partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | query | Query encoder/decoder with a request value | opus/api/ctl.py | def query(request):
"""Query encoder/decoder with a request value"""
def inner(func, obj):
result_code = func(obj, request)
if result_code is not constants.OK:
raise OpusError(result_code)
return result_code
return inner | def query(request):
"""Query encoder/decoder with a request value"""
def inner(func, obj):
result_code = func(obj, request)
if result_code is not constants.OK:
raise OpusError(result_code)
return result_code
return inner | [
"Query",
"encoder",
"/",
"decoder",
"with",
"a",
"request",
"value"
] | svartalf/python-opus | python | https://github.com/svartalf/python-opus/blob/a3c1d556d2772b5be659ddd08c033ddd4d566b3a/opus/api/ctl.py#L19-L30 | [
"def",
"query",
"(",
"request",
")",
":",
"def",
"inner",
"(",
"func",
",",
"obj",
")",
":",
"result_code",
"=",
"func",
"(",
"obj",
",",
"request",
")",
"if",
"result_code",
"is",
"not",
"constants",
".",
"OK",
":",
"raise",
"OpusError",
"(",
"resul... | a3c1d556d2772b5be659ddd08c033ddd4d566b3a |
train | get | Get CTL value from a encoder/decoder | opus/api/ctl.py | def get(request, result_type):
"""Get CTL value from a encoder/decoder"""
def inner(func, obj):
result = result_type()
result_code = func(obj, request, ctypes.byref(result))
if result_code is not constants.OK:
raise OpusError(result_code)
return result.value
r... | def get(request, result_type):
"""Get CTL value from a encoder/decoder"""
def inner(func, obj):
result = result_type()
result_code = func(obj, request, ctypes.byref(result))
if result_code is not constants.OK:
raise OpusError(result_code)
return result.value
r... | [
"Get",
"CTL",
"value",
"from",
"a",
"encoder",
"/",
"decoder"
] | svartalf/python-opus | python | https://github.com/svartalf/python-opus/blob/a3c1d556d2772b5be659ddd08c033ddd4d566b3a/opus/api/ctl.py#L33-L45 | [
"def",
"get",
"(",
"request",
",",
"result_type",
")",
":",
"def",
"inner",
"(",
"func",
",",
"obj",
")",
":",
"result",
"=",
"result_type",
"(",
")",
"result_code",
"=",
"func",
"(",
"obj",
",",
"request",
",",
"ctypes",
".",
"byref",
"(",
"result",... | a3c1d556d2772b5be659ddd08c033ddd4d566b3a |
train | set | Set new CTL value to a encoder/decoder | opus/api/ctl.py | def set(request):
"""Set new CTL value to a encoder/decoder"""
def inner(func, obj, value):
result_code = func(obj, request, value)
if result_code is not constants.OK:
raise OpusError(result_code)
return inner | def set(request):
"""Set new CTL value to a encoder/decoder"""
def inner(func, obj, value):
result_code = func(obj, request, value)
if result_code is not constants.OK:
raise OpusError(result_code)
return inner | [
"Set",
"new",
"CTL",
"value",
"to",
"a",
"encoder",
"/",
"decoder"
] | svartalf/python-opus | python | https://github.com/svartalf/python-opus/blob/a3c1d556d2772b5be659ddd08c033ddd4d566b3a/opus/api/ctl.py#L48-L56 | [
"def",
"set",
"(",
"request",
")",
":",
"def",
"inner",
"(",
"func",
",",
"obj",
",",
"value",
")",
":",
"result_code",
"=",
"func",
"(",
"obj",
",",
"request",
",",
"value",
")",
"if",
"result_code",
"is",
"not",
"constants",
".",
"OK",
":",
"rais... | a3c1d556d2772b5be659ddd08c033ddd4d566b3a |
train | sort_schemas | Sort a list of SQL schemas in order | omego/db.py | def sort_schemas(schemas):
"""Sort a list of SQL schemas in order"""
def keyfun(v):
x = SQL_SCHEMA_REGEXP.match(v).groups()
# x3: 'DEV' should come before ''
return (int(x[0]), x[1], int(x[2]) if x[2] else None,
x[3] if x[3] else 'zzz', int(x[4]))
return sorted(schem... | def sort_schemas(schemas):
"""Sort a list of SQL schemas in order"""
def keyfun(v):
x = SQL_SCHEMA_REGEXP.match(v).groups()
# x3: 'DEV' should come before ''
return (int(x[0]), x[1], int(x[2]) if x[2] else None,
x[3] if x[3] else 'zzz', int(x[4]))
return sorted(schem... | [
"Sort",
"a",
"list",
"of",
"SQL",
"schemas",
"in",
"order"
] | ome/omego | python | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/db.py#L31-L39 | [
"def",
"sort_schemas",
"(",
"schemas",
")",
":",
"def",
"keyfun",
"(",
"v",
")",
":",
"x",
"=",
"SQL_SCHEMA_REGEXP",
".",
"match",
"(",
"v",
")",
".",
"groups",
"(",
")",
"# x3: 'DEV' should come before ''",
"return",
"(",
"int",
"(",
"x",
"[",
"0",
"]... | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb |
train | parse_schema_files | Parse a list of SQL files and return a dictionary of valid schema
files where each key is a valid schema file and the corresponding value is
a tuple containing the source and the target schema. | omego/db.py | def parse_schema_files(files):
"""
Parse a list of SQL files and return a dictionary of valid schema
files where each key is a valid schema file and the corresponding value is
a tuple containing the source and the target schema.
"""
f_dict = {}
for f in files:
root, ext = os.path.spl... | def parse_schema_files(files):
"""
Parse a list of SQL files and return a dictionary of valid schema
files where each key is a valid schema file and the corresponding value is
a tuple containing the source and the target schema.
"""
f_dict = {}
for f in files:
root, ext = os.path.spl... | [
"Parse",
"a",
"list",
"of",
"SQL",
"files",
"and",
"return",
"a",
"dictionary",
"of",
"valid",
"schema",
"files",
"where",
"each",
"key",
"is",
"a",
"valid",
"schema",
"file",
"and",
"the",
"corresponding",
"value",
"is",
"a",
"tuple",
"containing",
"the",... | ome/omego | python | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/db.py#L42-L57 | [
"def",
"parse_schema_files",
"(",
"files",
")",
":",
"f_dict",
"=",
"{",
"}",
"for",
"f",
"in",
"files",
":",
"root",
",",
"ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"f",
")",
"if",
"ext",
"!=",
"\".sql\"",
":",
"continue",
"vto",
",",
... | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb |
train | DbAdmin.dump | Dump the database using the postgres custom format | omego/db.py | def dump(self):
"""
Dump the database using the postgres custom format
"""
dumpfile = self.args.dumpfile
if not dumpfile:
db, env = self.get_db_args_env()
dumpfile = fileutils.timestamp_filename(
'omero-database-%s' % db['name'], 'pgdump')
... | def dump(self):
"""
Dump the database using the postgres custom format
"""
dumpfile = self.args.dumpfile
if not dumpfile:
db, env = self.get_db_args_env()
dumpfile = fileutils.timestamp_filename(
'omero-database-%s' % db['name'], 'pgdump')
... | [
"Dump",
"the",
"database",
"using",
"the",
"postgres",
"custom",
"format"
] | ome/omego | python | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/db.py#L206-L218 | [
"def",
"dump",
"(",
"self",
")",
":",
"dumpfile",
"=",
"self",
".",
"args",
".",
"dumpfile",
"if",
"not",
"dumpfile",
":",
"db",
",",
"env",
"=",
"self",
".",
"get_db_args_env",
"(",
")",
"dumpfile",
"=",
"fileutils",
".",
"timestamp_filename",
"(",
"'... | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb |
train | DbAdmin.get_db_args_env | Get a dictionary of database connection parameters, and create an
environment for running postgres commands.
Falls back to omego defaults. | omego/db.py | def get_db_args_env(self):
"""
Get a dictionary of database connection parameters, and create an
environment for running postgres commands.
Falls back to omego defaults.
"""
db = {
'name': self.args.dbname,
'host': self.args.dbhost,
'us... | def get_db_args_env(self):
"""
Get a dictionary of database connection parameters, and create an
environment for running postgres commands.
Falls back to omego defaults.
"""
db = {
'name': self.args.dbname,
'host': self.args.dbhost,
'us... | [
"Get",
"a",
"dictionary",
"of",
"database",
"connection",
"parameters",
"and",
"create",
"an",
"environment",
"for",
"running",
"postgres",
"commands",
".",
"Falls",
"back",
"to",
"omego",
"defaults",
"."
] | ome/omego | python | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/db.py#L220-L253 | [
"def",
"get_db_args_env",
"(",
"self",
")",
":",
"db",
"=",
"{",
"'name'",
":",
"self",
".",
"args",
".",
"dbname",
",",
"'host'",
":",
"self",
".",
"args",
".",
"dbhost",
",",
"'user'",
":",
"self",
".",
"args",
".",
"dbuser",
",",
"'pass'",
":",
... | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb |
train | DbAdmin.psql | Run a psql command | omego/db.py | def psql(self, *psqlargs):
"""
Run a psql command
"""
db, env = self.get_db_args_env()
args = [
'-v', 'ON_ERROR_STOP=on',
'-d', db['name'],
'-h', db['host'],
'-U', db['user'],
'-w', '-A', '-t'
] + list(psqla... | def psql(self, *psqlargs):
"""
Run a psql command
"""
db, env = self.get_db_args_env()
args = [
'-v', 'ON_ERROR_STOP=on',
'-d', db['name'],
'-h', db['host'],
'-U', db['user'],
'-w', '-A', '-t'
] + list(psqla... | [
"Run",
"a",
"psql",
"command"
] | ome/omego | python | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/db.py#L255-L272 | [
"def",
"psql",
"(",
"self",
",",
"*",
"psqlargs",
")",
":",
"db",
",",
"env",
"=",
"self",
".",
"get_db_args_env",
"(",
")",
"args",
"=",
"[",
"'-v'",
",",
"'ON_ERROR_STOP=on'",
",",
"'-d'",
",",
"db",
"[",
"'name'",
"]",
",",
"'-h'",
",",
"db",
... | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb |
train | DbAdmin.pgdump | Run a pg_dump command | omego/db.py | def pgdump(self, *pgdumpargs):
"""
Run a pg_dump command
"""
db, env = self.get_db_args_env()
args = ['-d', db['name'], '-h', db['host'], '-U', db['user'], '-w'
] + list(pgdumpargs)
stdout, stderr = External.run(
'pg_dump', args, capturestd=Tr... | def pgdump(self, *pgdumpargs):
"""
Run a pg_dump command
"""
db, env = self.get_db_args_env()
args = ['-d', db['name'], '-h', db['host'], '-U', db['user'], '-w'
] + list(pgdumpargs)
stdout, stderr = External.run(
'pg_dump', args, capturestd=Tr... | [
"Run",
"a",
"pg_dump",
"command"
] | ome/omego | python | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/db.py#L274-L287 | [
"def",
"pgdump",
"(",
"self",
",",
"*",
"pgdumpargs",
")",
":",
"db",
",",
"env",
"=",
"self",
".",
"get_db_args_env",
"(",
")",
"args",
"=",
"[",
"'-d'",
",",
"db",
"[",
"'name'",
"]",
",",
"'-h'",
",",
"db",
"[",
"'host'",
"]",
",",
"'-U'",
"... | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb |
train | External.set_server_dir | Set the directory of the server to be controlled | omego/external.py | def set_server_dir(self, dir):
"""
Set the directory of the server to be controlled
"""
self.dir = os.path.abspath(dir)
config = os.path.join(self.dir, 'etc', 'grid', 'config.xml')
self.configured = os.path.exists(config) | def set_server_dir(self, dir):
"""
Set the directory of the server to be controlled
"""
self.dir = os.path.abspath(dir)
config = os.path.join(self.dir, 'etc', 'grid', 'config.xml')
self.configured = os.path.exists(config) | [
"Set",
"the",
"directory",
"of",
"the",
"server",
"to",
"be",
"controlled"
] | ome/omego | python | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/external.py#L55-L61 | [
"def",
"set_server_dir",
"(",
"self",
",",
"dir",
")",
":",
"self",
".",
"dir",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"dir",
")",
"config",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"dir",
",",
"'etc'",
",",
"'grid'",
",",
"... | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb |
train | External.get_config | Returns a dictionary of all config.xml properties
If `force = True` then ignore any cached state and read config.xml
if possible
setup_omero_cli() must be called before this method to import the
correct omero module to minimise the possibility of version conflicts | omego/external.py | def get_config(self, force=False):
"""
Returns a dictionary of all config.xml properties
If `force = True` then ignore any cached state and read config.xml
if possible
setup_omero_cli() must be called before this method to import the
correct omero module to minimise the... | def get_config(self, force=False):
"""
Returns a dictionary of all config.xml properties
If `force = True` then ignore any cached state and read config.xml
if possible
setup_omero_cli() must be called before this method to import the
correct omero module to minimise the... | [
"Returns",
"a",
"dictionary",
"of",
"all",
"config",
".",
"xml",
"properties"
] | ome/omego | python | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/external.py#L74-L102 | [
"def",
"get_config",
"(",
"self",
",",
"force",
"=",
"False",
")",
":",
"if",
"not",
"force",
"and",
"not",
"self",
".",
"has_config",
"(",
")",
":",
"raise",
"Exception",
"(",
"'No config file'",
")",
"configxml",
"=",
"os",
".",
"path",
".",
"join",
... | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb |
train | External.setup_omero_cli | Imports the omero CLI module so that commands can be run directly.
Note Python does not allow a module to be imported multiple times,
so this will only work with a single omero instance.
This can have several surprising effects, so setup_omero_cli()
must be explcitly called. | omego/external.py | def setup_omero_cli(self):
"""
Imports the omero CLI module so that commands can be run directly.
Note Python does not allow a module to be imported multiple times,
so this will only work with a single omero instance.
This can have several surprising effects, so setup_omero_cli(... | def setup_omero_cli(self):
"""
Imports the omero CLI module so that commands can be run directly.
Note Python does not allow a module to be imported multiple times,
so this will only work with a single omero instance.
This can have several surprising effects, so setup_omero_cli(... | [
"Imports",
"the",
"omero",
"CLI",
"module",
"so",
"that",
"commands",
"can",
"be",
"run",
"directly",
".",
"Note",
"Python",
"does",
"not",
"allow",
"a",
"module",
"to",
"be",
"imported",
"multiple",
"times",
"so",
"this",
"will",
"only",
"work",
"with",
... | ome/omego | python | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/external.py#L104-L132 | [
"def",
"setup_omero_cli",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"dir",
":",
"raise",
"Exception",
"(",
"'No server directory set'",
")",
"if",
"'omero.cli'",
"in",
"sys",
".",
"modules",
":",
"raise",
"Exception",
"(",
"'omero.cli can only be imported... | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb |
train | External.setup_previous_omero_env | Create a copy of the current environment for interacting with the
current OMERO server installation | omego/external.py | def setup_previous_omero_env(self, olddir, savevarsfile):
"""
Create a copy of the current environment for interacting with the
current OMERO server installation
"""
env = self.get_environment(savevarsfile)
def addpath(varname, p):
if not os.path.exists(p):
... | def setup_previous_omero_env(self, olddir, savevarsfile):
"""
Create a copy of the current environment for interacting with the
current OMERO server installation
"""
env = self.get_environment(savevarsfile)
def addpath(varname, p):
if not os.path.exists(p):
... | [
"Create",
"a",
"copy",
"of",
"the",
"current",
"environment",
"for",
"interacting",
"with",
"the",
"current",
"OMERO",
"server",
"installation"
] | ome/omego | python | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/external.py#L134-L155 | [
"def",
"setup_previous_omero_env",
"(",
"self",
",",
"olddir",
",",
"savevarsfile",
")",
":",
"env",
"=",
"self",
".",
"get_environment",
"(",
"savevarsfile",
")",
"def",
"addpath",
"(",
"varname",
",",
"p",
")",
":",
"if",
"not",
"os",
".",
"path",
".",... | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb |
train | External.omero_cli | Runs a command as if from the OMERO command-line without the need
for using popen or subprocess. | omego/external.py | def omero_cli(self, command):
"""
Runs a command as if from the OMERO command-line without the need
for using popen or subprocess.
"""
assert isinstance(command, list)
if not self.cli:
raise Exception('omero.cli not initialised')
log.info("Invoking CLI... | def omero_cli(self, command):
"""
Runs a command as if from the OMERO command-line without the need
for using popen or subprocess.
"""
assert isinstance(command, list)
if not self.cli:
raise Exception('omero.cli not initialised')
log.info("Invoking CLI... | [
"Runs",
"a",
"command",
"as",
"if",
"from",
"the",
"OMERO",
"command",
"-",
"line",
"without",
"the",
"need",
"for",
"using",
"popen",
"or",
"subprocess",
"."
] | ome/omego | python | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/external.py#L157-L166 | [
"def",
"omero_cli",
"(",
"self",
",",
"command",
")",
":",
"assert",
"isinstance",
"(",
"command",
",",
"list",
")",
"if",
"not",
"self",
".",
"cli",
":",
"raise",
"Exception",
"(",
"'omero.cli not initialised'",
")",
"log",
".",
"info",
"(",
"\"Invoking C... | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb |
train | External.omero_bin | Runs the omero command-line client with an array of arguments using the
old environment | omego/external.py | def omero_bin(self, command):
"""
Runs the omero command-line client with an array of arguments using the
old environment
"""
assert isinstance(command, list)
if not self.old_env:
raise Exception('Old environment not initialised')
log.info("Running [ol... | def omero_bin(self, command):
"""
Runs the omero command-line client with an array of arguments using the
old environment
"""
assert isinstance(command, list)
if not self.old_env:
raise Exception('Old environment not initialised')
log.info("Running [ol... | [
"Runs",
"the",
"omero",
"command",
"-",
"line",
"client",
"with",
"an",
"array",
"of",
"arguments",
"using",
"the",
"old",
"environment"
] | ome/omego | python | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/external.py#L168-L177 | [
"def",
"omero_bin",
"(",
"self",
",",
"command",
")",
":",
"assert",
"isinstance",
"(",
"command",
",",
"list",
")",
"if",
"not",
"self",
".",
"old_env",
":",
"raise",
"Exception",
"(",
"'Old environment not initialised'",
")",
"log",
".",
"info",
"(",
"\"... | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb |
train | External.run | Runs an executable with an array of arguments, optionally in the
specified environment.
Returns stdout and stderr | omego/external.py | def run(exe, args, capturestd=False, env=None):
"""
Runs an executable with an array of arguments, optionally in the
specified environment.
Returns stdout and stderr
"""
command = [exe] + args
if env:
log.info("Executing [custom environment]: %s", " ".... | def run(exe, args, capturestd=False, env=None):
"""
Runs an executable with an array of arguments, optionally in the
specified environment.
Returns stdout and stderr
"""
command = [exe] + args
if env:
log.info("Executing [custom environment]: %s", " ".... | [
"Runs",
"an",
"executable",
"with",
"an",
"array",
"of",
"arguments",
"optionally",
"in",
"the",
"specified",
"environment",
".",
"Returns",
"stdout",
"and",
"stderr"
] | ome/omego | python | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/external.py#L180-L225 | [
"def",
"run",
"(",
"exe",
",",
"args",
",",
"capturestd",
"=",
"False",
",",
"env",
"=",
"None",
")",
":",
"command",
"=",
"[",
"exe",
"]",
"+",
"args",
"if",
"env",
":",
"log",
".",
"info",
"(",
"\"Executing [custom environment]: %s\"",
",",
"\" \"",
... | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb |
train | string_support | Create byte-to-string and string-to-byte conversion functions for
internal use.
:param py3enc: Encoding used by Python 3 environment.
:type py3enc: str | natto/support.py | def string_support(py3enc):
'''Create byte-to-string and string-to-byte conversion functions for
internal use.
:param py3enc: Encoding used by Python 3 environment.
:type py3enc: str
'''
if sys.version < '3':
def bytes2str(b):
'''Identity, returns the argument string (bytes)... | def string_support(py3enc):
'''Create byte-to-string and string-to-byte conversion functions for
internal use.
:param py3enc: Encoding used by Python 3 environment.
:type py3enc: str
'''
if sys.version < '3':
def bytes2str(b):
'''Identity, returns the argument string (bytes)... | [
"Create",
"byte",
"-",
"to",
"-",
"string",
"and",
"string",
"-",
"to",
"-",
"byte",
"conversion",
"functions",
"for",
"internal",
"use",
"."
] | buruzaemon/natto-py | python | https://github.com/buruzaemon/natto-py/blob/018fe004c47c45c66bdf2e03fe24e981ae089b76/natto/support.py#L9-L30 | [
"def",
"string_support",
"(",
"py3enc",
")",
":",
"if",
"sys",
".",
"version",
"<",
"'3'",
":",
"def",
"bytes2str",
"(",
"b",
")",
":",
"'''Identity, returns the argument string (bytes).'''",
"return",
"b",
"def",
"str2bytes",
"(",
"s",
")",
":",
"'''Identity,... | 018fe004c47c45c66bdf2e03fe24e981ae089b76 |
train | splitter_support | Create tokenizer for use in boundary constraint parsing.
:param py2enc: Encoding used by Python 2 environment.
:type py2enc: str | natto/support.py | def splitter_support(py2enc):
'''Create tokenizer for use in boundary constraint parsing.
:param py2enc: Encoding used by Python 2 environment.
:type py2enc: str
'''
if sys.version < '3':
def _fn_sentence(pattern, sentence):
if REGEXTYPE == type(pattern):
if patt... | def splitter_support(py2enc):
'''Create tokenizer for use in boundary constraint parsing.
:param py2enc: Encoding used by Python 2 environment.
:type py2enc: str
'''
if sys.version < '3':
def _fn_sentence(pattern, sentence):
if REGEXTYPE == type(pattern):
if patt... | [
"Create",
"tokenizer",
"for",
"use",
"in",
"boundary",
"constraint",
"parsing",
"."
] | buruzaemon/natto-py | python | https://github.com/buruzaemon/natto-py/blob/018fe004c47c45c66bdf2e03fe24e981ae089b76/natto/support.py#L32-L96 | [
"def",
"splitter_support",
"(",
"py2enc",
")",
":",
"if",
"sys",
".",
"version",
"<",
"'3'",
":",
"def",
"_fn_sentence",
"(",
"pattern",
",",
"sentence",
")",
":",
"if",
"REGEXTYPE",
"==",
"type",
"(",
"pattern",
")",
":",
"if",
"pattern",
".",
"flags"... | 018fe004c47c45c66bdf2e03fe24e981ae089b76 |
train | DocManager.update | Apply updates given in update_spec to the document whose id
matches that of doc. | mongo_connector/doc_managers/elastic_doc_manager.py | def update(self, document_id, update_spec, namespace, timestamp):
"""Apply updates given in update_spec to the document whose id
matches that of doc.
"""
index, doc_type = self._index_and_mapping(namespace)
with self.lock:
# Check if document source is stored in loca... | def update(self, document_id, update_spec, namespace, timestamp):
"""Apply updates given in update_spec to the document whose id
matches that of doc.
"""
index, doc_type = self._index_and_mapping(namespace)
with self.lock:
# Check if document source is stored in loca... | [
"Apply",
"updates",
"given",
"in",
"update_spec",
"to",
"the",
"document",
"whose",
"id",
"matches",
"that",
"of",
"doc",
"."
] | yougov/elastic-doc-manager | python | https://github.com/yougov/elastic-doc-manager/blob/17c35f4dd3d081b171c45ba0eb9616da9dc89e82/mongo_connector/doc_managers/elastic_doc_manager.py#L243-L268 | [
"def",
"update",
"(",
"self",
",",
"document_id",
",",
"update_spec",
",",
"namespace",
",",
"timestamp",
")",
":",
"index",
",",
"doc_type",
"=",
"self",
".",
"_index_and_mapping",
"(",
"namespace",
")",
"with",
"self",
".",
"lock",
":",
"# Check if documen... | 17c35f4dd3d081b171c45ba0eb9616da9dc89e82 |
train | DocManager.upsert | Insert a document into Elasticsearch. | mongo_connector/doc_managers/elastic_doc_manager.py | def upsert(self, doc, namespace, timestamp, update_spec=None):
"""Insert a document into Elasticsearch."""
index, doc_type = self._index_and_mapping(namespace)
# No need to duplicate '_id' in source document
doc_id = u(doc.pop("_id"))
metadata = {
'ns': namespace,
... | def upsert(self, doc, namespace, timestamp, update_spec=None):
"""Insert a document into Elasticsearch."""
index, doc_type = self._index_and_mapping(namespace)
# No need to duplicate '_id' in source document
doc_id = u(doc.pop("_id"))
metadata = {
'ns': namespace,
... | [
"Insert",
"a",
"document",
"into",
"Elasticsearch",
"."
] | yougov/elastic-doc-manager | python | https://github.com/yougov/elastic-doc-manager/blob/17c35f4dd3d081b171c45ba0eb9616da9dc89e82/mongo_connector/doc_managers/elastic_doc_manager.py#L271-L301 | [
"def",
"upsert",
"(",
"self",
",",
"doc",
",",
"namespace",
",",
"timestamp",
",",
"update_spec",
"=",
"None",
")",
":",
"index",
",",
"doc_type",
"=",
"self",
".",
"_index_and_mapping",
"(",
"namespace",
")",
"# No need to duplicate '_id' in source document",
"... | 17c35f4dd3d081b171c45ba0eb9616da9dc89e82 |
train | DocManager.bulk_upsert | Insert multiple documents into Elasticsearch. | mongo_connector/doc_managers/elastic_doc_manager.py | def bulk_upsert(self, docs, namespace, timestamp):
"""Insert multiple documents into Elasticsearch."""
def docs_to_upsert():
doc = None
for doc in docs:
# Remove metadata and redundant _id
index, doc_type = self._index_and_mapping(namespace)
... | def bulk_upsert(self, docs, namespace, timestamp):
"""Insert multiple documents into Elasticsearch."""
def docs_to_upsert():
doc = None
for doc in docs:
# Remove metadata and redundant _id
index, doc_type = self._index_and_mapping(namespace)
... | [
"Insert",
"multiple",
"documents",
"into",
"Elasticsearch",
"."
] | yougov/elastic-doc-manager | python | https://github.com/yougov/elastic-doc-manager/blob/17c35f4dd3d081b171c45ba0eb9616da9dc89e82/mongo_connector/doc_managers/elastic_doc_manager.py#L304-L352 | [
"def",
"bulk_upsert",
"(",
"self",
",",
"docs",
",",
"namespace",
",",
"timestamp",
")",
":",
"def",
"docs_to_upsert",
"(",
")",
":",
"doc",
"=",
"None",
"for",
"doc",
"in",
"docs",
":",
"# Remove metadata and redundant _id",
"index",
",",
"doc_type",
"=",
... | 17c35f4dd3d081b171c45ba0eb9616da9dc89e82 |
train | DocManager.remove | Remove a document from Elasticsearch. | mongo_connector/doc_managers/elastic_doc_manager.py | def remove(self, document_id, namespace, timestamp):
"""Remove a document from Elasticsearch."""
index, doc_type = self._index_and_mapping(namespace)
action = {
'_op_type': 'delete',
'_index': index,
'_type': doc_type,
'_id': u(document_id)
... | def remove(self, document_id, namespace, timestamp):
"""Remove a document from Elasticsearch."""
index, doc_type = self._index_and_mapping(namespace)
action = {
'_op_type': 'delete',
'_index': index,
'_type': doc_type,
'_id': u(document_id)
... | [
"Remove",
"a",
"document",
"from",
"Elasticsearch",
"."
] | yougov/elastic-doc-manager | python | https://github.com/yougov/elastic-doc-manager/blob/17c35f4dd3d081b171c45ba0eb9616da9dc89e82/mongo_connector/doc_managers/elastic_doc_manager.py#L398-L416 | [
"def",
"remove",
"(",
"self",
",",
"document_id",
",",
"namespace",
",",
"timestamp",
")",
":",
"index",
",",
"doc_type",
"=",
"self",
".",
"_index_and_mapping",
"(",
"namespace",
")",
"action",
"=",
"{",
"'_op_type'",
":",
"'delete'",
",",
"'_index'",
":"... | 17c35f4dd3d081b171c45ba0eb9616da9dc89e82 |
train | DocManager.send_buffered_operations | Send buffered operations to Elasticsearch.
This method is periodically called by the AutoCommitThread. | mongo_connector/doc_managers/elastic_doc_manager.py | def send_buffered_operations(self):
"""Send buffered operations to Elasticsearch.
This method is periodically called by the AutoCommitThread.
"""
with self.lock:
try:
action_buffer = self.BulkBuffer.get_buffer()
if action_buffer:
... | def send_buffered_operations(self):
"""Send buffered operations to Elasticsearch.
This method is periodically called by the AutoCommitThread.
"""
with self.lock:
try:
action_buffer = self.BulkBuffer.get_buffer()
if action_buffer:
... | [
"Send",
"buffered",
"operations",
"to",
"Elasticsearch",
"."
] | yougov/elastic-doc-manager | python | https://github.com/yougov/elastic-doc-manager/blob/17c35f4dd3d081b171c45ba0eb9616da9dc89e82/mongo_connector/doc_managers/elastic_doc_manager.py#L454-L470 | [
"def",
"send_buffered_operations",
"(",
"self",
")",
":",
"with",
"self",
".",
"lock",
":",
"try",
":",
"action_buffer",
"=",
"self",
".",
"BulkBuffer",
".",
"get_buffer",
"(",
")",
"if",
"action_buffer",
":",
"successes",
",",
"errors",
"=",
"bulk",
"(",
... | 17c35f4dd3d081b171c45ba0eb9616da9dc89e82 |
train | DocManager.get_last_doc | Get the most recently modified document from Elasticsearch.
This method is used to help define a time window within which documents
may be in conflict after a MongoDB rollback. | mongo_connector/doc_managers/elastic_doc_manager.py | def get_last_doc(self):
"""Get the most recently modified document from Elasticsearch.
This method is used to help define a time window within which documents
may be in conflict after a MongoDB rollback.
"""
try:
result = self.elastic.search(
index=se... | def get_last_doc(self):
"""Get the most recently modified document from Elasticsearch.
This method is used to help define a time window within which documents
may be in conflict after a MongoDB rollback.
"""
try:
result = self.elastic.search(
index=se... | [
"Get",
"the",
"most",
"recently",
"modified",
"document",
"from",
"Elasticsearch",
"."
] | yougov/elastic-doc-manager | python | https://github.com/yougov/elastic-doc-manager/blob/17c35f4dd3d081b171c45ba0eb9616da9dc89e82/mongo_connector/doc_managers/elastic_doc_manager.py#L478-L498 | [
"def",
"get_last_doc",
"(",
"self",
")",
":",
"try",
":",
"result",
"=",
"self",
".",
"elastic",
".",
"search",
"(",
"index",
"=",
"self",
".",
"meta_index_name",
",",
"body",
"=",
"{",
"\"query\"",
":",
"{",
"\"match_all\"",
":",
"{",
"}",
"}",
",",... | 17c35f4dd3d081b171c45ba0eb9616da9dc89e82 |
train | split_sig | Split a list of parameters/types by commas,
whilst respecting brackets.
For example:
String arg0, int arg2 = 1, List<int> arg3 = [1, 2, 3]
=> ['String arg0', 'int arg2 = 1', 'List<int> arg3 = [1, 2, 3]'] | sphinx_csharp/csharp.py | def split_sig(params):
"""
Split a list of parameters/types by commas,
whilst respecting brackets.
For example:
String arg0, int arg2 = 1, List<int> arg3 = [1, 2, 3]
=> ['String arg0', 'int arg2 = 1', 'List<int> arg3 = [1, 2, 3]']
"""
result = []
current = ''
level = 0
f... | def split_sig(params):
"""
Split a list of parameters/types by commas,
whilst respecting brackets.
For example:
String arg0, int arg2 = 1, List<int> arg3 = [1, 2, 3]
=> ['String arg0', 'int arg2 = 1', 'List<int> arg3 = [1, 2, 3]']
"""
result = []
current = ''
level = 0
f... | [
"Split",
"a",
"list",
"of",
"parameters",
"/",
"types",
"by",
"commas",
"whilst",
"respecting",
"brackets",
"."
] | djungelorm/sphinx-csharp | python | https://github.com/djungelorm/sphinx-csharp/blob/aaa0c5fbe514d7f0b1a89625185fc608e5d30702/sphinx_csharp/csharp.py#L39-L63 | [
"def",
"split_sig",
"(",
"params",
")",
":",
"result",
"=",
"[",
"]",
"current",
"=",
"''",
"level",
"=",
"0",
"for",
"char",
"in",
"params",
":",
"if",
"char",
"in",
"(",
"'<'",
",",
"'{'",
",",
"'['",
")",
":",
"level",
"+=",
"1",
"elif",
"ch... | aaa0c5fbe514d7f0b1a89625185fc608e5d30702 |
train | parse_method_signature | Parse a method signature of the form: modifier* type name (params) | sphinx_csharp/csharp.py | def parse_method_signature(sig):
""" Parse a method signature of the form: modifier* type name (params) """
match = METH_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Method signature invalid: ' + sig)
modifiers, return_type, name, generic_types, params = match.groups()
if para... | def parse_method_signature(sig):
""" Parse a method signature of the form: modifier* type name (params) """
match = METH_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Method signature invalid: ' + sig)
modifiers, return_type, name, generic_types, params = match.groups()
if para... | [
"Parse",
"a",
"method",
"signature",
"of",
"the",
"form",
":",
"modifier",
"*",
"type",
"name",
"(",
"params",
")"
] | djungelorm/sphinx-csharp | python | https://github.com/djungelorm/sphinx-csharp/blob/aaa0c5fbe514d7f0b1a89625185fc608e5d30702/sphinx_csharp/csharp.py#L66-L77 | [
"def",
"parse_method_signature",
"(",
"sig",
")",
":",
"match",
"=",
"METH_SIG_RE",
".",
"match",
"(",
"sig",
".",
"strip",
"(",
")",
")",
"if",
"not",
"match",
":",
"raise",
"RuntimeError",
"(",
"'Method signature invalid: '",
"+",
"sig",
")",
"modifiers",
... | aaa0c5fbe514d7f0b1a89625185fc608e5d30702 |
train | parse_property_signature | Parse a property signature of the form:
modifier* type name { (get;)? (set;)? } | sphinx_csharp/csharp.py | def parse_property_signature(sig):
""" Parse a property signature of the form:
modifier* type name { (get;)? (set;)? } """
match = PROP_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Property signature invalid: ' + sig)
groups = match.groups()
if groups[0] is not None:
... | def parse_property_signature(sig):
""" Parse a property signature of the form:
modifier* type name { (get;)? (set;)? } """
match = PROP_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Property signature invalid: ' + sig)
groups = match.groups()
if groups[0] is not None:
... | [
"Parse",
"a",
"property",
"signature",
"of",
"the",
"form",
":",
"modifier",
"*",
"type",
"name",
"{",
"(",
"get",
";",
")",
"?",
"(",
"set",
";",
")",
"?",
"}"
] | djungelorm/sphinx-csharp | python | https://github.com/djungelorm/sphinx-csharp/blob/aaa0c5fbe514d7f0b1a89625185fc608e5d30702/sphinx_csharp/csharp.py#L80-L94 | [
"def",
"parse_property_signature",
"(",
"sig",
")",
":",
"match",
"=",
"PROP_SIG_RE",
".",
"match",
"(",
"sig",
".",
"strip",
"(",
")",
")",
"if",
"not",
"match",
":",
"raise",
"RuntimeError",
"(",
"'Property signature invalid: '",
"+",
"sig",
")",
"groups",... | aaa0c5fbe514d7f0b1a89625185fc608e5d30702 |
train | parse_indexer_signature | Parse a indexer signature of the form:
modifier* type this[params] { (get;)? (set;)? } | sphinx_csharp/csharp.py | def parse_indexer_signature(sig):
""" Parse a indexer signature of the form:
modifier* type this[params] { (get;)? (set;)? } """
match = IDXR_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Indexer signature invalid: ' + sig)
modifiers, return_type, params, getter, setter = m... | def parse_indexer_signature(sig):
""" Parse a indexer signature of the form:
modifier* type this[params] { (get;)? (set;)? } """
match = IDXR_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Indexer signature invalid: ' + sig)
modifiers, return_type, params, getter, setter = m... | [
"Parse",
"a",
"indexer",
"signature",
"of",
"the",
"form",
":",
"modifier",
"*",
"type",
"this",
"[",
"params",
"]",
"{",
"(",
"get",
";",
")",
"?",
"(",
"set",
";",
")",
"?",
"}"
] | djungelorm/sphinx-csharp | python | https://github.com/djungelorm/sphinx-csharp/blob/aaa0c5fbe514d7f0b1a89625185fc608e5d30702/sphinx_csharp/csharp.py#L97-L107 | [
"def",
"parse_indexer_signature",
"(",
"sig",
")",
":",
"match",
"=",
"IDXR_SIG_RE",
".",
"match",
"(",
"sig",
".",
"strip",
"(",
")",
")",
"if",
"not",
"match",
":",
"raise",
"RuntimeError",
"(",
"'Indexer signature invalid: '",
"+",
"sig",
")",
"modifiers"... | aaa0c5fbe514d7f0b1a89625185fc608e5d30702 |
train | parse_param_signature | Parse a parameter signature of the form: type name (= default)? | sphinx_csharp/csharp.py | def parse_param_signature(sig):
""" Parse a parameter signature of the form: type name (= default)? """
match = PARAM_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Parameter signature invalid, got ' + sig)
groups = match.groups()
modifiers = groups[0].split()
typ, name, _, ... | def parse_param_signature(sig):
""" Parse a parameter signature of the form: type name (= default)? """
match = PARAM_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Parameter signature invalid, got ' + sig)
groups = match.groups()
modifiers = groups[0].split()
typ, name, _, ... | [
"Parse",
"a",
"parameter",
"signature",
"of",
"the",
"form",
":",
"type",
"name",
"(",
"=",
"default",
")",
"?"
] | djungelorm/sphinx-csharp | python | https://github.com/djungelorm/sphinx-csharp/blob/aaa0c5fbe514d7f0b1a89625185fc608e5d30702/sphinx_csharp/csharp.py#L110-L119 | [
"def",
"parse_param_signature",
"(",
"sig",
")",
":",
"match",
"=",
"PARAM_SIG_RE",
".",
"match",
"(",
"sig",
".",
"strip",
"(",
")",
")",
"if",
"not",
"match",
":",
"raise",
"RuntimeError",
"(",
"'Parameter signature invalid, got '",
"+",
"sig",
")",
"group... | aaa0c5fbe514d7f0b1a89625185fc608e5d30702 |
train | parse_type_signature | Parse a type signature | sphinx_csharp/csharp.py | def parse_type_signature(sig):
""" Parse a type signature """
match = TYPE_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Type signature invalid, got ' + sig)
groups = match.groups()
typ = groups[0]
generic_types = groups[1]
if not generic_types:
generic_types = ... | def parse_type_signature(sig):
""" Parse a type signature """
match = TYPE_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Type signature invalid, got ' + sig)
groups = match.groups()
typ = groups[0]
generic_types = groups[1]
if not generic_types:
generic_types = ... | [
"Parse",
"a",
"type",
"signature"
] | djungelorm/sphinx-csharp | python | https://github.com/djungelorm/sphinx-csharp/blob/aaa0c5fbe514d7f0b1a89625185fc608e5d30702/sphinx_csharp/csharp.py#L122-L135 | [
"def",
"parse_type_signature",
"(",
"sig",
")",
":",
"match",
"=",
"TYPE_SIG_RE",
".",
"match",
"(",
"sig",
".",
"strip",
"(",
")",
")",
"if",
"not",
"match",
":",
"raise",
"RuntimeError",
"(",
"'Type signature invalid, got '",
"+",
"sig",
")",
"groups",
"... | aaa0c5fbe514d7f0b1a89625185fc608e5d30702 |
train | parse_attr_signature | Parse an attribute signature | sphinx_csharp/csharp.py | def parse_attr_signature(sig):
""" Parse an attribute signature """
match = ATTR_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Attribute signature invalid, got ' + sig)
name, _, params = match.groups()
if params is not None and params.strip() != '':
params = split_sig(p... | def parse_attr_signature(sig):
""" Parse an attribute signature """
match = ATTR_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Attribute signature invalid, got ' + sig)
name, _, params = match.groups()
if params is not None and params.strip() != '':
params = split_sig(p... | [
"Parse",
"an",
"attribute",
"signature"
] | djungelorm/sphinx-csharp | python | https://github.com/djungelorm/sphinx-csharp/blob/aaa0c5fbe514d7f0b1a89625185fc608e5d30702/sphinx_csharp/csharp.py#L138-L149 | [
"def",
"parse_attr_signature",
"(",
"sig",
")",
":",
"match",
"=",
"ATTR_SIG_RE",
".",
"match",
"(",
"sig",
".",
"strip",
"(",
")",
")",
"if",
"not",
"match",
":",
"raise",
"RuntimeError",
"(",
"'Attribute signature invalid, got '",
"+",
"sig",
")",
"name",
... | aaa0c5fbe514d7f0b1a89625185fc608e5d30702 |
train | get_msdn_ref | Try and create a reference to a type on MSDN | sphinx_csharp/csharp.py | def get_msdn_ref(name):
""" Try and create a reference to a type on MSDN """
in_msdn = False
if name in MSDN_VALUE_TYPES:
name = MSDN_VALUE_TYPES[name]
in_msdn = True
if name.startswith('System.'):
in_msdn = True
if in_msdn:
link = name.split('<')[0]
if link i... | def get_msdn_ref(name):
""" Try and create a reference to a type on MSDN """
in_msdn = False
if name in MSDN_VALUE_TYPES:
name = MSDN_VALUE_TYPES[name]
in_msdn = True
if name.startswith('System.'):
in_msdn = True
if in_msdn:
link = name.split('<')[0]
if link i... | [
"Try",
"and",
"create",
"a",
"reference",
"to",
"a",
"type",
"on",
"MSDN"
] | djungelorm/sphinx-csharp | python | https://github.com/djungelorm/sphinx-csharp/blob/aaa0c5fbe514d7f0b1a89625185fc608e5d30702/sphinx_csharp/csharp.py#L172-L192 | [
"def",
"get_msdn_ref",
"(",
"name",
")",
":",
"in_msdn",
"=",
"False",
"if",
"name",
"in",
"MSDN_VALUE_TYPES",
":",
"name",
"=",
"MSDN_VALUE_TYPES",
"[",
"name",
"]",
"in_msdn",
"=",
"True",
"if",
"name",
".",
"startswith",
"(",
"'System.'",
")",
":",
"i... | aaa0c5fbe514d7f0b1a89625185fc608e5d30702 |
train | shorten_type | Shorten a type. E.g. drops 'System.' | sphinx_csharp/csharp.py | def shorten_type(typ):
""" Shorten a type. E.g. drops 'System.' """
offset = 0
for prefix in SHORTEN_TYPE_PREFIXES:
if typ.startswith(prefix):
if len(prefix) > offset:
offset = len(prefix)
return typ[offset:] | def shorten_type(typ):
""" Shorten a type. E.g. drops 'System.' """
offset = 0
for prefix in SHORTEN_TYPE_PREFIXES:
if typ.startswith(prefix):
if len(prefix) > offset:
offset = len(prefix)
return typ[offset:] | [
"Shorten",
"a",
"type",
".",
"E",
".",
"g",
".",
"drops",
"System",
"."
] | djungelorm/sphinx-csharp | python | https://github.com/djungelorm/sphinx-csharp/blob/aaa0c5fbe514d7f0b1a89625185fc608e5d30702/sphinx_csharp/csharp.py#L201-L208 | [
"def",
"shorten_type",
"(",
"typ",
")",
":",
"offset",
"=",
"0",
"for",
"prefix",
"in",
"SHORTEN_TYPE_PREFIXES",
":",
"if",
"typ",
".",
"startswith",
"(",
"prefix",
")",
":",
"if",
"len",
"(",
"prefix",
")",
">",
"offset",
":",
"offset",
"=",
"len",
... | aaa0c5fbe514d7f0b1a89625185fc608e5d30702 |
train | OptionParse.parse_mecab_options | Parses the MeCab options, returning them in a dictionary.
Lattice-level option has been deprecated; please use marginal or nbest
instead.
:options string or dictionary of options to use when instantiating
the MeCab instance. May be in short- or long-form, or in a
... | natto/option_parse.py | def parse_mecab_options(self, options):
'''Parses the MeCab options, returning them in a dictionary.
Lattice-level option has been deprecated; please use marginal or nbest
instead.
:options string or dictionary of options to use when instantiating
the MeCab insta... | def parse_mecab_options(self, options):
'''Parses the MeCab options, returning them in a dictionary.
Lattice-level option has been deprecated; please use marginal or nbest
instead.
:options string or dictionary of options to use when instantiating
the MeCab insta... | [
"Parses",
"the",
"MeCab",
"options",
"returning",
"them",
"in",
"a",
"dictionary",
".",
"Lattice",
"-",
"level",
"option",
"has",
"been",
"deprecated",
";",
"please",
"use",
"marginal",
"or",
"nbest",
"instead",
".",
":",
"options",
"string",
"or",
"dictiona... | buruzaemon/natto-py | python | https://github.com/buruzaemon/natto-py/blob/018fe004c47c45c66bdf2e03fe24e981ae089b76/natto/option_parse.py#L47-L173 | [
"def",
"parse_mecab_options",
"(",
"self",
",",
"options",
")",
":",
"class",
"MeCabArgumentParser",
"(",
"argparse",
".",
"ArgumentParser",
")",
":",
"'''MeCab option parser for natto-py.'''",
"def",
"error",
"(",
"self",
",",
"message",
")",
":",
"'''error(message... | 018fe004c47c45c66bdf2e03fe24e981ae089b76 |
train | OptionParse.build_options_str | Returns a string concatenation of the MeCab options.
Args:
options: dictionary of options to use when instantiating the MeCab
instance.
Returns:
A string concatenation of the options used when instantiating the
MeCab instance, in long-form. | natto/option_parse.py | def build_options_str(self, options):
'''Returns a string concatenation of the MeCab options.
Args:
options: dictionary of options to use when instantiating the MeCab
instance.
Returns:
A string concatenation of the options used when instantiatin... | def build_options_str(self, options):
'''Returns a string concatenation of the MeCab options.
Args:
options: dictionary of options to use when instantiating the MeCab
instance.
Returns:
A string concatenation of the options used when instantiatin... | [
"Returns",
"a",
"string",
"concatenation",
"of",
"the",
"MeCab",
"options",
".",
"Args",
":",
"options",
":",
"dictionary",
"of",
"options",
"to",
"use",
"when",
"instantiating",
"the",
"MeCab",
"instance",
".",
"Returns",
":",
"A",
"string",
"concatenation",
... | buruzaemon/natto-py | python | https://github.com/buruzaemon/natto-py/blob/018fe004c47c45c66bdf2e03fe24e981ae089b76/natto/option_parse.py#L175-L196 | [
"def",
"build_options_str",
"(",
"self",
",",
"options",
")",
":",
"opts",
"=",
"[",
"]",
"for",
"name",
"in",
"iter",
"(",
"list",
"(",
"self",
".",
"_SUPPORTED_OPTS",
".",
"values",
"(",
")",
")",
")",
":",
"if",
"name",
"in",
"options",
":",
"ke... | 018fe004c47c45c66bdf2e03fe24e981ae089b76 |
train | create | Allocates and initializes a decoder state | opus/api/decoder.py | def create(fs, channels):
"""Allocates and initializes a decoder state"""
result_code = ctypes.c_int()
result = _create(fs, channels, ctypes.byref(result_code))
if result_code.value is not 0:
raise OpusError(result_code.value)
return result | def create(fs, channels):
"""Allocates and initializes a decoder state"""
result_code = ctypes.c_int()
result = _create(fs, channels, ctypes.byref(result_code))
if result_code.value is not 0:
raise OpusError(result_code.value)
return result | [
"Allocates",
"and",
"initializes",
"a",
"decoder",
"state"
] | svartalf/python-opus | python | https://github.com/svartalf/python-opus/blob/a3c1d556d2772b5be659ddd08c033ddd4d566b3a/opus/api/decoder.py#L32-L41 | [
"def",
"create",
"(",
"fs",
",",
"channels",
")",
":",
"result_code",
"=",
"ctypes",
".",
"c_int",
"(",
")",
"result",
"=",
"_create",
"(",
"fs",
",",
"channels",
",",
"ctypes",
".",
"byref",
"(",
"result_code",
")",
")",
"if",
"result_code",
".",
"v... | a3c1d556d2772b5be659ddd08c033ddd4d566b3a |
train | packet_get_bandwidth | Gets the bandwidth of an Opus packet. | opus/api/decoder.py | def packet_get_bandwidth(data):
"""Gets the bandwidth of an Opus packet."""
data_pointer = ctypes.c_char_p(data)
result = _packet_get_bandwidth(data_pointer)
if result < 0:
raise OpusError(result)
return result | def packet_get_bandwidth(data):
"""Gets the bandwidth of an Opus packet."""
data_pointer = ctypes.c_char_p(data)
result = _packet_get_bandwidth(data_pointer)
if result < 0:
raise OpusError(result)
return result | [
"Gets",
"the",
"bandwidth",
"of",
"an",
"Opus",
"packet",
"."
] | svartalf/python-opus | python | https://github.com/svartalf/python-opus/blob/a3c1d556d2772b5be659ddd08c033ddd4d566b3a/opus/api/decoder.py#L49-L58 | [
"def",
"packet_get_bandwidth",
"(",
"data",
")",
":",
"data_pointer",
"=",
"ctypes",
".",
"c_char_p",
"(",
"data",
")",
"result",
"=",
"_packet_get_bandwidth",
"(",
"data_pointer",
")",
"if",
"result",
"<",
"0",
":",
"raise",
"OpusError",
"(",
"result",
")",... | a3c1d556d2772b5be659ddd08c033ddd4d566b3a |
train | packet_get_nb_channels | Gets the number of channels from an Opus packet | opus/api/decoder.py | def packet_get_nb_channels(data):
"""Gets the number of channels from an Opus packet"""
data_pointer = ctypes.c_char_p(data)
result = _packet_get_nb_channels(data_pointer)
if result < 0:
raise OpusError(result)
return result | def packet_get_nb_channels(data):
"""Gets the number of channels from an Opus packet"""
data_pointer = ctypes.c_char_p(data)
result = _packet_get_nb_channels(data_pointer)
if result < 0:
raise OpusError(result)
return result | [
"Gets",
"the",
"number",
"of",
"channels",
"from",
"an",
"Opus",
"packet"
] | svartalf/python-opus | python | https://github.com/svartalf/python-opus/blob/a3c1d556d2772b5be659ddd08c033ddd4d566b3a/opus/api/decoder.py#L66-L75 | [
"def",
"packet_get_nb_channels",
"(",
"data",
")",
":",
"data_pointer",
"=",
"ctypes",
".",
"c_char_p",
"(",
"data",
")",
"result",
"=",
"_packet_get_nb_channels",
"(",
"data_pointer",
")",
"if",
"result",
"<",
"0",
":",
"raise",
"OpusError",
"(",
"result",
... | a3c1d556d2772b5be659ddd08c033ddd4d566b3a |
train | packet_get_nb_frames | Gets the number of frames in an Opus packet | opus/api/decoder.py | def packet_get_nb_frames(data, length=None):
"""Gets the number of frames in an Opus packet"""
data_pointer = ctypes.c_char_p(data)
if length is None:
length = len(data)
result = _packet_get_nb_frames(data_pointer, ctypes.c_int(length))
if result < 0:
raise OpusError(result)
r... | def packet_get_nb_frames(data, length=None):
"""Gets the number of frames in an Opus packet"""
data_pointer = ctypes.c_char_p(data)
if length is None:
length = len(data)
result = _packet_get_nb_frames(data_pointer, ctypes.c_int(length))
if result < 0:
raise OpusError(result)
r... | [
"Gets",
"the",
"number",
"of",
"frames",
"in",
"an",
"Opus",
"packet"
] | svartalf/python-opus | python | https://github.com/svartalf/python-opus/blob/a3c1d556d2772b5be659ddd08c033ddd4d566b3a/opus/api/decoder.py#L83-L94 | [
"def",
"packet_get_nb_frames",
"(",
"data",
",",
"length",
"=",
"None",
")",
":",
"data_pointer",
"=",
"ctypes",
".",
"c_char_p",
"(",
"data",
")",
"if",
"length",
"is",
"None",
":",
"length",
"=",
"len",
"(",
"data",
")",
"result",
"=",
"_packet_get_nb_... | a3c1d556d2772b5be659ddd08c033ddd4d566b3a |
train | packet_get_samples_per_frame | Gets the number of samples per frame from an Opus packet | opus/api/decoder.py | def packet_get_samples_per_frame(data, fs):
"""Gets the number of samples per frame from an Opus packet"""
data_pointer = ctypes.c_char_p(data)
result = _packet_get_nb_frames(data_pointer, ctypes.c_int(fs))
if result < 0:
raise OpusError(result)
return result | def packet_get_samples_per_frame(data, fs):
"""Gets the number of samples per frame from an Opus packet"""
data_pointer = ctypes.c_char_p(data)
result = _packet_get_nb_frames(data_pointer, ctypes.c_int(fs))
if result < 0:
raise OpusError(result)
return result | [
"Gets",
"the",
"number",
"of",
"samples",
"per",
"frame",
"from",
"an",
"Opus",
"packet"
] | svartalf/python-opus | python | https://github.com/svartalf/python-opus/blob/a3c1d556d2772b5be659ddd08c033ddd4d566b3a/opus/api/decoder.py#L102-L111 | [
"def",
"packet_get_samples_per_frame",
"(",
"data",
",",
"fs",
")",
":",
"data_pointer",
"=",
"ctypes",
".",
"c_char_p",
"(",
"data",
")",
"result",
"=",
"_packet_get_nb_frames",
"(",
"data_pointer",
",",
"ctypes",
".",
"c_int",
"(",
"fs",
")",
")",
"if",
... | a3c1d556d2772b5be659ddd08c033ddd4d566b3a |
train | decode | Decode an Opus frame
Unlike the `opus_decode` function , this function takes an additional parameter `channels`,
which indicates the number of channels in the frame | opus/api/decoder.py | def decode(decoder, data, length, frame_size, decode_fec, channels=2):
"""Decode an Opus frame
Unlike the `opus_decode` function , this function takes an additional parameter `channels`,
which indicates the number of channels in the frame
"""
pcm_size = frame_size * channels * ctypes.sizeof(ctypes... | def decode(decoder, data, length, frame_size, decode_fec, channels=2):
"""Decode an Opus frame
Unlike the `opus_decode` function , this function takes an additional parameter `channels`,
which indicates the number of channels in the frame
"""
pcm_size = frame_size * channels * ctypes.sizeof(ctypes... | [
"Decode",
"an",
"Opus",
"frame"
] | svartalf/python-opus | python | https://github.com/svartalf/python-opus/blob/a3c1d556d2772b5be659ddd08c033ddd4d566b3a/opus/api/decoder.py#L132-L150 | [
"def",
"decode",
"(",
"decoder",
",",
"data",
",",
"length",
",",
"frame_size",
",",
"decode_fec",
",",
"channels",
"=",
"2",
")",
":",
"pcm_size",
"=",
"frame_size",
"*",
"channels",
"*",
"ctypes",
".",
"sizeof",
"(",
"ctypes",
".",
"c_int16",
")",
"p... | a3c1d556d2772b5be659ddd08c033ddd4d566b3a |
train | JenkinsArtifacts.label_list_parser | Extracts comma separate tag=value pairs from a string
Assumes all characters other than / and , are valid | omego/artifacts.py | def label_list_parser(self, url):
"""
Extracts comma separate tag=value pairs from a string
Assumes all characters other than / and , are valid
"""
labels = re.findall('([^/,]+=[^/,]+)', url)
slabels = set(labels)
if '' in slabels:
slabels.remove('')
... | def label_list_parser(self, url):
"""
Extracts comma separate tag=value pairs from a string
Assumes all characters other than / and , are valid
"""
labels = re.findall('([^/,]+=[^/,]+)', url)
slabels = set(labels)
if '' in slabels:
slabels.remove('')
... | [
"Extracts",
"comma",
"separate",
"tag",
"=",
"value",
"pairs",
"from",
"a",
"string",
"Assumes",
"all",
"characters",
"other",
"than",
"/",
"and",
"are",
"valid"
] | ome/omego | python | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/artifacts.py#L327-L336 | [
"def",
"label_list_parser",
"(",
"self",
",",
"url",
")",
":",
"labels",
"=",
"re",
".",
"findall",
"(",
"'([^/,]+=[^/,]+)'",
",",
"url",
")",
"slabels",
"=",
"set",
"(",
"labels",
")",
"if",
"''",
"in",
"slabels",
":",
"slabels",
".",
"remove",
"(",
... | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb |
train | init | :param app: The Flask app
:param register_blueprint: Override to False to stop the blueprint from automatically being registered to the
app
:param url_prefix: The URL prefix for the blueprint, defaults to /fm
:param access_control_function: Pass in a function here to implement... | flaskfilemanager/filemanager.py | def init(app, register_blueprint=True, url_prefix='/fm', access_control_function=None,
custom_config_json_path=None, custom_init_js_path=None):
"""
:param app: The Flask app
:param register_blueprint: Override to False to stop the blueprint from automatically being registered to the
... | def init(app, register_blueprint=True, url_prefix='/fm', access_control_function=None,
custom_config_json_path=None, custom_init_js_path=None):
"""
:param app: The Flask app
:param register_blueprint: Override to False to stop the blueprint from automatically being registered to the
... | [
":",
"param",
"app",
":",
"The",
"Flask",
"app",
":",
"param",
"register_blueprint",
":",
"Override",
"to",
"False",
"to",
"stop",
"the",
"blueprint",
"from",
"automatically",
"being",
"registered",
"to",
"the",
"app",
":",
"param",
"url_prefix",
":",
"The",... | stevelittlefish/flaskfilemanager | python | https://github.com/stevelittlefish/flaskfilemanager/blob/e37faf5cb4c1370e069bf009ce65c88ad8ee0e94/flaskfilemanager/filemanager.py#L48-L93 | [
"def",
"init",
"(",
"app",
",",
"register_blueprint",
"=",
"True",
",",
"url_prefix",
"=",
"'/fm'",
",",
"access_control_function",
"=",
"None",
",",
"custom_config_json_path",
"=",
"None",
",",
"custom_init_js_path",
"=",
"None",
")",
":",
"global",
"_initialis... | e37faf5cb4c1370e069bf009ce65c88ad8ee0e94 |
train | get_file | :param path: relative path, or None to get from request
:param content: file content, output in data. Used for editfile | flaskfilemanager/filemanager.py | def get_file(path=None, content=None):
"""
:param path: relative path, or None to get from request
:param content: file content, output in data. Used for editfile
"""
if path is None:
path = request.args.get('path')
if path is None:
return error('No path in request')
fi... | def get_file(path=None, content=None):
"""
:param path: relative path, or None to get from request
:param content: file content, output in data. Used for editfile
"""
if path is None:
path = request.args.get('path')
if path is None:
return error('No path in request')
fi... | [
":",
"param",
"path",
":",
"relative",
"path",
"or",
"None",
"to",
"get",
"from",
"request",
":",
"param",
"content",
":",
"file",
"content",
"output",
"in",
"data",
".",
"Used",
"for",
"editfile"
] | stevelittlefish/flaskfilemanager | python | https://github.com/stevelittlefish/flaskfilemanager/blob/e37faf5cb4c1370e069bf009ce65c88ad8ee0e94/flaskfilemanager/filemanager.py#L274-L329 | [
"def",
"get_file",
"(",
"path",
"=",
"None",
",",
"content",
"=",
"None",
")",
":",
"if",
"path",
"is",
"None",
":",
"path",
"=",
"request",
".",
"args",
".",
"get",
"(",
"'path'",
")",
"if",
"path",
"is",
"None",
":",
"return",
"error",
"(",
"'N... | e37faf5cb4c1370e069bf009ce65c88ad8ee0e94 |
train | MeCabEnv.__get_charset | Return the character encoding (charset) used internally by MeCab.
Charset is that of the system dictionary used by MeCab. Will defer to
the user-specified MECAB_CHARSET environment variable, if set.
Defaults to shift-jis on Windows.
Defaults to utf-8 on Mac OS.
Defaults ... | natto/environment.py | def __get_charset(self):
'''Return the character encoding (charset) used internally by MeCab.
Charset is that of the system dictionary used by MeCab. Will defer to
the user-specified MECAB_CHARSET environment variable, if set.
Defaults to shift-jis on Windows.
Defaults t... | def __get_charset(self):
'''Return the character encoding (charset) used internally by MeCab.
Charset is that of the system dictionary used by MeCab. Will defer to
the user-specified MECAB_CHARSET environment variable, if set.
Defaults to shift-jis on Windows.
Defaults t... | [
"Return",
"the",
"character",
"encoding",
"(",
"charset",
")",
"used",
"internally",
"by",
"MeCab",
".",
"Charset",
"is",
"that",
"of",
"the",
"system",
"dictionary",
"used",
"by",
"MeCab",
".",
"Will",
"defer",
"to",
"the",
"user",
"-",
"specified",
"MECA... | buruzaemon/natto-py | python | https://github.com/buruzaemon/natto-py/blob/018fe004c47c45c66bdf2e03fe24e981ae089b76/natto/environment.py#L55-L96 | [
"def",
"__get_charset",
"(",
"self",
")",
":",
"cset",
"=",
"os",
".",
"getenv",
"(",
"self",
".",
"MECAB_CHARSET",
")",
"if",
"cset",
":",
"logger",
".",
"debug",
"(",
"self",
".",
"_DEBUG_CSET_DEFAULT",
".",
"format",
"(",
"cset",
")",
")",
"return",... | 018fe004c47c45c66bdf2e03fe24e981ae089b76 |
train | MeCabEnv.__get_libpath | Return the absolute path to the MeCab library.
On Windows, the path to the system dictionary is used to deduce the
path to libmecab.dll.
Otherwise, mecab-config is used find the libmecab shared object or
dynamic library (*NIX or Mac OS, respectively).
Will defer to the... | natto/environment.py | def __get_libpath(self):
'''Return the absolute path to the MeCab library.
On Windows, the path to the system dictionary is used to deduce the
path to libmecab.dll.
Otherwise, mecab-config is used find the libmecab shared object or
dynamic library (*NIX or Mac OS, respec... | def __get_libpath(self):
'''Return the absolute path to the MeCab library.
On Windows, the path to the system dictionary is used to deduce the
path to libmecab.dll.
Otherwise, mecab-config is used find the libmecab shared object or
dynamic library (*NIX or Mac OS, respec... | [
"Return",
"the",
"absolute",
"path",
"to",
"the",
"MeCab",
"library",
".",
"On",
"Windows",
"the",
"path",
"to",
"the",
"system",
"dictionary",
"is",
"used",
"to",
"deduce",
"the",
"path",
"to",
"libmecab",
".",
"dll",
".",
"Otherwise",
"mecab",
"-",
"co... | buruzaemon/natto-py | python | https://github.com/buruzaemon/natto-py/blob/018fe004c47c45c66bdf2e03fe24e981ae089b76/natto/environment.py#L98-L162 | [
"def",
"__get_libpath",
"(",
"self",
")",
":",
"libp",
"=",
"os",
".",
"getenv",
"(",
"self",
".",
"MECAB_PATH",
")",
"if",
"libp",
":",
"return",
"os",
".",
"path",
".",
"abspath",
"(",
"libp",
")",
"else",
":",
"plat",
"=",
"sys",
".",
"platform"... | 018fe004c47c45c66bdf2e03fe24e981ae089b76 |
train | MeCabEnv.__regkey_value | r'''Return the data of value mecabrc at MeCab HKEY node.
On Windows, the path to the mecabrc as set in the Windows Registry is
used to deduce the path to libmecab.dll.
Returns:
The full path to the mecabrc on Windows.
Raises:
WindowsError: A problem wa... | natto/environment.py | def __regkey_value(self, path, name='', start_key=None):
r'''Return the data of value mecabrc at MeCab HKEY node.
On Windows, the path to the mecabrc as set in the Windows Registry is
used to deduce the path to libmecab.dll.
Returns:
The full path to the mecabrc on W... | def __regkey_value(self, path, name='', start_key=None):
r'''Return the data of value mecabrc at MeCab HKEY node.
On Windows, the path to the mecabrc as set in the Windows Registry is
used to deduce the path to libmecab.dll.
Returns:
The full path to the mecabrc on W... | [
"r",
"Return",
"the",
"data",
"of",
"value",
"mecabrc",
"at",
"MeCab",
"HKEY",
"node",
".",
"On",
"Windows",
"the",
"path",
"to",
"the",
"mecabrc",
"as",
"set",
"in",
"the",
"Windows",
"Registry",
"is",
"used",
"to",
"deduce",
"the",
"path",
"to",
"lib... | buruzaemon/natto-py | python | https://github.com/buruzaemon/natto-py/blob/018fe004c47c45c66bdf2e03fe24e981ae089b76/natto/environment.py#L164-L199 | [
"def",
"__regkey_value",
"(",
"self",
",",
"path",
",",
"name",
"=",
"''",
",",
"start_key",
"=",
"None",
")",
":",
"if",
"sys",
".",
"version",
"<",
"'3'",
":",
"import",
"_winreg",
"as",
"reg",
"else",
":",
"import",
"winreg",
"as",
"reg",
"def",
... | 018fe004c47c45c66bdf2e03fe24e981ae089b76 |
train | diff | Show the differences between the old and new html document, as html.
Return the document html with extra tags added to show changes. Add <ins>
tags around newly added sections, and <del> tags to show sections that have
been deleted. | htmltreediff/html.py | def diff(old_html, new_html, cutoff=0.0, plaintext=False, pretty=False):
"""Show the differences between the old and new html document, as html.
Return the document html with extra tags added to show changes. Add <ins>
tags around newly added sections, and <del> tags to show sections that have
been del... | def diff(old_html, new_html, cutoff=0.0, plaintext=False, pretty=False):
"""Show the differences between the old and new html document, as html.
Return the document html with extra tags added to show changes. Add <ins>
tags around newly added sections, and <del> tags to show sections that have
been del... | [
"Show",
"the",
"differences",
"between",
"the",
"old",
"and",
"new",
"html",
"document",
"as",
"html",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/html.py#L12-L42 | [
"def",
"diff",
"(",
"old_html",
",",
"new_html",
",",
"cutoff",
"=",
"0.0",
",",
"plaintext",
"=",
"False",
",",
"pretty",
"=",
"False",
")",
":",
"if",
"plaintext",
":",
"old_dom",
"=",
"parse_text",
"(",
"old_html",
")",
"new_dom",
"=",
"parse_text",
... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | adjusted_ops | Iterate through opcodes, turning them into a series of insert and delete
operations, adjusting indices to account for the size of insertions and
deletions.
>>> def sequence_opcodes(old, new): return difflib.SequenceMatcher(a=old, b=new).get_opcodes()
>>> list(adjusted_ops(sequence_opcodes('abc', 'b')))... | htmltreediff/diff_core.py | def adjusted_ops(opcodes):
"""
Iterate through opcodes, turning them into a series of insert and delete
operations, adjusting indices to account for the size of insertions and
deletions.
>>> def sequence_opcodes(old, new): return difflib.SequenceMatcher(a=old, b=new).get_opcodes()
>>> list(adju... | def adjusted_ops(opcodes):
"""
Iterate through opcodes, turning them into a series of insert and delete
operations, adjusting indices to account for the size of insertions and
deletions.
>>> def sequence_opcodes(old, new): return difflib.SequenceMatcher(a=old, b=new).get_opcodes()
>>> list(adju... | [
"Iterate",
"through",
"opcodes",
"turning",
"them",
"into",
"a",
"series",
"of",
"insert",
"and",
"delete",
"operations",
"adjusting",
"indices",
"to",
"account",
"for",
"the",
"size",
"of",
"insertions",
"and",
"deletions",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/diff_core.py#L161-L209 | [
"def",
"adjusted_ops",
"(",
"opcodes",
")",
":",
"while",
"opcodes",
":",
"op",
"=",
"opcodes",
".",
"pop",
"(",
"0",
")",
"tag",
",",
"i1",
",",
"i2",
",",
"j1",
",",
"j2",
"=",
"op",
"shift",
"=",
"0",
"if",
"tag",
"==",
"'equal'",
":",
"cont... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | match_indices | Yield index tuples (old_index, new_index) for each place in the match. | htmltreediff/diff_core.py | def match_indices(match):
"""Yield index tuples (old_index, new_index) for each place in the match."""
a, b, size = match
for i in range(size):
yield a + i, b + i | def match_indices(match):
"""Yield index tuples (old_index, new_index) for each place in the match."""
a, b, size = match
for i in range(size):
yield a + i, b + i | [
"Yield",
"index",
"tuples",
"(",
"old_index",
"new_index",
")",
"for",
"each",
"place",
"in",
"the",
"match",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/diff_core.py#L224-L228 | [
"def",
"match_indices",
"(",
"match",
")",
":",
"a",
",",
"b",
",",
"size",
"=",
"match",
"for",
"i",
"in",
"range",
"(",
"size",
")",
":",
"yield",
"a",
"+",
"i",
",",
"b",
"+",
"i"
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | get_opcodes | Use difflib to get the opcodes for a set of matching blocks. | htmltreediff/diff_core.py | def get_opcodes(matching_blocks):
"""Use difflib to get the opcodes for a set of matching blocks."""
sm = difflib.SequenceMatcher(a=[], b=[])
sm.matching_blocks = matching_blocks
return sm.get_opcodes() | def get_opcodes(matching_blocks):
"""Use difflib to get the opcodes for a set of matching blocks."""
sm = difflib.SequenceMatcher(a=[], b=[])
sm.matching_blocks = matching_blocks
return sm.get_opcodes() | [
"Use",
"difflib",
"to",
"get",
"the",
"opcodes",
"for",
"a",
"set",
"of",
"matching",
"blocks",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/diff_core.py#L230-L234 | [
"def",
"get_opcodes",
"(",
"matching_blocks",
")",
":",
"sm",
"=",
"difflib",
".",
"SequenceMatcher",
"(",
"a",
"=",
"[",
"]",
",",
"b",
"=",
"[",
"]",
")",
"sm",
".",
"matching_blocks",
"=",
"matching_blocks",
"return",
"sm",
".",
"get_opcodes",
"(",
... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | match_blocks | Use difflib to find matching blocks. | htmltreediff/diff_core.py | def match_blocks(hash_func, old_children, new_children):
"""Use difflib to find matching blocks."""
sm = difflib.SequenceMatcher(
_is_junk,
a=[hash_func(c) for c in old_children],
b=[hash_func(c) for c in new_children],
)
return sm | def match_blocks(hash_func, old_children, new_children):
"""Use difflib to find matching blocks."""
sm = difflib.SequenceMatcher(
_is_junk,
a=[hash_func(c) for c in old_children],
b=[hash_func(c) for c in new_children],
)
return sm | [
"Use",
"difflib",
"to",
"find",
"matching",
"blocks",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/diff_core.py#L246-L253 | [
"def",
"match_blocks",
"(",
"hash_func",
",",
"old_children",
",",
"new_children",
")",
":",
"sm",
"=",
"difflib",
".",
"SequenceMatcher",
"(",
"_is_junk",
",",
"a",
"=",
"[",
"hash_func",
"(",
"c",
")",
"for",
"c",
"in",
"old_children",
"]",
",",
"b",
... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | get_nonmatching_blocks | Given a list of matching blocks, output the gaps between them.
Non-matches have the format (alo, ahi, blo, bhi). This specifies two index
ranges, one in the A sequence, and one in the B sequence. | htmltreediff/diff_core.py | def get_nonmatching_blocks(matching_blocks):
"""Given a list of matching blocks, output the gaps between them.
Non-matches have the format (alo, ahi, blo, bhi). This specifies two index
ranges, one in the A sequence, and one in the B sequence.
"""
i = j = 0
for match in matching_blocks:
... | def get_nonmatching_blocks(matching_blocks):
"""Given a list of matching blocks, output the gaps between them.
Non-matches have the format (alo, ahi, blo, bhi). This specifies two index
ranges, one in the A sequence, and one in the B sequence.
"""
i = j = 0
for match in matching_blocks:
... | [
"Given",
"a",
"list",
"of",
"matching",
"blocks",
"output",
"the",
"gaps",
"between",
"them",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/diff_core.py#L255-L266 | [
"def",
"get_nonmatching_blocks",
"(",
"matching_blocks",
")",
":",
"i",
"=",
"j",
"=",
"0",
"for",
"match",
"in",
"matching_blocks",
":",
"a",
",",
"b",
",",
"size",
"=",
"match",
"yield",
"(",
"i",
",",
"a",
",",
"j",
",",
"b",
")",
"i",
"=",
"a... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | merge_blocks | Given two lists of blocks, combine them, in the proper order.
Ensure that there are no overlaps, and that they are for sequences of the
same length. | htmltreediff/diff_core.py | def merge_blocks(a_blocks, b_blocks):
"""Given two lists of blocks, combine them, in the proper order.
Ensure that there are no overlaps, and that they are for sequences of the
same length.
"""
# Check sentinels for sequence length.
assert a_blocks[-1][2] == b_blocks[-1][2] == 0 # sentinel size... | def merge_blocks(a_blocks, b_blocks):
"""Given two lists of blocks, combine them, in the proper order.
Ensure that there are no overlaps, and that they are for sequences of the
same length.
"""
# Check sentinels for sequence length.
assert a_blocks[-1][2] == b_blocks[-1][2] == 0 # sentinel size... | [
"Given",
"two",
"lists",
"of",
"blocks",
"combine",
"them",
"in",
"the",
"proper",
"order",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/diff_core.py#L268-L285 | [
"def",
"merge_blocks",
"(",
"a_blocks",
",",
"b_blocks",
")",
":",
"# Check sentinels for sequence length.",
"assert",
"a_blocks",
"[",
"-",
"1",
"]",
"[",
"2",
"]",
"==",
"b_blocks",
"[",
"-",
"1",
"]",
"[",
"2",
"]",
"==",
"0",
"# sentinel size is 0",
"a... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | remove_comments | Remove comments, as they can break the xml parser.
See html5lib issue #122 ( http://code.google.com/p/html5lib/issues/detail?id=122 ).
>>> remove_comments('<!-- -->')
''
>>> remove_comments('<!--\\n-->')
''
>>> remove_comments('<p>stuff<!-- \\n -->stuff</p>')
'<p>stuffstuff</p>' | htmltreediff/util.py | def remove_comments(xml):
"""
Remove comments, as they can break the xml parser.
See html5lib issue #122 ( http://code.google.com/p/html5lib/issues/detail?id=122 ).
>>> remove_comments('<!-- -->')
''
>>> remove_comments('<!--\\n-->')
''
>>> remove_comments('<p>stuff<!-- \\n -->stuff</p... | def remove_comments(xml):
"""
Remove comments, as they can break the xml parser.
See html5lib issue #122 ( http://code.google.com/p/html5lib/issues/detail?id=122 ).
>>> remove_comments('<!-- -->')
''
>>> remove_comments('<!--\\n-->')
''
>>> remove_comments('<p>stuff<!-- \\n -->stuff</p... | [
"Remove",
"comments",
"as",
"they",
"can",
"break",
"the",
"xml",
"parser",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L74-L88 | [
"def",
"remove_comments",
"(",
"xml",
")",
":",
"regex",
"=",
"re",
".",
"compile",
"(",
"r'<!--.*?-->'",
",",
"re",
".",
"DOTALL",
")",
"return",
"regex",
".",
"sub",
"(",
"''",
",",
"xml",
")"
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | remove_newlines | r"""Remove newlines in the xml.
If the newline separates words in text, then replace with a space instead.
>>> remove_newlines('<p>para one</p>\n<p>para two</p>')
'<p>para one</p><p>para two</p>'
>>> remove_newlines('<p>line one\nline two</p>')
'<p>line one line two</p>'
>>> remove_newlines('o... | htmltreediff/util.py | def remove_newlines(xml):
r"""Remove newlines in the xml.
If the newline separates words in text, then replace with a space instead.
>>> remove_newlines('<p>para one</p>\n<p>para two</p>')
'<p>para one</p><p>para two</p>'
>>> remove_newlines('<p>line one\nline two</p>')
'<p>line one line two</... | def remove_newlines(xml):
r"""Remove newlines in the xml.
If the newline separates words in text, then replace with a space instead.
>>> remove_newlines('<p>para one</p>\n<p>para two</p>')
'<p>para one</p><p>para two</p>'
>>> remove_newlines('<p>line one\nline two</p>')
'<p>line one line two</... | [
"r",
"Remove",
"newlines",
"in",
"the",
"xml",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L90-L110 | [
"def",
"remove_newlines",
"(",
"xml",
")",
":",
"# Normalize newlines.",
"xml",
"=",
"xml",
".",
"replace",
"(",
"'\\r\\n'",
",",
"'\\n'",
")",
"xml",
"=",
"xml",
".",
"replace",
"(",
"'\\r'",
",",
"'\\n'",
")",
"# Remove newlines that don't separate text. The r... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | remove_insignificant_text_nodes | For html elements that should not have text nodes inside them, remove all
whitespace. For elements that may have text, collapse multiple spaces to a
single space. | htmltreediff/util.py | def remove_insignificant_text_nodes(dom):
"""
For html elements that should not have text nodes inside them, remove all
whitespace. For elements that may have text, collapse multiple spaces to a
single space.
"""
nodes_to_remove = []
for node in walk_dom(dom):
if is_text(node):
... | def remove_insignificant_text_nodes(dom):
"""
For html elements that should not have text nodes inside them, remove all
whitespace. For elements that may have text, collapse multiple spaces to a
single space.
"""
nodes_to_remove = []
for node in walk_dom(dom):
if is_text(node):
... | [
"For",
"html",
"elements",
"that",
"should",
"not",
"have",
"text",
"nodes",
"inside",
"them",
"remove",
"all",
"whitespace",
".",
"For",
"elements",
"that",
"may",
"have",
"text",
"collapse",
"multiple",
"spaces",
"to",
"a",
"single",
"space",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L229-L244 | [
"def",
"remove_insignificant_text_nodes",
"(",
"dom",
")",
":",
"nodes_to_remove",
"=",
"[",
"]",
"for",
"node",
"in",
"walk_dom",
"(",
"dom",
")",
":",
"if",
"is_text",
"(",
"node",
")",
":",
"text",
"=",
"node",
".",
"nodeValue",
"if",
"node",
".",
"... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | get_child | Get the child at the given index, or return None if it doesn't exist. | htmltreediff/util.py | def get_child(parent, child_index):
"""
Get the child at the given index, or return None if it doesn't exist.
"""
if child_index < 0 or child_index >= len(parent.childNodes):
return None
return parent.childNodes[child_index] | def get_child(parent, child_index):
"""
Get the child at the given index, or return None if it doesn't exist.
"""
if child_index < 0 or child_index >= len(parent.childNodes):
return None
return parent.childNodes[child_index] | [
"Get",
"the",
"child",
"at",
"the",
"given",
"index",
"or",
"return",
"None",
"if",
"it",
"doesn",
"t",
"exist",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L253-L259 | [
"def",
"get_child",
"(",
"parent",
",",
"child_index",
")",
":",
"if",
"child_index",
"<",
"0",
"or",
"child_index",
">=",
"len",
"(",
"parent",
".",
"childNodes",
")",
":",
"return",
"None",
"return",
"parent",
".",
"childNodes",
"[",
"child_index",
"]"
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | get_location | Get the node at the specified location in the dom.
Location is a sequence of child indices, starting at the children of the
root element. If there is no node at this location, raise a ValueError. | htmltreediff/util.py | def get_location(dom, location):
"""
Get the node at the specified location in the dom.
Location is a sequence of child indices, starting at the children of the
root element. If there is no node at this location, raise a ValueError.
"""
node = dom.documentElement
for i in location:
n... | def get_location(dom, location):
"""
Get the node at the specified location in the dom.
Location is a sequence of child indices, starting at the children of the
root element. If there is no node at this location, raise a ValueError.
"""
node = dom.documentElement
for i in location:
n... | [
"Get",
"the",
"node",
"at",
"the",
"specified",
"location",
"in",
"the",
"dom",
".",
"Location",
"is",
"a",
"sequence",
"of",
"child",
"indices",
"starting",
"at",
"the",
"children",
"of",
"the",
"root",
"element",
".",
"If",
"there",
"is",
"no",
"node",... | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L261-L272 | [
"def",
"get_location",
"(",
"dom",
",",
"location",
")",
":",
"node",
"=",
"dom",
".",
"documentElement",
"for",
"i",
"in",
"location",
":",
"node",
"=",
"get_child",
"(",
"node",
",",
"i",
")",
"if",
"not",
"node",
":",
"raise",
"ValueError",
"(",
"... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | check_text_similarity | Check whether two dom trees have similar text or not. | htmltreediff/util.py | def check_text_similarity(a_dom, b_dom, cutoff):
"""Check whether two dom trees have similar text or not."""
a_words = list(tree_words(a_dom))
b_words = list(tree_words(b_dom))
sm = WordMatcher(a=a_words, b=b_words)
if sm.text_ratio() >= cutoff:
return True
return False | def check_text_similarity(a_dom, b_dom, cutoff):
"""Check whether two dom trees have similar text or not."""
a_words = list(tree_words(a_dom))
b_words = list(tree_words(b_dom))
sm = WordMatcher(a=a_words, b=b_words)
if sm.text_ratio() >= cutoff:
return True
return False | [
"Check",
"whether",
"two",
"dom",
"trees",
"have",
"similar",
"text",
"or",
"not",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L295-L303 | [
"def",
"check_text_similarity",
"(",
"a_dom",
",",
"b_dom",
",",
"cutoff",
")",
":",
"a_words",
"=",
"list",
"(",
"tree_words",
"(",
"a_dom",
")",
")",
"b_words",
"=",
"list",
"(",
"tree_words",
"(",
"b_dom",
")",
")",
"sm",
"=",
"WordMatcher",
"(",
"a... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | tree_words | Return all the significant text below the given node as a list of words.
>>> list(tree_words(parse_minidom('<h1>one</h1> two <div>three<em>four</em></div>')))
['one', 'two', 'three', 'four'] | htmltreediff/util.py | def tree_words(node):
"""Return all the significant text below the given node as a list of words.
>>> list(tree_words(parse_minidom('<h1>one</h1> two <div>three<em>four</em></div>')))
['one', 'two', 'three', 'four']
"""
for word in split_text(tree_text(node)):
word = word.strip()
if ... | def tree_words(node):
"""Return all the significant text below the given node as a list of words.
>>> list(tree_words(parse_minidom('<h1>one</h1> two <div>three<em>four</em></div>')))
['one', 'two', 'three', 'four']
"""
for word in split_text(tree_text(node)):
word = word.strip()
if ... | [
"Return",
"all",
"the",
"significant",
"text",
"below",
"the",
"given",
"node",
"as",
"a",
"list",
"of",
"words",
".",
">>>",
"list",
"(",
"tree_words",
"(",
"parse_minidom",
"(",
"<h1",
">",
"one<",
"/",
"h1",
">",
"two",
"<div",
">",
"three<em",
">",... | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L305-L313 | [
"def",
"tree_words",
"(",
"node",
")",
":",
"for",
"word",
"in",
"split_text",
"(",
"tree_text",
"(",
"node",
")",
")",
":",
"word",
"=",
"word",
".",
"strip",
"(",
")",
"if",
"word",
":",
"yield",
"word"
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | tree_text | >>> tree_text(parse_minidom('<h1>one</h1>two<div>three<em>four</em></div>'))
'one two three four' | htmltreediff/util.py | def tree_text(node):
"""
>>> tree_text(parse_minidom('<h1>one</h1>two<div>three<em>four</em></div>'))
'one two three four'
"""
text = []
for descendant in walk_dom(node):
if is_text(descendant):
text.append(descendant.nodeValue)
return ' '.join(text) | def tree_text(node):
"""
>>> tree_text(parse_minidom('<h1>one</h1>two<div>three<em>four</em></div>'))
'one two three four'
"""
text = []
for descendant in walk_dom(node):
if is_text(descendant):
text.append(descendant.nodeValue)
return ' '.join(text) | [
">>>",
"tree_text",
"(",
"parse_minidom",
"(",
"<h1",
">",
"one<",
"/",
"h1",
">",
"two<div",
">",
"three<em",
">",
"four<",
"/",
"em",
">",
"<",
"/",
"div",
">",
"))",
"one",
"two",
"three",
"four"
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L315-L324 | [
"def",
"tree_text",
"(",
"node",
")",
":",
"text",
"=",
"[",
"]",
"for",
"descendant",
"in",
"walk_dom",
"(",
"node",
")",
":",
"if",
"is_text",
"(",
"descendant",
")",
":",
"text",
".",
"append",
"(",
"descendant",
".",
"nodeValue",
")",
"return",
"... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | insert_or_append | Insert the node before next_sibling. If next_sibling is None, append the node last instead. | htmltreediff/util.py | def insert_or_append(parent, node, next_sibling):
"""
Insert the node before next_sibling. If next_sibling is None, append the node last instead.
"""
# simple insert
if next_sibling:
parent.insertBefore(node, next_sibling)
else:
parent.appendChild(node) | def insert_or_append(parent, node, next_sibling):
"""
Insert the node before next_sibling. If next_sibling is None, append the node last instead.
"""
# simple insert
if next_sibling:
parent.insertBefore(node, next_sibling)
else:
parent.appendChild(node) | [
"Insert",
"the",
"node",
"before",
"next_sibling",
".",
"If",
"next_sibling",
"is",
"None",
"append",
"the",
"node",
"last",
"instead",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L339-L347 | [
"def",
"insert_or_append",
"(",
"parent",
",",
"node",
",",
"next_sibling",
")",
":",
"# simple insert",
"if",
"next_sibling",
":",
"parent",
".",
"insertBefore",
"(",
"node",
",",
"next_sibling",
")",
"else",
":",
"parent",
".",
"appendChild",
"(",
"node",
... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | wrap | Wrap the given tag around a node. | htmltreediff/util.py | def wrap(node, tag):
"""Wrap the given tag around a node."""
wrap_node = node.ownerDocument.createElement(tag)
parent = node.parentNode
if parent:
parent.replaceChild(wrap_node, node)
wrap_node.appendChild(node)
return wrap_node | def wrap(node, tag):
"""Wrap the given tag around a node."""
wrap_node = node.ownerDocument.createElement(tag)
parent = node.parentNode
if parent:
parent.replaceChild(wrap_node, node)
wrap_node.appendChild(node)
return wrap_node | [
"Wrap",
"the",
"given",
"tag",
"around",
"a",
"node",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L349-L356 | [
"def",
"wrap",
"(",
"node",
",",
"tag",
")",
":",
"wrap_node",
"=",
"node",
".",
"ownerDocument",
".",
"createElement",
"(",
"tag",
")",
"parent",
"=",
"node",
".",
"parentNode",
"if",
"parent",
":",
"parent",
".",
"replaceChild",
"(",
"wrap_node",
",",
... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | wrap_inner | Wrap the given tag around the contents of a node. | htmltreediff/util.py | def wrap_inner(node, tag):
"""Wrap the given tag around the contents of a node."""
children = list(node.childNodes)
wrap_node = node.ownerDocument.createElement(tag)
for c in children:
wrap_node.appendChild(c)
node.appendChild(wrap_node) | def wrap_inner(node, tag):
"""Wrap the given tag around the contents of a node."""
children = list(node.childNodes)
wrap_node = node.ownerDocument.createElement(tag)
for c in children:
wrap_node.appendChild(c)
node.appendChild(wrap_node) | [
"Wrap",
"the",
"given",
"tag",
"around",
"the",
"contents",
"of",
"a",
"node",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L358-L364 | [
"def",
"wrap_inner",
"(",
"node",
",",
"tag",
")",
":",
"children",
"=",
"list",
"(",
"node",
".",
"childNodes",
")",
"wrap_node",
"=",
"node",
".",
"ownerDocument",
".",
"createElement",
"(",
"tag",
")",
"for",
"c",
"in",
"children",
":",
"wrap_node",
... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | unwrap | Remove a node, replacing it with its children. | htmltreediff/util.py | def unwrap(node):
"""Remove a node, replacing it with its children."""
for child in list(node.childNodes):
node.parentNode.insertBefore(child, node)
remove_node(node) | def unwrap(node):
"""Remove a node, replacing it with its children."""
for child in list(node.childNodes):
node.parentNode.insertBefore(child, node)
remove_node(node) | [
"Remove",
"a",
"node",
"replacing",
"it",
"with",
"its",
"children",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L366-L370 | [
"def",
"unwrap",
"(",
"node",
")",
":",
"for",
"child",
"in",
"list",
"(",
"node",
".",
"childNodes",
")",
":",
"node",
".",
"parentNode",
".",
"insertBefore",
"(",
"child",
",",
"node",
")",
"remove_node",
"(",
"node",
")"
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | full_split | Split the text by the regex, keeping all parts.
The parts should re-join back into the original text.
>>> list(full_split('word', re.compile('&.*?')))
['word'] | htmltreediff/text.py | def full_split(text, regex):
"""
Split the text by the regex, keeping all parts.
The parts should re-join back into the original text.
>>> list(full_split('word', re.compile('&.*?')))
['word']
"""
while text:
m = regex.search(text)
if not m:
yield text
... | def full_split(text, regex):
"""
Split the text by the regex, keeping all parts.
The parts should re-join back into the original text.
>>> list(full_split('word', re.compile('&.*?')))
['word']
"""
while text:
m = regex.search(text)
if not m:
yield text
... | [
"Split",
"the",
"text",
"by",
"the",
"regex",
"keeping",
"all",
"parts",
".",
"The",
"parts",
"should",
"re",
"-",
"join",
"back",
"into",
"the",
"original",
"text",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/text.py#L4-L24 | [
"def",
"full_split",
"(",
"text",
",",
"regex",
")",
":",
"while",
"text",
":",
"m",
"=",
"regex",
".",
"search",
"(",
"text",
")",
"if",
"not",
"m",
":",
"yield",
"text",
"break",
"left",
"=",
"text",
"[",
":",
"m",
".",
"start",
"(",
")",
"]"... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | multi_split | Split the text by the given regexes, in priority order.
Make sure that the regex is parenthesized so that matches are returned in
re.split().
Splitting on a single regex works like normal split.
>>> '|'.join(multi_split('one two three', [r'\w+']))
'one| |two| |three'
Splitting on digits first... | htmltreediff/text.py | def multi_split(text, regexes):
"""
Split the text by the given regexes, in priority order.
Make sure that the regex is parenthesized so that matches are returned in
re.split().
Splitting on a single regex works like normal split.
>>> '|'.join(multi_split('one two three', [r'\w+']))
'one| ... | def multi_split(text, regexes):
"""
Split the text by the given regexes, in priority order.
Make sure that the regex is parenthesized so that matches are returned in
re.split().
Splitting on a single regex works like normal split.
>>> '|'.join(multi_split('one two three', [r'\w+']))
'one| ... | [
"Split",
"the",
"text",
"by",
"the",
"given",
"regexes",
"in",
"priority",
"order",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/text.py#L26-L69 | [
"def",
"multi_split",
"(",
"text",
",",
"regexes",
")",
":",
"def",
"make_regex",
"(",
"s",
")",
":",
"return",
"re",
".",
"compile",
"(",
"s",
")",
"if",
"isinstance",
"(",
"s",
",",
"basestring",
")",
"else",
"s",
"regexes",
"=",
"[",
"make_regex",... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | WordMatcher.text_ratio | Return a measure of the sequences' word similarity (float in [0,1]).
Each word has weight equal to its length for this measure
>>> m = WordMatcher(a=['abcdef', '12'], b=['abcdef', '34']) # 3/4 of the text is the same
>>> '%.3f' % m.ratio() # normal ratio fails
'0.500'
>>> '%.3f... | htmltreediff/text.py | def text_ratio(self):
"""Return a measure of the sequences' word similarity (float in [0,1]).
Each word has weight equal to its length for this measure
>>> m = WordMatcher(a=['abcdef', '12'], b=['abcdef', '34']) # 3/4 of the text is the same
>>> '%.3f' % m.ratio() # normal ratio fails
... | def text_ratio(self):
"""Return a measure of the sequences' word similarity (float in [0,1]).
Each word has weight equal to its length for this measure
>>> m = WordMatcher(a=['abcdef', '12'], b=['abcdef', '34']) # 3/4 of the text is the same
>>> '%.3f' % m.ratio() # normal ratio fails
... | [
"Return",
"a",
"measure",
"of",
"the",
"sequences",
"word",
"similarity",
"(",
"float",
"in",
"[",
"0",
"1",
"]",
")",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/text.py#L124-L138 | [
"def",
"text_ratio",
"(",
"self",
")",
":",
"return",
"_calculate_ratio",
"(",
"self",
".",
"match_length",
"(",
")",
",",
"self",
".",
"_text_length",
"(",
"self",
".",
"a",
")",
"+",
"self",
".",
"_text_length",
"(",
"self",
".",
"b",
")",
",",
")"... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | WordMatcher.match_length | Find the total length of all words that match between the two sequences. | htmltreediff/text.py | def match_length(self):
""" Find the total length of all words that match between the two sequences."""
length = 0
for match in self.get_matching_blocks():
a, b, size = match
length += self._text_length(self.a[a:a+size])
return length | def match_length(self):
""" Find the total length of all words that match between the two sequences."""
length = 0
for match in self.get_matching_blocks():
a, b, size = match
length += self._text_length(self.a[a:a+size])
return length | [
"Find",
"the",
"total",
"length",
"of",
"all",
"words",
"that",
"match",
"between",
"the",
"two",
"sequences",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/text.py#L140-L146 | [
"def",
"match_length",
"(",
"self",
")",
":",
"length",
"=",
"0",
"for",
"match",
"in",
"self",
".",
"get_matching_blocks",
"(",
")",
":",
"a",
",",
"b",
",",
"size",
"=",
"match",
"length",
"+=",
"self",
".",
"_text_length",
"(",
"self",
".",
"a",
... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | EditScriptRunner.run_edit_script | Run an xml edit script, and return the new html produced. | htmltreediff/edit_script_runner.py | def run_edit_script(self):
"""
Run an xml edit script, and return the new html produced.
"""
for action, location, properties in self.edit_script:
if action == 'delete':
node = get_location(self.dom, location)
self.action_delete(node)
... | def run_edit_script(self):
"""
Run an xml edit script, and return the new html produced.
"""
for action, location, properties in self.edit_script:
if action == 'delete':
node = get_location(self.dom, location)
self.action_delete(node)
... | [
"Run",
"an",
"xml",
"edit",
"script",
"and",
"return",
"the",
"new",
"html",
"produced",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/edit_script_runner.py#L48-L60 | [
"def",
"run_edit_script",
"(",
"self",
")",
":",
"for",
"action",
",",
"location",
",",
"properties",
"in",
"self",
".",
"edit_script",
":",
"if",
"action",
"==",
"'delete'",
":",
"node",
"=",
"get_location",
"(",
"self",
".",
"dom",
",",
"location",
")"... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | add_changes_markup | Add <ins> and <del> tags to the dom to show changes. | htmltreediff/changes.py | def add_changes_markup(dom, ins_nodes, del_nodes):
"""
Add <ins> and <del> tags to the dom to show changes.
"""
# add markup for inserted and deleted sections
for node in reversed(del_nodes):
# diff algorithm deletes nodes in reverse order, so un-reverse the
# order for this iteratio... | def add_changes_markup(dom, ins_nodes, del_nodes):
"""
Add <ins> and <del> tags to the dom to show changes.
"""
# add markup for inserted and deleted sections
for node in reversed(del_nodes):
# diff algorithm deletes nodes in reverse order, so un-reverse the
# order for this iteratio... | [
"Add",
"<ins",
">",
"and",
"<del",
">",
"tags",
"to",
"the",
"dom",
"to",
"show",
"changes",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/changes.py#L48-L65 | [
"def",
"add_changes_markup",
"(",
"dom",
",",
"ins_nodes",
",",
"del_nodes",
")",
":",
"# add markup for inserted and deleted sections",
"for",
"node",
"in",
"reversed",
"(",
"del_nodes",
")",
":",
"# diff algorithm deletes nodes in reverse order, so un-reverse the",
"# order... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | remove_nesting | Unwrap items in the node list that have ancestors with the same tag. | htmltreediff/changes.py | def remove_nesting(dom, tag_name):
"""
Unwrap items in the node list that have ancestors with the same tag.
"""
for node in dom.getElementsByTagName(tag_name):
for ancestor in ancestors(node):
if ancestor is node:
continue
if ancestor is dom.documentElemen... | def remove_nesting(dom, tag_name):
"""
Unwrap items in the node list that have ancestors with the same tag.
"""
for node in dom.getElementsByTagName(tag_name):
for ancestor in ancestors(node):
if ancestor is node:
continue
if ancestor is dom.documentElemen... | [
"Unwrap",
"items",
"in",
"the",
"node",
"list",
"that",
"have",
"ancestors",
"with",
"the",
"same",
"tag",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/changes.py#L67-L79 | [
"def",
"remove_nesting",
"(",
"dom",
",",
"tag_name",
")",
":",
"for",
"node",
"in",
"dom",
".",
"getElementsByTagName",
"(",
"tag_name",
")",
":",
"for",
"ancestor",
"in",
"ancestors",
"(",
"node",
")",
":",
"if",
"ancestor",
"is",
"node",
":",
"continu... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | sort_nodes | Sort the nodes of the dom in-place, based on a comparison function. | htmltreediff/changes.py | def sort_nodes(dom, cmp_func):
"""
Sort the nodes of the dom in-place, based on a comparison function.
"""
dom.normalize()
for node in list(walk_dom(dom, elements_only=True)):
prev_sib = node.previousSibling
while prev_sib and cmp_func(prev_sib, node) == 1:
node.parentNod... | def sort_nodes(dom, cmp_func):
"""
Sort the nodes of the dom in-place, based on a comparison function.
"""
dom.normalize()
for node in list(walk_dom(dom, elements_only=True)):
prev_sib = node.previousSibling
while prev_sib and cmp_func(prev_sib, node) == 1:
node.parentNod... | [
"Sort",
"the",
"nodes",
"of",
"the",
"dom",
"in",
"-",
"place",
"based",
"on",
"a",
"comparison",
"function",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/changes.py#L81-L90 | [
"def",
"sort_nodes",
"(",
"dom",
",",
"cmp_func",
")",
":",
"dom",
".",
"normalize",
"(",
")",
"for",
"node",
"in",
"list",
"(",
"walk_dom",
"(",
"dom",
",",
"elements_only",
"=",
"True",
")",
")",
":",
"prev_sib",
"=",
"node",
".",
"previousSibling",
... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | merge_adjacent | Merge all adjacent tags with the specified tag name.
Return the number of merges performed. | htmltreediff/changes.py | def merge_adjacent(dom, tag_name):
"""
Merge all adjacent tags with the specified tag name.
Return the number of merges performed.
"""
for node in dom.getElementsByTagName(tag_name):
prev_sib = node.previousSibling
if prev_sib and prev_sib.nodeName == node.tagName:
for ch... | def merge_adjacent(dom, tag_name):
"""
Merge all adjacent tags with the specified tag name.
Return the number of merges performed.
"""
for node in dom.getElementsByTagName(tag_name):
prev_sib = node.previousSibling
if prev_sib and prev_sib.nodeName == node.tagName:
for ch... | [
"Merge",
"all",
"adjacent",
"tags",
"with",
"the",
"specified",
"tag",
"name",
".",
"Return",
"the",
"number",
"of",
"merges",
"performed",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/changes.py#L104-L114 | [
"def",
"merge_adjacent",
"(",
"dom",
",",
"tag_name",
")",
":",
"for",
"node",
"in",
"dom",
".",
"getElementsByTagName",
"(",
"tag_name",
")",
":",
"prev_sib",
"=",
"node",
".",
"previousSibling",
"if",
"prev_sib",
"and",
"prev_sib",
".",
"nodeName",
"==",
... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | distribute | Wrap a copy of the given element around the contents of each of its
children, removing the node in the process. | htmltreediff/changes.py | def distribute(node):
"""
Wrap a copy of the given element around the contents of each of its
children, removing the node in the process.
"""
children = list(c for c in node.childNodes if is_element(c))
unwrap(node)
tag_name = node.tagName
for c in children:
wrap_inner(c, tag_nam... | def distribute(node):
"""
Wrap a copy of the given element around the contents of each of its
children, removing the node in the process.
"""
children = list(c for c in node.childNodes if is_element(c))
unwrap(node)
tag_name = node.tagName
for c in children:
wrap_inner(c, tag_nam... | [
"Wrap",
"a",
"copy",
"of",
"the",
"given",
"element",
"around",
"the",
"contents",
"of",
"each",
"of",
"its",
"children",
"removing",
"the",
"node",
"in",
"the",
"process",
"."
] | christian-oudard/htmltreediff | python | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/changes.py#L116-L125 | [
"def",
"distribute",
"(",
"node",
")",
":",
"children",
"=",
"list",
"(",
"c",
"for",
"c",
"in",
"node",
".",
"childNodes",
"if",
"is_element",
"(",
"c",
")",
")",
"unwrap",
"(",
"node",
")",
"tag_name",
"=",
"node",
".",
"tagName",
"for",
"c",
"in... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d |
train | SingletonModel.save | Save object to the database. Removes all other entries if there
are any. | background_image/models.py | def save(self, *args, **kwargs):
"""
Save object to the database. Removes all other entries if there
are any.
"""
self.__class__.objects.exclude(id=self.id).delete()
super(SingletonModel, self).save(*args, **kwargs) | def save(self, *args, **kwargs):
"""
Save object to the database. Removes all other entries if there
are any.
"""
self.__class__.objects.exclude(id=self.id).delete()
super(SingletonModel, self).save(*args, **kwargs) | [
"Save",
"object",
"to",
"the",
"database",
".",
"Removes",
"all",
"other",
"entries",
"if",
"there",
"are",
"any",
"."
] | arteria/django-background-image | python | https://github.com/arteria/django-background-image/blob/30d2c80512bfde0aaf927bde84a50a20e089cd9c/background_image/models.py#L22-L28 | [
"def",
"save",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"__class__",
".",
"objects",
".",
"exclude",
"(",
"id",
"=",
"self",
".",
"id",
")",
".",
"delete",
"(",
")",
"super",
"(",
"SingletonModel",
",",
"self... | 30d2c80512bfde0aaf927bde84a50a20e089cd9c |
train | get_magicc_region_to_openscm_region_mapping | Get the mappings from MAGICC to OpenSCM regions.
This is not a pure inverse of the other way around. For example, we never provide
"GLOBAL" as a MAGICC return value because it's unnecesarily confusing when we also
have "World". Fortunately MAGICC doesn't ever read the name "GLOBAL" so this
shouldn't ma... | pymagicc/definitions/__init__.py | def get_magicc_region_to_openscm_region_mapping(inverse=False):
"""Get the mappings from MAGICC to OpenSCM regions.
This is not a pure inverse of the other way around. For example, we never provide
"GLOBAL" as a MAGICC return value because it's unnecesarily confusing when we also
have "World". Fortunat... | def get_magicc_region_to_openscm_region_mapping(inverse=False):
"""Get the mappings from MAGICC to OpenSCM regions.
This is not a pure inverse of the other way around. For example, we never provide
"GLOBAL" as a MAGICC return value because it's unnecesarily confusing when we also
have "World". Fortunat... | [
"Get",
"the",
"mappings",
"from",
"MAGICC",
"to",
"OpenSCM",
"regions",
"."
] | openclimatedata/pymagicc | python | https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L80-L158 | [
"def",
"get_magicc_region_to_openscm_region_mapping",
"(",
"inverse",
"=",
"False",
")",
":",
"def",
"get_openscm_replacement",
"(",
"in_region",
")",
":",
"world",
"=",
"\"World\"",
"if",
"in_region",
"in",
"(",
"\"WORLD\"",
",",
"\"GLOBAL\"",
")",
":",
"return",... | d896014832cf458d1e95e5878fd6d5961f3e2e05 |
train | convert_magicc_to_openscm_regions | Convert MAGICC regions to OpenSCM regions
Parameters
----------
regions : list_like, str
Regions to convert
inverse : bool
If True, convert the other way i.e. convert OpenSCM regions to MAGICC7
regions
Returns
-------
``type(regions)``
Set of converted regi... | pymagicc/definitions/__init__.py | def convert_magicc_to_openscm_regions(regions, inverse=False):
"""
Convert MAGICC regions to OpenSCM regions
Parameters
----------
regions : list_like, str
Regions to convert
inverse : bool
If True, convert the other way i.e. convert OpenSCM regions to MAGICC7
regions
... | def convert_magicc_to_openscm_regions(regions, inverse=False):
"""
Convert MAGICC regions to OpenSCM regions
Parameters
----------
regions : list_like, str
Regions to convert
inverse : bool
If True, convert the other way i.e. convert OpenSCM regions to MAGICC7
regions
... | [
"Convert",
"MAGICC",
"regions",
"to",
"OpenSCM",
"regions"
] | openclimatedata/pymagicc | python | https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L188-L209 | [
"def",
"convert_magicc_to_openscm_regions",
"(",
"regions",
",",
"inverse",
"=",
"False",
")",
":",
"if",
"isinstance",
"(",
"regions",
",",
"(",
"list",
",",
"pd",
".",
"Index",
")",
")",
":",
"return",
"[",
"_apply_convert_magicc_to_openscm_regions",
"(",
"r... | d896014832cf458d1e95e5878fd6d5961f3e2e05 |
train | get_magicc7_to_openscm_variable_mapping | Get the mappings from MAGICC7 to OpenSCM variables.
Parameters
----------
inverse : bool
If True, return the inverse mappings i.e. OpenSCM to MAGICC7 mappings
Returns
-------
dict
Dictionary of mappings | pymagicc/definitions/__init__.py | def get_magicc7_to_openscm_variable_mapping(inverse=False):
"""Get the mappings from MAGICC7 to OpenSCM variables.
Parameters
----------
inverse : bool
If True, return the inverse mappings i.e. OpenSCM to MAGICC7 mappings
Returns
-------
dict
Dictionary of mappings
"""
... | def get_magicc7_to_openscm_variable_mapping(inverse=False):
"""Get the mappings from MAGICC7 to OpenSCM variables.
Parameters
----------
inverse : bool
If True, return the inverse mappings i.e. OpenSCM to MAGICC7 mappings
Returns
-------
dict
Dictionary of mappings
"""
... | [
"Get",
"the",
"mappings",
"from",
"MAGICC7",
"to",
"OpenSCM",
"variables",
"."
] | openclimatedata/pymagicc | python | https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L212-L369 | [
"def",
"get_magicc7_to_openscm_variable_mapping",
"(",
"inverse",
"=",
"False",
")",
":",
"def",
"get_openscm_replacement",
"(",
"in_var",
")",
":",
"if",
"in_var",
".",
"endswith",
"(",
"\"_INVERSE_EMIS\"",
")",
":",
"prefix",
"=",
"\"Inverse Emissions\"",
"elif",
... | d896014832cf458d1e95e5878fd6d5961f3e2e05 |
train | convert_magicc7_to_openscm_variables | Convert MAGICC7 variables to OpenSCM variables
Parameters
----------
variables : list_like, str
Variables to convert
inverse : bool
If True, convert the other way i.e. convert OpenSCM variables to MAGICC7
variables
Returns
-------
``type(variables)``
Set of... | pymagicc/definitions/__init__.py | def convert_magicc7_to_openscm_variables(variables, inverse=False):
"""
Convert MAGICC7 variables to OpenSCM variables
Parameters
----------
variables : list_like, str
Variables to convert
inverse : bool
If True, convert the other way i.e. convert OpenSCM variables to MAGICC7
... | def convert_magicc7_to_openscm_variables(variables, inverse=False):
"""
Convert MAGICC7 variables to OpenSCM variables
Parameters
----------
variables : list_like, str
Variables to convert
inverse : bool
If True, convert the other way i.e. convert OpenSCM variables to MAGICC7
... | [
"Convert",
"MAGICC7",
"variables",
"to",
"OpenSCM",
"variables"
] | openclimatedata/pymagicc | python | https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L400-L423 | [
"def",
"convert_magicc7_to_openscm_variables",
"(",
"variables",
",",
"inverse",
"=",
"False",
")",
":",
"if",
"isinstance",
"(",
"variables",
",",
"(",
"list",
",",
"pd",
".",
"Index",
")",
")",
":",
"return",
"[",
"_apply_convert_magicc7_to_openscm_variables",
... | d896014832cf458d1e95e5878fd6d5961f3e2e05 |
train | get_magicc6_to_magicc7_variable_mapping | Get the mappings from MAGICC6 to MAGICC7 variables.
Note that this mapping is not one to one. For example, "HFC4310", "HFC43-10" and
"HFC-43-10" in MAGICC6 both map to "HFC4310" in MAGICC7 but "HFC4310" in
MAGICC7 maps back to "HFC4310".
Note that HFC-245fa was mistakenly labelled as HFC-245ca in MAGI... | pymagicc/definitions/__init__.py | def get_magicc6_to_magicc7_variable_mapping(inverse=False):
"""Get the mappings from MAGICC6 to MAGICC7 variables.
Note that this mapping is not one to one. For example, "HFC4310", "HFC43-10" and
"HFC-43-10" in MAGICC6 both map to "HFC4310" in MAGICC7 but "HFC4310" in
MAGICC7 maps back to "HFC4310".
... | def get_magicc6_to_magicc7_variable_mapping(inverse=False):
"""Get the mappings from MAGICC6 to MAGICC7 variables.
Note that this mapping is not one to one. For example, "HFC4310", "HFC43-10" and
"HFC-43-10" in MAGICC6 both map to "HFC4310" in MAGICC7 but "HFC4310" in
MAGICC7 maps back to "HFC4310".
... | [
"Get",
"the",
"mappings",
"from",
"MAGICC6",
"to",
"MAGICC7",
"variables",
"."
] | openclimatedata/pymagicc | python | https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L426-L562 | [
"def",
"get_magicc6_to_magicc7_variable_mapping",
"(",
"inverse",
"=",
"False",
")",
":",
"# we generate the mapping dynamically, the first name in the list",
"# is the one which will be used for inverse mappings",
"magicc6_simple_mapping_vars",
"=",
"[",
"\"KYOTO-CO2EQ\"",
",",
"\"CO2... | d896014832cf458d1e95e5878fd6d5961f3e2e05 |
train | convert_magicc6_to_magicc7_variables | Convert MAGICC6 variables to MAGICC7 variables
Parameters
----------
variables : list_like, str
Variables to convert
inverse : bool
If True, convert the other way i.e. convert MAGICC7 variables to MAGICC6
variables
Raises
------
ValueError
If you try to con... | pymagicc/definitions/__init__.py | def convert_magicc6_to_magicc7_variables(variables, inverse=False):
"""
Convert MAGICC6 variables to MAGICC7 variables
Parameters
----------
variables : list_like, str
Variables to convert
inverse : bool
If True, convert the other way i.e. convert MAGICC7 variables to MAGICC6
... | def convert_magicc6_to_magicc7_variables(variables, inverse=False):
"""
Convert MAGICC6 variables to MAGICC7 variables
Parameters
----------
variables : list_like, str
Variables to convert
inverse : bool
If True, convert the other way i.e. convert MAGICC7 variables to MAGICC6
... | [
"Convert",
"MAGICC6",
"variables",
"to",
"MAGICC7",
"variables"
] | openclimatedata/pymagicc | python | https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L604-L636 | [
"def",
"convert_magicc6_to_magicc7_variables",
"(",
"variables",
",",
"inverse",
"=",
"False",
")",
":",
"if",
"isinstance",
"(",
"variables",
",",
"(",
"list",
",",
"pd",
".",
"Index",
")",
")",
":",
"return",
"[",
"_apply_convert_magicc6_to_magicc7_variables",
... | d896014832cf458d1e95e5878fd6d5961f3e2e05 |
train | get_pint_to_fortran_safe_units_mapping | Get the mappings from Pint to Fortran safe units.
Fortran can't handle special characters like "^" or "/" in names, but we need
these in Pint. Conversely, Pint stores variables with spaces by default e.g. "Mt
CO2 / yr" but we don't want these in the input files as Fortran is likely to think
the whitesp... | pymagicc/definitions/__init__.py | def get_pint_to_fortran_safe_units_mapping(inverse=False):
"""Get the mappings from Pint to Fortran safe units.
Fortran can't handle special characters like "^" or "/" in names, but we need
these in Pint. Conversely, Pint stores variables with spaces by default e.g. "Mt
CO2 / yr" but we don't want thes... | def get_pint_to_fortran_safe_units_mapping(inverse=False):
"""Get the mappings from Pint to Fortran safe units.
Fortran can't handle special characters like "^" or "/" in names, but we need
these in Pint. Conversely, Pint stores variables with spaces by default e.g. "Mt
CO2 / yr" but we don't want thes... | [
"Get",
"the",
"mappings",
"from",
"Pint",
"to",
"Fortran",
"safe",
"units",
"."
] | openclimatedata/pymagicc | python | https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L639-L664 | [
"def",
"get_pint_to_fortran_safe_units_mapping",
"(",
"inverse",
"=",
"False",
")",
":",
"replacements",
"=",
"{",
"\"^\"",
":",
"\"super\"",
",",
"\"/\"",
":",
"\"per\"",
",",
"\" \"",
":",
"\"\"",
"}",
"if",
"inverse",
":",
"replacements",
"=",
"{",
"v",
... | d896014832cf458d1e95e5878fd6d5961f3e2e05 |
train | convert_pint_to_fortran_safe_units | Convert Pint units to Fortran safe units
Parameters
----------
units : list_like, str
Units to convert
inverse : bool
If True, convert the other way i.e. convert Fortran safe units to Pint units
Returns
-------
``type(units)``
Set of converted units | pymagicc/definitions/__init__.py | def convert_pint_to_fortran_safe_units(units, inverse=False):
"""
Convert Pint units to Fortran safe units
Parameters
----------
units : list_like, str
Units to convert
inverse : bool
If True, convert the other way i.e. convert Fortran safe units to Pint units
Returns
... | def convert_pint_to_fortran_safe_units(units, inverse=False):
"""
Convert Pint units to Fortran safe units
Parameters
----------
units : list_like, str
Units to convert
inverse : bool
If True, convert the other way i.e. convert Fortran safe units to Pint units
Returns
... | [
"Convert",
"Pint",
"units",
"to",
"Fortran",
"safe",
"units"
] | openclimatedata/pymagicc | python | https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L678-L698 | [
"def",
"convert_pint_to_fortran_safe_units",
"(",
"units",
",",
"inverse",
"=",
"False",
")",
":",
"if",
"inverse",
":",
"return",
"apply_string_substitutions",
"(",
"units",
",",
"FORTRAN_SAFE_TO_PINT_UNITS_MAPPING",
")",
"else",
":",
"return",
"apply_string_substituti... | d896014832cf458d1e95e5878fd6d5961f3e2e05 |
train | Field.run_evaluate | Overrides the base evaluation to set the value to the evaluation result of the value
expression in the schema | blurr/core/field.py | def run_evaluate(self) -> None:
"""
Overrides the base evaluation to set the value to the evaluation result of the value
expression in the schema
"""
result = None
self.eval_error = False
if self._needs_evaluation:
result = self._schema.value.evaluate(... | def run_evaluate(self) -> None:
"""
Overrides the base evaluation to set the value to the evaluation result of the value
expression in the schema
"""
result = None
self.eval_error = False
if self._needs_evaluation:
result = self._schema.value.evaluate(... | [
"Overrides",
"the",
"base",
"evaluation",
"to",
"set",
"the",
"value",
"to",
"the",
"evaluation",
"result",
"of",
"the",
"value",
"expression",
"in",
"the",
"schema"
] | productml/blurr | python | https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/field.py#L90-L124 | [
"def",
"run_evaluate",
"(",
"self",
")",
"->",
"None",
":",
"result",
"=",
"None",
"self",
".",
"eval_error",
"=",
"False",
"if",
"self",
".",
"_needs_evaluation",
":",
"result",
"=",
"self",
".",
"_schema",
".",
"value",
".",
"evaluate",
"(",
"self",
... | 1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa |
train | Map.set | Sets the value of a key to a supplied value | blurr/core/field_complex.py | def set(self, key: Any, value: Any) -> None:
""" Sets the value of a key to a supplied value """
if key is not None:
self[key] = value | def set(self, key: Any, value: Any) -> None:
""" Sets the value of a key to a supplied value """
if key is not None:
self[key] = value | [
"Sets",
"the",
"value",
"of",
"a",
"key",
"to",
"a",
"supplied",
"value"
] | productml/blurr | python | https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/field_complex.py#L11-L14 | [
"def",
"set",
"(",
"self",
",",
"key",
":",
"Any",
",",
"value",
":",
"Any",
")",
"->",
"None",
":",
"if",
"key",
"is",
"not",
"None",
":",
"self",
"[",
"key",
"]",
"=",
"value"
] | 1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa |
train | Map.increment | Increments the value set against a key. If the key is not present, 0 is assumed as the initial state | blurr/core/field_complex.py | def increment(self, key: Any, by: int = 1) -> None:
""" Increments the value set against a key. If the key is not present, 0 is assumed as the initial state """
if key is not None:
self[key] = self.get(key, 0) + by | def increment(self, key: Any, by: int = 1) -> None:
""" Increments the value set against a key. If the key is not present, 0 is assumed as the initial state """
if key is not None:
self[key] = self.get(key, 0) + by | [
"Increments",
"the",
"value",
"set",
"against",
"a",
"key",
".",
"If",
"the",
"key",
"is",
"not",
"present",
"0",
"is",
"assumed",
"as",
"the",
"initial",
"state"
] | productml/blurr | python | https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/field_complex.py#L16-L19 | [
"def",
"increment",
"(",
"self",
",",
"key",
":",
"Any",
",",
"by",
":",
"int",
"=",
"1",
")",
"->",
"None",
":",
"if",
"key",
"is",
"not",
"None",
":",
"self",
"[",
"key",
"]",
"=",
"self",
".",
"get",
"(",
"key",
",",
"0",
")",
"+",
"by"
... | 1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa |
train | List.insert | Inserts an item to the list as long as it is not None | blurr/core/field_complex.py | def insert(self, index: int, obj: Any) -> None:
""" Inserts an item to the list as long as it is not None """
if obj is not None:
super().insert(index, obj) | def insert(self, index: int, obj: Any) -> None:
""" Inserts an item to the list as long as it is not None """
if obj is not None:
super().insert(index, obj) | [
"Inserts",
"an",
"item",
"to",
"the",
"list",
"as",
"long",
"as",
"it",
"is",
"not",
"None"
] | productml/blurr | python | https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/field_complex.py#L42-L45 | [
"def",
"insert",
"(",
"self",
",",
"index",
":",
"int",
",",
"obj",
":",
"Any",
")",
"->",
"None",
":",
"if",
"obj",
"is",
"not",
"None",
":",
"super",
"(",
")",
".",
"insert",
"(",
"index",
",",
"obj",
")"
] | 1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa |
train | get_dattype_regionmode | Get the THISFILE_DATTYPE and THISFILE_REGIONMODE flags for a given region set.
In all MAGICC input files, there are two flags: THISFILE_DATTYPE and
THISFILE_REGIONMODE. These tell MAGICC how to read in a given input file. This
function maps the regions which are in a given file to the value of these flags
... | pymagicc/io.py | def get_dattype_regionmode(regions, scen7=False):
"""
Get the THISFILE_DATTYPE and THISFILE_REGIONMODE flags for a given region set.
In all MAGICC input files, there are two flags: THISFILE_DATTYPE and
THISFILE_REGIONMODE. These tell MAGICC how to read in a given input file. This
function maps the ... | def get_dattype_regionmode(regions, scen7=False):
"""
Get the THISFILE_DATTYPE and THISFILE_REGIONMODE flags for a given region set.
In all MAGICC input files, there are two flags: THISFILE_DATTYPE and
THISFILE_REGIONMODE. These tell MAGICC how to read in a given input file. This
function maps the ... | [
"Get",
"the",
"THISFILE_DATTYPE",
"and",
"THISFILE_REGIONMODE",
"flags",
"for",
"a",
"given",
"region",
"set",
"."
] | openclimatedata/pymagicc | python | https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L1131-L1165 | [
"def",
"get_dattype_regionmode",
"(",
"regions",
",",
"scen7",
"=",
"False",
")",
":",
"dattype_flag",
"=",
"\"THISFILE_DATTYPE\"",
"regionmode_flag",
"=",
"\"THISFILE_REGIONMODE\"",
"region_dattype_row",
"=",
"_get_dattype_regionmode_regions_row",
"(",
"regions",
",",
"s... | d896014832cf458d1e95e5878fd6d5961f3e2e05 |
train | get_region_order | Get the region order expected by MAGICC.
Parameters
----------
regions : list_like
The regions to get THISFILE_DATTYPE and THISFILE_REGIONMODE flags for.
scen7 : bool, optional
Whether the file we are getting the flags for is a SCEN7 file or not.
Returns
-------
list
... | pymagicc/io.py | def get_region_order(regions, scen7=False):
"""
Get the region order expected by MAGICC.
Parameters
----------
regions : list_like
The regions to get THISFILE_DATTYPE and THISFILE_REGIONMODE flags for.
scen7 : bool, optional
Whether the file we are getting the flags for is a SC... | def get_region_order(regions, scen7=False):
"""
Get the region order expected by MAGICC.
Parameters
----------
regions : list_like
The regions to get THISFILE_DATTYPE and THISFILE_REGIONMODE flags for.
scen7 : bool, optional
Whether the file we are getting the flags for is a SC... | [
"Get",
"the",
"region",
"order",
"expected",
"by",
"MAGICC",
"."
] | openclimatedata/pymagicc | python | https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L1168-L1188 | [
"def",
"get_region_order",
"(",
"regions",
",",
"scen7",
"=",
"False",
")",
":",
"region_dattype_row",
"=",
"_get_dattype_regionmode_regions_row",
"(",
"regions",
",",
"scen7",
"=",
"scen7",
")",
"region_order",
"=",
"DATTYPE_REGIONMODE_REGIONS",
"[",
"\"regions\"",
... | d896014832cf458d1e95e5878fd6d5961f3e2e05 |
train | get_special_scen_code | Get special code for MAGICC6 SCEN files.
At the top of every MAGICC6 and MAGICC5 SCEN file there is a two digit
number. The first digit, the 'scenfile_region_code' tells MAGICC how many regions
data is being provided for. The second digit, the 'scenfile_emissions_code', tells
MAGICC which gases are in ... | pymagicc/io.py | def get_special_scen_code(regions, emissions):
"""
Get special code for MAGICC6 SCEN files.
At the top of every MAGICC6 and MAGICC5 SCEN file there is a two digit
number. The first digit, the 'scenfile_region_code' tells MAGICC how many regions
data is being provided for. The second digit, the 'sce... | def get_special_scen_code(regions, emissions):
"""
Get special code for MAGICC6 SCEN files.
At the top of every MAGICC6 and MAGICC5 SCEN file there is a two digit
number. The first digit, the 'scenfile_region_code' tells MAGICC how many regions
data is being provided for. The second digit, the 'sce... | [
"Get",
"special",
"code",
"for",
"MAGICC6",
"SCEN",
"files",
"."
] | openclimatedata/pymagicc | python | https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L1796-L1852 | [
"def",
"get_special_scen_code",
"(",
"regions",
",",
"emissions",
")",
":",
"if",
"sorted",
"(",
"set",
"(",
"PART_OF_SCENFILE_WITH_EMISSIONS_CODE_0",
")",
")",
"==",
"sorted",
"(",
"set",
"(",
"emissions",
")",
")",
":",
"scenfile_emissions_code",
"=",
"0",
"... | d896014832cf458d1e95e5878fd6d5961f3e2e05 |
train | determine_tool | Determine the tool to use for reading/writing.
The function uses an internally defined set of mappings between filepaths,
regular expresions and readers/writers to work out which tool to use
for a given task, given the filepath.
It is intended for internal use only, but is public because of its
im... | pymagicc/io.py | def determine_tool(filepath, tool_to_get):
"""
Determine the tool to use for reading/writing.
The function uses an internally defined set of mappings between filepaths,
regular expresions and readers/writers to work out which tool to use
for a given task, given the filepath.
It is intended for... | def determine_tool(filepath, tool_to_get):
"""
Determine the tool to use for reading/writing.
The function uses an internally defined set of mappings between filepaths,
regular expresions and readers/writers to work out which tool to use
for a given task, given the filepath.
It is intended for... | [
"Determine",
"the",
"tool",
"to",
"use",
"for",
"reading",
"/",
"writing",
"."
] | openclimatedata/pymagicc | python | https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2021-L2163 | [
"def",
"determine_tool",
"(",
"filepath",
",",
"tool_to_get",
")",
":",
"file_regexp_reader_writer",
"=",
"{",
"\"SCEN\"",
":",
"{",
"\"regexp\"",
":",
"r\"^.*\\.SCEN$\"",
",",
"\"reader\"",
":",
"_ScenReader",
",",
"\"writer\"",
":",
"_ScenWriter",
"}",
",",
"\... | d896014832cf458d1e95e5878fd6d5961f3e2e05 |
train | pull_cfg_from_parameters_out | Pull out a single config set from a parameters_out namelist.
This function returns a single file with the config that needs to be passed to
MAGICC in order to do the same run as is represented by the values in
``parameters_out``.
Parameters
----------
parameters_out : dict, f90nml.Namelist
... | pymagicc/io.py | def pull_cfg_from_parameters_out(parameters_out, namelist_to_read="nml_allcfgs"):
"""Pull out a single config set from a parameters_out namelist.
This function returns a single file with the config that needs to be passed to
MAGICC in order to do the same run as is represented by the values in
``parame... | def pull_cfg_from_parameters_out(parameters_out, namelist_to_read="nml_allcfgs"):
"""Pull out a single config set from a parameters_out namelist.
This function returns a single file with the config that needs to be passed to
MAGICC in order to do the same run as is represented by the values in
``parame... | [
"Pull",
"out",
"a",
"single",
"config",
"set",
"from",
"a",
"parameters_out",
"namelist",
"."
] | openclimatedata/pymagicc | python | https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2196-L2246 | [
"def",
"pull_cfg_from_parameters_out",
"(",
"parameters_out",
",",
"namelist_to_read",
"=",
"\"nml_allcfgs\"",
")",
":",
"single_cfg",
"=",
"Namelist",
"(",
"{",
"namelist_to_read",
":",
"{",
"}",
"}",
")",
"for",
"key",
",",
"value",
"in",
"parameters_out",
"["... | d896014832cf458d1e95e5878fd6d5961f3e2e05 |
train | pull_cfg_from_parameters_out_file | Pull out a single config set from a MAGICC ``PARAMETERS.OUT`` file.
This function reads in the ``PARAMETERS.OUT`` file and returns a single file with
the config that needs to be passed to MAGICC in order to do the same run as is
represented by the values in ``PARAMETERS.OUT``.
Parameters
---------... | pymagicc/io.py | def pull_cfg_from_parameters_out_file(
parameters_out_file, namelist_to_read="nml_allcfgs"
):
"""Pull out a single config set from a MAGICC ``PARAMETERS.OUT`` file.
This function reads in the ``PARAMETERS.OUT`` file and returns a single file with
the config that needs to be passed to MAGICC in order to... | def pull_cfg_from_parameters_out_file(
parameters_out_file, namelist_to_read="nml_allcfgs"
):
"""Pull out a single config set from a MAGICC ``PARAMETERS.OUT`` file.
This function reads in the ``PARAMETERS.OUT`` file and returns a single file with
the config that needs to be passed to MAGICC in order to... | [
"Pull",
"out",
"a",
"single",
"config",
"set",
"from",
"a",
"MAGICC",
"PARAMETERS",
".",
"OUT",
"file",
"."
] | openclimatedata/pymagicc | python | https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2249-L2279 | [
"def",
"pull_cfg_from_parameters_out_file",
"(",
"parameters_out_file",
",",
"namelist_to_read",
"=",
"\"nml_allcfgs\"",
")",
":",
"parameters_out",
"=",
"read_cfg_file",
"(",
"parameters_out_file",
")",
"return",
"pull_cfg_from_parameters_out",
"(",
"parameters_out",
",",
... | d896014832cf458d1e95e5878fd6d5961f3e2e05 |
train | get_generic_rcp_name | Convert an RCP name into the generic Pymagicc RCP name
The conversion is case insensitive.
Parameters
----------
inname : str
The name for which to get the generic Pymagicc RCP name
Returns
-------
str
The generic Pymagicc RCP name
Examples
--------
>>> get_ge... | pymagicc/io.py | def get_generic_rcp_name(inname):
"""Convert an RCP name into the generic Pymagicc RCP name
The conversion is case insensitive.
Parameters
----------
inname : str
The name for which to get the generic Pymagicc RCP name
Returns
-------
str
The generic Pymagicc RCP name
... | def get_generic_rcp_name(inname):
"""Convert an RCP name into the generic Pymagicc RCP name
The conversion is case insensitive.
Parameters
----------
inname : str
The name for which to get the generic Pymagicc RCP name
Returns
-------
str
The generic Pymagicc RCP name
... | [
"Convert",
"an",
"RCP",
"name",
"into",
"the",
"generic",
"Pymagicc",
"RCP",
"name"
] | openclimatedata/pymagicc | python | https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2282-L2315 | [
"def",
"get_generic_rcp_name",
"(",
"inname",
")",
":",
"# TODO: move into OpenSCM",
"mapping",
"=",
"{",
"\"rcp26\"",
":",
"\"rcp26\"",
",",
"\"rcp3pd\"",
":",
"\"rcp26\"",
",",
"\"rcp45\"",
":",
"\"rcp45\"",
",",
"\"rcp6\"",
":",
"\"rcp60\"",
",",
"\"rcp60\"",
... | d896014832cf458d1e95e5878fd6d5961f3e2e05 |
train | join_timeseries | Join two sets of timeseries
Parameters
----------
base : :obj:`MAGICCData`, :obj:`pd.DataFrame`, filepath
Base timeseries to use. If a filepath, the data will first be loaded from disk.
overwrite : :obj:`MAGICCData`, :obj:`pd.DataFrame`, filepath
Timeseries to join onto base. Any point... | pymagicc/io.py | def join_timeseries(base, overwrite, join_linear=None):
"""Join two sets of timeseries
Parameters
----------
base : :obj:`MAGICCData`, :obj:`pd.DataFrame`, filepath
Base timeseries to use. If a filepath, the data will first be loaded from disk.
overwrite : :obj:`MAGICCData`, :obj:`pd.DataF... | def join_timeseries(base, overwrite, join_linear=None):
"""Join two sets of timeseries
Parameters
----------
base : :obj:`MAGICCData`, :obj:`pd.DataFrame`, filepath
Base timeseries to use. If a filepath, the data will first be loaded from disk.
overwrite : :obj:`MAGICCData`, :obj:`pd.DataF... | [
"Join",
"two",
"sets",
"of",
"timeseries"
] | openclimatedata/pymagicc | python | https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2320-L2363 | [
"def",
"join_timeseries",
"(",
"base",
",",
"overwrite",
",",
"join_linear",
"=",
"None",
")",
":",
"if",
"join_linear",
"is",
"not",
"None",
":",
"if",
"len",
"(",
"join_linear",
")",
"!=",
"2",
":",
"raise",
"ValueError",
"(",
"\"join_linear must have a le... | d896014832cf458d1e95e5878fd6d5961f3e2e05 |
train | read_scen_file | Read a MAGICC .SCEN file.
Parameters
----------
filepath : str
Filepath of the .SCEN file to read
columns : dict
Passed to ``__init__`` method of MAGICCData. See
``MAGICCData.__init__`` for details.
kwargs
Passed to ``__init__`` method of MAGICCData. See
``... | pymagicc/io.py | def read_scen_file(
filepath,
columns={
"model": ["unspecified"],
"scenario": ["unspecified"],
"climate_model": ["unspecified"],
},
**kwargs
):
"""
Read a MAGICC .SCEN file.
Parameters
----------
filepath : str
Filepath of the .SCEN file to read
... | def read_scen_file(
filepath,
columns={
"model": ["unspecified"],
"scenario": ["unspecified"],
"climate_model": ["unspecified"],
},
**kwargs
):
"""
Read a MAGICC .SCEN file.
Parameters
----------
filepath : str
Filepath of the .SCEN file to read
... | [
"Read",
"a",
"MAGICC",
".",
"SCEN",
"file",
"."
] | openclimatedata/pymagicc | python | https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2431-L2463 | [
"def",
"read_scen_file",
"(",
"filepath",
",",
"columns",
"=",
"{",
"\"model\"",
":",
"[",
"\"unspecified\"",
"]",
",",
"\"scenario\"",
":",
"[",
"\"unspecified\"",
"]",
",",
"\"climate_model\"",
":",
"[",
"\"unspecified\"",
"]",
",",
"}",
",",
"*",
"*",
"... | d896014832cf458d1e95e5878fd6d5961f3e2e05 |
train | _get_openscm_var_from_filepath | Determine the OpenSCM variable from a filepath.
Uses MAGICC's internal, implicit, filenaming conventions.
Parameters
----------
filepath : str
Filepath from which to determine the OpenSCM variable.
Returns
-------
str
The OpenSCM variable implied by the filepath. | pymagicc/io.py | def _get_openscm_var_from_filepath(filepath):
"""
Determine the OpenSCM variable from a filepath.
Uses MAGICC's internal, implicit, filenaming conventions.
Parameters
----------
filepath : str
Filepath from which to determine the OpenSCM variable.
Returns
-------
str
... | def _get_openscm_var_from_filepath(filepath):
"""
Determine the OpenSCM variable from a filepath.
Uses MAGICC's internal, implicit, filenaming conventions.
Parameters
----------
filepath : str
Filepath from which to determine the OpenSCM variable.
Returns
-------
str
... | [
"Determine",
"the",
"OpenSCM",
"variable",
"from",
"a",
"filepath",
"."
] | openclimatedata/pymagicc | python | https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2466-L2487 | [
"def",
"_get_openscm_var_from_filepath",
"(",
"filepath",
")",
":",
"reader",
"=",
"determine_tool",
"(",
"filepath",
",",
"\"reader\"",
")",
"(",
"filepath",
")",
"openscm_var",
"=",
"convert_magicc7_to_openscm_variables",
"(",
"convert_magicc6_to_magicc7_variables",
"("... | d896014832cf458d1e95e5878fd6d5961f3e2e05 |
train | _Reader._find_nml | Find the start and end of the embedded namelist.
Returns
-------
(int, int)
start and end index for the namelist | pymagicc/io.py | def _find_nml(self):
"""
Find the start and end of the embedded namelist.
Returns
-------
(int, int)
start and end index for the namelist
"""
nml_start = None
nml_end = None
for i in range(len(self.lines)):
if self.lines[i]... | def _find_nml(self):
"""
Find the start and end of the embedded namelist.
Returns
-------
(int, int)
start and end index for the namelist
"""
nml_start = None
nml_end = None
for i in range(len(self.lines)):
if self.lines[i]... | [
"Find",
"the",
"start",
"and",
"end",
"of",
"the",
"embedded",
"namelist",
"."
] | openclimatedata/pymagicc | python | https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L143-L163 | [
"def",
"_find_nml",
"(",
"self",
")",
":",
"nml_start",
"=",
"None",
"nml_end",
"=",
"None",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"self",
".",
"lines",
")",
")",
":",
"if",
"self",
".",
"lines",
"[",
"i",
"]",
".",
"strip",
"(",
")",
"."... | d896014832cf458d1e95e5878fd6d5961f3e2e05 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.