Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

90
LINES

< > BotCompany Repo | #1013031 // Matrix Module [Smart Bot Dyn]

JavaX module [tags: use-pretranspiled]

Download Jar. Libraryless. Click here for Pure Java version (12998L/89K/289K).

!7

// "Matrix functions" are not supposed to use the index
// ...but now they can.

!include once #1013530 // Dyn

html {
  bool authed = creatorAuthed();
  
  S _topic = params.get("topic");
  if (empty(_topic))
    _topic = ai_randomString();
  fS topic = _topic;
  if (nempty(params.get("topic"))) { // not from "random topic" url
    // post user's answers (verified or unverified)
    
    // free-text line
    S newCat = params.get("new-cat"), newValue = params.get("new-value");
    if (nempty(newCat)) {
      S verb = ai_matrix_answerToVerb(newValue);
      if (nempty(verb))
        post(topic, verb, newCat);
      else
        post(quote(newCat), " is a matrix category for", topic);
    }
    
    // all other lines
    for (S key : keysStartingWith2(params, "cat-")) {
      S value = params.get(key);
      continue if empty(value);
      S verb = ai_matrix_answerToVerb(value);
      continue if empty(verb);
      S cat = urldecode(dropPrefix("cat-", key));
      temp tempSetThreadLocal(ai_postTriple_verified, authed);
      post(topic, verb, cat);
    }
  }
  
  L<S> functions = ai_matrix_standardFunctions();
  Map<S, O> rawResults = evaluateFunctionsAsMap(functions, topic);
  SS results = mapValues(f ai_html_struct, rawResults);
  for (S f : keys(rawResults))
    postWithSource(topic, "under " + f + " is", sfu(rawResults.get(f)), "matrix");

  final L<S> answers = concatLists(ll(""), ai_matrix_standardAnswers());
  
  Set<S> options = ai_matrix_categoriesForTopic(topic);
  options.addAll(ai_matrix_standardCategories());
  
  L<Map> data = map(options, func(S cat) -> Map {
    S userAnswer = null;

    ret litorderedmap(
      "Statement", b(htmlencode2(topic)) + " is " + html_matrixLink(cat),
      "Computer Answer", htmlEncode(ai_matrixGet(topic, cat)),
      "Your Answer",
        hselect_list(answers, userAnswer, name := "cat-" + urlencode(cat))
        //hcheckbox(urlencode(s), tossCoin())
    );
  });
  
  S formURL =
    //smartBotRealURL() + "/dyn/" + psI(programID()) + "?topic=" + urlencode(topic);
    smartBot_matrixLink(topic);
  
  // Free category entry line
  data.add(litorderedmap(
    "Statement", b(htmlencode2(topic)) + " is " + htextinput("new-cat", onkeypress :=
      [[ if ($("#new_value").val() == '') $("#new_value").val("yes").prop('selected', true); ]]),
    "Your Answer", hselect_list(answers, name := "new-value", id := "new_value")));
  
  // Main HTML
  
  ret hstyle_matrixBackground()
    + htitle_htmlencode("Matrix: " + topic) + loadJQuery() 
    + div(small(authed ? "Authed" : "Not authed"), style := "position:absolute; right: 10px; top: 10px;")
    + hcenter(
      hform("Topic: " + hinputfield('topic, value := topic), style := "display: inline", action := smartBot_emptyMatrixLink()) + " "
    + hform(hsubmit("Random"), style := "display: inline", action := "/matrix/")
    + p(b(
      hfontsize(15, "Matrix Page for:") + "<br>" +
      targetBlank(smartBot_encyclopediaLink(topic), hfontsize(40, topic), style := "text-decoration: none")) + "<br>"
      /*+ ahref(smartBot_encyclopediaLink(topic), "[more]")*/, style := "margin-top: 3em")
    + hpostform(hhidden(+topic)
    + hsubmit("Save answers") + "<br><br>"
    + htable_noEncode(data), action := formURL)
    + htable_noEncode(mapToListOfMaps(results, "Function", "Result"))
  );
}

Author comment

Began life as a copy of #1013022

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1013031
Snippet name: Matrix Module [Smart Bot Dyn]
Eternal ID of this version: #1013031/86
Text MD5: e561ccd748286bdf383138606739c66b
Transpilation MD5: 8639c0dc326e0598a951471c267f03c7
Author: stefan
Category: javax / a.i. / html
Type: JavaX module
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-01-08 06:33:40
Source code size: 3416 bytes / 90 lines
Pitched / IR pitched: No / No
Views / Downloads: 573 / 1830
Version history: 85 change(s)
Referenced in: [show references]