<commit_before>package org.musetest.builtins.value.string;

import org.musetest.builtins.value.*;
import org.musetest.core.*;
import org.musetest.core.events.*;
import org.musetest.core.values.*;
import org.musetest.core.values.descriptor.*;

import java.util.regex.*;

/**
 * @author <NAME> (see LICENSE.txt for license details)
 */
@MuseTypeId("find-nvp-regex")
@MuseValueSourceName("Find NVP by RegEx")
@MuseValueSourceShortDescription("Uses a RegularExpression to find an NVP within a String")
@MuseValueSourceLongDescription("Resolves the RegEx parameter to a string and uses it to search the Target parameter, which is also resolved as a string. Selects 2 capture groups and constructs an NVP (Name Value Pair) from the values. Returns null if not found")
@MuseStringExpressionSupportImplementation(FindNvpByRegexSource.StringExpressionSupport.class)
@MuseSubsourceDescriptor(displayName = "RegEx", description = "Regular Expression to evaluate", type = SubsourceDescriptor.Type.Named, name = FindNvpByRegexSource.REGEX_PARAM)
@MuseSubsourceDescriptor(displayName = "Target", description = "String to search", type = SubsourceDescriptor.Type.Named, name = FindNvpByRegexSource.TARGET_PARAM)
@MuseSubsourceDescriptor(displayName = "Name Group", description = "Index of the capture group containing the name. Default is 1.", type = SubsourceDescriptor.Type.Named, name = FindNvpByRegexSource.NAME_GROUP_PARAM, defaultValue = "1")
@MuseSubsourceDescriptor(displayName = "Value Group", description = "Index of the capture group containing the value. Default is 2.", type = SubsourceDescriptor.Type.Named, name = FindNvpByRegexSource.NAME_GROUP_PARAM, defaultValue = "2")
public class FindNvpByRegexSource extends BaseValueSource
    {
    @SuppressWarnings("unused")  // used via reflection
    public FindNvpByRegexSource(ValueSourceConfiguration config, MuseProject project) throws MuseExecutionError
        {
        super(config, project);
        _regex = getValueSource(config, REGEX_PARAM, true, project);
        _target = getValueSource(config, TARGET_PARAM, true, project);
        _match_index = getValueSource(config, MATCH_INDEX_PARAM, false, project);
        _name_group = getValueSource(config, NAME_GROUP_PARAM, false, project);
        _value_group = getValueSource(config, VALUE_GROUP_PARAM, false, project);
        }

    @Override
    public Object resolveValue(MuseExecutionContext context) throws ValueSourceResolutionError
        {
        String regex = getValue(_regex, context, false, String.class);
        String target = getValue(_target, context, false, String.class);
        long match_index = getValue(_match_index, context, Long.class, 0L);
        long name_group = getValue(_name_group, context, Long.class, 1L);
        long value_group = getValue(_value_group, context, Long.class, 2L);

        Matcher matcher = Pattern.compile(regex).matcher(target);
        int found_index = -1;
        while (found_index < match_index)
            {
            if (matcher.find())
                found_index++;<commit_msg>Add parameter for the match index<commit_after>package org.musetest.builtins.value.string;

import org.musetest.builtins.value.*;
import org.musetest.core.*;
import org.musetest.core.events.*;
import org.musetest.core.values.*;
import org.musetest.core.values.descriptor.*;

import java.util.regex.*;

/**
 * @author <NAME> (see LICENSE.txt for license details)
 */
@MuseTypeId("find-nvp-regex")
@MuseValueSourceName("Find NVP by RegEx")
@MuseValueSourceShortDescription("Uses a RegularExpression to find an NVP within a String")
@MuseValueSourceLongDescription("Resolves the RegEx parameter to a string and uses it to search the Target parameter, which is also resolved as a string. Selects 2 capture groups and constructs an NVP (Name Value Pair) from the values. Returns null if not found")
@MuseStringExpressionSupportImplementation(FindNvpByRegexSource.StringExpressionSupport.class)
@MuseSubsourceDescriptor(displayName = "RegEx", description = "Regular Expression to evaluate", type = SubsourceDescriptor.Type.Named, name = FindNvpByRegexSource.REGEX_PARAM)
@MuseSubsourceDescriptor(displayName = "Target", description = "String to search", type = SubsourceDescriptor.Type.Named, name = FindNvpByRegexSource.TARGET_PARAM)
@MuseSubsourceDescriptor(displayName = "Name Group", description = "Index of the capture group containing the name. Default is 1.", type = SubsourceDescriptor.Type.Named, name = FindNvpByRegexSource.NAME_GROUP_PARAM, defaultValue = "1")
@MuseSubsourceDescriptor(displayName = "Value Group", description = "Index of the capture group containing the value. Default is 2.", type = SubsourceDescriptor.Type.Named, name = FindNvpByRegexSource.NAME_GROUP_PARAM, defaultValue = "2")
@MuseSubsourceDescriptor(displayName = "Match index", description = "Index of the match to create the NVP from. Default is 1.", type = SubsourceDescriptor.Type.Named, name = FindNvpByRegexSource.MATCH_INDEX_PARAM, defaultValue = "1")
public class FindNvpByRegexSource extends BaseValueSource
    {
    @SuppressWarnings("unused")  // used via reflection
    public FindNvpByRegexSource(ValueSourceConfiguration config, MuseProject project) throws MuseExecutionError
        {
        super(config, project);
        _regex = getValueSource(config, REGEX_PARAM, true, project);
        _target = getValueSource(config, TARGET_PARAM, true, project);
        _match_index = getValueSource(config, MATCH_INDEX_PARAM, false, project);
        _name_group = getValueSource(config, NAME_GROUP_PARAM, false, project);
        _value_group = getValueSource(config, VALUE_GROUP_PARAM, false, project);
        }

    @Override
    public Object resolveValue(MuseExecutionContext context) throws ValueSourceResolutionError
        {
        String regex = getValue(_regex, context, false, String.class);
        String target = getValue(_target, context, false, String.class);
        long match_index = getValue(_match_index, context, Long.class, 0L);
        long name_group = getValue(_name_group, context, Long.class, 1L);
        long value_group = getValue(_value_group, context, Long.class, 2L);

        Matcher matcher = Pattern.compile(regex).matcher(target);
        int found_index = -1;
        while (found_index < match_index)
            {
            if (matcher.find())
                found_index++;
{'fraction_non_alphanumeric': 0.09340659340659341, 'fraction_numerical': 0.0031397174254317113, 'mean_word_length': 4.708781362007168, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '3319242', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1733, 'n_words': 492}