Warning: session_start(): open(/var/lib/php/sessions/sess_rsf72kaklrhio8e6qiltt8ca33, 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 Statement {
S globalID = aGlobalID(), text;
S possibleEnglishTranslation;
S universe;
S importedFrom;
long imported, touched; // TODO: actually set touched
}
static Q q;
sS hE = "English (machine-generated)";
sS hC = "Computer Language";
p-pretty {
framesBot();
final SimpleCRUD crud = new SimpleCRUD(Statement);
crud.renderer = func(Statement s) { litorderedmap(hC, s.text, hE, s.possibleEnglishTranslation) };
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 { q.add(r { makeTranslations(true) }) });
crud.buttons.add(jbutton("Export", r-thread { swingExportConcepts("Truth Table") }));
crud.buttons.add(jbutton("Import...", f doImport));
addAISuiteMenu(crud.panel);
q = new Q(true);
q.add(r { makeTranslations(false) });
awtCalcOnConceptChanges(crud.table, 500, r { makeTranslations(false) }, true);
conceptLanguageToolTips();
}
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 ? #1007208 : 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", "universe");
}