output
stringlengths
1
928k
instruction
stringlengths
7
928k
system
stringlengths
0
104k
Run the linter over the new metadata comparing to the old.
Explain what the following Python 3 code does def metadata_lint(old, new, locations): # ensure we don't modify the metadata old = old.copy() new = new.copy() # remove version info old.pop('$version', None) new.pop('$version', None) for old_group_name in old: if old_group_name not in...
You are a Python code architect, reviewing and designing scalable and efficient code
def lint_api(api_name, old, new, locations): """Lint an acceptable api metadata.""" is_new_api = not old api_location = locations['api'] changelog = new.get('changelog', {}) changelog_location = api_location if locations['changelog']: changelog_location = list(locations['changelog'].val...
Can you write a function in Python 3 where it lints an acceptable api metadata.
You are a Python code analyst, evaluating scripts for potential improvements.
def bind(self, flask_app, service, group=None): """Bind the service API urls to a flask app.""" if group not in self.services[service]: raise RuntimeError( 'API group {} does not exist in service {}'.format( group, service) ) for name, ...
How would you code a function in Python 3 to bind the service API urls to a flask app.
As a Python code translator, you convert algorithms and pseudocode into Python.
def serialize(self): """Serialize into JSONable dict, and associated locations data.""" api_metadata = OrderedDict() # $ char makes this come first in sort ordering api_metadata['$version'] = self.current_version locations = {} for svc_name, group in self.groups(): ...
Write a Python 3 function that can serialize into JSONable dict and associated locations data.
As a Python code analyst, you investigate and solve complex coding mysteries
def api(self, url, name, introduced_at=None, undocumented=False, deprecated_at=None, title=None, **options): """Add an API to the service. :param url: This is the url that the API should be registered at. :param...
Implement a function in Python 3 to add an AcceptableAPI to the service.
You are a Python code architect, reviewing and designing scalable and efficient code
def django_api( self, name, introduced_at, undocumented=False, deprecated_at=None, title=None, **options): """Add a django API handler to the service. :param name: This is the name of the django url to use. The...
How would you code a function in Python 3 to add a django API handler to the service.
As a Python code translator, you convert algorithms and pseudocode into Python.
def bind(self, flask_app): """Bind the service API urls to a flask app.""" self.metadata.bind(flask_app, self.name, self.group)
Create a Python 3 function to bind the service API urls to a flask app.
You are a Python code architect, reviewing and designing scalable and efficient code
Add a changelog entry for this api.
Can you tell what is the following Python 3 function doing def changelog(self, api_version, doc): doc = textwrap.dedent(doc).strip() self._changelog[api_version] = doc self._changelog_locations[api_version] = get_callsite_location()
You are a Python code generator, capable of creating scripts from specifications.
titlePrefix for article JSON is only articles with certain display_channel values
Explain what the following Python 3 code does def title_prefix(soup): "titlePrefix for article JSON is only articles with certain display_channel values" prefix = None display_channel_match_list = ['feature article', 'insight', 'editorial'] for d_channel in display_channel(soup): if d_channel.lo...
You are a Python code generator, capable of creating scripts from specifications.
titlePrefix with capitalisation changed
Can you generate a brief explanation for the following Python 3 code def title_prefix_json(soup): "titlePrefix with capitalisation changed" prefix = title_prefix(soup) prefix_rewritten = elifetools.json_rewrite.rewrite_json("title_prefix_json", soup, prefix) return prefix_rewritten
As a python code expert, you are capable of creating scripts from specifications.
Find the research - organism from the set of kwd - group tags
Can you generate a brief explanation for the following Python 3 code def research_organism(soup): "Find the research-organism from the set of kwd-group tags" if not raw_parser.research_organism_keywords(soup): return [] return list(map(node_text, raw_parser.research_organism_keywords(soup)))
You are a Python code generator, capable of creating scripts from specifications.
def full_research_organism(soup): "research-organism list including inline tags, such as italic" if not raw_parser.research_organism_keywords(soup): return [] return list(map(node_contents_str, raw_parser.research_organism_keywords(soup)))
Implement a function in Python 3 to full research - organism list including inline tags such as italic
As a Python code translator, you convert algorithms and pseudocode into Python.
Return a list of keywords from the set of keywords that are typically labeled as the author keywords.
Can you generate a brief explanation for the following Python 3 code def keywords(soup): if not raw_parser.author_keywords(soup): return [] return list(map(node_text, raw_parser.author_keywords(soup)))
As a Python code analyst, you investigate and solve complex coding mysteries
def full_keywords(soup): "author keywords list including inline tags, such as italic" if not raw_parser.author_keywords(soup): return [] return list(map(node_contents_str, raw_parser.author_keywords(soup)))
Create a Python 3 function to author keywords list including inline tags such as italic
You are a Python code architect, reviewing and designing scalable and efficient code
extract the article version history details
Here you have a function in Python 3, explain what it does def version_history(soup, html_flag=True): "extract the article version history details" convert = lambda xml_string: xml_to_html(html_flag, xml_string) version_history = [] related_object_tags = raw_parser.related_object(raw_parser.article_meta...
You are a Python code generator, capable of creating scripts from specifications.
def article_id_list(soup): """return a list of article-id data""" id_list = [] for article_id_tag in raw_parser.article_id(soup): id_details = OrderedDict() set_if_value(id_details, "type", article_id_tag.get("pub-id-type")) set_if_value(id_details, "value", article_id_tag.text) ...
Create a Python 3 function for returning a list of article - id data
As a python code expert, you are capable of creating scripts from specifications.
for json output add a full stop if ends in et al
Here you have a function in Python 3, explain what it does def copyright_holder_json(soup): "for json output add a full stop if ends in et al" holder = None permissions_tag = raw_parser.article_permissions(soup) if permissions_tag: holder = node_text(raw_parser.copyright_holder(permissions_tag))...
You are a Python code architect, reviewing and designing scalable and efficient code
def subject_area(soup): """ Find the subject areas from article-categories subject tags """ subject_area = [] tags = raw_parser.subject_area(soup) for tag in tags: subject_area.append(node_text(tag)) return subject_area
Write a Python 3 script to find the subject areas from article - categories subject tags
As a Python code analyst, you investigate and solve complex coding mysteries
Find the subject areas of type display - channel
Explain what the following Python 3 code does def display_channel(soup): display_channel = [] tags = raw_parser.display_channel(soup) for tag in tags: display_channel.append(node_text(tag)) return display_channel
As a python code expert, you are capable of creating scripts from specifications.
def category(soup): """ Find the category from subject areas """ category = [] tags = raw_parser.category(soup) for tag in tags: category.append(node_text(tag)) return category
Can you write a function in Python 3 where it finds the category from subject areas
You are a Python code architect, reviewing and designing scalable and efficient code
Get the year month and day from child tags
Can you generate a brief explanation for the following Python 3 code def ymd(soup): day = node_text(raw_parser.day(soup)) month = node_text(raw_parser.month(soup)) year = node_text(raw_parser.year(soup)) return (day, month, year)
As a Python code translator, you convert algorithms and pseudocode into Python.
Return the publication date in struct format
Can you generate the documentation for the following Python 3 function def pub_date(soup): pub_date = first(raw_parser.pub_date(soup, date_type="pub")) if pub_date is None: pub_date = first(raw_parser.pub_date(soup, date_type="publication")) if pub_date is None: return None (day, month, ...
As a Python code composer, you craft elegant and concise scripts.
return a list of all the pub dates
Can you tell what is the following Python 3 function doing def pub_dates(soup): pub_dates = [] tags = raw_parser.pub_date(soup) for tag in tags: pub_date = OrderedDict() copy_attribute(tag.attrs, 'publication-format', pub_date) copy_attribute(tag.attrs, 'date-type', pub_date) ...
As a Python code composer, you craft elegant and concise scripts.
Find a date in the history tag for the given date type
Can you generate a brief explanation for the following Python 3 code def history_date(soup, date_type = None): if(date_type == None): return None history_date = raw_parser.history_date(soup, date_type) if history_date is None: return None (day, month, year) = ymd(history_date) retur...
As a python code expert, you are capable of creating scripts from specifications.
def collection_year(soup): """ Pub date of type collection will hold a year element for VOR articles """ pub_date = first(raw_parser.pub_date(soup, pub_type="collection")) if not pub_date: pub_date = first(raw_parser.pub_date(soup, date_type="collection")) if not pub_date: return...
How would you implement a function in Python 3 that gets the year of the first publication of a VOR article
As a Python code analyst, you investigate and solve complex coding mysteries
Find the article abstract and format it
Can you generate a brief explanation for the following Python 3 code def abstracts(soup): abstracts = [] abstract_tags = raw_parser.abstract(soup) for tag in abstract_tags: abstract = {} abstract["abstract_type"] = tag.get("abstract-type") title_tag = raw_parser.title(tag) ...
As a Python code analyst, you investigate and solve complex coding mysteries
def component_doi(soup): """ Look for all object-id of pub-type-id = doi, these are the component DOI tags """ component_doi = [] object_id_tags = raw_parser.object_id(soup, pub_id_type = "doi") # Get components too for later component_list = components(soup) position = 1 for tag...
Can you write a function in Python 3 where it gets the component DOI from a soup.
As a Python code composer, you craft elegant and concise scripts.
Extract data from the parent tags
Can you tell what is the following Python 3 function doing def tag_details(tag, nodenames): details = {} details['type'] = tag.name details['ordinal'] = tag_ordinal(tag) # Ordinal value if tag_details_sibling_ordinal(tag): details['sibling_ordinal'] = tag_details_sibling_ordinal(tag) ...
As a Python code composer, you craft elegant and concise scripts.
Returns a list of all media tags and some associated data about the related component doi and the parent of that doi
Explain what the following Python 3 code does def media(soup): media = [] media_tags = raw_parser.media(soup) position = 1 for tag in media_tags: media_item = {} copy_attribute(tag.attrs, 'mime-subtype', media_item) copy_attribute(tag.attrs, 'mimetype', media_item) co...
You are a Python code generator, capable of creating scripts from specifications.
def graphics(soup): """ All graphic tags and some associated data about the related component doi and the parent of that doi (not always present), and whether it is part of a figure supplement """ graphics = [] graphic_tags = raw_parser.graphic(soup) position = 1 for tag in graphi...
Can you create a Python 3 function that gets all graphics tags and some associated data about the related component doi and the parent of that doi .
As a python code expert, you are capable of creating scripts from specifications.
def inline_graphics(soup): """ inline-graphic tags """ inline_graphics = [] inline_graphic_tags = raw_parser.inline_graphic(soup) position = 1 for tag in inline_graphic_tags: item = {} copy_attribute(tag.attrs, 'xlink:href', item, 'xlink_href') # Get the tag type...
Can you create a Python 3 function that gets the list of inline - graphic tags from a soup
You are a Python code analyst, evaluating scripts for potential improvements.
Get the self - uri tags from a soup
Here you have a function in Python 3, explain what it does def self_uri(soup): self_uri = [] self_uri_tags = raw_parser.self_uri(soup) position = 1 for tag in self_uri_tags: item = {} copy_attribute(tag.attrs, 'xlink:href', item, 'xlink_href') copy_attribute(tag.attrs, 'content...
You are a Python code generator, capable of creating scripts from specifications.
Get the supplementary - material tags from a soup
Given the following Python 3 function, write the documentation def supplementary_material(soup): supplementary_material = [] supplementary_material_tags = raw_parser.supplementary_material(soup) position = 1 for tag in supplementary_material_tags: item = {} copy_attribute(tag.attrs, ...
As a python code expert, you are capable of creating scripts from specifications.
def contrib_email(contrib_tag): """ Given a contrib tag, look for an email tag, and only return the value if it is not inside an aff tag """ email = [] for email_tag in extract_nodes(contrib_tag, "email"): if email_tag.parent.name != "aff": email.append(email_tag.text) re...
Can you write a function in Python 3 where it gives a contrib tag look for an email tag and return the value if it is not inside an aff tag and return the value if it is not inside an aff tag
As a Python code translator, you convert algorithms and pseudocode into Python.
def contrib_phone(contrib_tag): """ Given a contrib tag, look for an phone tag """ phone = None if raw_parser.phone(contrib_tag): phone = first(raw_parser.phone(contrib_tag)).text return phone
Implement a function in Python 3 to give a contrib tag look for a phone tag
As a Python code composer, you craft elegant and concise scripts.
def contrib_inline_aff(contrib_tag): """ Given a contrib tag, look for an aff tag directly inside it """ aff_tags = [] for child_tag in contrib_tag: if child_tag and child_tag.name and child_tag.name == "aff": aff_tags.append(child_tag) return aff_tags
How would you implement a function in Python 3 that gives a contrib tag look for an aff tag directly inside it
As a Python code composer, you craft elegant and concise scripts.
Given a contrib tag look for an xref tag of type ref_type directly inside the contrib tag
Can you tell what is the following Python 3 function doing def contrib_xref(contrib_tag, ref_type): aff_tags = [] for child_tag in contrib_tag: if (child_tag and child_tag.name and child_tag.name == "xref" and child_tag.get('ref-type') and child_tag.get('ref-type') == ref_type): ...
You are a Python code generator, capable of creating scripts from specifications.
find all contributors not contrained to only the ones in article meta
Explain what the following Python 3 code does def all_contributors(soup, detail="brief"): "find all contributors not contrained to only the ones in article meta" contrib_tags = raw_parser.contributors(soup) contributors = format_authors(soup, contrib_tags, detail) return contributors
As a Python code analyst, you investigate and solve complex coding mysteries
Get a list of non - byline authors for group author members
Here you have a function in Python 3, explain what it does def authors_non_byline(soup, detail="full"): # Get a filtered list of contributors, in order to get their group-author-id contrib_type = "author non-byline" contributors_ = contributors(soup, detail) non_byline_authors = [author for author in co...
You are a Python code architect, reviewing and designing scalable and efficient code
def refs(soup): """Find and return all the references""" tags = raw_parser.ref_list(soup) refs = [] position = 1 article_doi = doi(soup) for tag in tags: ref = {} ref['ref'] = ref_text(tag) # ref_id copy_attribute(tag.attrs, "id", ref) # article_title...
Write a Python 3 script to find and return all the references in a single page.
As a Python code analyst, you investigate and solve complex coding mysteries
Extract the component DOI from a tag and confirm it is actually for that tag and it is not for one of the nodenames.
Given the following Python 3 function, write the documentation def extract_component_doi(tag, nodenames): component_doi = None if(tag.name == "sub-article"): component_doi = doi_uri_to_doi(node_text(first(raw_parser.article_id(tag, pub_id_type= "doi")))) else: object_id_tag = first(raw_pars...
As a python code expert, you are capable of creating scripts from specifications.
Find the components of a given soup.
Can you generate a brief explanation for the following Python 3 code def components(soup): components = [] nodenames = ["abstract", "fig", "table-wrap", "media", "chem-struct-wrap", "sub-article", "supplementary-material", "boxed-text", "app"] # Count node order overall ...
As a Python code analyst, you investigate and solve complex coding mysteries
def correspondence(soup): """ Find the corresp tags included in author-notes for primary correspondence """ correspondence = [] author_notes_nodes = raw_parser.author_notes(soup) if author_notes_nodes: corresp_nodes = raw_parser.corresp(author_notes_nodes) for tag in corres...
Implement a function in Python 3 to find the corresp tags included in author - notes for primary correspondence
As a Python code analyst, you investigate and solve complex coding mysteries
Return a list of the text of the author - notes for the given soup.
Explain what the following Python 3 code does def author_notes(soup): author_notes = [] author_notes_section = raw_parser.author_notes(soup) if author_notes_section: fn_nodes = raw_parser.fn(author_notes_section) for tag in fn_nodes: if 'fn-type' in tag.attrs: if...
As a Python code composer, you craft elegant and concise scripts.
Find the full list of author - notes from a soup
Explain what the following Python 3 code does def full_author_notes(soup, fntype_filter=None): notes = [] author_notes_section = raw_parser.author_notes(soup) if author_notes_section: fn_nodes = raw_parser.fn(author_notes_section) notes = footnotes(fn_nodes, fntype_filter) return notes
As a Python code translator, you convert algorithms and pseudocode into Python.
def competing_interests(soup, fntype_filter): """ Find the fn tags included in the competing interest """ competing_interests_section = extract_nodes(soup, "fn-group", attr="content-type", value="competing-interest") if not competing_interests_section: return None fn = extract_nodes(fir...
Create a Python 3 function to find the footnotes of the competing interests in the given soup.
You are a Python code analyst, evaluating scripts for potential improvements.
def author_contributions(soup, fntype_filter): """ Find the fn tags included in the competing interest """ author_contributions_section = extract_nodes(soup, "fn-group", attr="content-type", value="author-contribution") if not author_contributions_section: return None fn = extract_nodes...
Implement a Python 3 function for finding the author - contribution tags in the given soup
You are a Python code analyst, evaluating scripts for potential improvements.
Find the full award - group items and return a list of details
Can you generate a brief explanation for the following Python 3 code def full_award_groups(soup): award_groups = [] funding_group_section = extract_nodes(soup, "funding-group") # counter for auto generated id values, if required generated_id_counter = 1 for fg in funding_group_section: awa...
As a python code expert, you are capable of creating scripts from specifications.
Find the award - group items and return a list of details
Here you have a function in Python 3, explain what it does def award_groups(soup): award_groups = [] funding_group_section = extract_nodes(soup, "funding-group") for fg in funding_group_section: award_group_tags = extract_nodes(fg, "award-group") for ag in award_group_tags: a...
You are a Python code analyst, evaluating scripts for potential improvements.
def award_group_funding_source(tag): """ Given a funding group element Find the award group funding sources, one for each item found in the get_funding_group section """ award_group_funding_source = [] funding_source_tags = extract_nodes(tag, "funding-source") for t in funding_source_tag...
Write a Python 3 script for giving a funding group element find the award group funding sources
You are a Python code analyst, evaluating scripts for potential improvements.
def full_award_group_funding_source(tag): """ Given a funding group element Find the award group funding sources, one for each item found in the get_funding_group section """ award_group_funding_sources = [] funding_source_nodes = extract_nodes(tag, "funding-source") for funding_source_n...
Write a Python 3 function that can give a funding group element find the full award group funding sources
As a Python code composer, you craft elegant and concise scripts.
Find the award group award id from the given tag
Make a summary of the following Python 3 code def award_group_award_id(tag): award_group_award_id = [] award_id_tags = extract_nodes(tag, "award-id") for t in award_id_tags: award_group_award_id.append(t.text) return award_group_award_id
As a Python code composer, you craft elegant and concise scripts.
Find the award group principal award recipient.
Can you generate a brief explanation for the following Python 3 code def award_group_principal_award_recipient(tag): award_group_principal_award_recipient = [] principal_award_recipients = extract_nodes(tag, "principal-award-recipient") for t in principal_award_recipients: principal_award_recipient...
As a Python code translator, you convert algorithms and pseudocode into Python.
DOI in an object - id tag found inside the tag
Can you generate a brief explanation for the following Python 3 code def object_id_doi(tag, parent_tag_name=None): doi = None object_id = None object_ids = raw_parser.object_id(tag, "doi") if object_ids: object_id = first([id_ for id_ in object_ids]) if parent_tag_name and object_id and obje...
You are a Python code generator, capable of creating scripts from specifications.
Extract the title tag and sometimes inspect its parents
Can you tell what is the following Python 3 function doing def title_tag_inspected(tag, parent_tag_name=None, p_parent_tag_name=None, direct_sibling_only=False): title_tag = None if direct_sibling_only is True: for sibling_tag in tag: if sibling_tag.name and sibling_tag.name == "title": ...
You are a Python code generator, capable of creating scripts from specifications.
Extract the text of a title tag and sometimes inspect its parents
Can you generate a brief explanation for the following Python 3 code def title_text(tag, parent_tag_name=None, p_parent_tag_name=None, direct_sibling_only=False): title = None title_tag = title_tag_inspected(tag, parent_tag_name, p_parent_tag_name, direct_sibling_only) if title_tag: title = node_c...
As a Python code translator, you convert algorithms and pseudocode into Python.
covert boxed - text to an image block containing an inline - graphic
Can you generate a brief explanation for the following Python 3 code def boxed_text_to_image_block(tag): "covert boxed-text to an image block containing an inline-graphic" tag_block = OrderedDict() image_content = body_block_image_content(first(raw_parser.inline_graphic(tag))) tag_block["type"] = "image...
You are a Python code analyst, evaluating scripts for potential improvements.
def body_json(soup, base_url=None): """ Get body json and then alter it with section wrapping and removing boxed-text """ body_content = body(soup, remove_key_info_box=True, base_url=base_url) # Wrap in a section if the first block is not a section if (body_content and len(body_content) > 0 and "type" i...
Create a Python 3 function to get body json and alter it with section wrapping and removing boxed - text
You are a Python code architect, reviewing and designing scalable and efficient code
Render the tag as body content and call recursively if recursive is True
Here you have a function in Python 3, explain what it does def body_block_content_render(tag, recursive=False, base_url=None): block_content_list = [] tag_content = OrderedDict() if tag.name == "p": for block_content in body_block_paragraph_render(tag, base_url=base_url): if block_conte...
As a Python code composer, you craft elegant and concise scripts.
def body_block_paragraph_render(p_tag, html_flag=True, base_url=None): """ paragraphs may wrap some other body block content this is separated out so it can be called from more than one place """ # Configure the XML to HTML conversion preference for shorthand use below convert = lambda xml_strin...
Implement a function in Python 3 to paragraph may wrap some other body block content this is separated out so it can be called from more than one place
As a Python code analyst, you investigate and solve complex coding mysteries
This function will take a list of caption tags and return a list of the caption content and supplementary material tags.
Explain what the following Python 3 code does def body_block_caption_render(caption_tags, base_url=None): caption_content = [] supplementary_material_tags = [] for block_tag in remove_doi_paragraph(caption_tags): # Note then skip p tags with supplementary-material inside if raw_parser.suppl...
As a python code expert, you are capable of creating scripts from specifications.
def body_block_supplementary_material_render(supp_tags, base_url=None): """fig and media tag caption may have supplementary material""" source_data = [] for supp_tag in supp_tags: for block_content in body_block_content_render(supp_tag, base_url=base_url): if block_content != {}: ...
How would you implement a function in Python 3 that renders supplementary material for the given list of supplementary tags.
You are a Python code analyst, evaluating scripts for potential improvements.
for formatting of simple paragraphs of text only and check if it is all whitespace
Here you have a function in Python 3, explain what it does def body_block_paragraph_content(text): "for formatting of simple paragraphs of text only, and check if it is all whitespace" tag_content = OrderedDict() if text and text != '': tag_content["type"] = "paragraph" tag_content["text"] =...
As a Python code analyst, you investigate and solve complex coding mysteries
def body_block_image_content(tag): "format a graphic or inline-graphic into a body block json format" image_content = OrderedDict() if tag: copy_attribute(tag.attrs, 'xlink:href', image_content, 'uri') if "uri" in image_content: # todo!! alt set_if_value(image_content...
Write a Python 3 function that can format a graphic or inline - graphic into a body block json format
You are a Python code architect, reviewing and designing scalable and efficient code
set the title label and caption values in a consistent way
Explain what the following Python 3 code does def body_block_title_label_caption(tag_content, title_value, label_value, caption_content, set_caption=True, prefer_title=False, prefer_label=False): """set the title, label and caption values in a consistent way set_caption: inse...
As a Python code analyst, you investigate and solve complex coding mysteries
def body_block_attribution(tag): "extract the attribution content for figures, tables, videos" attributions = [] if raw_parser.attrib(tag): for attrib_tag in raw_parser.attrib(tag): attributions.append(node_contents_str(attrib_tag)) if raw_parser.permissions(tag): # concatena...
Write a Python 3 function for extracting the attribution content for figures tables videos
You are a Python code generator, capable of creating scripts from specifications.
def body_blocks(soup): """ Note: for some reason this works and few other attempted methods work Search for certain node types, find the first nodes siblings of the same type Add the first sibling and the other siblings to a list and return them """ nodenames = body_block_nodenames() body_b...
Can you create a Python 3 function that gets a list of all the body blocks that are part of the page
You are a Python code generator, capable of creating scripts from specifications.
abstract in article json format
How would you explain what the following Python 3 function does def abstract_json(soup): abstract_tags = raw_parser.abstract(soup) abstract_json = None for tag in abstract_tags: if tag.get("abstract-type") is None: abstract_json = render_abstract_json(tag) return abstract_json
You are a Python code architect, reviewing and designing scalable and efficient code
def digest_json(soup): """digest in article json format""" abstract_tags = raw_parser.abstract(soup, abstract_type="executive-summary") abstract_json = None for tag in abstract_tags: abstract_json = render_abstract_json(tag) return abstract_json
Can you create a Python 3 function that digests in article json format
You are a Python code generator, capable of creating scripts from specifications.
def author_affiliations(author, html_flag=True): """compile author affiliations for json output""" # Configure the XML to HTML conversion preference for shorthand use below convert = lambda xml_string: xml_to_html(html_flag, xml_string) affilations = [] if author.get("affiliations"): for ...
Write a Python 3 function for compiling author affiliations for json output
You are a Python code generator, capable of creating scripts from specifications.
def author_json_details(author, author_json, contributions, correspondence, competing_interests, equal_contributions_map, present_address_data, foot_notes_data, html_flag=True): # Configure the XML to HTML conversion preference for shorthand use below convert = la...
Create a Python 3 function for adding more author json
As a Python code analyst, you investigate and solve complex coding mysteries
def collab_to_group_author_key_map(authors): """compile a map of author collab to group-author-key""" collab_map = {} for author in authors: if author.get("collab"): collab_map[author.get("collab")] = author.get("group-author-key") return collab_map
Write a Python 3 script to compile a map of author collab to group - author - key
As a Python code analyst, you investigate and solve complex coding mysteries
map numeric values to each unique equal - contrib id
Can you tell what is the following Python 3 function doing def map_equal_contributions(contributors): equal_contribution_map = {} equal_contribution_keys = [] for contributor in contributors: if contributor.get("references") and "equal-contrib" in contributor.get("references"): for key i...
You are a Python code analyst, evaluating scripts for potential improvements.
def authors_json(soup): """authors list in article json format""" authors_json_data = [] contributors_data = contributors(soup, "full") author_contributions_data = author_contributions(soup, None) author_competing_interests_data = competing_interests(soup, None) author_correspondence_data = full...
How would you code a function in Python 3 to return a list of authors in article json format
As a Python code analyst, you investigate and solve complex coding mysteries
take preferred names from authors json and format them into an author line
Here you have a function in Python 3, explain what it does def author_line(soup): author_line = None authors_json_data = authors_json(soup) author_names = extract_author_line_names(authors_json_data) if len(author_names) > 0: author_line = format_author_line(author_names) return author_line
You are a Python code generator, capable of creating scripts from specifications.
authorLine format depends on if there is 1, 2 or more than 2 authors
Can you generate a brief explanation for the following Python 3 code def format_author_line(author_names): author_line = None if not author_names: return author_line if len(author_names) <= 2: author_line = ", ".join(author_names) elif len(author_names) > 2: author_line = author_...
You are a Python code analyst, evaluating scripts for potential improvements.
def references_date(year=None): "Handle year value parsing for some edge cases" date = None discriminator = None in_press = None if year and "in press" in year.lower().strip(): in_press = True elif year and re.match("^[0-9]+$", year): date = year elif year: discrimina...
How would you code a function in Python 3 to handle year value parsing for some edge cases
You are a Python code generator, capable of creating scripts from specifications.
def references_json_authors(ref_authors, ref_content): "build the authors for references json here for testability" all_authors = references_authors(ref_authors) if all_authors != {}: if ref_content.get("type") in ["conference-proceeding", "journal", "other", ...
Implement a Python 3 function for building the authors for references json here for testability
You are a Python code analyst, evaluating scripts for potential improvements.
def convert_references_json(ref_content, soup=None): "Check for references that will not pass schema validation, fix or convert them to unknown" # Convert reference to unkonwn if still missing important values if ( (ref_content.get("type") == "other") or (ref_content.get("type") == ...
Can you write a function in Python 3 where it checks for references that will not pass schema validation fix or convert them to unknown
You are a Python code architect, reviewing and designing scalable and efficient code
Extract detail value for references of type unknown
Explain what the following Python 3 code does def references_json_unknown_details(ref_content, soup=None): "Extract detail value for references of type unknown" details = "" # Try adding pages values first if "pages" in ref_content: if "range" in ref_content["pages"]: details += ref...
As a python code expert, you are capable of creating scripts from specifications.
for use in removing unwanted boxed - content from appendices json
Explain what the following Python 3 code does def unwrap_appendix_box(json_content): if json_content.get("content") and len(json_content["content"]) > 0: first_block = json_content["content"][0] if (first_block.get("type") and first_block.get("type") == "box" and first_block....
As a Python code translator, you convert algorithms and pseudocode into Python.
def extract_schemas_from_file(source_path): """Extract schemas from 'source_path'. :returns: a list of ViewSchema objects on success, None if no schemas could be extracted. """ logging.info("Extracting schemas from %s", source_path) try: with open(source_path, 'r') as source_file: ...
Can you create a Python 3 function that extracts schemas from source_path.
As a Python code analyst, you investigate and solve complex coding mysteries
Get simple assignments from node tree.
Make a summary of the following Python 3 code def _get_simple_assignments(tree): result = {} for node in ast.walk(tree): if isinstance(node, ast.Assign): for target in node.targets: if isinstance(target, ast.Name): result[target.id] = node.value return...
You are a Python code analyst, evaluating scripts for potential improvements.
Extract schemas from source.
Make a summary of the following Python 3 code def extract_schemas_from_source(source, filename='<unknown>'): # Track which acceptable services have been configured. acceptable_services = set() # Track which acceptable views have been configured: acceptable_views = {} schemas_found = [] ast_tree ...
You are a Python code analyst, evaluating scripts for potential improvements.
def render_value(value): """Render a value, ensuring that any nested dicts are sorted by key.""" if isinstance(value, list): return '[' + ', '.join(render_value(v) for v in value) + ']' elif isinstance(value, dict): return ( '{' + ', '.join('{k!r}: {v}'.format( ...
Implement a function in Python 3 to render a value ensuring that any nested dicts are sorted by key.
You are a Python code generator, capable of creating scripts from specifications.
def write_service_double_file(target_root, service_name, rendered): """Render syntactically valid python service double code.""" target_path = os.path.join( target_root, 'snapstore_schemas', 'service_doubles', '%s.py' % service_name ) with open(target_path, 'w') as target_file: t...
How would you implement a function in Python 3 that writes a syntactically valid python service double code.
As a Python code composer, you craft elegant and concise scripts.
Recursively sorts a JSON schema by dict key.
Can you generate a brief explanation for the following Python 3 code def _sort_schema(schema): if isinstance(schema, dict): for k, v in sorted(schema.items()): if isinstance(v, dict): yield k, OrderedDict(_sort_schema(v)) elif isinstance(v, list): yie...
You are a Python code analyst, evaluating scripts for potential improvements.
Recursively build a map of ( group name path ) => url patterns.
Given the following Python 3 function, write the documentation def urlmap(patterns): for pattern in patterns: group = getattr(pattern, 'namespace', None) if group is None: group = getattr(pattern, 'app_name', None) path = '/' + get_pattern(pattern).lstrip('^').rstrip('$') ...
You are a Python code architect, reviewing and designing scalable and efficient code
Returns a JSON Schema representation of a form field.
Can you tell what is the following Python 3 function doing def get_field_schema(name, field): field_schema = { 'type': 'string', } if field.label: field_schema['title'] = str(field.label) # force translation if field.help_text: field_schema['description'] = str(field.help_text...
You are a Python code analyst, evaluating scripts for potential improvements.
Return a JSON Schema object for a Django Form.
Here you have a function in Python 3, explain what it does def get_form_schema(form): schema = { 'type': 'object', 'properties': {}, } for name, field in form.base_fields.items(): schema['properties'][name] = get_field_schema(name, field) if field.required: schem...
As a Python code analyst, you investigate and solve complex coding mysteries
def handler(self, handler_class): """Link to an API handler class (e.g. piston or DRF).""" self.handler_class = handler_class # we take the docstring from the handler class, not the methods if self.docs is None and handler_class.__doc__: self.docs = clean_docstring(handler_cl...
Write a Python 3 function that can link to an API handler class.
You are a Python code generator, capable of creating scripts from specifications.
Replace simple tags such as italic to i
How would you explain what the following Python 3 function does def replace_simple_tags(s, from_tag='italic', to_tag='i', to_open_tag=None): if to_open_tag: s = s.replace('<' + from_tag + '>', to_open_tag) elif to_tag: s = s.replace('<' + from_tag + '>', '<' + to_tag + '>') s = s.replace...
As a Python code analyst, you investigate and solve complex coding mysteries
def validate_body(schema): """Validate the body of incoming requests for a flask view. An example usage might look like this:: from snapstore_schemas import validate_body @validate_body({ 'type': 'array', 'items': { 'type': 'object', 'p...
Implement a Python 3 function for validating the body of incoming requests for a flask view. An example usage might look like this:: from snapstore_schemas import validate_body @validate_body({ 'type': 'array', 'items': { 'type': 'object', 'properties': { 'snap_id': {'type': 'string'}, 'series': {'type': 'string'}, 'na...
You are a Python code architect, reviewing and designing scalable and efficient code
def record_schemas( fn, wrapper, location, request_schema=None, response_schema=None): """Support extracting the schema from the decorated function.""" # have we already been decorated by an acceptable api call? has_acceptable = hasattr(fn, '_acceptable_metadata') if request_schema is not None:...
How would you implement a function in Python 3 that supports extracting the schema from the decorated function.
You are a Python code analyst, evaluating scripts for potential improvements.
def validate_output(schema): """Validate the body of a response from a flask view. Like `validate_body`, this function compares a json document to a jsonschema specification. However, this function applies the schema to the view response. Instead of the view returning a flask response object, it s...
How would you code a function in Python 3 to validate the body of a flask view against a schema.
As a Python code analyst, you investigate and solve complex coding mysteries
Validate payload against schema returning an error list.
Given the following Python 3 function, write the documentation def validate(payload, schema): v = jsonschema.Draft4Validator( schema, format_checker=jsonschema.FormatChecker()) error_list = [] for error in v.iter_errors(payload): message = error.message location = '/' + '/'.join([str...
You are a Python code analyst, evaluating scripts for potential improvements.
Connects to a Phoenix query server.
Given the following Python 3 function, write the documentation def connect(url, max_retries=None, **kwargs): client = AvaticaClient(url, max_retries=max_retries) client.connect() return Connection(client, **kwargs)
You are a Python code analyst, evaluating scripts for potential improvements.
Opens a HTTP connection to the RPC server.
Here you have a function in Python 3, explain what it does def connect(self): logger.debug("Opening connection to %s:%s", self.url.hostname, self.url.port) try: self.connection = httplib.HTTPConnection(self.url.hostname, self.url.port) self.connection.connect() except (ht...
You are a Python code generator, capable of creating scripts from specifications.
def close(self): """Closes the HTTP connection to the RPC server.""" if self.connection is not None: logger.debug("Closing connection to %s:%s", self.url.hostname, self.url.port) try: self.connection.close() except httplib.HTTPException: ...
Implement a Python 3 function for closing the HTTP connection to the RPC server.
As a Python code composer, you craft elegant and concise scripts.
def connection_sync(self, connection_id, connProps=None): """Synchronizes connection properties with the server. :param connection_id: ID of the current connection. :param connProps: Dictionary with the properties that should be changed. :returns: A...
Write a Python 3 function that can synchronize the current connection properties with the server.
As a Python code translator, you convert algorithms and pseudocode into Python.