[ 
https://issues.apache.org/jira/browse/TINKERPOP-1632?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16191816#comment-16191816
 ] 

ASF GitHub Bot commented on TINKERPOP-1632:
-------------------------------------------

Github user dkuppitz commented on the issue:

    https://github.com/apache/tinkerpop/pull/729
  
    You can add a static compiled regex pattern:
    
    ```
    private static final Pattern EQUATION_PATTERN = 
Pattern.compile("\\b(?!abs|acos|asin|atan|cbrt|ceil|cos|cosh|exp|floor|log|log10|log2|sin|sinh|sqrt|tan|tanh|signum)(_|([A-Za-z][A-Za-z0-9]*))\\b");
    ```
    
    ...then `getVariables()` can be as simple as:
    
    ```
    protected static final Set<String> getVariables(final String equation) {
        final Matcher matcher = EQUATION_PATTERN.matcher(equation);
        final Set<String> variables = new LinkedHashSet<>();
        while (matcher.find()) {
            variables.add(matcher.group());
        }
        return variables;
    }
    ```
    
    And perhaps to increase the readability and maintainability, we should do 
something like this:
    
    ```
    private static final String[] FUNCTIONS = new String[] {
            "abs", "acos", "asin", "atan",
            "cbrt", "ceil", "cos", "cosh",
            "exp",
            "floor",
            "log", "log10", "log2",
            "signum", "sin", "sinh", "sqrt",
            "tan", "tanh"
        };
    
    private static final Pattern EQUATION_PATTERN = Pattern.compile("\\b(?!" +
            String.join("|", FUNCTIONS) + ")(_|([A-Za-z][A-Za-z0-9]*))\\b");
    ```


> Create a set of default functions
> ---------------------------------
>
>                 Key: TINKERPOP-1632
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-1632
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: process
>    Affects Versions: 3.3.0
>            Reporter: Daniel Kuppitz
>
> We already have a a set of default BiFunctions / operators, that are not 
> treated as lambdas. We should also have a bunch of simple functions, that can 
> then be used in {{map()}} or {{sack()}} and that can be serialized as 
> bytecode. For example:
> {noformat}
> ...map(sqrt)
> ...map(log)
> ...sack(sigmoid)     // compute sigmoid of the current sack and update the 
> sack
> ...sack(cos).by("x") // compute the cosine of the current element's "x" and 
> assign / overwrite the current sack value
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to