Warning: session_start(): open(/var/lib/php/sessions/sess_hpnd4k5l824ktoh20lc7sn4s0j, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
/*
Input:
123 is a number
blubb is not a number
5$"%! is not a number
45 is a number
task 1: tokenize well (in this case, ignore quotes)
task 2: discover patterns "* is a number" and "* is not a number"
task 3: call pattern 1 positive, pattern 2 negative
task 4: make set of positive/negative example strings for argument
task 5a: learn description for positive examples, output new examples
task 5b: learn description for negative examples, output new examples
Generates new examples for numbers, e.g.:
351 is a number
73 is a number
*/
cprint {
S input = autoUnindent_mls([[
123 is a number
blubb is not a number
5$"%! is not a number
45 is a number
]]);
S output;
transient L someFunctions = ll(
f isDigit,
f isLetter,
f isLetterOrDigit,
f isSpace);
visual jvsplit(jhsplit(dm_textAreaAsSection input(), dm_textAreaAsSection output()), super);
start { dm_onFieldChangeAndNow input(r calc); }
void calc {
// task 1: tokenize well (in this case, ignore quotes)
ITokenizer tokenizer = lambda1 splitAtSpaceTokenizer;
LLS tokenizedInput = map(s -> simpleSpacesAndTrim(tokenizer.tokenize(s)), tlft(input));
pnlStruct(+tokenizedInput);
// task 2: discover patterns "* is a number" and "* is not a number"
Set patterns = asSet(findOneArgumentPatterns(tokenizedInput));
assertEquals(2, l(patterns));
print(+patterns);
// task 3: make set of positive/negative example strings for argument
Map examples = mapToValues_linkedHashMap(patterns, pat ->
mapNotNulls(tok -> firstMatch(getFlexMatchIC(pat, tok)), tokenizedInput));
print(+examples);
// task 4: make theories
replace Xmp with L.
Map> examplesAsLists = mapValues(l -> lambdaMap characters(l), examples);
print(examplesAsLists);
//examplesAsLists = reverseKeys(examplesAsLists); // test reversing to see if theory gets reversed
L posExamples = firstValue(examplesAsLists), negExamples = secondValue(examplesAsLists);
// for functions that are applicable to the elements of the examples:
new LinkedHashSet> theories;
for (O function : concatAsOrderedSet(lambdaMap plusNegation(someFunctions))) {
//if (!functionCallableOnAll_nonSynthetic(function, concatLists(values(examplesAsLists)))) continue;
print("Testing function " + function);
theories.add(new AllElementsSatisfy(function));
theories.add(new AnyElementSatisfies(function));
}
theories.addAll(concatLists(lambdaMap theoryPlusInverse(theories)));
pnl(theories);
// test theories
Map, PosNeg> theoryResults = mapToValues(theories, theory ->
PosNeg(mapToValues(trueFalseMap(posExamples, negExamples), (example, x) ->
theory.check(example) == x)));
pnl(theoryResults);
// make new examples
replace Theory with ITheoryOn.
new LS newStatements;
L perfectTheories = sortByMetaTransformerStructureComplexity(keysWhereValue(theoryResults, pn -> pn.perfect()));
print(+perfectTheories);
newStatements.addAll(makeExamplesFor(perfectTheories, posExamples, firstKey(examplesAsLists)));
// perfect theories for negative examples
L antiPerfectTheories = sortByMetaTransformerStructureComplexity(keysWhereValue(theoryResults, pn -> pn.antiPerfect()));
print(+antiPerfectTheories);
newStatements.addAll(makeExamplesFor(antiPerfectTheories, negExamples, secondKey(examplesAsLists)));
setField(output := lines(newStatements));
}
LS makeExamplesFor(L>> theories, Cl> examples, S pattern) {
new LS out;
IntRange sizeRange = sizeRangeOfCollections(examples);
print(+sizeRange);
for (ITheoryOn> t : theories)
if (t cast AllElementsSatisfy) {
IF0 generator = predicateToGenerator(t.pred);
if (generator == null) continue with print("No generator for " + t.pred);
repeat 3 {
S example = charactersToString(repF(random(sizeRange), generator));
print("> ", addAndReturn(out, format_noQuote(pattern, example)));
}
}
ret out;
}
IF0 predicateToGenerator(O f) {
ret () -> (Char) random(filter(f, printableASCIICharsList()));
}
}