code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
def _strip_last_part(date): parts = date.split('-') return '-'.join(parts[:-1]) fake_dates = {'0000', '9999'} if date in fake_dates: return None try: return normalize_date(date) except ValueError: if '-' not in date: raise else: ...
def normalize_date_aggressively(date)
Normalize date, stripping date parts until a valid date is obtained.
3.236566
3.020528
1.071523
if country_name: country_name = country_name.upper().replace('.', '').strip() if country_to_iso_code.get(country_name): return country_to_iso_code.get(country_name) elif country_name == 'KOREA': if city.upper() in south_korean_cities: return 'KR'...
def match_country_name_to_its_code(country_name, city='')
Try to match country name with its code. Name of the city helps when country_name is "Korea".
3.050684
3.073332
0.992631
if state_string: state_string = state_string.upper().replace('.', '').strip() if us_state_to_iso_code.get(state_string): return us_state_to_iso_code.get(state_string) else: for code, state_spellings in us_states_alternative_spellings.items(): for ...
def match_us_state(state_string)
Try to match a string with one of the states in the US.
2.633873
2.666413
0.987796
geo_elements = address_string.split(',') city = geo_elements[0] country_name = geo_elements[-1].upper().replace('.', '').strip() us_state = None state = None country_code = None # Try to match the country country_code = match_country_name_to_its_code(country_name, city) if co...
def parse_conference_address(address_string)
Parse a conference address. This is a pretty dummy address parser. It only extracts country and state (for US) and should be replaced with something better, like Google Geocoding.
3.347648
3.24589
1.03135
address_list = force_list(address) state_province = match_us_state(state_province) or state_province postal_code = force_list(postal_code) country = force_list(country) country_code = match_country_code(country_code) if isinstance(postal_code, (tuple, list)): postal_code = ', '.jo...
def parse_institution_address(address, city, state_province, country, postal_code, country_code)
Parse an institution address.
2.556016
2.5166
1.015662
def _is_schema_inspire_bai(id_, schema): return schema == 'INSPIRE BAI' def _is_schema_inspire_id(id_, schema): return schema == 'INSPIRE ID' def _is_schema_spires(id_, schema): return schema == 'SPIRES' def _is_schema_linkedin(id, schema): return schema == 'LINKE...
def ids2marc(self, key, value)
Populate the ``035`` MARC field. Also populates the ``8564`` and ``970`` MARC field through side effects.
2.385497
2.210515
1.079159
def _get_title(value): c_value = force_single_element(value.get('c', '')) if c_value != 'title (e.g. Sir)': return c_value def _get_value(value): a_value = force_single_element(value.get('a', '')) q_value = force_single_element(value.get('q', '')) return...
def name(self, key, value)
Populate the ``name`` key. Also populates the ``status``, ``birth_date`` and ``death_date`` keys through side effects.
3.160582
3.004469
1.05196
result = self.get('100', {}) result['a'] = value.get('value') result['b'] = value.get('numeration') result['c'] = value.get('title') result['q'] = value.get('preferred_name') if 'name_variants' in value: self['400'] = [{'a': el} for el in value['name_variants']] if 'native_nam...
def name2marc(self, key, value)
Populates the ``100`` field. Also populates the ``400``, ``880``, and ``667`` fields through side effects.
3.806011
3.227695
1.179173
email_addresses = self.get("email_addresses", []) current = None record = None recid_or_status = force_list(value.get('z')) for el in recid_or_status: if el.lower() == 'current': current = True if value.get('a') else None else: record = get_record_ref(ma...
def positions(self, key, value)
Populate the positions field. Also populates the email_addresses field by side effect.
3.678184
3.530628
1.041793
m_or_o = 'm' if value.get('current') else 'o' element = { m_or_o: value.get('value') } if value.get('hidden'): return element else: self.setdefault('371', []).append(element) return None
def email_addresses2marc(self, key, value)
Populate the 595 MARCXML field. Also populates the 371 field as a side effect.
6.524986
5.58241
1.168847
emails = self.get('email_addresses', []) if value.get('o'): emails.append({ 'value': value.get('o'), 'current': False, 'hidden': True, }) if value.get('m'): emails.append({ 'value': value.get('m'), 'current': True, ...
def email_addresses595(self, key, value)
Populates the ``email_addresses`` field using the 595 MARCXML field. Also populates ``_private_notes`` as a side effect.
3.694863
3.129433
1.180681
def _is_arxiv(category): return category in valid_arxiv_categories() def _is_inspire(category): schema = load_schema('elements/inspire_field') valid_inspire_categories = schema['properties']['term']['enum'] return category in valid_inspire_categories def _normalize(a_...
def arxiv_categories(self, key, value)
Populate the ``arxiv_categories`` key. Also populates the ``inspire_categories`` key through side effects.
2.859147
2.716483
1.052518
name_field = self.get('100', {}) if 'd' in name_field: if int(name_field['d'].split('-')[0]) > int(value.split('-')[0]): dates_field = ' - '.join([value, name_field['d']]) else: dates_field = ' - '.join([name_field['d'], value]) else: dates_field = value...
def birth_and_death_date2marc(self, key, value)
Populate the ``100__d`` MARC field, which includes the birth and the death date. By not using the decorator ```for_each_value```, the values of the fields ```birth_date``` and ```death_date``` are both added to ```values``` as a list.
3.089775
2.974053
1.03891
description = force_single_element(value.get('y')) url = value.get('u') linkedin_match = LINKEDIN_URL.match(url) twitter_match = TWITTER_URL.match(url) wikipedia_match = WIKIPEDIA_URL.match(url) if linkedin_match: self.setdefault('ids', []).append( { 'sc...
def urls(self, key, value)
Populate the ``url`` key. Also populates the ``ids`` key through side effects.
2.562108
2.506226
1.022297
new_record = self.get('new_record', {}) ids = self.get('ids', []) for value in force_list(value): for id_ in force_list(value.get('a')): ids.append({ 'schema': 'SPIRES', 'value': id_, }) new_recid = force_single_element(value.get...
def new_record(self, key, value)
Populate the ``new_record`` key. Also populates the ``ids`` key through side effects.
6.566931
5.552187
1.182765
def _is_deleted(value): return force_single_element(value.get('c', '')).upper() == 'DELETED' def _is_stub(value): return not (force_single_element(value.get('a', '')).upper() == 'USEFUL') deleted = self.get('deleted') stub = self.get('stub') for value in force_list(value): ...
def deleted(self, key, value)
Populate the ``deleted`` key. Also populates the ``stub`` key through side effects.
4.938163
4.135978
1.193953
value = force_list(value) def _get_ids(value): ids = { 'i': [], 'j': [], } if value.get('ids'): for _id in value.get('ids'): if _id.get('schema') == 'INSPIRE ID': ids['i'].append(_id.get('value')) ...
def authors2marc(self, key, value)
Populate the ``100`` MARC field. Also populates the ``700`` and the ``701`` MARC fields through side effects.
2.234745
2.21596
1.008477
def _get_medium(value): def _normalize(medium): schema = load_schema('hep') valid_media = schema['properties']['isbns']['items']['properties']['medium']['enum'] medium = medium.lower().replace('-', '').replace(' ', '') if medium in valid_media: ...
def isbns(self, key, value)
Populate the ``isbns`` key.
4.111602
3.986311
1.03143
def _get_first_non_curator_source(sources): sources_without_curator = [el for el in sources if el.upper() != 'CURATOR'] return force_single_element(sources_without_curator) def _get_material(value): MATERIAL_MAP = { 'ebook': 'publication', } q_value = f...
def dois(self, key, value)
Populate the ``dois`` key. Also populates the ``persistent_identifiers`` key through side effects.
2.995548
2.7402
1.093186
return { '2': 'DOI', '9': value.get('source'), 'a': value.get('value'), 'q': value.get('material'), }
def dois2marc(self, key, value)
Populate the ``0247`` MARC field.
7.240866
6.925584
1.045524
return { '2': value.get('schema'), '9': value.get('source'), 'a': value.get('value'), 'q': value.get('material'), }
def persistent_identifiers2marc(self, key, value)
Populate the ``0247`` MARC field.
6.188312
6.139181
1.008003
def _is_oai(id_, schema): return id_.startswith('oai:') def _is_desy(id_, schema): return id_ and schema in ('DESY',) def _is_texkey(id_, schema): return id_ and schema in ('INSPIRETeX', 'SPIRESTeX') texkeys = self.get('texkeys', []) external_system_identifiers = self...
def texkeys(self, key, value)
Populate the ``texkeys`` key. Also populates the ``external_system_identifiers`` and ``_desy_bookkeeping`` keys through side effects.
2.585923
2.205359
1.172563
result = [] values = force_list(value) if values: value = values[0] result.append({ '9': 'INSPIRETeX', 'a': value, }) for value in values[1:]: result.append({ '9': 'INSPIRETeX', 'z': value, ...
def texkeys2marc(self, key, value)
Populate the ``035`` MARC field.
4.817169
4.336767
1.110774
def _is_scheme_cernkey(id_, schema): return schema == 'CERNKEY' def _is_scheme_spires(id_, schema): return schema == 'SPIRES' result_035 = self.get('035', []) id_dict = self.get('id_dict', defaultdict(list)) result_970 = self.get('970', []) values = force_list(value) ...
def external_system_identifiers2marc(self, key, value)
Populate the ``035`` MARC field. Also populates the ``970`` MARC field through side effects and an extra ``id_dict`` dictionary that holds potentially duplicate IDs that are post-processed in a filter.
3.490487
2.823097
1.236404
def _get_clean_arxiv_eprint(id_): return id_.split(':')[-1] def _is_arxiv_eprint(id_, source): return source.lower() == 'arxiv' def _is_hidden_report_number(other_id, source): return other_id def _get_clean_source(source): if source == 'arXiv:reportnumber': ...
def arxiv_eprints(self, key, value)
Populate the ``arxiv_eprints`` key. Also populates the ``report_numbers`` key through side effects.
2.826962
2.619738
1.079101
result_037 = self.get('037', []) result_035 = self.get('035', []) result_65017 = self.get('65017', []) for value in values: arxiv_id = value.get('value') arxiv_id = 'arXiv:' + arxiv_id if is_arxiv_post_2007(arxiv_id) else arxiv_id result_037.append({ '9': 'arXiv...
def arxiv_eprints2marc(self, key, values)
Populate the ``037`` MARC field. Also populates the ``035`` and the ``65017`` MARC fields through side effects.
2.885427
2.379237
1.212753
def _get_mangled_source(source): if source == 'arXiv': return 'arXiv:reportnumber' return source source = _get_mangled_source(value.get('source')) if value.get('hidden'): return { '9': source, 'z': value.get('value'), } return {...
def report_numbers2marc(self, key, value)
Populate the ``037`` MARC field.
5.465593
5.395712
1.012951
languages = self.get('languages', []) values = force_list(value.get('a')) for value in values: for language in RE_LANGUAGE.split(value): try: name = language.strip().capitalize() languages.append(pycountry.languages.get(name=name).alpha_2) ...
def languages(self, key, value)
Populate the ``languages`` key.
5.089746
4.854918
1.048369
return {'a': pycountry.languages.get(alpha_2=value).name.lower()}
def languages2marc(self, key, value)
Populate the ``041`` MARC field.
9.921303
10.86675
0.912996
record = get_record_ref(value.get('z'), 'institutions') return { 'curated_relation': record is not None, 'record': record, 'value': value.get('a'), }
def record_affiliations(self, key, value)
Populate the ``record_affiliations`` key.
11.216563
10.669552
1.051268
schema = load_schema('hep') publication_type_schema = schema['properties']['publication_type'] valid_publication_types = publication_type_schema['items']['enum'] document_type = self.get('document_type', []) publication_type = self.get('publication_type', []) a_values = force_list(value.g...
def document_type(self, key, value)
Populate the ``document_type`` key. Also populates the ``_collections``, ``citeable``, ``core``, ``deleted``, ``refereed``, ``publication_type``, and ``withdrawn`` keys through side effects.
2.719714
2.321698
1.171433
if value in DOCUMENT_TYPE_REVERSE_MAP and DOCUMENT_TYPE_REVERSE_MAP[value]: return {'a': DOCUMENT_TYPE_REVERSE_MAP[value]}
def document_type2marc(self, key, value)
Populate the ``980`` MARC field.
4.762321
4.360028
1.092268
def _has_curator_flag(value): normalized_nine_values = [el.upper() for el in force_list(value.get('9'))] return 'CURATOR' in normalized_nine_values def _is_curated(value): return force_single_element(value.get('z')) == '1' and _has_curator_flag(value) def _set_record(el): ...
def references(self, key, value)
Populate the ``references`` key.
4.335742
4.278977
1.013266
reference = value.get('reference', {}) pids = force_list(reference.get('persistent_identifiers')) a_values = ['doi:' + el for el in force_list(reference.get('dois'))] a_values.extend(['hdl:' + el['value'] for el in pids if el.get('schema') == 'HDL']) a_values.extend(['urn:' + el['value'] for e...
def references2marc(self, key, value)
Populate the ``999C5`` MARC field.
2.835053
2.821749
1.004715
def _is_hidden(value): return 'HIDDEN' in [val.upper() for val in value] or None def _is_figure(value): figures_extensions = ['.png'] return value.get('f') in figures_extensions def _is_fulltext(value): return value.get('d', '').lower() == 'fulltext' or None def _...
def documents(self, key, value)
Populate the ``documents`` key. Also populates the ``figures`` key through side effects.
3.839185
3.691251
1.040077
marcjson = create_record(marcxml, keep_singletons=False) collections = _get_collections(marcjson) if 'conferences' in collections: return conferences.do(marcjson) elif 'data' in collections: return data.do(marcjson) elif 'experiment' in collections: return experiments.d...
def marcxml2record(marcxml)
Convert a MARCXML string to a JSON record. Tries to guess which set of rules to use by inspecting the contents of the ``980__a`` MARC field, but falls back to HEP in case nothing matches, because records belonging to special collections logically belong to the Literature collection but don't have ``980...
3.166177
3.187709
0.993245
schema_name = _get_schema_name(record) if schema_name == 'hep': marcjson = hep2marc.do(record) elif schema_name == 'authors': marcjson = hepnames2marc.do(record) else: raise NotImplementedError(u'JSON -> MARC rules missing for "{}"'.format(schema_name)) record = RECORD...
def record2marcxml(record)
Convert a JSON record to a MARCXML string. Deduces which set of rules to use by parsing the ``$schema`` key, as it unequivocally determines which kind of record we have. Args: record(dict): a JSON record. Returns: str: a MARCXML string converted from the record.
3.37002
3.51853
0.957792
result = maybe_int(force_single_element(value.get('a', ''))) if result and result > 0: return result
def number_of_pages(self, key, value)
Populate the ``number_of_pages`` key.
13.483664
13.044195
1.033691
preliminary_results_prefixes = ['ATLAS-CONF-', 'CMS-PAS-', 'CMS-DP-', 'LHCB-CONF-'] note_prefixes = ['ALICE-INT-', 'ATL-', 'ATLAS-CONF-', 'CMS-DP-', 'CMS-PAS-', 'LHCB-CONF-', 'LHCB-PUB-'] result_037 = self.get('037__', []) result_500 = self.get('500__', []) result_595 = self.get('595__', []) ...
def secondary_report_numbers(self, key, value)
Populate the ``037`` MARC field. Also populates the ``500``, ``595`` and ``980`` MARC field through side effects.
4.316386
3.78055
1.141735
field_700 = self.get('700__', []) field_701 = self.get('701__', []) is_supervisor = any(el.lower().startswith('dir') for el in force_list(value.get('e', ''))) if is_supervisor: field_701.append(_converted_author(value)) else: field_700.append(_converted_author(value)) self...
def nonfirst_authors(self, key, value)
Populate ``700`` MARC field. Also populates the ``701`` MARC field through side-effects.
5.001022
4.163787
1.201075
def _is_preprint(value): return value.get('y', '').lower() == 'preprint' def _is_fulltext(value): return value['u'].endswith('.pdf') and value['u'].startswith('http://cds.cern.ch') def _is_local_copy(value): return 'local copy' in value.get('y', '') def _is_ignored_domain...
def urls(self, key, value)
Populate the ``8564`` MARC field. Also populate the ``FFT`` field through side effects.
3.142
2.827893
1.111075
if not key.startswith('245'): return { 'source': value.get('9'), 'subtitle': value.get('b'), 'title': value.get('a'), } self.setdefault('titles', []).insert(0, { 'source': value.get('9'), 'subtitle': value.get('b'), 'title': value...
def titles(self, key, value)
Populate the ``titles`` key.
3.804403
3.654632
1.040981
return { 'language': langdetect.detect(value.get('a')), 'source': value.get('9'), 'subtitle': value.get('b'), 'title': value.get('a'), }
def title_translations(self, key, value)
Populate the ``title_translations`` key.
6.297039
6.601796
0.953837
first, rest = values[0], values[1:] self.setdefault('245', []).append({ 'a': first.get('title'), 'b': first.get('subtitle'), '9': first.get('source'), }) return [ { 'a': value.get('title'), 'b': value.get('subtitle'), '9': value....
def titles2marc(self, key, values)
Populate the ``246`` MARC field. Also populates the ``245`` MARC field through side effects.
2.832095
3.15856
0.896641
return { 'a': value.get('title'), 'b': value.get('subtitle'), '9': value.get('source'), }
def title_translations2marc(self, key, value)
Populate the ``242`` MARC field.
4.564257
4.42359
1.031799
return { 'place': value.get('a'), 'publisher': value.get('b'), 'date': normalize_date_aggressively(value.get('c')), }
def imprints(self, key, value)
Populate the ``imprints`` key.
8.53527
7.825248
1.090735
return { 'a': value.get('place'), 'b': value.get('publisher'), 'c': value.get('date'), }
def imprints2marc(self, key, value)
Populate the ``260`` MARC field.
4.675845
4.509909
1.036794
def _means_not_curated(public_note): return public_note in [ '*Brief entry*', '* Brief entry *', '*Temporary entry*', '* Temporary entry *', '*Temporary record*', '* Temporary record *', ] public_notes = self.get('publ...
def public_notes(self, key, value)
Populate the ``public_notes`` key. Also populates the ``curated`` and ``thesis_info`` keys through side effects.
4.506859
4.031061
1.118033
def _get_degree_type(value): DEGREE_TYPES_MAP = { 'RAPPORT DE STAGE': 'other', 'INTERNSHIP REPORT': 'other', 'DIPLOMA': 'diploma', 'BACHELOR': 'bachelor', 'LAUREA': 'laurea', 'MASTER': 'master', 'THESIS': 'other', ...
def thesis_info(self, key, value)
Populate the ``thesis_info`` key.
3.867854
3.750615
1.031258
def _get_b_value(value): DEGREE_TYPES_MAP = { 'bachelor': 'Bachelor', 'diploma': 'Diploma', 'habilitation': 'Habilitation', 'laurea': 'Laurea', 'master': 'Master', 'other': 'Thesis', 'phd': 'PhD', } deg...
def thesis_info2marc(self, key, value)
Populate the ``502`` MARC field. Also populates the ``500`` MARC field through side effects.
3.607292
3.312795
1.088897
result = [] source = force_single_element(value.get('9')) for a_value in force_list(value.get('a')): result.append({ 'source': source, 'value': a_value, }) return result
def abstracts(self, key, value)
Populate the ``abstracts`` key.
7.750946
6.937846
1.117198
return { 'agency': value.get('a'), 'grant_number': value.get('c'), 'project_number': value.get('f'), }
def funding_info(self, key, value)
Populate the ``funding_info`` key.
6.264318
5.911957
1.059601
return { 'a': value.get('agency'), 'c': value.get('grant_number'), 'f': value.get('project_number'), }
def funding_info2marc(self, key, value)
Populate the ``536`` MARC field.
4.970734
4.760396
1.044185
def _get_license(value): a_values = force_list(value.get('a')) oa_licenses = [el for el in a_values if el == 'OA' or el == 'Open Access'] other_licenses = [el for el in a_values if el != 'OA' and el != 'Open Access'] if not other_licenses: return force_single_eleme...
def license(self, key, value)
Populate the ``license`` key.
4.141431
4.085623
1.01366
return { 'a': value.get('license'), 'b': value.get('imposing'), 'u': value.get('url'), '3': value.get('material'), }
def license2marc(self, key, value)
Populate the ``540`` MARC field.
7.413738
6.957043
1.065645
MATERIAL_MAP = { 'Article': 'publication', 'Published thesis as a book': 'publication', } material = value.get('e') or value.get('3') return { 'holder': value.get('d'), 'material': MATERIAL_MAP.get(material), 'statement': value.get('f'), 'url': valu...
def copyright(self, key, value)
Populate the ``copyright`` key.
7.265054
6.81452
1.066114
E_MAP = { 'publication': 'Article', } e_value = value.get('material') return { 'd': value.get('holder'), 'e': E_MAP.get(e_value), 'f': value.get('statement'), 'g': value.get('year'), 'u': value.get('url'), }
def copyright2marc(self, key, value)
Populate the ``542`` MARC field.
6.011621
5.74013
1.047297
def _is_for_cds(value): normalized_c_values = [el.upper() for el in force_list(value.get('c'))] return 'CDS' in normalized_c_values def _is_for_hal(value): normalized_c_values = [el.upper() for el in force_list(value.get('c'))] return 'HAL' in normalized_c_values def _...
def _private_notes(self, key, value)
Populate the ``_private_notes`` key. Also populates the ``_export_to`` key through side effects.
2.691786
2.483932
1.08368
def _is_from_hal(value): return value.get('source') == 'HAL' if not _is_from_hal(value): return { '9': value.get('source'), 'a': value.get('value'), } self.setdefault('595_H', []).append({'a': value.get('value')})
def _private_notes2marc(self, key, value)
Populate the ``595`` MARC key. Also populates the `595_H` MARC key through side effects.
7.307973
4.961171
1.473034
def _is_for_cds(value): return 'CDS' in value def _is_for_hal(value): return 'HAL' in value and value['HAL'] def _is_not_for_hal(value): return 'HAL' in value and not value['HAL'] result = [] if _is_for_cds(value): result.append({'c': 'CDS'}) if _is_for_...
def _export_to2marc(self, key, value)
Populate the ``595`` MARC field.
2.787387
2.834651
0.983326
return { 'date': normalize_date(value.get('d')), 'expert': force_single_element(value.get('a')), 'status': value.get('s'), }
def _desy_bookkeeping(self, key, value)
Populate the ``_desy_bookkeeping`` key.
8.639607
8.716738
0.991151
if 'identifier' not in value: return { 'a': value.get('expert'), 'd': value.get('date'), 's': value.get('status'), } self.setdefault('035', []).append({ '9': 'DESY', 'z': value['identifier'] })
def _desy_bookkeeping2marc(self, key, value)
Populate the ``595_D`` MARC field. Also populates the ``035`` MARC field through side effects.
6.72047
5.8481
1.149172
if value.get('q'): self['date_proposed'] = normalize_date(value['q']) if value.get('r'): self['date_approved'] = normalize_date(value['r']) if value.get('s'): self['date_started'] = normalize_date(value['s']) if value.get('c'): self['date_cancelled'] = normalize_date...
def _dates(self, key, value)
Don't populate any key through the return value. On the other hand, populates the ``date_proposed``, ``date_approved``, ``date_started``, ``date_cancelled``, and the ``date_completed`` keys through side effects.
2.580143
1.994672
1.293517
experiment = self.get('experiment', {}) legacy_name = self.get('legacy_name', '') accelerator = self.get('accelerator', {}) institutions = self.get('institutions', []) for value in force_list(values): if value.get('c'): experiment['value'] = value.get('c') if value....
def experiment(self, key, values)
Populate the ``experiment`` key. Also populates the ``legacy_name``, the ``accelerator``, and the ``institutions`` keys through side effects.
3.139162
2.555258
1.228511
core = self.get('core') deleted = self.get('deleted') project_type = self.get('project_type', []) if not core: normalized_a_values = [el.upper() for el in force_list(value.get('a'))] if 'CORE' in normalized_a_values: core = True if not deleted: normalized_c...
def core(self, key, value)
Populate the ``core`` key. Also populates the ``deleted`` and ``project_type`` keys through side effects.
2.69618
2.410321
1.118598
def _control_number(self, key, value): self['self'] = get_record_ref(int(value), endpoint) return int(value) return _control_number
def control_number(endpoint)
Populate the ``control_number`` key. Also populates the ``self`` key through side effects.
9.964553
7.148843
1.393869
def _get_datetime(value): d_value = force_single_element(value.get('d', '')) if d_value: try: date = PartialDate.loads(d_value) except ValueError: return d_value else: datetime_ = datetime(year=date.year, month=...
def acquisition_source(self, key, value)
Populate the ``acquisition_source`` key.
2.817532
2.802813
1.005252
return [ { 'source': value.get('9'), 'value': public_note, } for public_note in force_list(value.get('a')) ]
def public_notes_500(self, key, value)
Populate the ``public_notes`` key.
8.386397
8.059411
1.040572
return [ { 'source': value.get('9'), 'value': _private_note, } for _private_note in force_list(value.get('a')) ]
def _private_notes_595(self, key, value)
Populate the ``_private_notes`` key.
8.612991
7.887519
1.091977
@utils.flatten @utils.for_each_value def _external_system_identifiers(self, key, value): new_recid = maybe_int(value.get('d')) if new_recid: self['new_record'] = get_record_ref(new_recid, endpoint) return [ { 'schema': 'SPIRES', ...
def external_system_identifiers(endpoint)
Populate the ``external_system_identifiers`` key. Also populates the ``new_record`` key through side effects.
6.835236
5.950144
1.148751
@utils.for_each_value def _deleted_records(self, key, value): deleted_recid = maybe_int(value.get('a')) if deleted_recid: return get_record_ref(deleted_recid, endpoint) return _deleted_records
def deleted_records(endpoint)
Populate the ``deleted_records`` key.
7.014112
6.804848
1.030752
result = [] a_value = force_single_element(value.get('a')) e_values = [el for el in force_list(value.get('e')) if el != '-'] zero_values = force_list(value.get('0')) if a_value and not e_values: result.append({'accelerator': a_value}) # XXX: we zip only when they have the same le...
def accelerator_experiments(self, key, value)
Populate the ``accelerator_experiments`` key.
4.36664
4.327188
1.009117
keywords = self.get('keywords', []) energy_ranges = self.get('energy_ranges', []) for value in force_list(values): if value.get('a'): schema = force_single_element(value.get('2', '')).upper() sources = force_list(value.get('9')) a_values = force_list(value....
def keywords(self, key, values)
Populate the ``keywords`` key. Also populates the ``energy_ranges`` key through side effects.
4.232082
3.771228
1.122203
result_695 = self.get('695', []) result_084 = self.get('084', []) result_6531 = self.get('6531', []) for value in values: schema = value.get('schema') source = value.get('source') keyword = value.get('value') if schema == 'PACS' or schema == 'PDG': resu...
def keywords2marc(self, key, values)
Populate the ``695`` MARC field. Also populates the ``084`` and ``6531`` MARC fields through side effects.
2.618365
2.229094
1.174632
result = [] for g_value in force_list(value.get('g')): collaborations = normalize_collaboration(g_value) if len(collaborations) == 1: result.append({ 'record': get_record_ref(maybe_int(value.get('0')), 'experiments'), 'value': collaborations[0], ...
def collaborations(self, key, value)
Populate the ``collaborations`` key.
6.338878
5.862449
1.081268
def _get_cnum(value): w_value = force_single_element(value.get('w', '')) normalized_w_value = w_value.replace('/', '-').upper() return normalized_w_value def _get_material(value): schema = load_schema('elements/material') valid_materials = schema['enum'] m...
def publication_info(self, key, value)
Populate the ``publication_info`` key.
2.625996
2.588229
1.014592
result_773 = self.get('773', []) result_7731 = self.get('7731', []) for value in force_list(convert_new_publication_info_to_old(values)): page_artid = [] if value.get('page_start') and value.get('page_end'): page_artid.append(u'{page_start}-{page_end}'.format(**value)) ...
def publication_info2marc(self, key, values)
Populate the ``773`` MARC field. Also populates the ``7731`` MARC field through side effects.
3.25131
3.038653
1.069984
record = get_record_ref(maybe_int(value.get('w')), 'literature') if record: return { 'curated_relation': record is not None, 'record': record, 'relation': 'predecessor', }
def related_records_78002(self, key, value)
Populate the ``related_records`` key.
12.687979
12.448434
1.019243
record = get_record_ref(maybe_int(value.get('w')), 'literature') if record: return { 'curated_relation': record is not None, 'record': record, 'relation': 'successor', }
def related_records_78502(self, key, value)
Populate the ``related_records`` key.
13.566691
13.345384
1.016583
record = get_record_ref(maybe_int(value.get('w')), 'literature') if record: return { 'curated_relation': record is not None, 'record': record, 'relation_freetext': value.get('i'), }
def related_records_78708(self, key, value)
Populate the ``related_records`` key.
11.572088
11.303019
1.023805
if value.get('relation_freetext'): return { 'i': value.get('relation_freetext'), 'w': get_recid_from_ref(value.get('record')), } elif value.get('relation') == 'successor': self.setdefault('78502', []).append({ 'i': 'superseded by', 'w'...
def related_records2marc(self, key, value)
Populate the ``78708`` MARC field Also populates the ``78002``, ``78502`` MARC fields through side effects.
3.263204
2.798191
1.166183
return [ { 'source': value.get('9'), 'value': _private_note, } for _private_note in force_list(value.get('x')) ]
def _private_notes(self, key, value)
Populate the ``_private_notes`` key.
8.692898
8.38018
1.037316
proceedings = self.get('proceedings') refereed = self.get('refereed') if not proceedings: normalized_a_values = [el.upper() for el in force_list(value.get('a'))] if 'PROCEEDINGS' in normalized_a_values: proceedings = True if not refereed: normalized_a_values = ...
def proceedings(self, key, value)
Populate the ``proceedings`` key. Also populates the ``refereed`` key through side effects.
3.070673
2.837787
1.082066
short_title = value.get('a') title_variants = self.get('title_variants', []) if value.get('u'): short_title = value.get('u') title_variants.append(value.get('a')) self['title_variants'] = title_variants return short_title
def short_title(self, key, value)
Populate the ``short_title`` key. Also populates the ``title_variants`` key through side effects.
4.606118
3.582847
1.285603
deleted = self.get('deleted') book_series = self.get('book_series') if not deleted: normalized_a_values = [el.upper() for el in force_list(value.get('a'))] normalized_c_values = [el.upper() for el in force_list(value.get('c'))] if 'DELETED' in normalized_a_values or 'DELETED' i...
def deleted(self, key, value)
Populate the ``deleted`` key. Also populates the ``book_series`` key through side effects.
2.730734
2.525201
1.081393
return [normalize_rank(el) for el in force_list(value.get('a'))]
def ranks(self, key, value)
Populate the ``ranks`` key.
21.406355
22.316635
0.959211
parser = argparse.ArgumentParser(description=self.description) parser.add_argument( '--version', help='show version and exit', default=False, action='store_true') parser.add_argument( '--debug', help='enable debugging', default=False, act...
def new_parser(self)
Create a command line argument parser Add a few default flags, such as --version for displaying the program version when invoked
2.517852
2.229897
1.129134
self.registered[command] = { 'function': function, 'description': description }
def add_command(self, command, function, description=None)
Register a new function with a the name `command` and `description` (which will be shown then help is invoked).
5.878416
4.839423
1.214693
args = args or self.parser.parse_args() if args.debug: logging.basicConfig(level=logging.DEBUG) if args.version: print(version.VERSION) sys.exit(0)
def run(self, args=None)
Parse command line arguments if necessary then run program. By default this method will just take of the --version flag. The logic for other flags should be handled by your subclass
2.702834
2.727895
0.990813
if command: return self.registered[command].get( 'description', 'No help available' ) return ', '.join(sorted(self.registered))
def help_function(self, command=None)
Show help for all available commands or just a single one
5.25593
5.386869
0.975693
super(Program, self).add_command(command, function, description) self.service.register(command, function)
def add_command(self, command, function, description=None)
Register a new function for command
4.927929
4.717709
1.04456
args = args or self.parser.parse_args() super(Program, self).run(args) # Read configuration file if any if args.config is not None: filepath = args.config self.config.read(filepath) # Start workers then wait until they finish work [w.st...
def run(self, args=None)
Parse comand line arguments/flags and run program
4.000923
3.754247
1.065706
def make(addr): c = Client(addr) c.socket._set_recv_timeout(timeout) return c if ',' in addr: addrs = addr.split(',') addrs = [a.strip() for a in addrs] return {a: make(a) for a in addrs} return make(addr)
def create_client(self, addr, timeout)
Create client(s) based on addr
3.611758
3.664788
0.98553
try: return client.call(command, *args) except Exception as e: return None, str(e)
def _call_single(self, client, command, *args)
Call single
3.1772
3.45717
0.919018
responses, errors = {}, {} for addr, client in clients.items(): res, err = self._call_single(client, command, *args) responses[addr] = res errors[addr] = err return responses, errors
def _call_multi(self, clients, command, *args)
Call multi
2.741015
2.717337
1.008714
if isinstance(self.c, dict): return self._call_multi(self.c, command, *args) return self._call_single(self.c, command, *args)
def call(self, command, *args)
Call remote service(s)
3.222865
3.141621
1.025861
if isinstance(self.c, dict): for client in self.c.values(): client.sock.close() return self.c.socket.close()
def close(self)
Close socket(s)
5.313388
4.599264
1.155269
if self.kind is 'local': what = res if not err else err print(what) return if self.kind is 'remote': if colored: red, green, reset = Fore.RED, Fore.GREEN, Fore.RESET else: red = green = reset = '' ...
def _show(self, res, err, prefix='', colored=False)
Show result or error
3.37502
3.356955
1.005381
if not command: return # Look for local methods first try: res = self.registered[command]['function'](self, *args) return Response('local', res, None) # Method not found, try remote except KeyError: # Execute remote com...
def call(self, command, *args)
Execute local OR remote command and show response
5.593123
4.981355
1.122812
parts = util.split(text) command = parts[0] if text and parts else None command = command.lower() if command else None args = parts[1:] if len(parts) > 1 else [] return (command, args)
def parse_input(self, text)
Parse ctl user input. Double quotes are used to group together multi words arguments.
4.045995
3.621979
1.117067