예제 #1
0
파일: utils.py 프로젝트: Theer108/invenio
def crossref_normalize_name(record):
    """
    Changes the format of author's name (often with initials) to the proper,
    unified one, using bibauthor_name_utils tools
    @return: changed record
    """
    # pattern for removing the spaces between two initials
    pattern_initials = '([A-Z]\\.)\\s([A-Z]\\.)'
    # first, change the main author
    for field in record_get_field_instances(record, '100'):
        main_author = field[0][0][1]
        new_author = create_normalized_name(split_name_parts(main_author))
        # remove spaces between initials
        # two iterations are required
        for _ in range(2):
            new_author = re.sub(pattern_initials, r'\g<1>\g<2>', new_author)
        position = field[4]
        record_modify_subfield(rec=record, tag='100', subfield_code='a',
        value=new_author, subfield_position=0, field_position_global=position)

    # then, change additional authors
    for field in record_get_field_instances(record, '700'):
        author = field[0][0][1]
        new_author = create_normalized_name(split_name_parts(author))
        for _ in range(2):
            new_author = re.sub(pattern_initials, r'\g<1>\g<2>', new_author)
        position = field[4]
        record_modify_subfield(rec=record, tag='700', subfield_code='a',
            value=new_author, subfield_position=0, field_position_global=position)
예제 #2
0
파일: utils.py 프로젝트: SCOAP3/invenio
def translate_fieldvalues_from_latex(record, tag, code='', encoding='utf-8'):
    """
    Given a record and field tag, this function will modify the record by
    translating the subfield values of found fields from LaTeX to chosen
    encoding for all the subfields with given code (or all if no code is given).

    :param record: record to modify, in BibRec style structure
    :type record: dict

    :param tag: tag of fields to modify
    :type tag: string

    :param code: restrict the translation to a given subfield code
    :type code: string

    :param encoding: scharacter encoding for the new value. Defaults to UTF-8.
    :type encoding: string
    """
    field_list = record_get_field_instances(record, tag)
    for field in field_list:
        subfields = field[0]
        subfield_index = 0
        for subfield_code, subfield_value in subfields:
            if code == '' or subfield_code == code:
                newvalue = translate_latex2unicode(
                    subfield_value
                ).encode(encoding)
                record_modify_subfield(record, tag, subfield_code, newvalue,
                                       subfield_index,
                                       field_position_global=field[4])
            subfield_index += 1
예제 #3
0
def crossref_normalize_name(record):
    """
    Changes the format of author's name (often with initials) to the proper,
    unified one, using bibauthor_name_utils tools
    @return: changed record
    """
    # pattern for removing the spaces between two initials
    pattern_initials = '([A-Z]\\.)\\s([A-Z]\\.)'
    # first, change the main author
    for field in record_get_field_instances(record, '100'):
        main_author = field[0][0][1]
        new_author = create_normalized_name(split_name_parts(main_author))
        # remove spaces between initials
        # two iterations are required
        for _ in range(2):
            new_author = re.sub(pattern_initials, r'\g<1>\g<2>', new_author)
        position = field[4]
        record_modify_subfield(rec=record, tag='100', subfield_code='a',
        value=new_author, subfield_position=0, field_position_global=position)

    # then, change additional authors
    for field in record_get_field_instances(record, '700'):
        author = field[0][0][1]
        new_author = create_normalized_name(split_name_parts(author))
        for _ in range(2):
            new_author = re.sub(pattern_initials, r'\g<1>\g<2>', new_author)
        position = field[4]
        record_modify_subfield(rec=record, tag='700', subfield_code='a',
            value=new_author, subfield_position=0, field_position_global=position)
예제 #4
0
def translate_fieldvalues_from_latex(record, tag, code='', encoding='utf-8'):
    """
    Given a record and field tag, this function will modify the record by
    translating the subfield values of found fields from LaTeX to chosen
    encoding for all the subfields with given code (or all if no code is given).

    :param record: record to modify, in BibRec style structure
    :type record: dict

    :param tag: tag of fields to modify
    :type tag: string

    :param code: restrict the translation to a given subfield code
    :type code: string

    :param encoding: scharacter encoding for the new value. Defaults to UTF-8.
    :type encoding: string
    """
    field_list = record_get_field_instances(record, tag)
    for field in field_list:
        subfields = field[0]
        subfield_index = 0
        for subfield_code, subfield_value in subfields:
            if code == '' or subfield_code == code:
                newvalue = translate_latex2unicode(subfield_value).encode(
                    encoding)
                record_modify_subfield(record,
                                       tag,
                                       subfield_code,
                                       newvalue,
                                       subfield_index,
                                       field_position_global=field[4])
            subfield_index += 1
예제 #5
0
파일: utils.py 프로젝트: mhellmic/b2share
def crossref_translate_title(record):
    """
    Convert the record's title to the Inspire specific abbreviation
    of the title (using JOURNALS knowledge base)
    @return: changed record
    """
    # probably there is only one 773 field
    # but just in case let's treat it as a list
    for field in record_get_field_instances(record, '773'):
        title = field[0][0][1]
        new_title = get_kbr_values("JOURNALS", title, searchtype='e')
        if new_title:
            # returned value is a list, and we need only the first value
            new_title = new_title[0][0]
            position = field[4]
            record_modify_subfield(rec=record, tag='773', subfield_code='p', \
            value=new_title, subfield_position=0, field_position_global=position)
예제 #6
0
def crossref_translate_title(record):
    """
    Convert the record's title to the Inspire specific abbreviation
    of the title (using JOURNALS knowledge base)
    @return: changed record
    """
    # probably there is only one 773 field
    # but just in case let's treat it as a list
    for field in record_get_field_instances(record, '773'):
        title = field[0][0][1]
        new_title = get_kbr_values("JOURNALS", title, searchtype='e')
        if new_title:
            # returned value is a list, and we need only the first value
            new_title = new_title[0][0]
            position = field[4]
            record_modify_subfield(rec=record, tag='773', subfield_code='p',
                                   value=new_title, subfield_position=0,
                                   field_position_global=position)
예제 #7
0
파일: engine.py 프로젝트: mhellmic/b2share
 def process_field(self, record, tag, field_number):
     """@see: BaseSubfieldCommand.process_field"""
     action = lambda record, tag, field_number, subfield_index: \
                 bibrecord.record_modify_subfield(record, tag,
                                                  self._subfield,
                                                  self._value,
                                                  subfield_index,
                                   field_position_global=field_number)
     self._perform_on_all_matching_subfields(record,
                                             tag,
                                             field_number,
                                             action)
예제 #8
0
파일: engine.py 프로젝트: mhellmic/b2share
 def replace_text(record, tag, field_number, subfield_index):
     """Method for replacing the text, performed on
     all the matching fields."""
     #get the field value
     field_value = ""
     for field in record[tag]:
         if field[4] == field_number:
             subfields = field[0]
             (field_code, field_value) = subfields[subfield_index]
     replace_string = re.escape(self._value)
     for val in self._additional_values:
         replace_string += "|" + re.escape(val)
     #replace text
     new_value = re.sub(replace_string, self._new_value, field_value)
     #update the subfield if needed
     if new_value != field_value:
         bibrecord.record_modify_subfield(record, tag,
                                         self._subfield, new_value,
                                         subfield_index,
                                         field_position_global=field_number)
     else:
         #No modification ocurred, update modification counter
         self._modifications -= 1