def _filter(file_path):
    index = Index()

    for notation, data in parse(file_path):
        if not notation.has_key():
            text = USE_CODE.findall(data['desc'])

            if text:
                match = ''.join(text[0].split())
                match = SCHEME.findall(match)

                if match and is_valid(Notation(match[0])):
                    valid_notation = Notation(match[0])

                    if valid_notation.has_text():
                        new_value = get_bracketed(text[0])
                        old_value = get_bracketed(valid_notation)

                        valid_notation = valid_notation.\
                            replace(old_value[0], new_value[0])

                    data['valid'] = valid_notation
                    index.add(notation, data, select=True)
                    continue

            index.add(notation, data, select=False)

    return index
    def _add_gender(notation, gender, anti=True):
        if anti:
            notation = notation.get_anti()
            gender = get_anti(gender)

        data = converter.index.get(notation)

        if data:
            data['gender'] = Notation(gender)
            converter.index.add(notation, data)

            if not anti and notation.division != 9:
                anti_notation = notation.get_anti()

                if anti_notation not in converter.index and \
                        not anti_notation.has_text():
                    anti_notation = anti_notation.get_parent()

                converter.add(notation, anti_notation)
            else:
                converter.add(notation)
        elif not anti:
            parent = notation.get_anti().get_parent()
            converter.add(notation, parent)

        return converter
示例#3
0
def get():
    def _sort_key(value):
        if value.startswith('rm'):
            return -1, value

        return 0, value

    index = dict()

    file_paths = listdir(FOLDER_PATH)
    file_paths.sort(key=_sort_key)

    for file_path in reversed(file_paths):
        if file_path.startswith(('rm', 'cv')):
            file_path = path.join(FOLDER_PATH, file_path)

            for key, values in parse(file_path):
                values = [Notation(x) for x in values]
                index[Notation(key)] = values

    return index
示例#4
0
def parse(file_path, lang='en', limit=-1, verbose=True):
    notations = set()

    for code, data in _wrapper(file_path, verbose):
        if lang in data['txt'] and lang in data['kw']:
            notation = Notation(code)

            if notation.is_valid() and \
                    notation not in notations:
                data = {
                    'desc': data['txt'][lang],
                    'keywords': data['kw'][lang]
                }

                notations.add(notation)

                yield notation, data

            if isinstance(limit, int) and limit >= 0:
                if len(notations) == limit:
                    break
def _filter(file_path):
    index = Index()

    for notation, data in parse(file_path):
        if notation.division != 3 and not notation.has_key():
            data['names'] = get_names(data, keep_all=False)

            if not (notation.has_text() or notation.depth > 7 or
                    data['desc'].startswith(('other', 'early'))):
                gender = Genderize(data['desc']).code

                if gender:
                    data['gender'] = Notation(gender)
                    index.add(notation, data, select=True)
                    continue

            index.add(notation, data, select=False)

    return index
示例#6
0
def test_get_queue():
    assert Notation('95A1').get_queue() == '1'
示例#7
0
def test_has_queue():
    assert not Notation('95A').has_queue()
    assert Notation('95A1').has_queue()
示例#8
0
def test_get_basic():
    assert Notation('7(+45)').get_basic() == '7'
    assert Notation('11').get_basic() == '11'
示例#9
0
def test_add(data):
    data.add(Notation('13'))
    assert Notation('13') in data
示例#10
0
def test_get_next():
    assert Notation('11').get_next() == Notation('12')
    assert Notation('11II').get_next() == Notation('11KK')

    assert Notation('11H(ANSELM)9').get_next() is None
    assert Notation('11H(ANSELM)').get_next() is None
示例#11
0
def test_get_key():
    assert Notation('7(+45)').get_key() == '45'
示例#12
0
def test_get_digit():
    assert Notation('11H(ANSELM)8').get_digit() == '8'
示例#13
0
def test_has_digit():
    assert not Notation('11H(ANSELM)').has_digit()
    assert Notation('11H(ANSELM)8').has_digit()
示例#14
0
def test_has_text():
    assert Notation('11H(ANSELM)8').has_text()
    assert Notation('95A(...)').has_text()
示例#15
0
def test_get_next(data):
    assert data.get_next(Notation('11')) == Notation('12')
    assert data.get_next(Notation('12')) is None
示例#16
0
def test_get_neighbors(data):
    assert data.get_neighbors(Notation('11')) == [Notation('12')]
示例#17
0
def test_get_children_until(data):
    assert sorted(data.get_children_until(Notation('1'))) == \
           sorted([Notation('11'), Notation('12'), Notation('11K')])
示例#18
0
def test_get_text():
    assert Notation('11H(ANSELM)8').get_text() == 'ANSELM'
示例#19
0
def test_depth():
    assert Notation('11H(ANSELM)8').depth == 6
    assert Notation('7(+45)').depth == 3
示例#20
0
def test_division():
    assert Notation('98').division == 9
示例#21
0
def test_is_valid():
    assert not Notation('11J').is_valid()
    assert Notation('11I').is_valid()
示例#22
0
def test_has_key():
    assert not Notation('7').has_key()
    assert Notation('7(+45)').has_key()
示例#23
0
def test_is_direct_child():
    assert not Notation('11H1').is_direct_child(Notation('11'))
    assert Notation('11H').is_direct_child(Notation('11'))
示例#24
0
def test_get_anti():
    assert Notation('11HH').get_anti() == Notation('11H')
示例#25
0
def test_is_basic():
    assert not Notation('95A(...)').is_basic()
    assert Notation('11H').is_basic()
示例#26
0
def test_get_parents_until():
    assert Notation('11H1').get_parents_until(depth=1) == \
           [Notation('1'), Notation('11'), Notation('11H')]

    assert Notation('11H(ANSELM)').get_parents_until(depth=2) == \
           [Notation('11'), Notation('11H'), Notation('11H(...)')]
示例#27
0
# !/usr/bin/python
# -*- coding: utf-8 -*-

import pytest

from classes.index import Index
from classes.notation import Notation

NOTATIONS = {
    Notation('1'): {
        'desc': 'Religion and Magic'
    },
    Notation('11'): {
        'desc': 'Christian religion'
    },
    Notation('11K'): {
        'desc': 'devil(s) and demon(s)'
    },
    Notation('12'): {
        'desc': 'non-Christian religions'
    }
}


@pytest.fixture()
def data():
    index = Index()

    for key, value in NOTATIONS.items():
        index.add(key, value)