query stringlengths 9 3.4k | document stringlengths 9 87.4k | metadata dict | negatives listlengths 4 101 | negative_scores listlengths 4 101 | document_score stringlengths 3 10 | document_rank stringclasses 102
values |
|---|---|---|---|---|---|---|
get the path of the page depending on the given language | def get_path(self, language=None, fallback=True, version_id=None, force_reload=False):
return self.get_title_obj_attribute("path", language, fallback, version_id, force_reload) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_localised_dir(self, language):\n return os.path.join(\n self.base_path,\n to_locale(language),\n self.content_path\n )",
"def translate_url(context, lang_code):\n # thanks to https://stackoverflow.com/a/51974042\n path = context.get(\"request\").get_fu... | [
"0.6667135",
"0.6576727",
"0.6028769",
"0.60194516",
"0.5998736",
"0.5993915",
"0.5961393",
"0.5933334",
"0.59209335",
"0.5895291",
"0.58546114",
"0.58436507",
"0.583109",
"0.5797118",
"0.5775825",
"0.5774116",
"0.57501113",
"0.5740522",
"0.5720349",
"0.5684372",
"0.568433",
... | 0.5887548 | 10 |
get the slug of the page depending on the given language | def get_slug(self, language=None, fallback=True, version_id=None, force_reload=False):
return self.get_title_obj_attribute("slug", language, fallback, version_id, force_reload) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_slug_in_language(record, language):\n if not record or not hasattr(record, \"safe_translation_getter\"):\n return None\n return record.safe_translation_getter(\n field=\"slug\", language_code=language, default=None, )",
"def get_default_lang_slug(instance):\n try:\n default_... | [
"0.7302063",
"0.6909704",
"0.6251314",
"0.60584575",
"0.59389293",
"0.5898402",
"0.5826802",
"0.58102244",
"0.58080703",
"0.5805271",
"0.5786454",
"0.57102716",
"0.5641056",
"0.5612126",
"0.561158",
"0.5601095",
"0.55954343",
"0.5508412",
"0.54940337",
"0.5490622",
"0.5445196... | 0.6829196 | 2 |
get the title of the page depending on the given language | def get_title(self, language=None, fallback=True, version_id=None, force_reload=False):
return self.get_title_obj_attribute("title", language, fallback, version_id, force_reload) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_title():",
"def get_page_title(self, language=None, fallback=False, version_id=None, force_reload=False):\n page_title = self.get_title_obj_attribute(\"page_title\", language, fallback, version_id, force_reload)\n if not page_title:\n return self.get_menu_title(language, True, ve... | [
"0.7281408",
"0.72495645",
"0.72407573",
"0.714993",
"0.67892957",
"0.6720059",
"0.67147255",
"0.6711752",
"0.66082484",
"0.6551873",
"0.64955837",
"0.64862525",
"0.6431003",
"0.64291364",
"0.64209545",
"0.64209545",
"0.6356931",
"0.63487184",
"0.63487184",
"0.63487184",
"0.6... | 0.69217676 | 4 |
get the menu title of the page depending on the given language | def get_menu_title(self, language=None, fallback=False, version_id=None, force_reload=False):
menu_title = self.get_title_obj_attribute("menu_title", language, fallback, version_id, force_reload)
if not menu_title:
return self.get_title(language, True, version_id, force_reload)
retur... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def getTitle(self):\n return self.context.getTitle(self.getLanguage())",
"def get_title():",
"def get_title_menu(self):\n return _(self.view_label).capitalize()",
"def get_page_title(self, language=None, fallback=False, version_id=None, force_reload=False):\n page_title = self.get_title_... | [
"0.6920393",
"0.68973166",
"0.671494",
"0.6652602",
"0.6392951",
"0.63896",
"0.6386491",
"0.6281369",
"0.62758493",
"0.62048024",
"0.6185566",
"0.61490595",
"0.61490595",
"0.61161995",
"0.60877156",
"0.6074168",
"0.6031214",
"0.6019012",
"0.6019012",
"0.5997675",
"0.5944884",... | 0.7287521 | 0 |
get the page title of the page depending on the given language | def get_page_title(self, language=None, fallback=False, version_id=None, force_reload=False):
page_title = self.get_title_obj_attribute("page_title", language, fallback, version_id, force_reload)
if not page_title:
return self.get_menu_title(language, True, version_id, force_reload)
... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def getTitle(self, language=None):\n document = self._get_or_add(language)\n return document.title",
"def getTitle(self):\n return self.context.getTitle(self.getLanguage())",
"def get_title():",
"def page_title(self):\n # if view explicitly sets a page_title, use it\n if se... | [
"0.71803176",
"0.70723855",
"0.6914621",
"0.68383604",
"0.6718075",
"0.66928214",
"0.6652376",
"0.65748155",
"0.65583384",
"0.65247035",
"0.6469829",
"0.63917917",
"0.6382786",
"0.63718766",
"0.6353152",
"0.63526255",
"0.63420594",
"0.6260748",
"0.62148196",
"0.62148196",
"0.... | 0.737846 | 0 |
get content for the description meta tag for the page depending on the given language | def get_meta_description(self, language=None, fallback=True, version_id=None, force_reload=False):
return self.get_title_obj_attribute("meta_description", language, fallback, version_id, force_reload) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_meta_description(self, article):\r\n return self.get_meta_content(article.doc, \"meta[name=description]\")",
"def description_mega(self, html): # pylint: disable=too-many-statements,too-many-branches\n description_list = []\n with suppress(Exception):\n '''\n T... | [
"0.699441",
"0.6745166",
"0.6740249",
"0.67005473",
"0.6627198",
"0.65410584",
"0.6275418",
"0.623432",
"0.6216396",
"0.6161247",
"0.614077",
"0.61108243",
"0.6075515",
"0.6053459",
"0.605007",
"0.60121346",
"0.5990863",
"0.5965748",
"0.59061915",
"0.5887589",
"0.5883138",
... | 0.70003384 | 0 |
get content for the keywords meta tag for the page depending on the given language | def get_meta_keywords(self, language=None, fallback=True, version_id=None, force_reload=False):
return self.get_title_obj_attribute("meta_keywords", language, fallback, version_id, force_reload) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_meta_keywords(self):\n return self.get_meta_content(self.article.doc, \"meta[name=keywords]\")",
"def get_webpage_keywords(self, response):\n tags = response.xpath('//*/meta[@property=\"keywords\"]/@content').extract_first()\n tags1 = response.xpath('//*/meta[@name=\"keywords\"]/@con... | [
"0.676739",
"0.6639563",
"0.6584144",
"0.6389217",
"0.62699366",
"0.61207944",
"0.6000832",
"0.5991287",
"0.5981294",
"0.5977819",
"0.5944709",
"0.58829457",
"0.5801803",
"0.57604015",
"0.5757392",
"0.5623684",
"0.55478525",
"0.5525141",
"0.5517788",
"0.5509089",
"0.5507465",... | 0.6496514 | 3 |
get application urls conf for application hook | def get_application_urls(self, language=None, fallback=True, version_id=None, force_reload=False):
return self.get_title_obj_attribute("application_urls", language, fallback, version_id, force_reload) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def urls(self):\n return lambda : self.config.urls(active_only=True)",
"def app_url(self):\n return self.request.host_url",
"def getURLs():",
"def inject_urls():\n return dict(company_name=config.company_name)",
"def url(self):\n return app.settings.cherrypy.url()",
"def appurl( instk... | [
"0.7195572",
"0.6960265",
"0.68794686",
"0.6843109",
"0.6598243",
"0.6364139",
"0.6350292",
"0.63497216",
"0.6319249",
"0.630334",
"0.6275786",
"0.6243338",
"0.6219739",
"0.6168902",
"0.6131243",
"0.61080205",
"0.61038977",
"0.6099552",
"0.6087151",
"0.60707104",
"0.60563594"... | 0.6093747 | 18 |
get the template of this page. | def get_template(self):
return self.template | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def GetTemplate(self, _page_data):\n return self.template",
"def get_template(self):\n if self.get_website:\n return self.get_website.get_template()\n else:\n return default_entity.get_website.get_template()",
"def template(self):\n return self._template",
"def t... | [
"0.8522231",
"0.81524044",
"0.7965052",
"0.7965052",
"0.7965052",
"0.7895042",
"0.7553917",
"0.75520504",
"0.7433693",
"0.7346615",
"0.7325824",
"0.7264637",
"0.72359586",
"0.69926757",
"0.6973034",
"0.69549125",
"0.6891636",
"0.6882589",
"0.68770707",
"0.68127596",
"0.681229... | 0.85542464 | 0 |
get the template of this page if defined or if closer parent if defined or DEFAULT_PAGE_TEMPLATE otherwise | def get_template_name(self):
template = None
if self.template:
template = self.template
if not template:
for p in self.get_ancestors(ascending=True):
if p.template:
template = p.template
break
if not templat... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_template(self):\n if self.get_website:\n return self.get_website.get_template()\n else:\n return default_entity.get_website.get_template()",
"def GetTemplate(self, _page_data):\n return self.template",
"def get_template_name(self):\n if self.template_name:\... | [
"0.6953846",
"0.6819903",
"0.6446561",
"0.6422601",
"0.63925564",
"0.63040316",
"0.62543637",
"0.61951923",
"0.56871915",
"0.5661854",
"0.5622901",
"0.56095",
"0.5555399",
"0.5551583",
"0.55412394",
"0.553155",
"0.55284125",
"0.54785556",
"0.54785556",
"0.54650855",
"0.546165... | 0.6979716 | 0 |
Has user ability to change permissions for current page? | def has_change_permissions_permission(self, request):
return self.has_generic_permission(request, "change_permissions") | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def changePermissions(self, event):\n pass",
"def permissions():\n pass",
"def test_permissions(self):\n \n from pages.permissions import PagePermission\n admin = User.objects.get(username='admin')\n page = self.new_page()\n pp = PagePermission(user=page.author)\n ... | [
"0.714865",
"0.70399934",
"0.6971559",
"0.6871188",
"0.68571097",
"0.68110865",
"0.6798078",
"0.672773",
"0.668785",
"0.6668849",
"0.65769285",
"0.65769285",
"0.65769285",
"0.65769285",
"0.65769285",
"0.65670377",
"0.65623647",
"0.6544074",
"0.6538024",
"0.6530861",
"0.650631... | 0.6499129 | 21 |
Has user ability to add page under current page? | def has_add_permission(self, request):
return self.has_generic_permission(request, "add") | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def add_page(self, page): \n self.pages.append(Page(page))",
"def can_add_menu_page(self):\n if not self.is_admin:\n return False\n return self.config.dbs.pages.for_slot(\"menu\", barcamp=self.barcamp).count() < 3",
"def add_page(self, edition_id, page): \n journal = self... | [
"0.6781153",
"0.65874547",
"0.6528876",
"0.6331094",
"0.6238765",
"0.614804",
"0.61327815",
"0.61216354",
"0.61215097",
"0.61149716",
"0.6102845",
"0.6084655",
"0.6084655",
"0.60625875",
"0.6025954",
"0.59758973",
"0.5972364",
"0.5972364",
"0.5927414",
"0.58913934",
"0.577331... | 0.567375 | 29 |
Has user ability to move current page? | def has_move_page_permission(self, request):
return self.has_generic_permission(request, "move_page") | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def move_page(self, target, position='first-child'):\n self.move_to(target, position)\n # fire signal\n \n self.force_moderation_action = PageModeratorState.ACTION_MOVE\n cms_signals.page_moved.send(sender=Page, instance=self) #titles get saved before moderation\n self.sav... | [
"0.64280534",
"0.6187641",
"0.61322004",
"0.58813006",
"0.58044183",
"0.578107",
"0.57779676",
"0.5712148",
"0.5658178",
"0.56542987",
"0.56440187",
"0.5615534",
"0.5597054",
"0.5594646",
"0.5581836",
"0.54903746",
"0.5489693",
"0.5466242",
"0.54378325",
"0.5430318",
"0.54303... | 0.67411345 | 0 |
Has user ability to moderate current page? If moderation isn't installed, nobody can moderate. | def has_moderate_permission(self, request):
if not settings.CMS_MODERATOR:
return False
return self.has_generic_permission(request, "moderate") | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def current_user_moderating(self):\n return self.user_moderating(users.GetCurrentUser())",
"def can_be_moderated_by(user):\n return user.is_active and user.is_staff and (\n user.has_perm('blog.change_membership') or\n user.has_perm('blog.change_blog'))",
"def is_moderator(self... | [
"0.7437271",
"0.7325415",
"0.72624916",
"0.68007153",
"0.65837425",
"0.65674955",
"0.6538372",
"0.6484397",
"0.6445654",
"0.64426666",
"0.6377128",
"0.63274056",
"0.63235515",
"0.62783694",
"0.6265251",
"0.6246652",
"0.62361526",
"0.6231501",
"0.6224706",
"0.6207935",
"0.6200... | 0.76758987 | 0 |
Return true if the current user has permission on the page. Return the string 'All' if the user has all rights. | def has_generic_permission(self, request, type):
att_name = "permission_%s_cache" % type
if not hasattr(self, "permission_user_cache") or not hasattr(self, att_name) \
or request.user.pk != self.permission_user_cache.pk:
from cms.utils.permissions import has_generic_... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def can_view_all(self):\n return self.request.user.has_permission(\"core.view_all_members\")",
"def has_permission_to_view(page, user):\n if page.permissions.count() == 0:\n return True\n for perm in page.permissions.all():\n perm_label = '%s.%s' % (perm.content_type.app_label, perm.co... | [
"0.7256139",
"0.7166198",
"0.7092246",
"0.6876739",
"0.681808",
"0.6816654",
"0.6807455",
"0.6800733",
"0.67991513",
"0.6795778",
"0.6773063",
"0.67362964",
"0.663953",
"0.663953",
"0.663953",
"0.6632615",
"0.6562264",
"0.6556973",
"0.6531856",
"0.6527152",
"0.6526607",
"0.... | 0.0 | -1 |
Returns path (relative to MEDIA_ROOT/MEDIA_URL) to directory for storing pagescope files. This allows multiple pages to contain files with identical names without namespace issues. Plugins such as Picture can use this method to initialise the 'upload_to' parameter for | def get_media_path(self, filename):
return join(settings.CMS_PAGE_MEDIA_PATH, "%d" % self.id, filename) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def upload_dir(self):\n return os.path.join(settings.MEDIA_ROOT,self.upload_dir_rel())",
"def public_upload_dir(self):\n return os.path.join(settings.MEDIA_ROOT,\n self.public_upload_dir_rel())",
"def get_upload_path(instance, filename):\n return os.path.join(getattr... | [
"0.75417954",
"0.7337136",
"0.69482565",
"0.6842317",
"0.6789822",
"0.6673382",
"0.6609158",
"0.66040426",
"0.6584662",
"0.63800055",
"0.6354606",
"0.6346663",
"0.6338599",
"0.6182578",
"0.61359954",
"0.6135264",
"0.6113495",
"0.60989684",
"0.6035798",
"0.60146284",
"0.599824... | 0.6443212 | 9 |
Returns last page state if CMS_MODERATOR | def last_page_state(self):
# TODO: optimize SQL... 1 query per page
if settings.CMS_MODERATOR:
# unknown state if no moderator
try:
return self.pagemoderatorstate_set.all().order_by('-created',)[0]
except IndexError:
pass
... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def is_last_page(self):\n return self.page == self.last_page",
"def get_last_page(self):\n return self.last_page",
"def get_latest(self):\n self.cprint(\"##\\tGetting max page number...\\n\", log=True)\n return 1",
"def is_last_allowable_page(self):\n if self.countable:\n ... | [
"0.63260895",
"0.6136354",
"0.5797387",
"0.5597132",
"0.5579155",
"0.55518484",
"0.5538862",
"0.5519774",
"0.5512011",
"0.54611725",
"0.53687274",
"0.53618336",
"0.5323161",
"0.5318444",
"0.53029406",
"0.5288249",
"0.5263255",
"0.52350307",
"0.5232209",
"0.52288336",
"0.51542... | 0.81155026 | 0 |
Returns ordered set of all PageModerator instances, which should moderate this page | def get_moderator_queryset(self):
if not settings.CMS_MODERATOR or not self.tree_id:
return PageModerator.objects.get_empty_query_set()
q = Q(page__tree_id=self.tree_id, page__level__lt=self.level, moderate_descendants=True) | \
Q(page__tree_id=self.tree_id, page__level=... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"async def fetch_moderated(self):\n\n logging.debug(\"Fetching moderated\")\n\n data = await self.client.request.get(\"/auth/user/playermoderated\")\n return [PlayerModeration.build_moderation(\n self.client, mod, self.loop) for mod in data[\"data\"]]",
"def get_required_groups(pag... | [
"0.6223007",
"0.57231057",
"0.5459483",
"0.5364359",
"0.5333543",
"0.5318118",
"0.5259848",
"0.5259629",
"0.5243814",
"0.52181244",
"0.51199985",
"0.51199985",
"0.503113",
"0.501669",
"0.5010157",
"0.5010113",
"0.4990176",
"0.4948901",
"0.49395126",
"0.49189487",
"0.49040362"... | 0.75413513 | 0 |
Returns true, if page is approved and published, or approved, but parents are missing.. | def is_approved(self):
return self.moderator_state in (Page.MODERATOR_APPROVED, Page.MODERATOR_APPROVED_WAITING_FOR_PARENTS) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def orphaned(self):\n return (self.parent is None)",
"def has_parent(self):\n return False",
"def has_parents(self):\n return len(self._parents) > 0",
"def publish(self, fields=None, exclude=None):\n # clean moderation log\n self.pagemoderatorstate_set.all().delete()\n \... | [
"0.63411736",
"0.6171674",
"0.61385125",
"0.60719556",
"0.602873",
"0.599978",
"0.5943389",
"0.59328663",
"0.5920528",
"0.58290297",
"0.58004415",
"0.5798648",
"0.57899135",
"0.57749325",
"0.57547385",
"0.5733244",
"0.5728598",
"0.5715474",
"0.57106864",
"0.5686434",
"0.56839... | 0.6747977 | 0 |
Overrides Publisher method, because there may be some descendants, which are waiting for parent to publish, so publish them if possible. | def publish(self, fields=None, exclude=None):
# clean moderation log
self.pagemoderatorstate_set.all().delete()
# can be this page published?
if self.mptt_can_publish():
self.moderator_state = Page.MODERATOR_APPROVED
else:
self.moderator_state = P... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def _notify_parent_change(self):\n pass",
"def on_parent_changed(self):\n pass",
"def _update_parent_attachments(self):\n try:\n self._parent.has_attachments = bool(len(self.__attachments))\n except AttributeError:\n pass",
"def publish(self):\n return... | [
"0.605876",
"0.5671696",
"0.56162834",
"0.5568196",
"0.55627656",
"0.55452615",
"0.55029297",
"0.54026634",
"0.54004335",
"0.54004335",
"0.537827",
"0.5354135",
"0.53013587",
"0.52420294",
"0.5166492",
"0.5158825",
"0.51457006",
"0.5101871",
"0.50980556",
"0.5087998",
"0.5087... | 0.6279266 | 0 |
Returns true if public model is published. | def is_public_published(self):
if hasattr(self, 'public_published_cache'):
# if it was cached in change list, return cached value
return self.public_published_cache
# othervise make db lookup
if self.public:
return self.public.published
#return is_publ... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def is_published(self) -> bool:\n return self.published and self.published <= timezone.now()",
"def is_published(self):\n now = timezone.now()\n return now >= self.pub_date",
"def is_public(self):\n return self.document.is_public",
"def public(self) -> bool:\n return self._... | [
"0.7853329",
"0.77930677",
"0.7677848",
"0.73914605",
"0.73765314",
"0.71067935",
"0.7081282",
"0.7081282",
"0.7081282",
"0.7081282",
"0.7045333",
"0.6970942",
"0.68620694",
"0.6652326",
"0.6652326",
"0.6616775",
"0.65929407",
"0.6519627",
"0.64643705",
"0.6459555",
"0.642842... | 0.84666336 | 0 |
Return overrwriten url, or None | def overwrite_url(self):
if self.has_url_overwrite:
return self.path
return None | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def _get_url(self, absolute):",
"def get_url(self):\r\n if self.mod.filename:\r\n return self.mod.service.get_mirror() + self.mod.filename",
"def __get_url_addr(self):\n request = urlopen(self.url)\n version = request.readline()\n request.close()\n request = urlparse.urlparse(self... | [
"0.6445694",
"0.6432429",
"0.63952386",
"0.6263736",
"0.6187996",
"0.61590326",
"0.60932136",
"0.6037233",
"0.5998153",
"0.5960509",
"0.5957526",
"0.5915956",
"0.59118295",
"0.58678854",
"0.5845085",
"0.5812721",
"0.57971686",
"0.57644355",
"0.5757884",
"0.57559407",
"0.57541... | 0.81936914 | 0 |
Get src URL for instance's icon | def get_instance_icon_src(self):
instance, plugin = self.get_plugin_instance()
if instance:
return plugin.icon_src(instance)
else:
return u'' | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def icon(self):\r\n try:\r\n return self.data['icon_url_base']+self.data['icon_url_name']\r\n except KeyError:\r\n return ''",
"def icon_url(self) -> Optional[pulumi.Input[str]]:\n return pulumi.get(self, \"icon_url\")",
"def icon(self):\n return self.__icon",
... | [
"0.7681349",
"0.7591989",
"0.7404013",
"0.73230845",
"0.7276072",
"0.7258099",
"0.7258099",
"0.72561705",
"0.72561705",
"0.72561705",
"0.72561705",
"0.72561705",
"0.72561705",
"0.72561705",
"0.72561705",
"0.72561705",
"0.72561705",
"0.72561705",
"0.72561705",
"0.72561705",
"0... | 0.85926807 | 0 |
Get alt text for instance's icon | def get_instance_icon_alt(self):
instance, plugin = self.get_plugin_instance()
if instance:
return unicode(plugin.icon_alt(instance))
else:
return u'' | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_icon_title(self): # real signature unknown; restored from __doc__\n return \"\"",
"def get_alt(self):\n p = self._get_sub_text('alt')\n if not p:\n return None\n else:\n try:\n return int(p)\n except ValueError:\n ... | [
"0.7206248",
"0.68852603",
"0.6804482",
"0.6772271",
"0.67636156",
"0.67636156",
"0.672871",
"0.67071545",
"0.67071545",
"0.67071545",
"0.66867185",
"0.6654262",
"0.6637052",
"0.6633226",
"0.6626289",
"0.6614716",
"0.6602623",
"0.6600994",
"0.6589052",
"0.6566196",
"0.6564646... | 0.8435488 | 0 |
Converts and sets binary state to local attributes | def set_decimal(self, state):
self.moderate_page = state & MASK_PAGE
self.moderate_children = state & MASK_CHILDREN
self.moderate_descendants = state & MASK_DESCENDANTS | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def toState(attrs=ALL):",
"def __setstate__(self, state):\n # compatibility with data from previous versions\n self._name = \"\"\n self._user_data = dict()\n self.__loaded_from = None\n # Restore state. This overrides the above if contained in the data.\n self.__dict__.u... | [
"0.6734996",
"0.66283816",
"0.6354064",
"0.63520515",
"0.6251809",
"0.62331605",
"0.62097543",
"0.61671144",
"0.61599064",
"0.61496055",
"0.6134978",
"0.6130802",
"0.61195123",
"0.61195123",
"0.61058176",
"0.60869485",
"0.6069266",
"0.6055331",
"0.60439646",
"0.6039078",
"0.6... | 0.0 | -1 |
Just some logical stuff if user haves moderate_descendants then moderate_children | def save(self, force_insert=False, force_update=False):
if self.moderate_descendants:
self.moderate_children = True
else:
self.moderate_children = False
super(PageModerator, self).save(force_insert, force_update) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def test_grandchildren():\n\n # note c.upto(\"status\").desired.grandchildren\n # this is the same as *c.upto(\"status\").desired in python3.5+\n res = conf.status.conditions.choose(lambda c: (c.type, c.reason, c.upto(\"status\").desired.grandchildren))\n assert \"type\" in res\n assert \"reason\" i... | [
"0.60822916",
"0.5971886",
"0.5689409",
"0.5348866",
"0.5331274",
"0.53272384",
"0.5250134",
"0.5239354",
"0.5235983",
"0.52199626",
"0.5202542",
"0.517231",
"0.517231",
"0.5168321",
"0.5156678",
"0.51472634",
"0.51328313",
"0.5096494",
"0.50384384",
"0.5033463",
"0.5027114",... | 0.6343787 | 0 |
viewfunction for home view | def home() -> 'html':
if request.method == 'POST':
# check if the http request was a post request
# the following if statements check which of the close buttons was clicked
# in order to delete the notification
if request.form.get('close-vacation'):
req_id = request.form... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def home(request):\n\treturn render(request, \"compta/home.html\")",
"def home(self, *args, **kwargs):\n pass",
"def home(request):\r\n return render(request, 'home.html')",
"def feature_view_home(request):\n return render(request, 'SNP_Feature_View/feature_view_home.html')",
"def home(request... | [
"0.7883946",
"0.7870451",
"0.7797532",
"0.7665668",
"0.7648475",
"0.76462525",
"0.7611321",
"0.7597093",
"0.7572959",
"0.7529134",
"0.7512292",
"0.7511995",
"0.750166",
"0.7486506",
"0.7486506",
"0.7486506",
"0.7486506",
"0.7486506",
"0.7486506",
"0.7486506",
"0.7486506",
"... | 0.0 | -1 |
Search for the value target in the array A using binary search. | def BinarySearch(A, target):
return _BinarySearchAux(A, target, 0, len(A) - 1) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def binary_search_whole_array(arr, target):\n return binary_search(arr, target, 0, len(arr))",
"def binary_search(alist, target):\n index = binary_search_iterative(alist, target)\n return index",
"def binary_search(array: list[int], target: int) -> int:\n left = 0\n right = len(array) - 1\n\n ... | [
"0.7775253",
"0.74781513",
"0.7369633",
"0.7230093",
"0.71581167",
"0.71295196",
"0.7120497",
"0.70985",
"0.7073721",
"0.7009145",
"0.6975184",
"0.6966726",
"0.69441426",
"0.6911794",
"0.6841253",
"0.6775388",
"0.6751996",
"0.6710357",
"0.66489124",
"0.6639372",
"0.66381973",... | 0.8287194 | 0 |
Simple instrumental variable dataset with a single IV and a single confounder. | def simple_iv_dataset(beta, num_samples,
num_treatments = 1,
treatment_is_binary=True,
outcome_is_binary=False):
W, Z, c1, c2, cz = [None]*5
num_instruments = 1
num_common_causes = 1
beta = float(beta)
# Making beta an array
if type(beta)... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def iris():\n return IrisDataset()",
"def dataset(options):\n pass",
"def iris_data():\n X, y = load_iris()['data'], load_iris()['target']\n y[y == 2.] = 0 # N.B. make binary, TODO simulate a competition dataset\n return BasicExamplesProvider(X, y)",
"def get_iiai_dataset():\n ds = AttrDic... | [
"0.5500359",
"0.53266674",
"0.5290605",
"0.5253644",
"0.5231031",
"0.5054699",
"0.49945283",
"0.49862596",
"0.4983791",
"0.49698672",
"0.493647",
"0.48998097",
"0.48933926",
"0.48924628",
"0.48863584",
"0.48535743",
"0.48104846",
"0.48009577",
"0.47921774",
"0.4790993",
"0.47... | 0.51637745 | 5 |
r"""Hyperbole function Implements $$ f(x_0, x_1) = 8 (x_0 2)^2 (x_1 2)^2 $$ | def f(x0: float, x1: float) -> float:
return 8 - (x0 - 2) ** 2 - (x1 - 2) ** 2 | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def f1(x, a, b):\n #return x**43 - b*x**42 + x**7 - x**6 * a + 84*x - 42 * b - 42 * a\n return (x**42 + 42)/(x-a) + (x**6 + 42)/(x-b)",
"def f1(x):\n return x**3 - 2*x + 2",
"def bdq1(f, x, h=1e-5):\n return (f(x)-f(x-h))/h\n raise NotImplementedError(\"Problem 2 Incomplete\")",
"def bdq2(f, x... | [
"0.7119387",
"0.6948508",
"0.6846777",
"0.67713606",
"0.67150784",
"0.6619665",
"0.65248656",
"0.65127057",
"0.65080285",
"0.646941",
"0.6453863",
"0.6434166",
"0.6391845",
"0.637635",
"0.63548464",
"0.6348041",
"0.6331476",
"0.6295169",
"0.62527907",
"0.6240218",
"0.62143505... | 0.7577568 | 0 |
r"""Computes the matrix which represents $f$ as a bit matrixvector operation E.g., $$ f(x_0, x_1) = \psi_\alpha M_{\alpha \beta} \psi_\beta \, , \qquad M_{\alpha \beta} = Q_{0\alpha}Q_{0\beta} Q_{1\alpha}Q_{1\beta} + 4Q_{0\alpha}\delta_{\alpha\beta} + 4Q_{1\alpha}\delta_{\alpha\beta} $$ where $\psi$ is a bit vector and... | def get_omega_0(n_bits: int, as_numeric: bool = False) -> Matrix:
q = qe.get_bit_map(len(DEPENDENTS), n_bits)
mat = -q.T @ q + 4 * np.diag(np.sum(q, axis=0))
return np.array(mat) if as_numeric else mat | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def f(m, x, b):\n return m*x + b",
"def matvec(self, x):\n return self * x",
"def __matmul__(self, q: np.ndarray) -> np.ndarray:\n return self.product(q)",
"def U_f(f, d):\n if d < 2:\n raise ValueError('U_f operator requires rank >= 2.')\n\n operator_shape = [2] * 2 * d\n t = ... | [
"0.5803424",
"0.5781998",
"0.5770333",
"0.5652507",
"0.5647167",
"0.5640449",
"0.561281",
"0.54662913",
"0.54496944",
"0.5445383",
"0.54440916",
"0.5424327",
"0.54239607",
"0.54151905",
"0.54047436",
"0.5398749",
"0.53917176",
"0.5387133",
"0.5385605",
"0.5366852",
"0.5337738... | 0.0 | -1 |
Computes `omega_0 p constraint2` in the bit basis with slack variables. Calls `qlp.eqn_converter.constraints_to_matrix` to compute the constrained matrix. | def get_omega(
inequalities: List[Relational], n_bits: int, p: int = 10, as_numeric: bool = False
) -> Matrix:
n_vars = len(DEPENDENTS) + len(inequalities)
q = qe.get_bit_map(n_vars=n_vars, n_bits=n_bits)
a, b = qe.constraints_to_matrix(
inequalities, dependents=DEPENDENTS, as_numeric=as_numeric... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_omega_0(n_bits: int, as_numeric: bool = False) -> Matrix:\n q = qe.get_bit_map(len(DEPENDENTS), n_bits)\n mat = -q.T @ q + 4 * np.diag(np.sum(q, axis=0))\n return np.array(mat) if as_numeric else mat",
"def constraints(self) -> Tuple[NDArray, NDArray]:\n symm = not self._asym\n k =... | [
"0.5836039",
"0.52766746",
"0.52113706",
"0.5034138",
"0.49834907",
"0.49747926",
"0.4951916",
"0.49246576",
"0.49246576",
"0.49243265",
"0.49236357",
"0.49225742",
"0.4921374",
"0.49076325",
"0.48932192",
"0.4883221",
"0.4836027",
"0.48178357",
"0.47918007",
"0.47856057",
"0... | 0.5731313 | 1 |
Calculates the area of a circle | def circle_area(circle):
return pi * circle.radius * circle.radius | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def area_of_circle(radius):\n return radius",
"def circle_area(radius):\n area = radius ** 2 * math.pi\n return area",
"def area(self):\n\t\t#print (self.radius*self.radius*math.pi)\n\t\tcircle_area = (self.radius*self.radius*math.pi)\n\t\treturn circle_area",
"def circle_area(radius):\n return m... | [
"0.8745869",
"0.85839",
"0.8566856",
"0.85599434",
"0.85569406",
"0.8524091",
"0.85074466",
"0.83901566",
"0.83901566",
"0.82570344",
"0.82275945",
"0.8139902",
"0.8088065",
"0.8049198",
"0.8049198",
"0.80170983",
"0.800644",
"0.80042857",
"0.7991567",
"0.7976803",
"0.7958631... | 0.8968238 | 0 |
Calculate volume of a cuboid. | def volume_of_a_cuboid(length, width, height):
return length * width * height | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def cube_volume(edge : number) -> number:\n volume = edge*edge*edge\n\n return volume",
"def volume (self):\n volume = self.sideLength**3\n return volume",
"def volume(self):\n _alpha = np.radians(self.alpha)\n _beta = np.radians(self.beta)\n _gamma = np.radians(self.g... | [
"0.7463701",
"0.7420508",
"0.7405192",
"0.7366741",
"0.72924733",
"0.7245695",
"0.7229531",
"0.72160167",
"0.714981",
"0.7031789",
"0.7000545",
"0.6992655",
"0.6952574",
"0.6806591",
"0.6764553",
"0.66988105",
"0.666664",
"0.6657859",
"0.6654271",
"0.66385776",
"0.66198796",
... | 0.8282409 | 0 |
Finds the number of cows and chickens by being given the amount of heads and legs on the farm. | def heads_legs(heads, legs):
for i in range(0, heads + 1):
cows = heads - i
if 4 * cows + 2 * i == legs:
chickens = i
return chickens, cows
return "No solutions." | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_number_of_cows(self):\n bulls = self.get_number_of_bulls()\n list_of_cows = set(self.puzzle) & set(self.guess)\n cows = (len(list_of_cows) - bulls)\n return cows",
"def get_number_of_cheeses(self):\n number = 0\n for i in range(len(self._stools)):\n nu... | [
"0.66352767",
"0.6518265",
"0.63447565",
"0.6115597",
"0.6059045",
"0.59676576",
"0.58928794",
"0.5813358",
"0.5791248",
"0.57536227",
"0.5720542",
"0.570668",
"0.56826264",
"0.56752414",
"0.5674353",
"0.56580544",
"0.56282103",
"0.56080395",
"0.5601535",
"0.557459",
"0.55704... | 0.68843335 | 0 |
Concatenates strings in a specific order (short + long + short). | def short_long_short(first, second):
if len(first) > len(second):
return ''.join(second + first + second)
return ''.join(first + second + first) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def concat_strings(l_strings):\n if l_strings == []:\n return \"\"\n else: \n return l_strings[0] + \" \" + concat_strings(l_strings[1:])",
"def laceStrings(s1, s2):\n # Your Code Here\n minLen = min(len(s1), len(s2))\n s3 = \"\".join(y for x in zip(s1, s2) for y in x) + s1[minLen:]... | [
"0.6632312",
"0.6397937",
"0.60567135",
"0.60250455",
"0.5989258",
"0.59715545",
"0.595117",
"0.58524996",
"0.5837099",
"0.5823456",
"0.57466316",
"0.574089",
"0.5736465",
"0.5709352",
"0.5689944",
"0.5689944",
"0.5689944",
"0.5687452",
"0.5655868",
"0.56552184",
"0.561772",
... | 0.69274545 | 0 |
Calculates needed amount of water | def litres(time):
return int(time / 2) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def water_needed(self):\n water = self.water_needed_by_trunk()\n\n water += sum(map(lambda e: e.water_needed(), self.children))\n\n return water",
"def eat(self, available_water, seconds):\n\n if available_water <= 0:\n\n return 0\n\n water_needed = 0\n\n if s... | [
"0.74489266",
"0.69223917",
"0.6898922",
"0.65085804",
"0.64406383",
"0.63230914",
"0.6304212",
"0.62404954",
"0.62377375",
"0.62160164",
"0.6172915",
"0.61499405",
"0.61430407",
"0.61286366",
"0.6057393",
"0.6056967",
"0.60557836",
"0.6054866",
"0.605421",
"0.60515213",
"0.6... | 0.0 | -1 |
calculates best starting mark | def starting_mark(height):
return round(height * LINEAR_RELATION + OFFSET, 2) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def next_mark(self):\n if self.n != 0:\n pmax = max(self.marks)\n else:\n pmax = 0\n \n return pmax + 1",
"def findMinFrom(lst, mark):\n iMin = mark\n for i in range(mark + 1, len(lst)):\n if lst[i] < lst[iMin]:\n iMin = i\n return ... | [
"0.6794963",
"0.6575641",
"0.6247827",
"0.6219214",
"0.6055779",
"0.597667",
"0.5963169",
"0.59471875",
"0.581982",
"0.58127075",
"0.57589376",
"0.5721955",
"0.57053584",
"0.5679926",
"0.55804247",
"0.5579275",
"0.5575373",
"0.55663073",
"0.5566031",
"0.5494723",
"0.54898405"... | 0.64611924 | 2 |
Calculates how many bottles of duty free whiskey you would have to buy bottle_cost, duty_free_discont and cost_of_the_holiday. | def duty_free(price: int, discount: int, holiday_cost: int) -> int:
if holiday_cost == 500:
return holiday_cost
discount /= 100
price = holiday_cost / (price * discount)
price = int(price)
return price | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def calculateCosts(self):\n self.costs = 0\n for house in self.houses:\n if not house.distance == 1000:\n self.costs += house.distance * 9\n for battery in self.batteries:\n self.costs += battery.costs\n return self.costs",
"def calculate_cost(self... | [
"0.67098325",
"0.66555476",
"0.65634406",
"0.6384225",
"0.63169754",
"0.62693393",
"0.6262279",
"0.61780584",
"0.6173227",
"0.6133311",
"0.6071943",
"0.60596",
"0.6055912",
"0.60195255",
"0.60087186",
"0.59921587",
"0.5984442",
"0.5981656",
"0.5976567",
"0.59566116",
"0.58903... | 0.6847768 | 0 |
Check your username for correctness | def validate_usr(username: str) -> bool:
if MIN_USERNAME_LENGHT <= len(username) < MAX_USERNAME_LENGHT:
return bool(re.search(ALLOWED_CHARACTERS_PATTERN, username))
return False | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def _check_username(self, username):\n if self.username_regex.search(username) is not None:\n print(\"Correct username\")\n return True\n else: \n print(\"Wrong username\")\n return False",
"def verify_username(entered_username):\n return USER_RE.match... | [
"0.85588443",
"0.83910775",
"0.8073701",
"0.80587053",
"0.8049643",
"0.8036112",
"0.79836196",
"0.79694843",
"0.7943183",
"0.79120827",
"0.7895858",
"0.7892639",
"0.786928",
"0.7862378",
"0.7854709",
"0.7793699",
"0.77915317",
"0.77914256",
"0.77722824",
"0.7762637",
"0.77368... | 0.78407246 | 15 |
Change the order of elements in list | def fix_the_meerkat(animal):
tail = animal[0]
animal[0] = animal[2]
animal[2] = tail
return animal | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def reorder_list(items, arg=''):\n\n if arg:\n\n for i in items:\n if i == arg:\n items.remove(i)\n items.insert(0, arg)\n\n return items",
"def reorder(self, flair_list: list[str]):\n self._reorder(flair_list, is_link=False)",
"def reorder(l: List[A... | [
"0.74736404",
"0.66628754",
"0.6642164",
"0.66405344",
"0.6612779",
"0.65459746",
"0.653205",
"0.6513294",
"0.6513294",
"0.64931965",
"0.63898516",
"0.6366638",
"0.6341586",
"0.6329533",
"0.6322915",
"0.6300973",
"0.6251926",
"0.6236372",
"0.6219306",
"0.6209153",
"0.6198925"... | 0.0 | -1 |
If the number has an integer square root, take this, otherwise square the number. | def square_or_square_root(numbers):
result = []
for element in numbers:
root = element ** 0.5
if root.is_integer():
result.append(int(root))
else:
result.append(int(element * element))
return result | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def square_number(number: int) -> int:\n return number * number",
"def squareroot(number):\n return math.sqrt(number)",
"def square(num):\n return num * num",
"def square(num):\n square = num ** 2\n return square",
"def sqrt(number):\n if number is None or number < 0:\n return None... | [
"0.75031054",
"0.71885216",
"0.70348656",
"0.69892645",
"0.6980272",
"0.6924001",
"0.6887427",
"0.6858872",
"0.68532336",
"0.6826913",
"0.6779441",
"0.67134345",
"0.6712574",
"0.66758066",
"0.6665416",
"0.66529655",
"0.6646135",
"0.66382545",
"0.65946454",
"0.6593646",
"0.659... | 0.59313005 | 64 |
Convert miles per imperial gallon into kilometers per liter. | def miles_per_gallon_to_kilometers_per_liter(miles_per_gallon):
converted_value = miles_per_gallon * ONE_MILE_IN_KILOMETERS / ONE_IMP_GALLON_IN_LITERS
return round(converted_value, 2) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def miles_to_kilometers(miles):\n #convert miles to km:\n return miles*1.60934",
"def miles_to_kilometers(miles: float) -> float:\n mile = float(miles)\n kilometers = float(float(mile) * 1.60934)\n return round(kilometers, 2)",
"def kilometers_to_miles(km):\n #convert km to miles:\n return... | [
"0.810501",
"0.77146244",
"0.7660003",
"0.7547199",
"0.7521227",
"0.7105088",
"0.7034444",
"0.6854184",
"0.6576829",
"0.6553181",
"0.6421252",
"0.6299841",
"0.62697154",
"0.6260179",
"0.6246678",
"0.62450707",
"0.6243071",
"0.6237388",
"0.6223361",
"0.6187523",
"0.6170195",
... | 0.81636584 | 0 |
Returns a list of numbers which are divisible by given number | def divisible_by(array, divisor):
return_list = list()
for i in array:
if i % divisor == 0:
return_list.append(i)
return return_list | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_divisores(num):\n divisores = [] #uso una lista para guardar los divisores\n for i in range(1, num):\n if num%i == 0:\n divisores.append(i)\n return divisores",
"def simple_get_divisors(num: int) -> list:\n all_divisors = []\n for possible_divisor in range(1, math.floor(n... | [
"0.7834503",
"0.76458055",
"0.76339",
"0.7617275",
"0.752643",
"0.745404",
"0.7447987",
"0.7377548",
"0.7367242",
"0.73452306",
"0.7332288",
"0.7256012",
"0.721771",
"0.7188026",
"0.7091371",
"0.7077676",
"0.70762545",
"0.70386696",
"0.698966",
"0.6971757",
"0.6922879",
"0.... | 0.7736536 | 1 |
Check if number is wilson prime. | def am_i_wilson(number):
return number in (5, 13, 563) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def is_prime(number):\n if number == 2:\n return True\n\n if number <= 1 or number % 2 == 0:\n return False\n\n # check to see if number has any odd factors\n for x in range(3, int(number ** 0.5) + 1, 2):\n if number % x == 0:\n return False\n return True",
"def isp... | [
"0.7402816",
"0.7349756",
"0.7347266",
"0.73105425",
"0.7309757",
"0.72747916",
"0.72445035",
"0.7216956",
"0.7191591",
"0.7191131",
"0.719108",
"0.7182881",
"0.7173971",
"0.71737874",
"0.7170034",
"0.7156106",
"0.7153922",
"0.7140362",
"0.71393466",
"0.7134284",
"0.7131141",... | 0.6657671 | 78 |
Round number to two decimal places. | def two_decimal_places(number):
return round(number, 2) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def two_decimal_places(n):\n return float('{:.2f}'.format(n))",
"def round2(number, ndigits=None):\n if ndigits is None:\n ndigits = 0\n\n if ndigits < 0:\n exponent = 10 ** (-ndigits)\n quotient, remainder = divmod(number, exponent)\n if remainder >= exponent // 2 and number... | [
"0.7912119",
"0.7121332",
"0.70237994",
"0.69846284",
"0.67931926",
"0.66351336",
"0.65924495",
"0.65116143",
"0.64275634",
"0.6412318",
"0.62899566",
"0.6285706",
"0.6269954",
"0.6259456",
"0.6230161",
"0.6226126",
"0.6186584",
"0.6106894",
"0.59868294",
"0.5954083",
"0.5928... | 0.8178348 | 0 |
Convert a name into initials | def abbrev_name(name):
arr = name.split()
if len(arr) == 2:
anw = arr[0][0] + "." + arr[1][0]
result = anw.upper()
else:
result = None
return result | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_initials(name, force_upper=True):\r\n if force_upper:\r\n return name[0:1].upper()\r\n return name[0:1]",
"def initials(full_name):\r\n\r\n if full_name is not None and len(full_name) > 0:\r\n return ''.join([s[0] for s in full_name.split(' ')]).upper()\r\n else:\r\n retu... | [
"0.8376018",
"0.81219697",
"0.7692363",
"0.7692363",
"0.7692363",
"0.7686876",
"0.76175344",
"0.7615349",
"0.7572603",
"0.74991775",
"0.7491891",
"0.74680877",
"0.74660325",
"0.73977965",
"0.73952067",
"0.7293612",
"0.72790784",
"0.7277742",
"0.7218639",
"0.7168545",
"0.71612... | 0.694311 | 35 |
convert a binary number into decimal | def bin_to_decimal(inp):
check_str = inp.replace('1', '')
check_str = check_str.replace('0', '')
if inp.isdigit() or check_str == '':
bin_list = list(inp)
j = len(bin_list)
dec_num = 0
for i in range(j):
dec_num += (int(bin_list[i]) * (2 ** (j - 1)))
... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def to_decimal(binary):\n if len(re.findall('[0-1]+', binary)[0] )< 9:\n return int('0b'+binary, 2)\n return -1",
"def bin2dec(x):\n return int(x, 2)",
"def DecimalToBinary(n):\n return bin(n)[2:]",
"def bin2dec(number):\n\tmysum = 0\n\tnumber = str(number)[::-1]\n\tfor i,x in enumerate(nu... | [
"0.8549305",
"0.80324656",
"0.76886725",
"0.7596421",
"0.7414899",
"0.7167138",
"0.7156202",
"0.71468645",
"0.7040041",
"0.702959",
"0.70113695",
"0.69720596",
"0.695063",
"0.6925231",
"0.69232446",
"0.6913598",
"0.6894258",
"0.6862613",
"0.6795378",
"0.67324436",
"0.66948646... | 0.7075541 | 8 |
Get name of layout | def getName(self):
return self.__name__ | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def getName(self):\n return _libsbml.Layout_getName(self)",
"def currentLayout( self ):\n return self._current_layout_name",
"def getElementName(self):\n return _libsbml.ListOfLayouts_getElementName(self)",
"def getName(self):\n return _libsbml.LayoutExtension_getName(self)",
"d... | [
"0.80484194",
"0.7654157",
"0.7408682",
"0.7279726",
"0.72148585",
"0.71642524",
"0.69108135",
"0.6701747",
"0.65263534",
"0.65142816",
"0.63942266",
"0.63833994",
"0.6355448",
"0.6243513",
"0.6238123",
"0.61900246",
"0.6125879",
"0.6020774",
"0.60066617",
"0.60066617",
"0.59... | 0.0 | -1 |
Build tiles from definition | def buildTiles(self, items, attributes):
pass | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def build_tiles(cls):\n\n LOGGER.debug(\"Building tiles\")\n\n for tile_id in tiledata.TILE_DATA:\n if not Tile.tile_factory(tile_id):\n LOGGER.error(\"Could not construct tile with ID %d\", tile_id)\n sys.exit(1)",
"def populate_tiles(self):\n\n # gr... | [
"0.68891084",
"0.64572304",
"0.6323403",
"0.6250683",
"0.6089269",
"0.6088719",
"0.5969581",
"0.5969581",
"0.59590614",
"0.5950307",
"0.5935144",
"0.59060156",
"0.5876645",
"0.5876645",
"0.58567715",
"0.5856534",
"0.5855962",
"0.58338034",
"0.5832484",
"0.582266",
"0.5780481"... | 0.6888281 | 1 |
Say hello to user. | def say_hello():
return render_template("hello.html") | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def greet_user():\n print(\"Hello\")",
"def greet_user():\r\n print(\"hello!\")",
"def greet_user():\n print(\"Hello!\")",
"def greet_user():\n print(\"Hello!\")",
"def greet_user():\n print(\"Hello!\")",
"def say_hi(self):\n print(\"Hi there, everyone!\")",
"def greet_user(us... | [
"0.86819047",
"0.8658209",
"0.8564081",
"0.8564081",
"0.8564081",
"0.8231708",
"0.82227147",
"0.81755567",
"0.8115332",
"0.80300087",
"0.80238485",
"0.8022591",
"0.79338837",
"0.7928814",
"0.7928814",
"0.7898282",
"0.78052473",
"0.78052473",
"0.7804362",
"0.77419686",
"0.7712... | 0.0 | -1 |
Greet user with compliment. | def greet_person():
player = request.args.get("person")
compliment = choice(AWESOMENESS)
return render_template("compliment.html",
person=player,
compliment=compliment) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def greet_user():\r\n print('Hi,' + FirstName + ' ' + LastName + ' thanks for joining us inside the beer app!')",
"def greet_user():\r\n print(\"hello!\")",
"def greet_user():\n print(\"Hello\")",
"def greet_user():\n print(\"Hello!\")",
"def greet_user():\n print(\"Hello!\")",
"def greet... | [
"0.7737727",
"0.7446383",
"0.7443655",
"0.7292987",
"0.7292987",
"0.7292987",
"0.72795635",
"0.72795635",
"0.7219241",
"0.7167798",
"0.71403813",
"0.70471334",
"0.70449835",
"0.7033462",
"0.6921098",
"0.6901213",
"0.68747765",
"0.685842",
"0.6848951",
"0.6835141",
"0.68243265... | 0.73524195 | 3 |
Gets input from user and directs to next page. | def show_madlib_form():
player = request.args.get("person")
answer = request.args.get("response")
if answer == "n":
return render_template("goodbye.html",
person=player)
else:
return render_template("game.html",
person=playe... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def redirect_to_next(self, request):\n\n if 'next' in request.GET:\n next_page = request.GET['next']\n return HttpResponseRedirect(next_page)\n else:\n return redirect('index')",
"def continue_to_next_page(self):\n\n while True:\n response = input(... | [
"0.6268959",
"0.62490445",
"0.61244357",
"0.60756904",
"0.6011896",
"0.59903705",
"0.5891934",
"0.5875174",
"0.585804",
"0.5818062",
"0.57474613",
"0.5687483",
"0.5643495",
"0.5588821",
"0.5571436",
"0.55707985",
"0.5542287",
"0.5538736",
"0.5537527",
"0.54941493",
"0.5471402... | 0.0 | -1 |
Process for logging all data generated during runtime. | def log_function(env, batch_size, shared_returns, log_running, log_dir):
old_size = len(shared_returns['episodic_returns'])
time.sleep(5.0)
logging.debug('Started logging process')
rets = []
# Create logs directory
if not os.path.exists(log_dir): os.makedirs(log_dir)
time_now = time.time... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def _logging(self):\n msgs = []\n # patch to log stdout spawned processes of dataloader\n logger = init_logger()\n for ds_name, ds_count in self._counts.items():\n msgs.append(f\"\\t\\t\\t* {ds_name}: {ds_count}\")\n logger.info(\"Weighted corpora loaded so far:\\n\" +... | [
"0.6757921",
"0.66993505",
"0.6548576",
"0.6424997",
"0.63836753",
"0.6319792",
"0.6280023",
"0.616865",
"0.6168313",
"0.6143672",
"0.61308694",
"0.6119171",
"0.60193807",
"0.60193807",
"0.5984264",
"0.5918175",
"0.5905446",
"0.58865213",
"0.5876823",
"0.5867697",
"0.58444226... | 0.0 | -1 |
Cheack home page h1 | def test_home_page_returns_correct_html(self):
request = HttpRequest()
response = home_page(request)
self.assertIn(
b'<h1>42 Coffee Cups Test Assignment</h1>',
response.content) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def home():\n return \"<h1>Not Much Going On Here</h1>\"",
"def homepage():\n return render_template('home/index.html', \n title=\"Bem vindo!\")",
"def homepage():\n\treturn render_template(\"home/a_homepage.html\", title=\"Welcome\")",
"def home():\n return render_templat... | [
"0.7361649",
"0.73463",
"0.72966886",
"0.7184059",
"0.7168969",
"0.7168969",
"0.7088299",
"0.7073218",
"0.6979629",
"0.6945285",
"0.6925841",
"0.6882961",
"0.68141276",
"0.6807741",
"0.67803615",
"0.675826",
"0.6745867",
"0.673467",
"0.67337036",
"0.66562915",
"0.66562915",
... | 0.0 | -1 |
ExpansionUsers that can get are correctly first name last name | def test_expansionusers_name(self):
user1 = ExpansionUsers.objects.get(username="test@test.ru")
user2 = ExpansionUsers.objects.get(username="test2@test.ru")
print user1.first_name, user1.last_name
print user2.first_name, user2.last_name | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def ldap_get_fullname(self, user):\n result = super(Auth42, self)._search_not_empty(user)\n if result is not None:\n fullname = (result.get(\"first-name\")[0], result.get(\"last-name\")[0])\n return ' '.join(str(name) for name in fullname)\n\n return None",
"def get_ful... | [
"0.67720646",
"0.6671337",
"0.6629962",
"0.64379114",
"0.64336544",
"0.64033014",
"0.6378841",
"0.6376377",
"0.6368268",
"0.6365409",
"0.6353563",
"0.6345074",
"0.63399214",
"0.63134235",
"0.63052213",
"0.6296006",
"0.6286999",
"0.6285708",
"0.6285708",
"0.6280305",
"0.626952... | 0.7815781 | 0 |
Returns a new Wall mirrored over the middle of the lanes. | def mirror(self):
newRot = [x for x in self.rot]
newRot[1] = -newRot[1]
newLRot = [x for x in self.lrot]
newLRot[1] = -newLRot[1]
newLRot[2] = -newLRot[2]
return Wall(self.beat, self.dur, -self.r, -self.l, self.d, self.u, newRot, newLRot) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def north_wall(self, x, y, z, width=10, length=10, height=10, details=None, name=\"wall\", mergeshape=None):\r\n global wallnum\r\n n = z + width / 2\r\n s = z - width / 2\r\n e = x + length / 2\r\n w = x - length / 2\r\n\r\n nwall = SolidObject(name+str(wallnum), Size(length, height, 1), Positio... | [
"0.63168657",
"0.63059783",
"0.6195468",
"0.6179768",
"0.6068646",
"0.60602653",
"0.60175794",
"0.5983031",
"0.59415644",
"0.59131116",
"0.5791608",
"0.5791608",
"0.5719669",
"0.569298",
"0.568444",
"0.566718",
"0.5666786",
"0.56274647",
"0.5609347",
"0.55890185",
"0.5540185"... | 0.7466312 | 0 |
Returns an identical Wall at the given beat. | def clone(self, beat):
return Wall(beat, self.dur, self.l, self.r, self.d, self.u, self.rot, self.lrot, self.animation) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def remove_duplicate_walls(self):\n wall_map = {}\n duplicates = []\n for cnt, thing in enumerate(self.things):\n if isinstance(thing, Wall):\n if not wall_map.has_key(thing.location):\n wall_map[thing.location] = True\n else:\n ... | [
"0.5049386",
"0.4911792",
"0.48737365",
"0.48634148",
"0.47977442",
"0.4789481",
"0.47650355",
"0.47466433",
"0.4713171",
"0.470344",
"0.46669558",
"0.46617383",
"0.4601232",
"0.45878884",
"0.45483723",
"0.45483723",
"0.4531489",
"0.45207295",
"0.45195243",
"0.45181847",
"0.4... | 0.76180756 | 0 |
Get the wall as a json object. | def json(self):
beat = self.beat + 1.4 # replace with hjd
w, h = self.getWidth(), self.getHeight()
return {
"_time": beat,
"_duration": self.dur,
#"_lineIndex": 0,
#"_type": 0,
#"_width": 0,
"_customData": {
... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_feed():\n return jsonify(dict({\n \"result\": mongo.get_hpfeed(),\n \"code\": 200\n }))",
"def walls(self):\n return self.container['walls']",
"def currentWall(request):\n if request.method == 'GET':\n current = WallConfiguration.objects.... | [
"0.61182976",
"0.6091173",
"0.60240865",
"0.60231704",
"0.58529484",
"0.58529484",
"0.5777419",
"0.57769907",
"0.5729566",
"0.5647898",
"0.56427675",
"0.5582847",
"0.54869914",
"0.54786336",
"0.54461646",
"0.5436713",
"0.5424193",
"0.54131466",
"0.540085",
"0.53960735",
"0.53... | 0.65477777 | 0 |
Sets up a filelikeobject with 6 Mbytes of data Since this is expensive to do, we share this object across test runs and just seek the file back to the start after each use. | def sample_data():
global _cached_sample_data
if _cached_sample_data is None:
data = StringIO()
chars = "".join(chr(i) for i in xrange(256))
for count in xrange(6):
cc = chr(count)
for _ in xrange(2 * 1024):
# each iteration adds 1MB
... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def __init__(self, path, max_cache=50000): # 50kb\n self.spindle = 0\n self.cache = BytesIO()\n self.max_cache = max_cache\n self.f = open(path, 'ab+')",
"def __init__(self, filename, offset):\r\n self.__input__ = open(filename, 'rb')\r\n self.__input__.seek(offset, FROM_START)... | [
"0.6616018",
"0.61529386",
"0.6102568",
"0.6055373",
"0.60258466",
"0.5977865",
"0.5960623",
"0.59479225",
"0.59345496",
"0.59118295",
"0.59086984",
"0.58870685",
"0.5877982",
"0.585848",
"0.5849558",
"0.5803683",
"0.5778263",
"0.5757148",
"0.5740492",
"0.5712975",
"0.5699629... | 0.55227613 | 48 |
Lookup municipality codes and names. By default, it looks for all municipalities. You can also use 'all' to in `name_muni` or `code_muni` to get all municipalities. Input a municipality NAME or CODE and get the names and codes of the municipality's corresponding state, meso, micro, intermediate, and immediate regions. ... | def lookup_muni(name_muni=None, code_muni=None, verbose=False):
# Get metadata with data url addresses
temp_meta = utils.select_metadata(geo="lookup_muni", year=2010)
# Read DataFrame available at provided url
lookup_table = utils.download_metadata(
temp_meta.loc[:, "download_path"].to_list()[0... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def municipality(self, municipality):\n\n self._municipality = municipality",
"def doMunicipalityExtraction(self, inputDataFile, col, row, lim):\n\n # print \"Harvesting data from input file {}...\".format(inputDataFile)\n\n # Open workbook for input data\n self.inputDataFile = inputD... | [
"0.5410167",
"0.53954566",
"0.52363294",
"0.5100454",
"0.4966442",
"0.4919593",
"0.4915527",
"0.48639882",
"0.48639882",
"0.47431022",
"0.47338513",
"0.46779698",
"0.46355852",
"0.46141896",
"0.45225304",
"0.4520622",
"0.45026007",
"0.44715694",
"0.44459715",
"0.44454393",
"0... | 0.7943366 | 0 |
Make arrays of an example input and output for one of the scalar time conversion functions for use in testing the vectorized version of that conversion function | def ex_as_arr(example,shape):
if shape is None:
return example
elif isinstance(shape,int):
return [example for i in range(shape)]
elif isinstance(shape,tuple):
array_type = 'object' if isinstance(example,datetime.datetime) else float
example_arr = np.full(shape,example,dtype=... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def test_TimeArray_convert_unit():",
"def test_transform(self):\n t = Quantize()\n assert t.transform(8.6) == 9\n assert t.transform(8.4) == 8\n assert t.transform(5.3) == 5\n assert numpy.all(t.transform([8.6, 5.3]) == numpy.array([9, 5], dtype=int))",
"def test_conversion(b... | [
"0.65150887",
"0.5882392",
"0.56571674",
"0.56103927",
"0.5598821",
"0.55335885",
"0.55065167",
"0.5501019",
"0.5478285",
"0.54716665",
"0.5360789",
"0.5360402",
"0.5357283",
"0.53515863",
"0.5348826",
"0.5336848",
"0.53088987",
"0.5307329",
"0.5292107",
"0.5280492",
"0.52596... | 0.0 | -1 |
Test that the julian date function matches | def test_julian_date_matches_vallado():
dt = vallado_3_4_dt
jd_ut = special_datetime.datetime2jd(dt)
expected_jd = vallado_3_4_jd
assert abs(jd_ut-expected_jd) < .000001 | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def test_julian_dates_10_1000_1582_2000():\n\tyears = [10,1000,1582,1582,2000]\n\tmonths = [5,12,10,10,1]\n\tdays = [30,20,4,5,1]\n\tjulians = date_functions.is_julian( years, months, days )\n\tassert julians[0] # 10-05-30 was a Julian date\n\tassert julians[1] # 1000-12-20 was a Julian date\n\tassert julians[2] #... | [
"0.83279824",
"0.73964554",
"0.7202944",
"0.7032448",
"0.6926785",
"0.67389816",
"0.6726091",
"0.67065644",
"0.6703583",
"0.6670712",
"0.66419154",
"0.65830725",
"0.6574549",
"0.65594155",
"0.6481684",
"0.64698035",
"0.64698035",
"0.6467114",
"0.6465527",
"0.63816047",
"0.634... | 0.81889576 | 1 |
Test that the gregorianjulian date function in astrodyanmics matches | def test_gregorian_date_matches_vallado():
#Test using example in vallado pp. 209
given_jd = vallado_3_13_jd
dt = special_datetime.jd2datetime(given_jd)
expected_dt = vallado_3_13_dt
delta_t = (dt-expected_dt).total_seconds()
#Better than millisecond accuracy, at least for this date!
assert ... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def test_gregorian_dates_10_1000_1582_2000():\n\tyears = [10,1000,1582,1582,2000]\n\tmonths = [5,12,10,10,1]\n\tdays = [30,20,4,5,1]\n\tgregorians = date_functions.is_gregorian( years, months, days )\n\tassert not gregorians[0] # 10-05-30 was not a Gegorian date\n\tassert not gregorians[1] # 1000-12-20 was not a G... | [
"0.8227319",
"0.75000685",
"0.7434814",
"0.7066292",
"0.70325553",
"0.6335981",
"0.6271381",
"0.62363726",
"0.6232766",
"0.6228892",
"0.6224275",
"0.6214344",
"0.61677647",
"0.61564004",
"0.61313844",
"0.6129193",
"0.6077165",
"0.6062438",
"0.6061544",
"0.60608673",
"0.604004... | 0.76632327 | 1 |
Test the vectorization function factory works to create datetimearr2jd, and that this function works with scalars, 1D lists and 1D numpy arrays | def test_vectorized_datetime_to_julian_date(example_dt,example_jd,shape):
dts = ex_as_arr(example_dt,shape)
expected_jds = ex_as_arr(example_jd,shape)
jds = special_datetime.datetimearr2jd(dts)
#Comparison is in units of days (use tolerance of a milisecond)
atol = .001/86400.
nptest.assert_allcl... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def test_vectorized_julian_date_to_datetime(example_jd,example_dt,shape):\n jds = ex_as_arr(example_jd,shape)\n expected_dts = ex_as_arr(example_dt,shape)\n dts = special_datetime.jdarr2datetime(jds)\n timedeltas = (expected_dts-dts).flatten()\n delta_ts = np.array([abs(tdelta.total_seconds()) for t... | [
"0.70639384",
"0.64770925",
"0.64389896",
"0.6249208",
"0.60850185",
"0.60801625",
"0.6063983",
"0.5967729",
"0.59255487",
"0.59204966",
"0.58881587",
"0.58787084",
"0.58785045",
"0.58393157",
"0.58264935",
"0.582606",
"0.58191967",
"0.5795057",
"0.5772121",
"0.57522243",
"0.... | 0.7364402 | 0 |
Test the vectorization function factory works to create datetimearr2jd, and that this function works with scalars, 1D lists and 1D numpy arrays | def test_vectorized_julian_date_to_datetime(example_jd,example_dt,shape):
jds = ex_as_arr(example_jd,shape)
expected_dts = ex_as_arr(example_dt,shape)
dts = special_datetime.jdarr2datetime(jds)
timedeltas = (expected_dts-dts).flatten()
delta_ts = np.array([abs(tdelta.total_seconds()) for tdelta in t... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def test_vectorized_datetime_to_julian_date(example_dt,example_jd,shape):\n dts = ex_as_arr(example_dt,shape)\n expected_jds = ex_as_arr(example_jd,shape)\n jds = special_datetime.datetimearr2jd(dts)\n #Comparison is in units of days (use tolerance of a milisecond)\n atol = .001/86400.\n nptest.a... | [
"0.7364292",
"0.6476464",
"0.64374894",
"0.62481827",
"0.6085785",
"0.6078412",
"0.60643107",
"0.59681135",
"0.5924805",
"0.59210545",
"0.5886178",
"0.58777344",
"0.58772993",
"0.5839404",
"0.5826778",
"0.5825607",
"0.5819688",
"0.57958835",
"0.5772121",
"0.57524043",
"0.5752... | 0.70635253 | 1 |
Test that vectorization works correctly in the presence of additional input arguments (the year, for the day of year to datetime conversion) | def test_vectorized_day_of_year_to_datetime(example_doy,example_dt,example_year,
shape):
doy = ex_as_arr(example_doy,shape)
year = ex_as_arr(example_year,shape)
expected_dts = ex_as_arr(example_dt,shape)
dts = special_datetime.doyarr2datetime(doy,year)
tim... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def test_convert_date_to_year(self):\n # TODO there might be a more robust way to write this with try except statements.",
"def test_evaluate_year_expression(self):\n for f, r in (\n (\"year\", 2013),\n (\"month\", 9),\n (\"day\", 1),\n (\... | [
"0.6325704",
"0.63071436",
"0.6047931",
"0.60215926",
"0.5969062",
"0.5864323",
"0.5816081",
"0.580706",
"0.57386917",
"0.5731787",
"0.5725655",
"0.5712398",
"0.57113844",
"0.5696993",
"0.5690391",
"0.5672519",
"0.5661212",
"0.5645891",
"0.5628325",
"0.56209546",
"0.5569543",... | 0.73709923 | 0 |
This is a custom template filter that i make that cuts out all values of "arg" from the string! | def cut(value,arg):
return value.replace(arg,'') | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def cut(value, arg):\n return value.replace(arg, '') # we can replace arg with ''. We also need to register it",
"def cut(value,arg):\n return value.replace(arg, '')",
"def cut_string(value, arg):\n\n return value.replace(arg, '')",
"def cut(value, arg):\n return value.replace(arg, '')",
"def c... | [
"0.6889592",
"0.6881727",
"0.6794615",
"0.6757703",
"0.6757703",
"0.66908175",
"0.66211545",
"0.649539",
"0.64127547",
"0.62883765",
"0.6286698",
"0.6284885",
"0.6210656",
"0.61250037",
"0.5852556",
"0.5744999",
"0.568353",
"0.55430156",
"0.55354595",
"0.55302554",
"0.5499544... | 0.64626956 | 11 |
Recursive utility function to get a (possibly nested) attribute of a gym Space | def get_space_attr(space, attr='shape'):
assert isinstance(space, gym.Space)
if hasattr(space, 'spaces'):
return tuple(get_space_attr(s, attr=attr) for s in space.spaces)
else:
value = getattr(space, attr)
# If this value is seen as nested (i.e. a tuple with shape), make it
# an array so that it i... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_attribute(root, attribute):\n command_tree = [root]\n while command_tree:\n current_object = command_tree.pop()\n if hasattr(current_object, attribute):\n return getattr(current_object, attribute)\n\n parent = getattr(current_object, \"parent\", None)\n if paren... | [
"0.5793785",
"0.5663005",
"0.55385864",
"0.551476",
"0.5488922",
"0.5479301",
"0.54579216",
"0.5456438",
"0.54298663",
"0.5381794",
"0.5380499",
"0.53704673",
"0.53517205",
"0.5322042",
"0.5284191",
"0.520735",
"0.5195089",
"0.5138233",
"0.5129488",
"0.5119389",
"0.5104115",
... | 0.66327345 | 0 |
Returns a (possibly nested) TensorSpec with space's shape and dtype. | def get_space_spec(space, remove_first_dim=None):
remove_first_dim = -3 if remove_first_dim is None else int(remove_first_dim)
return tf.nest.map_structure(
lambda s,d: tf.TensorSpec(shape=s[remove_first_dim:], dtype=d),
get_space_attr(space, 'shape'),
get_space_attr(space, 'dtype')
) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def input_spec_to_jax_shape_dtype_struct(\n spec: Union[Tuple[Tuple[int, ...], jnp.dtype], Tuple[int, ...]],\n batch_size: Optional[int] = None) -> jax.ShapeDtypeStruct:\n spec = tuple(spec)\n if len(spec) == 2 and isinstance(spec[0], collections.abc.Iterable):\n shape = (batch_size,) + tuple(spec[0][1:... | [
"0.5697807",
"0.5612899",
"0.53450495",
"0.5181592",
"0.5137726",
"0.51283",
"0.4993917",
"0.4989812",
"0.49839875",
"0.4942706",
"0.48814404",
"0.48760477",
"0.4757064",
"0.47533423",
"0.47456124",
"0.47387892",
"0.47022027",
"0.4699525",
"0.46986052",
"0.46869597",
"0.46786... | 0.76544815 | 0 |
Instantiate an environment wrapped to be compatible with stackrl.Training. | def make(
env='Stack-v0',
n_parallel=None,
block=None,
curriculum=None,
unwrapped=False,
as_path=False,
**kwargs,
):
if curriculum:
return make_curriculum(
env,
n_parallel=n_parallel,
block=block,
curriculum=curriculum,
unwrapped=unwrapped,
as_path=as_path,
... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def make_environment(\n evaluation: bool = False,\n task: str = 'MountainCarContinuous-v0') -> dm_env.Environment:\n del evaluation\n\n # Load the gym environment.\n environment = gym.make(task)\n\n # Make sure the environment obeys the dm_env.Environment interface.\n environment = wrappers.GymWrapper(e... | [
"0.69595337",
"0.6858885",
"0.6837624",
"0.67771894",
"0.6776568",
"0.66850716",
"0.6674813",
"0.6640321",
"0.6640321",
"0.65623885",
"0.6454325",
"0.6391635",
"0.63682014",
"0.6335106",
"0.6326718",
"0.6305858",
"0.63046753",
"0.62897015",
"0.62835145",
"0.6258138",
"0.62372... | 0.56070113 | 91 |
Generator function that yields tuples with environment instances and goal returns. | def make_curriculum(
env='Stack-v0',
n_parallel=None,
block=None,
curriculum={},
unwrapped=False,
as_path=False,
**kwargs,
):
if 'goals' in curriculum:
goals = curriculum.pop('goals')
else:
goals = None
# raise ValueError("Missing key 'goals' in curriculum.")
# Turn dict of lists to ... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def __iter__( self ):\n assert isinstance( self._env, Env )\n assert isinstance( self._steps, list )\n\n return iter( self._steps )",
"def multi_goal_given(self):\n goals = set(self.goals)\n for start in self.starts:\n yield Grid2DProblem(self.space, set([st... | [
"0.62241805",
"0.60232127",
"0.5850565",
"0.58474064",
"0.5782678",
"0.5752052",
"0.571804",
"0.57132906",
"0.56936187",
"0.56792194",
"0.5625535",
"0.56054693",
"0.5573388",
"0.55457854",
"0.55298275",
"0.5492635",
"0.5492635",
"0.5489841",
"0.5483807",
"0.5473392",
"0.54229... | 0.0 | -1 |
Sample an action from the environment's action space | def sample(self):
return self._action_out(self._env.action_space.sample()) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def choose_random_action(env):\n return env.action_space.sample()",
"def act(self, env: FakeEnv, s: ActorStrategy):\n action = env.action_space.sample()\n print(f\"Sampled action shape : {action.shape}\")\n env.step(action)",
"def get_action(self, state):\n return self.env.action... | [
"0.80715424",
"0.7760127",
"0.7720179",
"0.76235783",
"0.7516814",
"0.7289412",
"0.7254607",
"0.7201601",
"0.7039239",
"0.7027224",
"0.7021836",
"0.6994475",
"0.6859091",
"0.6837737",
"0.68123066",
"0.6800573",
"0.6772669",
"0.6708706",
"0.67032886",
"0.6620695",
"0.65986115"... | 0.7905459 | 1 |
Set and start the processes. (Can be used to restart after a call of terminate) | def start(self):
assert not self._running
for i in range(self._n_parallel):
# Set the unique seed.
self._kwargs['seed'] = (self._seed + i)%2**32 if self._seed is not None else None
# Create the pipe to comunicate with this process.
conn1, conn2 = mp.Pipe()
# Create and start the pr... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def initialize_and_join_processes(procs):\n for proc in procs:\n proc.start()\n for proc in procs:\n proc.join()",
"def start(self, *args):\n if args[0] == 'all':\n params = args[1:]\n for x in self.processers.keys():\n cmd = ['python', 'processmgr.... | [
"0.70479506",
"0.68946695",
"0.6850072",
"0.66866785",
"0.66238666",
"0.64633894",
"0.64075637",
"0.63830376",
"0.63579905",
"0.63219225",
"0.63145196",
"0.6306938",
"0.6302962",
"0.62488997",
"0.62427175",
"0.623752",
"0.6236638",
"0.6232648",
"0.62301123",
"0.6180198",
"0.6... | 0.66408813 | 4 |
Sends the exit command and joins each process. | def terminate(self):
while self._conns:
conn = self._conns.pop()
try:
conn.send((self.EXIT, ()))
except BrokenPipeError:
pass
conn.close()
while self._processes:
p = self._processes.pop()
p.join(1)
if p.exitcode is None:
# Force termination if ne... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def exit(self):\n self.tcp_server_exit_event.set()\n for _, process in self.name_to_process.items():\n process.terminate()",
"def exit(self):\n if self._isSubProcessRunning() and self._exitCommand is not None:\n self.__process.stdin.write(self._exitCommand)\n ... | [
"0.7215597",
"0.7111311",
"0.6823135",
"0.67789716",
"0.66514933",
"0.6586141",
"0.6395664",
"0.6376092",
"0.63705796",
"0.6341093",
"0.63190144",
"0.6283062",
"0.62591743",
"0.6225285",
"0.62007153",
"0.61884004",
"0.61577284",
"0.61331403",
"0.6066164",
"0.6064636",
"0.6053... | 0.7258543 | 0 |
Unstacks batched action and sends the step command to each environment's process. | def step(self, action, block=None):
for conn, a in zip(self._conns, self._action_in(action)):
conn.send((self.STEP,(a,)))
block = self._block if block is None else block
if block:
return self._recv_step()
else:
return self._recv_step | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def step_env(self, action):\n return self.env.step(action)",
"def step_up(self, action, sensors):\n self.num_actions = action.size\n cable_activities = np.vstack((action, sensors))\n for gearbox in self.gearboxes:\n cable_activities = gearbox.step_up(cable_activities) \n ... | [
"0.56708163",
"0.5556689",
"0.5490474",
"0.53995717",
"0.53879476",
"0.53879476",
"0.53378284",
"0.5310669",
"0.53073055",
"0.5278401",
"0.5182098",
"0.5131085",
"0.51222175",
"0.51199466",
"0.5116015",
"0.5087378",
"0.5082724",
"0.50722253",
"0.504782",
"0.50469667",
"0.5036... | 0.45898688 | 68 |
Sends the reset command to each environment's proccess. | def reset(self, block=None):
for conn in self._conns:
conn.send((self.RESET,()))
block = self._block if block is None else block
if block:
return self._recv_reset()
else:
return self._recv_reset | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def _soft_reset(self):\n self._reset_specific_envs(self.episodes_done)\n self._update_other_info()",
"def _hard_reset(self):\n self._reset_specific_envs(np.ones_like(self.episodes_done))\n self._update_other_info()",
"async def send_reset(self):\n try:\n await self... | [
"0.7194827",
"0.7141568",
"0.70543116",
"0.70412654",
"0.7040971",
"0.7008781",
"0.6990032",
"0.68869406",
"0.68717074",
"0.68043953",
"0.67088145",
"0.6705303",
"0.6676505",
"0.6610808",
"0.6558193",
"0.6485594",
"0.64435375",
"0.643971",
"0.6434078",
"0.64317757",
"0.640082... | 0.0 | -1 |
Sends the render command to each environment's proccess. | def render(self, mode=None):
arg = (mode,) if mode is not None else ()
for conn in self._conns:
conn.send((self.RENDER,arg))
return [conn.recv() for conn in self._conns] | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def render(self):\n self.rendering = True\n self.env.render()",
"def render(self):\n self.env.render()",
"def batchRender(*args, filename: AnyStr=\"\", melCommand: AnyStr=\"\", numProcs: int=0,\n preRenderCommand: AnyStr=\"\", remoteRenderMachine: AnyStr=\"\",\n ... | [
"0.7452957",
"0.71947724",
"0.65434456",
"0.6536819",
"0.632437",
"0.61503196",
"0.600774",
"0.59992033",
"0.58201873",
"0.58201873",
"0.5751689",
"0.5751316",
"0.56780666",
"0.56636953",
"0.56163096",
"0.56149817",
"0.560509",
"0.55915284",
"0.555739",
"0.55463415",
"0.55454... | 0.62304676 | 5 |
Sends the close command to each environment's proccess. | def close(self):
for conn in self._conns:
conn.send((self.CLOSE,())) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def close(self): \n\t\tself.env.close()",
"def terminate(self):\n super(ReacherEnv, self).close()",
"def close_env(self):\n self.env.close()",
"def close(self):\n logging.info(\"closing SmartBotEnv\")\n super(gym.Env, self).close()",
"def close(self):\n rospy.logdebug(\"C... | [
"0.76091236",
"0.7331379",
"0.7144671",
"0.7112953",
"0.695987",
"0.67845637",
"0.6770932",
"0.674975",
"0.6731603",
"0.67058825",
"0.66903657",
"0.6676927",
"0.6655957",
"0.66238225",
"0.66060716",
"0.6595494",
"0.65878826",
"0.6552395",
"0.65008247",
"0.6483434",
"0.6479267... | 0.66119534 | 14 |
Sends the new seed to each environment's proccess. | def seed(self, seed):
for i, conn in enumerate(self._conns):
conn.send((self.SEED, ((seed + i) % 2**32,)))
return [conn.recv() for conn in self._conns] | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def seed():",
"def seed(self, seed=None):\n raise self.gym.seed(seed)",
"def seed():\n pass",
"def seed():\n pass",
"def _seed(self, seed):\n self.world.seed(seed)",
"def simulate(self, environment, seed=0):\n # set the seeds\n np.random.seed(seed)\n environment.s... | [
"0.72692704",
"0.6965361",
"0.69415504",
"0.69415504",
"0.6766503",
"0.665036",
"0.6588007",
"0.6584953",
"0.654418",
"0.6528836",
"0.64877456",
"0.64264005",
"0.64192843",
"0.6394537",
"0.6383773",
"0.63793826",
"0.63793826",
"0.6342112",
"0.63297546",
"0.6301109",
"0.626355... | 0.65356755 | 9 |
Sample a batch of actions from the environment's action space | def sample(self):
return self._action_out(
[self.action_space.sample() for _ in range(self.batch_size)]
) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def sample(self):\n return self._action_out(self._env.action_space.sample())",
"def choose_random_action(env):\n return env.action_space.sample()",
"def act(self, env: FakeEnv, s: ActorStrategy):\n action = env.action_space.sample()\n print(f\"Sampled action shape : {action.shape}\")\n ... | [
"0.7261363",
"0.70785296",
"0.70598066",
"0.70200413",
"0.6730061",
"0.66145",
"0.6612352",
"0.65283436",
"0.65097225",
"0.64853877",
"0.64653045",
"0.6393944",
"0.63342696",
"0.62621653",
"0.6246169",
"0.6203756",
"0.61971754",
"0.61967456",
"0.6166335",
"0.6162748",
"0.6137... | 0.6985456 | 4 |
Receives the observations, rewards and terminal states from steping the environments and stacks them on the batch dimension. | def _recv_step(self):
return self._step_out([conn.recv() for conn in self._conns]) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def step(self, observation, last_state):\n # We are omitting the details of network inference here.\n # ...\n feature_screen = observation[3]['feature_screen']\n feature_minimap = observation[3]['feature_minimap']\n feature_units = observation[3]['feature_units']\n feature_player = observation[3]... | [
"0.5954786",
"0.5885272",
"0.577291",
"0.5772666",
"0.5756016",
"0.5727625",
"0.57105917",
"0.56907904",
"0.5686082",
"0.56372905",
"0.5592407",
"0.5558757",
"0.55341005",
"0.5483003",
"0.54775935",
"0.54675126",
"0.5457856",
"0.5455138",
"0.545193",
"0.5448966",
"0.5420197",... | 0.0 | -1 |
Receives the observations from reseting the environments and stacks them on the batch dimension. | def _recv_reset(self):
return (
self._observation_out([conn.recv() for conn in self._conns]),
tf.zeros((self.batch_size,), dtype=tf.float32),
tf.zeros((self.batch_size,), dtype=tf.bool)
) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def reset(self, observation: TObs) -> TObs:\n if isinstance(observation, dict):\n return {\n key: self.sub_stacked_observations[key].reset(obs) for key, obs in observation.items()\n } # pytype: disable=bad-return-type\n\n self.stacked_obs[...] = 0\n if sel... | [
"0.6108992",
"0.58209074",
"0.58075863",
"0.5792126",
"0.57656705",
"0.5725079",
"0.5687533",
"0.5634614",
"0.56013334",
"0.55658793",
"0.5546136",
"0.5546098",
"0.55387",
"0.5533666",
"0.5472139",
"0.5457267",
"0.5432866",
"0.5430189",
"0.53981423",
"0.53960735",
"0.5367245"... | 0.0 | -1 |
Create a new directory for the model. | def make_model_dir(model_dir: str, overwrite: bool = False) -> str:
if os.path.isdir(model_dir):
if not overwrite:
raise FileExistsError("Model directory exists and overwriting is disabled.")
# delete previous directory to start with empty dir again
shutil.rmtree(model_dir)
o... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def make_new_dir(self):\n try:\n shutil.rmtree(self.model_path)\n except:\n pass\n os.mkdir(self.model_path)",
"def make_directory(self):\n if not os.path.isdir(self.directory):\n os.mkdir(self.directory)",
"def createDir(self, dir_name):\n os... | [
"0.85916835",
"0.77791375",
"0.7669803",
"0.76294756",
"0.75628453",
"0.74993503",
"0.747899",
"0.7418361",
"0.739917",
"0.73178834",
"0.72848946",
"0.7258146",
"0.7240003",
"0.7225286",
"0.7200297",
"0.7192122",
"0.7190312",
"0.7185826",
"0.7167809",
"0.71039575",
"0.7103957... | 0.762489 | 4 |
Create a logger for logging the training process. | def make_logger(model_dir: str, log_file: str = "train.log") -> Logger:
logger = logging.getLogger(__name__)
if not logger.handlers:
logger.setLevel(level=logging.DEBUG)
fh = logging.FileHandler("{}/{}".format(model_dir, log_file))
fh.setLevel(level=logging.DEBUG)
logger.addHandl... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def setup_logging(config: Any) -> Logger:\n green = \"\\033[32m\"\n reset = \"\\033[0m\"\n logger = setup_logger(\n name=f\"{green}[ignite]{reset}\",\n level=logging.DEBUG if config.debug else logging.INFO,\n format=\"%(name)s: %(message)s\",\n filepath=config.output_dir / \"tr... | [
"0.73104",
"0.7274566",
"0.72351295",
"0.7038086",
"0.6970917",
"0.694863",
"0.69329464",
"0.6877087",
"0.67576975",
"0.6727164",
"0.6625625",
"0.6584788",
"0.65420365",
"0.6532559",
"0.6518412",
"0.6513807",
"0.64985186",
"0.64930636",
"0.64551353",
"0.6439497",
"0.6430948",... | 0.7477239 | 0 |
Write configuration to log. | def log_cfg(cfg: dict, logger: Logger, prefix: str = "cfg"):
for k, v in cfg.items():
if isinstance(v, dict):
p = ".".join([prefix, k])
log_cfg(v, logger, prefix=p)
else:
p = ".".join([prefix, k])
logger.info("{:34s} : {}".format(p, v)) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def configLogging():\n # define a basic logger to write to file\n logging.basicConfig(level=logging.DEBUG,\n format='%(asctime)s %(levelname)-8s %(message)s',\n datefmt='%a, %d %b %Y %H:%M:%S',\n filename='/tmp/execute_pomset.log',\n ... | [
"0.7370298",
"0.72371703",
"0.69266737",
"0.6907391",
"0.68533045",
"0.6734786",
"0.672302",
"0.66427577",
"0.66206384",
"0.6593361",
"0.6543791",
"0.65168977",
"0.650658",
"0.64685774",
"0.6446984",
"0.64342976",
"0.64136505",
"0.64079636",
"0.63922846",
"0.63905615",
"0.638... | 0.58359724 | 90 |
Produce N identical layers. Transformer helper function. | def clones(module: nn.Module, n: int) -> nn.ModuleList:
return nn.ModuleList([copy.deepcopy(module) for _ in range(n)]) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def make_layers(self, n_repetitions: int = 1) -> List[List[tuple]]:\n if n_repetitions <= 0:\n raise ValueError(\"The number of repetitions must be positve\")\n\n root = [self.items]\n graph_layers = [root] + [[]] * (self.depth * 2)\n\n for _ in range(n_repetitions):\n ... | [
"0.67104334",
"0.6260822",
"0.62257266",
"0.6123026",
"0.6122135",
"0.60268253",
"0.59398365",
"0.59085363",
"0.57816464",
"0.57496655",
"0.5699841",
"0.5687807",
"0.56847733",
"0.5683838",
"0.5676078",
"0.56483936",
"0.5609706",
"0.5597455",
"0.55660874",
"0.5565739",
"0.556... | 0.0 | -1 |
Mask out subsequent positions (to prevent attending to future positions) Transformer helper function. | def subsequent_mask(size: int) -> Tensor:
mask = np.triu(np.ones((1, size, size)), k=1).astype("uint8")
return torch.from_numpy(mask) == 0 | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def mask(self):",
"def shift_mask(self, x, mask):\n for i in np.where(mask)[0]:\n try:\n if mask[i] == mask[i + 1]:\n x[i] = x[i - 1]\n else:\n x[i] = x[i + 1]\n except IndexError:\n pass\n\n re... | [
"0.6420095",
"0.61061084",
"0.58194923",
"0.5764358",
"0.5708898",
"0.56982183",
"0.5676855",
"0.5669923",
"0.5589697",
"0.5586654",
"0.5434076",
"0.54117256",
"0.5407499",
"0.53901273",
"0.5340406",
"0.5312617",
"0.529994",
"0.52929336",
"0.52752227",
"0.5271067",
"0.5264898... | 0.0 | -1 |
Set the random seed for modules torch, numpy and random. | def set_seed(seed: int):
torch.manual_seed(seed)
np.random.seed(seed)
random.seed(seed) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def set_seed(seed):\n torch.manual_seed(seed)\n random.seed(seed)\n np.random.seed(seed)",
"def set_seed(seed: int):\n random.seed(seed)\n np.random.seed(seed)\n torch.manual_seed(seed)",
"def set_global_seeds(seed):\n \n torch.manual_seed(seed)\n np.random.seed(seed)\n random.see... | [
"0.83239275",
"0.8218641",
"0.82023215",
"0.81600124",
"0.8130066",
"0.8105975",
"0.8091466",
"0.8070724",
"0.8070274",
"0.8041538",
"0.8000993",
"0.7976506",
"0.7959923",
"0.7942736",
"0.7942736",
"0.7922287",
"0.79220265",
"0.79220265",
"0.78897405",
"0.78857374",
"0.786589... | 0.82849205 | 1 |
Log statistics of data and vocabulary. | def log_data_info(
train_data: Dataset,
valid_data: Dataset,
test_data: Dataset,
gls_vocab: GlossVocabulary,
txt_vocab: TextVocabulary,
logging_function: Callable[[str], None],
):
logging_function(
"Data set sizes: \n\ttrain {:d},\n\tvalid {:d},\n\ttest {:d}".format(
len(... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def _logging(self):\n msgs = []\n # patch to log stdout spawned processes of dataloader\n logger = init_logger()\n for ds_name, ds_count in self._counts.items():\n msgs.append(f\"\\t\\t\\t* {ds_name}: {ds_count}\")\n logger.info(\"Weighted corpora loaded so far:\\n\" +... | [
"0.66488",
"0.6610018",
"0.6240891",
"0.61634624",
"0.6061095",
"0.6054172",
"0.60420674",
"0.598377",
"0.59695536",
"0.5959021",
"0.58413374",
"0.58403563",
"0.5838658",
"0.5812123",
"0.5798962",
"0.57827675",
"0.5781888",
"0.5759608",
"0.5751315",
"0.5745328",
"0.57450753",... | 0.69618124 | 0 |
Loads and parses a YAML configuration file. | def load_config(path="configs/default.yaml") -> dict:
with open(path, "r", encoding="utf-8") as ymlfile:
cfg = yaml.safe_load(ymlfile)
return cfg | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def _parse_from_yaml(self) -> Dict:\n config_path = path.join(path.dirname(path.abspath(__file__)), self.config_file)\n try:\n with open(config_path, \"r\") as f:\n config_dict = yaml.load(f, Loader=yaml.FullLoader)\n return config_dict\n except FileNotFoundError as fnfe:\n raise F... | [
"0.7902378",
"0.7885701",
"0.78658706",
"0.78286827",
"0.77730346",
"0.7747524",
"0.77428514",
"0.77232844",
"0.7719344",
"0.77055913",
"0.7682004",
"0.7681451",
"0.7674585",
"0.7672605",
"0.7634164",
"0.7608393",
"0.7578547",
"0.75417423",
"0.75334585",
"0.74926627",
"0.7486... | 0.73542976 | 26 |
Postprocessor for BPE output. Recombines BPEsplit tokens. | def bpe_postprocess(string) -> str:
return string.replace("@@ ", "") | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def _postprocess(self, output: Dict[str, np.ndarray]):\n # Slice to remove padding, omitting initial [CLS] and final [SEP]\n slicer = slice(1, output.pop(\"ntok\") - 1)\n output[\"tokens\"] = self.tokenizer.convert_ids_to_tokens(\n output.pop(\"input_ids\")[slicer])\n probas = output.pop(\"proba... | [
"0.61384356",
"0.5990779",
"0.5882785",
"0.5602581",
"0.5460554",
"0.53708434",
"0.5317069",
"0.5169969",
"0.5117042",
"0.51150984",
"0.5112273",
"0.5090558",
"0.5088386",
"0.50634426",
"0.50634426",
"0.5028415",
"0.50253236",
"0.50170124",
"0.50156873",
"0.5004158",
"0.49823... | 0.48066896 | 34 |
Returns the latest checkpoint (by time) from the given directory. If there is no checkpoint in this directory, returns None | def get_latest_checkpoint(ckpt_dir: str) -> Optional[str]:
list_of_files = glob.glob("{}/*.ckpt".format(ckpt_dir))
latest_checkpoint = None
if list_of_files:
latest_checkpoint = max(list_of_files, key=os.path.getctime)
return latest_checkpoint | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_latest_checkpoint(cls, experiment_path):\n checkpoints_path = os.path.join(experiment_path, cls.CHECKPOINT_DIR_NAME)\n all_times = sorted(os.listdir(checkpoints_path), reverse=True)\n return os.path.join(checkpoints_path, all_times[0])",
"def get_latest_checkpoint_path(dirpath: str) ... | [
"0.7700107",
"0.74362636",
"0.7350826",
"0.70492095",
"0.70353407",
"0.686673",
"0.6788162",
"0.6776815",
"0.6733546",
"0.67268467",
"0.66239303",
"0.64845854",
"0.64429843",
"0.640534",
"0.62015307",
"0.6133778",
"0.6057183",
"0.6019879",
"0.59937334",
"0.5984722",
"0.595231... | 0.8131056 | 0 |
Load model from saved checkpoint. | def load_checkpoint(path: str, use_cuda: bool = True) -> dict:
assert os.path.isfile(path), "Checkpoint %s not found" % path
checkpoint = torch.load(path, map_location="cuda" if use_cuda else "cpu")
return checkpoint | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def load_checkpoint(self, model):\n print(f\"load model {self.save_model_path}\")\n model.load_state_dict(torch.load(self.save_model_path))",
"def load(self):\n if self.model is None:\n raise Exception(\"Build the model first.\")\n\n print(\"Loading model checkpoint {} ...\... | [
"0.8587296",
"0.8373741",
"0.8373741",
"0.8330554",
"0.8327572",
"0.8280634",
"0.80553234",
"0.80274415",
"0.7999282",
"0.79711145",
"0.7931497",
"0.7921606",
"0.7906906",
"0.78961265",
"0.7877432",
"0.782573",
"0.7806855",
"0.78011715",
"0.7697628",
"0.7690242",
"0.76757795"... | 0.0 | -1 |
Tiles x on dimension dim count times. From OpenNMT. Used for beam search. | def tile(x: Tensor, count: int, dim=0) -> Tensor:
if isinstance(x, tuple):
h, c = x
return tile(h, count, dim=dim), tile(c, count, dim=dim)
perm = list(range(len(x.size())))
if dim != 0:
perm[0], perm[dim] = perm[dim], perm[0]
x = x.permute(perm).contiguous()
out_size = ... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def tile(x, count, dim=0):\n perm = list(range(len(x.size())))\n if dim != 0:\n perm[0], perm[dim] = perm[dim], perm[0]\n x = x.permute(perm).contiguous()\n out_size = list(x.size())\n out_size[0] *= count\n x = x.repeat(count, *(1,) * x.dim()).transpose(0, 1).contiguous().view(*out_si... | [
"0.7133111",
"0.70022035",
"0.6921732",
"0.68431103",
"0.68431103",
"0.6697111",
"0.6491093",
"0.6400127",
"0.6390758",
"0.63895595",
"0.618992",
"0.61550206",
"0.611867",
"0.6112979",
"0.6105785",
"0.6094317",
"0.60829765",
"0.6058554",
"0.6034927",
"0.60330725",
"0.6024326"... | 0.6827513 | 5 |
Freeze the parameters of this module, i.e. do not update them during training | def freeze_params(module: nn.Module):
for _, p in module.named_parameters():
p.requires_grad = False | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def freeze(self):\n # Freeze.\n self.frozen = True\n for param in self.parameters():\n param.requires_grad = False",
"def __freeze(self):\r\n features_layer = self._model._net\r\n for param in features_layer.parameters():\r\n param.requires_grad = False",
... | [
"0.77948684",
"0.76171887",
"0.7449217",
"0.73946375",
"0.7314692",
"0.729194",
"0.72498846",
"0.7186831",
"0.70168376",
"0.69934535",
"0.69930685",
"0.6821718",
"0.68051827",
"0.6795892",
"0.6745624",
"0.6734002",
"0.67038447",
"0.66956234",
"0.66798335",
"0.6644752",
"0.664... | 0.73185027 | 4 |
Enumerates absolute paths of files under `dir` but excluding those the function `filter` returns False. | def list_image_files(dir, filter=None):
for entry in os.listdir(dir):
path = os.path.join(dir, entry)
if os.path.isdir(path):
for p in list_image_files(path, filter):
yield p
elif any((entry.lower().endswith(ext) for ext in image_exts)):
if filter and ... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def list_files_recursively(dir: str, valid_extensions: list = None, filter_fn=None) -> list:\n\n def file_path_generator():\n for dir_name, _, file_names in os.walk(dir):\n for filename in file_names:\n yield os.path.join(dir_name, filename)\n\n return [file_path for file_pat... | [
"0.6643024",
"0.66275597",
"0.6609569",
"0.65067625",
"0.6464404",
"0.64575857",
"0.6438825",
"0.6407994",
"0.6387433",
"0.6345481",
"0.6318649",
"0.6316253",
"0.62388134",
"0.6195835",
"0.6184927",
"0.61324525",
"0.6122803",
"0.6077047",
"0.6065856",
"0.6043274",
"0.60263616... | 0.6766971 | 0 |
Returns whether the file specified with `path` is a sidecar JPEG file or not. | def is_sidecar_jpeg(path):
path_filename, ext = os.path.splitext(path)
ext = ext.lower()
return any((ext == x for x in jpeg_exts)) and \
any((os.path.exists(path_filename + x) for x in raw_exts)) | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def is_jpg(filename):\n return '.jpg' in filename",
"def isPicture(file): \n return os.path.splitext(file)[1][1:].lower() in ['jpg', 'jpeg', 'gif', 'png', 'tif', 'tiff', 'bmp']",
"def check_type(filename):\n try:\n im = Image.read(filename)\n except SanperaError:\n return False\n e... | [
"0.61065996",
"0.60510033",
"0.59241307",
"0.59176433",
"0.5875605",
"0.58321977",
"0.5815605",
"0.574858",
"0.56689245",
"0.56637555",
"0.56612223",
"0.5611139",
"0.5608929",
"0.5594044",
"0.5588557",
"0.55783355",
"0.5538523",
"0.5523795",
"0.5503051",
"0.5489112",
"0.54878... | 0.8176112 | 0 |
transform target sense annotated with NOAD (New Oxford American Dictionary) word senses into WordNet senses | def NOAD_to_wordnet(data):
NOAD_to_wordnet = {}
with open(algorithmic_map, 'r') as f:
lines = f.readlines()
for line in lines:
noad, wordnet = line.split()
NOAD_to_wordnet[noad] = wordnet
with open(manual_map, 'r') as f:
lines = f.readlines()
... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def extract_english_raw_texts():\n # conceptnet triples raw text\n cpnet_en_raw_text = []\n\n # conceptnet entity context\n cpnet_en_entity_context = []\n\n with open(conceptnet_path, encoding=\"utf8\") as f:\n for line in f.readlines():\n ls = line.split('\\t')\n if ls[... | [
"0.61455923",
"0.6104557",
"0.5963491",
"0.58825034",
"0.5802276",
"0.5780971",
"0.57554984",
"0.5746371",
"0.5708776",
"0.56963277",
"0.56147546",
"0.560279",
"0.55962706",
"0.55882293",
"0.5502685",
"0.5463144",
"0.5444419",
"0.5439072",
"0.54318523",
"0.54296017",
"0.54290... | 0.7904227 | 0 |
build sense vector for every target sense using the definition of wordnet and glove embedding return | def build_sense_embedding(target_sense_to_id, word_freq, EMBEDDING_DIM):
res = {}
wordvecs = load_glove(EMBEDDING_DIM)
for target_sense_list in target_sense_to_id:
for key, _ in target_sense_list.items():
sense_vector = np.zeros(EMBEDDING_DIM)
senses = key.split('... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def build_doc_sense_vec(self):\n\t\twith codecs.open(self.vocab_file, encoding='utf-8', mode='r') as infile:\n\t\t\tline = infile.readline()\n\t\t\ti = 0\n\t\t\twhile line:\n\t\t\t\tword = line.split()[0]\n\t\t\t\tif not self.word2IdVocabulary.has_key(word):\n\t\t\t\t\t# print i, word\n\t\t\t\t\t# else:\n\t\t\t\t\... | [
"0.6847894",
"0.6233457",
"0.6051749",
"0.6051169",
"0.60288686",
"0.5982624",
"0.5979444",
"0.59690243",
"0.5957364",
"0.59261304",
"0.5911474",
"0.58430237",
"0.5838928",
"0.580763",
"0.5762697",
"0.57598484",
"0.57554895",
"0.57523525",
"0.57427406",
"0.5739391",
"0.572869... | 0.73034346 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.