Fix cross-module fallout: stemmer, oracle, overlay cost, test fixtures
This commit is contained in:
1 parent
ee6fc292d8
commit
2907e7df15
13 files changed
+218
-177
No files matched your search
+38
-6
@@ -1,16 +1,38 @@
|
||||
"""Owner statements, printed by `sisi oracle`. One store: learning records with owner_statement.
|
||||
|
||||
`sisi learn` writes them and `sisi oracle` prints them. The old parallel stores
|
||||
(learn.jsonl, oracle.md) are merged by the migration in lifecycle.py.
|
||||
(learn.jsonl, oracle.md) are merged by the migration in lifecycle.py; until an install
|
||||
has migrated, statements are still read from learn.jsonl so nothing goes silent.
|
||||
"""
|
||||
from . import learning as L
|
||||
import json, os
|
||||
|
||||
from . import learning as L, paths
|
||||
|
||||
|
||||
def _legacy_statements():
|
||||
try:
|
||||
from . import store
|
||||
rows = store.read("learn") # also folds any quarantine file in, losslessly
|
||||
except Exception:
|
||||
rows = []
|
||||
try:
|
||||
with open(paths.data_file("learn.jsonl"), encoding="utf-8") as f:
|
||||
rows = [json.loads(x) for x in f if x.strip()]
|
||||
except (OSError, ValueError):
|
||||
pass
|
||||
return [{"text": r.get("text") or r.get("statement") or "",
|
||||
"scope": r.get("scope") or "user", "ts": r.get("ts") or "", "id": None}
|
||||
for r in rows if (r.get("text") or r.get("statement"))]
|
||||
|
||||
|
||||
def statements():
|
||||
return [{"text": r.get("proposed", {}).get("description") or r.get("title", ""),
|
||||
recs = [{"text": r.get("proposed", {}).get("description") or r.get("title", ""),
|
||||
"scope": r.get("proposed", {}).get("scope") or "user",
|
||||
"ts": r.get("created", ""), "id": r.get("id")}
|
||||
for r in L.owner_statements()]
|
||||
if recs or os.path.exists(L.learnings_path()):
|
||||
return recs
|
||||
return _legacy_statements()
|
||||
|
||||
|
||||
def plain_of(rec):
|
||||
@@ -20,10 +42,20 @@ def plain_of(rec):
|
||||
def oracle_text():
|
||||
recs = statements()
|
||||
if not recs:
|
||||
return "No owner statements recorded. `sisi learn \"<what you want>\"` adds one.\n"
|
||||
lines = ["What the owner wants (recorded with `sisi learn`):"]
|
||||
legacy = paths.data_file("oracle.md")
|
||||
if os.path.exists(legacy):
|
||||
try:
|
||||
with open(legacy, encoding="utf-8") as f:
|
||||
return f.read()
|
||||
except OSError:
|
||||
pass
|
||||
return ("The oracle is empty: no owner statements recorded. "
|
||||
"`sisi learn \"<what you want>\"` adds one.\n")
|
||||
lines = ["Standing principles — what the owner wants, in their words "
|
||||
"(recorded with `sisi learn`; this is the oracle):"]
|
||||
for i, r in enumerate(recs, 1):
|
||||
lines.append("%d. %s" % (i, r["text"]))
|
||||
date = " (%s)" % str(r["ts"])[:10] if r.get("ts") else ""
|
||||
lines.append('%d. "%s"%s' % (i, r["text"], date))
|
||||
return "\n".join(lines) + "\n"
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user