import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.*;
import java.math.*;
import java.text.SimpleDateFormat;
import java.text.NumberFormat;
class main {
static void test_ai_findNounPlusVar() {
testFunctionValues(s -> getVars(ai_findNounPlusVar((String) s)),
"if a snippet contains token X, it also contains token Y",
ll(pair("token", "X"), pair("token", "Y")));
}
// params = input, output, input, output, ...
static void testFunctionValues(Object function, Object... params) {
for (int i = 0; i+1 < l(params); i += 2) {
Object in = params[i], expected = params[i+1];
testFunctionValue(function, in, expected);
}
}
static void testFunctionValues(IF1 function, Object... params) {
testFunctionValues((Object) function, params);
}
static > List getVars(Iterable l) {
return lambdaMap(__18 -> getVar(__18),l);
}
// e.g. "if a snippet contains token X, it also contains token Y";
static List>> ai_findNounPlusVar(String s) {
Set vars = ai_mostLikelyVariables(s);
List>> out = new ArrayList();
List> nouns = pwt_filter(__19 -> isNoun(__19),pwt_initial(s, 2));
print("nouns", nouns);
for (ParsedWithTokens noun : nouns)
for (ParsedWithTokens var : pwt_stepRight_filter(1, x -> contains(vars, x), noun))
out.add(pwt_combine(pair(noun.get(), var.get()), noun, var));
return out;
}
static List ll(A... a) {
ArrayList l = new ArrayList(a.length);
if (a != null) for (A x : a) l.add(x);
return l;
}
static Pair pair(A a, B b) {
return new Pair(a, b);
}
static Pair pair(A a) {
return new Pair(a, a);
}
static int l(Object[] a) { return a == null ? 0 : a.length; }
static int l(boolean[] a) { return a == null ? 0 : a.length; }
static int l(byte[] a) { return a == null ? 0 : a.length; }
static int l(short[] a) { return a == null ? 0 : a.length; }
static int l(long[] a) { return a == null ? 0 : a.length; }
static int l(int[] a) { return a == null ? 0 : a.length; }
static int l(float[] a) { return a == null ? 0 : a.length; }
static int l(double[] a) { return a == null ? 0 : a.length; }
static int l(char[] a) { return a == null ? 0 : a.length; }
static int l(Collection c) { return c == null ? 0 : c.size(); }
static int l(Iterator i) { return iteratorCount_int_close(i); } // consumes the iterator && closes it if possible
static int l(Map m) { return m == null ? 0 : m.size(); }
static int l(CharSequence s) { return s == null ? 0 : s.length(); }
static long l(File f) { return f == null ? 0 : f.length(); }
static int l(Object o) {
return o == null ? 0
: o instanceof String ? l((String) o)
: o instanceof Map ? l((Map) o)
: o instanceof Collection ? l((Collection) o)
: o instanceof Object[] ? l((Object[]) o)
: o instanceof boolean[] ? l((boolean[]) o)
: o instanceof byte[] ? l((byte[]) o)
: o instanceof char[] ? l((char[]) o)
: o instanceof short[] ? l((short[]) o)
: o instanceof int[] ? l((int[]) o)
: o instanceof float[] ? l((float[]) o)
: o instanceof double[] ? l((double[]) o)
: o instanceof long[] ? l((long[]) o)
: (Integer) call(o, "size");
}
static void testFunctionValue(Object function, Object in, Object expected) {
String strIn = str(in);
String msg = function + "(" + strIn + ")";
print(msg);
assertEqualsVerbose(strIn, expected, callF(function, in));
}
static List lambdaMap(IF1 f, Iterable l) {
return map(l, f);
}
static List lambdaMap(IF1 f, A[] l) {
return map(l, f);
}
static A getVar(IF0 v) {
return v == null ? null : v.get();
}
static Set ai_mostLikelyVariables(String s) {
Set set = asSet(javaTok_cached(s));
if (contains(set, "X")) return intersectSetWithItems(set, "X", "Y", "Z");
if (any("isDollarVar",set)) return filterSet(__20 -> isDollarVar(__20),set);
if (contains(set, "*")) return litset("*");
return null;
}
static List> pwt_filter(IF1 f, Iterable> l) {
return filter(p -> f.get(p.get()), l);
}
static Object _override_isNoun;
static boolean isNoun(String s) { if (_override_isNoun != null) return (boolean) callF(_override_isNoun, s);
if (ai_enabled() && has(s, "is", "a noun")) return true;
return isSingularNoun(s) || isPluralNoun(s) || mechCISetContains("Nouns", s);
}
static List> pwt_initial(String s, int maxTokens) {
return pwt_initial(javaTok(s), maxTokens);
}
// maxTokens = how many code tokens per range (max)
static List> pwt_initial(List tok, int maxTokens) {
return concatMap(lai_codeTokens(tok), lai -> pwt_followingTokens(1, maxTokens, lai));
}
static volatile StringBuffer local_log = new StringBuffer(); // not redirected
static volatile Appendable print_log = local_log; // might be redirected, e.g. to main bot
// in bytes - will cut to half that
static volatile int print_log_max = 1024*1024;
static volatile int local_log_max = 100*1024;
static boolean print_silent = false; // total mute if set
static Object print_byThread_lock = new Object();
static volatile ThreadLocal