!7 extend Statement { Statement() { if (!_loading()) originatingUniverse = myUniverse_cache != null ? myUniverse_cache : myUniverse(); } } concept ImportedFrom { S snippetID; long lastTime; } static Q q; static S myUniverse_cache; sS hE = "English (machine-generated)"; sS hC = "Computer Language"; p { framesBot(); db(); truthBot(); if (isHeadless()) { calcOnConceptChanges(1000, r { makeTranslations(false) }, true); } else { q = new Q(true); substance(); swingMain(); } } svoid swingMain swing { final SimpleCRUD crud = new SimpleCRUD(Statement) { L fields() { ret prioritizeList(super.fields(), ll("text", "globalID")); } }; crud.renderer = func(Statement s) { litorderedmap(hC, s.text, hE, s.possibleEnglishTranslation) }; showConceptsTable_postProcess.set(f reversedList); showConceptsTable_afterUpdate.set(r { //print("Setting width"); //tableSetColumnWidths_debug = true; //tableSetColumnWidths(crud.table, hC, 100); //crud.table.getColumnModel().getColumn(1).setWidth(100); }); crud.show(programTitle()); //swing { crud.table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); } addMenu(crud.panel, "Menu!", "Rebuild Translations", r { clearAICaches(); q.add(r { makeTranslations(true) }); }); swing { crud.buttons.add(jbutton("Export", r { swingExportConcepts("Truth Table") })); crud.buttons.add(jbutton("Import...", f doImport)); } addAISuiteMenu(crud.panel); q.add(r { makeTranslations(false) }); awtCalcOnConceptChanges(crud.table, 500, r { makeTranslations(false) }, true); aiEnhancements(); hideConsole(); } svoid makeTranslations(bool all) { for (Statement s) { if (all || empty(s.possibleEnglishTranslation) || eq(s.possibleEnglishTranslation, "?")) cset(s, possibleEnglishTranslation := orQuestionMark2(f conceptLanguageToEnglish, s.text)); } } svoid doImport { ImportedFrom last = last(sortedByField("lastTime", list(ImportedFrom))); final JTextField tf = jTextField(last == null ? #1007475 : last.snippetID); showFormTitled("Import Truth Table", "Snippet ID", tf, r-thread { loading { importFrom(getTextTrim(tf)); } }); } svoid importFrom(S snippetID) { snippetID = fsI(snippetID); cset(uniq(ImportedFrom, +snippetID), lastTime := now()); S text = loadSnippet(snippetID); Concepts newConcepts = new Concepts(snippetID).safeLoad(text); print(n(list(newConcepts, "Statement"), "statement") + " loaded from " + snippetID); Concepts myConcepts = mainConcepts; print("I have " + n(list(myConcepts, "Statement"), "statement"); Map myIDs = indexByField(list(myConcepts, Statement), "globalID"); int nNew = 0; for (Concept c : list(newConcepts, "Statement")) { S id = getString(c, "globalID"); bool has = myIDs.containsKey(id); print("ID: " + id + " - " + (has ? "I have it" : "I don't have it")); if (!has) { // Creating Statement c2 = cnew(Statement, importedFrom := snippetID, imported := now()); importFields(c, c2); myIDs.put(id, c2); ++nNew; } else { // Updating Statement c2 = myIDs.get(id); if (c2.touched > c2.imported) print(" Statement touched locally! Not changing."); else { cset(c2, imported := now()); int changes = importFields(c, c2); if (changes == 0) print(" No change."); else print(" Updated statement! " + n(changes, "fields") + " changed"); } } } infoBox("Import done. " + n(nNew, "new statement")); } static int importFields(Concept c, Statement c2) { ret copyConceptFields(c, c2, "globalID", "text", "possibleEnglishTranslation", "originatingUniverse"); } svoid truthBot { new Android3 android; android.greeting = "Truth Table Bot."; android.console = false; android.responder = new Responder { S answer(S s, L history) { new Matches m; if "add truth * by *" { L statements = cast unstructure($1); S importedFrom = $2; int added = 0; myUniverse_cache = myUniverse(); try { for (S text : statements) { text = trim(text); Statement st = conceptWhere(Statement, +text); if (st == null) { cnew(Statement, +text, +importedFrom, imported := now(), possibleEnglishTranslation := conceptLanguageToEnglish(text)); ++added; } } } finally { myUniverse_cache = null; } ret "OK, added " + n(added, "statements"); } if "import from *" { importFrom(formatSnippetID($1)); ret "OK"; } if "export" { swingExportConcepts_impl("Truth Table"); ret "OK, " + exportSnippetID; } null; } }; makeBot(android); }