Get entire index of geographic name (key) and set of associated authors
    (value).
551414
def get_geo_index():
    
    _dict = {}
    for k, v in AUTHOR_EPITHET.items():
        _dict[k] = set(v)

    return _dict
8390
def index(self, key):
        
        if is_iterable(key):
            return [self.index(subkey) for subkey in key]
        return self.map[key]
1297710
private SortedSet<String> findIdsPerName(final String indexName,
            final SortedMap<String, SortedSet<String>> names) {
        if (names.containsKey(indexName)) {
            return names.get(indexName);
        }
        final TreeSet<String> idsPerName = new TreeSet<String>();
        names.put(indexName, idsPerName);
        return idsPerName;
    }
1213985
def _key_to_index(keys, key, single_only=False):
    ''
    if isinstance(key, int): # validate the int index
        try:
            keys[key]
        except IndexError:
            raise KeyError('Index out of range of keys: %s' % (key,))
        if key < 0:
            key += len(keys) # always positive index
        return key
#    keys = d.keys()
    if not single_only:
        if isinstance(key, (tuple, list)):
            return [_key_to_index_single(keys, k) for k in key]

        if isinstance(key, slice):
            start, stop, step = key.start, key.stop, key.step
            try:
                MI_check_index_name(start)
                start = keys.index(start)
            except TypeError:
                pass
            try:
                MI_check_index_name(stop)
                stop = keys.index(stop)
            except TypeError:
                pass
#            return slice(start, stop, step)
            args = slice(start, stop, step).indices(len(keys))
            return force_list(range(*args)) # list of indices
    try:
        return keys.index(key)
    except ValueError: # not IndexError
        raise KeyError('Key not found: %s' % (key,))
1315593
def authors2marc(self, key, value):
    
    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'))
                elif _id.get('schema') == 'ORCID':
                    ids['j'].append('ORCID:' + _id.get('value'))
                elif _id.get('schema') == 'JACOW':
                    ids['j'].append(_id.get('value'))
                elif _id.get('schema') == 'CERN':
                    ids['j'].append('CCID-' + _id.get('value')[5:])
        return ids

    def _get_affiliations(value):
        return [
            aff.get('value') for aff in value.get('affiliations', [])
        ]

    def _get_affiliations_identifiers(value):
        return [
            u'{}:{}'.format(aff.get('schema'), aff.get('value')) for aff in value.get('affiliations_identifiers', [])
        ]

    def _get_inspire_roles(value):
        values = force_list(value.get('inspire_roles'))
        return ['ed.' for role in values if role == 'editor']

    def _get_raw_affiliations(value):
        return [
            aff.get('value') for aff in value.get('raw_affiliations', [])
        ]

    def get_value_100_700(value):
        ids = _get_ids(value)
        return {
            'a': value.get('full_name'),
            'e': _get_inspire_roles(value),
            'q': value.get('alternative_names'),
            'i': ids.get('i'),
            'j': ids.get('j'),
            'm': value.get('emails'),
            't': _get_affiliations_identifiers(value),
            'u': _get_affiliations(value),
            'v': _get_raw_affiliations(value),
        }

    def get_value_701(value):
        ids = _get_ids(value)
        return {
            'a': value.get('full_name'),
            'q': value.get('alternative_names'),
            'i': ids.get('i'),
            'j': ids.get('j'),
            'u': _get_affiliations(value),
            'v': _get_raw_affiliations(value),
        }

    if len(value) > 1:
        self["700"] = []
        self["701"] = []

    for author in value[1:]:
        is_supervisor = 'supervisor' in author.get('inspire_roles', [])
        if is_supervisor:
            self["701"].append(get_value_701(author))
        else:
            self["700"].append(get_value_100_700(author))
    return get_value_100_700(value[0])
181980
def to_query(self):
        
        return {
            "geo_shape": {
                self.name: {
                    "indexed_shape":  {
                        "index": self.index_name,
                        "type": self.doc_type,
                        "id": self.shape_id,
                        "path": self.path
                    }
                }
            }
        }
882349
def _get_hash(self):
        
        if self.optionals and self.optionals.ISBN:
            isbn = self.optionals.ISBN.replace("-", "")

            if len(isbn) <= 10:
                return "97880" + isbn

            return isbn

        if self.optionals and self.optionals.EAN:
            return self.optionals.EAN

        return self.title + ",".join(map(lambda x: x.name, self.authors))
136740
def list_authors():
    """"""
    authors = Author.query.all()
    content = '<p>Authors:</p>'
    for author in authors:
        content += '<p>%s</p>' % author.name
    return content
457659
def keys(self):
    """"""
    columns = set()
    for name in vars(self):
      if (not name) or name[0] == "_":
        continue
      columns.add(name)
    return columns
1011217
def keys(self, prefix=None):
        """"""
        query = Setting.query
        if prefix:
            query = query.filter(Setting.key.startswith(prefix))

        # don't use iteritems: 'value' require little processing whereas we only
        # want 'key'
        return [i[0] for i in query.yield_per(1000).values(Setting.key)]
619102
public V get(K key, int index) {
		final Collection<V> collection = get(key);
		return CollUtil.get(collection, index);
	}
1158380
def index_map(data):
  """"""
  (entry, text_fn) = data
  text = text_fn()

  logging.debug("Got %s", entry.filename)
  for s in split_into_sentences(text):
    for w in split_into_words(s.lower()):
      yield (w, entry.filename)
41350
@Provides
  @Singleton
  @Named("geo")
  Map<String, Collection<String>> provideCountriesByRegion() {
    Map<String, Collection<String>>
        countriesByRegion =
        new LinkedHashMap<String, Collection<String>>();
    countriesByRegion.put("11",
                          Arrays.asList("AG", "AI", "AN", "AW", "BB", "BL", "BM", "BS", "BZ", "CA",
                                        "CR", "CU", "DM",
                                        "DO", "GD", "GL", "GP", "GT", "HN", "HT", "JM", "KN", "KY",
                                        "LC", "MF", "MQ", "MS",
                                        "MX", "NI", "PA", "PM", "PR", "SV", "TC", "TT", "US", "VC",
                                        "VG", "VI"));
    countriesByRegion.put("United States",
                          Arrays.asList("al", "ak", "as", "az", "ar", "aa", "ae", "ap", "ca", "co",
                                        "ct", "de", "dc",
                                        "fm", "fl", "ga", "gu", "hi", "id", "il", "in", "ia", "ks",
                                        "ky", "la", "me", "mh",
                                        "md", "ma", "mi", "mn", "ms", "mo", "mt", "ne", "nv", "nh",
                                        "nj", "nm", "ny", "nc",
                                        "nd", "mp", "oh", "ok", "or", "pw", "pa", "pr", "ri", "sc",
                                        "sd", "tn", "tx", "ut",
                                        "vt", "vi", "va", "wa", "wv", "wi", "wy"));
    countriesByRegion.put("Canada",
                          Arrays.asList("ab", "bc", "mb", "nb", "nl", "nt", "ns", "nu", "on", "pe",
                                        "qc", "sk", "yt"));
    // Continental South America
    countriesByRegion.put("12",
                          Arrays.asList("AR", "BO", "BR", "CL", "CO", "EC", "FK", "GF", "GY", "PE",
                                        "PY", "SR", "UY",
                                        "VE"));
    // Continental Europe
    countriesByRegion.put("13",
                          Arrays.asList("AD", "AL", "AT", "AX", "BA", "BE", "BG", "BY", "CH", "CZ",
                                        "DE", "DK", "EE",
                                        "ES", "EU", "FI", "FO", "FR", "FX", "GB", "GG", "GI", "GR",
                                        "HR", "HU", "IE", "IM",
                                        "IS", "IT", "JE", "LI", "LT", "LU", "LV", "MC", "MD", "ME",
                                        "MK", "MT", "NL", "NO",
                                        "PL", "PT", "RO", "RS", "RU", "SE", "SI", "SJ", "SK", "SM",
                                        "TR", "UA", "VA"));
    // Continental Africa
    countriesByRegion.put("14",
                          Arrays.asList("AO", "BF", "BI", "BJ", "BW", "CD", "CF", "CG", "CI", "CM",
                                        "CV", "DJ", "DZ",
                                        "EG", "EH", "ER", "ET", "GA", "GH", "GM", "GN", "GQ", "GW",
                                        "KE", "KM", "LR", "LS",
                                        "LY", "MA", "MG", "ML", "MR", "MU", "MW", "MZ", "NA", "NE",
                                        "NG", "RE", "RW", "SC",
                                        "SD", "SH", "SL", "SN", "SO", "ST", "SZ", "TD", "TG", "TN",
                                        "TZ", "UG", "YT", "ZA",
                                        "ZM", "ZW"));
    // Continental Asia
    countriesByRegion.put("15",
                          Arrays.asList("AE", "AF", "AM", "AP", "AZ", "BD", "BH", "BN", "BT", "CC",
                                        "CN", "CX", "CY",
                                        "GE", "HK", "ID", "IL", "IN", "IO", "IQ", "IR", "JO", "JP",
                                        "KG", "KH", "KP", "KR",
                                        "KW", "KZ", "LA", "LB", "LK", "MM", "MN", "MO", "MV", "MY",
                                        "NP", "OM", "PH", "PK",
                                        "PS", "QA", "SA", "SG", "SY", "TH", "TJ", "TL", "TM", "TW",
                                        "UZ", "VN", "YE"));
    // Continental Australia
    countriesByRegion.put("16",
                          Arrays.asList("AS", "AU", "CK", "FJ", "FM", "GU", "KI", "MH", "MP", "NC",
                                        "NF", "NR", "NU",
                                        "NZ", "PF", "PG", "PN", "PW", "SB", "TK", "TO", "TV", "UM",
                                        "VU", "WF", "WS"));
    // Continental Antarctica
    countriesByRegion.put("17", Arrays.asList("AQ", "BV", "GS", "HM", "TF"));
    countriesByRegion.put("Fallback", Arrays.asList("@@"));
    countriesByRegion.put("Unknown IP", Arrays.asList("@!"));
    countriesByRegion.put("Anonymous Proxy", Arrays.asList("A1"));
    countriesByRegion.put("Other Country", Arrays.asList("O1"));
    countriesByRegion.put("Satellite Provider", Arrays.asList("A2"));
    return countriesByRegion;
  }
1348226
def references(self, key, value):
    """"""
    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):
        recid = maybe_int(el)
        record = get_record_ref(recid, 'literature')
        rb.set_record(record)

    rb = ReferenceBuilder()
    mapping = [
        ('0', _set_record),
        ('a', rb.add_uid),
        ('b', rb.add_uid),
        ('c', rb.add_collaboration),
        ('e', partial(rb.add_author, role='ed.')),
        ('h', rb.add_refextract_authors_str),
        ('i', rb.add_uid),
        ('k', rb.set_texkey),
        ('m', rb.add_misc),
        ('o', rb.set_label),
        ('p', rb.set_publisher),
        ('q', rb.add_parent_title),
        ('r', rb.add_report_number),
        ('s', rb.set_pubnote),
        ('t', rb.add_title),
        ('x', rb.add_raw_reference),
        ('y', rb.set_year),
    ]

    for field, method in mapping:
        for el in force_list(value.get(field)):
            if el:
                method(el)

    for el in dedupe_list(force_list(value.get('u'))):
        if el:
            rb.add_url(el)

    if _is_curated(value):
        rb.curate()

    if _has_curator_flag(value):
        rb.obj['legacy_curated'] = True

    return rb.obj
607721
def getall(self, key, failobj=None):
        """"""
        if self.mmkeys is None: self._mmInit()
        k = self.mmkeys.get(key)
        if not k: return failobj
        return list(map(self.data.get, k))
852814
def get_coauthors(self):
        """"""
        url = self.xml.find('coredata/link[@rel="coauthor-search"]').get('href')
        xml = download(url=url).text.encode('utf-8')
        xml = ET.fromstring(xml)
        coauthors = []
        N = int(get_encoded_text(xml, 'opensearch:totalResults') or 0)

        AUTHOR = namedtuple('Author',
                            ['name', 'scopus_id', 'affiliation', 'categories'])

        count = 0
        while count < N:
            params = {'start': count, 'count': 25}
            xml = download(url=url, params=params).text.encode('utf-8')
            xml = ET.fromstring(xml)

            for entry in xml.findall('atom:entry', ns):

                given_name = get_encoded_text(entry,
                    'atom:preferred-name/atom:given-name')
                surname = get_encoded_text(entry,
                    'atom:preferred-name/atom:surname')
                coauthor_name = u'{0} {1}'.format(given_name, surname)

                scopus_id = get_encoded_text(entry,
                    'dc:identifier').replace('AUTHOR_ID:', '')

                affiliation = get_encoded_text(entry,
                    'atom:affiliation-current/atom:affiliation-name')

                # get categories for this author
                s = u', '.join(['{0} ({1})'.format(subject.text,
                                                   subject.attrib['frequency'])
                               for subject in
                               entry.findall('atom:subject-area', ns)])

                coauthors += [AUTHOR(coauthor_name, scopus_id, affiliation, s)]
            count += 25

        return coauthors
254359
private static CSLName[] toAuthors(List<Map<String, Object>> authors) {
		CSLName[] result = new CSLName[authors.size()];
		int i = 0;
		for (Map<String, Object> a : authors) {
			CSLNameBuilder builder = new CSLNameBuilder();
			if (a.containsKey(FIELD_FIRSTNAME)) {
				builder.given(strOrNull(a.get(FIELD_FIRSTNAME)));
			}
			if (a.containsKey(FIELD_LASTNAME)) {
				builder.family(strOrNull(a.get(FIELD_LASTNAME)));
			}
			builder.parseNames(true);
			result[i] = builder.build();
			++i;
		}
		return result;
	}