Skip to content

World's first open-source enterprise world model.

An entity panel lists the entity's names (#711)

WaylandYanga4dca3d7a215
diff --git a/web/src/api.ts b/web/src/api.ts
index 69f56ab1..b2e20a84 100644
--- a/web/src/api.ts
+++ b/web/src/api.ts
@@ -888,6 +888,20 @@ export interface GraphEdge {
qualifiers: FactQualifier[];
}
+/** 实体的一个名字(0041)。`canonical` 是面板标题上那个;曾用名在世界轴上有结束 */
+export interface NameView {
+ fact_id: string;
+ name: string;
+ canonical: boolean;
+ recorded_at: string;
+ valid_from: string | null;
+ valid_from_precision: string | null;
+ valid_to: string | null;
+ valid_to_precision: string | null;
+ document_ids: string[];
+ evidence_count: number;
+}
+
export interface EntityFact {
id: string;
direction: "out" | "in";
@@ -1745,6 +1759,9 @@ export const api = {
request<{
entity: GraphNode;
facts: EntityFact[];
+ /** 这个实体的名字(0041):本名、简称、曾用名,各带出处与有效期。
+ * 名字事实不在 facts 里——它不是一条「关于它的事」 */
+ names: NameView[];
/** 推出来的那些**单独一个键**,不掺进 facts:混在同一个列表里,
* 用户看不出「文档里写的」和「引擎推的」的区别 */
derived: DerivedFact[];
diff --git a/web/src/i18n/en.ts b/web/src/i18n/en.ts
index 605f1bb8..cfb468ac 100644
--- a/web/src/i18n/en.ts
+++ b/web/src/i18n/en.ts
@@ -921,6 +921,12 @@ export const en = {
openEntity: (name: string) => `Open ${name}`,
past: (n: number) => (n === 1 ? "1 past" : `${n} past`),
sources: (n: number) => (n === 1 ? "1 source" : `${n} sources`),
+ /* 名字一节(0041):本名、简称、曾用名 */
+ names: "Names",
+ shownName: "shown name",
+ nameUntil: (d: string) => `until ${d}`,
+ removeName: "Remove",
+ nameRemoved: "Name removed",
timelineEmpty: "No dated facts yet.",
lastConfirmed: (d: string) => `confirmed ${d}`,
/* 三种来源共用一个标记(引擎接任对账、Review 裁决、有人手改),所以这句
diff --git a/web/src/i18n/zh.ts b/web/src/i18n/zh.ts
index f7caefde..42e7742d 100644
--- a/web/src/i18n/zh.ts
+++ b/web/src/i18n/zh.ts
@@ -828,6 +828,11 @@ export const zh: Strings = {
openEntity: (name) => `打开 ${name}`,
past: (n) => `${n} 条已结束`,
sources: (n) => `${n} 处来源`,
+ names: "名字",
+ shownName: "显示名",
+ nameUntil: (d) => `至 ${d}`,
+ removeName: "移除",
+ nameRemoved: "已移除这个名字",
timelineEmpty: "还没有带日期的事实。",
lastConfirmed: (d: string) => `${d} 确认`,
correctedHint:
diff --git a/web/src/pages/Graph.tsx b/web/src/pages/Graph.tsx
index fe509c6f..3e4e05f6 100644
--- a/web/src/pages/Graph.tsx
+++ b/web/src/pages/Graph.tsx
@@ -78,6 +78,7 @@ import {
Pencil,
Play,
Search,
+ Tag,
Waypoints,
X,
ZoomIn,
@@ -90,6 +91,7 @@ import {
type Evidence,
type GraphEdge,
type GraphNode,
+ type NameView,
type BlockedDerivation,
type ProofStep,
} from "../api";
@@ -2921,6 +2923,11 @@ function EntityPanel({
</div>
<div className="u-scroll flex-1 overflow-y-auto px-2 py-2">
+ {/* 名字在关系之前:先回答「它叫什么」,再回答「它和谁有关」。只有本名一个的时候
+ 不出这一节——标题上已经写着,再列一遍是噪声 */}
+ {view === "relations" && (detail.data?.names.length ?? 0) > 1 && (
+ <NameSection kbId={kbId} entityId={entityId} names={detail.data!.names} />
+ )}
{view === "relations" &&
(["out", "in"] as const).map((dir) => {
const { rows, past } = sections[dir];
@@ -3099,6 +3106,84 @@ function FactSection({
);
}
+/** 名字一节(0041):本名、简称、曾用名,一个名字一行。
+ *
+ * 名字是一条事实,所以记错的名字也是一条可以撤回的事实——抽取把「OpenAI's」「ChatGPT
+ * apps」记成别名时,从前界面上没有任何地方看得见它,只能等它把两个实体错合了才发现。
+ * 撤回走驳回事实那一条(有审计、能在 History 里看到);本名不给撤,改名在编辑弹窗里 */
+function NameSection({
+ kbId,
+ entityId,
+ names,
+}: {
+ kbId: string;
+ entityId: string;
+ names: NameView[];
+}) {
+ const [open, setOpen] = useState(true);
+ const qc = useQueryClient();
+ const remove = useMutation({
+ mutationFn: (factId: string) => api.rejectFact(kbId, factId),
+ onSuccess: () => {
+ qc.invalidateQueries({ queryKey: ["entity", kbId, entityId] });
+ toast.success(S.graph.nameRemoved);
+ },
+ onError: (err: Error) => toast.error(err.message),
+ });
+ return (
+ <div className="mb-2">
+ <Row
+ className="mt-1"
+ icon={
+ <span className="flex w-4 justify-center">
+ <ChevronRight size={12} className={cn("u-turn", open && "rotate-90")} />
+ </span>
+ }
+ onClick={() => setOpen((v) => !v)}
+ >
+ <span className="flex items-center gap-2 text-small font-medium">
+ <Tag size={12} />
+ <span className="truncate">{S.graph.names}</span>
+ <span className="u-num">{names.length}</span>
+ </span>
+ </Row>
+ {open && (
+ <div className="pl-6">
+ {names.map((n) => {
+ const until = n.valid_to ? fmtTime(n.valid_to, n.valid_to_precision) : null;
+ return (
+ <div key={n.fact_id} className={cn(HOVER_ROW, "items-start", until && "opacity-55")}>
+ <span className="shrink-0 pt-1 text-violet">
+ <Tag size={12} />
+ </span>
+ <span className="min-w-0 flex-1">
+ <span className="block truncate text-body text-ink" title={n.name}>
+ {n.name}
+ </span>
+ <span className="flex items-center gap-2 text-fine text-ink-2">
+ {n.canonical && <span>{S.graph.shownName}</span>}
+ {until && <span className="u-num">{S.graph.nameUntil(until)}</span>}
+ {n.evidence_count > 0 && <span>{S.graph.sources(n.evidence_count)}</span>}
+ {!n.canonical && (
+ <LinkButton
+ className={cn(REVEAL, "ml-auto text-fine")}
+ disabled={remove.isPending}
+ onClick={() => remove.mutate(n.fact_id)}
+ >
+ {S.graph.removeName}
+ </LinkButton>
+ )}
+ </span>
+ </span>
+ </div>
+ );
+ })}
+ </div>
+ )}
+ </div>
+ );
+}
+
/** 已结束的留在同一节里,折起来:默认看现行的,要看来路展开它 */
function PastFold({ n, children }: { n: number; children: ReactNode }) {
const [open, setOpen] = useState(false);