<commit_before>import re
import numpy as nm

from base import Struct, IndexedStruct, dict_to_struct, pause, output, copy,\
     import_file, assert_, get_default
from reader import Reader

_required = ['filename_mesh', 'field_[0-9]+|fields',
             'ebc_[0-9]+|ebcs', 'fe', 'equations',
             'region_[0-9]+|regions', 'variable_[0-9]+|variables',
             'material_[0-9]+|materials', 'integral_[0-9]+|integrals',
             'solver_[0-9]+|solvers']
_other = ['epbc_[0-9]+|epbcs', 'lcbc_[0-9]+|lcbcs', 'nbc_[0-9]+|nbcs',
          'ic_[0-9]+|ics', 'options']

##
# c: 19.02.2008, r: 19.02.2008
def get_standard_keywords():
    return copy( _required ), copy( _other )

##
# c: 10.04.2008, r: 10.04.2008
def tuple_to_conf( name, vals, order ):
    conf = Struct( name = name )
    for ii, key in enumerate( order ):
        setattr( conf, key, vals[ii] )
    return conf

##
# Short syntax: key is suffixed with '__<number>' to prevent collisions with
# long syntax keys -> both cases can be used in a single input.
def transform_variables( adict ):
    d2 = {}
    for ii, (key, conf) in enumerate( adict.iteritems() ):
        if isinstance( conf, tuple ):
            c2 = tuple_to_conf( key, conf, ['kind', 'field'] )
            if len( conf ) >= 3:
                kind = c2.kind.split()[0]
                if kind == 'unknown':
                    c2.order = conf[2]
                elif kind == 'test':
                    c2.dual = conf[2]
                elif kind == 'parameter':
                    c2.like = conf[2]
                if len( conf ) == 4:
                    c2.history = conf[3]
            d2['variable_%s__%d' % (c2.name, ii)] = c2
        else:
            c2 = transform_to_struct_1( conf )
            d2['variable_'+c2.name] = c2
    return d2

def transform_conditions( adict, prefix ):
    d2 = {}
    for ii, (key, conf) in enumerate( adict.iteritems() ):
        if isinstance( conf, tuple ):
            c2 = tuple_to_conf( key, conf, ['region', 'dofs'] )
            if len( conf ) == 3:
                c2.filename = conf[2]
            d2['%s_%s__%d' % (prefix, c2.name, ii)] = c2
        else:
            c2 = transform_to_struct_1( conf )
            d2['%s_%s' % (prefix, c2.name)] = c2
    return d2
    
def transform_ebcs( adict ):
    return transform_conditions( adict, 'ebc' )

def transform_ics( adict ):
    return transform_conditions( adict, 'ic' )

def transform_lcbcs( adict ):
    return transform_conditions( adict, 'lcbc' )

def transform_regions( adict ):
    d2 = {}
    for ii, (key, conf) in enumerate( adict.iteritems() ):
        if isinstance( conf, tuple ):
            c2 = tuple_to_conf( key, conf, ['select', 'flags'] )
            for flag, val in c2.flags.iteritems():
                setattr( c2, flag, val )
            delattr( c2, 'flags' )
            d2['region_%s__%d' % (c2.name, ii)] = c2
        else:
            c2 = transform_to_struct_1( conf )
            d2['region_'+c2.name] = c2
    return d2

def transform_integrals( adict ):
    d2 = {}
    for ii, (key, conf) in enumerate( adict.iteritems() ):
        if isinstance( conf, tuple ):
            c2 = tuple_to_conf( key, conf, ['kind', 'quadrature'] )
            d2['integral_%s__%d' % (c2.name, ii)] = c2
        else:
            c2 = transform_to_struct_1( conf )
            d2['integral_'+c2.name] = c2
    return d2

def transform_fields( adict ):
    dtypes = {'real' : nm.float64, 'complex' : nm.complex128}
    d2 = {}
    for ii, (key, conf) in enumerate( adict.iteritems() ):
        if isinstance( conf, tuple ):
            c2 = tuple_to_conf( key, conf, ['dim', 'type', 'domain','bases'] )
            setattr( c2, 'dtype', dtypes[c2.type] )
            delattr( c2, 'type' )
            d2['field_%s__%d' % (c2.name, ii)] = c2
        else:
            c2 = transform_to_struct_1( conf )
            d2['field_'+c2.name] = c2
    return d2

def transform_materials( adict ):
    d2 = {}
    for ii, (key, conf) in enumerate( adict.iteritems() ):
        if isinstance( conf, tuple ):
            c2 = tuple_to_conf( key, conf, ['mode', 'region', 'params'] )
            dpar = {}
            dpar['name'] = key
            dpar['mode'] = c2.mode
            dpar['region'] = c2.region
            dpar.update( c2.params )
            d2['material_%s__%d' % (c2.name, ii)] = dpar
        else:
            d2['material_'+conf['name']] = conf
    return d2
<commit_msg>fixed type specification in long field definition<commit_after>import re
import numpy as nm

from base import Struct, IndexedStruct, dict_to_struct, pause, output, copy,\
     import_file, assert_, get_default
from reader import Reader

_required = ['filename_mesh', 'field_[0-9]+|fields',
             'ebc_[0-9]+|ebcs', 'fe', 'equations',
             'region_[0-9]+|regions', 'variable_[0-9]+|variables',
             'material_[0-9]+|materials', 'integral_[0-9]+|integrals',
             'solver_[0-9]+|solvers']
_other = ['epbc_[0-9]+|epbcs', 'lcbc_[0-9]+|lcbcs', 'nbc_[0-9]+|nbcs',
          'ic_[0-9]+|ics', 'options']

##
# c: 19.02.2008, r: 19.02.2008
def get_standard_keywords():
    return copy( _required ), copy( _other )

##
# c: 10.04.2008, r: 10.04.2008
def tuple_to_conf( name, vals, order ):
    conf = Struct( name = name )
    for ii, key in enumerate( order ):
        setattr( conf, key, vals[ii] )
    return conf

##
# Short syntax: key is suffixed with '__<number>' to prevent collisions with
# long syntax keys -> both cases can be used in a single input.
def transform_variables( adict ):
    d2 = {}
    for ii, (key, conf) in enumerate( adict.iteritems() ):
        if isinstance( conf, tuple ):
            c2 = tuple_to_conf( key, conf, ['kind', 'field'] )
            if len( conf ) >= 3:
                kind = c2.kind.split()[0]
                if kind == 'unknown':
                    c2.order = conf[2]
                elif kind == 'test':
                    c2.dual = conf[2]
                elif kind == 'parameter':
                    c2.like = conf[2]
                if len( conf ) == 4:
                    c2.history = conf[3]
            d2['variable_%s__%d' % (c2.name, ii)] = c2
        else:
            c2 = transform_to_struct_1( conf )
            d2['variable_'+c2.name] = c2
    return d2

def transform_conditions( adict, prefix ):
    d2 = {}
    for ii, (key, conf) in enumerate( adict.iteritems() ):
        if isinstance( conf, tuple ):
            c2 = tuple_to_conf( key, conf, ['region', 'dofs'] )
            if len( conf ) == 3:
                c2.filename = conf[2]
            d2['%s_%s__%d' % (prefix, c2.name, ii)] = c2
        else:
            c2 = transform_to_struct_1( conf )
            d2['%s_%s' % (prefix, c2.name)] = c2
    return d2
    
def transform_ebcs( adict ):
    return transform_conditions( adict, 'ebc' )

def transform_ics( adict ):
    return transform_conditions( adict, 'ic' )

def transform_lcbcs( adict ):
    return transform_conditions( adict, 'lcbc' )

def transform_regions( adict ):
    d2 = {}
    for ii, (key, conf) in enumerate( adict.iteritems() ):
        if isinstance( conf, tuple ):
            c2 = tuple_to_conf( key, conf, ['select', 'flags'] )
            for flag, val in c2.flags.iteritems():
                setattr( c2, flag, val )
            delattr( c2, 'flags' )
            d2['region_%s__%d' % (c2.name, ii)] = c2
        else:
            c2 = transform_to_struct_1( conf )
            d2['region_'+c2.name] = c2
    return d2

def transform_integrals( adict ):
    d2 = {}
    for ii, (key, conf) in enumerate( adict.iteritems() ):
        if isinstance( conf, tuple ):
            c2 = tuple_to_conf( key, conf, ['kind', 'quadrature'] )
            d2['integral_%s__%d' % (c2.name, ii)] = c2
        else:
            c2 = transform_to_struct_1( conf )
            d2['integral_'+c2.name] = c2
    return d2

def transform_fields( adict ):
    dtypes = {'real' : nm.float64, 'complex' : nm.complex128}
    d2 = {}
    for ii, (key, conf) in enumerate( adict.iteritems() ):
        if isinstance( conf, tuple ):
            c2 = tuple_to_conf( key, conf, ['dim', 'type', 'domain','bases'] )
            setattr( c2, 'dtype', dtypes[c2.type] )
            d2['field_%s__%d' % (c2.name, ii)] = c2
        else:
            c2 = transform_to_struct_1( conf )
            c2.set_default_attr('type', 'real')
            setattr( c2, 'dtype', dtypes[c2.type] )
            d2['field_'+c2.name] = c2
    return d2

def transform_materials( adict ):
    d2 = {}
    for ii, (key, conf) in enumerate( adict.iteritems() ):
        if isinstance( conf, tuple ):
            c2 = tuple_to_conf( key, conf, ['mode', 'region', 'params'] )
            dpar = {}
            dpar['name'] = key
            dpar['mode'] = c2.mode
            dpar['region'] = c2.region
            dpar.update( c2.params )
            d2['material_%s__%d' % (c2.name, ii)] = dpar
        else:
            d2['material_'+conf['name']] = conf
    return d2

{'fraction_non_alphanumeric': 0.1498443752779013, 'fraction_numerical': 0.03223654957759004, 'mean_word_length': 2.064373297002725, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6674467', 'n_tokens_mistral': 3182, 'n_tokens_neox': 3059, 'n_words': 781}