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

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

GitHub user okram opened a pull request:

    https://github.com/apache/tinkerpop/pull/729

    TINKERPOP-1632: Create a set of default functions

    https://issues.apache.org/jira/browse/TINKERPOP-1632
    
    This is an implementation of lambda-less math capabilities in Gremlin 
leveraging the String-based calculator model proposed by @twilmes. This model 
deviates from Gremlin's standard function composition and nesting model to 
provide a easy to read "math processor" that leverages Gremlin scopes for data 
access (e.g. path data, map keys, and side-effects). The feature is 
encapsulated in `MathStep` which implements `PathProcessor` and `Scoping`. 
Furthermore, `by()`-modulation is supported. `by()`-modulators are applied in 
the order in which the variable is first used in the equation. Thus:
    
    ```
    g.V().as("a").out("knows").by("b").
      math("b + a").
        by(out().count()).
        by("age")
    ```
    
    In the above: `a` -> `age` and `b` -> `out().count()`. More complex 
examples are provided below:
    
    ```
    gremlin> g = TinkerFactory.createModern().traversal()
    ==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
    gremlin> g.V().as('a').out('knows').as('b').math('a + b').by('age')
    ==>56.0
    ==>61.0
    gremlin> g.V().as('a').out('created').as('b').
    ......1>   math('b + a').
    ......2>     by(both().count().math('_ + 100')).
    ......3>     by('age')
    ==>132.0
    ==>133.0
    ==>135.0
    ==>138.0
    gremlin> g.withSideEffect('x',10).V().values('age').math('_ / x')
    ==>2.9
    ==>2.7
    ==>3.2
    ==>3.5
    gremlin> 
g.withSack(1).V(1).repeat(sack(sum).by(constant(1))).times(10).emit().sack().math('sin
 _')
    ==>0.9092974268256817
    ==>0.1411200080598672
    ==>-0.7568024953079282
    ==>-0.9589242746631385
    ==>-0.27941549819892586
    ==>0.6569865987187891
    ==>0.9893582466233818
    ==>0.4121184852417566
    ==>-0.5440211108893698
    ==>-0.9999902065507035
    ```

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/apache/tinkerpop TINKERPOP-1632

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/tinkerpop/pull/729.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #729
    
----
commit 6f1a1f7028f285c6e45b7e7596320710b91114c5
Author: Marko A. Rodriguez <okramma...@gmail.com>
Date:   2017-10-03T23:37:10Z

    first non-tested implementation of math()-step. It uses the @twilmes model 
which parses a String representation of the expression.

commit 624a8d706e150cc15dc2412d66d3ac9a61b90682
Author: Marko A. Rodriguez <okramma...@gmail.com>
Date:   2017-10-04T16:27:48Z

    I wrote a small parser that is able to extract variables from an exp4j 
equation. So far, it is pretty durable. This is a much cleaner way of 
determining variables than via label, side-effect, and map analysis. However, 
this means that the by()-modulations are with respects to the order in which 
the variables are contained in the equation.

commit c36493b6d66406b0d6b50e6c292e6d43216b4c4c
Author: Marko A. Rodriguez <okramma...@gmail.com>
Date:   2017-10-04T16:42:06Z

    added MathTest to test math() using step labels, side-effects, and implicit 
current -- and with various uses of by()-modulation. This is a really cool step.

commit dfddccaaa85898e046e6b7a5bd81da3d94777d7d
Author: Marko A. Rodriguez <okramma...@gmail.com>
Date:   2017-10-04T17:01:53Z

    added MathStepTest to test hashCode() and the custom variable finder. Found 
a couple of problems in my parser and I fixed them. Forgot to make MathStep a 
PathProcessor so that OLAP is smart about data access. Both OLTP and OLAP tests 
pass.

commit 7217823c3ea73f2d32ffa975e417dcd49d40cbdd
Author: Marko A. Rodriguez <okramma...@gmail.com>
Date:   2017-10-04T17:30:55Z

    added math()-step to the reference docs and updated CHANGELOG and upgrade 
docs.

----


> 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