Beispiel #1
0
def check_records(records):
    from invenio.bibrank import ConfigParser, CFG_ETCDIR
    from invenio.bibrank_citation_indexer import get_recids_matching_query
    config = ConfigParser.ConfigParser()
    config.read("%s/bibrank/%s.cfg" % (CFG_ETCDIR, "citation"))
    for record in records:
        for field in record_get_field_instances(record, '999', 'C', '5'):
            subfields = field_get_subfield_instances(field)
            subfields_dict = dict(subfields)
            if '0' not in subfields_dict and 's' in subfields_dict:
                old_pubnote = subfields_dict['s']
                g = RE_BROKEN_PUBNOTES.match(old_pubnote)
                if g:
                    new_pubnote = '%(journal)s,%(volume)s,P%(id)s' % g.groupdict(
                    )
                    subfields.remove(('s', old_pubnote))
                    subfields.append(('s', new_pubnote))
                    recids = get_recids_matching_query(p=new_pubnote,
                                                       f='journal',
                                                       config=config)
                    if len(recids) == 1:
                        recid = recids.pop()
                        subfields.append(('0', str(recid)))
                        record.set_amended(
                            "Pubnote changed from %s to %s and matched a new record %s: Sam is the best, HURRAY!!!"
                            % (old_pubnote, new_pubnote, recid))
                    else:
                        record.set_amended("Pubnote changed from %s to %s" %
                                           (old_pubnote, new_pubnote))
Beispiel #2
0
def check_records(records):
    from invenio.bibrank import ConfigParser, CFG_ETCDIR
    from invenio.bibrank_citation_indexer import get_recids_matching_query
    codens = get_codens()
    config = ConfigParser.ConfigParser()
    config.read("%s/bibrank/%s.cfg" % (CFG_ETCDIR, "citation"))
    for record in records:
        for field in record_get_field_instances(record, '999', 'C', '5'):
            subfields = field_get_subfield_instances(field)
            subfields_dict = dict(subfields)
            if 's' in subfields_dict:
                old_pubnote = subfields_dict['s']
                g = RE_BROKEN_PUBNOTES.match(old_pubnote)
                if g:
                    new_groupdict = g.groupdict()
                    new_groupdict['coden'] = new_groupdict['coden'].upper()
                    if new_groupdict['coden'] in codens:
                        new_groupdict['journal'] = codens[
                            new_groupdict['coden']]
                        new_pubnote = '%(journal)s,%(volume)s,%(id)s' % new_groupdict
                        if new_pubnote == old_pubnote:
                            # No change, e.g. due to JINST == JINST
                            continue
                        subfields.remove(('s', old_pubnote))
                        subfields.append(('s', new_pubnote))
                        recids = get_recids_matching_query(p=new_pubnote,
                                                           f='journal',
                                                           config=config)
                        if len(recids) == 1:
                            recid = recids.pop()
                            if '0' in subfields_dict:
                                if str(recid) == subfields_dict['0']:
                                    record.set_amended(
                                        "Pubnote changed from %s to %s and matched the same known record %s"
                                        % (old_pubnote, new_pubnote, recid))
                                else:
                                    record.warn(
                                        "Pubnote changed from %s to %s and matched a different record %s (instead of %s)!"
                                        % (old_pubnote, new_pubnote, recid,
                                           subfields_dict[0]))
                            else:
                                subfields.append(('0', str(recid)))
                                record.set_amended(
                                    "Pubnote changed from %s to %s and matched a new record %s: Sam is the best, HURRAY!!!"
                                    % (old_pubnote, new_pubnote, recid))
                        else:
                            record.set_amended(
                                "Pubnote changed from %s to %s" %
                                (old_pubnote, new_pubnote))