Exemplo n.º 1
0
def flatten(items, seqtypes=(list, tuple)):
    """
    Convert an arbitrarily deep nested list into a single flat list.

    DEPRECATED IN FAVOUR OF PLUGIN_UTILS VERSION
    """
    return plugin_utils.flatten(items, seqtypes)
Exemplo n.º 2
0
def test_flatten(mydata, myexpected):
    """
    Unit test for flatten() utility function.
    """
    data = mydata
    expected = myexpected
    actual = plugin_utils.flatten(data)
    assert actual == expected
Exemplo n.º 3
0
def test_flatten(mydata, myexpected):
    """
    Unit test for flatten() utility function.
    """
    data = mydata
    expected = myexpected
    actual = plugin_utils.flatten(data)
    assert actual == expected
Exemplo n.º 4
0
    def get_version_info(current_version):
        for version in info['version']:
            if version['attributes']['title'] == current_version:
                    curv = version
                    vlang = curv['attributes']['language']
                    levels = curv['organisation_levels']
        mslist = flatten([[to_unicode(k.strip()) for k, c in v.iteritems()
                           if c['attributes']['show'] == 'yes']
                          for v in curv['manuscripts']])

        return curv, vlang, levels, mslist
Exemplo n.º 5
0
    def get_version_info(current_version):
        for version in info['version']:
            if version['attributes']['title'] == current_version:
                    curv = version
                    vlang = curv['attributes']['language']
                    levels = curv['organisation_levels']
        mslist = flatten([[to_unicode(k.strip()) for k, c in v.iteritems()
                           if c['attributes']['show'] == 'yes']
                          for v in curv['manuscripts']])

        return curv, vlang, levels, mslist
Exemplo n.º 6
0
def gather_word_forms():
    """
    Return a list of all strings satisfying the supplied regex.

    The fieldnames argument should be a list, so that multiple target fields
    can be searched at once.

    The optional 'unique' keyword argument determines whether duplicates will
    be removed from the list. (Defaults to True.)

    The optional 'filterfunc' keyword argument allows a function to be passed
    which which will be used to alter the gathered strings. This alteration will
    happen before duplicate values are removed. So, for example, the strings
    can be normalized for case or accent characters if those variations are
    not significant.
    """

    items = []
    db = current.db
    x = ['πιλ', 'βοδυ', 'μειδ', 'νηλ', 'ἰλ', 'σαγγ', 'ἁμ', 'ἱτ', 'ἑλπ', 'ἑλω', 'ο',
         'βοτ', 'ὁλ', 'ὁγ', 'παθ', 'τιψ', 'β', 'σωλ', 'κορπ', 'ὡλ', 'κατς', 'γγς',
         'μωλτεγγ', 'δεκ', 'φιξ', 'βαλ', 'διλ', 'δαξ', 'δρομα', 'δακ', 'δαγ', 'ἁγ',
         'λοξ', 'δυδ', 'βωθ', 'ὐψ', 'καν', 'καβ', 'ὀτ', 'βαδ', 'μωστ', 'μοισδ',
         'μιλ', 'βελ', 'ἑδ', 'θοτ', 'κιλ', 'κρω', 'βοχ', 'ω', 'μεντ', 'ἁτ', 'νεατ',
         'σπηρ', 'βοδι', 'πιτ', 'βονδ', 'ἁρδ', 'δοκς', 'μελτ', 'βεδ', 'μαλ', 'δατς',
         'σωπ', 'α', 'πενσιλ', 'κς', 'δεκς', 'αριας', 'βαγγ', 'σετ', 'βρουμ', 'ἀδ',
         'πωλ', 'δατ', 'ἁγγ', 'πραυδ', 'αὐτης', 'νειλ', 'σογγ', 'ζαπ', 'κλαδ',
         'νιτ', 'φαξ', 'βολ', 'κεπτ', 'μοιστ', 'ἁμερ', 'τουνα', 'προγγ', 'τ',
         'κλυν', 'λοβ', 'πλειαρ', 'κροπ', 'βανδ', 'μωλτεν', 'υτ', 'κοτ', 'κοπ',
         'ἀτ', 'φυξ', 'ὡλι', 'μυτ', 'θατ', 'δοτ', 'βικς', 'ἁμαρ', 'λωφερ', 'δοκ',
         'ταπ', 'ἀβωδ', 'ὑτος', 'λωφρ', 'ἁμρ', 'ροκ', 'πς', 'βαδυ', 'οὐψ', 'πραγγ',
         'σπειρ', 'ἀγγλ', 'σλαψ', 'πλαυ', 'δραμα', 'φοξ', 'ἱτεδ', 'ὁτ', 'δογ',
         'δολ', 'ρω', 'δοξ', 'ὗτος', 'μιτ', 'αὑ', 'ἱτς', 'μωλτ', 'βατ', 'βαχ',
         'βικ', 'μιαλ', 'μολ', 'μιελ', 'κον', 'μωισδ', 'κραπ', 'καπ', 'ὑπ', 'ἀγκλ',
         'λιξ', 'ρωλ', 'λαβ', 'ὀδ', 'λαξ', 'δοτς', 'ἀνκλ', 'ρακ', 'πεγ', 'τυνα',
         'βρυμ', 'καρπ', 'βρεδ', 'κιπ', 'μηδ', 'δαλ', 'βετ', 'διπ', 'κλιν', 'πετ',
         'βαδι', 'λικς', 'δακς', 'πς', 'ὑπ', 'κς', 'α', 'ος', 'μιτ', 'βρεδ', 'ί',
         'ο', 'νεατ', 'δι', 'Ω', 'τ', 'υτ', 'η', 'ον', 'β', 'α', 'δεξ', 'παι']
    x = [makeutf8(word) for word in x]

    form = SQLFORM.factory(Field('search_table', default='steps',
                                 writable=False),
                           Field('search_field',
                                 requires=IS_IN_SET(['prompt',
                                                     'readable_response'])),
                           Field('write_table', default='word_forms',
                                 writable=False),
                           Field('write_field', default='word_form',
                                 writable=False),
                           Field('unique', 'boolean', default=True),
                           Field('testing', 'boolean', default=True),
                           Field('new', 'boolean', default=True))
    form.vars.search_table = 'steps'
    form.vars.write_table = 'word_forms'
    form.vars.write_field = 'word_form'

    if form.process().accepted:
        vv = form.vars
        filter_func = eval(vv.filter_func) if vv.filter_func else None
        trans_func = eval(vv.trans_func) if vv.trans_func else None

        rows = db(db[vv.search_table].id > 0).select()
        for r in rows:
            items.append(r[vv['search_field']])

        ptrn = re.compile(u'[\u0370-\u03FF\u1F00-\u1FFF]+', flags=re.U)
        items = flatten([re.findall(ptrn, makeutf8(i)) for i in items])
        normalizer = GreekNormalizer()
        items = [normalizer.normalize(i) for i in items]
        if vv.unique:
            items = list(set(items))
        items = [i.lower() for i in items if i not in x]

        if vv.new:
            existing = [makeutf8(r['word_form']) for r in
                        db(db.word_forms.id > 0).select(db.word_forms.word_form)]
            items = [i for i in items if i not in existing
                     and i.capitalize() not in existing
                     and i.lower() not in existing]
        if vv.testing:
            pass
            response.flash = 'Success, but nothing written to database.'
        else:
            newdata = [{'word_form': item} for item in items]
            rowcount = db.word_forms.bulk_insert(newdata)
            response.flash = 'Success. Added', len(rowcount), 'new word forms.'

    elif form.errors:
        items = BEAUTIFY(form.errors)

    return {'form': form, 'items': items}