Example #1
0
def convert_roman_numbers_factory(conf):
    """@todo: Docstring for convert_roman_numbers_factory.

    :conf: @todo
    :returns: @todo

    """
    def convert_tokens(tokens):
        tokens = processing.process_text(tokens, convert_numbers)
        return tokens
    # Convert roman numbers
    wiek = [[u'w.'], [u'w', u'.']]
    near_check = check.any_ok([check.after(wiek), check.before(wiek)])
    convert_numbers = converter.convert_to_roman(near_check)
    return convert_tokens
Example #2
0
def convert_tokens_factory(conf):
    """@todo: Docstring for convert_tokens.

    :tokens: @todo
    :conf: @todo
    :returns: @todo

    """
    def convert_tokens(tokens):
        return processing.process_text(tokens, conv)

    convs = []

    # Capitalize surnames
    convs.append(converter.replace(conf.surnames, check.matches_phrase(conf.surnames)))
    near_phrase = dict(conf.names.items() +
                       conf.names_near_surname.items() +
                       conf.salutations.items())
    near_pcheck = check.all_ok([check.matches_phrase(conf.surnames_near_name),
                                check.any_ok([check.after(near_phrase),
                                              check.before(near_phrase)])])
    convs.append(converter.replace(conf.surnames_near_name, near_pcheck))

    # Capitalize names
    convs.append(converter.replace(conf.names, check.matches_phrase(conf.names)))
    near_phrase = dict(conf.surnames.items() +
                       conf.surnames_near_name.items() +
                       conf.salutations.items())
    near_pcheck = check.all_ok([check.matches_phrase(near_phrase),
                                check.any_ok([check.after(near_phrase),
                                              check.before(near_phrase)])])
    convs.append(converter.replace(conf.names_near_surname, near_pcheck))

    # Capitalize salutations
    convs.append(converter.replace(conf.salutations, check.matches_phrase(conf.salutations)))

    # Abbreviate
    convs.append(converter.replace(conf.abbreviations, check.matches_phrase(conf.abbreviations),
                                   junction_words=[u'.']))
    near_number = check.all_ok([check.matches_phrase(conf.abbreviations_near_number),
                                check.any_ok([check.after_number(),
                                              check.before_number()])])
    convs.append(converter.replace(conf.abbreviations_near_number, near_number,
                                   junction_words=[u'.']))

    # Insert symbols
    after_number = check.all_ok([check.matches_phrase(conf.symbols), check.after_number()])
    convs.append(converter.replace(conf.symbols, after_number))

    # Capitalise initilas
    near_surname = check.all_ok([check.is_initials,
                                 check.any_ok([check.after(conf.surnames),
                                               check.before(conf.surnames)])])
    convs.append(converter.make_word_upper(near_surname))

    # Insert commas before some words
    check_comma = check.all_ok([check.matches_phrase(conf.comma_phrases),
                                check.not_check(check.after([[u',']]))])
    convs.append(converter.insert_punct(conf.comma_phrases, u',', check_comma))

    # Convert dates
    convs.append(converter.make_date(conf.months))

    conv = converter.join(convs)
    return convert_tokens