function make_word($name, $jp = NULL, $zh = NULL) { global $sql_stmts; sql_exec(sql_stmt("word_lang,word_name,word_spart->new in words"), ["sss", "tp", $name, "multi"]); $id = NULL; sql_getone(sql_stmt("word_lang,word_name,word_spart->word_id"), $id, ["sss", "tp", $name, "multi"]); $GLOBALS["word"] = WORD(defaultDB(), $id); if ($jp) { $a = ATTR("jp", $jp); $GLOBALS["word"]->add_attr($a); } if ($zh) { $a = ATTR("zh", $jp); $GLOBALS["word"]->add_attr($a); } }
} else { $p = PATH($w); $p->set($names[0]); exit("success"); } } } } $ignore = array_map(function ($a) { return explode("/", $a); }, $ignore); // Template: passed by name, spart from word, attr template=true $t = defaultDB()->searcher(); $t = $t->spart($w->speechpart()); $t = $t->name($template); $t = $t->only_with_attr(ATTR("template", "true")); $t = $t->all(); //error_log(var_export(array_map(function($a){return$a->id();},$t),1)); if (count($t) === 0) { exit("Could not find template with name: " . $template); } elseif (count($t) !== 1) { exit("Ambiguous template name (please remove duplicate template(s))"); } if ($path === "common") { if (($s = run_template($w, PATH($w, "feminine"), $t[0], $forms, $ignore, $changes, FALSE)) === NULL) { if (($s = run_template($w, PATH($w, "masculine"), $t[0], $forms, $ignore, $changes, FALSE)) === NULL) { exit("success"); } else { exit("Template did not run successfully: {$s}"); } } else {
global $quiz_types; global $df_exclude; $challenge = function ($spart, $lang = 'la') { return function () use($spart, $lang) { global $OP_USER_INPUT; return [["help" => function (&$pick_db, $db) { $word = $pick_db["word"]; $paths = $pick_db["word"]->read_paths(); $paths = array_filter($paths, function ($p) { return $p->get(); }); $path = $pick_db["path"] = choose_one($paths); error_log(var_export($path->get(), 1)); $pick_db["form"] = $path->get(); $path = implode(" ", array_map("format_path", array_reverse(explode("/", (string) $path)))); $word_name = display_word_name($word); return "What is the {$path} for {$word_name}."; }, "selections" => ["word" => function ($_, $db, $path) use($spart, $lang) { $s = $db->searcher()->spart($spart)->lang($lang)->only_without_attr(ATTR("irregular"))->only_without_attr(ATTR("hidden"))->only_without_attr(ATTR("template")); $s->stmt .= " AND EXISTS (SELECT 1 FROM forms WHERE forms.word_id = words.word_id AND form_tag != '' AND form_value != '')"; return $s->rand(); }], "sentence" => [$OP_USER_INPUT], "answer0" => function ($pick_db) { $map = function ($w) use($pick_db) { return word_link2($pick_db["word"], $w, true, true); }; return array_map($map, explode("\n", $pick_db["form"])); }, "answer0-tooltip" => "Enter form"]]; }; }; $quiz_types = array_merge($quiz_types, ["random-verb-forms1" => ["name" => "Random verb forms", "category" => "Challenge", "lang" => "la", "options" => $challenge("verb")], "random-noun-forms1" => ["name" => "Random noun forms", "category" => "Challenge", "lang" => "la", "options" => $challenge("noun")]]);
function get_template($conj) { return safe_get(0, defaultDB()->searcher()->spart("verb")->name($conj)->only_with_attr(ATTR("template", "true"))->all()); }
if ($no_templates) { $attrs[] = "!template"; } foreach ($attrs as $attr) { if (!$attr) { continue; } $a = NULL; if ($reverse = substr($attr, 0, 1) === "!") { $attr = substr($attr, 1); } if (strpos($attr, "=") === FALSE) { $a = ATTR($attr); } else { list($name, $value) = explode("=", $attr, 2); $a = ATTR($name, $value); } if ($a !== NULL) { if (!$reverse) { $searcher = $searcher->only_with_attr($a); } else { $searcher = $searcher->only_without_attr($a); } } } $list = $searcher->all(); } else { $list = []; foreach ($ids as $id) { $list[] = WORD(defaultDB(), intval($id)); }
if (!array_key_exists("spart", $_GET) or !($sparts = vec_norm(explode(",", $_GET["spart"]), "trim"))) { $sparts = NULL; } if (!array_key_exists("attr", $_GET) or !($attrs = vec_norm(explode(",", $_GET["attr"]), "trim"))) { $attrs = []; } if (!requireRank(3, FALSE)) { echo "Insufficient permissions"; } else { if ($langs and count($langs) == 1 and $names and count($names) == 1 and $sparts and count($sparts) == 1) { $w = defaultDB()->searcher()->name($names[0])->spart($sparts[0])->lang($langs[0])->all(); if (count($w)) { echo "Word seems to be already added"; } else { sql_exec(sql_stmt("word_lang,word_name,word_spart->new in words"), ["sss", $langs[0], $names[0], $sparts[0]]); $w = defaultDB()->searcher()->name($names[0])->spart($sparts[0])->lang($langs[0])->all(); if (count($w) === 1) { $w = $w[0]; foreach ($attrs as $a) { $a = explode("=", $a, 2); if (count($a) === 2) { $w->add_attr(ATTR($a[0], $a[1])); } } } exit("success"); } } else { exit("Bad \$_GET"); } }
function attrs() { global $sql_stmts; if ($this->issql and $this->_id !== NULL) { $added = []; # id's returned sql_getmany(sql_stmt("word_id->attr_tag"), $added, ["i", $this->_id]); foreach ($added as $attr) { $cont = FALSE; foreach ($this->_attrs as $_attr) { if (ISPATH($_attr) ? $_attr->tag() == $attr : $_attr == $attr) { $cont = TRUE; break; } } if (!$cont) { $this->_attrs[] = ATTR($this, $attr); } } } return $this->_attrs; }
<?php require_once '/var/www/config.php'; sro('/Includes/mysql.php'); sro('/Includes/session.php'); sro('/Includes/functions.php'); sro('/PHP5/lib/PHPLang/sql_stmts.php'); sro('/PHP5/lib/PHPLang/db.php'); sro('/PHP5/lib/PHPLang/display.php'); sro('/PHP5/lib/PHPLang/misc.php'); global $mysqli; $w = defaultDB()->searcher()->lang('la')->only_without_attr(ATTR('template')); $ws = $w->all(); ?> <table class="inflection"><?php foreach ($ws as $i => $word) { ?> <tr><td><ol start="<?php echo $i + 1; ?> "><li><a class="word-ref format-word-<?php echo $word->lang(); ?> " href="dictionary.php?id=<?php echo $word->id(); ?> "><?php echo $word->name(); ?> </ol></td><td style="border-spacing: 0px; padding: 0px;"><?php display_definitions($word);
function do_pick($t, $db, &$pick_db, &$reason) { if ($db === NULL) { $db = defaultDB(); } if ($t === NULL) { $reason = "pick was null"; return $t; } elseif (ISOP($t) or ISHTML($t)) { return $t; } elseif (ISPICK($t)) { return $t->rand($db); } elseif (is_string($t)) { return $t; } elseif (is_callable($t)) { $t = _process_value($t, $pick_db, $db); if ($t === NULL) { $reason = "custom function returned NULL"; return $t; } else { return do_pick($t, $db, $pick_db, $reason); } } elseif (array_key_exists("condition", $t) and !$t["condition"]($pick_db, $db, null)) { return FALSE; } elseif (array_key_exists("value", $t)) { return _process_value($t["value"], $pick_db, $db); } if (!($word = safe_get("word", $t))) { $searcher = $db->searcher(); #var_dump(array_keys($searcher->master)); if (array_key_exists("name", $t)) { $searcher = $searcher->name(_process_value($t["name"], $pick_db, $db)); } if (array_key_exists("language", $t)) { $searcher = $searcher->lang(_process_value($t["language"], $pick_db, $db)); } elseif (array_key_exists("lang", $t)) { $searcher = $searcher->lang(_process_value($t["lang"], $pick_db, $db)); } if (array_key_exists("speechpart", $t)) { $searcher = $searcher->partofspeech(_process_value($t["speechpart"], $pick_db, $db)); } elseif (array_key_exists("spart", $t)) { $searcher = $searcher->partofspeech(_process_value($t["spart"], $pick_db, $db)); } if (array_key_exists("attr", $t)) { foreach ($t["attr"] as $k => $v) { $v = _process_value($v, $pick_db, $db); if ($reverse = substr($k, 0, 1) === "!") { $k = substr($k, 1); $m = "only_without_attr"; } else { $m = "only_with_attr"; } $searcher = $searcher->{$m}($v !== NULL ? ATTR($k, $v) : ATTR($k)); } } $word = $searcher->rand(); } if (!ISWORD($word)) { $reason = "could not find a word with name " . var_export($t["name"], 1) . " and attrs " . var_export(safe_get("attr", $t), 1); return; } if (array_key_exists("store_word", $t)) { $pick_db[$t["store_word"]] = $word; } $word->read_paths(); $path = PATH($word); if (array_key_exists("path", $t)) { $p = $t["path"]; if (!is_array($p)) { $p = _process_value($p, $pick_db, $db, $path); } foreach ($p as $k => $_) { $path->add2([$k => _process_value($_, $pick_db, $db, $path)]); } } if (array_key_exists("verb-gender", $t)) { $g = $t["verb-gender"]; $g = _process_value($g, $pick_db, $db, $path); if ($g !== NULL and $path->exists()) { $path->add($g); if (!$path->hasvalue()) { $path->take("gender"); } } } if ($path->hasvalue() || !(string) $path) { $ret = $path->hasvalue() ? $path->get() : $word->name(); if (array_key_exists("store", $t)) { $pick_db[$t["store"]] = $ret; } if (array_key_exists("store_path", $t)) { $pick_db[$t["store_path"]] = $path; } return format_word($ret, $word->lang()); } else { $reason = "path '{$path}' didn't exist in word with id <a target='_blank' href='dictionary.php?id=" . $word->id() . "'>" . $word->id() . "</a> or was NULL"; return; } }
function display_word_name($w, &$common = false) { $lang = $w->lang(); $spart = $w->speechpart(); $name = NULL; if ($lang === "la") { if ($spart === "noun") { if ($genders = $w->path()->iterate("gender")) { $name = []; $common = true; if ($name !== NULL and in_array($g = "masculine", $genders)) { $key = PATH($w, "nominative/singular/{$g}"); if (!$key->hasvalue()) { $name = NULL; } else { $name[] = $key->get(); $key = PATH($w, "genitive/singular/{$g}"); if (!$key->hasvalue()) { $name = NULL; } else { $name[] = $key->get(); } } } else { $common = false; } if ($name !== NULL and in_array($g = "feminine", $genders)) { $key = PATH($w, "nominative/singular/{$g}"); if (!$key->hasvalue()) { $name = NULL; } else { $name[] = $key->get(); $key = PATH($w, "genitive/singular/{$g}"); if (!$key->hasvalue()) { $name = NULL; } else { $name[] = $key->get(); } } } else { $common = false; } if ($name !== NULL and in_array($g = "neuter", $genders)) { $key = PATH($w, "nominative/singular/{$g}"); if (!$key->hasvalue()) { $name = NULL; } else { $name[] = $key->get(); $key = PATH($w, "genitive/singular/{$g}"); if (!$key->hasvalue()) { $name = NULL; } else { $name[] = $key->get(); } } $common = false; } if ($common and count($name) === 4 and $name[0] == $name[2] and $name[1] == $name[3]) { $name = [$name[0], $name[1]]; } else { $common = false; } } } elseif ($spart === "pronoun") { if ($genders = $w->path()->iterate("gender")) { $name = []; if ($name !== NULL and in_array($g = "masculine", $genders)) { $key = PATH($w, "nominative/singular/{$g}"); if (!$key->hasvalue()) { $name = NULL; } else { $name[] = $key->get(); } } if ($name !== NULL and in_array($g = "feminine", $genders)) { $key = PATH($w, "nominative/singular/{$g}"); if (!$key->hasvalue()) { $name = NULL; } else { $name[] = $key->get(); } } if ($name !== NULL and in_array($g = "neuter", $genders)) { $key = PATH($w, "nominative/singular/{$g}"); if (!$key->hasvalue()) { $name = NULL; } else { $name[] = $key->get(); } } if (count($name) == 2 and $name[0] === $name[1] or count($name) == 3 and $name[0] === $name[1] and $name[1] === $name[2]) { $name = [$name[0]]; $key = PATH($w, "nominative/plural"); if ($key->hasvalue()) { $name[] = $key->get(); } } } } elseif ($spart === "adjective") { $name = []; $number = safe_get(0, PATH($w, "positive")->iterate("number")); $keys = ["" => ["positive/nominative/{$number}/masculine", "positive/nominative/{$number}/feminine", "positive/nominative/{$number}/neuter"], "adjective-12" => ["positive/nominative/{$number}/masculine", "positive/nominative/{$number}/feminine", "positive/nominative/{$number}/neuter"], "adjective-3" => ["positive/nominative/{$number}/masculine", "positive/nominative/{$number}/neuter", "positive/genitive/{$number}/masculine"], "adjective-3-3" => ["positive/nominative/{$number}/masculine", "positive/nominative/{$number}/feminine", "positive/nominative/{$number}/neuter"]]; $keys = $keys[ATTR($w, "declension")->get()]; foreach ($keys as $_ => $key) { $key = PATH($w, $key); if (!$key->hasvalue()) { $name = NULL; break; } $name[] = $key->get(); } } elseif ($spart === "verb") { $name = []; foreach (["indicative/active/present/person-1/singular", "infinitive/active/present", "indicative/active/perfect/person-1/singular", "participle/perfect/passive"] as $_ => $key) { $key = PATH($w, $key); if (!$key->hasvalue()) { if ($_ <= 1) { $name = NULL; break; } elseif ($_ == 3) { $key = PATH($w, "supine/accusative"); if (!$key->hasvalue()) { continue; } } else { continue; } } $name[] = $key->get(); } } } if ($name === NULL) { $name = $w->name(); } else { $name = implode(", ", array_map("modify_options", $name)); } if (no_format($w)) { $name = $w->name(); } else { $name = format_word($name, $w->lang()); } return $name; }
} if (strpos($attr, "=") === FALSE) { $a = ATTR($attr); } else { list($name, $value) = explode("=", $attr, 2); $a = ATTR($name, $value); } if ($a !== NULL) { if (!$reverse) { $searcher = $searcher->only_with_attr($a); } else { $searcher = $searcher->only_without_attr($a); } } } $searcher = $searcher->only_without_attr(ATTR("template")); //$stmt = "SELECT form_value FROM forms WHERE word_id IN (".$searcher->stmt.")"; $stmt = "SELECT DISTINCT form_value FROM forms WHERE EXISTS (" . $searcher->stmt . " AND word_id = forms.word_id)"; if ($forms) { //$searcher = $searcher->form_includes($forms); $op = " AND ("; foreach ($forms as $f) { $stmt .= $op . "form_value LIKE CONCAT('%',?,'%')"; $searcher->args[0] .= "s"; $searcher->args[] .= $f; $op = " OR "; } if ($op === " OR ") { $stmt .= ")"; } }
return "subjunctive"; } return "indicative"; }], "choices0-tooltip" => "Which mood?", "choices0-language" => "en"]]], "subjunctive-infinitives" => ["name" => "Subjunctive practice", "category" => "Grammar", "lang" => "la", "stage" => 24, "options" => function () { global $OP_USER_INPUT; return [["help" => function (&$pick_db, $db) { $word = $pick_db["word"]; $pick_db["word"]->read_paths(); $path = $pick_db["path"] = PATH($word); foreach ($pick_db as $k => $v) { if ($k === "word" or $k === "path") { continue; } #error_log("$k = $v".var_export($v,true)); $path->add2($v); } #error_log(var_export($path->get(),1)); $pick_db["form"] = $path->get(); $path = implode(" ", array_map("format_path", array_reverse(explode("/", (string) $path)))); $word_name = display_word_name($word); return "What is the {$path} for {$word_name}."; }, "selections" => ["word" => function ($_, $db, $path) { $s = $db->searcher()->spart("verb")->only_without_attr(ATTR("irregular"))->only_without_attr(ATTR("template")); $s->stmt .= " AND EXISTS (SELECT 1 FROM forms WHERE forms.word_id = words.word_id AND form_tag != '' AND form_value != '') AND NOT EXISTS (SELECT 1 FROM attributes WHERE attr_tag = 'conjugation' AND attr_value like '%deponent%' AND word_id = words.word_id)"; return $s->rand(); }, "tense" => PICK(["imperfect", "pluperfect"]), "mood" => PICK(["indicative", "indicative", "indicative", "subjunctive", "subjunctive", "subjunctive", "subjunctive", "subjunctive"]), "number" => PICK(["singular", "plural"]), "person" => "person-3", "voice" => "active"], "sentence" => [$OP_USER_INPUT], "answer0" => function ($pick_db) { return array_map("format_word", explode("\n", $pick_db["form"])); }, "answer0-tooltip" => "Enter form"], make_chart(RWORD2("la", "verb"), null, ["participle", "infinitive", "supine", "imperative", "passive", "person-1", "person-2", "present", "perfect", "future", "future-perfect"])]; }], "013" => ["name" => "Subjunctive matching", "lang" => "la", "category" => "Grammar", "n_questions" => 1, "options" => function () { return [make_matching(["Pluperfect Subjunctive" => "portāvisset", "Pluperfect Indicative" => "discēderat", "Imperfect Indicative" => "veniēbat", "Imperfect Subjunctive" => "prōmitteret"])]; }]]);
function search_GET($limit = 50, &$max_size = NULL) { $db = defaultDB(); if (!array_key_exists("lang", $_GET) or !($langs = vec_norm(explode(",", $_GET["lang"]), "trim"))) { $langs = ['la']; } if (!array_key_exists("name", $_GET) or !($names = vec_norm(explode(",", $_GET["name"]), "trim"))) { $names = NULL; } if (!array_key_exists("form", $_GET) or !($forms = vec_norm(explode(",", $_GET["form"]), "trim"))) { $forms = NULL; } if (!array_key_exists("spart", $_GET) or !($sparts = vec_norm(explode(",", $_GET["spart"]), "trim"))) { $sparts = NULL; } if (!array_key_exists("attr", $_GET) or !($attrs = vec_norm(explode(",", $_GET["attr"]), "trim"))) { $attrs = []; } if (!array_key_exists("def", $_GET) or !($defs = vec_norm(explode(";", $_GET["def"]), "trim"))) { $defs = []; } if (!array_key_exists("id", $_GET) or !($ids = vec_norm(explode(",", $_GET["id"]), "trim"))) { $ids = NULL; } $no_definitions = safe_get("no_definitions", $_GET) === "true"; $no_templates = !(safe_get("show_templates", $_GET) === "true"); $start = intval(safe_get("start", $_GET)); $_ = $limit; $limit = intval(safe_get("limit", $_GET)); if ($limit <= 0) { $limit = 5; } if ($limit > $_) { $limit = $_; } if ($ids === NULL) { $searcher = $db->searcher(); if ($names) { $searcher = $searcher->name($names); } if ($forms) { $searcher = $searcher->form($forms); } if ($langs) { $searcher = $searcher->lang($langs); } if ($sparts) { $searcher = $searcher->spart($sparts); } if ($defs) { $searcher = $searcher->definition_parse($defs); } else { if ($no_definitions) { $searcher = $searcher->no_definitions(); } } if ($no_templates) { $attrs[] = "!template"; } foreach ($attrs as $attr) { if (!$attr) { continue; } $a = NULL; if ($reverse = substr($attr, 0, 1) === "!") { $attr = substr($attr, 1); } if (strpos($attr, "=") === FALSE) { $a = ATTR($attr); } else { list($name, $value) = explode("=", $attr, 2); $a = ATTR($name, $value); } if ($a !== NULL) { if (!$reverse) { $searcher = $searcher->only_with_attr($a); } else { $searcher = $searcher->only_without_attr($a); } } } $max_size = $searcher->max_size(); $list = $searcher->limit($start, $limit)->all("name"); if (count($list) === $max_size) { $max_size = NULL; } } else { $max_size = NULL; $list = []; foreach ($ids as $id) { $list[] = WORD(defaultDB(), intval($id)); } } return $list; }