metron-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmiklavc <...@git.apache.org>
Subject [GitHub] incubator-metron pull request #403: METRON-640: Add a Stellar function to co...
Date Tue, 10 Jan 2017 14:48:23 GMT
Github user mmiklavc commented on a diff in the pull request:

    https://github.com/apache/incubator-metron/pull/403#discussion_r95377207
  
    --- Diff: metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/StringFunctions.java
---
    @@ -284,4 +287,36 @@ private static Object fill(FillDirection direction, Object inputObject,
Object f
         }
         return org.apache.commons.lang.StringUtils.rightPad(input,requiredLength,fill);
       }
    +
    +  @Stellar( namespace="STRING"
    +          , name="ENTROPY"
    +          , description = "Computes the base-2 shannon entropy of a string"
    +          , params = { "input - String" }
    +          , returns = "The base-2 shannon entropy of the string.  The unit of this is
bits."
    +  )
    +  public static class Entropy extends BaseStellarFunction {
    +    @Override
    +    public Object apply(List<Object> strings) {
    +      /*
    +      Shannon entropy is defined as follows:
    +      \Eta(X) = - \sum(p(x_i)*log_2(p(x_i)), i=0, n-1) where x_i are distinct characters
in the string.
    +       */
    +      Map<Character, Integer> frequency = new HashMap<>();
    +      String input = (String)strings.get(0);
    --- End diff --
    
    Super minor, but we should probably catch the no-arg provided NPE scenario and throw new
IllegalStateException showing usage to the user when they fail to provide an arg.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message