repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
huntrar/scrape | scrape/scrape.py | prompt_save_images | 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'
... | python | 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",
")",
":",
"if",
"args",
"[",
"'images'",
"]",
"or",
"args",
"[",
"'no_images'",
"]",
":",
"return",
"if",
"(",
"args",
"[",
"'pdf'",
"]",
"or",
"args",
"[",
"'html'",
"]",
")",
"and",
"(",
"args",
"[",
"'cr... | Prompt user to save images when crawling (for pdf and HTML formats). | [
"Prompt",
"user",
"to",
"save",
"images",
"when",
"crawling",
"(",
"for",
"pdf",
"and",
"HTML",
"formats",
")",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L275-L289 |
huntrar/scrape | scrape/scrape.py | command_line_runner | 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... | python | 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",
"(",
")",
":",
"parser",
"=",
"get_parser",
"(",
")",
"args",
"=",
"vars",
"(",
"parser",
".",
"parse_args",
"(",
")",
")",
"if",
"args",
"[",
"'version'",
"]",
":",
"print",
"(",
"__version__",
")",
"return",
"if",
"args"... | Handle command-line interaction. | [
"Handle",
"command",
"-",
"line",
"interaction",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L292-L322 |
chrisspen/weka | weka/classifiers.py | Classifier.load_raw | 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... | python | 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",
")",
":",
"c",
"=",
"cls",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"c",
".",
"schema",
"=",
"schema",
".",
"copy",
"(",
"schema_on... | 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. | [
"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",
".... | train | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/classifiers.py#L270-L279 |
chrisspen/weka | weka/classifiers.py | Classifier.train | 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... | python | 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",
")",
":",
"model_fn",
"=",
"None",
"training_fn",
"=",
"None",
"clean_training",
"=",
"False",
"testing_fn",
"=",
"None",
"clean_testing",
"=",... | Updates the classifier with new data. | [
"Updates",
"the",
"classifier",
"with",
"new",
"data",
"."
] | train | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/classifiers.py#L312-L417 |
chrisspen/weka | weka/classifiers.py | Classifier.predict | 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... | python | 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",
")",
":",
"model_fn",
"=",
"None",
"query_fn",
"=",
"None",
"clean_query",
"=",
"False",
"stdout",
"=",
"None"... | 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... | [
"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",
... | train | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/classifiers.py#L419-L592 |
chrisspen/weka | weka/classifiers.py | EnsembleClassifier.get_training_coverage | 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) | python | 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",
")",
":",
"total",
"=",
"len",
"(",
"self",
".",
"training_results",
")",
"i",
"=",
"sum",
"(",
"1",
"for",
"data",
"in",
"self",
".",
"training_results",
".",
"values",
"(",
")",
"if",
"not",
"isinstance",
... | Returns a ratio of classifiers that were able to be trained successfully. | [
"Returns",
"a",
"ratio",
"of",
"classifiers",
"that",
"were",
"able",
"to",
"be",
"trained",
"successfully",
"."
] | train | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/classifiers.py#L640-L646 |
huntrar/scrape | scrape/crawler.py | Crawler.get_new_links | 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... | python | 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",
")",
":",
"links_on_page",
"=",
"resp",
".",
"xpath",
"(",
"'//a/@href'",
")",
"links",
"=",
"[",
"utils",
".",
"clean_url",
"(",
"u",
",",
"url",
")",
"for",
"u",
"in",
"links_on_page",
"... | Get new links from a URL and filter them. | [
"Get",
"new",
"links",
"from",
"a",
"URL",
"and",
"filter",
"them",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/crawler.py#L20-L36 |
huntrar/scrape | scrape/crawler.py | Crawler.page_crawled | 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))
... | python | 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",
")",
":",
"page_text",
"=",
"utils",
".",
"parse_text",
"(",
"page_resp",
")",
"page_hash",
"=",
"utils",
".",
"hash_text",
"(",
"''",
".",
"join",
"(",
"page_text",
")",
")",
"if",
"page_hash",
"not"... | 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. | [
"Check",
"if",
"page",
"has",
"been",
"crawled",
"by",
"hashing",
"its",
"text",
"content",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/crawler.py#L42-L53 |
huntrar/scrape | scrape/crawler.py | Crawler.crawl_links | 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... | python | 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",
")",
":",
"if",
"seed_url",
"is",
"not",
"None",
":",
"self",
".",
"seed_url",
"=",
"seed_url",
"if",
"self",
".",
"seed_url",
"is",
"None",
":",
"sys",
".",
"stderr",
".",
"write",
"("... | 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. | [
"Find",
"new",
"links",
"given",
"a",
"seed",
"URL",
"and",
"follow",
"them",
"breadth",
"-",
"first",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/crawler.py#L55-L105 |
huntrar/scrape | scrape/utils.py | get_proxies | 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... | python | 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",
"(",
")",
":",
"proxies",
"=",
"getproxies",
"(",
")",
"filtered_proxies",
"=",
"{",
"}",
"for",
"key",
",",
"value",
"in",
"proxies",
".",
"items",
"(",
")",
":",
"if",
"key",
".",
"startswith",
"(",
"'http://'",
")",
":",
"if"... | Get available proxies to use with requests library. | [
"Get",
"available",
"proxies",
"to",
"use",
"with",
"requests",
"library",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L63-L73 |
huntrar/scrape | scrape/utils.py | get_resp | 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)
... | python | 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",
")",
":",
"try",
":",
"headers",
"=",
"{",
"'User-Agent'",
":",
"random",
".",
"choice",
"(",
"USER_AGENTS",
")",
"}",
"try",
":",
"request",
"=",
"requests",
".",
"get",
"(",
"url",
",",
"headers",
"=",
"headers",
",",... | Get webpage response as an lxml.html.HtmlElement object. | [
"Get",
"webpage",
"response",
"as",
"an",
"lxml",
".",
"html",
".",
"HtmlElement",
"object",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L76-L88 |
huntrar/scrape | scrape/utils.py | enable_cache | 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... | python | 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",
"(",
")",
":",
"try",
":",
"import",
"requests_cache",
"except",
"ImportError",
"as",
"err",
":",
"sys",
".",
"stderr",
".",
"write",
"(",
"'Failed to enable cache: {0}\\n'",
".",
"format",
"(",
"str",
"(",
"err",
")",
")",
")",
"ret... | Enable requests library cache. | [
"Enable",
"requests",
"library",
"cache",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L106-L115 |
huntrar/scrape | scrape/utils.py | hash_text | def hash_text(text):
"""Return MD5 hash of a string."""
md5 = hashlib.md5()
md5.update(text)
return md5.hexdigest() | python | def hash_text(text):
"""Return MD5 hash of a string."""
md5 = hashlib.md5()
md5.update(text)
return md5.hexdigest() | [
"def",
"hash_text",
"(",
"text",
")",
":",
"md5",
"=",
"hashlib",
".",
"md5",
"(",
")",
"md5",
".",
"update",
"(",
"text",
")",
"return",
"md5",
".",
"hexdigest",
"(",
")"
] | Return MD5 hash of a string. | [
"Return",
"MD5",
"hash",
"of",
"a",
"string",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L127-L131 |
huntrar/scrape | scrape/utils.py | cache_page | 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) | python | 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",
")",
":",
"page_cache",
".",
"append",
"(",
"page_hash",
")",
"if",
"len",
"(",
"page_cache",
")",
">",
"cache_size",
":",
"page_cache",
".",
"pop",
"(",
"0",
")"
] | Add a page to the page cache. | [
"Add",
"a",
"page",
"to",
"the",
"page",
"cache",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L134-L138 |
huntrar/scrape | scrape/utils.py | re_filter | 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:
... | python | 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",
")",
":",
"if",
"not",
"regexps",
":",
"return",
"text",
"matched_text",
"=",
"[",
"]",
"compiled_regexps",
"=",
"[",
"re",
".",
"compile",
"(",
"x",
")",
"for",
"x",
"in",
"regexps",
"]",
"for",
"line... | Filter text using regular expressions. | [
"Filter",
"text",
"using",
"regular",
"expressions",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L144-L160 |
huntrar/scrape | scrape/utils.py | remove_whitespace | 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.
"""
... | python | 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",
")",
":",
"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... | 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",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L163-L211 |
huntrar/scrape | scrape/utils.py | parse_text | 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... | python | 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",
")",
":",
"infiles",
"=",
"[",
"]",
"text",
"=",
"[",
"]",
"if",
"xpath",
"is",
"not",
"None",
":",
"infile",
"=",
"par... | 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. | [
"Filter",
"text",
"using",
"XPath",
"regex",
"keywords",
"and",
"tag",
"attributes",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L214-L261 |
huntrar/scrape | scrape/utils.py | get_parsed_text | 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... | python | 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",
")",
":",
"parsed_text",
"=",
"[",
"]",
"if",
"infilename",
".",
"endswith",
"(",
"'.html'",
")",
":",
"# Convert HTML to lxml object for content parsing",
"html",
"=",
"lh",
".",
"fromstring",
"(",
"read... | 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. | [
"Parse",
"and",
"return",
"text",
"content",
"of",
"infiles",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L264-L291 |
huntrar/scrape | scrape/utils.py | parse_html | 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 | python | 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",
")",
":",
"if",
"not",
"isinstance",
"(",
"infile",
",",
"lh",
".",
"HtmlElement",
")",
":",
"infile",
"=",
"lh",
".",
"fromstring",
"(",
"infile",
")",
"infile",
"=",
"infile",
".",
"xpath",
"(",
"xp... | Filter HTML using XPath. | [
"Filter",
"HTML",
"using",
"XPath",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L309-L316 |
huntrar/scrape | scrape/utils.py | clean_url | 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 = '... | python | 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",
")",
":",
"parsed_url",
"=",
"urlparse",
"(",
"url",
")",
"fragment",
"=",
"'{url.fragment}'",
".",
"format",
"(",
"url",
"=",
"parsed_url",
")",
"if",
"fragment",
":",
"url",
"=",
"url",
".... | Add base netloc and path to internal URLs and remove www, fragments. | [
"Add",
"base",
"netloc",
"and",
"path",
"to",
"internal",
"URLs",
"and",
"remove",
"www",
"fragments",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L348-L366 |
huntrar/scrape | scrape/utils.py | add_url_suffix | 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 | python | 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",
")",
":",
"url",
"=",
"url",
".",
"rstrip",
"(",
"'/'",
")",
"if",
"not",
"has_suffix",
"(",
"url",
")",
":",
"return",
"'{0}.com'",
".",
"format",
"(",
"url",
")",
"return",
"url"
] | Add .com suffix to URL if none found. | [
"Add",
".",
"com",
"suffix",
"to",
"URL",
"if",
"none",
"found",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L374-L379 |
huntrar/scrape | scrape/utils.py | get_outfilename | 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... | python | 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",
")",
":",
"if",
"domain",
"is",
"None",
":",
"domain",
"=",
"get_domain",
"(",
"url",
")",
"path",
"=",
"'{url.path}'",
".",
"format",
"(",
"url",
"=",
"urlparse",
"(",
"url",
")",
")"... | Construct the output filename from domain and end of path. | [
"Construct",
"the",
"output",
"filename",
"from",
"domain",
"and",
"end",
"of",
"path",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L385-L426 |
huntrar/scrape | scrape/utils.py | get_single_outfilename | 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(... | python | 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",
")",
":",
"for",
"arg",
"in",
"args",
"[",
"'query'",
"]",
":",
"if",
"arg",
"in",
"args",
"[",
"'files'",
"]",
":",
"return",
"(",
"'.'",
".",
"join",
"(",
"arg",
".",
"split",
"(",
"'.'",
")",
"[",
... | Use first possible entry in query as filename. | [
"Use",
"first",
"possible",
"entry",
"in",
"query",
"as",
"filename",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L429-L439 |
huntrar/scrape | scrape/utils.py | modify_filename_id | 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... | python | 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",
")",
":",
"split_filename",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"filename",
")",
"id_num_re",
"=",
"re",
".",
"compile",
"(",
"'(\\(\\d\\))'",
")",
"id_num",
"=",
"re",
".",
"findall",
"(",
"id_num_re... | Modify filename to have a unique numerical identifier. | [
"Modify",
"filename",
"to",
"have",
"a",
"unique",
"numerical",
"identifier",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L451-L468 |
huntrar/scrape | scrape/utils.py | overwrite_file_check | 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... | python | 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",
"not",
"args",
"[",
"'overwrite'",
"]",
"and",
"os",
".",
"path",
".",
"exists",
"(",
"filename",
")",
":",
"# Confirm overwriting of the file, or modify filename",
"if",
"args",
"[",
... | If filename exists, overwrite or modify it to be unique. | [
"If",
"filename",
"exists",
"overwrite",
"or",
"modify",
"it",
"to",
"be",
"unique",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L471-L488 |
huntrar/scrape | scrape/utils.py | print_text | 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... | python | 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",
")",
":",
"for",
"infilename",
"in",
"infilenames",
":",
"parsed_text",
"=",
"get_parsed_text",
"(",
"args",
",",
"infilename",
")",
"if",
"parsed_text",
":",
"for",
"line... | 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) | [
"Print",
"text",
"content",
"of",
"infiles",
"to",
"stdout",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L491-L504 |
huntrar/scrape | scrape/utils.py | write_pdf_files | 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... | python | 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",
")",
":",
"if",
"not",
"outfilename",
".",
"endswith",
"(",
"'.pdf'",
")",
":",
"outfilename",
"=",
"outfilename",
"+",
"'.pdf'",
"outfilename",
"=",
"overwrite_file_check",
"(",
"a... | 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) | [
"Write",
"pdf",
"file",
"(",
"s",
")",
"to",
"disk",
"using",
"pdfkit",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L507-L575 |
huntrar/scrape | scrape/utils.py | write_csv_files | 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... | python | 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",
")",
":",
"def",
"csv_convert",
"(",
"line",
")",
":",
"\"\"\"Strip punctuation and insert commas\"\"\"",
"clean_line",
"=",
"[",
"]",
"for",
"word",
"in",
"line",
".",
"split",
"(",
... | 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) | [
"Write",
"csv",
"file",
"(",
"s",
")",
"to",
"disk",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L578-L622 |
huntrar/scrape | scrape/utils.py | write_text_files | 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')... | python | 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",
")",
":",
"if",
"not",
"outfilename",
".",
"endswith",
"(",
"'.txt'",
")",
":",
"outfilename",
"=",
"outfilename",
"+",
"'.txt'",
"outfilename",
"=",
"overwrite_file_check",
"(",
"... | 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) | [
"Write",
"text",
"file",
"(",
"s",
")",
"to",
"disk",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L625-L656 |
huntrar/scrape | scrape/utils.py | write_file | 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... | python | 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",
")",
":",
"if",
"not",
"data",
":",
"return",
"False",
"try",
":",
"with",
"open",
"(",
"outfilename",
",",
"'w'",
")",
"as",
"outfile",
":",
"for",
"line",
"in",
"data",
":",
"if",
"line",
":",
... | Write a single file to disk. | [
"Write",
"a",
"single",
"file",
"to",
"disk",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L659-L672 |
huntrar/scrape | scrape/utils.py | get_num_part_files | 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 | python | 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",
"(",
")",
":",
"num_parts",
"=",
"0",
"for",
"filename",
"in",
"os",
".",
"listdir",
"(",
"os",
".",
"getcwd",
"(",
")",
")",
":",
"if",
"filename",
".",
"startswith",
"(",
"'PART'",
")",
"and",
"filename",
".",
"endswith",... | Get the number of PART.html files currently saved to disk. | [
"Get",
"the",
"number",
"of",
"PART",
".",
"html",
"files",
"currently",
"saved",
"to",
"disk",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L675-L681 |
huntrar/scrape | scrape/utils.py | write_part_images | 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... | python | 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",
")",
":",
"save_dirname",
"=",
"'{0}_files'",
".",
"format",
"(",
"os",
".",
"path",
".",
"splitext",
"(",
"filename",
")",
"[",
"0",
"]",
")",
"if",
"not",
"os",
... | 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.... | [
"Write",
"image",
"file",
"(",
"s",
")",
"associated",
"with",
"HTML",
"to",
"disk",
"substituting",
"filenames",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L684-L725 |
huntrar/scrape | scrape/utils.py | write_part_file | 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... | python | 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",
")",
":",
"if",
"part_num",
"is",
"None",
":",
"part_num",
"=",
"get_num_part_files",
"(",
")",
"+",
"1",
"filename",
"=",
"'PAR... | 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) | [
"Write",
"PART",
".",
"html",
"file",
"(",
"s",
")",
"to",
"disk",
"images",
"in",
"PART_files",
"directory",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L728-L771 |
huntrar/scrape | scrape/utils.py | get_part_filenames | 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)] | python | 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",
")",
":",
"if",
"num_parts",
"is",
"None",
":",
"num_parts",
"=",
"get_num_part_files",
"(",
")",
"return",
"[",
"'PART{0}.html'",
".",
"format",
"(",
"i",
")",
"for",
... | Get numbered PART.html filenames. | [
"Get",
"numbered",
"PART",
".",
"html",
"filenames",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L774-L778 |
huntrar/scrape | scrape/utils.py | read_files | 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() | python | 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",
")",
":",
"if",
"isinstance",
"(",
"filenames",
",",
"list",
")",
":",
"for",
"filename",
"in",
"filenames",
":",
"with",
"open",
"(",
"filename",
",",
"'r'",
")",
"as",
"infile",
":",
"return",
"infile",
".",
"re... | Read a file into memory. | [
"Read",
"a",
"file",
"into",
"memory",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L781-L789 |
huntrar/scrape | scrape/utils.py | remove_part_images | 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) | python | 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",
")",
":",
"dirname",
"=",
"'{0}_files'",
".",
"format",
"(",
"os",
".",
"path",
".",
"splitext",
"(",
"filename",
")",
"[",
"0",
"]",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"dirname",
")",
":",... | Remove PART(#)_files directory containing images from disk. | [
"Remove",
"PART",
"(",
"#",
")",
"_files",
"directory",
"containing",
"images",
"from",
"disk",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L792-L796 |
huntrar/scrape | scrape/utils.py | remove_part_files | 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) | python | 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",
")",
":",
"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. | [
"Remove",
"PART",
"(",
"#",
")",
".",
"html",
"files",
"and",
"image",
"directories",
"from",
"disk",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L799-L804 |
huntrar/scrape | scrape/utils.py | confirm_input | 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 ... | python | 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",
")",
":",
"if",
"isinstance",
"(",
"user_input",
",",
"list",
")",
":",
"user_input",
"=",
"''",
".",
"join",
"(",
"user_input",
")",
"try",
":",
"u_inp",
"=",
"user_input",
".",
"lower",
"(",
")",
".",
"strip... | Check user input for yes, no, or an exit signal. | [
"Check",
"user",
"input",
"for",
"yes",
"no",
"or",
"an",
"exit",
"signal",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L810-L825 |
huntrar/scrape | scrape/utils.py | mkdir_and_cd | 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) | python | 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",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"dirname",
")",
":",
"os",
".",
"makedirs",
"(",
"dirname",
")",
"os",
".",
"chdir",
"(",
"dirname",
")",
"else",
":",
"os",
".",
"chdir",
"(",
"... | Change directory and/or create it if necessary. | [
"Change",
"directory",
"and",
"/",
"or",
"create",
"it",
"if",
"necessary",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L831-L837 |
patrickfuller/imolecule | imolecule/format_converter.py | convert | 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... | python | 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",
")",
":",
"# Decide on a json formatter depending on desired prettiness",
"dumps",
"=",
"json",
".",
"dumps",
"if",
"pretty",
"else",
"json... | 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... | [
"Converts",
"between",
"two",
"inputted",
"chemical",
"formats",
"."
] | train | https://github.com/patrickfuller/imolecule/blob/07e91600c805123935a78782871414754bd3696d/imolecule/format_converter.py#L19-L72 |
patrickfuller/imolecule | imolecule/format_converter.py | json_to_pybel | 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:
... | python | 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",
")",
":",
"obmol",
"=",
"ob",
".",
"OBMol",
"(",
")",
"obmol",
".",
"BeginModify",
"(",
")",
"for",
"atom",
"in",
"data",
"[",
"'atoms'",
"]",
":",
"obatom",
"=",
"obmol",
".",
... | 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` | [
"Converts",
"python",
"data",
"structure",
"to",
"pybel",
".",
"Molecule",
"."
] | train | https://github.com/patrickfuller/imolecule/blob/07e91600c805123935a78782871414754bd3696d/imolecule/format_converter.py#L75-L127 |
patrickfuller/imolecule | imolecule/format_converter.py | pybel_to_json | 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... | python | 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",
")",
":",
"# Save atom element type and 3D location.",
"atoms",
"=",
"[",
"{",
"'element'",
":",
"table",
".",
"GetSymbol",
"(",
"atom",
".",
"atomicnum",
")",
",",
"'location'",
":",
"list",
... | 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 | [
"Converts",
"a",
"pybel",
"molecule",
"to",
"json",
"."
] | train | https://github.com/patrickfuller/imolecule/blob/07e91600c805123935a78782871414754bd3696d/imolecule/format_converter.py#L130-L193 |
patrickfuller/imolecule | imolecule/json_formatter.py | CustomEncoder.default | 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... | python | 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",
")",
":",
"if",
"hasattr",
"(",
"obj",
",",
"'__dict__'",
")",
":",
"return",
"obj",
".",
"__dict__",
".",
"copy",
"(",
")",
"elif",
"HAS_NUMPY",
"and",
"isinstance",
"(",
"obj",
",",
"np",
".",
"ndarray",
... | Fired when an unserializable object is hit. | [
"Fired",
"when",
"an",
"unserializable",
"object",
"is",
"hit",
"."
] | train | https://github.com/patrickfuller/imolecule/blob/07e91600c805123935a78782871414754bd3696d/imolecule/json_formatter.py#L37-L45 |
patrickfuller/imolecule | imolecule/notebook.py | draw | 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... | python | 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",
"=",
"T... | 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... | [
"Draws",
"an",
"interactive",
"3D",
"visualization",
"of",
"the",
"inputted",
"chemical",
"."
] | train | https://github.com/patrickfuller/imolecule/blob/07e91600c805123935a78782871414754bd3696d/imolecule/notebook.py#L30-L152 |
patrickfuller/imolecule | imolecule/notebook.py | generate | 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... | python | 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\"",
")",
":",
"# Support both files and strings and attempt to infer file type",
"try",
":",
"with",
"open",
"(",
"data",
")",
"as",
"in_file",
":",
"if",
"format",
"==",
"'auto'",
":",
"format",
"=",
... | 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... | [
"Converts",
"input",
"chemical",
"formats",
"to",
"json",
"and",
"optimizes",
"structure",
"."
] | train | https://github.com/patrickfuller/imolecule/blob/07e91600c805123935a78782871414754bd3696d/imolecule/notebook.py#L155-L176 |
patrickfuller/imolecule | imolecule/notebook.py | to_json | 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) | python | 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",
")",
":",
"return",
"json",
".",
"compress",
"(",
"data",
")",
"if",
"compress",
"else",
"json",
".",
"dumps",
"(",
"data",
")"
] | 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. | [
"Converts",
"the",
"output",
"of",
"generate",
"(",
"...",
")",
"to",
"formatted",
"json",
"."
] | train | https://github.com/patrickfuller/imolecule/blob/07e91600c805123935a78782871414754bd3696d/imolecule/notebook.py#L179-L185 |
patrickfuller/imolecule | imolecule/server/server.py | start_server | def start_server():
"""Starts up the imolecule server, complete with argparse handling."""
parser = argparse.ArgumentParser(description="Opens a browser-based "
"client that interfaces with the "
"chemical format converter.")
parser.a... | python | def start_server():
"""Starts up the imolecule server, complete with argparse handling."""
parser = argparse.ArgumentParser(description="Opens a browser-based "
"client that interfaces with the "
"chemical format converter.")
parser.a... | [
"def",
"start_server",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"\"Opens a browser-based \"",
"\"client that interfaces with the \"",
"\"chemical format converter.\"",
")",
"parser",
".",
"add_argument",
"(",
"'--debug'",
"... | Starts up the imolecule server, complete with argparse handling. | [
"Starts",
"up",
"the",
"imolecule",
"server",
"complete",
"with",
"argparse",
"handling",
"."
] | train | https://github.com/patrickfuller/imolecule/blob/07e91600c805123935a78782871414754bd3696d/imolecule/server/server.py#L69-L105 |
patrickfuller/imolecule | imolecule/server/server.py | WebSocket.on_message | def on_message(self, message):
"""Evaluates the function pointed to by json-rpc."""
json_rpc = json.loads(message)
logging.log(logging.DEBUG, json_rpc)
if self.pool is None:
self.pool = multiprocessing.Pool(processes=args.workers)
# Spawn a process to protect the se... | python | def on_message(self, message):
"""Evaluates the function pointed to by json-rpc."""
json_rpc = json.loads(message)
logging.log(logging.DEBUG, json_rpc)
if self.pool is None:
self.pool = multiprocessing.Pool(processes=args.workers)
# Spawn a process to protect the se... | [
"def",
"on_message",
"(",
"self",
",",
"message",
")",
":",
"json_rpc",
"=",
"json",
".",
"loads",
"(",
"message",
")",
"logging",
".",
"log",
"(",
"logging",
".",
"DEBUG",
",",
"json_rpc",
")",
"if",
"self",
".",
"pool",
"is",
"None",
":",
"self",
... | Evaluates the function pointed to by json-rpc. | [
"Evaluates",
"the",
"function",
"pointed",
"to",
"by",
"json",
"-",
"rpc",
"."
] | train | https://github.com/patrickfuller/imolecule/blob/07e91600c805123935a78782871414754bd3696d/imolecule/server/server.py#L39-L66 |
JnyJny/Geometry | Geometry/constants.py | nearly_eq | def nearly_eq(valA, valB, maxf=None, minf=None, epsilon=None):
'''
implementation based on:
http://floating-point-gui.de/errors/comparison/
'''
if valA == valB:
return True
if maxf is None:
maxf = float_info.max
if minf is None:
minf = float_info.min
if epsil... | python | def nearly_eq(valA, valB, maxf=None, minf=None, epsilon=None):
'''
implementation based on:
http://floating-point-gui.de/errors/comparison/
'''
if valA == valB:
return True
if maxf is None:
maxf = float_info.max
if minf is None:
minf = float_info.min
if epsil... | [
"def",
"nearly_eq",
"(",
"valA",
",",
"valB",
",",
"maxf",
"=",
"None",
",",
"minf",
"=",
"None",
",",
"epsilon",
"=",
"None",
")",
":",
"if",
"valA",
"==",
"valB",
":",
"return",
"True",
"if",
"maxf",
"is",
"None",
":",
"maxf",
"=",
"float_info",
... | implementation based on:
http://floating-point-gui.de/errors/comparison/ | [
"implementation",
"based",
"on",
":"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/constants.py#L12-L38 |
JnyJny/Geometry | Geometry/point.py | Point._convert | def _convert(cls, other, ignoreScalars=False):
'''
:other: Point or point equivalent
:ignorescalars: optional boolean
:return: Point
Class private method for converting 'other' into a Point
subclasss. If 'other' already is a Point subclass, nothing
is done. If ig... | python | def _convert(cls, other, ignoreScalars=False):
'''
:other: Point or point equivalent
:ignorescalars: optional boolean
:return: Point
Class private method for converting 'other' into a Point
subclasss. If 'other' already is a Point subclass, nothing
is done. If ig... | [
"def",
"_convert",
"(",
"cls",
",",
"other",
",",
"ignoreScalars",
"=",
"False",
")",
":",
"if",
"ignoreScalars",
":",
"if",
"isinstance",
"(",
"other",
",",
"(",
"int",
",",
"float",
")",
")",
":",
"msg",
"=",
"\"unable to convert {} to {}\"",
".",
"for... | :other: Point or point equivalent
:ignorescalars: optional boolean
:return: Point
Class private method for converting 'other' into a Point
subclasss. If 'other' already is a Point subclass, nothing
is done. If ignoreScalars is True and other is a float or int
type, a Typ... | [
":",
"other",
":",
"Point",
"or",
"point",
"equivalent",
":",
"ignorescalars",
":",
"optional",
"boolean",
":",
"return",
":",
"Point"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/point.py#L115-L131 |
JnyJny/Geometry | Geometry/point.py | Point.units | def units(cls, scale=1):
'''
:scale: optional integer scaling factor
:return: list of three Point subclass
Returns three points whose coordinates are the head of a
unit vector from the origin ( conventionally i, j and k).
'''
return [cls(x=scale), cls(y=scale), ... | python | def units(cls, scale=1):
'''
:scale: optional integer scaling factor
:return: list of three Point subclass
Returns three points whose coordinates are the head of a
unit vector from the origin ( conventionally i, j and k).
'''
return [cls(x=scale), cls(y=scale), ... | [
"def",
"units",
"(",
"cls",
",",
"scale",
"=",
"1",
")",
":",
"return",
"[",
"cls",
"(",
"x",
"=",
"scale",
")",
",",
"cls",
"(",
"y",
"=",
"scale",
")",
",",
"cls",
"(",
"z",
"=",
"scale",
")",
"]"
] | :scale: optional integer scaling factor
:return: list of three Point subclass
Returns three points whose coordinates are the head of a
unit vector from the origin ( conventionally i, j and k). | [
":",
"scale",
":",
"optional",
"integer",
"scaling",
"factor",
":",
"return",
":",
"list",
"of",
"three",
"Point",
"subclass"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/point.py#L148-L157 |
JnyJny/Geometry | Geometry/point.py | Point.gaussian | def gaussian(cls, mu=0, sigma=1):
'''
:mu: mean
:sigma: standard deviation
:return: Point subclass
Returns a point whose coordinates are picked from a Gaussian
distribution with mean 'mu' and standard deviation 'sigma'.
See random.gauss for further explanati... | python | def gaussian(cls, mu=0, sigma=1):
'''
:mu: mean
:sigma: standard deviation
:return: Point subclass
Returns a point whose coordinates are picked from a Gaussian
distribution with mean 'mu' and standard deviation 'sigma'.
See random.gauss for further explanati... | [
"def",
"gaussian",
"(",
"cls",
",",
"mu",
"=",
"0",
",",
"sigma",
"=",
"1",
")",
":",
"return",
"cls",
"(",
"random",
".",
"gauss",
"(",
"mu",
",",
"sigma",
")",
",",
"random",
".",
"gauss",
"(",
"mu",
",",
"sigma",
")",
",",
"random",
".",
"... | :mu: mean
:sigma: standard deviation
:return: Point subclass
Returns a point whose coordinates are picked from a Gaussian
distribution with mean 'mu' and standard deviation 'sigma'.
See random.gauss for further explanation of those parameters. | [
":",
"mu",
":",
"mean",
":",
"sigma",
":",
"standard",
"deviation",
":",
"return",
":",
"Point",
"subclass"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/point.py#L160-L172 |
JnyJny/Geometry | Geometry/point.py | Point.random | def random(cls, origin=None, radius=1):
'''
:origin: optional Point or point equivalent
:radius: optional float, radius around origin
:return: Point subclass
Returns a point with random x, y and z coordinates bounded by
the sphere defined by (origin,radius).
If ... | python | def random(cls, origin=None, radius=1):
'''
:origin: optional Point or point equivalent
:radius: optional float, radius around origin
:return: Point subclass
Returns a point with random x, y and z coordinates bounded by
the sphere defined by (origin,radius).
If ... | [
"def",
"random",
"(",
"cls",
",",
"origin",
"=",
"None",
",",
"radius",
"=",
"1",
")",
":",
"p",
"=",
"cls",
"(",
"origin",
")",
"r",
"=",
"random",
".",
"uniform",
"(",
"0",
",",
"radius",
")",
"u",
"=",
"random",
".",
"uniform",
"(",
"0",
"... | :origin: optional Point or point equivalent
:radius: optional float, radius around origin
:return: Point subclass
Returns a point with random x, y and z coordinates bounded by
the sphere defined by (origin,radius).
If a sphere is not supplied, a unit sphere at the origin is
... | [
":",
"origin",
":",
"optional",
"Point",
"or",
"point",
"equivalent",
":",
"radius",
":",
"optional",
"float",
"radius",
"around",
"origin",
":",
"return",
":",
"Point",
"subclass"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/point.py#L175-L200 |
JnyJny/Geometry | Geometry/point.py | Point._binary_ | def _binary_(self, other, func, inplace=False):
'''
:other: Point or point equivalent
:func: binary function to apply
:inplace: optional boolean
:return: Point
Implementation private method.
All of the binary operations funnel thru this method to
r... | python | def _binary_(self, other, func, inplace=False):
'''
:other: Point or point equivalent
:func: binary function to apply
:inplace: optional boolean
:return: Point
Implementation private method.
All of the binary operations funnel thru this method to
r... | [
"def",
"_binary_",
"(",
"self",
",",
"other",
",",
"func",
",",
"inplace",
"=",
"False",
")",
":",
"dst",
"=",
"self",
"if",
"inplace",
"else",
"self",
".",
"__class__",
"(",
"self",
")",
"try",
":",
"b",
"=",
"self",
".",
"__class__",
".",
"_conve... | :other: Point or point equivalent
:func: binary function to apply
:inplace: optional boolean
:return: Point
Implementation private method.
All of the binary operations funnel thru this method to
reduce cut-and-paste code and enforce consistent behavior
of ... | [
":",
"other",
":",
"Point",
"or",
"point",
"equivalent",
":",
"func",
":",
"binary",
"function",
"to",
"apply",
":",
"inplace",
":",
"optional",
"boolean",
":",
"return",
":",
"Point"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/point.py#L466-L502 |
JnyJny/Geometry | Geometry/point.py | Point._unary_ | def _unary_(self, func, inplace=False):
'''
:func: unary function to apply to each coordinate
:inplace: optional boolean
:return: Point
Implementation private method.
All of the unary operations funnel thru this method
to reduce cut-and-paste code and enforce co... | python | def _unary_(self, func, inplace=False):
'''
:func: unary function to apply to each coordinate
:inplace: optional boolean
:return: Point
Implementation private method.
All of the unary operations funnel thru this method
to reduce cut-and-paste code and enforce co... | [
"def",
"_unary_",
"(",
"self",
",",
"func",
",",
"inplace",
"=",
"False",
")",
":",
"dst",
"=",
"self",
"if",
"inplace",
"else",
"self",
".",
"__class__",
"(",
"self",
")",
"dst",
".",
"x",
"=",
"func",
"(",
"dst",
".",
"x",
")",
"dst",
".",
"y... | :func: unary function to apply to each coordinate
:inplace: optional boolean
:return: Point
Implementation private method.
All of the unary operations funnel thru this method
to reduce cut-and-paste code and enforce consistent
behavior of unary ops.
Applies 'fu... | [
":",
"func",
":",
"unary",
"function",
"to",
"apply",
"to",
"each",
"coordinate",
":",
"inplace",
":",
"optional",
"boolean",
":",
"return",
":",
"Point"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/point.py#L504-L530 |
JnyJny/Geometry | Geometry/point.py | Point.cross | def cross(self, other):
'''
:other: Point or point equivalent
:return: float
Vector cross product of points U (self) and V (other), computed:
U x V = (u1*i + u2*j + u3*k) x (v1*i + v2*j + v3*k)
s1 = u2v3 - u3v2
s2 = u3v1 - u1v3
s3 = u1v2 - u2v1
... | python | def cross(self, other):
'''
:other: Point or point equivalent
:return: float
Vector cross product of points U (self) and V (other), computed:
U x V = (u1*i + u2*j + u3*k) x (v1*i + v2*j + v3*k)
s1 = u2v3 - u3v2
s2 = u3v1 - u1v3
s3 = u1v2 - u2v1
... | [
"def",
"cross",
"(",
"self",
",",
"other",
")",
":",
"b",
"=",
"self",
".",
"__class__",
".",
"_convert",
"(",
"other",
")",
"return",
"sum",
"(",
"[",
"(",
"self",
".",
"y",
"*",
"b",
".",
"z",
")",
"-",
"(",
"self",
".",
"z",
"*",
"b",
".... | :other: Point or point equivalent
:return: float
Vector cross product of points U (self) and V (other), computed:
U x V = (u1*i + u2*j + u3*k) x (v1*i + v2*j + v3*k)
s1 = u2v3 - u3v2
s2 = u3v1 - u1v3
s3 = u1v2 - u2v1
U x V = s1 + s2 + s3
Returns a floa... | [
":",
"other",
":",
"Point",
"or",
"point",
"equivalent",
":",
"return",
":",
"float"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/point.py#L1260-L1281 |
JnyJny/Geometry | Geometry/point.py | Point.isBetween | def isBetween(self, a, b, axes='xyz'):
'''
:a: Point or point equivalent
:b: Point or point equivalent
:axis: optional string
:return: float
Checks the coordinates specified in 'axes' of 'self' to
determine if they are bounded by 'a' and 'b'. The range
is... | python | def isBetween(self, a, b, axes='xyz'):
'''
:a: Point or point equivalent
:b: Point or point equivalent
:axis: optional string
:return: float
Checks the coordinates specified in 'axes' of 'self' to
determine if they are bounded by 'a' and 'b'. The range
is... | [
"def",
"isBetween",
"(",
"self",
",",
"a",
",",
"b",
",",
"axes",
"=",
"'xyz'",
")",
":",
"a",
"=",
"self",
".",
"__class__",
".",
"_convert",
"(",
"a",
")",
"b",
"=",
"self",
".",
"__class__",
".",
"_convert",
"(",
"b",
")",
"fn",
"=",
"lambda... | :a: Point or point equivalent
:b: Point or point equivalent
:axis: optional string
:return: float
Checks the coordinates specified in 'axes' of 'self' to
determine if they are bounded by 'a' and 'b'. The range
is inclusive of end-points.
Returns boolean. | [
":",
"a",
":",
"Point",
"or",
"point",
"equivalent",
":",
"b",
":",
"Point",
"or",
"point",
"equivalent",
":",
"axis",
":",
"optional",
"string",
":",
"return",
":",
"float"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/point.py#L1302-L1321 |
JnyJny/Geometry | Geometry/point.py | Point.ccw | def ccw(self, b, c, axis='z'):
'''
:b: Point or point equivalent
:c: Point or point equivalent
:axis: optional string or integer in set('x',0,'y',1,'z',2)
:return: float
CCW - Counter Clockwise
Returns an integer signifying the direction of rotation around 'axis... | python | def ccw(self, b, c, axis='z'):
'''
:b: Point or point equivalent
:c: Point or point equivalent
:axis: optional string or integer in set('x',0,'y',1,'z',2)
:return: float
CCW - Counter Clockwise
Returns an integer signifying the direction of rotation around 'axis... | [
"def",
"ccw",
"(",
"self",
",",
"b",
",",
"c",
",",
"axis",
"=",
"'z'",
")",
":",
"bsuba",
"=",
"b",
"-",
"self",
"csuba",
"=",
"c",
"-",
"self",
"if",
"axis",
"in",
"[",
"'z'",
",",
"2",
"]",
":",
"return",
"(",
"bsuba",
".",
"x",
"*",
"... | :b: Point or point equivalent
:c: Point or point equivalent
:axis: optional string or integer in set('x',0,'y',1,'z',2)
:return: float
CCW - Counter Clockwise
Returns an integer signifying the direction of rotation around 'axis'
described by the angle [b, self, c].
... | [
":",
"b",
":",
"Point",
"or",
"point",
"equivalent",
":",
"c",
":",
"Point",
"or",
"point",
"equivalent",
":",
"axis",
":",
"optional",
"string",
"or",
"integer",
"in",
"set",
"(",
"x",
"0",
"y",
"1",
"z",
"2",
")",
":",
"return",
":",
"float"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/point.py#L1353-L1387 |
JnyJny/Geometry | Geometry/point.py | Point.isCCW | def isCCW(self, b, c, axis='z'):
'''
:b: Point or point equivalent
:c: Point or point equivalent
:axis: optional string or integer in set('x',0,'y',1,'z',2)
:return: boolean
True if the angle determined by a,self,b around 'axis'
describes a counter-clockwise rota... | python | def isCCW(self, b, c, axis='z'):
'''
:b: Point or point equivalent
:c: Point or point equivalent
:axis: optional string or integer in set('x',0,'y',1,'z',2)
:return: boolean
True if the angle determined by a,self,b around 'axis'
describes a counter-clockwise rota... | [
"def",
"isCCW",
"(",
"self",
",",
"b",
",",
"c",
",",
"axis",
"=",
"'z'",
")",
":",
"result",
"=",
"self",
".",
"ccw",
"(",
"b",
",",
"c",
",",
"axis",
")",
"if",
"result",
"==",
"0",
":",
"raise",
"CollinearPoints",
"(",
"b",
",",
"self",
",... | :b: Point or point equivalent
:c: Point or point equivalent
:axis: optional string or integer in set('x',0,'y',1,'z',2)
:return: boolean
True if the angle determined by a,self,b around 'axis'
describes a counter-clockwise rotation, otherwise False.
Raises CollinearPoint... | [
":",
"b",
":",
"Point",
"or",
"point",
"equivalent",
":",
"c",
":",
"Point",
"or",
"point",
"equivalent",
":",
"axis",
":",
"optional",
"string",
"or",
"integer",
"in",
"set",
"(",
"x",
"0",
"y",
"1",
"z",
"2",
")",
":",
"return",
":",
"boolean"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/point.py#L1389-L1407 |
JnyJny/Geometry | Geometry/point.py | Point.isCollinear | def isCollinear(self, b, c):
'''
:b: Point or point equivalent
:c: Point or point equivalent
:return: boolean
True if 'self' is collinear with 'b' and 'c', otherwise False.
'''
return all(self.ccw(b, c, axis) == 0 for axis in self._keys) | python | def isCollinear(self, b, c):
'''
:b: Point or point equivalent
:c: Point or point equivalent
:return: boolean
True if 'self' is collinear with 'b' and 'c', otherwise False.
'''
return all(self.ccw(b, c, axis) == 0 for axis in self._keys) | [
"def",
"isCollinear",
"(",
"self",
",",
"b",
",",
"c",
")",
":",
"return",
"all",
"(",
"self",
".",
"ccw",
"(",
"b",
",",
"c",
",",
"axis",
")",
"==",
"0",
"for",
"axis",
"in",
"self",
".",
"_keys",
")"
] | :b: Point or point equivalent
:c: Point or point equivalent
:return: boolean
True if 'self' is collinear with 'b' and 'c', otherwise False. | [
":",
"b",
":",
"Point",
"or",
"point",
"equivalent",
":",
"c",
":",
"Point",
"or",
"point",
"equivalent",
":",
"return",
":",
"boolean"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/point.py#L1409-L1418 |
JnyJny/Geometry | Geometry/point.py | Point.rotate2d | def rotate2d(self, theta, origin=None, axis='z', radians=False):
'''
:theta: float radians to rotate self around origin
:origin: optional Point, defaults to 0,0,0
Returns a Point rotated by :theta: around :origin:.
'''
origin = Point._convert(origin)
delta = se... | python | def rotate2d(self, theta, origin=None, axis='z', radians=False):
'''
:theta: float radians to rotate self around origin
:origin: optional Point, defaults to 0,0,0
Returns a Point rotated by :theta: around :origin:.
'''
origin = Point._convert(origin)
delta = se... | [
"def",
"rotate2d",
"(",
"self",
",",
"theta",
",",
"origin",
"=",
"None",
",",
"axis",
"=",
"'z'",
",",
"radians",
"=",
"False",
")",
":",
"origin",
"=",
"Point",
".",
"_convert",
"(",
"origin",
")",
"delta",
"=",
"self",
"-",
"origin",
"p",
"=",
... | :theta: float radians to rotate self around origin
:origin: optional Point, defaults to 0,0,0
Returns a Point rotated by :theta: around :origin:. | [
":",
"theta",
":",
"float",
"radians",
"to",
"rotate",
"self",
"around",
"origin",
":",
"origin",
":",
"optional",
"Point",
"defaults",
"to",
"0",
"0",
"0"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/point.py#L1420-L1455 |
JnyJny/Geometry | Geometry/triangle2.py | Triangle.withAngles | def withAngles(cls, origin=None, base=1, alpha=None,
beta=None, gamma=None, inDegrees=False):
'''
:origin: optional Point
:alpha: optional float describing length of the side opposite A
:beta: optional float describing length of the side opposite B
:gamma: opti... | python | def withAngles(cls, origin=None, base=1, alpha=None,
beta=None, gamma=None, inDegrees=False):
'''
:origin: optional Point
:alpha: optional float describing length of the side opposite A
:beta: optional float describing length of the side opposite B
:gamma: opti... | [
"def",
"withAngles",
"(",
"cls",
",",
"origin",
"=",
"None",
",",
"base",
"=",
"1",
",",
"alpha",
"=",
"None",
",",
"beta",
"=",
"None",
",",
"gamma",
"=",
"None",
",",
"inDegrees",
"=",
"False",
")",
":",
"raise",
"NotImplementedError",
"(",
"\"with... | :origin: optional Point
:alpha: optional float describing length of the side opposite A
:beta: optional float describing length of the side opposite B
:gamma: optional float describing length of the side opposite C
:return: Triangle initialized with points comprising the triangle
... | [
":",
"origin",
":",
"optional",
"Point",
":",
"alpha",
":",
"optional",
"float",
"describing",
"length",
"of",
"the",
"side",
"opposite",
"A",
":",
"beta",
":",
"optional",
"float",
"describing",
"length",
"of",
"the",
"side",
"opposite",
"B",
":",
"gamma"... | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/triangle2.py#L45-L55 |
JnyJny/Geometry | Geometry/triangle2.py | Triangle.heronsArea | def heronsArea(self):
'''
Heron's forumla for computing the area of a triangle, float.
Performance note: contains a square root.
'''
s = self.semiperimeter
return math.sqrt(s * ((s - self.a) * (s - self.b) * (s - self.c))) | python | def heronsArea(self):
'''
Heron's forumla for computing the area of a triangle, float.
Performance note: contains a square root.
'''
s = self.semiperimeter
return math.sqrt(s * ((s - self.a) * (s - self.b) * (s - self.c))) | [
"def",
"heronsArea",
"(",
"self",
")",
":",
"s",
"=",
"self",
".",
"semiperimeter",
"return",
"math",
".",
"sqrt",
"(",
"s",
"*",
"(",
"(",
"s",
"-",
"self",
".",
"a",
")",
"*",
"(",
"s",
"-",
"self",
".",
"b",
")",
"*",
"(",
"s",
"-",
"sel... | Heron's forumla for computing the area of a triangle, float.
Performance note: contains a square root. | [
"Heron",
"s",
"forumla",
"for",
"computing",
"the",
"area",
"of",
"a",
"triangle",
"float",
"."
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/triangle2.py#L182-L191 |
JnyJny/Geometry | Geometry/triangle2.py | Triangle.circumradius | def circumradius(self):
'''
Distance from the circumcenter to all the verticies in
the Triangle, float.
'''
return (self.a * self.b * self.c) / (self.area * 4) | python | def circumradius(self):
'''
Distance from the circumcenter to all the verticies in
the Triangle, float.
'''
return (self.a * self.b * self.c) / (self.area * 4) | [
"def",
"circumradius",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"a",
"*",
"self",
".",
"b",
"*",
"self",
".",
"c",
")",
"/",
"(",
"self",
".",
"area",
"*",
"4",
")"
] | Distance from the circumcenter to all the verticies in
the Triangle, float. | [
"Distance",
"from",
"the",
"circumcenter",
"to",
"all",
"the",
"verticies",
"in",
"the",
"Triangle",
"float",
"."
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/triangle2.py#L238-L244 |
JnyJny/Geometry | Geometry/triangle2.py | Triangle.altitudes | def altitudes(self):
'''
A list of the altitudes of each vertex [AltA, AltB, AltC], list of
floats.
An altitude is the shortest distance from a vertex to the side
opposite of it.
'''
A = self.area * 2
return [A / self.a, A / self.b, A / self.c] | python | def altitudes(self):
'''
A list of the altitudes of each vertex [AltA, AltB, AltC], list of
floats.
An altitude is the shortest distance from a vertex to the side
opposite of it.
'''
A = self.area * 2
return [A / self.a, A / self.b, A / self.c] | [
"def",
"altitudes",
"(",
"self",
")",
":",
"A",
"=",
"self",
".",
"area",
"*",
"2",
"return",
"[",
"A",
"/",
"self",
".",
"a",
",",
"A",
"/",
"self",
".",
"b",
",",
"A",
"/",
"self",
".",
"c",
"]"
] | A list of the altitudes of each vertex [AltA, AltB, AltC], list of
floats.
An altitude is the shortest distance from a vertex to the side
opposite of it. | [
"A",
"list",
"of",
"the",
"altitudes",
"of",
"each",
"vertex",
"[",
"AltA",
"AltB",
"AltC",
"]",
"list",
"of",
"floats",
"."
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/triangle2.py#L334-L345 |
JnyJny/Geometry | Geometry/triangle2.py | Triangle.isIsosceles | def isIsosceles(self):
'''
True iff two side lengths are equal, boolean.
'''
return (self.a == self.b) or (self.a == self.c) or (self.b == self.c) | python | def isIsosceles(self):
'''
True iff two side lengths are equal, boolean.
'''
return (self.a == self.b) or (self.a == self.c) or (self.b == self.c) | [
"def",
"isIsosceles",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"a",
"==",
"self",
".",
"b",
")",
"or",
"(",
"self",
".",
"a",
"==",
"self",
".",
"c",
")",
"or",
"(",
"self",
".",
"b",
"==",
"self",
".",
"c",
")"
] | True iff two side lengths are equal, boolean. | [
"True",
"iff",
"two",
"side",
"lengths",
"are",
"equal",
"boolean",
"."
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/triangle2.py#L355-L359 |
JnyJny/Geometry | Geometry/triangle2.py | Triangle.congruent | def congruent(self, other):
'''
A congruent B
True iff all angles of 'A' equal angles in 'B' and
all side lengths of 'A' equal all side lengths of 'B', boolean.
'''
a = set(self.angles)
b = set(other.angles)
if len(a) != len(b) or len(a.difference(b)) ... | python | def congruent(self, other):
'''
A congruent B
True iff all angles of 'A' equal angles in 'B' and
all side lengths of 'A' equal all side lengths of 'B', boolean.
'''
a = set(self.angles)
b = set(other.angles)
if len(a) != len(b) or len(a.difference(b)) ... | [
"def",
"congruent",
"(",
"self",
",",
"other",
")",
":",
"a",
"=",
"set",
"(",
"self",
".",
"angles",
")",
"b",
"=",
"set",
"(",
"other",
".",
"angles",
")",
"if",
"len",
"(",
"a",
")",
"!=",
"len",
"(",
"b",
")",
"or",
"len",
"(",
"a",
"."... | A congruent B
True iff all angles of 'A' equal angles in 'B' and
all side lengths of 'A' equal all side lengths of 'B', boolean. | [
"A",
"congruent",
"B"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/triangle2.py#L393-L411 |
JnyJny/Geometry | Geometry/ellipse.py | Ellipse.center | def center(self):
'''
Center point of the ellipse, equidistant from foci, Point class.\n
Defaults to the origin.
'''
try:
return self._center
except AttributeError:
pass
self._center = Point()
return self._center | python | def center(self):
'''
Center point of the ellipse, equidistant from foci, Point class.\n
Defaults to the origin.
'''
try:
return self._center
except AttributeError:
pass
self._center = Point()
return self._center | [
"def",
"center",
"(",
"self",
")",
":",
"try",
":",
"return",
"self",
".",
"_center",
"except",
"AttributeError",
":",
"pass",
"self",
".",
"_center",
"=",
"Point",
"(",
")",
"return",
"self",
".",
"_center"
] | Center point of the ellipse, equidistant from foci, Point class.\n
Defaults to the origin. | [
"Center",
"point",
"of",
"the",
"ellipse",
"equidistant",
"from",
"foci",
"Point",
"class",
".",
"\\",
"n",
"Defaults",
"to",
"the",
"origin",
"."
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/ellipse.py#L47-L57 |
JnyJny/Geometry | Geometry/ellipse.py | Ellipse.radius | def radius(self):
'''
Radius of the ellipse, Point class.
'''
try:
return self._radius
except AttributeError:
pass
self._radius = Point(1, 1, 0)
return self._radius | python | def radius(self):
'''
Radius of the ellipse, Point class.
'''
try:
return self._radius
except AttributeError:
pass
self._radius = Point(1, 1, 0)
return self._radius | [
"def",
"radius",
"(",
"self",
")",
":",
"try",
":",
"return",
"self",
".",
"_radius",
"except",
"AttributeError",
":",
"pass",
"self",
".",
"_radius",
"=",
"Point",
"(",
"1",
",",
"1",
",",
"0",
")",
"return",
"self",
".",
"_radius"
] | Radius of the ellipse, Point class. | [
"Radius",
"of",
"the",
"ellipse",
"Point",
"class",
"."
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/ellipse.py#L64-L73 |
JnyJny/Geometry | Geometry/ellipse.py | Ellipse.xAxisIsMajor | def xAxisIsMajor(self):
'''
Returns True if the major axis is parallel to the X axis, boolean.
'''
return max(self.radius.x, self.radius.y) == self.radius.x | python | def xAxisIsMajor(self):
'''
Returns True if the major axis is parallel to the X axis, boolean.
'''
return max(self.radius.x, self.radius.y) == self.radius.x | [
"def",
"xAxisIsMajor",
"(",
"self",
")",
":",
"return",
"max",
"(",
"self",
".",
"radius",
".",
"x",
",",
"self",
".",
"radius",
".",
"y",
")",
"==",
"self",
".",
"radius",
".",
"x"
] | Returns True if the major axis is parallel to the X axis, boolean. | [
"Returns",
"True",
"if",
"the",
"major",
"axis",
"is",
"parallel",
"to",
"the",
"X",
"axis",
"boolean",
"."
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/ellipse.py#L111-L115 |
JnyJny/Geometry | Geometry/ellipse.py | Ellipse.xAxisIsMinor | def xAxisIsMinor(self):
'''
Returns True if the minor axis is parallel to the X axis, boolean.
'''
return min(self.radius.x, self.radius.y) == self.radius.x | python | def xAxisIsMinor(self):
'''
Returns True if the minor axis is parallel to the X axis, boolean.
'''
return min(self.radius.x, self.radius.y) == self.radius.x | [
"def",
"xAxisIsMinor",
"(",
"self",
")",
":",
"return",
"min",
"(",
"self",
".",
"radius",
".",
"x",
",",
"self",
".",
"radius",
".",
"y",
")",
"==",
"self",
".",
"radius",
".",
"x"
] | Returns True if the minor axis is parallel to the X axis, boolean. | [
"Returns",
"True",
"if",
"the",
"minor",
"axis",
"is",
"parallel",
"to",
"the",
"X",
"axis",
"boolean",
"."
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/ellipse.py#L118-L122 |
JnyJny/Geometry | Geometry/ellipse.py | Ellipse.yAxisIsMajor | def yAxisIsMajor(self):
'''
Returns True if the major axis is parallel to the Y axis, boolean.
'''
return max(self.radius.x, self.radius.y) == self.radius.y | python | def yAxisIsMajor(self):
'''
Returns True if the major axis is parallel to the Y axis, boolean.
'''
return max(self.radius.x, self.radius.y) == self.radius.y | [
"def",
"yAxisIsMajor",
"(",
"self",
")",
":",
"return",
"max",
"(",
"self",
".",
"radius",
".",
"x",
",",
"self",
".",
"radius",
".",
"y",
")",
"==",
"self",
".",
"radius",
".",
"y"
] | Returns True if the major axis is parallel to the Y axis, boolean. | [
"Returns",
"True",
"if",
"the",
"major",
"axis",
"is",
"parallel",
"to",
"the",
"Y",
"axis",
"boolean",
"."
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/ellipse.py#L125-L129 |
JnyJny/Geometry | Geometry/ellipse.py | Ellipse.yAxisIsMinor | def yAxisIsMinor(self):
'''
Returns True if the minor axis is parallel to the Y axis, boolean.
'''
return min(self.radius.x, self.radius.y) == self.radius.y | python | def yAxisIsMinor(self):
'''
Returns True if the minor axis is parallel to the Y axis, boolean.
'''
return min(self.radius.x, self.radius.y) == self.radius.y | [
"def",
"yAxisIsMinor",
"(",
"self",
")",
":",
"return",
"min",
"(",
"self",
".",
"radius",
".",
"x",
",",
"self",
".",
"radius",
".",
"y",
")",
"==",
"self",
".",
"radius",
".",
"y"
] | Returns True if the minor axis is parallel to the Y axis, boolean. | [
"Returns",
"True",
"if",
"the",
"minor",
"axis",
"is",
"parallel",
"to",
"the",
"Y",
"axis",
"boolean",
"."
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/ellipse.py#L132-L136 |
JnyJny/Geometry | Geometry/ellipse.py | Ellipse.a | def a(self):
'''
Positive antipodal point on the major axis, Point class.
'''
a = Point(self.center)
if self.xAxisIsMajor:
a.x += self.majorRadius
else:
a.y += self.majorRadius
return a | python | def a(self):
'''
Positive antipodal point on the major axis, Point class.
'''
a = Point(self.center)
if self.xAxisIsMajor:
a.x += self.majorRadius
else:
a.y += self.majorRadius
return a | [
"def",
"a",
"(",
"self",
")",
":",
"a",
"=",
"Point",
"(",
"self",
".",
"center",
")",
"if",
"self",
".",
"xAxisIsMajor",
":",
"a",
".",
"x",
"+=",
"self",
".",
"majorRadius",
"else",
":",
"a",
".",
"y",
"+=",
"self",
".",
"majorRadius",
"return"... | Positive antipodal point on the major axis, Point class. | [
"Positive",
"antipodal",
"point",
"on",
"the",
"major",
"axis",
"Point",
"class",
"."
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/ellipse.py#L181-L192 |
JnyJny/Geometry | Geometry/ellipse.py | Ellipse.a_neg | def a_neg(self):
'''
Negative antipodal point on the major axis, Point class.
'''
na = Point(self.center)
if self.xAxisIsMajor:
na.x -= self.majorRadius
else:
na.y -= self.majorRadius
return na | python | def a_neg(self):
'''
Negative antipodal point on the major axis, Point class.
'''
na = Point(self.center)
if self.xAxisIsMajor:
na.x -= self.majorRadius
else:
na.y -= self.majorRadius
return na | [
"def",
"a_neg",
"(",
"self",
")",
":",
"na",
"=",
"Point",
"(",
"self",
".",
"center",
")",
"if",
"self",
".",
"xAxisIsMajor",
":",
"na",
".",
"x",
"-=",
"self",
".",
"majorRadius",
"else",
":",
"na",
".",
"y",
"-=",
"self",
".",
"majorRadius",
"... | Negative antipodal point on the major axis, Point class. | [
"Negative",
"antipodal",
"point",
"on",
"the",
"major",
"axis",
"Point",
"class",
"."
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/ellipse.py#L195-L206 |
JnyJny/Geometry | Geometry/ellipse.py | Ellipse.b | def b(self):
'''
Positive antipodal point on the minor axis, Point class.
'''
b = Point(self.center)
if self.xAxisIsMinor:
b.x += self.minorRadius
else:
b.y += self.minorRadius
return b | python | def b(self):
'''
Positive antipodal point on the minor axis, Point class.
'''
b = Point(self.center)
if self.xAxisIsMinor:
b.x += self.minorRadius
else:
b.y += self.minorRadius
return b | [
"def",
"b",
"(",
"self",
")",
":",
"b",
"=",
"Point",
"(",
"self",
".",
"center",
")",
"if",
"self",
".",
"xAxisIsMinor",
":",
"b",
".",
"x",
"+=",
"self",
".",
"minorRadius",
"else",
":",
"b",
".",
"y",
"+=",
"self",
".",
"minorRadius",
"return"... | Positive antipodal point on the minor axis, Point class. | [
"Positive",
"antipodal",
"point",
"on",
"the",
"minor",
"axis",
"Point",
"class",
"."
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/ellipse.py#L209-L220 |
JnyJny/Geometry | Geometry/ellipse.py | Ellipse.b_neg | def b_neg(self):
'''
Negative antipodal point on the minor axis, Point class.
'''
nb = Point(self.center)
if self.xAxisIsMinor:
nb.x -= self.minorRadius
else:
nb.y -= self.minorRadius
return nb | python | def b_neg(self):
'''
Negative antipodal point on the minor axis, Point class.
'''
nb = Point(self.center)
if self.xAxisIsMinor:
nb.x -= self.minorRadius
else:
nb.y -= self.minorRadius
return nb | [
"def",
"b_neg",
"(",
"self",
")",
":",
"nb",
"=",
"Point",
"(",
"self",
".",
"center",
")",
"if",
"self",
".",
"xAxisIsMinor",
":",
"nb",
".",
"x",
"-=",
"self",
".",
"minorRadius",
"else",
":",
"nb",
".",
"y",
"-=",
"self",
".",
"minorRadius",
"... | Negative antipodal point on the minor axis, Point class. | [
"Negative",
"antipodal",
"point",
"on",
"the",
"minor",
"axis",
"Point",
"class",
"."
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/ellipse.py#L223-L233 |
JnyJny/Geometry | Geometry/ellipse.py | Ellipse.vertices | def vertices(self):
'''
A dictionary of four points where the axes intersect the ellipse, dict.
'''
return {'a': self.a, 'a_neg': self.a_neg,
'b': self.b, 'b_neg': self.b_neg} | python | def vertices(self):
'''
A dictionary of four points where the axes intersect the ellipse, dict.
'''
return {'a': self.a, 'a_neg': self.a_neg,
'b': self.b, 'b_neg': self.b_neg} | [
"def",
"vertices",
"(",
"self",
")",
":",
"return",
"{",
"'a'",
":",
"self",
".",
"a",
",",
"'a_neg'",
":",
"self",
".",
"a_neg",
",",
"'b'",
":",
"self",
".",
"b",
",",
"'b_neg'",
":",
"self",
".",
"b_neg",
"}"
] | A dictionary of four points where the axes intersect the ellipse, dict. | [
"A",
"dictionary",
"of",
"four",
"points",
"where",
"the",
"axes",
"intersect",
"the",
"ellipse",
"dict",
"."
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/ellipse.py#L236-L241 |
JnyJny/Geometry | Geometry/ellipse.py | Ellipse.focus0 | def focus0(self):
'''
First focus of the ellipse, Point class.
'''
f = Point(self.center)
if self.xAxisIsMajor:
f.x -= self.linearEccentricity
else:
f.y -= self.linearEccentricity
return f | python | def focus0(self):
'''
First focus of the ellipse, Point class.
'''
f = Point(self.center)
if self.xAxisIsMajor:
f.x -= self.linearEccentricity
else:
f.y -= self.linearEccentricity
return f | [
"def",
"focus0",
"(",
"self",
")",
":",
"f",
"=",
"Point",
"(",
"self",
".",
"center",
")",
"if",
"self",
".",
"xAxisIsMajor",
":",
"f",
".",
"x",
"-=",
"self",
".",
"linearEccentricity",
"else",
":",
"f",
".",
"y",
"-=",
"self",
".",
"linearEccent... | First focus of the ellipse, Point class. | [
"First",
"focus",
"of",
"the",
"ellipse",
"Point",
"class",
"."
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/ellipse.py#L244-L255 |
JnyJny/Geometry | Geometry/ellipse.py | Circle.circumcircleForTriangle | def circumcircleForTriangle(cls, triangle):
'''
:param: triangle - Triangle class
:return: Circle class
Returns the circle where every vertex in the input triangle is
on the radius of that circle.
'''
if triangle.isRight:
# circumcircle origin is th... | python | def circumcircleForTriangle(cls, triangle):
'''
:param: triangle - Triangle class
:return: Circle class
Returns the circle where every vertex in the input triangle is
on the radius of that circle.
'''
if triangle.isRight:
# circumcircle origin is th... | [
"def",
"circumcircleForTriangle",
"(",
"cls",
",",
"triangle",
")",
":",
"if",
"triangle",
".",
"isRight",
":",
"# circumcircle origin is the midpoint of the hypotenues",
"o",
"=",
"triangle",
".",
"hypotenuse",
".",
"midpoint",
"r",
"=",
"o",
".",
"distance",
"("... | :param: triangle - Triangle class
:return: Circle class
Returns the circle where every vertex in the input triangle is
on the radius of that circle. | [
":",
"param",
":",
"triangle",
"-",
"Triangle",
"class",
":",
"return",
":",
"Circle",
"class"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/ellipse.py#L416-L446 |
JnyJny/Geometry | Geometry/ellipse.py | Circle.doesIntersect | def doesIntersect(self, other):
'''
:param: other - Circle class
Returns True iff:
self.center.distance(other.center) <= self.radius+other.radius
'''
otherType = type(other)
if issubclass(otherType, Ellipse):
distance = self.center.distance(other.... | python | def doesIntersect(self, other):
'''
:param: other - Circle class
Returns True iff:
self.center.distance(other.center) <= self.radius+other.radius
'''
otherType = type(other)
if issubclass(otherType, Ellipse):
distance = self.center.distance(other.... | [
"def",
"doesIntersect",
"(",
"self",
",",
"other",
")",
":",
"otherType",
"=",
"type",
"(",
"other",
")",
"if",
"issubclass",
"(",
"otherType",
",",
"Ellipse",
")",
":",
"distance",
"=",
"self",
".",
"center",
".",
"distance",
"(",
"other",
".",
"cente... | :param: other - Circle class
Returns True iff:
self.center.distance(other.center) <= self.radius+other.radius | [
":",
"param",
":",
"other",
"-",
"Circle",
"class"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/ellipse.py#L535-L553 |
JnyJny/Geometry | Geometry/line.py | Line.AB | def AB(self):
'''
A list containing Points A and B.
'''
try:
return self._AB
except AttributeError:
pass
self._AB = [self.A, self.B]
return self._AB | python | def AB(self):
'''
A list containing Points A and B.
'''
try:
return self._AB
except AttributeError:
pass
self._AB = [self.A, self.B]
return self._AB | [
"def",
"AB",
"(",
"self",
")",
":",
"try",
":",
"return",
"self",
".",
"_AB",
"except",
"AttributeError",
":",
"pass",
"self",
".",
"_AB",
"=",
"[",
"self",
".",
"A",
",",
"self",
".",
"B",
"]",
"return",
"self",
".",
"_AB"
] | A list containing Points A and B. | [
"A",
"list",
"containing",
"Points",
"A",
"and",
"B",
"."
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/line.py#L117-L126 |
JnyJny/Geometry | Geometry/line.py | Line.normal | def normal(self):
'''
:return: Line
Returns a Line normal (perpendicular) to this Line.
'''
d = self.B - self.A
return Line([-d.y, d.x], [d.y, -d.x]) | python | def normal(self):
'''
:return: Line
Returns a Line normal (perpendicular) to this Line.
'''
d = self.B - self.A
return Line([-d.y, d.x], [d.y, -d.x]) | [
"def",
"normal",
"(",
"self",
")",
":",
"d",
"=",
"self",
".",
"B",
"-",
"self",
".",
"A",
"return",
"Line",
"(",
"[",
"-",
"d",
".",
"y",
",",
"d",
".",
"x",
"]",
",",
"[",
"d",
".",
"y",
",",
"-",
"d",
".",
"x",
"]",
")"
] | :return: Line
Returns a Line normal (perpendicular) to this Line. | [
":",
"return",
":",
"Line"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/line.py#L173-L182 |
JnyJny/Geometry | Geometry/line.py | Line.t | def t(self, point):
'''
:point: Point subclass
:return: float
If :point: is collinear, determine the 't' coefficient of
the parametric equation:
xyz = A<xyz> + t ( B<xyz> - A<xyz> )
if t < 0, point is less than A and B on the line
if t >= 0 and <= 1, po... | python | def t(self, point):
'''
:point: Point subclass
:return: float
If :point: is collinear, determine the 't' coefficient of
the parametric equation:
xyz = A<xyz> + t ( B<xyz> - A<xyz> )
if t < 0, point is less than A and B on the line
if t >= 0 and <= 1, po... | [
"def",
"t",
"(",
"self",
",",
"point",
")",
":",
"# XXX could use for an ordering on points?",
"if",
"point",
"not",
"in",
"self",
":",
"msg",
"=",
"\"'{p}' is not collinear with '{l}'\"",
"raise",
"CollinearPoints",
"(",
"msg",
".",
"format",
"(",
"p",
"=",
"po... | :point: Point subclass
:return: float
If :point: is collinear, determine the 't' coefficient of
the parametric equation:
xyz = A<xyz> + t ( B<xyz> - A<xyz> )
if t < 0, point is less than A and B on the line
if t >= 0 and <= 1, point is between A and B
if t > 1 ... | [
":",
"point",
":",
"Point",
"subclass",
":",
"return",
":",
"float"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/line.py#L198-L223 |
JnyJny/Geometry | Geometry/line.py | Line.flip | def flip(self):
'''
:returns: None
Swaps the positions of A and B.
'''
tmp = self.A.xyz
self.A = self.B
self.B = tmp | python | def flip(self):
'''
:returns: None
Swaps the positions of A and B.
'''
tmp = self.A.xyz
self.A = self.B
self.B = tmp | [
"def",
"flip",
"(",
"self",
")",
":",
"tmp",
"=",
"self",
".",
"A",
".",
"xyz",
"self",
".",
"A",
"=",
"self",
".",
"B",
"self",
".",
"B",
"=",
"tmp"
] | :returns: None
Swaps the positions of A and B. | [
":",
"returns",
":",
"None"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/line.py#L294-L302 |
JnyJny/Geometry | Geometry/line.py | Line.doesIntersect | def doesIntersect(self, other):
'''
:param: other - Line subclass
:return: boolean
Returns True iff:
ccw(self.A,self.B,other.A) * ccw(self.A,self.B,other.B) <= 0
and
ccw(other.A,other.B,self.A) * ccw(other.A,other.B,self.B) <= 0
'''
if s... | python | def doesIntersect(self, other):
'''
:param: other - Line subclass
:return: boolean
Returns True iff:
ccw(self.A,self.B,other.A) * ccw(self.A,self.B,other.B) <= 0
and
ccw(other.A,other.B,self.A) * ccw(other.A,other.B,self.B) <= 0
'''
if s... | [
"def",
"doesIntersect",
"(",
"self",
",",
"other",
")",
":",
"if",
"self",
".",
"A",
".",
"ccw",
"(",
"self",
".",
"B",
",",
"other",
".",
"A",
")",
"*",
"self",
".",
"A",
".",
"ccw",
"(",
"self",
".",
"B",
",",
"other",
".",
"B",
")",
">",... | :param: other - Line subclass
:return: boolean
Returns True iff:
ccw(self.A,self.B,other.A) * ccw(self.A,self.B,other.B) <= 0
and
ccw(other.A,other.B,self.A) * ccw(other.A,other.B,self.B) <= 0 | [
":",
"param",
":",
"other",
"-",
"Line",
"subclass",
":",
"return",
":",
"boolean"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/line.py#L304-L321 |
JnyJny/Geometry | Geometry/line.py | Line.intersection | def intersection(self, other):
'''
:param: other - Line subclass
:return: Point subclass
Returns a Point object with the coordinates of the intersection
between the current line and the other line.
Will raise Parallel() if the two lines are parallel.
Will raise ... | python | def intersection(self, other):
'''
:param: other - Line subclass
:return: Point subclass
Returns a Point object with the coordinates of the intersection
between the current line and the other line.
Will raise Parallel() if the two lines are parallel.
Will raise ... | [
"def",
"intersection",
"(",
"self",
",",
"other",
")",
":",
"if",
"self",
".",
"isCollinear",
"(",
"other",
")",
":",
"msg",
"=",
"'{!r} and {!r} are collinear'",
"raise",
"CollinearLines",
"(",
"msg",
".",
"format",
"(",
"self",
",",
"other",
")",
")",
... | :param: other - Line subclass
:return: Point subclass
Returns a Point object with the coordinates of the intersection
between the current line and the other line.
Will raise Parallel() if the two lines are parallel.
Will raise Collinear() if the two lines are collinear. | [
":",
"param",
":",
"other",
"-",
"Line",
"subclass",
":",
"return",
":",
"Point",
"subclass"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/line.py#L342-L379 |
JnyJny/Geometry | Geometry/line.py | Line.distanceFromPoint | def distanceFromPoint(self, point):
'''
:param: point - Point subclass
:return: float
Distance from the line to the given point.
'''
# XXX planar distance, doesn't take into account z ?
d = self.m
n = (d.y * point.x) - (d.x * point.y) + self.A.cross(self.... | python | def distanceFromPoint(self, point):
'''
:param: point - Point subclass
:return: float
Distance from the line to the given point.
'''
# XXX planar distance, doesn't take into account z ?
d = self.m
n = (d.y * point.x) - (d.x * point.y) + self.A.cross(self.... | [
"def",
"distanceFromPoint",
"(",
"self",
",",
"point",
")",
":",
"# XXX planar distance, doesn't take into account z ?",
"d",
"=",
"self",
".",
"m",
"n",
"=",
"(",
"d",
".",
"y",
"*",
"point",
".",
"x",
")",
"-",
"(",
"d",
".",
"x",
"*",
"point",
".",
... | :param: point - Point subclass
:return: float
Distance from the line to the given point. | [
":",
"param",
":",
"point",
"-",
"Point",
"subclass",
":",
"return",
":",
"float"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/line.py#L381-L391 |
JnyJny/Geometry | Geometry/line.py | Line.radiansBetween | def radiansBetween(self, other):
'''
:param: other - Line subclass
:return: float
Returns the angle measured between two lines in radians
with a range of [0, 2 * math.pi].
'''
# a dot b = |a||b| * cos(theta)
# a dot b / |a||b| = cos(theta)
# cos-... | python | def radiansBetween(self, other):
'''
:param: other - Line subclass
:return: float
Returns the angle measured between two lines in radians
with a range of [0, 2 * math.pi].
'''
# a dot b = |a||b| * cos(theta)
# a dot b / |a||b| = cos(theta)
# cos-... | [
"def",
"radiansBetween",
"(",
"self",
",",
"other",
")",
":",
"# a dot b = |a||b| * cos(theta)",
"# a dot b / |a||b| = cos(theta)",
"# cos-1(a dot b / |a||b|) = theta",
"# translate each line so that it passes through the origin and",
"# produce a new point whose distance (magnitude) from th... | :param: other - Line subclass
:return: float
Returns the angle measured between two lines in radians
with a range of [0, 2 * math.pi]. | [
":",
"param",
":",
"other",
"-",
"Line",
"subclass",
":",
"return",
":",
"float"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/line.py#L403-L430 |
JnyJny/Geometry | Geometry/propgen.py | FloatProperty | def FloatProperty(name, default=0.0, readonly=False, docs=None):
'''
:name: string - property name
:default: float - property default value
:readonly: boolean - if True, setter method is NOT generated
Returns a property object that can be used to initialize a
class instance variable as a proper... | python | def FloatProperty(name, default=0.0, readonly=False, docs=None):
'''
:name: string - property name
:default: float - property default value
:readonly: boolean - if True, setter method is NOT generated
Returns a property object that can be used to initialize a
class instance variable as a proper... | [
"def",
"FloatProperty",
"(",
"name",
",",
"default",
"=",
"0.0",
",",
"readonly",
"=",
"False",
",",
"docs",
"=",
"None",
")",
":",
"private_name",
"=",
"'_'",
"+",
"name",
"def",
"getf",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
... | :name: string - property name
:default: float - property default value
:readonly: boolean - if True, setter method is NOT generated
Returns a property object that can be used to initialize a
class instance variable as a property. | [
":",
"name",
":",
"string",
"-",
"property",
"name",
":",
"default",
":",
"float",
"-",
"property",
"default",
"value",
":",
"readonly",
":",
"boolean",
"-",
"if",
"True",
"setter",
"method",
"is",
"NOT",
"generated"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/propgen.py#L25-L86 |
JnyJny/Geometry | Geometry/rectangle.py | Rectangle.randomSizeAndLocation | def randomSizeAndLocation(cls, radius, widthLimits,
heightLimits, origin=None):
'''
:param: radius - float
:param: widthLimits - iterable of floats with length >= 2
:param: heightLimits - iterable of floats with length >= 2
:param: origin ... | python | def randomSizeAndLocation(cls, radius, widthLimits,
heightLimits, origin=None):
'''
:param: radius - float
:param: widthLimits - iterable of floats with length >= 2
:param: heightLimits - iterable of floats with length >= 2
:param: origin ... | [
"def",
"randomSizeAndLocation",
"(",
"cls",
",",
"radius",
",",
"widthLimits",
",",
"heightLimits",
",",
"origin",
"=",
"None",
")",
":",
"r",
"=",
"cls",
"(",
"widthLimits",
",",
"heightLimits",
",",
"origin",
")",
"r",
".",
"origin",
"=",
"Point",
".",... | :param: radius - float
:param: widthLimits - iterable of floats with length >= 2
:param: heightLimits - iterable of floats with length >= 2
:param: origin - optional Point subclass
:return: Rectangle | [
":",
"param",
":",
"radius",
"-",
"float",
":",
"param",
":",
"widthLimits",
"-",
"iterable",
"of",
"floats",
"with",
"length",
">",
"=",
"2",
":",
"param",
":",
"heightLimits",
"-",
"iterable",
"of",
"floats",
"with",
"length",
">",
"=",
"2",
":",
"... | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/rectangle.py#L26-L38 |
JnyJny/Geometry | Geometry/rectangle.py | Rectangle.randomSize | def randomSize(cls, widthLimits, heightLimits, origin=None):
'''
:param: widthLimits - iterable of integers with length >= 2
:param: heightLimits - iterable of integers with length >= 2
:param: origin - optional Point subclass
:return: Rectangle
'''
r = cl... | python | def randomSize(cls, widthLimits, heightLimits, origin=None):
'''
:param: widthLimits - iterable of integers with length >= 2
:param: heightLimits - iterable of integers with length >= 2
:param: origin - optional Point subclass
:return: Rectangle
'''
r = cl... | [
"def",
"randomSize",
"(",
"cls",
",",
"widthLimits",
",",
"heightLimits",
",",
"origin",
"=",
"None",
")",
":",
"r",
"=",
"cls",
"(",
"0",
",",
"0",
",",
"origin",
")",
"r",
".",
"w",
"=",
"random",
".",
"randint",
"(",
"widthLimits",
"[",
"0",
"... | :param: widthLimits - iterable of integers with length >= 2
:param: heightLimits - iterable of integers with length >= 2
:param: origin - optional Point subclass
:return: Rectangle | [
":",
"param",
":",
"widthLimits",
"-",
"iterable",
"of",
"integers",
"with",
"length",
">",
"=",
"2",
":",
"param",
":",
"heightLimits",
"-",
"iterable",
"of",
"integers",
"with",
"length",
">",
"=",
"2",
":",
"param",
":",
"origin",
"-",
"optional",
"... | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/rectangle.py#L41-L54 |
JnyJny/Geometry | Geometry/rectangle.py | Rectangle.randomLocation | def randomLocation(cls, radius, width, height, origin=None):
'''
:param: radius - float
:param: width - float
:param: height - float
:param: origin - optional Point subclass
:return: Rectangle
'''
return cls(width,
height,
... | python | def randomLocation(cls, radius, width, height, origin=None):
'''
:param: radius - float
:param: width - float
:param: height - float
:param: origin - optional Point subclass
:return: Rectangle
'''
return cls(width,
height,
... | [
"def",
"randomLocation",
"(",
"cls",
",",
"radius",
",",
"width",
",",
"height",
",",
"origin",
"=",
"None",
")",
":",
"return",
"cls",
"(",
"width",
",",
"height",
",",
"Point",
".",
"randomLocation",
"(",
"radius",
",",
"origin",
")",
")"
] | :param: radius - float
:param: width - float
:param: height - float
:param: origin - optional Point subclass
:return: Rectangle | [
":",
"param",
":",
"radius",
"-",
"float",
":",
"param",
":",
"width",
"-",
"float",
":",
"param",
":",
"height",
"-",
"float",
":",
"param",
":",
"origin",
"-",
"optional",
"Point",
"subclass",
":",
"return",
":",
"Rectangle"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/rectangle.py#L57-L67 |
JnyJny/Geometry | Geometry/rectangle.py | Rectangle.origin | def origin(self):
'''
Point describing the origin of the rectangle. Defaults to (0,0,0).
'''
try:
return self._origin
except AttributeError:
pass
self._origin = Point()
return self._origin | python | def origin(self):
'''
Point describing the origin of the rectangle. Defaults to (0,0,0).
'''
try:
return self._origin
except AttributeError:
pass
self._origin = Point()
return self._origin | [
"def",
"origin",
"(",
"self",
")",
":",
"try",
":",
"return",
"self",
".",
"_origin",
"except",
"AttributeError",
":",
"pass",
"self",
".",
"_origin",
"=",
"Point",
"(",
")",
"return",
"self",
".",
"_origin"
] | Point describing the origin of the rectangle. Defaults to (0,0,0). | [
"Point",
"describing",
"the",
"origin",
"of",
"the",
"rectangle",
".",
"Defaults",
"to",
"(",
"0",
"0",
"0",
")",
"."
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/rectangle.py#L87-L96 |
JnyJny/Geometry | Geometry/rectangle.py | Rectangle.B | def B(self):
'''
Point whose coordinates are (maxX,minY,origin.z), Point.
'''
return Point(self.maxX, self.minY, self.origin.z) | python | def B(self):
'''
Point whose coordinates are (maxX,minY,origin.z), Point.
'''
return Point(self.maxX, self.minY, self.origin.z) | [
"def",
"B",
"(",
"self",
")",
":",
"return",
"Point",
"(",
"self",
".",
"maxX",
",",
"self",
".",
"minY",
",",
"self",
".",
"origin",
".",
"z",
")"
] | Point whose coordinates are (maxX,minY,origin.z), Point. | [
"Point",
"whose",
"coordinates",
"are",
"(",
"maxX",
"minY",
"origin",
".",
"z",
")",
"Point",
"."
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/rectangle.py#L302-L306 |
JnyJny/Geometry | Geometry/rectangle.py | Rectangle.C | def C(self):
'''
Point whose coordinates are (maxX,maxY,origin.z), Point.
'''
return Point(self.maxX, self.maxY, self.origin.z) | python | def C(self):
'''
Point whose coordinates are (maxX,maxY,origin.z), Point.
'''
return Point(self.maxX, self.maxY, self.origin.z) | [
"def",
"C",
"(",
"self",
")",
":",
"return",
"Point",
"(",
"self",
".",
"maxX",
",",
"self",
".",
"maxY",
",",
"self",
".",
"origin",
".",
"z",
")"
] | Point whose coordinates are (maxX,maxY,origin.z), Point. | [
"Point",
"whose",
"coordinates",
"are",
"(",
"maxX",
"maxY",
"origin",
".",
"z",
")",
"Point",
"."
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/rectangle.py#L314-L318 |
JnyJny/Geometry | Geometry/rectangle.py | Rectangle.D | def D(self):
'''
Point whose coordinates are (minX,maxY,origin.Z), Point.
'''
return Point(self.minX, self.maxY, self.origin.z) | python | def D(self):
'''
Point whose coordinates are (minX,maxY,origin.Z), Point.
'''
return Point(self.minX, self.maxY, self.origin.z) | [
"def",
"D",
"(",
"self",
")",
":",
"return",
"Point",
"(",
"self",
".",
"minX",
",",
"self",
".",
"maxY",
",",
"self",
".",
"origin",
".",
"z",
")"
] | Point whose coordinates are (minX,maxY,origin.Z), Point. | [
"Point",
"whose",
"coordinates",
"are",
"(",
"minX",
"maxY",
"origin",
".",
"Z",
")",
"Point",
"."
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/rectangle.py#L327-L331 |
JnyJny/Geometry | Geometry/rectangle.py | Rectangle.center | def center(self):
'''
Point whose coordinates are (midX,midY,origin.z), Point.
'''
return Point(self.midX, self.midY, self.origin.z) | python | def center(self):
'''
Point whose coordinates are (midX,midY,origin.z), Point.
'''
return Point(self.midX, self.midY, self.origin.z) | [
"def",
"center",
"(",
"self",
")",
":",
"return",
"Point",
"(",
"self",
".",
"midX",
",",
"self",
".",
"midY",
",",
"self",
".",
"origin",
".",
"z",
")"
] | Point whose coordinates are (midX,midY,origin.z), Point. | [
"Point",
"whose",
"coordinates",
"are",
"(",
"midX",
"midY",
"origin",
".",
"z",
")",
"Point",
"."
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/rectangle.py#L339-L343 |
JnyJny/Geometry | Geometry/rectangle.py | Rectangle.scale | def scale(self, dx=1.0, dy=1.0):
'''
:param: dx - optional float
:param: dy - optional float
Scales the rectangle's width and height by dx and dy.
'''
self.width *= dx
self.height *= dy | python | def scale(self, dx=1.0, dy=1.0):
'''
:param: dx - optional float
:param: dy - optional float
Scales the rectangle's width and height by dx and dy.
'''
self.width *= dx
self.height *= dy | [
"def",
"scale",
"(",
"self",
",",
"dx",
"=",
"1.0",
",",
"dy",
"=",
"1.0",
")",
":",
"self",
".",
"width",
"*=",
"dx",
"self",
".",
"height",
"*=",
"dy"
] | :param: dx - optional float
:param: dy - optional float
Scales the rectangle's width and height by dx and dy. | [
":",
"param",
":",
"dx",
"-",
"optional",
"float",
":",
"param",
":",
"dy",
"-",
"optional",
"float"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/rectangle.py#L503-L512 |
JnyJny/Geometry | Geometry/rectangle.py | Rectangle.containsPoint | def containsPoint(self, point, Zorder=False):
'''
:param: point - Point subclass
:param: Zorder - optional Boolean
Is true if the point is contain in the rectangle or
along the rectangle's edges.
If Zorder is True, the method will check point.z for
equality wit... | python | def containsPoint(self, point, Zorder=False):
'''
:param: point - Point subclass
:param: Zorder - optional Boolean
Is true if the point is contain in the rectangle or
along the rectangle's edges.
If Zorder is True, the method will check point.z for
equality wit... | [
"def",
"containsPoint",
"(",
"self",
",",
"point",
",",
"Zorder",
"=",
"False",
")",
":",
"if",
"not",
"point",
".",
"isBetweenX",
"(",
"self",
".",
"A",
",",
"self",
".",
"B",
")",
":",
"return",
"False",
"if",
"not",
"point",
".",
"isBetweenY",
"... | :param: point - Point subclass
:param: Zorder - optional Boolean
Is true if the point is contain in the rectangle or
along the rectangle's edges.
If Zorder is True, the method will check point.z for
equality with the rectangle origin's Z coordinate. | [
":",
"param",
":",
"point",
"-",
"Point",
"subclass",
":",
"param",
":",
"Zorder",
"-",
"optional",
"Boolean"
] | train | https://github.com/JnyJny/Geometry/blob/3500f815fa56c535b36d1b6fd0afe69ce5d055be/Geometry/rectangle.py#L536-L556 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.