sclass BEACalculations { GazelleBEA mod; *(GazelleBEA *mod) {} transient int liveOutputDelay = 1000; transient double algoTimeout = 30.0; 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 text = getString text(input); ret matchInputWithPattern(text, pattern); } SS matchInputWithPattern(S text, BEAObject pattern) { S pat = getString text(pattern); bool punctuationOnly = isTrue_getOpt punctuationOnly(pattern); if (pattern.typeIs("Syntactic Pattern")) ret matchInputWithSyntacticPattern(text, pat, punctuationOnly); else if (eqic_gen(pattern~.subType, "PhraseCache")) ret phraseCache(pat, text) ? litmap() : null; else ret matchInputWithPattern(text, pat, punctuationOnly); } SS matchInputWithSyntacticPattern(S text, S pat, bool punctuationOnly default false) { pat = starsToAngleBracketedNumbers(pat); ret matchInputWithPattern(text, pat, punctuationOnly); } SS matchInputWithPattern(S text, S pat, bool punctuationOnly default false) { SS mapping = flexMatchAngleBracketVarsIC_honorPunctuation_first(pat, text); if (mapping != null || punctuationOnly) ret mapping; ret flexMatchAngleBracketVarsIC_first(pat, text); } BEAObject reactInputWithPattern(BEAObject input, BEAObject pattern, Concepts ccOut default db_mainConcepts()) { if (input == null || pattern == null) null; 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"); bool dontRun = eq(req.get("dontRun"), "1"); bool liveOutput = eq(req.get("liveOutput"), "1"); if (liveOutput) req.noSpam(); if (eqic(algorithm, "process input")) algorithm = "Process new input v3"; //if (liveOutput) ret jsonEncode(litmap(answer := "Live output demo: " + htmlEncode2(q))); Map> algorithms = litorderedmap( "Process new input v3" := (IF0) () -> new ProcessNewInput_v3, "Process new input v2" := (IF0) () -> new ProcessNewInput_v2, "Process new input" := (IF0) () -> new ProcessNewInput, "Run pattern" := (IF0) () -> new RunPattern, "Find rewrites for match" := (IF0) () -> new FindRewrites, "Reverse input (test algorithm)" := (IF0) () -> new ReverseInput, "Timeout test" := (IF0) () -> new TimeoutTest, "Syntactic pattern from input" := (IF0) () -> new SyntacticPatternFromInput, "Apply all text functions" := (IF0) () -> new ApplyTextFunctions, "Find Path" := (IF0) () -> new FindPath, "Execute text query" := (IF0) () -> new ExecuteTextQuery, "Make syntactic patterns for all patterns in DB" := (IF0) () -> new MakeSyntacticPatterns, "Input summary" := (IF0) () -> new InputSummary, // add algorithms here ); S output = empty(algorithm) || dontRun ? null : doAlgorithm(algorithms, algorithm, q, liveOutput); if (liveOutput) ret jsonEncode(litorderedmap(answer := output)); S right = mod.html_loggedIn(); S centered = htitle_h2(ahref(mod.baseLink + "/", "Gazelle") + " Query" + htmlEncode2((empty(q) ? "" : ": " + q) + appendSquareBracketed(algorithm))) + hscript(replaceVars([[ var sugLoading = false, sugTriggerAgain = false; function sugTrigger() { console.log("sugTrigger"); if (sugLoading) { sugTriggerAgain = true; return; } // get form data as JSON var data = { "liveOutput" : "1", "q": $("textarea[name=q]").val(), "algorithm": $("select[name=algorithm]").val() }; const url = "/query"; console.log("Loading " + url + " with " + data); sugLoading = true; $.post(url, data, function(result) { console.log("Suggestor result: " + result); const answer = !result ? "" : JSON.parse(result).answer; if (answer) { $("#liveResult .sectionContents").html(answer); $("#liveResult").show(); } else $("#liveResult").hide(); //$("#suggestorResult").html(answer ? "Suggestor says: " + answer : ""); } ).always(function() { console.log("sug loading done"); setTimeout(function() { sugLoading = false; if (sugTriggerAgain) { sugTriggerAgain = false; sugTrigger(); } }, liveOutputDelay); }); } $(document).ready(function() { $("textarea[name=q], input[name=q], select[name=algorithm]").on('input propertychange change', sugTrigger); sugTrigger(); }); ]], +liveOutputDelay)) + hform(p("Query (Ctrl+Enter): " + htextarea(q, id := "mainInput", name := "q", class := "auto-expand", style := "max-height: 10em; width: 300px; vertical-align: top", onkeydown := jquery_submitFormOnCtrlEnter()) + hjs([[$(document).ready(function() { autoExpandTextArea(document.getElementById("mainInput")); });]]) //+ htextfield(+q, style := "width: 300px; text-align: center", autofocus := true) + "   Algorithm: " + hselect_list(keys(algorithms), algorithm, name := "algorithm") + "   " + hbutton("Go"))); ret hhtml(hhead( hmobilefix() + hsansserif() + loadJQuery2() + hjs_autoExpandingTextAreas() + mod.webSocketHeadStuff(req) + hNotificationPopups()) + hbody( div_alignRight(right) + div_center(centered) + htitledSectionWithDiv("Live Result", "", id := "liveResult", style := "display: none", innerDivStyle := "max-height: 150px; overflow: auto") + (output == null ? "" : h3(algorithm) + output))); } S doAlgorithm(Map> algorithms, S algorithm, S q, bool liveMode) { GazelleBEA.Req req = mod.currentReq!; StringBufferWithMaxSize out = new(1000000); // TODO: make sure HTML tags are closed properly IF0 algo = lookupPossiblyCI(algorithms, algorithm); if (algo == null) out.append("Algorithm not found: " + algorithm); else { if (isB(evalWithTimeout(algoTimeout, r { temp mod.enter(); temp tempSetTL(mod.currentReq, req); Algorithm alg = algo!; alg.liveMode = liveMode; alg.q = q; alg.out = out; alg.runIt(); }))) out.append("\n[algorithm timeout]"); } ret str(out); } abstract class Algorithm implements Runnable { S q; Appendable out; //Appendable outPrio = new StringBufferWithMaxSize(10000); bool liveMode; Concepts localConcepts /*= childConcepts(db_mainConcepts())*/; L nonMatches; // null so not filled by default // override for live mode void runLiveMode {} /*void cleanForStorage { out = outPrio = null; }*/ void appendHTML(Appendable out default this.out, S html) ctex { if (empty(html)) ret; html = wrapInDiv(html, style := "margin-top: 0.5em"); out.append(html).append("\n"); } void appendText(Appendable out default this.out, S text) ctex { if (empty(text)) ret; out.append(hpre_htmlencode(rtrim(text))); } void appendTextBold(Appendable out default this.out, S text) ctex { if (empty(text)) ret; out.append(b(hpre_htmlencode(rtrim(text)))); } void allowSuggestingAnswer(BEAObject input) { if (input == null) ret; S text = input.text(); S url = mod.baseLink + "/saveAnswer"; appendHTML( hpostform("Suggest an answer to " + htmlEncode_quote(text) + ": " //+ hinputfield(+text, style := "width: 300px") + htextarea(text, id := "suggestAnswer", name := "text", class := "auto-expand", style := "max-height: 10em; width: 300px; vertical-align: top") + hhidden(inputID := input.id) + hhidden(redirect := "") + " " + hsubmit("Save answer") + " [Optional rewrite type: " + hinputfield("rewriteType", style := "width: 100px") + " ]", action := url, onsubmit := js_setRedirect())); } BEA saveInput(S q) { Pair p = uniqCI2 BEAObject(type := "Input", text := q); if (p.b) { csetIfUnset(p.a, createdBy := mod.user(mod.currentReq!)); appendHTML("Input saved"); } ret p.a; } void runNonMatches { if (nempty(nonMatches)) { appendHTML(hr()); callFAll(nonMatches); } } void runIt { if (liveMode) runLiveMode(); else run(); runNonMatches(); } } // end of Algorithm class ReverseInput extends Algorithm { run { appendText(reversed(q)); } void runLiveMode { run(); } } class TimeoutTest extends Algorithm { run { sleepSeconds(120); } } class RunPattern extends Algorithm { run { BEAObject pattern = mod.beaGet(parseFirstLong(q)); if (pattern == null) ret with appendText("Pattern not found"); appendText("Pattern: " + pattern); for (BEAObject input : mod.beaList("Input")) { S text = input.text(); SS mapping = matchInputWithPattern(input, pattern); if (mapping == null) nonMatches.add(r { appendText("Checking Input: " + input + " - No match"); }); else { S result = "\n" + indent(formatDoubleArrowMap_horizontallyAligned(mapping)); appendText("Checking Input: " + input + result); allowStoringMatch(this, input, pattern, mapping); } } } } class FindRewrites extends Algorithm { run { // argument is ID of a match BEAObject match = mod.beaGet(parseFirstLong(q)); if (match == null || !match.typeIs("Match")) ret with appendText("Match not found"); BEAObject pattern = cast cget pattern(match); BEAObject input = cast cget input(match); SS mapping = cast get mapping(match); appendText("Match: " + match); appendText("Input: " + input); appendText("Pattern: " + pattern); appendText("Mapping:\n" + indent(formatDoubleArrowMap_horizontallyAligned(mapping))); appendRewrites(this, input, input.text(), pattern, match, mapping); } } // match and input can be null, pattern has to be set LS appendRewrites(Algorithm algo, BEAObject input, S inputText, BEAObject pattern, BEAObject match, SS mapping) { Cl rewrites = mod.beaBackRefs(pattern, "Rewrite"); new LS texts; for (BEAObject r : rewrites) { S text = r.text(); S textWithVars = text; if (pattern.typeIs("Syntactic pattern")) textWithVars = starsToAngleBracketedNumbers(text); S text2 = replaceAngleBracketVars_curly(textWithVars, mapping); algo.appendText(" Using pattern rewrite: " + text); algo.appendTextBold( " " + inputText + "\n" + " => " + text2); texts.add(text2); // look for existing rewrite BEAObject existing = match == null || input == null ?: conceptWhereIC BEAObject( type := "Rewrite", +input, text := text2, +match, patternRewrite := r, label := "good" ); if (existing != null) algo.appendHTML("Rewrite exists: " + mod.beaLinkHTML(existing)); else if (match != null && input != null) algo.appendHTML( hinlinepostform( hhiddenMulti( action := "create", f_type := "Rewrite", f_text := text2, f_input := input.id, metaInfo_input := "concept", f_match := match.id, metaInfo_match := "concept", f_patternRewrite := r.id, metaInfo_patternRewrite := "concept", f_label := "good") + hbutton("Good rewrite"), target := "_blank", action := mod.crudLink(BEAObject))); } ret texts; } class ProcessNewInput extends Algorithm { run { q = trim(q); BEAObject input = handleInput(this, q, false); for (BEAObject pattern : mod.beaListAny("Pattern", "Syntactic Pattern")) { SS mapping = matchInputWithPattern(q, pattern); if (mapping == null) nonMatches.add(r { appendText("Checking Pattern: " + pattern + " - No match"); }); else { S result = "\n" + indent(formatDoubleArrowMap_horizontallyAligned(mapping)); appendText("Checking Pattern: " + pattern + result); if (input == null) { //appendHTML("Click \"Save input\" first to store this match"); } else allowStoringMatch(this, input, pattern, mapping); appendRewrites(this, input, q, pattern, null, mapping); } } } } class ProcessNewInput_v2 extends Algorithm { run { q = trim(q); saveInput(q); BEAObject input = handleInput(this, q, false); if (input != null) { Cl rewrites = mod.beaBackRefs(input, "Rewrite"); BEAObject rewrite = random(rewrites); if (rewrite != null) appendHTML("My answer: " + b(htmlEncode2(rewrite.text())) + " " + ahref(mod.beaShortURL(rewrite), "[source]")); } allowSuggestingAnswer(input); for (BEAObject pattern : syntacticPatternsSortedBySpecificityDesc()) { continue if isTrue_getOpt alwaysMatches(pattern); SS mapping = matchInputWithPattern(q, pattern); if (mapping == null) nonMatches?.add(r { appendHTML("Checking Syntactic Pattern: " + mod.beaLinkHTML(pattern) + " - No match"); }); else { S result = "Grouped as: " + replaceAngleBracketVars_curly(starsToAngleBracketedNumbers(pattern.text()), mapping) + "\n" + indent(formatDoubleArrowMap_horizontallyAligned(mapping)); appendHTML(hr()); appendHTML("Checking Syntactic Pattern: " + mod.beaLinkHTML(pattern)); appendText(result); BEAObject match = null; if (input == null) { //appendHTML("Click \"Save input\" first to store this match"); } else match = allowStoringMatch(this, input, pattern, mapping); MultiMap subInputRewrites = ciMultiMap(); for (S subInput : uniquifyCI(values(mapping))) if (!eqic(subInput, q)) { BEAObject subInputObj = handleInput(this, subInput, "Sub-Input", true); // find rewrites for sub-input if (subInputObj != null) { L subRewrites = concatLists( conceptsWhereCI(BEAObject, type := "Rewrite", input := subInputObj), conceptsWhereCI(BEAObject, type := "Rewrite", isRewriteOf := subInputObj)); for (BEAObject r : subRewrites) appendHTML("  Sub-Rewrite found: " + r); subInputRewrites.putAll(subInput, subRewrites); } } // show all rewrites for the pattern appendRewrites(this, input, q, pattern, match, mapping); // apply some sub-rewrites randomly SS rewrittenMapping = mapValues(mapping, s -> { BEAObject rewrite = random(subInputRewrites.get(s)); ret rewrite == null ? s : uncurly(rewrite.text()); }); S randomRewrite = replaceAngleBracketVars_curly(starsToAngleBracketedNumbers(pattern.text()), rewrittenMapping); if (neq(randomRewrite, q)) appendText("Random rewrite from sub-inputs: " + randomRewrite); } } // for pattern } } class ProcessNewInput_v3 extends Algorithm { run { q = trim(q); saveInput(q); BEAObject input = handleInput(this, q, false); new HTMLTabs tabs; { new StringBuffer toTab; Algorithm alg = new ProcessNewInput_v2; alg.q = q; alg.out = toTab; alg.runIt(); tabs.add("Match input with patterns", toTab); } { new StringBuffer toTab; Algorithm alg = new SyntacticPatternFromInput; alg.q = q; alg.out = toTab; alg.runIt(); tabs.add("Make syntactic pattern", toTab); } appendHTML(tabs.html()); } } BEAObject allowStoringMatch(Algorithm algo, BEAObject input, BEAObject pattern, SS mapping) { BEAObject match = conceptWhereCI(BEAObject, type := "Match", +pattern, +input, +mapping); if (match != null) ret match with algo.appendHTML("Match exists: " + mod.beaLinkHTML(match)); /*S url = appendParamsToURL(mod.baseLink + "/storeMatch", pattern := pattern.id, input := input.id); algo.appendHTML( hbuttonLink(appendParamsToURL(url, label := "good"), "Good match") + " " + hbuttonLink(appendParamsToURL(url, label := "bad"), "Bad match"));*/ algo.appendHTML(joinWithSpace( storeMatchForm(input, pattern, "good"), storeMatchForm(input, pattern, "bad"))); null; } S storeMatchForm(BEAObject input, BEAObject pattern, S label) { ret hinlinepostform( hhiddenMulti( pattern := pattern.id, input := input.id, +label, redirect := "") + hbutton(firstToUpper(label) + " match"), action := mod.baseLink + "/storeMatch", onsubmit := js_setRedirect()); } runnable class MakeSyntacticPatterns extends Algorithm { for (BEAObject p : mod.beaList("Pattern")) { appendText(p + " => " + makeSyntacticPattern(p)); } } S syntacticPatternText(BEAObject p) { ret simpleSpacesTrim_javaTok(angleBracketVarsToStars(p.text())); } // convert angle bracket var pattern to syntactic pattern BEAObject makeSyntacticPattern(BEAObject p) { if (p == null || !p.typeIs("Pattern") || empty(p.text())) null; print("makeSyntacticPattern", p); S text = syntacticPatternText(p); BEAObject sp = uniqCI BEAObject(type := "Syntactic Pattern", +text); cset(p, syntacticPattern := sp); ret sp; } S processInputURL(S q) { ret addParamsToURL(mod.baseLink + "/query", +q, algorithm := "process input"); } BEAObject handleInput(Algorithm algo, S q, S desc default "Input", bool showProcessLink) { algo.appendHTML("\*desc*/: " + tt(htmlEncode(q)) + (!showProcessLink ? "" : " " + targetBlank(processInputURL(q), "Process"))); BEAObject input = mod.findInput(q); algo.appendHTML(inputHTML(input, desc, q)); ret input; } // Link to or allow to save input object S inputHTML(BEAObject input, S desc default "Input", S q) { ret input != null ? "\*desc*/ exists: " + mod.beaLinkHTML(input) : !mod.requestAuthed() && !mod.allowAnonymousInputUpload ? null : hinlinepostform( hhiddenMulti( text := q, redirect := "") + hbutton("Save \*desc*/"), action := mod.baseLink + "/saveInput", onsubmit := js_setRedirect()); } // Link to or allow to save syntactic pattern S syntacticPatternLinkHTML(BEAObject obj, S text, BEAObject fromInput default null) { S desc = "Syntactic pattern"; ret obj != null ? mod.beaLinkHTML(obj) : !mod.requestAuthed() ? null : hinlinepostform( hhiddenMulti( +text, fromInput := conceptIDOrNull(fromInput), redirect := "") + hbutton("Save \*firstToLower(desc)*/"), action := mod.baseLink + "/saveSyntacticPattern", onsubmit := js_setRedirect()); } runnable class SyntacticPatternFromInput extends Algorithm { //appendHTML(inputHTML(mod.findInput(q), q)); BEAObject input = handleInput(this, q, false); if (countTokens(q) > 10) ret with appendText("Input too long to extract syntactic patterns"); S q2 = dropPunctuation(q); new L data; for (S pat : sortedIC(gazelle_allSyntacticPatternsFromInput(q))) { SS mapping = matchInputWithSyntacticPattern(q2, pat); BEAObject obj = conceptWhereIC(BEAObject, type := "Syntactic Pattern", text := pat); /*appendHTML(htmlEncode2(pat) + " " + syntacticPatternLinkHTML(obj, pat) + (empty(mapping) ? "" : hpre_htmlencode(indent(formatDoubleArrowMap_horizontallyAligned(mapping)))));*/ Map row = litorderedmap( "Syntactic Pattern" := htmlEncode2(pat), "In database" := syntacticPatternLinkHTML(obj, pat, input)); for (S key, S val : mapping) row.put("Argument " + key, htmlEncode2(val)); data.add(row); } appendHTML(print(htmlTable2_noHtmlEncode(data))); } class ApplyTextFunctions extends Algorithm { run { q = trim(q); saveInput(q); BEAObject input = handleInput(this, q, false); localConcepts = db_mainConcepts(); // new Concepts; new LinkedHashSet objectsMade; for (BEAObject f : mod.beaList("JavaX Standard Function")) pcall { S fName = getString name(f); if (!isIdentifier(fName)) continue; if (!isSafeStandardFunction(fName)) continue with nonMatches?.add(r { appendText("Function " + fName + " not safe"); }); BEAObject o = cnew(localConcepts, BEAObject, type := "Function Result", function := f, functionCalled := fName, +input, calculating := true); objectsMade.add(o); try { O holder = loadFunction_cached(fName); O result = evalWithTimeoutOrFail(10.0, () -> call(holder, fName, q)); // convert string collections to list if (!result instanceof L && isStringCollection(result)) result = asList((Cl) result); if (result == null) cset(o, resultType := "null"); else if (result instanceof S) cset(o, resultType := "string", +result); else if (isStringList(result)) cset(o, resultType := "list of strings", +result); else cset(o, result := "other" + appendRoundBracketed(className(result)), result := shorten(1000, str(result))); } catch e { cset(o, resultType := "error", error := getStackTrace(e)); } cset(o, calculating := null); } appendHTML(h3("Results of function calls")); //appendHTML(ul_htmlencode(allToString(list(localConcepts, BEAObject)))); /*HCRUD_Concepts crudData = new(localConcepts, BEAObject); HCRUD crud = new(null, crudData); crud.unshownFields = litset("globalID", "mirrorPost"); crudData.massageItemMapForList = (item, map) -> { BEAObject o = item/BEAObject; O value = o~.result; map.put("result", HTML(javaValueToHTML(value, identityHashSet()))); //map.put("Save", HTML(hbutton())); };*/ HCRUD crud = mod.makeCRUD(BEAObject, mod.currentReq!); HCRUD_Concepts crudData = cast crud.data; crudData.listConcepts_firstStep = () -> objectsMade; appendHTML(crud.renderTable(true)); } } class FindPath extends Algorithm { new BreadthFirstPathFinder_withLinkType pathFinder; BEAObject start, dest; run { start = mod.beaGet(parseFirstLong(q)); dest = mod.beaGet(parseSecondLong(q)); if (start == null || dest == null) ret with appendText("Please supply object IDs of start and end"); appendHTML("Looking for path from " + mod.beaToHTML(start) + " to " + mod.beaToHTML(dest)); pathFinder.getChildren = o -> cForwardAndBackRefsWithFieldIndicator BEAObject(o); pathFinder.add(start); while (!pathFinder.nodeReached(dest) && pathFinder.step()) {} //appendHTML(hcomment(struct(pathFinder))); LPair path = pathFinder.examplePathWithTypes(start, dest); if (path == null) appendText("No path found!"); else { appendHTML(b("Path found!")); appendHTML(ol(map(path, p -> { S html = mod.beaHTML(p.a); if (p.b == null) ret html; S arrow = ifThenElse(p.b.forward, ">>", "<<"); ret html + " " + htmlEncode2( joinNemptiesWithSpace(arrow, p.b.field, arrow)); }))); } } } class ExecuteTextQuery extends Algorithm { run { saveInput(q = trim(q)); appendHTML(h3("Result")); appendHTML(htmlEncode2(strOrEmpty(executeTextQuery(q)))); } } class InputSummary extends Algorithm { run { BEA mainInput = saveInput(q = trim(q)); Cl inputs = conceptsWhere BEAObject(type := "Input", text := q); if (l(inputs) > 1) appendHTML("Note: Input appears " + l(inputs) + " times in the database: " + joinWithSpace(map(o -> mod.beaToHTML(o), inputs))); for (BEA input : inputs) { if (input != mainInput) { appendHTML(hr()); appendHTML("Input: " + input); } // rewrites Cl rewrites = mod.beaBackRefs(input, "Rewrite"); if (empty(rewrites)) appendHTML(h3("No rewrites")); else for (int i, BEA r : unpair iterateWithIndex1(rewrites)) appendHTML("Rewrite " + i + ": " + ahref(mod.beaURL(r), tok_dropCurlyBrackets(r.text()))); // matches //beaBackRefs("Match } } } // add algorithms here int patternSpecificity(BEAObject pattern) { ret countWordsWithoutAngleBracketedAndStars(pattern.text()); } L syntacticPatternsSortedBySpecificityDesc() { ret sortedByCalculatedFieldDesc patternSpecificity(mod.beaList("Syntactic Pattern")); } O executeTextQuery(S s) { new Matches m; if (match3_withIntsAndIDs("all references in field of object ", s, m)) { O value = cget(mod.beaGet($2), $1); ret value instanceof Cl ? instancesOf BEAObject((Cl) value) : value instanceof BEAObject ? ll((BEAObject) value) : ll(); } ret new QueryNotUnderstood(s); } srecord QueryNotUnderstood(S s) {} S beaToHTML(BEA o) { ret mod.beaToHTML(o); } S beaHTML(BEA o) { ret mod.beaHTML(o); } S beaURL(BEA o) { ret mod.beaURL(o); } bool isSyntacticPattern(BEA pat) { ret pat != null && pat.typeIs("Syntactic pattern"); } S patternTextWithAngleBracketVars(BEA pat) { S text = pat.text(); ret isSyntacticPattern(pat) ? starsToAngleBracketedNumbers(text) : text; } bool isCommentOrFeedback(BEA o) { ret o != null && o.typeIsOneOf("Comment", "Useful", "Feedback"); } S feedbackHTML(BEA o) { Cl l = filter isCommentOrFeedback(mod.beaBackRefs(o)); ret joinWithBR(map(l, c -> c.typeIs("Comment") ? ahref(beaURL(c), htmlEncode2(c.text())) : beaHTML(c))); } S bestInputURL(S text) { text = trim(text); BEA input = mod.findInput(text); ret input != null ? beaURL(input) : processInputURL(text); } } // end of Calculations