示例#1
0
def est_smooth_kernel(txt):

    # Initialize FWHM
    kernels = []

    ctxt = re.sub(r'[():=]', '', txt)

    for ptn in smooth_spatial_ptn:

        matches = rex_flex(ptn, ctxt, re.finditer)

        for match in matches:

            kernel_str = match.groupdict()['kernel']

            # Handle ...
            six_match = re.search('(\d+?)6(\d+?)6(\d+)', kernel_str)
            if six_match:
                if len(set(six_match.groups())) == 1:
                    kernel_str = six_match.groups()[-1]

            # Skip if match preceded by number; prevents matches on input like
            # "6 .5 mm fwhm"
            context_back, _ = rex_ctx(match, ctxt, nchar_pre=10, nchar_post=0)
            before_group = context_back.replace(match.group(), '')
            if re.search(r'[.\d]\s+$', before_group):
                continue

            # Skip if not float
            try:
                kernel = float(kernel_str)
            except (ValueError, TypeError):
                continue

            # Skip if implausible
            if kernel > MAX_FWHM:
                continue

            context, span = rex_ctx(match, ctxt)
            group = match.group()
            kernels.append({
                'value': kernel,
                'context': context,
                'group': group,
                'span': span,
            })

    return kernels
示例#2
0
def est_smooth_kernel(txt):

    # Initialize FWHM
    kernels = []

    ctxt = re.sub(r'[():=]', '', txt)

    for ptn in smooth_spatial_ptn:

        matches = rex_flex(ptn, ctxt, re.finditer)

        for match in matches:

            kernel_str = match.groupdict()['kernel']

            # Handle ...
            six_match = re.search('(\d+?)6(\d+?)6(\d+)', kernel_str)
            if six_match:
                if len(set(six_match.groups())) == 1:
                    kernel_str = six_match.groups()[-1]

            # Skip if match preceded by number; prevents matches on input like
            # "6 .5 mm fwhm"
            context_back, _ = rex_ctx(match, ctxt, nchar_pre=10, nchar_post=0)
            before_group = context_back.replace(match.group(), '')
            if re.search(r'[.\d]\s+$', before_group):
                continue

            # Skip if not float
            try:
                kernel = float(kernel_str)
            except (ValueError, TypeError):
                continue

            # Skip if implausible
            if kernel > MAX_FWHM:
                continue

            context, span = rex_ctx(match, ctxt)
            group = match.group()
            kernels.append({
                'value': kernel,
                'context': context,
                'group': group,
                'span': span,
            })

    return kernels
示例#3
0
def est_field_strength(txt):

    fields = []

    for ptn in field_ptn:

        matches = rex_flex(ptn, txt, fun=re.finditer)

        for match in matches:

            short_context, _ = rex_ctx(match=match, txt=txt, nchar=50)

            if not re.search(mag_ptn, short_context, re.I):
                continue

            # Skip if significance test; easy to confuse with e.g.
            # "3.0 T, p < 0.05"
            post_context, _ = rex_ctx(match, txt, nchar_pre=0, nchar_post=50)
            if rex_flex(sig_ptn, post_context):
                continue

            field_str = match.groupdict()['field']

            # Try to cast field strength to float
            try:
                field = float(field_str)
            except (ValueError, TypeError):
                continue

            if MIN_FIELD_STRENGTH <= field <= MAX_FIELD_STRENGTH:

                context, span = rex_ctx(match, txt)
                group = match.group()

                fields.append({
                    'value': field,
                    'context': context,
                    'group': group,
                    'span': span,
                })

    return fields
示例#4
0
def est_field_strength(txt):

    fields = []

    for ptn in field_ptn:

        matches = rex_flex(ptn, txt, fun=re.finditer)

        for match in matches:

            short_context, _ = rex_ctx(match=match, txt=txt, nchar=50)

            if not re.search(mag_ptn, short_context, re.I):
                continue

            # Skip if significance test; easy to confuse with e.g.
            # "3.0 T, p < 0.05"
            post_context, _ = rex_ctx(match, txt, nchar_pre=0, nchar_post=50)
            if rex_flex(sig_ptn, post_context):
                continue

            field_str = match.groupdict()['field']

            # Try to cast field strength to float
            try:
                field = float(field_str)
            except (ValueError, TypeError):
                continue

            if MIN_FIELD_STRENGTH <= field <= MAX_FIELD_STRENGTH:

                context, span = rex_ctx(match, txt)
                group = match.group()

                fields.append({
                    'value': field,
                    'context': context,
                    'group': group,
                    'span': span,
                })

    return fields