コード例 #1
0
def main():
    verbose = '-v' in sys.argv

    recids = perform_request_search(p='-035:spirestex -035:inspiretex', cc='HEP')
    print "Found %s records to assign texkeys" % len(recids)
    processed = []
    to_process = []
    for count, recid in enumerate(recids):
        if count % 300 == 0:
            print 'done %s of %s' % (count, len(recids))

        if verbose:
            print "processing ", recid

        # Check that the record does not have already a texkey
        has_texkey = False
        recstruct = get_record(recid)
        for instance in record_get_field_instances(recstruct, tag="035", ind1="", ind2=""):
            try:
                provenance = field_get_subfield_values(instance, "9")[0]
            except IndexError:
                provenance = ""
            try:
                value = field_get_subfield_values(instance, "z")[0]
            except IndexError:
                value = ""
            provenances = ["SPIRESTeX", "INSPIRETeX"]
            if provenance in provenances and value:
                has_texkey = True
                print "INFO: Record %s has already texkey %s" % (recid, value)

        if not has_texkey:
            TexKeySeq = TexkeySeq()
            new_texkey = ""
            try:
                new_texkey = TexKeySeq.next_value(recid)
            except TexkeyNoAuthorError:
                print "WARNING: Record %s has no first author or collaboration" % recid
                continue
            xml = create_xml(recid, new_texkey)
            processed.append(recid)
            to_process.append(xml)

        if len(to_process) == 500:
            process_chunk(to_process)
            to_process = []

    if to_process:
        process_chunk(to_process)

    # Finally, index all the records processed
    if processed:
        submit_bibindex_task(processed)
コード例 #2
0
ファイル: texkey.py プロジェクト: chokribr/inveniotest
def check_record(record, texkey_field="035__a", extra_subfields=()):
    """
    Add a tex key to a record, checking that it doesn't have one already.
    """
    tag = texkey_field[:3]
    ind1, ind2, subfield = texkey_field[3:]

    provenances = list(record.iterfield(texkey_field[:5] + "9"))
    if len(provenances) and provenances[0][1] in ("SPIRESTeX", "INSPIRETeX"):
        for _, val in record.iterfield(texkey_field[:5] + "z"):
            if val:
                return  # Record already has a texkey

    if len(list(record.iterfield(texkey_field))) == 0:
        try:
            texkey = TexkeySeq().next_value(bibrecord=record)
        except TexkeyNoAuthorError:
            record.warn("No first author or collaboration")
            return
        subfields_to_add = [(subfield, texkey)] + map(tuple, extra_subfields)
        record_add_field(record,
                         tag=tag,
                         ind1=ind1,
                         ind2=ind2,
                         subfields=subfields_to_add)
        record.set_amended("Added Tex key '%s' to field %s" %
                           (texkey, texkey_field))
コード例 #3
0
    def test_get_next_texkey_no_author(self):
        """ Generate an error while getting a texkey with no author """

        texkey_seq = TexkeySeq()
        self.assertRaises(TexkeyNoAuthorError,
                          texkey_seq.next_value,
                          xml_record=get_sample_texkey(3))
コード例 #4
0
ファイル: texkey.py プロジェクト: tsgit/invenio
def check_record(record,
                 texkey_field="035__a",
                 provenances=None,
                 extra_subfields=None):
    """
    Add a texkey to a record, checking that it doesn't have one already.
    """

    if provenances is None:
        provenances = ["SPIRESTeX", "INSPIRETeX"]

    for provenance in provenances:
        for _, val in record.iterfield(texkey_field,
                                       subfield_filter=('9', provenance)):
            if len(val) > 6:  # texkey composition <name>:\d{4}<randchars>
                return

    try:
        texkey = TexkeySeq().next_value(bibrecord=record)
    except TexkeyNoAuthorError:
        record.warn("No first author or collaboration")
        return
    except TexkeyNoYearError:
        record.warn("No suitable year/date info")
        return

    if extra_subfields is None:
        extra_subfields = [('9', 'INSPIRETeX')]

    tag = texkey_field[:3]
    ind1, ind2, subfield = texkey_field[3:]
    subfields_to_add = [(subfield, texkey)] + map(tuple, extra_subfields)
    record_add_field(record,
                     tag=tag,
                     ind1=ind1,
                     ind2=ind2,
                     subfields=subfields_to_add)
    record.set_amended("Added Tex key '%s' to field %s" %
                       (texkey, texkey_field))
コード例 #5
0
    def test_get_next_texkey3(self):
        """ Generate the third texkey """

        texkey_seq = TexkeySeq()
        self.texkey3 = texkey_seq.next_value(xml_record=get_sample_texkey(2))
        self.assertEqual(self.texkey3[:-3], 'ATLAS:2012')
コード例 #6
0
    def test_get_next_texkey2(self):
        """ Generate the second texkey """

        texkey_seq = TexkeySeq()
        self.texkey2 = texkey_seq.next_value(xml_record=get_sample_texkey(1))
        self.assertEqual(self.texkey2[:-3], 'Broekhoven-Fiene:2012')
コード例 #7
0
    def test_get_next_texkey1(self):
        """ Generate the first texkey """

        texkey_seq = TexkeySeq()
        self.texkey1 = texkey_seq.next_value(xml_record=get_sample_texkey(0))
        self.assertEqual(self.texkey1[:-3], 'Boyle:2012')
コード例 #8
0
    def test_get_next_texkey3(self):
        """ Generate the third texkey """

        texkey_seq = TexkeySeq()
        self.texkey3 = texkey_seq.next_value(xml_record=get_sample_texkey(2))
        self.assertEqual(self.texkey3[:-3], 'ATLAS:2012')
コード例 #9
0
    def test_get_next_texkey2(self):
        """ Generate the second texkey """

        texkey_seq = TexkeySeq()
        self.texkey2 = texkey_seq.next_value(xml_record=get_sample_texkey(1))
        self.assertEqual(self.texkey2[:-3], 'Broekhoven-Fiene:2012')
コード例 #10
0
    def test_get_next_texkey1(self):
        """ Generate the first texkey """

        texkey_seq = TexkeySeq()
        self.texkey1 = texkey_seq.next_value(xml_record=get_sample_texkey(0))
        self.assertEqual(self.texkey1[:-3], 'Boyle:2012')