Ejemplo n.º 1
0
def filter_marcrec(marcrec, main_field=bconfig.CFG_MAIN_FIELD, others=bconfig.CFG_OTHER_FIELDS):
    """Remove the unwanted fields and returns xml."""
    if isinstance(main_field, six.string_types):
        main_field = [main_field]
    if isinstance(others, six.string_types):
        others = [others]
    key_map = ["001"]

    for field in main_field + others:
        tag, ind1, ind2 = _parse_marc_code(field)
        key_map.append(tag)

    return bibrecord.print_rec(marcrec, 1, tags=key_map)
Ejemplo n.º 2
0
def filter_marcrec(marcrec, main_field=bconfig.CFG_MAIN_FIELD,
                   others=bconfig.CFG_OTHER_FIELDS):
    """Remove the unwanted fields and returns xml."""
    if isinstance(main_field, six.string_types):
        main_field = [main_field]
    if isinstance(others, six.string_types):
        others = [others]
    key_map = ['001']

    for field in main_field + others:
        tag, ind1, ind2 = _parse_marc_code(field)
        key_map.append(tag)

    return bibrecord.print_rec(marcrec, 1, tags=key_map)
Ejemplo n.º 3
0
def record_get_keywords(record,
                        main_field=bconfig.CFG_MAIN_FIELD,
                        others=bconfig.CFG_OTHER_FIELDS):
    """Return a dictionary of keywordToken objects from the marc record.

     Weight is set to (0,0) if no weight can be found.

    This will load keywords from the field 653 and 695__a (which are the
    old 'DESY' keywords)

    :param record: int or marc record, if int - marc record is loaded
        from the database. If you pass record instance, keywords are
        extracted from it
    :return: tuple (found, keywords, marcxml)
        found - int indicating how many main_field keywords were found
            the other fields are not counted
        keywords - standard dictionary of keywordToken objects
        marcrec - marc record object loaded with data
    """
    keywords = {}

    if isinstance(main_field, six.string_types):
        main_field = [main_field]
    if isinstance(others, six.string_types):
        others = [others]

    if isinstance(record, int):
        rec = get_record(record)
    else:
        rec = record

    found = 0
    for m_field in main_field:
        tag, ind1, ind2 = _parse_marc_code(m_field)
        for field in rec.get(tag, []):
            keyword = ''
            weight = 0
            type = ''

            for subfield in field[0]:
                if subfield[0] == 'a':
                    keyword = subfield[1]
                elif subfield[0] == 'n':
                    weight = int(subfield[1])
                elif subfield[0] == '9':
                    type = subfield[1]
            if keyword:
                found += 1
                keywords[bor.KeywordToken(keyword, type=type)] = [[
                    (0, 0) for x in range(weight)
                ]]

    if others:
        for field_no in others:
            tag, ind1, ind2 = _parse_marc_code(field_no)
            type = 'f%s' % field_no
            for field in rec.get(tag, []):
                keyword = ''
                for subfield in field[0]:
                    if subfield[0] == 'a':
                        keyword = subfield[1]
                        keywords[bor.KeywordToken(keyword,
                                                  type=type)] = [[(0, 0)]]
                        break

    return found, keywords, rec
Ejemplo n.º 4
0
def record_get_keywords(record, main_field=bconfig.CFG_MAIN_FIELD, others=bconfig.CFG_OTHER_FIELDS):
    """Return a dictionary of keywordToken objects from the marc record.

     Weight is set to (0,0) if no weight can be found.

    This will load keywords from the field 653 and 695__a (which are the
    old 'DESY' keywords)

    :param record: int or marc record, if int - marc record is loaded
        from the database. If you pass record instance, keywords are
        extracted from it
    :return: tuple (found, keywords, marcxml)
        found - int indicating how many main_field keywords were found
            the other fields are not counted
        keywords - standard dictionary of keywordToken objects
        marcrec - marc record object loaded with data
    """
    keywords = {}

    if isinstance(main_field, six.string_types):
        main_field = [main_field]
    if isinstance(others, six.string_types):
        others = [others]

    if isinstance(record, int):
        rec = get_record(record)
    else:
        rec = record

    found = 0
    for m_field in main_field:
        tag, ind1, ind2 = _parse_marc_code(m_field)
        for field in rec.get(tag, []):
            keyword = ""
            weight = 0
            type = ""

            for subfield in field[0]:
                if subfield[0] == "a":
                    keyword = subfield[1]
                elif subfield[0] == "n":
                    weight = int(subfield[1])
                elif subfield[0] == "9":
                    type = subfield[1]
            if keyword:
                found += 1
                keywords[bor.KeywordToken(keyword, type=type)] = [[(0, 0) for x in range(weight)]]

    if others:
        for field_no in others:
            tag, ind1, ind2 = _parse_marc_code(field_no)
            type = "f%s" % field_no
            for field in rec.get(tag, []):
                keyword = ""
                for subfield in field[0]:
                    if subfield[0] == "a":
                        keyword = subfield[1]
                        keywords[bor.KeywordToken(keyword, type=type)] = [[(0, 0)]]
                        break

    return found, keywords, rec