<commit_before>/**
 * @license
 * Copyright 2017 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

foam.INTERFACE({
  refines: 'foam.mlang.F',

  methods: [
    {
      name: 'f',
      args: [
        {
          name: 'obj',
          javaType: 'foam.core.FObject'
        }
      ],
      javaReturns: 'Object'
    }
  ]
});

foam.INTERFACE({
  refines: 'foam.mlang.Expr',

  methods: [
    {
      name: 'partialEval',
      javaReturns: 'foam.mlang.Expr'
    },
    {
      name: 'createStatement',
      javaReturns: 'String'
    },
    {
      name: 'prepareStatement',
      javaReturns: 'void',
      args: [
        {
          name: 'stmt',
          javaType: 'java.sql.PreparedStatement'
        }
      ]
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.ExprProperty',

  properties: [
    ['javaType', 'foam.mlang.Expr'],
    ['javaJSONParser', 'foam.lib.json.ExprParser']
  ]
});


foam.CLASS({
  refines: 'foam.mlang.SinkProperty',

  properties: [
    ['javaType', 'foam.dao.Sink'],
    ['javaJSONParser', 'foam.lib.json.FObjectParser']
  ]
});


foam.INTERFACE({
  refines: 'foam.mlang.predicate.Predicate',

  methods: [
    {
      name: 'f',
      args: [
        {
          name: 'obj',
          javaType: 'foam.core.FObject'
        }
      ],
      javaReturns: 'boolean'
    },
    {
      name: 'createStatement',
      javaReturns: 'String',
      args: [{
        name: 'table',
        javaType: 'String'
      }]
    },
    {
      name: 'prepareStatement',
      args: [
        {
          name: 'stmt',
          javaType: 'java.sql.PreparedStatement'
        }
      ]
    },
    {
      name: 'partialEval',
      javaReturns: 'foam.mlang.predicate.Predicate'
    },
    {
      name: 'toIndex',
      javaSupport: false,
      args: [
        {
          name: 'tail',
          javaType: 'foam.dao.index.Index'
        }
      ],
      javaReturns: 'foam.dao.index.Index'
    },
    {
      name: 'toDisjunctiveNormalForm',
      javaSupport: false,
      javaReturns: 'foam.mlang.predicate.Predicate'
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.PredicateProperty',

  properties: [
    ['javaType', 'foam.mlang.predicate.Predicate']
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.PredicateArray',

  properties: [
    ['javaType', 'foam.mlang.predicate.Predicate[]']
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.AbstractPredicate',

  methods: [
    {
      // TODO: This is a duplicate of the method in Predicate,
      // but it's necessary because when we refine Predicate, it doesn't
      // update classes that copied their axioms in from Predicate as a trait.
      // If we were more careful about the ordering of classes this wouldn't be
      // necessary.
      name: 'f',
      args: [
        {
          name: 'obj',
          javaType: 'foam.core.FObject'
        }
      ],
      javaCode: 'return false;',
      javaReturns: 'boolean'
    },
    {
      // TODO: Same TODO as .f method above
      name: 'toIndex',
      javaSupport: false
    },
    {
      // TODO: Same TODO as .f
      name: 'toDisjunctiveNormalForm',
      javaSupport: false,
      javaReturns: 'foam.mlang.predicate.Predicate'
    },
    {
      name: 'partialEval',
      javaCode: 'return this;',
      javaReturns: 'foam.mlang.predicate.Predicate'
    },
    {
      name: 'toString',
      javaCode: 'return classInfo_.getId();'
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.AbstractExpr',

  methods: [
    {
      name: 'partialEval',
      javaCode: 'return this;',
      // Remove this javaReturns when it is inherited properly. (Traits are fixed).
      javaReturns: 'foam.mlang.Expr'
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.True',

  methods: [
    {
      name: 'f',
      javaCode: 'return true;'
    },
    {
      name: 'createStatement',
      javaReturns: 'String',
      args: [{
        name: 'table',
        javaType : 'String'
      }],
      javaCode: 'return "";'
    },
    {
      name: 'prepareStatement',
      args: [{
        name: 'stmt',
        javaType: 'java.sql.PreparedStatement'
      }],
      javaCode: " return; "
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.False',

  methods: [
    {
      name: 'f',
      javaCode: 'return false;'
    },
    {
      name: 'createStatement',
      javaReturns: 'String',
      args: [{
        name: 'table',
        javaType : 'String'
      }],
      javaCode: 'return "";'
    },
    {
      name: 'prepareStatement',
      args: [{
        name: 'stmt',
        javaType: 'java.sql.PreparedStatement'
      }],
      javaCode: " return; "
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.Or',

  methods: [
    {
      name: 'f',
      javaCode: 'for ( int i = 0 ; i < getArgs().length ; i++ ) {\n'
                + '  if ( getArgs()[i].f(obj) ) return true;\n'
                + '}\n'
                + 'return false;\n'
    },
    {
      name: 'createStatement',
      javaReturns: 'String',
      args: [{
        name: 'table',
        javaType : 'String'
      }],
      javaCode: 'return "";'
    },
    {
      name: 'prepareStatement',
      args: [{
        name: 'stmt',
        javaType: 'java.sql.PreparedStatement'
      }],
      javaCode: " return; "
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.And',

  methods: [
    {
      name: 'f',
      javaCode: 'for ( int i = 0 ; i < getArgs().length ; i++ ) {\n'
                + '  if ( ! getArgs()[i].f(obj) ) return false;\n'
                + '}\n'
                + 'return true;'
    },
    {
      name: 'createStatement',
      javaReturns: 'String',
      args: [{
        name: 'table',
        javaType : 'String'
      }],
      javaCode: 'return "";'
    },
    {
      name: 'prepareStatement',
      args: [{
        name: 'stmt',
        javaType: 'java.sql.PreparedStatement'
      }],
      javaCode: " return; "
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.In',

  methods: [
    {
      name: 'f',
      javaCode:
  `
  Object lhs = getArg1().f(obj);
  // boolean uppercase = lhs.getClass().isEnum(); TODO: Account for ENUMs? (See js)
  Object rhs = getArg2().f(obj);

  if ( rhs instanceof Object[] ) {
    // Checks if rhs array contains the lhs object
    Object[] values = (Object[])rhs;

    for ( int i = 0 ; i < values.length ; i++ ) {
      if ( ( ( (Comparable) lhs ).compareTo( (Comparable) values[i] ) ) == 0 ) {
        return true;
      }
    }
  } else if ( rhs instanceof String ) {
    // Checks if lhs is substring of rhs
    return ( lhs instanceof String ) &&
      ( ( (String) rhs ).contains( (String) lhs ) );
  }

  return false;
  `
    },
    {
      name: 'createStatement',
      javaReturns: 'String',
      args: [{
        name: 'table',
        javaType : 'String'
      }],
      javaCode: 'return "";'
    },
    {
      name: 'prepareStatement',
      args: [{
        name: 'stmt',
        javaType: 'java.sql.PreparedStatement'
      }],
      javaCode: " return; "
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.sink.Map',

  methods: [
    {
      name: 'f',
      args: [
        {
          name: 'obj',
          javaType: 'foam.core.FObject'
        }
      ],
      javaReturns: 'foam.core.FObject',
      javaCode: `return (foam.core.FObject) getArg1().f(obj);`
    },
    {
      name: 'put',
      javaCode: 'getDelegate().put(f(obj), sub);'
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.Contains',

  methods: [
    {
      name: 'f',
      javaCode: `String s1 = (String) getArg1().f(obj);
String s2 = (String) getArg2().f(obj);
return ( s1 != null && s2 != null && s1.contains(s2) );`
    },
    {
      name: 'createStatement',
      javaReturns: 'String',
      args: [{
        // table as method argument because it can't be parametrized into a prepared statement
        name: 'table',
        javaType : 'String'
      }],
      javaCode: 'return "";'
    },
    {
      name: 'prepareStatement',
      args: [{
        name: 'stmt',
        javaType: 'java.sql.PreparedStatement'
      }],
      javaCode: " return; "
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.ContainsIC',

  methods: [
    {
      name: 'f',
      javaCode: `String s1 = (String) getArg1().f(obj);
String s2 = (String) getArg2().f(obj);
return ( s1 != null && s2 != null && s1.toUpperCase().contains(s2.toUpperCase()) );`
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.StartsWith',

  methods: [
    {
      name: 'f',
      javaCode: `
Object arg1 = getArg1().f(obj);
String arg2 = (String) getArg2().f(obj);

if ( arg1 instanceof Object[] ) {
  Object[] values = (Object[]) arg1;
  for ( int i = 0 ; i < values.length ; i++ ) {
    if ( values[i] instanceof String && ((String) values[i]).startsWith(arg2) )
      return true;
  }
} else if ( arg1 instanceof String ) {
  return ((String) arg1).startsWith(arg2);
}
return false;`
    },
    {
      name: 'createStatement',
      javaReturns: 'String',
      args: [{
        name: 'table',
        javaType : 'String'
      }],
      javaCode: `return getArg1().createStatement() + " like '%" + getArg2().createStatement() + "'";`
    },
    {
      name: 'prepareStatement',
      args: [{
        name: 'stmt',
        javaType: 'java.sql.PreparedStatement'
      }],
      javaCode: " return; "
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.StartsWithIC',

  methods: [
    {
      name: 'f',
      javaCode: `
Object arg1 = getArg1().f(obj);
String arg2 = ((String) getArg2().f(obj)).toUpperCase();

if ( arg1 instanceof Object[] ) {
  Object[] values = (Object[]) arg1;
  for ( int i = 0 ; i < values.length ; i++ ) {
    if ( values[i] instanceof String && ((String) values[i]).toUpperCase().startsWith(arg2) )
      return true;
  }
} else if ( arg1 instanceof String ) {
  return ((String) arg1).toUpperCase().startsWith(arg2);<commit_msg>Moved percent sign to end<commit_after>/**
 * @license
 * Copyright 2017 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

foam.INTERFACE({
  refines: 'foam.mlang.F',

  methods: [
    {
      name: 'f',
      args: [
        {
          name: 'obj',
          javaType: 'foam.core.FObject'
        }
      ],
      javaReturns: 'Object'
    }
  ]
});

foam.INTERFACE({
  refines: 'foam.mlang.Expr',

  methods: [
    {
      name: 'partialEval',
      javaReturns: 'foam.mlang.Expr'
    },
    {
      name: 'createStatement',
      javaReturns: 'String'
    },
    {
      name: 'prepareStatement',
      javaReturns: 'void',
      args: [
        {
          name: 'stmt',
          javaType: 'java.sql.PreparedStatement'
        }
      ]
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.ExprProperty',

  properties: [
    ['javaType', 'foam.mlang.Expr'],
    ['javaJSONParser', 'foam.lib.json.ExprParser']
  ]
});


foam.CLASS({
  refines: 'foam.mlang.SinkProperty',

  properties: [
    ['javaType', 'foam.dao.Sink'],
    ['javaJSONParser', 'foam.lib.json.FObjectParser']
  ]
});


foam.INTERFACE({
  refines: 'foam.mlang.predicate.Predicate',

  methods: [
    {
      name: 'f',
      args: [
        {
          name: 'obj',
          javaType: 'foam.core.FObject'
        }
      ],
      javaReturns: 'boolean'
    },
    {
      name: 'createStatement',
      javaReturns: 'String',
      args: [{
        name: 'table',
        javaType: 'String'
      }]
    },
    {
      name: 'prepareStatement',
      args: [
        {
          name: 'stmt',
          javaType: 'java.sql.PreparedStatement'
        }
      ]
    },
    {
      name: 'partialEval',
      javaReturns: 'foam.mlang.predicate.Predicate'
    },
    {
      name: 'toIndex',
      javaSupport: false,
      args: [
        {
          name: 'tail',
          javaType: 'foam.dao.index.Index'
        }
      ],
      javaReturns: 'foam.dao.index.Index'
    },
    {
      name: 'toDisjunctiveNormalForm',
      javaSupport: false,
      javaReturns: 'foam.mlang.predicate.Predicate'
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.PredicateProperty',

  properties: [
    ['javaType', 'foam.mlang.predicate.Predicate']
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.PredicateArray',

  properties: [
    ['javaType', 'foam.mlang.predicate.Predicate[]']
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.AbstractPredicate',

  methods: [
    {
      // TODO: This is a duplicate of the method in Predicate,
      // but it's necessary because when we refine Predicate, it doesn't
      // update classes that copied their axioms in from Predicate as a trait.
      // If we were more careful about the ordering of classes this wouldn't be
      // necessary.
      name: 'f',
      args: [
        {
          name: 'obj',
          javaType: 'foam.core.FObject'
        }
      ],
      javaCode: 'return false;',
      javaReturns: 'boolean'
    },
    {
      // TODO: Same TODO as .f method above
      name: 'toIndex',
      javaSupport: false
    },
    {
      // TODO: Same TODO as .f
      name: 'toDisjunctiveNormalForm',
      javaSupport: false,
      javaReturns: 'foam.mlang.predicate.Predicate'
    },
    {
      name: 'partialEval',
      javaCode: 'return this;',
      javaReturns: 'foam.mlang.predicate.Predicate'
    },
    {
      name: 'toString',
      javaCode: 'return classInfo_.getId();'
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.AbstractExpr',

  methods: [
    {
      name: 'partialEval',
      javaCode: 'return this;',
      // Remove this javaReturns when it is inherited properly. (Traits are fixed).
      javaReturns: 'foam.mlang.Expr'
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.True',

  methods: [
    {
      name: 'f',
      javaCode: 'return true;'
    },
    {
      name: 'createStatement',
      javaReturns: 'String',
      args: [{
        name: 'table',
        javaType : 'String'
      }],
      javaCode: 'return "";'
    },
    {
      name: 'prepareStatement',
      args: [{
        name: 'stmt',
        javaType: 'java.sql.PreparedStatement'
      }],
      javaCode: " return; "
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.False',

  methods: [
    {
      name: 'f',
      javaCode: 'return false;'
    },
    {
      name: 'createStatement',
      javaReturns: 'String',
      args: [{
        name: 'table',
        javaType : 'String'
      }],
      javaCode: 'return "";'
    },
    {
      name: 'prepareStatement',
      args: [{
        name: 'stmt',
        javaType: 'java.sql.PreparedStatement'
      }],
      javaCode: " return; "
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.Or',

  methods: [
    {
      name: 'f',
      javaCode: 'for ( int i = 0 ; i < getArgs().length ; i++ ) {\n'
                + '  if ( getArgs()[i].f(obj) ) return true;\n'
                + '}\n'
                + 'return false;\n'
    },
    {
      name: 'createStatement',
      javaReturns: 'String',
      args: [{
        name: 'table',
        javaType : 'String'
      }],
      javaCode: 'return "";'
    },
    {
      name: 'prepareStatement',
      args: [{
        name: 'stmt',
        javaType: 'java.sql.PreparedStatement'
      }],
      javaCode: " return; "
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.And',

  methods: [
    {
      name: 'f',
      javaCode: 'for ( int i = 0 ; i < getArgs().length ; i++ ) {\n'
                + '  if ( ! getArgs()[i].f(obj) ) return false;\n'
                + '}\n'
                + 'return true;'
    },
    {
      name: 'createStatement',
      javaReturns: 'String',
      args: [{
        name: 'table',
        javaType : 'String'
      }],
      javaCode: 'return "";'
    },
    {
      name: 'prepareStatement',
      args: [{
        name: 'stmt',
        javaType: 'java.sql.PreparedStatement'
      }],
      javaCode: " return; "
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.In',

  methods: [
    {
      name: 'f',
      javaCode:
  `
  Object lhs = getArg1().f(obj);
  // boolean uppercase = lhs.getClass().isEnum(); TODO: Account for ENUMs? (See js)
  Object rhs = getArg2().f(obj);

  if ( rhs instanceof Object[] ) {
    // Checks if rhs array contains the lhs object
    Object[] values = (Object[])rhs;

    for ( int i = 0 ; i < values.length ; i++ ) {
      if ( ( ( (Comparable) lhs ).compareTo( (Comparable) values[i] ) ) == 0 ) {
        return true;
      }
    }
  } else if ( rhs instanceof String ) {
    // Checks if lhs is substring of rhs
    return ( lhs instanceof String ) &&
      ( ( (String) rhs ).contains( (String) lhs ) );
  }

  return false;
  `
    },
    {
      name: 'createStatement',
      javaReturns: 'String',
      args: [{
        name: 'table',
        javaType : 'String'
      }],
      javaCode: 'return "";'
    },
    {
      name: 'prepareStatement',
      args: [{
        name: 'stmt',
        javaType: 'java.sql.PreparedStatement'
      }],
      javaCode: " return; "
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.sink.Map',

  methods: [
    {
      name: 'f',
      args: [
        {
          name: 'obj',
          javaType: 'foam.core.FObject'
        }
      ],
      javaReturns: 'foam.core.FObject',
      javaCode: `return (foam.core.FObject) getArg1().f(obj);`
    },
    {
      name: 'put',
      javaCode: 'getDelegate().put(f(obj), sub);'
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.Contains',

  methods: [
    {
      name: 'f',
      javaCode: `String s1 = (String) getArg1().f(obj);
String s2 = (String) getArg2().f(obj);
return ( s1 != null && s2 != null && s1.contains(s2) );`
    },
    {
      name: 'createStatement',
      javaReturns: 'String',
      args: [{
        // table as method argument because it can't be parametrized into a prepared statement
        name: 'table',
        javaType : 'String'
      }],
      javaCode: 'return "";'
    },
    {
      name: 'prepareStatement',
      args: [{
        name: 'stmt',
        javaType: 'java.sql.PreparedStatement'
      }],
      javaCode: " return; "
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.ContainsIC',

  methods: [
    {
      name: 'f',
      javaCode: `String s1 = (String) getArg1().f(obj);
String s2 = (String) getArg2().f(obj);
return ( s1 != null && s2 != null && s1.toUpperCase().contains(s2.toUpperCase()) );`
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.StartsWith',

  methods: [
    {
      name: 'f',
      javaCode: `
Object arg1 = getArg1().f(obj);
String arg2 = (String) getArg2().f(obj);

if ( arg1 instanceof Object[] ) {
  Object[] values = (Object[]) arg1;
  for ( int i = 0 ; i < values.length ; i++ ) {
    if ( values[i] instanceof String && ((String) values[i]).startsWith(arg2) )
      return true;
  }
} else if ( arg1 instanceof String ) {
  return ((String) arg1).startsWith(arg2);
}
return false;`
    },
    {
      name: 'createStatement',
      javaReturns: 'String',
      args: [{
        name: 'table',
        javaType : 'String'
      }],
      javaCode: `return getArg1().createStatement() + " like '" + getArg2().createStatement() + "%'";`
    },
    {
      name: 'prepareStatement',
      args: [{
        name: 'stmt',
        javaType: 'java.sql.PreparedStatement'
      }],
      javaCode: " return; "
    }
  ]
});


foam.CLASS({
  refines: 'foam.mlang.predicate.StartsWithIC',

  methods: [
    {
      name: 'f',
      javaCode: `
Object arg1 = getArg1().f(obj);
String arg2 = ((String) getArg2().f(obj)).toUpperCase();

if ( arg1 instanceof Object[] ) {
  Object[] values = (Object[]) arg1;
  for ( int i = 0 ; i < values.length ; i++ ) {
    if ( values[i] instanceof String && ((String) values[i]).toUpperCase().startsWith(arg2) )
      return true;
  }
} else if ( arg1 instanceof String ) {
  return ((String) arg1).toUpperCase().startsWith(arg2);
{'fraction_non_alphanumeric': 0.1657475182994084, 'fraction_numerical': 0.005314348741602326, 'mean_word_length': 1.939867354458364, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4010737', 'n_tokens_mistral': 6970, 'n_tokens_neox': 6865, 'n_words': 1385}