Warning: session_start(): open(/var/lib/php/sessions/sess_44egv9bd3ptjlq8klvh2lve8pt, 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
!7
concept Rule > ConceptWithGlobalID {
S input, output, variables /* comma-separated */, comment;
sS _fieldOrder = "globalID input output variables comment";
Set vars() { ret asCISet(tok_splitAtComma(variables)); }
}
concept PossibleExample > ConceptWithGlobalID {
Rule rule;
S input, output;
SS mapping;
sS _fieldOrder = "globalID rule input output mapping";
}
concept Input > ConceptWithGlobalID {
S input;
}
p {
db();
indexConceptFields(PossibleExample, 'rule);
indexConceptFieldsCI(Input, 'input, Rule, 'input);
indexConceptFieldsOrdered(Rule, 'globalID);
}
static HCRUD rulesCRUD() {
ret new HCRUD(rawLink("admin"), new HCRUD_Concepts(Rule) {
MapSO itemToMap(Rule r) {
ret mapPlus(super.itemToMap(r), "Possible Examples" := countConcepts(PossibleExample, rule := r));
}
Cl listConcepts() {
ret conceptsSortedByFieldCI(Rule, 'input);
}
}.fieldHelp(variables := "comma-separated")
) {
S renderValue(S field, O value) {
S html = super.renderValue(field, value);
if (eq(field, 'globalID))
ret ahref(rawLink(str(value)), html);
if (eq(field, 'input))
ret b(html);
ret html;
}
};
}
static HCRUD inputsCRUD() {
ret new HCRUD(new HCRUD_Concepts(Input.class));
}
static HCRUD possibleExamplesCRUD() {
ret new HCRUD(new HCRUD_Concepts(PossibleExample.class));
}
set flag NoNanoHTTPD. html {
bool authed = webAuthed(params);
if (empty(uri = dropSlashPrefix(uri)))
ret htitle_h1("Rules")
+ (webAuthed(params) ? p(ahref(rawLink("admin"), "Admin")) : "")
+ ul_noEncode(map(list(Rule), r -> ahref(rawLink(r.globalIDStr()), htmlEncode2(r.input + " => " + r.output))));
// serve rule
if (possibleGlobalID(uri)) {
Rule r = conceptWhere(Rule, globalID := GlobalID(uri));
if (r == null) ret subBot_serve404("Rule not found");
S html = htitle_h1("Rule " + r.globalID)
+ htmlTable2(mapToTwoElementMaps("Field", "Value", litorderedmap("Input" := r.input, "Output" := r.output, "Variables" := r.variables, "Comment" := r.comment)));
html += new HCRUD(new HCRUD_Concepts(PossibleExample.class)
.addFilter(rule := r)).renderTable(false);
//Cl examples = conceptsWhere PossibleExample(rule := r);
//ret possibleExamplesCRUD().render(false, )
ret html;
}
new Matches m;
if (swic_slash(uri, "admin", m))
{
HMultiCRUD multi = new(rawLink("admin"), Rule, Input, PossibleExample) {
HCRUD makeCRUD(S className) {
if (eq(className, "Rule")) ret rulesCRUD();
if (eq(className, "Input")) ret inputsCRUD();
if (eq(className, "PossibleExample")) ret possibleExamplesCRUD();
null;
}
LS naviComponents() {
LS l = super.naviComponents();
if (mutationRights)
l.add(ahref(appendQueryToURL(baseLink, cmd := "processInputs"), "process inputs"));
ret l;
}
} .mainTitle("Rules + Inputs")
.mutationRights(authed);
multi.downloadRights = authed;
if (eqGet(params, cmd := "processInputs")) {
try object checkWebAuthed(params);
time {
for (Input i)
processInput(i.input);
}
ret multi.refreshWithMsgs("Processed " + nInputs(countConcepts(Input)) + " in " + lastTiming() + " ms");
}
ret multi.renderPage(m.rest(), params);
}
ret subBot_serve404();
}
static void processInput(S input) {
for (Rule r) {
new Set found;
for (SS mapping : arbitraryVarsFlexMatchIC_iterator(r.vars(), r.input, input)) {
PossibleExample e = uniq PossibleExample(rule := r, +input, +mapping);
found.add(e);
S output = replaceVars_optRound(r.output, mapping);
output = applyTransformers(output);
cset(found, +output);
}
deleteConcepts(listMinusSet(conceptsWhere(PossibleExample, rule := r), found));
}
}
static IF1> transformers() {
ret mapGet_if1(litmap(nominativ := (IF1) (lambda1 german_toNominativ)));
}
sS applyTransformers(S s) {
pcall {
ret tok_applyCurlyTransformers(transformers(), s);
}
ret s;
}