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 | ArffFile.alphabetize_attributes | Orders attributes names alphabetically, except for the class attribute, which is kept last. | weka/arff.py | def alphabetize_attributes(self):
"""
Orders attributes names alphabetically, except for the class attribute, which is kept last.
"""
self.attributes.sort(key=lambda name: (name == self.class_attr_name, name)) | def alphabetize_attributes(self):
"""
Orders attributes names alphabetically, except for the class attribute, which is kept last.
"""
self.attributes.sort(key=lambda name: (name == self.class_attr_name, name)) | [
"Orders",
"attributes",
"names",
"alphabetically",
"except",
"for",
"the",
"class",
"attribute",
"which",
"is",
"kept",
"last",
"."
] | chrisspen/weka | python | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L746-L750 | [
"def",
"alphabetize_attributes",
"(",
"self",
")",
":",
"self",
".",
"attributes",
".",
"sort",
"(",
"key",
"=",
"lambda",
"name",
":",
"(",
"name",
"==",
"self",
".",
"class_attr_name",
",",
"name",
")",
")"
] | c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b |
train | rgb_to_hsl | Convert the color from RGB coordinates to HSL.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (h, s, l) tuple in the range:
h[0...360],
s[0...1],
l[0...1]
>>> rgb_t... | grapefruit.py | def rgb_to_hsl(r, g=None, b=None):
"""Convert the color from RGB coordinates to HSL.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (h, s, l) tuple in the range:
h[0...360],... | def rgb_to_hsl(r, g=None, b=None):
"""Convert the color from RGB coordinates to HSL.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (h, s, l) tuple in the range:
h[0...360],... | [
"Convert",
"the",
"color",
"from",
"RGB",
"coordinates",
"to",
"HSL",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L249-L295 | [
"def",
"rgb_to_hsl",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"minVal",
"=",
"min",
"(",
"r",
",",
"g",
... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | hsl_to_rgb | Convert the color from HSL coordinates to RGB.
Parameters:
:h:
The Hue component value [0...1]
:s:
The Saturation component value [0...1]
:l:
The Lightness component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
b[0...1]
>... | grapefruit.py | def hsl_to_rgb(h, s=None, l=None):
"""Convert the color from HSL coordinates to RGB.
Parameters:
:h:
The Hue component value [0...1]
:s:
The Saturation component value [0...1]
:l:
The Lightness component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r... | def hsl_to_rgb(h, s=None, l=None):
"""Convert the color from HSL coordinates to RGB.
Parameters:
:h:
The Hue component value [0...1]
:s:
The Saturation component value [0...1]
:l:
The Lightness component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r... | [
"Convert",
"the",
"color",
"from",
"HSL",
"coordinates",
"to",
"RGB",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L307-L344 | [
"def",
"hsl_to_rgb",
"(",
"h",
",",
"s",
"=",
"None",
",",
"l",
"=",
"None",
")",
":",
"if",
"type",
"(",
"h",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"h",
",",
"s",
",",
"l",
"=",
"h",
"if",
"s",
"==",
"0",
":",
"return",
"(",
... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | rgb_to_hsv | Convert the color from RGB coordinates to HSV.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (h, s, v) tuple in the range:
h[0...360],
s[0...1],
v[0...1]
>>> rgb_t... | grapefruit.py | def rgb_to_hsv(r, g=None, b=None):
"""Convert the color from RGB coordinates to HSV.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (h, s, v) tuple in the range:
h[0...360],... | def rgb_to_hsv(r, g=None, b=None):
"""Convert the color from RGB coordinates to HSV.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (h, s, v) tuple in the range:
h[0...360],... | [
"Convert",
"the",
"color",
"from",
"RGB",
"coordinates",
"to",
"HSV",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L346-L385 | [
"def",
"rgb_to_hsv",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"v",
"=",
"float",
"(",
"max",
"(",
"r",
"... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | hsv_to_rgb | Convert the color from RGB coordinates to HSV.
Parameters:
:h:
The Hus component value [0...1]
:s:
The Saturation component value [0...1]
:v:
The Value component [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
b[0...1]
>>> hsv_to_... | grapefruit.py | def hsv_to_rgb(h, s=None, v=None):
"""Convert the color from RGB coordinates to HSV.
Parameters:
:h:
The Hus component value [0...1]
:s:
The Saturation component value [0...1]
:v:
The Value component [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
... | def hsv_to_rgb(h, s=None, v=None):
"""Convert the color from RGB coordinates to HSV.
Parameters:
:h:
The Hus component value [0...1]
:s:
The Saturation component value [0...1]
:v:
The Value component [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
... | [
"Convert",
"the",
"color",
"from",
"RGB",
"coordinates",
"to",
"HSV",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L387-L428 | [
"def",
"hsv_to_rgb",
"(",
"h",
",",
"s",
"=",
"None",
",",
"v",
"=",
"None",
")",
":",
"if",
"type",
"(",
"h",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"h",
",",
"s",
",",
"v",
"=",
"h",
"if",
"s",
"==",
"0",
":",
"return",
"(",
... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | rgb_to_yiq | Convert the color from RGB to YIQ.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (y, i, q) tuple in the range:
y[0...1],
i[0...1],
q[0...1]
>>> '(%g, %g, %g)' % rg... | grapefruit.py | def rgb_to_yiq(r, g=None, b=None):
"""Convert the color from RGB to YIQ.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (y, i, q) tuple in the range:
y[0...1],
i[0...1],... | def rgb_to_yiq(r, g=None, b=None):
"""Convert the color from RGB to YIQ.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (y, i, q) tuple in the range:
y[0...1],
i[0...1],... | [
"Convert",
"the",
"color",
"from",
"RGB",
"to",
"YIQ",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L430-L457 | [
"def",
"rgb_to_yiq",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"y",
"=",
"(",
"r",
"*",
"0.29895808",
")",
... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | yiq_to_rgb | Convert the color from YIQ coordinates to RGB.
Parameters:
:y:
Tte Y component value [0...1]
:i:
The I component value [0...1]
:q:
The Q component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
b[0...1]
>>> '({}, {}, {})'.f... | grapefruit.py | def yiq_to_rgb(y, i=None, q=None):
"""Convert the color from YIQ coordinates to RGB.
Parameters:
:y:
Tte Y component value [0...1]
:i:
The I component value [0...1]
:q:
The Q component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...... | def yiq_to_rgb(y, i=None, q=None):
"""Convert the color from YIQ coordinates to RGB.
Parameters:
:y:
Tte Y component value [0...1]
:i:
The I component value [0...1]
:q:
The Q component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...... | [
"Convert",
"the",
"color",
"from",
"YIQ",
"coordinates",
"to",
"RGB",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L459-L485 | [
"def",
"yiq_to_rgb",
"(",
"y",
",",
"i",
"=",
"None",
",",
"q",
"=",
"None",
")",
":",
"if",
"type",
"(",
"y",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"y",
",",
"i",
",",
"q",
"=",
"y",
"r",
"=",
"y",
"+",
"(",
"i",
"*",
"0.9562... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | rgb_to_yuv | Convert the color from RGB coordinates to YUV.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (y, u, v) tuple in the range:
y[0...1],
u[-0.436...0.436],
v[-0.615...0.6... | grapefruit.py | def rgb_to_yuv(r, g=None, b=None):
"""Convert the color from RGB coordinates to YUV.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (y, u, v) tuple in the range:
y[0...1],
... | def rgb_to_yuv(r, g=None, b=None):
"""Convert the color from RGB coordinates to YUV.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (y, u, v) tuple in the range:
y[0...1],
... | [
"Convert",
"the",
"color",
"from",
"RGB",
"coordinates",
"to",
"YUV",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L487-L514 | [
"def",
"rgb_to_yuv",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"y",
"=",
"(",
"r",
"*",
"0.29900",
")",
"... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | yuv_to_rgb | Convert the color from YUV coordinates to RGB.
Parameters:
:y:
The Y component value [0...1]
:u:
The U component value [-0.436...0.436]
:v:
The V component value [-0.615...0.615]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
b[0...1]
>>... | grapefruit.py | def yuv_to_rgb(y, u=None, v=None):
"""Convert the color from YUV coordinates to RGB.
Parameters:
:y:
The Y component value [0...1]
:u:
The U component value [-0.436...0.436]
:v:
The V component value [-0.615...0.615]
Returns:
The color as an (r, g, b) tuple in the range:
r[... | def yuv_to_rgb(y, u=None, v=None):
"""Convert the color from YUV coordinates to RGB.
Parameters:
:y:
The Y component value [0...1]
:u:
The U component value [-0.436...0.436]
:v:
The V component value [-0.615...0.615]
Returns:
The color as an (r, g, b) tuple in the range:
r[... | [
"Convert",
"the",
"color",
"from",
"YUV",
"coordinates",
"to",
"RGB",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L516-L542 | [
"def",
"yuv_to_rgb",
"(",
"y",
",",
"u",
"=",
"None",
",",
"v",
"=",
"None",
")",
":",
"if",
"type",
"(",
"y",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"y",
",",
"u",
",",
"v",
"=",
"y",
"r",
"=",
"y",
"+",
"(",
"v",
"*",
"1.1398... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | rgb_to_xyz | Convert the color from sRGB to CIE XYZ.
The methods assumes that the RGB coordinates are given in the sRGB
colorspace (D65).
.. note::
Compensation for the sRGB gamma correction is applied before converting.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component val... | grapefruit.py | def rgb_to_xyz(r, g=None, b=None):
"""Convert the color from sRGB to CIE XYZ.
The methods assumes that the RGB coordinates are given in the sRGB
colorspace (D65).
.. note::
Compensation for the sRGB gamma correction is applied before converting.
Parameters:
:r:
The Red component value [0...... | def rgb_to_xyz(r, g=None, b=None):
"""Convert the color from sRGB to CIE XYZ.
The methods assumes that the RGB coordinates are given in the sRGB
colorspace (D65).
.. note::
Compensation for the sRGB gamma correction is applied before converting.
Parameters:
:r:
The Red component value [0...... | [
"Convert",
"the",
"color",
"from",
"sRGB",
"to",
"CIE",
"XYZ",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L544-L580 | [
"def",
"rgb_to_xyz",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"r",
",",
"g",
",",
"b",
"=",
"[",
"(",
... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | xyz_to_rgb | Convert the color from CIE XYZ coordinates to sRGB.
.. note::
Compensation for sRGB gamma correction is applied before converting.
Parameters:
:x:
The X component value [0...1]
:y:
The Y component value [0...1]
:z:
The Z component value [0...1]
Returns:
The color as an (... | grapefruit.py | def xyz_to_rgb(x, y=None, z=None):
"""Convert the color from CIE XYZ coordinates to sRGB.
.. note::
Compensation for sRGB gamma correction is applied before converting.
Parameters:
:x:
The X component value [0...1]
:y:
The Y component value [0...1]
:z:
The Z component value [... | def xyz_to_rgb(x, y=None, z=None):
"""Convert the color from CIE XYZ coordinates to sRGB.
.. note::
Compensation for sRGB gamma correction is applied before converting.
Parameters:
:x:
The X component value [0...1]
:y:
The Y component value [0...1]
:z:
The Z component value [... | [
"Convert",
"the",
"color",
"from",
"CIE",
"XYZ",
"coordinates",
"to",
"sRGB",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L582-L612 | [
"def",
"xyz_to_rgb",
"(",
"x",
",",
"y",
"=",
"None",
",",
"z",
"=",
"None",
")",
":",
"if",
"type",
"(",
"x",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"x",
",",
"y",
",",
"z",
"=",
"x",
"r",
"=",
"(",
"x",
"*",
"3.2406255",
")",
... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | xyz_to_lab | Convert the color from CIE XYZ to CIE L*a*b*.
Parameters:
:x:
The X component value [0...1]
:y:
The Y component value [0...1]
:z:
The Z component value [0...1]
:wref:
The whitepoint reference, default is 2° D65.
Returns:
The color as an (L, a, b) tuple in the range:
... | grapefruit.py | def xyz_to_lab(x, y=None, z=None, wref=_DEFAULT_WREF):
"""Convert the color from CIE XYZ to CIE L*a*b*.
Parameters:
:x:
The X component value [0...1]
:y:
The Y component value [0...1]
:z:
The Z component value [0...1]
:wref:
The whitepoint reference, default is 2° D65.
Re... | def xyz_to_lab(x, y=None, z=None, wref=_DEFAULT_WREF):
"""Convert the color from CIE XYZ to CIE L*a*b*.
Parameters:
:x:
The X component value [0...1]
:y:
The Y component value [0...1]
:z:
The Z component value [0...1]
:wref:
The whitepoint reference, default is 2° D65.
Re... | [
"Convert",
"the",
"color",
"from",
"CIE",
"XYZ",
"to",
"CIE",
"L",
"*",
"a",
"*",
"b",
"*",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L614-L655 | [
"def",
"xyz_to_lab",
"(",
"x",
",",
"y",
"=",
"None",
",",
"z",
"=",
"None",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"if",
"type",
"(",
"x",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"x",
",",
"y",
",",
"z",
"=",
"x",
"# White poin... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | lab_to_xyz | Convert the color from CIE L*a*b* to CIE 1931 XYZ.
Parameters:
:l:
The L component [0...100]
:a:
The a component [-1...1]
:b:
The a component [-1...1]
:wref:
The whitepoint reference, default is 2° D65.
Returns:
The color as an (x, y, z) tuple in the range:
x[0...q]... | grapefruit.py | def lab_to_xyz(l, a=None, b=None, wref=_DEFAULT_WREF):
"""Convert the color from CIE L*a*b* to CIE 1931 XYZ.
Parameters:
:l:
The L component [0...100]
:a:
The a component [-1...1]
:b:
The a component [-1...1]
:wref:
The whitepoint reference, default is 2° D65.
Returns:
... | def lab_to_xyz(l, a=None, b=None, wref=_DEFAULT_WREF):
"""Convert the color from CIE L*a*b* to CIE 1931 XYZ.
Parameters:
:l:
The L component [0...100]
:a:
The a component [-1...1]
:b:
The a component [-1...1]
:wref:
The whitepoint reference, default is 2° D65.
Returns:
... | [
"Convert",
"the",
"color",
"from",
"CIE",
"L",
"*",
"a",
"*",
"b",
"*",
"to",
"CIE",
"1931",
"XYZ",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L657-L688 | [
"def",
"lab_to_xyz",
"(",
"l",
",",
"a",
"=",
"None",
",",
"b",
"=",
"None",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"if",
"type",
"(",
"l",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"l",
",",
"a",
",",
"b",
"=",
"l",
"y",
"=",
... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | cmyk_to_cmy | Convert the color from CMYK coordinates to CMY.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:k:
The Black component value [0...1]
Returns:
The color as an (c, m, y) tuple in the range:
... | grapefruit.py | def cmyk_to_cmy(c, m=None, y=None, k=None):
"""Convert the color from CMYK coordinates to CMY.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:k:
The Black component value [0...1]
Returns:
... | def cmyk_to_cmy(c, m=None, y=None, k=None):
"""Convert the color from CMYK coordinates to CMY.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:k:
The Black component value [0...1]
Returns:
... | [
"Convert",
"the",
"color",
"from",
"CMYK",
"coordinates",
"to",
"CMY",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L690-L716 | [
"def",
"cmyk_to_cmy",
"(",
"c",
",",
"m",
"=",
"None",
",",
"y",
"=",
"None",
",",
"k",
"=",
"None",
")",
":",
"if",
"type",
"(",
"c",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"c",
",",
"m",
",",
"y",
",",
"k",
"=",
"c",
"mk",
"=... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | cmy_to_cmyk | Convert the color from CMY coordinates to CMYK.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
Returns:
The color as an (c, m, y, k) tuple in the range:
c[0...1],
m[0...1],
y[0...1],
... | grapefruit.py | def cmy_to_cmyk(c, m=None, y=None):
"""Convert the color from CMY coordinates to CMYK.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
Returns:
The color as an (c, m, y, k) tuple in the range:
c... | def cmy_to_cmyk(c, m=None, y=None):
"""Convert the color from CMY coordinates to CMYK.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
Returns:
The color as an (c, m, y, k) tuple in the range:
c... | [
"Convert",
"the",
"color",
"from",
"CMY",
"coordinates",
"to",
"CMYK",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L718-L745 | [
"def",
"cmy_to_cmyk",
"(",
"c",
",",
"m",
"=",
"None",
",",
"y",
"=",
"None",
")",
":",
"if",
"type",
"(",
"c",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"c",
",",
"m",
",",
"y",
"=",
"c",
"k",
"=",
"min",
"(",
"c",
",",
"m",
",",... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | rgb_to_cmy | Convert the color from RGB coordinates to CMY.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (c, m, y) tuple in the range:
c[0...1],
m[0...1],
y[0...1]
>>> rgb_to_... | grapefruit.py | def rgb_to_cmy(r, g=None, b=None):
"""Convert the color from RGB coordinates to CMY.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (c, m, y) tuple in the range:
c[0...1],
... | def rgb_to_cmy(r, g=None, b=None):
"""Convert the color from RGB coordinates to CMY.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (c, m, y) tuple in the range:
c[0...1],
... | [
"Convert",
"the",
"color",
"from",
"RGB",
"coordinates",
"to",
"CMY",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L747-L770 | [
"def",
"rgb_to_cmy",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"return",
"(",
"1",
"-",
"r",
",",
"1",
"-... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | cmy_to_rgb | Convert the color from CMY coordinates to RGB.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
b[0...1]
>>> cm... | grapefruit.py | def cmy_to_rgb(c, m=None, y=None):
"""Convert the color from CMY coordinates to RGB.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...... | def cmy_to_rgb(c, m=None, y=None):
"""Convert the color from CMY coordinates to RGB.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...... | [
"Convert",
"the",
"color",
"from",
"CMY",
"coordinates",
"to",
"RGB",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L772-L795 | [
"def",
"cmy_to_rgb",
"(",
"c",
",",
"m",
"=",
"None",
",",
"y",
"=",
"None",
")",
":",
"if",
"type",
"(",
"c",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"c",
",",
"m",
",",
"y",
"=",
"c",
"return",
"(",
"1",
"-",
"c",
",",
"1",
"-... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | rgb_to_ints | Convert the color in the standard [0...1] range to ints in the [0..255] range.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...255],
g[0... | grapefruit.py | def rgb_to_ints(r, g=None, b=None):
"""Convert the color in the standard [0...1] range to ints in the [0..255] range.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (r, g, b) tu... | def rgb_to_ints(r, g=None, b=None):
"""Convert the color in the standard [0...1] range to ints in the [0..255] range.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (r, g, b) tu... | [
"Convert",
"the",
"color",
"in",
"the",
"standard",
"[",
"0",
"...",
"1",
"]",
"range",
"to",
"ints",
"in",
"the",
"[",
"0",
"..",
"255",
"]",
"range",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L797-L820 | [
"def",
"rgb_to_ints",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"return",
"tuple",
"(",
"int",
"(",
"round",
... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | ints_to_rgb | Convert ints in the [0...255] range to the standard [0...1] range.
Parameters:
:r:
The Red component value [0...255]
:g:
The Green component value [0...255]
:b:
The Blue component value [0...255]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
... | grapefruit.py | def ints_to_rgb(r, g=None, b=None):
"""Convert ints in the [0...255] range to the standard [0...1] range.
Parameters:
:r:
The Red component value [0...255]
:g:
The Green component value [0...255]
:b:
The Blue component value [0...255]
Returns:
The color as an (r, g, b) tuple in... | def ints_to_rgb(r, g=None, b=None):
"""Convert ints in the [0...255] range to the standard [0...1] range.
Parameters:
:r:
The Red component value [0...255]
:g:
The Green component value [0...255]
:b:
The Blue component value [0...255]
Returns:
The color as an (r, g, b) tuple in... | [
"Convert",
"ints",
"in",
"the",
"[",
"0",
"...",
"255",
"]",
"range",
"to",
"the",
"standard",
"[",
"0",
"...",
"1",
"]",
"range",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L822-L845 | [
"def",
"ints_to_rgb",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"return",
"tuple",
"(",
"float",
"(",
"v",
... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | rgb_to_html | Convert the color from (r, g, b) to #RRGGBB.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
A CSS string representation of this color (#RRGGBB).
>>> rgb_to_html(1, 0.5, 0)
'#ff8000' | grapefruit.py | def rgb_to_html(r, g=None, b=None):
"""Convert the color from (r, g, b) to #RRGGBB.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
A CSS string representation of this color (#RRGGBB).
>>> rg... | def rgb_to_html(r, g=None, b=None):
"""Convert the color from (r, g, b) to #RRGGBB.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
A CSS string representation of this color (#RRGGBB).
>>> rg... | [
"Convert",
"the",
"color",
"from",
"(",
"r",
"g",
"b",
")",
"to",
"#RRGGBB",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L847-L867 | [
"def",
"rgb_to_html",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"return",
"'#%02x%02x%02x'",
"%",
"tuple",
"(",... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | html_to_rgb | Convert the HTML color to (r, g, b).
Parameters:
:html:
the HTML definition of the color (#RRGGBB or #RGB or a color name).
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
b[0...1]
Throws:
:ValueError:
If html is neither a known color name or a hex... | grapefruit.py | def html_to_rgb(html):
"""Convert the HTML color to (r, g, b).
Parameters:
:html:
the HTML definition of the color (#RRGGBB or #RGB or a color name).
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
b[0...1]
Throws:
:ValueError:
If html is neither... | def html_to_rgb(html):
"""Convert the HTML color to (r, g, b).
Parameters:
:html:
the HTML definition of the color (#RRGGBB or #RGB or a color name).
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
b[0...1]
Throws:
:ValueError:
If html is neither... | [
"Convert",
"the",
"HTML",
"color",
"to",
"(",
"r",
"g",
"b",
")",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L869-L912 | [
"def",
"html_to_rgb",
"(",
"html",
")",
":",
"html",
"=",
"html",
".",
"strip",
"(",
")",
".",
"lower",
"(",
")",
"if",
"html",
"[",
"0",
"]",
"==",
"'#'",
":",
"html",
"=",
"html",
"[",
"1",
":",
"]",
"elif",
"html",
"in",
"NAMED_COLOR",
":",
... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | rgb_to_pil | Convert the color from RGB to a PIL-compatible integer.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
A PIL compatible integer (0xBBGGRR).
>>> '0x%06x' % rgb_to_pil(1, 0.5, 0)
'0x0080ff' | grapefruit.py | def rgb_to_pil(r, g=None, b=None):
"""Convert the color from RGB to a PIL-compatible integer.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
A PIL compatible integer (0xBBGGRR).
>>> '0x%06x'... | def rgb_to_pil(r, g=None, b=None):
"""Convert the color from RGB to a PIL-compatible integer.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
A PIL compatible integer (0xBBGGRR).
>>> '0x%06x'... | [
"Convert",
"the",
"color",
"from",
"RGB",
"to",
"a",
"PIL",
"-",
"compatible",
"integer",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L914-L935 | [
"def",
"rgb_to_pil",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"r",
",",
"g",
",",
"b",
"=",
"[",
"min",
... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | pil_to_rgb | Convert the color from a PIL-compatible integer to RGB.
Parameters:
pil: a PIL compatible color representation (0xBBGGRR)
Returns:
The color as an (r, g, b) tuple in the range:
the range:
r: [0...1]
g: [0...1]
b: [0...1]
>>> '(%g, %g, %g)' % pil_to_rgb(0x0080ff)
'(1, 0.501961, 0)' | grapefruit.py | def pil_to_rgb(pil):
"""Convert the color from a PIL-compatible integer to RGB.
Parameters:
pil: a PIL compatible color representation (0xBBGGRR)
Returns:
The color as an (r, g, b) tuple in the range:
the range:
r: [0...1]
g: [0...1]
b: [0...1]
>>> '(%g, %g, %g)' % pil_to_rgb(0x0080ff)... | def pil_to_rgb(pil):
"""Convert the color from a PIL-compatible integer to RGB.
Parameters:
pil: a PIL compatible color representation (0xBBGGRR)
Returns:
The color as an (r, g, b) tuple in the range:
the range:
r: [0...1]
g: [0...1]
b: [0...1]
>>> '(%g, %g, %g)' % pil_to_rgb(0x0080ff)... | [
"Convert",
"the",
"color",
"from",
"a",
"PIL",
"-",
"compatible",
"integer",
"to",
"RGB",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L937-L956 | [
"def",
"pil_to_rgb",
"(",
"pil",
")",
":",
"r",
"=",
"0xff",
"&",
"pil",
"g",
"=",
"0xff",
"&",
"(",
"pil",
">>",
"8",
")",
"b",
"=",
"0xff",
"&",
"(",
"pil",
">>",
"16",
")",
"return",
"tuple",
"(",
"(",
"v",
"/",
"255.0",
"for",
"v",
"in"... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | _websafe_component | Convert a color component to its web safe equivalent.
Parameters:
:c:
The component value [0...1]
:alt:
If True, return the alternative value instead of the nearest one.
Returns:
The web safe equivalent of the component value. | grapefruit.py | def _websafe_component(c, alt=False):
"""Convert a color component to its web safe equivalent.
Parameters:
:c:
The component value [0...1]
:alt:
If True, return the alternative value instead of the nearest one.
Returns:
The web safe equivalent of the component value.
"""
# This suck... | def _websafe_component(c, alt=False):
"""Convert a color component to its web safe equivalent.
Parameters:
:c:
The component value [0...1]
:alt:
If True, return the alternative value instead of the nearest one.
Returns:
The web safe equivalent of the component value.
"""
# This suck... | [
"Convert",
"a",
"color",
"component",
"to",
"its",
"web",
"safe",
"equivalent",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L958-L990 | [
"def",
"_websafe_component",
"(",
"c",
",",
"alt",
"=",
"False",
")",
":",
"# This sucks, but floating point between 0 and 1 is quite fuzzy...",
"# So we just change the scale a while to make the equality tests",
"# work, otherwise it gets wrong at some decimal far to the right.",
"sc",
... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | rgb_to_websafe | Convert the color from RGB to 'web safe' RGB
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
:alt:
If True, use the alternative color instead of the nearest one.
Can be used for dithering.
Retu... | grapefruit.py | def rgb_to_websafe(r, g=None, b=None, alt=False):
"""Convert the color from RGB to 'web safe' RGB
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
:alt:
If True, use the alternative color instead of th... | def rgb_to_websafe(r, g=None, b=None, alt=False):
"""Convert the color from RGB to 'web safe' RGB
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
:alt:
If True, use the alternative color instead of th... | [
"Convert",
"the",
"color",
"from",
"RGB",
"to",
"web",
"safe",
"RGB"
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L992-L1020 | [
"def",
"rgb_to_websafe",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
",",
"alt",
"=",
"False",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"websafeComponent"... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | rgb_to_greyscale | Convert the color from RGB to its greyscale equivalent
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
the range:
r[0...1],
g[0...1],
... | grapefruit.py | def rgb_to_greyscale(r, g=None, b=None):
"""Convert the color from RGB to its greyscale equivalent
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
... | def rgb_to_greyscale(r, g=None, b=None):
"""Convert the color from RGB to its greyscale equivalent
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
... | [
"Convert",
"the",
"color",
"from",
"RGB",
"to",
"its",
"greyscale",
"equivalent"
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1022-L1047 | [
"def",
"rgb_to_greyscale",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"v",
"=",
"(",
"r",
"+",
"g",
"+",
"... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | rgb_to_ryb | Maps a hue on the RGB color wheel to Itten's RYB wheel.
Parameters:
:hue:
The hue on the RGB color wheel [0...360]
Returns:
An approximation of the corresponding hue on Itten's RYB wheel.
>>> rgb_to_ryb(15)
26.0 | grapefruit.py | def rgb_to_ryb(hue):
"""Maps a hue on the RGB color wheel to Itten's RYB wheel.
Parameters:
:hue:
The hue on the RGB color wheel [0...360]
Returns:
An approximation of the corresponding hue on Itten's RYB wheel.
>>> rgb_to_ryb(15)
26.0
"""
d = hue % 15
i = int(hue / 15)
x0 = _RybWhee... | def rgb_to_ryb(hue):
"""Maps a hue on the RGB color wheel to Itten's RYB wheel.
Parameters:
:hue:
The hue on the RGB color wheel [0...360]
Returns:
An approximation of the corresponding hue on Itten's RYB wheel.
>>> rgb_to_ryb(15)
26.0
"""
d = hue % 15
i = int(hue / 15)
x0 = _RybWhee... | [
"Maps",
"a",
"hue",
"on",
"the",
"RGB",
"color",
"wheel",
"to",
"Itten",
"s",
"RYB",
"wheel",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1049-L1067 | [
"def",
"rgb_to_ryb",
"(",
"hue",
")",
":",
"d",
"=",
"hue",
"%",
"15",
"i",
"=",
"int",
"(",
"hue",
"/",
"15",
")",
"x0",
"=",
"_RybWheel",
"[",
"i",
"]",
"x1",
"=",
"_RybWheel",
"[",
"i",
"+",
"1",
"]",
"return",
"x0",
"+",
"(",
"x1",
"-",... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | ryb_to_rgb | Maps a hue on Itten's RYB color wheel to the standard RGB wheel.
Parameters:
:hue:
The hue on Itten's RYB color wheel [0...360]
Returns:
An approximation of the corresponding hue on the standard RGB wheel.
>>> ryb_to_rgb(15)
8.0 | grapefruit.py | def ryb_to_rgb(hue):
"""Maps a hue on Itten's RYB color wheel to the standard RGB wheel.
Parameters:
:hue:
The hue on Itten's RYB color wheel [0...360]
Returns:
An approximation of the corresponding hue on the standard RGB wheel.
>>> ryb_to_rgb(15)
8.0
"""
d = hue % 15
i = int(hue / 15... | def ryb_to_rgb(hue):
"""Maps a hue on Itten's RYB color wheel to the standard RGB wheel.
Parameters:
:hue:
The hue on Itten's RYB color wheel [0...360]
Returns:
An approximation of the corresponding hue on the standard RGB wheel.
>>> ryb_to_rgb(15)
8.0
"""
d = hue % 15
i = int(hue / 15... | [
"Maps",
"a",
"hue",
"on",
"Itten",
"s",
"RYB",
"color",
"wheel",
"to",
"the",
"standard",
"RGB",
"wheel",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1069-L1087 | [
"def",
"ryb_to_rgb",
"(",
"hue",
")",
":",
"d",
"=",
"hue",
"%",
"15",
"i",
"=",
"int",
"(",
"hue",
"/",
"15",
")",
"x0",
"=",
"_RgbWheel",
"[",
"i",
"]",
"x1",
"=",
"_RgbWheel",
"[",
"i",
"+",
"1",
"]",
"return",
"x0",
"+",
"(",
"x1",
"-",... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | Color.from_rgb | Create a new instance based on the specifed RGB values.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:
T... | grapefruit.py | def from_rgb(r, g, b, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed RGB values.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
:alpha:
The color t... | def from_rgb(r, g, b, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed RGB values.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
:alpha:
The color t... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"the",
"specifed",
"RGB",
"values",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1123-L1147 | [
"def",
"from_rgb",
"(",
"r",
",",
"g",
",",
"b",
",",
"alpha",
"=",
"1.0",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"return",
"Color",
"(",
"(",
"r",
",",
"g",
",",
"b",
")",
",",
"'rgb'",
",",
"alpha",
",",
"wref",
")"
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | Color.from_hsl | Create a new instance based on the specifed HSL values.
Parameters:
:h:
The Hue component value [0...1]
:s:
The Saturation component value [0...1]
:l:
The Lightness component value [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:... | grapefruit.py | def from_hsl(h, s, l, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed HSL values.
Parameters:
:h:
The Hue component value [0...1]
:s:
The Saturation component value [0...1]
:l:
The Lightness component value [0...1]
:alpha:
T... | def from_hsl(h, s, l, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed HSL values.
Parameters:
:h:
The Hue component value [0...1]
:s:
The Saturation component value [0...1]
:l:
The Lightness component value [0...1]
:alpha:
T... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"the",
"specifed",
"HSL",
"values",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1150-L1174 | [
"def",
"from_hsl",
"(",
"h",
",",
"s",
",",
"l",
",",
"alpha",
"=",
"1.0",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"return",
"Color",
"(",
"(",
"h",
",",
"s",
",",
"l",
")",
",",
"'hsl'",
",",
"alpha",
",",
"wref",
")"
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | Color.from_hsv | Create a new instance based on the specifed HSV values.
Parameters:
:h:
The Hus component value [0...1]
:s:
The Saturation component value [0...1]
:v:
The Value component [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:
T... | grapefruit.py | def from_hsv(h, s, v, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed HSV values.
Parameters:
:h:
The Hus component value [0...1]
:s:
The Saturation component value [0...1]
:v:
The Value component [0...1]
:alpha:
The color t... | def from_hsv(h, s, v, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed HSV values.
Parameters:
:h:
The Hus component value [0...1]
:s:
The Saturation component value [0...1]
:v:
The Value component [0...1]
:alpha:
The color t... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"the",
"specifed",
"HSV",
"values",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1177-L1202 | [
"def",
"from_hsv",
"(",
"h",
",",
"s",
",",
"v",
",",
"alpha",
"=",
"1.0",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"h2",
",",
"s",
",",
"l",
"=",
"rgb_to_hsl",
"(",
"*",
"hsv_to_rgb",
"(",
"h",
",",
"s",
",",
"v",
")",
")",
"return",
"Co... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | Color.from_yiq | Create a new instance based on the specifed YIQ values.
Parameters:
:y:
The Y component value [0...1]
:i:
The I component value [0...1]
:q:
The Q component value [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:
The whitep... | grapefruit.py | def from_yiq(y, i, q, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed YIQ values.
Parameters:
:y:
The Y component value [0...1]
:i:
The I component value [0...1]
:q:
The Q component value [0...1]
:alpha:
The color transparen... | def from_yiq(y, i, q, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed YIQ values.
Parameters:
:y:
The Y component value [0...1]
:i:
The I component value [0...1]
:q:
The Q component value [0...1]
:alpha:
The color transparen... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"the",
"specifed",
"YIQ",
"values",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1205-L1229 | [
"def",
"from_yiq",
"(",
"y",
",",
"i",
",",
"q",
",",
"alpha",
"=",
"1.0",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"return",
"Color",
"(",
"yiq_to_rgb",
"(",
"y",
",",
"i",
",",
"q",
")",
",",
"'rgb'",
",",
"alpha",
",",
"wref",
")"
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | Color.from_yuv | Create a new instance based on the specifed YUV values.
Parameters:
:y:
The Y component value [0...1]
:u:
The U component value [-0.436...0.436]
:v:
The V component value [-0.615...0.615]
:alpha:
The color transparency [0...1], default is opaque
:wref:
... | grapefruit.py | def from_yuv(y, u, v, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed YUV values.
Parameters:
:y:
The Y component value [0...1]
:u:
The U component value [-0.436...0.436]
:v:
The V component value [-0.615...0.615]
:alpha:
Th... | def from_yuv(y, u, v, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed YUV values.
Parameters:
:y:
The Y component value [0...1]
:u:
The U component value [-0.436...0.436]
:v:
The V component value [-0.615...0.615]
:alpha:
Th... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"the",
"specifed",
"YUV",
"values",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1232-L1256 | [
"def",
"from_yuv",
"(",
"y",
",",
"u",
",",
"v",
",",
"alpha",
"=",
"1.0",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"return",
"Color",
"(",
"yuv_to_rgb",
"(",
"y",
",",
"u",
",",
"v",
")",
",",
"'rgb'",
",",
"alpha",
",",
"wref",
")"
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | Color.from_xyz | Create a new instance based on the specifed CIE-XYZ values.
Parameters:
:x:
The Red component value [0...1]
:y:
The Green component value [0...1]
:z:
The Blue component value [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:
... | grapefruit.py | def from_xyz(x, y, z, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed CIE-XYZ values.
Parameters:
:x:
The Red component value [0...1]
:y:
The Green component value [0...1]
:z:
The Blue component value [0...1]
:alpha:
The col... | def from_xyz(x, y, z, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed CIE-XYZ values.
Parameters:
:x:
The Red component value [0...1]
:y:
The Green component value [0...1]
:z:
The Blue component value [0...1]
:alpha:
The col... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"the",
"specifed",
"CIE",
"-",
"XYZ",
"values",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1259-L1283 | [
"def",
"from_xyz",
"(",
"x",
",",
"y",
",",
"z",
",",
"alpha",
"=",
"1.0",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"return",
"Color",
"(",
"xyz_to_rgb",
"(",
"x",
",",
"y",
",",
"z",
")",
",",
"'rgb'",
",",
"alpha",
",",
"wref",
")"
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | Color.from_lab | Create a new instance based on the specifed CIE-LAB values.
Parameters:
:l:
The L component [0...100]
:a:
The a component [-1...1]
:b:
The a component [-1...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:
The whitepoint refer... | grapefruit.py | def from_lab(l, a, b, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed CIE-LAB values.
Parameters:
:l:
The L component [0...100]
:a:
The a component [-1...1]
:b:
The a component [-1...1]
:alpha:
The color transparency [0...1]... | def from_lab(l, a, b, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed CIE-LAB values.
Parameters:
:l:
The L component [0...100]
:a:
The a component [-1...1]
:b:
The a component [-1...1]
:alpha:
The color transparency [0...1]... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"the",
"specifed",
"CIE",
"-",
"LAB",
"values",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1286-L1314 | [
"def",
"from_lab",
"(",
"l",
",",
"a",
",",
"b",
",",
"alpha",
"=",
"1.0",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"return",
"Color",
"(",
"xyz_to_rgb",
"(",
"*",
"lab_to_xyz",
"(",
"l",
",",
"a",
",",
"b",
",",
"wref",
")",
")",
",",
"'rg... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | Color.from_cmy | Create a new instance based on the specifed CMY values.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:
... | grapefruit.py | def from_cmy(c, m, y, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed CMY values.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:alpha:
The co... | def from_cmy(c, m, y, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed CMY values.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:alpha:
The co... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"the",
"specifed",
"CMY",
"values",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1317-L1341 | [
"def",
"from_cmy",
"(",
"c",
",",
"m",
",",
"y",
",",
"alpha",
"=",
"1.0",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"return",
"Color",
"(",
"cmy_to_rgb",
"(",
"c",
",",
"m",
",",
"y",
")",
",",
"'rgb'",
",",
"alpha",
",",
"wref",
")"
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | Color.from_cmyk | Create a new instance based on the specifed CMYK values.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:k:
The Black component value [0...1]
:alpha:
The color tran... | grapefruit.py | def from_cmyk(c, m, y, k, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed CMYK values.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:k:
The B... | def from_cmyk(c, m, y, k, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed CMYK values.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:k:
The B... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"the",
"specifed",
"CMYK",
"values",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1344-L1370 | [
"def",
"from_cmyk",
"(",
"c",
",",
"m",
",",
"y",
",",
"k",
",",
"alpha",
"=",
"1.0",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"return",
"Color",
"(",
"cmy_to_rgb",
"(",
"*",
"cmyk_to_cmy",
"(",
"c",
",",
"m",
",",
"y",
",",
"k",
")",
")",
... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | Color.from_html | Create a new instance based on the specifed HTML color definition.
Parameters:
:html:
The HTML definition of the color (#RRGGBB or #RGB or a color name).
:alpha:
The color transparency [0...1], default is opaque.
:wref:
The whitepoint reference, default is 2° D65.
Ret... | grapefruit.py | def from_html(html, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed HTML color definition.
Parameters:
:html:
The HTML definition of the color (#RRGGBB or #RGB or a color name).
:alpha:
The color transparency [0...1], default is opaque.
:wref:
... | def from_html(html, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed HTML color definition.
Parameters:
:html:
The HTML definition of the color (#RRGGBB or #RGB or a color name).
:alpha:
The color transparency [0...1], default is opaque.
:wref:
... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"the",
"specifed",
"HTML",
"color",
"definition",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1373-L1401 | [
"def",
"from_html",
"(",
"html",
",",
"alpha",
"=",
"1.0",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"return",
"Color",
"(",
"html_to_rgb",
"(",
"html",
")",
",",
"'rgb'",
",",
"alpha",
",",
"wref",
")"
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | Color.from_pil | Create a new instance based on the specifed PIL color.
Parameters:
:pil:
A PIL compatible color representation (0xBBGGRR)
:alpha:
The color transparency [0...1], default is opaque
:wref:
The whitepoint reference, default is 2° D65.
Returns:
A grapefruit.Color in... | grapefruit.py | def from_pil(pil, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed PIL color.
Parameters:
:pil:
A PIL compatible color representation (0xBBGGRR)
:alpha:
The color transparency [0...1], default is opaque
:wref:
The whitepoint reference, def... | def from_pil(pil, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed PIL color.
Parameters:
:pil:
A PIL compatible color representation (0xBBGGRR)
:alpha:
The color transparency [0...1], default is opaque
:wref:
The whitepoint reference, def... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"the",
"specifed",
"PIL",
"color",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1404-L1424 | [
"def",
"from_pil",
"(",
"pil",
",",
"alpha",
"=",
"1.0",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"return",
"Color",
"(",
"pil_to_rgb",
"(",
"pil",
")",
",",
"'rgb'",
",",
"alpha",
",",
"wref",
")"
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | Color.with_white_ref | Create a new instance based on this one with a new white reference.
Parameters:
:wref:
The whitepoint reference.
:labAsRef:
If True, the L*a*b* values of the current instance are used as reference
for the new color; otherwise, the RGB values are used as reference.
Returns:
... | grapefruit.py | def with_white_ref(self, wref, labAsRef=False):
"""Create a new instance based on this one with a new white reference.
Parameters:
:wref:
The whitepoint reference.
:labAsRef:
If True, the L*a*b* values of the current instance are used as reference
for the new color; otherwis... | def with_white_ref(self, wref, labAsRef=False):
"""Create a new instance based on this one with a new white reference.
Parameters:
:wref:
The whitepoint reference.
:labAsRef:
If True, the L*a*b* values of the current instance are used as reference
for the new color; otherwis... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"this",
"one",
"with",
"a",
"new",
"white",
"reference",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1707-L1744 | [
"def",
"with_white_ref",
"(",
"self",
",",
"wref",
",",
"labAsRef",
"=",
"False",
")",
":",
"if",
"labAsRef",
":",
"l",
",",
"a",
",",
"b",
"=",
"self",
".",
"lab",
"return",
"Color",
".",
"from_lab",
"(",
"l",
",",
"a",
",",
"b",
",",
"self",
... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | Color.desaturate | Create a new instance based on this one but less saturated.
Parameters:
:level:
The amount by which the color should be desaturated to produce
the new one [0...1].
Returns:
A grapefruit.Color instance.
>>> Color.from_hsl(30, 0.5, 0.5).desaturate(0.25)
Color(0.625, 0.5, 0.3... | grapefruit.py | def desaturate(self, level):
"""Create a new instance based on this one but less saturated.
Parameters:
:level:
The amount by which the color should be desaturated to produce
the new one [0...1].
Returns:
A grapefruit.Color instance.
>>> Color.from_hsl(30, 0.5, 0.5).desatu... | def desaturate(self, level):
"""Create a new instance based on this one but less saturated.
Parameters:
:level:
The amount by which the color should be desaturated to produce
the new one [0...1].
Returns:
A grapefruit.Color instance.
>>> Color.from_hsl(30, 0.5, 0.5).desatu... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"this",
"one",
"but",
"less",
"saturated",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1867-L1885 | [
"def",
"desaturate",
"(",
"self",
",",
"level",
")",
":",
"h",
",",
"s",
",",
"l",
"=",
"self",
".",
"__hsl",
"return",
"Color",
"(",
"(",
"h",
",",
"max",
"(",
"s",
"-",
"level",
",",
"0",
")",
",",
"l",
")",
",",
"'hsl'",
",",
"self",
"."... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | Color.websafe_dither | Return the two websafe colors nearest to this one.
Returns:
A tuple of two grapefruit.Color instances which are the two
web safe colors closest this one.
>>> c = Color.from_rgb(1.0, 0.45, 0.0)
>>> c1, c2 = c.websafe_dither()
>>> c1
Color(1.0, 0.4, 0.0, 1.0)
>>> c2
Color(1.0, 0.... | grapefruit.py | def websafe_dither(self):
"""Return the two websafe colors nearest to this one.
Returns:
A tuple of two grapefruit.Color instances which are the two
web safe colors closest this one.
>>> c = Color.from_rgb(1.0, 0.45, 0.0)
>>> c1, c2 = c.websafe_dither()
>>> c1
Color(1.0, 0.4, 0.0, ... | def websafe_dither(self):
"""Return the two websafe colors nearest to this one.
Returns:
A tuple of two grapefruit.Color instances which are the two
web safe colors closest this one.
>>> c = Color.from_rgb(1.0, 0.45, 0.0)
>>> c1, c2 = c.websafe_dither()
>>> c1
Color(1.0, 0.4, 0.0, ... | [
"Return",
"the",
"two",
"websafe",
"colors",
"nearest",
"to",
"this",
"one",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1895-L1912 | [
"def",
"websafe_dither",
"(",
"self",
")",
":",
"return",
"(",
"Color",
"(",
"rgb_to_websafe",
"(",
"*",
"self",
".",
"__rgb",
")",
",",
"'rgb'",
",",
"self",
".",
"__a",
",",
"self",
".",
"__wref",
")",
",",
"Color",
"(",
"rgb_to_websafe",
"(",
"alt... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | Color.complementary_color | Create a new instance which is the complementary color of this one.
Parameters:
:mode:
Select which color wheel to use for the generation (ryb/rgb).
Returns:
A grapefruit.Color instance.
>>> Color.from_hsl(30, 1, 0.5).complementary_color(mode='rgb')
Color(0.0, 0.5, 1.0, 1.0)
... | grapefruit.py | def complementary_color(self, mode='ryb'):
"""Create a new instance which is the complementary color of this one.
Parameters:
:mode:
Select which color wheel to use for the generation (ryb/rgb).
Returns:
A grapefruit.Color instance.
>>> Color.from_hsl(30, 1, 0.5).complementary_co... | def complementary_color(self, mode='ryb'):
"""Create a new instance which is the complementary color of this one.
Parameters:
:mode:
Select which color wheel to use for the generation (ryb/rgb).
Returns:
A grapefruit.Color instance.
>>> Color.from_hsl(30, 1, 0.5).complementary_co... | [
"Create",
"a",
"new",
"instance",
"which",
"is",
"the",
"complementary",
"color",
"of",
"this",
"one",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1914-L1937 | [
"def",
"complementary_color",
"(",
"self",
",",
"mode",
"=",
"'ryb'",
")",
":",
"h",
",",
"s",
",",
"l",
"=",
"self",
".",
"__hsl",
"if",
"mode",
"==",
"'ryb'",
":",
"h",
"=",
"rgb_to_ryb",
"(",
"h",
")",
"h",
"=",
"(",
"h",
"+",
"180",
")",
... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | Color.make_analogous_scheme | Return two colors analogous to this one.
Args:
:angle:
The angle between the hues of the created colors and this one.
:mode:
Select which color wheel to use for the generation (ryb/rgb).
Returns:
A tuple of grapefruit.Colors analogous to this one.
>>> c1 = Color.from_hsl... | grapefruit.py | def make_analogous_scheme(self, angle=30, mode='ryb'):
"""Return two colors analogous to this one.
Args:
:angle:
The angle between the hues of the created colors and this one.
:mode:
Select which color wheel to use for the generation (ryb/rgb).
Returns:
A tuple of grapefr... | def make_analogous_scheme(self, angle=30, mode='ryb'):
"""Return two colors analogous to this one.
Args:
:angle:
The angle between the hues of the created colors and this one.
:mode:
Select which color wheel to use for the generation (ryb/rgb).
Returns:
A tuple of grapefr... | [
"Return",
"two",
"colors",
"analogous",
"to",
"this",
"one",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L2089-L2127 | [
"def",
"make_analogous_scheme",
"(",
"self",
",",
"angle",
"=",
"30",
",",
"mode",
"=",
"'ryb'",
")",
":",
"h",
",",
"s",
",",
"l",
"=",
"self",
".",
"__hsl",
"if",
"mode",
"==",
"'ryb'",
":",
"h",
"=",
"rgb_to_ryb",
"(",
"h",
")",
"h",
"+=",
"... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | Color.alpha_blend | Alpha-blend this color on the other one.
Args:
:other:
The grapefruit.Color to alpha-blend with this one.
Returns:
A grapefruit.Color instance which is the result of alpha-blending
this color on the other one.
>>> c1 = Color.from_rgb(1, 0.5, 0, 0.2)
>>> c2 = Color.from_rgb(1... | grapefruit.py | def alpha_blend(self, other):
"""Alpha-blend this color on the other one.
Args:
:other:
The grapefruit.Color to alpha-blend with this one.
Returns:
A grapefruit.Color instance which is the result of alpha-blending
this color on the other one.
>>> c1 = Color.from_rgb(1, 0.5, ... | def alpha_blend(self, other):
"""Alpha-blend this color on the other one.
Args:
:other:
The grapefruit.Color to alpha-blend with this one.
Returns:
A grapefruit.Color instance which is the result of alpha-blending
this color on the other one.
>>> c1 = Color.from_rgb(1, 0.5, ... | [
"Alpha",
"-",
"blend",
"this",
"color",
"on",
"the",
"other",
"one",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L2129-L2160 | [
"def",
"alpha_blend",
"(",
"self",
",",
"other",
")",
":",
"# get final alpha channel",
"fa",
"=",
"self",
".",
"__a",
"+",
"other",
".",
"__a",
"-",
"(",
"self",
".",
"__a",
"*",
"other",
".",
"__a",
")",
"# get percentage of source alpha compared to final al... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | Color.blend | blend this color with the other one.
Args:
:other:
the grapefruit.Color to blend with this one.
Returns:
A grapefruit.Color instance which is the result of blending
this color on the other one.
>>> c1 = Color.from_rgb(1, 0.5, 0, 0.2)
>>> c2 = Color.from_rgb(1, 1, 1, 0.6)
... | grapefruit.py | def blend(self, other, percent=0.5):
"""blend this color with the other one.
Args:
:other:
the grapefruit.Color to blend with this one.
Returns:
A grapefruit.Color instance which is the result of blending
this color on the other one.
>>> c1 = Color.from_rgb(1, 0.5, 0, 0.2)
... | def blend(self, other, percent=0.5):
"""blend this color with the other one.
Args:
:other:
the grapefruit.Color to blend with this one.
Returns:
A grapefruit.Color instance which is the result of blending
this color on the other one.
>>> c1 = Color.from_rgb(1, 0.5, 0, 0.2)
... | [
"blend",
"this",
"color",
"with",
"the",
"other",
"one",
"."
] | xav/Grapefruit | python | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L2162-L2183 | [
"def",
"blend",
"(",
"self",
",",
"other",
",",
"percent",
"=",
"0.5",
")",
":",
"dest",
"=",
"1.0",
"-",
"percent",
"rgb",
"=",
"tuple",
"(",
"(",
"(",
"u",
"*",
"percent",
")",
"+",
"(",
"v",
"*",
"dest",
")",
"for",
"u",
",",
"v",
"in",
... | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 |
train | get_parser | Parse command-line arguments. | scrape/scrape.py | def get_parser():
"""Parse command-line arguments."""
parser = ArgumentParser(description='a command-line web scraping tool')
parser.add_argument('query', metavar='QUERY', type=str, nargs='*',
help='URLs/files to scrape')
parser.add_argument('-a', '--attributes', type=str, nargs=... | def get_parser():
"""Parse command-line arguments."""
parser = ArgumentParser(description='a command-line web scraping tool')
parser.add_argument('query', metavar='QUERY', type=str, nargs='*',
help='URLs/files to scrape')
parser.add_argument('-a', '--attributes', type=str, nargs=... | [
"Parse",
"command",
"-",
"line",
"arguments",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L19-L71 | [
"def",
"get_parser",
"(",
")",
":",
"parser",
"=",
"ArgumentParser",
"(",
"description",
"=",
"'a command-line web scraping tool'",
")",
"parser",
".",
"add_argument",
"(",
"'query'",
",",
"metavar",
"=",
"'QUERY'",
",",
"type",
"=",
"str",
",",
"nargs",
"=",
... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | write_files | Write scraped or local file(s) in desired format.
Keyword arguments:
args -- program arguments (dict)
infilenames -- names of user-inputted and/or downloaded files (list)
outfilename -- name of output file (str)
Remove PART(#).html files after conversion unless otherwise specified. | scrape/scrape.py | def write_files(args, infilenames, outfilename):
"""Write scraped or local file(s) in desired format.
Keyword arguments:
args -- program arguments (dict)
infilenames -- names of user-inputted and/or downloaded files (list)
outfilename -- name of output file (str)
Remove PART(#).html files afte... | def write_files(args, infilenames, outfilename):
"""Write scraped or local file(s) in desired format.
Keyword arguments:
args -- program arguments (dict)
infilenames -- names of user-inputted and/or downloaded files (list)
outfilename -- name of output file (str)
Remove PART(#).html files afte... | [
"Write",
"scraped",
"or",
"local",
"file",
"(",
"s",
")",
"in",
"desired",
"format",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L74-L94 | [
"def",
"write_files",
"(",
"args",
",",
"infilenames",
",",
"outfilename",
")",
":",
"write_actions",
"=",
"{",
"'print'",
":",
"utils",
".",
"print_text",
",",
"'pdf'",
":",
"utils",
".",
"write_pdf_files",
",",
"'csv'",
":",
"utils",
".",
"write_csv_files"... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | write_single_file | Write to a single output file and/or subdirectory. | scrape/scrape.py | def write_single_file(args, base_dir, crawler):
"""Write to a single output file and/or subdirectory."""
if args['urls'] and args['html']:
# Create a directory to save PART.html files in
domain = utils.get_domain(args['urls'][0])
if not args['quiet']:
print('Storing html file... | def write_single_file(args, base_dir, crawler):
"""Write to a single output file and/or subdirectory."""
if args['urls'] and args['html']:
# Create a directory to save PART.html files in
domain = utils.get_domain(args['urls'][0])
if not args['quiet']:
print('Storing html file... | [
"Write",
"to",
"a",
"single",
"output",
"file",
"and",
"/",
"or",
"subdirectory",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L97-L139 | [
"def",
"write_single_file",
"(",
"args",
",",
"base_dir",
",",
"crawler",
")",
":",
"if",
"args",
"[",
"'urls'",
"]",
"and",
"args",
"[",
"'html'",
"]",
":",
"# Create a directory to save PART.html files in",
"domain",
"=",
"utils",
".",
"get_domain",
"(",
"ar... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | write_multiple_files | Write to multiple output files and/or subdirectories. | scrape/scrape.py | def write_multiple_files(args, base_dir, crawler):
"""Write to multiple output files and/or subdirectories."""
for i, query in enumerate(args['query']):
if query in args['files']:
# Write files
if args['out'] and i < len(args['out']):
outfilename = args['out'][i]
... | def write_multiple_files(args, base_dir, crawler):
"""Write to multiple output files and/or subdirectories."""
for i, query in enumerate(args['query']):
if query in args['files']:
# Write files
if args['out'] and i < len(args['out']):
outfilename = args['out'][i]
... | [
"Write",
"to",
"multiple",
"output",
"files",
"and",
"/",
"or",
"subdirectories",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L142-L190 | [
"def",
"write_multiple_files",
"(",
"args",
",",
"base_dir",
",",
"crawler",
")",
":",
"for",
"i",
",",
"query",
"in",
"enumerate",
"(",
"args",
"[",
"'query'",
"]",
")",
":",
"if",
"query",
"in",
"args",
"[",
"'files'",
"]",
":",
"# Write files",
"if"... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | split_input | Split query input into local files and URLs. | scrape/scrape.py | def split_input(args):
"""Split query input into local files and URLs."""
args['files'] = []
args['urls'] = []
for arg in args['query']:
if os.path.isfile(arg):
args['files'].append(arg)
else:
args['urls'].append(arg.strip('/')) | def split_input(args):
"""Split query input into local files and URLs."""
args['files'] = []
args['urls'] = []
for arg in args['query']:
if os.path.isfile(arg):
args['files'].append(arg)
else:
args['urls'].append(arg.strip('/')) | [
"Split",
"query",
"input",
"into",
"local",
"files",
"and",
"URLs",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L193-L201 | [
"def",
"split_input",
"(",
"args",
")",
":",
"args",
"[",
"'files'",
"]",
"=",
"[",
"]",
"args",
"[",
"'urls'",
"]",
"=",
"[",
"]",
"for",
"arg",
"in",
"args",
"[",
"'query'",
"]",
":",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"arg",
")",
... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | detect_output_type | Detect whether to save to a single or multiple files. | scrape/scrape.py | def detect_output_type(args):
"""Detect whether to save to a single or multiple files."""
if not args['single'] and not args['multiple']:
# Save to multiple files if multiple files/URLs entered
if len(args['query']) > 1 or len(args['out']) > 1:
args['multiple'] = True
else:
... | def detect_output_type(args):
"""Detect whether to save to a single or multiple files."""
if not args['single'] and not args['multiple']:
# Save to multiple files if multiple files/URLs entered
if len(args['query']) > 1 or len(args['out']) > 1:
args['multiple'] = True
else:
... | [
"Detect",
"whether",
"to",
"save",
"to",
"a",
"single",
"or",
"multiple",
"files",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L204-L211 | [
"def",
"detect_output_type",
"(",
"args",
")",
":",
"if",
"not",
"args",
"[",
"'single'",
"]",
"and",
"not",
"args",
"[",
"'multiple'",
"]",
":",
"# Save to multiple files if multiple files/URLs entered",
"if",
"len",
"(",
"args",
"[",
"'query'",
"]",
")",
">"... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | scrape | Scrape webpage content. | scrape/scrape.py | def scrape(args):
"""Scrape webpage content."""
try:
base_dir = os.getcwd()
if args['out'] is None:
args['out'] = []
# Detect whether to save to a single or multiple files
detect_output_type(args)
# Split query input into local files and URLs
split_i... | def scrape(args):
"""Scrape webpage content."""
try:
base_dir = os.getcwd()
if args['out'] is None:
args['out'] = []
# Detect whether to save to a single or multiple files
detect_output_type(args)
# Split query input into local files and URLs
split_i... | [
"Scrape",
"webpage",
"content",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L214-L257 | [
"def",
"scrape",
"(",
"args",
")",
":",
"try",
":",
"base_dir",
"=",
"os",
".",
"getcwd",
"(",
")",
"if",
"args",
"[",
"'out'",
"]",
"is",
"None",
":",
"args",
"[",
"'out'",
"]",
"=",
"[",
"]",
"# Detect whether to save to a single or multiple files",
"d... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | prompt_filetype | Prompt user for filetype if none specified. | scrape/scrape.py | def prompt_filetype(args):
"""Prompt user for filetype if none specified."""
valid_types = ('print', 'text', 'csv', 'pdf', 'html')
if not any(args[x] for x in valid_types):
try:
filetype = input('Print or save output as ({0}): '
.format(', '.join(valid_types)... | def prompt_filetype(args):
"""Prompt user for filetype if none specified."""
valid_types = ('print', 'text', 'csv', 'pdf', 'html')
if not any(args[x] for x in valid_types):
try:
filetype = input('Print or save output as ({0}): '
.format(', '.join(valid_types)... | [
"Prompt",
"user",
"for",
"filetype",
"if",
"none",
"specified",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L260-L272 | [
"def",
"prompt_filetype",
"(",
"args",
")",
":",
"valid_types",
"=",
"(",
"'print'",
",",
"'text'",
",",
"'csv'",
",",
"'pdf'",
",",
"'html'",
")",
"if",
"not",
"any",
"(",
"args",
"[",
"x",
"]",
"for",
"x",
"in",
"valid_types",
")",
":",
"try",
":... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | prompt_save_images | Prompt user to save images when crawling (for pdf and HTML formats). | scrape/scrape.py | def prompt_save_images(args):
"""Prompt user to save images when crawling (for pdf and HTML formats)."""
if args['images'] or args['no_images']:
return
if (args['pdf'] or args['html']) and (args['crawl'] or args['crawl_all']):
save_msg = ('Choosing to save images will greatly slow the'
... | def prompt_save_images(args):
"""Prompt user to save images when crawling (for pdf and HTML formats)."""
if args['images'] or args['no_images']:
return
if (args['pdf'] or args['html']) and (args['crawl'] or args['crawl_all']):
save_msg = ('Choosing to save images will greatly slow the'
... | [
"Prompt",
"user",
"to",
"save",
"images",
"when",
"crawling",
"(",
"for",
"pdf",
"and",
"HTML",
"formats",
")",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L275-L289 | [
"def",
"prompt_save_images",
"(",
"args",
")",
":",
"if",
"args",
"[",
"'images'",
"]",
"or",
"args",
"[",
"'no_images'",
"]",
":",
"return",
"if",
"(",
"args",
"[",
"'pdf'",
"]",
"or",
"args",
"[",
"'html'",
"]",
")",
"and",
"(",
"args",
"[",
"'cr... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | command_line_runner | Handle command-line interaction. | scrape/scrape.py | def command_line_runner():
"""Handle command-line interaction."""
parser = get_parser()
args = vars(parser.parse_args())
if args['version']:
print(__version__)
return
if args['clear_cache']:
utils.clear_cache()
print('Cleared {0}.'.format(utils.CACHE_DIR))
ret... | def command_line_runner():
"""Handle command-line interaction."""
parser = get_parser()
args = vars(parser.parse_args())
if args['version']:
print(__version__)
return
if args['clear_cache']:
utils.clear_cache()
print('Cleared {0}.'.format(utils.CACHE_DIR))
ret... | [
"Handle",
"command",
"-",
"line",
"interaction",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L292-L322 | [
"def",
"command_line_runner",
"(",
")",
":",
"parser",
"=",
"get_parser",
"(",
")",
"args",
"=",
"vars",
"(",
"parser",
".",
"parse_args",
"(",
")",
")",
"if",
"args",
"[",
"'version'",
"]",
":",
"print",
"(",
"__version__",
")",
"return",
"if",
"args"... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | Classifier.load_raw | Loads a trained classifier from the raw Weka model format.
Must specify the model schema and classifier name, since
these aren't currently deduced from the model format. | weka/classifiers.py | def load_raw(cls, model_fn, schema, *args, **kwargs):
"""
Loads a trained classifier from the raw Weka model format.
Must specify the model schema and classifier name, since
these aren't currently deduced from the model format.
"""
c = cls(*args, **kwargs)
c.schem... | def load_raw(cls, model_fn, schema, *args, **kwargs):
"""
Loads a trained classifier from the raw Weka model format.
Must specify the model schema and classifier name, since
these aren't currently deduced from the model format.
"""
c = cls(*args, **kwargs)
c.schem... | [
"Loads",
"a",
"trained",
"classifier",
"from",
"the",
"raw",
"Weka",
"model",
"format",
".",
"Must",
"specify",
"the",
"model",
"schema",
"and",
"classifier",
"name",
"since",
"these",
"aren",
"t",
"currently",
"deduced",
"from",
"the",
"model",
"format",
".... | chrisspen/weka | python | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/classifiers.py#L270-L279 | [
"def",
"load_raw",
"(",
"cls",
",",
"model_fn",
",",
"schema",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"c",
"=",
"cls",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"c",
".",
"schema",
"=",
"schema",
".",
"copy",
"(",
"schema_on... | c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b |
train | Classifier.train | Updates the classifier with new data. | weka/classifiers.py | def train(self, training_data, testing_data=None, verbose=False):
"""
Updates the classifier with new data.
"""
model_fn = None
training_fn = None
clean_training = False
testing_fn = None
clean_testing = False
try:
# Valida... | def train(self, training_data, testing_data=None, verbose=False):
"""
Updates the classifier with new data.
"""
model_fn = None
training_fn = None
clean_training = False
testing_fn = None
clean_testing = False
try:
# Valida... | [
"Updates",
"the",
"classifier",
"with",
"new",
"data",
"."
] | chrisspen/weka | python | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/classifiers.py#L312-L417 | [
"def",
"train",
"(",
"self",
",",
"training_data",
",",
"testing_data",
"=",
"None",
",",
"verbose",
"=",
"False",
")",
":",
"model_fn",
"=",
"None",
"training_fn",
"=",
"None",
"clean_training",
"=",
"False",
"testing_fn",
"=",
"None",
"clean_testing",
"=",... | c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b |
train | Classifier.predict | Iterates over the predicted values and probability (if supported).
Each iteration yields a tuple of the form (prediction, probability).
If the file is a test file (i.e. contains no query variables),
then the tuple will be of the form (prediction, actual).
See http://wek... | weka/classifiers.py | def predict(self, query_data, verbose=False, distribution=False, cleanup=True):
"""
Iterates over the predicted values and probability (if supported).
Each iteration yields a tuple of the form (prediction, probability).
If the file is a test file (i.e. contains no query variable... | def predict(self, query_data, verbose=False, distribution=False, cleanup=True):
"""
Iterates over the predicted values and probability (if supported).
Each iteration yields a tuple of the form (prediction, probability).
If the file is a test file (i.e. contains no query variable... | [
"Iterates",
"over",
"the",
"predicted",
"values",
"and",
"probability",
"(",
"if",
"supported",
")",
".",
"Each",
"iteration",
"yields",
"a",
"tuple",
"of",
"the",
"form",
"(",
"prediction",
"probability",
")",
".",
"If",
"the",
"file",
"is",
"a",
"test",
... | chrisspen/weka | python | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/classifiers.py#L419-L592 | [
"def",
"predict",
"(",
"self",
",",
"query_data",
",",
"verbose",
"=",
"False",
",",
"distribution",
"=",
"False",
",",
"cleanup",
"=",
"True",
")",
":",
"model_fn",
"=",
"None",
"query_fn",
"=",
"None",
"clean_query",
"=",
"False",
"stdout",
"=",
"None"... | c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b |
train | EnsembleClassifier.get_training_coverage | Returns a ratio of classifiers that were able to be trained successfully. | weka/classifiers.py | def get_training_coverage(self):
"""
Returns a ratio of classifiers that were able to be trained successfully.
"""
total = len(self.training_results)
i = sum(1 for data in self.training_results.values() if not isinstance(data, basestring))
return i/float(total) | def get_training_coverage(self):
"""
Returns a ratio of classifiers that were able to be trained successfully.
"""
total = len(self.training_results)
i = sum(1 for data in self.training_results.values() if not isinstance(data, basestring))
return i/float(total) | [
"Returns",
"a",
"ratio",
"of",
"classifiers",
"that",
"were",
"able",
"to",
"be",
"trained",
"successfully",
"."
] | chrisspen/weka | python | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/classifiers.py#L640-L646 | [
"def",
"get_training_coverage",
"(",
"self",
")",
":",
"total",
"=",
"len",
"(",
"self",
".",
"training_results",
")",
"i",
"=",
"sum",
"(",
"1",
"for",
"data",
"in",
"self",
".",
"training_results",
".",
"values",
"(",
")",
"if",
"not",
"isinstance",
... | c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b |
train | Crawler.get_new_links | Get new links from a URL and filter them. | scrape/crawler.py | def get_new_links(self, url, resp):
"""Get new links from a URL and filter them."""
links_on_page = resp.xpath('//a/@href')
links = [utils.clean_url(u, url) for u in links_on_page]
# Remove non-links through filtering by protocol
links = [x for x in links if utils.check_protocol... | def get_new_links(self, url, resp):
"""Get new links from a URL and filter them."""
links_on_page = resp.xpath('//a/@href')
links = [utils.clean_url(u, url) for u in links_on_page]
# Remove non-links through filtering by protocol
links = [x for x in links if utils.check_protocol... | [
"Get",
"new",
"links",
"from",
"a",
"URL",
"and",
"filter",
"them",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/crawler.py#L20-L36 | [
"def",
"get_new_links",
"(",
"self",
",",
"url",
",",
"resp",
")",
":",
"links_on_page",
"=",
"resp",
".",
"xpath",
"(",
"'//a/@href'",
")",
"links",
"=",
"[",
"utils",
".",
"clean_url",
"(",
"u",
",",
"url",
")",
"for",
"u",
"in",
"links_on_page",
"... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | Crawler.page_crawled | Check if page has been crawled by hashing its text content.
Add new pages to the page cache.
Return whether page was found in cache. | scrape/crawler.py | def page_crawled(self, page_resp):
"""Check if page has been crawled by hashing its text content.
Add new pages to the page cache.
Return whether page was found in cache.
"""
page_text = utils.parse_text(page_resp)
page_hash = utils.hash_text(''.join(page_text))
... | def page_crawled(self, page_resp):
"""Check if page has been crawled by hashing its text content.
Add new pages to the page cache.
Return whether page was found in cache.
"""
page_text = utils.parse_text(page_resp)
page_hash = utils.hash_text(''.join(page_text))
... | [
"Check",
"if",
"page",
"has",
"been",
"crawled",
"by",
"hashing",
"its",
"text",
"content",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/crawler.py#L42-L53 | [
"def",
"page_crawled",
"(",
"self",
",",
"page_resp",
")",
":",
"page_text",
"=",
"utils",
".",
"parse_text",
"(",
"page_resp",
")",
"page_hash",
"=",
"utils",
".",
"hash_text",
"(",
"''",
".",
"join",
"(",
"page_text",
")",
")",
"if",
"page_hash",
"not"... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | Crawler.crawl_links | Find new links given a seed URL and follow them breadth-first.
Save page responses as PART.html files.
Return the PART.html filenames created during crawling. | scrape/crawler.py | def crawl_links(self, seed_url=None):
"""Find new links given a seed URL and follow them breadth-first.
Save page responses as PART.html files.
Return the PART.html filenames created during crawling.
"""
if seed_url is not None:
self.seed_url = seed_url
if s... | def crawl_links(self, seed_url=None):
"""Find new links given a seed URL and follow them breadth-first.
Save page responses as PART.html files.
Return the PART.html filenames created during crawling.
"""
if seed_url is not None:
self.seed_url = seed_url
if s... | [
"Find",
"new",
"links",
"given",
"a",
"seed",
"URL",
"and",
"follow",
"them",
"breadth",
"-",
"first",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/crawler.py#L55-L105 | [
"def",
"crawl_links",
"(",
"self",
",",
"seed_url",
"=",
"None",
")",
":",
"if",
"seed_url",
"is",
"not",
"None",
":",
"self",
".",
"seed_url",
"=",
"seed_url",
"if",
"self",
".",
"seed_url",
"is",
"None",
":",
"sys",
".",
"stderr",
".",
"write",
"("... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | get_proxies | Get available proxies to use with requests library. | scrape/utils.py | def get_proxies():
"""Get available proxies to use with requests library."""
proxies = getproxies()
filtered_proxies = {}
for key, value in proxies.items():
if key.startswith('http://'):
if not value.startswith('http://'):
filtered_proxies[key] = 'http://{0}'.format(v... | def get_proxies():
"""Get available proxies to use with requests library."""
proxies = getproxies()
filtered_proxies = {}
for key, value in proxies.items():
if key.startswith('http://'):
if not value.startswith('http://'):
filtered_proxies[key] = 'http://{0}'.format(v... | [
"Get",
"available",
"proxies",
"to",
"use",
"with",
"requests",
"library",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L63-L73 | [
"def",
"get_proxies",
"(",
")",
":",
"proxies",
"=",
"getproxies",
"(",
")",
"filtered_proxies",
"=",
"{",
"}",
"for",
"key",
",",
"value",
"in",
"proxies",
".",
"items",
"(",
")",
":",
"if",
"key",
".",
"startswith",
"(",
"'http://'",
")",
":",
"if"... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | get_resp | Get webpage response as an lxml.html.HtmlElement object. | scrape/utils.py | def get_resp(url):
"""Get webpage response as an lxml.html.HtmlElement object."""
try:
headers = {'User-Agent': random.choice(USER_AGENTS)}
try:
request = requests.get(url, headers=headers, proxies=get_proxies())
except MissingSchema:
url = add_protocol(url)
... | def get_resp(url):
"""Get webpage response as an lxml.html.HtmlElement object."""
try:
headers = {'User-Agent': random.choice(USER_AGENTS)}
try:
request = requests.get(url, headers=headers, proxies=get_proxies())
except MissingSchema:
url = add_protocol(url)
... | [
"Get",
"webpage",
"response",
"as",
"an",
"lxml",
".",
"html",
".",
"HtmlElement",
"object",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L76-L88 | [
"def",
"get_resp",
"(",
"url",
")",
":",
"try",
":",
"headers",
"=",
"{",
"'User-Agent'",
":",
"random",
".",
"choice",
"(",
"USER_AGENTS",
")",
"}",
"try",
":",
"request",
"=",
"requests",
".",
"get",
"(",
"url",
",",
"headers",
"=",
"headers",
",",... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | enable_cache | Enable requests library cache. | scrape/utils.py | def enable_cache():
"""Enable requests library cache."""
try:
import requests_cache
except ImportError as err:
sys.stderr.write('Failed to enable cache: {0}\n'.format(str(err)))
return
if not os.path.exists(CACHE_DIR):
os.makedirs(CACHE_DIR)
requests_cache.install_cac... | def enable_cache():
"""Enable requests library cache."""
try:
import requests_cache
except ImportError as err:
sys.stderr.write('Failed to enable cache: {0}\n'.format(str(err)))
return
if not os.path.exists(CACHE_DIR):
os.makedirs(CACHE_DIR)
requests_cache.install_cac... | [
"Enable",
"requests",
"library",
"cache",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L106-L115 | [
"def",
"enable_cache",
"(",
")",
":",
"try",
":",
"import",
"requests_cache",
"except",
"ImportError",
"as",
"err",
":",
"sys",
".",
"stderr",
".",
"write",
"(",
"'Failed to enable cache: {0}\\n'",
".",
"format",
"(",
"str",
"(",
"err",
")",
")",
")",
"ret... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | hash_text | Return MD5 hash of a string. | scrape/utils.py | def hash_text(text):
"""Return MD5 hash of a string."""
md5 = hashlib.md5()
md5.update(text)
return md5.hexdigest() | def hash_text(text):
"""Return MD5 hash of a string."""
md5 = hashlib.md5()
md5.update(text)
return md5.hexdigest() | [
"Return",
"MD5",
"hash",
"of",
"a",
"string",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L127-L131 | [
"def",
"hash_text",
"(",
"text",
")",
":",
"md5",
"=",
"hashlib",
".",
"md5",
"(",
")",
"md5",
".",
"update",
"(",
"text",
")",
"return",
"md5",
".",
"hexdigest",
"(",
")"
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | cache_page | Add a page to the page cache. | scrape/utils.py | def cache_page(page_cache, page_hash, cache_size):
"""Add a page to the page cache."""
page_cache.append(page_hash)
if len(page_cache) > cache_size:
page_cache.pop(0) | def cache_page(page_cache, page_hash, cache_size):
"""Add a page to the page cache."""
page_cache.append(page_hash)
if len(page_cache) > cache_size:
page_cache.pop(0) | [
"Add",
"a",
"page",
"to",
"the",
"page",
"cache",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L134-L138 | [
"def",
"cache_page",
"(",
"page_cache",
",",
"page_hash",
",",
"cache_size",
")",
":",
"page_cache",
".",
"append",
"(",
"page_hash",
")",
"if",
"len",
"(",
"page_cache",
")",
">",
"cache_size",
":",
"page_cache",
".",
"pop",
"(",
"0",
")"
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | re_filter | Filter text using regular expressions. | scrape/utils.py | def re_filter(text, regexps):
"""Filter text using regular expressions."""
if not regexps:
return text
matched_text = []
compiled_regexps = [re.compile(x) for x in regexps]
for line in text:
if line in matched_text:
continue
for regexp in compiled_regexps:
... | def re_filter(text, regexps):
"""Filter text using regular expressions."""
if not regexps:
return text
matched_text = []
compiled_regexps = [re.compile(x) for x in regexps]
for line in text:
if line in matched_text:
continue
for regexp in compiled_regexps:
... | [
"Filter",
"text",
"using",
"regular",
"expressions",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L144-L160 | [
"def",
"re_filter",
"(",
"text",
",",
"regexps",
")",
":",
"if",
"not",
"regexps",
":",
"return",
"text",
"matched_text",
"=",
"[",
"]",
"compiled_regexps",
"=",
"[",
"re",
".",
"compile",
"(",
"x",
")",
"for",
"x",
"in",
"regexps",
"]",
"for",
"line... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | remove_whitespace | Remove unnecessary whitespace while keeping logical structure.
Keyword arguments:
text -- text to remove whitespace from (list)
Retain paragraph structure but remove other whitespace,
such as between words on a line and at the start and end of the text. | scrape/utils.py | def remove_whitespace(text):
"""Remove unnecessary whitespace while keeping logical structure.
Keyword arguments:
text -- text to remove whitespace from (list)
Retain paragraph structure but remove other whitespace,
such as between words on a line and at the start and end of the text.
"""
... | def remove_whitespace(text):
"""Remove unnecessary whitespace while keeping logical structure.
Keyword arguments:
text -- text to remove whitespace from (list)
Retain paragraph structure but remove other whitespace,
such as between words on a line and at the start and end of the text.
"""
... | [
"Remove",
"unnecessary",
"whitespace",
"while",
"keeping",
"logical",
"structure",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L163-L211 | [
"def",
"remove_whitespace",
"(",
"text",
")",
":",
"clean_text",
"=",
"[",
"]",
"curr_line",
"=",
"''",
"# Remove any newlines that follow two lines of whitespace consecutively",
"# Also remove whitespace at start and end of text",
"while",
"text",
":",
"if",
"not",
"curr_lin... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | parse_text | Filter text using XPath, regex keywords, and tag attributes.
Keyword arguments:
infile -- HTML or text content to parse (list)
xpath -- an XPath expression (str)
filter_words -- regex keywords (list)
attributes -- HTML tag attributes (list)
Return a list of strings of text. | scrape/utils.py | def parse_text(infile, xpath=None, filter_words=None, attributes=None):
"""Filter text using XPath, regex keywords, and tag attributes.
Keyword arguments:
infile -- HTML or text content to parse (list)
xpath -- an XPath expression (str)
filter_words -- regex keywords (list)
attributes -- HTML t... | def parse_text(infile, xpath=None, filter_words=None, attributes=None):
"""Filter text using XPath, regex keywords, and tag attributes.
Keyword arguments:
infile -- HTML or text content to parse (list)
xpath -- an XPath expression (str)
filter_words -- regex keywords (list)
attributes -- HTML t... | [
"Filter",
"text",
"using",
"XPath",
"regex",
"keywords",
"and",
"tag",
"attributes",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L214-L261 | [
"def",
"parse_text",
"(",
"infile",
",",
"xpath",
"=",
"None",
",",
"filter_words",
"=",
"None",
",",
"attributes",
"=",
"None",
")",
":",
"infiles",
"=",
"[",
"]",
"text",
"=",
"[",
"]",
"if",
"xpath",
"is",
"not",
"None",
":",
"infile",
"=",
"par... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | get_parsed_text | Parse and return text content of infiles.
Keyword arguments:
args -- program arguments (dict)
infilenames -- name of user-inputted and/or downloaded file (str)
Return a list of strings of text. | scrape/utils.py | def get_parsed_text(args, infilename):
"""Parse and return text content of infiles.
Keyword arguments:
args -- program arguments (dict)
infilenames -- name of user-inputted and/or downloaded file (str)
Return a list of strings of text.
"""
parsed_text = []
if infilename.endswith('.html... | def get_parsed_text(args, infilename):
"""Parse and return text content of infiles.
Keyword arguments:
args -- program arguments (dict)
infilenames -- name of user-inputted and/or downloaded file (str)
Return a list of strings of text.
"""
parsed_text = []
if infilename.endswith('.html... | [
"Parse",
"and",
"return",
"text",
"content",
"of",
"infiles",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L264-L291 | [
"def",
"get_parsed_text",
"(",
"args",
",",
"infilename",
")",
":",
"parsed_text",
"=",
"[",
"]",
"if",
"infilename",
".",
"endswith",
"(",
"'.html'",
")",
":",
"# Convert HTML to lxml object for content parsing",
"html",
"=",
"lh",
".",
"fromstring",
"(",
"read... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | parse_html | Filter HTML using XPath. | scrape/utils.py | def parse_html(infile, xpath):
"""Filter HTML using XPath."""
if not isinstance(infile, lh.HtmlElement):
infile = lh.fromstring(infile)
infile = infile.xpath(xpath)
if not infile:
raise ValueError('XPath {0} returned no results.'.format(xpath))
return infile | def parse_html(infile, xpath):
"""Filter HTML using XPath."""
if not isinstance(infile, lh.HtmlElement):
infile = lh.fromstring(infile)
infile = infile.xpath(xpath)
if not infile:
raise ValueError('XPath {0} returned no results.'.format(xpath))
return infile | [
"Filter",
"HTML",
"using",
"XPath",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L309-L316 | [
"def",
"parse_html",
"(",
"infile",
",",
"xpath",
")",
":",
"if",
"not",
"isinstance",
"(",
"infile",
",",
"lh",
".",
"HtmlElement",
")",
":",
"infile",
"=",
"lh",
".",
"fromstring",
"(",
"infile",
")",
"infile",
"=",
"infile",
".",
"xpath",
"(",
"xp... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | clean_url | Add base netloc and path to internal URLs and remove www, fragments. | scrape/utils.py | def clean_url(url, base_url=None):
"""Add base netloc and path to internal URLs and remove www, fragments."""
parsed_url = urlparse(url)
fragment = '{url.fragment}'.format(url=parsed_url)
if fragment:
url = url.split(fragment)[0]
# Identify internal URLs and fix their format
netloc = '... | def clean_url(url, base_url=None):
"""Add base netloc and path to internal URLs and remove www, fragments."""
parsed_url = urlparse(url)
fragment = '{url.fragment}'.format(url=parsed_url)
if fragment:
url = url.split(fragment)[0]
# Identify internal URLs and fix their format
netloc = '... | [
"Add",
"base",
"netloc",
"and",
"path",
"to",
"internal",
"URLs",
"and",
"remove",
"www",
"fragments",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L348-L366 | [
"def",
"clean_url",
"(",
"url",
",",
"base_url",
"=",
"None",
")",
":",
"parsed_url",
"=",
"urlparse",
"(",
"url",
")",
"fragment",
"=",
"'{url.fragment}'",
".",
"format",
"(",
"url",
"=",
"parsed_url",
")",
"if",
"fragment",
":",
"url",
"=",
"url",
".... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | add_url_suffix | Add .com suffix to URL if none found. | scrape/utils.py | def add_url_suffix(url):
"""Add .com suffix to URL if none found."""
url = url.rstrip('/')
if not has_suffix(url):
return '{0}.com'.format(url)
return url | def add_url_suffix(url):
"""Add .com suffix to URL if none found."""
url = url.rstrip('/')
if not has_suffix(url):
return '{0}.com'.format(url)
return url | [
"Add",
".",
"com",
"suffix",
"to",
"URL",
"if",
"none",
"found",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L374-L379 | [
"def",
"add_url_suffix",
"(",
"url",
")",
":",
"url",
"=",
"url",
".",
"rstrip",
"(",
"'/'",
")",
"if",
"not",
"has_suffix",
"(",
"url",
")",
":",
"return",
"'{0}.com'",
".",
"format",
"(",
"url",
")",
"return",
"url"
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | get_outfilename | Construct the output filename from domain and end of path. | scrape/utils.py | def get_outfilename(url, domain=None):
"""Construct the output filename from domain and end of path."""
if domain is None:
domain = get_domain(url)
path = '{url.path}'.format(url=urlparse(url))
if '.' in path:
tail_url = path.split('.')[-2]
else:
tail_url = path
if tail... | def get_outfilename(url, domain=None):
"""Construct the output filename from domain and end of path."""
if domain is None:
domain = get_domain(url)
path = '{url.path}'.format(url=urlparse(url))
if '.' in path:
tail_url = path.split('.')[-2]
else:
tail_url = path
if tail... | [
"Construct",
"the",
"output",
"filename",
"from",
"domain",
"and",
"end",
"of",
"path",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L385-L426 | [
"def",
"get_outfilename",
"(",
"url",
",",
"domain",
"=",
"None",
")",
":",
"if",
"domain",
"is",
"None",
":",
"domain",
"=",
"get_domain",
"(",
"url",
")",
"path",
"=",
"'{url.path}'",
".",
"format",
"(",
"url",
"=",
"urlparse",
"(",
"url",
")",
")"... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | get_single_outfilename | Use first possible entry in query as filename. | scrape/utils.py | def get_single_outfilename(args):
"""Use first possible entry in query as filename."""
for arg in args['query']:
if arg in args['files']:
return ('.'.join(arg.split('.')[:-1])).lower()
for url in args['urls']:
if arg.strip('/') in url:
domain = get_domain(... | def get_single_outfilename(args):
"""Use first possible entry in query as filename."""
for arg in args['query']:
if arg in args['files']:
return ('.'.join(arg.split('.')[:-1])).lower()
for url in args['urls']:
if arg.strip('/') in url:
domain = get_domain(... | [
"Use",
"first",
"possible",
"entry",
"in",
"query",
"as",
"filename",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L429-L439 | [
"def",
"get_single_outfilename",
"(",
"args",
")",
":",
"for",
"arg",
"in",
"args",
"[",
"'query'",
"]",
":",
"if",
"arg",
"in",
"args",
"[",
"'files'",
"]",
":",
"return",
"(",
"'.'",
".",
"join",
"(",
"arg",
".",
"split",
"(",
"'.'",
")",
"[",
... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | modify_filename_id | Modify filename to have a unique numerical identifier. | scrape/utils.py | def modify_filename_id(filename):
"""Modify filename to have a unique numerical identifier."""
split_filename = os.path.splitext(filename)
id_num_re = re.compile('(\(\d\))')
id_num = re.findall(id_num_re, split_filename[-2])
if id_num:
new_id_num = int(id_num[-1].lstrip('(').rstrip(')')) + 1... | def modify_filename_id(filename):
"""Modify filename to have a unique numerical identifier."""
split_filename = os.path.splitext(filename)
id_num_re = re.compile('(\(\d\))')
id_num = re.findall(id_num_re, split_filename[-2])
if id_num:
new_id_num = int(id_num[-1].lstrip('(').rstrip(')')) + 1... | [
"Modify",
"filename",
"to",
"have",
"a",
"unique",
"numerical",
"identifier",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L451-L468 | [
"def",
"modify_filename_id",
"(",
"filename",
")",
":",
"split_filename",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"filename",
")",
"id_num_re",
"=",
"re",
".",
"compile",
"(",
"'(\\(\\d\\))'",
")",
"id_num",
"=",
"re",
".",
"findall",
"(",
"id_num_re... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | overwrite_file_check | If filename exists, overwrite or modify it to be unique. | scrape/utils.py | def overwrite_file_check(args, filename):
"""If filename exists, overwrite or modify it to be unique."""
if not args['overwrite'] and os.path.exists(filename):
# Confirm overwriting of the file, or modify filename
if args['no_overwrite']:
overwrite = False
else:
t... | def overwrite_file_check(args, filename):
"""If filename exists, overwrite or modify it to be unique."""
if not args['overwrite'] and os.path.exists(filename):
# Confirm overwriting of the file, or modify filename
if args['no_overwrite']:
overwrite = False
else:
t... | [
"If",
"filename",
"exists",
"overwrite",
"or",
"modify",
"it",
"to",
"be",
"unique",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L471-L488 | [
"def",
"overwrite_file_check",
"(",
"args",
",",
"filename",
")",
":",
"if",
"not",
"args",
"[",
"'overwrite'",
"]",
"and",
"os",
".",
"path",
".",
"exists",
"(",
"filename",
")",
":",
"# Confirm overwriting of the file, or modify filename",
"if",
"args",
"[",
... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | print_text | Print text content of infiles to stdout.
Keyword arguments:
args -- program arguments (dict)
infilenames -- names of user-inputted and/or downloaded files (list)
outfilename -- only used for interface purposes (None) | scrape/utils.py | def print_text(args, infilenames, outfilename=None):
"""Print text content of infiles to stdout.
Keyword arguments:
args -- program arguments (dict)
infilenames -- names of user-inputted and/or downloaded files (list)
outfilename -- only used for interface purposes (None)
"""
for infilename... | def print_text(args, infilenames, outfilename=None):
"""Print text content of infiles to stdout.
Keyword arguments:
args -- program arguments (dict)
infilenames -- names of user-inputted and/or downloaded files (list)
outfilename -- only used for interface purposes (None)
"""
for infilename... | [
"Print",
"text",
"content",
"of",
"infiles",
"to",
"stdout",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L491-L504 | [
"def",
"print_text",
"(",
"args",
",",
"infilenames",
",",
"outfilename",
"=",
"None",
")",
":",
"for",
"infilename",
"in",
"infilenames",
":",
"parsed_text",
"=",
"get_parsed_text",
"(",
"args",
",",
"infilename",
")",
"if",
"parsed_text",
":",
"for",
"line... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | write_pdf_files | Write pdf file(s) to disk using pdfkit.
Keyword arguments:
args -- program arguments (dict)
infilenames -- names of user-inputted and/or downloaded files (list)
outfilename -- name of output pdf file (str) | scrape/utils.py | def write_pdf_files(args, infilenames, outfilename):
"""Write pdf file(s) to disk using pdfkit.
Keyword arguments:
args -- program arguments (dict)
infilenames -- names of user-inputted and/or downloaded files (list)
outfilename -- name of output pdf file (str)
"""
if not outfilename.endswi... | def write_pdf_files(args, infilenames, outfilename):
"""Write pdf file(s) to disk using pdfkit.
Keyword arguments:
args -- program arguments (dict)
infilenames -- names of user-inputted and/or downloaded files (list)
outfilename -- name of output pdf file (str)
"""
if not outfilename.endswi... | [
"Write",
"pdf",
"file",
"(",
"s",
")",
"to",
"disk",
"using",
"pdfkit",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L507-L575 | [
"def",
"write_pdf_files",
"(",
"args",
",",
"infilenames",
",",
"outfilename",
")",
":",
"if",
"not",
"outfilename",
".",
"endswith",
"(",
"'.pdf'",
")",
":",
"outfilename",
"=",
"outfilename",
"+",
"'.pdf'",
"outfilename",
"=",
"overwrite_file_check",
"(",
"a... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | write_csv_files | Write csv file(s) to disk.
Keyword arguments:
args -- program arguments (dict)
infilenames -- names of user-inputted and/or downloaded files (list)
outfilename -- name of output text file (str) | scrape/utils.py | def write_csv_files(args, infilenames, outfilename):
"""Write csv file(s) to disk.
Keyword arguments:
args -- program arguments (dict)
infilenames -- names of user-inputted and/or downloaded files (list)
outfilename -- name of output text file (str)
"""
def csv_convert(line):
"""Str... | def write_csv_files(args, infilenames, outfilename):
"""Write csv file(s) to disk.
Keyword arguments:
args -- program arguments (dict)
infilenames -- names of user-inputted and/or downloaded files (list)
outfilename -- name of output text file (str)
"""
def csv_convert(line):
"""Str... | [
"Write",
"csv",
"file",
"(",
"s",
")",
"to",
"disk",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L578-L622 | [
"def",
"write_csv_files",
"(",
"args",
",",
"infilenames",
",",
"outfilename",
")",
":",
"def",
"csv_convert",
"(",
"line",
")",
":",
"\"\"\"Strip punctuation and insert commas\"\"\"",
"clean_line",
"=",
"[",
"]",
"for",
"word",
"in",
"line",
".",
"split",
"(",
... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | write_text_files | Write text file(s) to disk.
Keyword arguments:
args -- program arguments (dict)
infilenames -- names of user-inputted and/or downloaded files (list)
outfilename -- name of output text file (str) | scrape/utils.py | def write_text_files(args, infilenames, outfilename):
"""Write text file(s) to disk.
Keyword arguments:
args -- program arguments (dict)
infilenames -- names of user-inputted and/or downloaded files (list)
outfilename -- name of output text file (str)
"""
if not outfilename.endswith('.txt')... | def write_text_files(args, infilenames, outfilename):
"""Write text file(s) to disk.
Keyword arguments:
args -- program arguments (dict)
infilenames -- names of user-inputted and/or downloaded files (list)
outfilename -- name of output text file (str)
"""
if not outfilename.endswith('.txt')... | [
"Write",
"text",
"file",
"(",
"s",
")",
"to",
"disk",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L625-L656 | [
"def",
"write_text_files",
"(",
"args",
",",
"infilenames",
",",
"outfilename",
")",
":",
"if",
"not",
"outfilename",
".",
"endswith",
"(",
"'.txt'",
")",
":",
"outfilename",
"=",
"outfilename",
"+",
"'.txt'",
"outfilename",
"=",
"overwrite_file_check",
"(",
"... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | write_file | Write a single file to disk. | scrape/utils.py | def write_file(data, outfilename):
"""Write a single file to disk."""
if not data:
return False
try:
with open(outfilename, 'w') as outfile:
for line in data:
if line:
outfile.write(line)
return True
except (OSError, IOError) as err... | def write_file(data, outfilename):
"""Write a single file to disk."""
if not data:
return False
try:
with open(outfilename, 'w') as outfile:
for line in data:
if line:
outfile.write(line)
return True
except (OSError, IOError) as err... | [
"Write",
"a",
"single",
"file",
"to",
"disk",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L659-L672 | [
"def",
"write_file",
"(",
"data",
",",
"outfilename",
")",
":",
"if",
"not",
"data",
":",
"return",
"False",
"try",
":",
"with",
"open",
"(",
"outfilename",
",",
"'w'",
")",
"as",
"outfile",
":",
"for",
"line",
"in",
"data",
":",
"if",
"line",
":",
... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | get_num_part_files | Get the number of PART.html files currently saved to disk. | scrape/utils.py | def get_num_part_files():
"""Get the number of PART.html files currently saved to disk."""
num_parts = 0
for filename in os.listdir(os.getcwd()):
if filename.startswith('PART') and filename.endswith('.html'):
num_parts += 1
return num_parts | def get_num_part_files():
"""Get the number of PART.html files currently saved to disk."""
num_parts = 0
for filename in os.listdir(os.getcwd()):
if filename.startswith('PART') and filename.endswith('.html'):
num_parts += 1
return num_parts | [
"Get",
"the",
"number",
"of",
"PART",
".",
"html",
"files",
"currently",
"saved",
"to",
"disk",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L675-L681 | [
"def",
"get_num_part_files",
"(",
")",
":",
"num_parts",
"=",
"0",
"for",
"filename",
"in",
"os",
".",
"listdir",
"(",
"os",
".",
"getcwd",
"(",
")",
")",
":",
"if",
"filename",
".",
"startswith",
"(",
"'PART'",
")",
"and",
"filename",
".",
"endswith",... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | write_part_images | Write image file(s) associated with HTML to disk, substituting filenames.
Keywords arguments:
url -- the URL from which the HTML has been extracted from (str)
raw_html -- unparsed HTML file content (list)
html -- parsed HTML file content (lxml.html.HtmlElement) (default: None)
filename -- the PART.... | scrape/utils.py | def write_part_images(url, raw_html, html, filename):
"""Write image file(s) associated with HTML to disk, substituting filenames.
Keywords arguments:
url -- the URL from which the HTML has been extracted from (str)
raw_html -- unparsed HTML file content (list)
html -- parsed HTML file content (lxm... | def write_part_images(url, raw_html, html, filename):
"""Write image file(s) associated with HTML to disk, substituting filenames.
Keywords arguments:
url -- the URL from which the HTML has been extracted from (str)
raw_html -- unparsed HTML file content (list)
html -- parsed HTML file content (lxm... | [
"Write",
"image",
"file",
"(",
"s",
")",
"associated",
"with",
"HTML",
"to",
"disk",
"substituting",
"filenames",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L684-L725 | [
"def",
"write_part_images",
"(",
"url",
",",
"raw_html",
",",
"html",
",",
"filename",
")",
":",
"save_dirname",
"=",
"'{0}_files'",
".",
"format",
"(",
"os",
".",
"path",
".",
"splitext",
"(",
"filename",
")",
"[",
"0",
"]",
")",
"if",
"not",
"os",
... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | write_part_file | Write PART.html file(s) to disk, images in PART_files directory.
Keyword arguments:
args -- program arguments (dict)
raw_html -- unparsed HTML file content (list)
html -- parsed HTML file content (lxml.html.HtmlElement) (default: None)
part_num -- PART(#).html file number (int) (default: None) | scrape/utils.py | def write_part_file(args, url, raw_html, html=None, part_num=None):
"""Write PART.html file(s) to disk, images in PART_files directory.
Keyword arguments:
args -- program arguments (dict)
raw_html -- unparsed HTML file content (list)
html -- parsed HTML file content (lxml.html.HtmlElement) (default... | def write_part_file(args, url, raw_html, html=None, part_num=None):
"""Write PART.html file(s) to disk, images in PART_files directory.
Keyword arguments:
args -- program arguments (dict)
raw_html -- unparsed HTML file content (list)
html -- parsed HTML file content (lxml.html.HtmlElement) (default... | [
"Write",
"PART",
".",
"html",
"file",
"(",
"s",
")",
"to",
"disk",
"images",
"in",
"PART_files",
"directory",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L728-L771 | [
"def",
"write_part_file",
"(",
"args",
",",
"url",
",",
"raw_html",
",",
"html",
"=",
"None",
",",
"part_num",
"=",
"None",
")",
":",
"if",
"part_num",
"is",
"None",
":",
"part_num",
"=",
"get_num_part_files",
"(",
")",
"+",
"1",
"filename",
"=",
"'PAR... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | get_part_filenames | Get numbered PART.html filenames. | scrape/utils.py | def get_part_filenames(num_parts=None, start_num=0):
"""Get numbered PART.html filenames."""
if num_parts is None:
num_parts = get_num_part_files()
return ['PART{0}.html'.format(i) for i in range(start_num+1, num_parts+1)] | def get_part_filenames(num_parts=None, start_num=0):
"""Get numbered PART.html filenames."""
if num_parts is None:
num_parts = get_num_part_files()
return ['PART{0}.html'.format(i) for i in range(start_num+1, num_parts+1)] | [
"Get",
"numbered",
"PART",
".",
"html",
"filenames",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L774-L778 | [
"def",
"get_part_filenames",
"(",
"num_parts",
"=",
"None",
",",
"start_num",
"=",
"0",
")",
":",
"if",
"num_parts",
"is",
"None",
":",
"num_parts",
"=",
"get_num_part_files",
"(",
")",
"return",
"[",
"'PART{0}.html'",
".",
"format",
"(",
"i",
")",
"for",
... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | read_files | Read a file into memory. | scrape/utils.py | def read_files(filenames):
"""Read a file into memory."""
if isinstance(filenames, list):
for filename in filenames:
with open(filename, 'r') as infile:
return infile.read()
else:
with open(filenames, 'r') as infile:
return infile.read() | def read_files(filenames):
"""Read a file into memory."""
if isinstance(filenames, list):
for filename in filenames:
with open(filename, 'r') as infile:
return infile.read()
else:
with open(filenames, 'r') as infile:
return infile.read() | [
"Read",
"a",
"file",
"into",
"memory",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L781-L789 | [
"def",
"read_files",
"(",
"filenames",
")",
":",
"if",
"isinstance",
"(",
"filenames",
",",
"list",
")",
":",
"for",
"filename",
"in",
"filenames",
":",
"with",
"open",
"(",
"filename",
",",
"'r'",
")",
"as",
"infile",
":",
"return",
"infile",
".",
"re... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | remove_part_images | Remove PART(#)_files directory containing images from disk. | scrape/utils.py | def remove_part_images(filename):
"""Remove PART(#)_files directory containing images from disk."""
dirname = '{0}_files'.format(os.path.splitext(filename)[0])
if os.path.exists(dirname):
shutil.rmtree(dirname) | def remove_part_images(filename):
"""Remove PART(#)_files directory containing images from disk."""
dirname = '{0}_files'.format(os.path.splitext(filename)[0])
if os.path.exists(dirname):
shutil.rmtree(dirname) | [
"Remove",
"PART",
"(",
"#",
")",
"_files",
"directory",
"containing",
"images",
"from",
"disk",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L792-L796 | [
"def",
"remove_part_images",
"(",
"filename",
")",
":",
"dirname",
"=",
"'{0}_files'",
".",
"format",
"(",
"os",
".",
"path",
".",
"splitext",
"(",
"filename",
")",
"[",
"0",
"]",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"dirname",
")",
":",... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | remove_part_files | Remove PART(#).html files and image directories from disk. | scrape/utils.py | def remove_part_files(num_parts=None):
"""Remove PART(#).html files and image directories from disk."""
filenames = get_part_filenames(num_parts)
for filename in filenames:
remove_part_images(filename)
remove_file(filename) | def remove_part_files(num_parts=None):
"""Remove PART(#).html files and image directories from disk."""
filenames = get_part_filenames(num_parts)
for filename in filenames:
remove_part_images(filename)
remove_file(filename) | [
"Remove",
"PART",
"(",
"#",
")",
".",
"html",
"files",
"and",
"image",
"directories",
"from",
"disk",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L799-L804 | [
"def",
"remove_part_files",
"(",
"num_parts",
"=",
"None",
")",
":",
"filenames",
"=",
"get_part_filenames",
"(",
"num_parts",
")",
"for",
"filename",
"in",
"filenames",
":",
"remove_part_images",
"(",
"filename",
")",
"remove_file",
"(",
"filename",
")"
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | confirm_input | Check user input for yes, no, or an exit signal. | scrape/utils.py | def confirm_input(user_input):
"""Check user input for yes, no, or an exit signal."""
if isinstance(user_input, list):
user_input = ''.join(user_input)
try:
u_inp = user_input.lower().strip()
except AttributeError:
u_inp = user_input
# Check for exit signal
if u_inp in ... | def confirm_input(user_input):
"""Check user input for yes, no, or an exit signal."""
if isinstance(user_input, list):
user_input = ''.join(user_input)
try:
u_inp = user_input.lower().strip()
except AttributeError:
u_inp = user_input
# Check for exit signal
if u_inp in ... | [
"Check",
"user",
"input",
"for",
"yes",
"no",
"or",
"an",
"exit",
"signal",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L810-L825 | [
"def",
"confirm_input",
"(",
"user_input",
")",
":",
"if",
"isinstance",
"(",
"user_input",
",",
"list",
")",
":",
"user_input",
"=",
"''",
".",
"join",
"(",
"user_input",
")",
"try",
":",
"u_inp",
"=",
"user_input",
".",
"lower",
"(",
")",
".",
"strip... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | mkdir_and_cd | Change directory and/or create it if necessary. | scrape/utils.py | def mkdir_and_cd(dirname):
"""Change directory and/or create it if necessary."""
if not os.path.exists(dirname):
os.makedirs(dirname)
os.chdir(dirname)
else:
os.chdir(dirname) | def mkdir_and_cd(dirname):
"""Change directory and/or create it if necessary."""
if not os.path.exists(dirname):
os.makedirs(dirname)
os.chdir(dirname)
else:
os.chdir(dirname) | [
"Change",
"directory",
"and",
"/",
"or",
"create",
"it",
"if",
"necessary",
"."
] | huntrar/scrape | python | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L831-L837 | [
"def",
"mkdir_and_cd",
"(",
"dirname",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"dirname",
")",
":",
"os",
".",
"makedirs",
"(",
"dirname",
")",
"os",
".",
"chdir",
"(",
"dirname",
")",
"else",
":",
"os",
".",
"chdir",
"(",
"... | bf877f6da5df3ed0f2bea60a95acf7df63c88002 |
train | convert | Converts between two inputted chemical formats.
Args:
data: A string representing the chemical file to be converted. If the
`in_format` is "json", this can also be a Python object
in_format: The format of the `data` string. Can be "json" or any format
recognized by Open Babe... | imolecule/format_converter.py | def convert(data, in_format, out_format, name=None, pretty=False):
"""Converts between two inputted chemical formats.
Args:
data: A string representing the chemical file to be converted. If the
`in_format` is "json", this can also be a Python object
in_format: The format of the `dat... | def convert(data, in_format, out_format, name=None, pretty=False):
"""Converts between two inputted chemical formats.
Args:
data: A string representing the chemical file to be converted. If the
`in_format` is "json", this can also be a Python object
in_format: The format of the `dat... | [
"Converts",
"between",
"two",
"inputted",
"chemical",
"formats",
"."
] | patrickfuller/imolecule | python | https://github.com/patrickfuller/imolecule/blob/07e91600c805123935a78782871414754bd3696d/imolecule/format_converter.py#L19-L72 | [
"def",
"convert",
"(",
"data",
",",
"in_format",
",",
"out_format",
",",
"name",
"=",
"None",
",",
"pretty",
"=",
"False",
")",
":",
"# Decide on a json formatter depending on desired prettiness",
"dumps",
"=",
"json",
".",
"dumps",
"if",
"pretty",
"else",
"json... | 07e91600c805123935a78782871414754bd3696d |
train | json_to_pybel | Converts python data structure to pybel.Molecule.
This will infer bond data if not specified.
Args:
data: The loaded json data of a molecule, as a Python object
infer_bonds (Optional): If no bonds specified in input, infer them
Returns:
An instance of `pybel.Molecule` | imolecule/format_converter.py | def json_to_pybel(data, infer_bonds=False):
"""Converts python data structure to pybel.Molecule.
This will infer bond data if not specified.
Args:
data: The loaded json data of a molecule, as a Python object
infer_bonds (Optional): If no bonds specified in input, infer them
Returns:
... | def json_to_pybel(data, infer_bonds=False):
"""Converts python data structure to pybel.Molecule.
This will infer bond data if not specified.
Args:
data: The loaded json data of a molecule, as a Python object
infer_bonds (Optional): If no bonds specified in input, infer them
Returns:
... | [
"Converts",
"python",
"data",
"structure",
"to",
"pybel",
".",
"Molecule",
"."
] | patrickfuller/imolecule | python | https://github.com/patrickfuller/imolecule/blob/07e91600c805123935a78782871414754bd3696d/imolecule/format_converter.py#L75-L127 | [
"def",
"json_to_pybel",
"(",
"data",
",",
"infer_bonds",
"=",
"False",
")",
":",
"obmol",
"=",
"ob",
".",
"OBMol",
"(",
")",
"obmol",
".",
"BeginModify",
"(",
")",
"for",
"atom",
"in",
"data",
"[",
"'atoms'",
"]",
":",
"obatom",
"=",
"obmol",
".",
... | 07e91600c805123935a78782871414754bd3696d |
train | pybel_to_json | Converts a pybel molecule to json.
Args:
molecule: An instance of `pybel.Molecule`
name: (Optional) If specified, will save a "name" property
Returns:
A Python dictionary containing atom and bond data | imolecule/format_converter.py | def pybel_to_json(molecule, name=None):
"""Converts a pybel molecule to json.
Args:
molecule: An instance of `pybel.Molecule`
name: (Optional) If specified, will save a "name" property
Returns:
A Python dictionary containing atom and bond data
"""
# Save atom element type and... | def pybel_to_json(molecule, name=None):
"""Converts a pybel molecule to json.
Args:
molecule: An instance of `pybel.Molecule`
name: (Optional) If specified, will save a "name" property
Returns:
A Python dictionary containing atom and bond data
"""
# Save atom element type and... | [
"Converts",
"a",
"pybel",
"molecule",
"to",
"json",
"."
] | patrickfuller/imolecule | python | https://github.com/patrickfuller/imolecule/blob/07e91600c805123935a78782871414754bd3696d/imolecule/format_converter.py#L130-L193 | [
"def",
"pybel_to_json",
"(",
"molecule",
",",
"name",
"=",
"None",
")",
":",
"# Save atom element type and 3D location.",
"atoms",
"=",
"[",
"{",
"'element'",
":",
"table",
".",
"GetSymbol",
"(",
"atom",
".",
"atomicnum",
")",
",",
"'location'",
":",
"list",
... | 07e91600c805123935a78782871414754bd3696d |
train | CustomEncoder.default | Fired when an unserializable object is hit. | imolecule/json_formatter.py | def default(self, obj):
"""Fired when an unserializable object is hit."""
if hasattr(obj, '__dict__'):
return obj.__dict__.copy()
elif HAS_NUMPY and isinstance(obj, np.ndarray):
return obj.copy().tolist()
else:
raise TypeError(("Object of type {:s} wit... | def default(self, obj):
"""Fired when an unserializable object is hit."""
if hasattr(obj, '__dict__'):
return obj.__dict__.copy()
elif HAS_NUMPY and isinstance(obj, np.ndarray):
return obj.copy().tolist()
else:
raise TypeError(("Object of type {:s} wit... | [
"Fired",
"when",
"an",
"unserializable",
"object",
"is",
"hit",
"."
] | patrickfuller/imolecule | python | https://github.com/patrickfuller/imolecule/blob/07e91600c805123935a78782871414754bd3696d/imolecule/json_formatter.py#L37-L45 | [
"def",
"default",
"(",
"self",
",",
"obj",
")",
":",
"if",
"hasattr",
"(",
"obj",
",",
"'__dict__'",
")",
":",
"return",
"obj",
".",
"__dict__",
".",
"copy",
"(",
")",
"elif",
"HAS_NUMPY",
"and",
"isinstance",
"(",
"obj",
",",
"np",
".",
"ndarray",
... | 07e91600c805123935a78782871414754bd3696d |
train | draw | Draws an interactive 3D visualization of the inputted chemical.
Args:
data: A string or file representing a chemical.
format: The format of the `data` variable (default is 'auto').
size: Starting dimensions of visualization, in pixels.
drawing_type: Specifies the molecular represent... | imolecule/notebook.py | def draw(data, format='auto', size=(400, 300), drawing_type='ball and stick',
camera_type='perspective', shader='lambert', display_html=True,
element_properties=None, show_save=False):
"""Draws an interactive 3D visualization of the inputted chemical.
Args:
data: A string or file repr... | def draw(data, format='auto', size=(400, 300), drawing_type='ball and stick',
camera_type='perspective', shader='lambert', display_html=True,
element_properties=None, show_save=False):
"""Draws an interactive 3D visualization of the inputted chemical.
Args:
data: A string or file repr... | [
"Draws",
"an",
"interactive",
"3D",
"visualization",
"of",
"the",
"inputted",
"chemical",
"."
] | patrickfuller/imolecule | python | https://github.com/patrickfuller/imolecule/blob/07e91600c805123935a78782871414754bd3696d/imolecule/notebook.py#L30-L152 | [
"def",
"draw",
"(",
"data",
",",
"format",
"=",
"'auto'",
",",
"size",
"=",
"(",
"400",
",",
"300",
")",
",",
"drawing_type",
"=",
"'ball and stick'",
",",
"camera_type",
"=",
"'perspective'",
",",
"shader",
"=",
"'lambert'",
",",
"display_html",
"=",
"T... | 07e91600c805123935a78782871414754bd3696d |
train | generate | Converts input chemical formats to json and optimizes structure.
Args:
data: A string or file representing a chemical
format: The format of the `data` variable (default is 'auto')
The `format` can be any value specified by Open Babel
(http://openbabel.org/docs/2.3.1/FileFormats/Overview.ht... | imolecule/notebook.py | def generate(data, format="auto"):
"""Converts input chemical formats to json and optimizes structure.
Args:
data: A string or file representing a chemical
format: The format of the `data` variable (default is 'auto')
The `format` can be any value specified by Open Babel
(http://openba... | def generate(data, format="auto"):
"""Converts input chemical formats to json and optimizes structure.
Args:
data: A string or file representing a chemical
format: The format of the `data` variable (default is 'auto')
The `format` can be any value specified by Open Babel
(http://openba... | [
"Converts",
"input",
"chemical",
"formats",
"to",
"json",
"and",
"optimizes",
"structure",
"."
] | patrickfuller/imolecule | python | https://github.com/patrickfuller/imolecule/blob/07e91600c805123935a78782871414754bd3696d/imolecule/notebook.py#L155-L176 | [
"def",
"generate",
"(",
"data",
",",
"format",
"=",
"\"auto\"",
")",
":",
"# Support both files and strings and attempt to infer file type",
"try",
":",
"with",
"open",
"(",
"data",
")",
"as",
"in_file",
":",
"if",
"format",
"==",
"'auto'",
":",
"format",
"=",
... | 07e91600c805123935a78782871414754bd3696d |
train | to_json | Converts the output of `generate(...)` to formatted json.
Floats are rounded to three decimals and positional vectors are printed on
one line with some whitespace buffer. | imolecule/notebook.py | def to_json(data, compress=False):
"""Converts the output of `generate(...)` to formatted json.
Floats are rounded to three decimals and positional vectors are printed on
one line with some whitespace buffer.
"""
return json.compress(data) if compress else json.dumps(data) | def to_json(data, compress=False):
"""Converts the output of `generate(...)` to formatted json.
Floats are rounded to three decimals and positional vectors are printed on
one line with some whitespace buffer.
"""
return json.compress(data) if compress else json.dumps(data) | [
"Converts",
"the",
"output",
"of",
"generate",
"(",
"...",
")",
"to",
"formatted",
"json",
"."
] | patrickfuller/imolecule | python | https://github.com/patrickfuller/imolecule/blob/07e91600c805123935a78782871414754bd3696d/imolecule/notebook.py#L179-L185 | [
"def",
"to_json",
"(",
"data",
",",
"compress",
"=",
"False",
")",
":",
"return",
"json",
".",
"compress",
"(",
"data",
")",
"if",
"compress",
"else",
"json",
".",
"dumps",
"(",
"data",
")"
] | 07e91600c805123935a78782871414754bd3696d |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.