Warning: session_start(): open(/var/lib/php/sessions/sess_c7vff137c049t7e65i1m8v3tql, 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
sclass BEACalculations {
GazelleBEA mod;
*(GazelleBEA *mod) {}
void reactAllInputsWithSomePatterns() {
for (BEAObject input : mod.beaObjectsOfType("input")) {
new ReactInputWithSomePatterns r;
r.input = input;
r.ccOut = db_mainConcepts();
r.max = 10;
r.start();
stepAllWithTimeout(10.0, r);
}
}
class ReactInputWithSomePatterns implements Steppable {
BEAObject input;
Concepts ccOut;
int max = 3, n;
Iterator patterns;
void start {
n = countConceptsWhereIC(ccOut, BEAObject, +input, type := "match");
patterns = iterator(sortByConceptID(conceptsWhereIC BEAObject(type := "Pattern")));
}
public bool step() {
if (n >= max) false;
if (!patterns.hasNext()) false;
if (reactInputWithPattern(input, patterns.next(), ccOut) != null)
++n;
true;
}
}
SS matchInputWithPattern(BEAObject input, BEAObject pattern) {
S pat = getString text(pattern);
S text = getString text(input);
ret flexMatchAngleBracketVarsIC_honorPunctuation_first(pat, text);
//ret flexMatchAngleBracketVarsIC_first(pat, text);
}
BEAObject reactInputWithPattern(BEAObject input, BEAObject pattern, Concepts ccOut) {
SS mapping = matchInputWithPattern(input, pattern);
//printVars_str("reactInputWithPattern", +input, +pattern, +mapping);
if (mapping == null) null;
ret cnew(ccOut, BEAObject,
type := "Match",
+input,
+pattern,
+mapping);
}
O serveAnalyzeInput(GazelleBEA.Req req) {
new Concepts ccOut;
BEAObject input = getConcept BEAObject(parseLong(req.get("id")));
if (input == null)
input = cnew(ccOut, BEAObject, type := "Input", text := req.get("q"));
S text = getString text(input);
new ReactInputWithSomePatterns r;
r.input = input;
r.ccOut = ccOut;
r.max = 1000;
r.start();
stepAllWithTimeout(10.0, r);
L matches = conceptsWhereIC(ccOut, BEAObject, type := "Match");
ret h1_title("Analyze Input")
+ p("Input: " + b(htmlEncode(text)))
+ p(empty(matches) ? "No matches" : "Matches")
+ ul_htmlEncode(matches);
}
O serveQueryPage(GazelleBEA.Req req) {
S q = req.get("q"), algorithm = req.get("algorithm");
Map> algorithms = litorderedmap(
"Reverse input (test algorithm)" := (IF0) () -> new ReverseInput,
"Timeout test" := (IF0) () -> new TimeoutTest,
);
S output = empty(algorithm) ? null : doAlgorithm(algorithms, algorithm, q);
ret hcenter3(
htitle_h2("Gazelle BEA Query")
+ hform(p("Query: " + htextfield(+q, style := "width: 300px; text-align: center") + " Algorithm: " + hselect_list(keys(algorithms), algorithm, name := "algorithm") + " " + hbutton("Go"))))
+ (output == null ? "" : h3("Output by" + algorithm) + output);
}
S doAlgorithm(Map> algorithms, S algorithm, S q) {
StringBufferWithMaxSize out = new(100000);
IF0 algo = mapGet(algorithms, algorithm);
if (algo == null)
out.append("Algorithm not found: " + algorithm);
else {
if (isB(evalWithTimeout(10.0, r {
Algorithm alg = algo!;
alg.q = q;
alg.out = out;
alg.run();
})))
out.append("\n[algorithm timeout]");
}
ret str(out);
}
abstract sclass Algorithm implements Runnable {
S q;
Appendable out;
void append(S s) ctex {
out.append(s);
}
}
sclass ReverseInput extends Algorithm {
run { append(reversed(q)); }
}
sclass TimeoutTest extends Algorithm {
run { sleepSeconds(120); }
}
}