<commit_before>package com.tinkerpop.gremlin.functions;

import com.tinkerpop.gremlin.FunctionHelper;
import com.tinkerpop.gremlin.GremlinFunctions;
import com.tinkerpop.gremlin.statements.EvaluationException;
import org.apache.commons.jxpath.ExpressionContext;
import org.apache.commons.jxpath.Function;

import java.util.Map;

/**
 * @author <NAME> (http://markorodriguez.com)
 * @version 0.1
 */
public class IncrementValueFunction implements Function {

    public static final String FUNCTION_NAME = "incr-value";

    public Boolean invoke(ExpressionContext context, Object[] parameters) {
        Object[] objects = FunctionHelper.nodeSetConversion(parameters);
        if (null != objects && objects.length == 2 && objects[0] instanceof Map && objects[1] instanceof Number) {
            System.out.println(context.getContextNodePointer().getValue());
            incrValue((Map) objects[0], context.getContextNodePointer().getValue(), (Number) objects[1]);
            return Boolean.TRUE;

        }
        throw EvaluationException.createException(FunctionHelper.makeFunctionName(GremlinFunctions.NAMESPACE_PREFIX, FUNCTION_NAME), EvaluationException.EvaluationErrorType.UNSUPPORTED_PARAMETERS);

    }

    private static void incrValue(Map map, Object key, Number amount) {
        Object value = map.get(key);
        if (value != null && value instanceof Number) {
            map.put(key, ((Number) value).doubleValue() + amount.doubleValue());
        } else {
            map.put(key, amount.doubleValue());
        }
    }
}<commit_msg>in a bit of pickle with some gremlin behavior on in-line path functions. there is an elegant solution, but I need to rest before I get back at it. Im hungry and tired.<commit_after>package com.tinkerpop.gremlin.functions;

import com.tinkerpop.gremlin.FunctionHelper;
import com.tinkerpop.gremlin.GremlinFunctions;
import com.tinkerpop.gremlin.statements.EvaluationException;
import org.apache.commons.jxpath.ExpressionContext;
import org.apache.commons.jxpath.Function;

import java.util.Map;

/**
 * @author <NAME> (http://markorodriguez.com)
 * @version 0.1
 */
public class IncrementValueFunction implements Function {

    public static final String FUNCTION_NAME = "incr-value";

    public Boolean invoke(ExpressionContext context, Object[] parameters) {
        Object[] objects = FunctionHelper.nodeSetConversion(parameters);
        if (null != objects && objects.length == 2 && objects[0] instanceof Map && objects[1] instanceof Number) {
            //System.out.println(context.getContextNodePointer().getValue());
            incrValue((Map) objects[0], context.getContextNodePointer().getValue(), (Number) objects[1]);
            return Boolean.TRUE;

        }
        throw EvaluationException.createException(FunctionHelper.makeFunctionName(GremlinFunctions.NAMESPACE_PREFIX, FUNCTION_NAME), EvaluationException.EvaluationErrorType.UNSUPPORTED_PARAMETERS);

    }

    private static void incrValue(Map map, Object key, Number amount) {
        Object value = map.get(key);
        if (value != null && value instanceof Number) {
            map.put(key, ((Number) value).doubleValue() + amount.doubleValue());
        } else {
            map.put(key, amount.doubleValue());
        }
    }
}
{'fraction_non_alphanumeric': 0.11230110159118727, 'fraction_numerical': 0.004283965728274173, 'mean_word_length': 3.842962962962963, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1222614', 'n_tokens_mistral': 912, 'n_tokens_neox': 871, 'n_words': 206}