Skip to content

World's first open-source enterprise world model.

The ontology reads as three tables (#524)

WaylandYangc1c657e3df13
diff --git a/web/src/i18n/en.ts b/web/src/i18n/en.ts
index c895e20e..fb5b87ec 100644
--- a/web/src/i18n/en.ts
+++ b/web/src/i18n/en.ts
@@ -1095,6 +1095,26 @@ export const en = {
title: "Ontology",
hint: "Classes & properties",
tabClasses: "Classes",
+ colName: "Name",
+ multiParentHint: "This class has more than one parent; the indentation follows one of them, and the Parent column lists them all",
+ colKey: "Key",
+ colSignature: "Subject → Object",
+ colInstances: "Instances",
+ colFacts: "Facts",
+ colOnClass: "On class",
+ colDatatype: "Type",
+ colUnit: "Unit",
+ colSingleValued: "Single-valued",
+ yes: "Yes",
+ rowsShown: (n: number) => `${n} rows`,
+ viewTable: "Table",
+ switchToTable: "Switch to table view",
+ switchToGraph: "Switch to graph view",
+ viewDiagram: "Graph",
+ axiomTransitive: "Transitive",
+ axiomSymmetric: "Symmetric",
+ axiomAsymmetric: "Asymmetric",
+ axiomIrreflexive: "Irreflexive",
tabProperties: "Properties",
newClass: "New class",
newSubClass: "New sub-class",
diff --git a/web/src/i18n/zh.ts b/web/src/i18n/zh.ts
index afadf184..151cd730 100644
--- a/web/src/i18n/zh.ts
+++ b/web/src/i18n/zh.ts
@@ -980,6 +980,26 @@ export const zh: Strings = {
title: "本体",
hint: "类与属性",
tabClasses: "类",
+ colName: "名称",
+ multiParentHint: "这个类有不止一个父类;缩进挂在其中一个,父类那一列把它们都列着",
+ colKey: "键",
+ colSignature: "主语 → 宾语",
+ colInstances: "实例",
+ colFacts: "事实",
+ colOnClass: "挂在",
+ colDatatype: "类型",
+ colUnit: "单位",
+ colSingleValued: "单值",
+ yes: "是",
+ rowsShown: (n: number) => `${n} 行`,
+ viewTable: "表格",
+ switchToTable: "切换到表格视图",
+ switchToGraph: "切换到图视图",
+ viewDiagram: "图",
+ axiomTransitive: "传递",
+ axiomSymmetric: "对称",
+ axiomAsymmetric: "反对称",
+ axiomIrreflexive: "非自反",
tabProperties: "属性",
newClass: "新建类",
newSubClass: "新建子类",
diff --git a/web/src/pages/Ontology.tsx b/web/src/pages/Ontology.tsx
index 6742a396..cc31e06a 100644
--- a/web/src/pages/Ontology.tsx
+++ b/web/src/pages/Ontology.tsx
@@ -7,16 +7,18 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { Link, useNavigate } from "@tanstack/react-router";
import {
ArrowLeft,
+ ArrowLeftRight,
ArrowRight,
ChevronRight,
Inbox,
Link2,
- Scale,
Network,
Pencil,
Plus,
+ Scale,
Search,
Split,
+ Table as TableIcon,
Upload,
Wand2,
X,
@@ -34,6 +36,7 @@ import {
type RelationTypeView,
type UniquenessCandidate,
} from "../api";
+import { OntologyTables, treeParent } from "./ontologyTables";
import { S } from "../i18n";
import { useKb } from "../kb";
import { toast } from "../toast";
@@ -62,7 +65,6 @@ import {
RAIL_CLS,
cn,
pageSlice,
- GroupLabel,
PageHeader,
Dialog,
LinkButton,
@@ -78,10 +80,12 @@ import {
/** 左栏行高(py-2 + 13px 文字 + space-y 间隙)与底部预留(新建行 + 分页器) */
const RAIL_ROW_H = 34;
const RAIL_RESERVED = 80;
+/** 上次看的是表还是图。**per 浏览器不 per 库**:这是读法的习惯,
+ * 换个知识库不会换读法 */
+const VIEW_KEY = "utopia.ontology.view";
/** 兜底页行数(首帧未量到高度时用) */
const RAIL_PAGE = 14;
/** 过滤模式两节混排时每节的行数 */
-const RAIL_PAGE_MIXED = 6;
/** 右侧详情区当前展示什么。
*
@@ -128,6 +132,33 @@ export function Ontology() {
const [sel, setSel] = useState<Sel>(null);
const [edit, setEdit] = useState<Edit>(null);
const [railTab, setRailTab] = useState<"classes" | "properties">("classes");
+ /* 主区看图还是看表(#498)。**默认图**,而且**记住上次那一版**——这是
+ "我习惯怎么读这一页",不是"这个链接指向什么",所以进 localStorage 不进
+ URL(与知识库切换器同一条判断,见 KbScope)。隐私模式下读写都会抛,
+ catch 掉回落到默认,别让整页挂掉 */
+ const [view, setView] = useState<"table" | "diagram">(() => {
+ try {
+ return localStorage.getItem(VIEW_KEY) === "table" ? "table" : "diagram";
+ } catch {
+ return "diagram";
+ }
+ });
+ const switchView = (v: "table" | "diagram") => {
+ setView(v);
+ try {
+ localStorage.setItem(VIEW_KEY, v);
+ } catch {
+ // 存不下就只在这一次会话里记着
+ }
+ if (!onPanel(sel)) setSel({ kind: "schema" });
+ };
+ /** Import / Rules / Refine / Overlaps / Unmatched 那几页把主区整个接管了 */
+ const inWorkflow =
+ sel?.kind === "import" ||
+ sel?.kind === "refine" ||
+ sel?.kind === "uniqueness" ||
+ sel?.kind === "rules" ||
+ sel?.kind === "misses";
// 模式图详情面板停在哪一段。**跨选中保留**:在实例上挨个类看下去,
// 是一种真实的读法,每换一个类就被弹回定义页会打断它
const [panelTab, setPanelTab] = useState<
@@ -248,42 +279,71 @@ export function Ontology() {
<aside className={`${RAIL_CLS} flex flex-col`}>
{/* 与图谱页的搜索框同一副身材、同一个角落(左上各 12px、中号、232 宽):
两个标签页切来切去,框留在原地 */}
- <div className="px-2 pt-3 pb-1">
- <Input
- icon={<Search size={12} />}
- placeholder={S.ontology.filter}
- value={filter}
- onChange={(e) => setFilter(e.target.value)}
- />
- </div>
- {/* 模式图:本体结构的主视图,不是 Import/Refine/Unmatched 那种管理性操作——
- 放在筛选框正下方、列表上方,与那三个钉在底部的按钮拉开位置,
- 视觉上就说明了「这是浏览本体的另一种方式」而不是「这是一项维护动作」 */}
- <div className="px-2 pb-1">
+ {/* 图 / 表:这一页的两种画法。**排在筛选框上面**——它定的是这一页
+ 是什么,筛选框是在里面找东西;而且表格那一档筛选框是收起的,
+ 切换键排在下面的话位置会跟着跳。
+
+ **一个键,写的是要去的那一版**:两档并排的话,得先读出哪一档亮着
+ 才知道自己在看什么,而主区摆的是表还是图一眼就看得出。
+
+ **Import / Rules / Refine / Overlaps / Unmatched 接管主区时,它是
+ 回去的路**——那时候写的是你原本在看的那一版,点了就回去。从前这条路
+ 是「Schema diagram」那一行,换成切换键之后断过一阵:进了 Import
+ 再没有任何一处能回到图或表。
+
+ **自成一组**:与底下钉住那一组同一个做法,外层一条线加 py-2 隔开,
+ 行本身不画框——它跟筛选框不是同一类东西,只隔 4px 会读成一串 */}
+ {/* 上面一行是**动作**(换到另一版),下面一行是**位置**(现在看的是哪一版)。
+ 一行里塞两件事,就成了「这个键写的到底是我在哪儿、还是我要去哪儿」;
+ 分成两行之后,位置那一行还兼着从 Import / Rules 那几页回来的路——
+ 它们把主区整个接管,从前没有任何一处能回到图或表。
+ **自成一组**:与底下钉住那一组同一个做法,外层一条线加 py-2 隔开 */}
+ <div className="u-rail-list shrink-0 border-b border-line px-2 py-2">
+ <Row
+ density="nav"
+ icon={<ArrowLeftRight size={14} />}
+ onClick={() => switchView(view === "diagram" ? "table" : "diagram")}
+ >
+ {view === "diagram"
+ ? S.ontology.switchToTable
+ : S.ontology.switchToGraph}
+ </Row>
<Row
density="nav"
- active={sel?.kind === "schema"}
- icon={<Network size={14} />}
+ active={!inWorkflow}
+ icon={
+ view === "diagram" ? <Network size={14} /> : <TableIcon size={14} />
+ }
onClick={() => setSel({ kind: "schema" })}
>
- {S.ontology.schemaDiagram}
+ {view === "diagram" ? S.ontology.viewDiagram : S.ontology.viewTable}
</Row>
</div>
- {/* 分段切换:与登录页模式切换/日程选择器同一语汇(bg-surface-2 容器 + 激活反白);
- 过滤时列表例外:两节混排同时给出命中 */}
- {/* 撑满的东西不能再带外边距:w-full 是按父容器算的,mx-3 只会把它往右
- 推出侧栏 12px。缩进交给外层 */}
- <div className="px-2 pb-1">
- <Segmented
- fill
- value={railTab}
- onChange={setRailTab}
- options={[
- { value: "classes", label: S.ontology.tabClasses },
- { value: "properties", label: S.ontology.tabProperties },
- ]}
- />
- </div>
+ {/* 筛选框、两档、清单**只属于图那一档**——表格自己就是清单,而且比这一列
+ 强(有列、能排序、带计数)。换档时它们**折起来**而不是瞬间消失:
+ 左栏是一直在的,一整段凭空没掉会让人以为跳到了别的页 */}
+ <div
+ className={cn("u-rail-fold", view === "table" && "is-folded")}
+ >
+ <div className="px-2 pt-3 pb-1">
+ <Input
+ icon={<Search size={12} />}
+ placeholder={S.ontology.filter}
+ value={filter}
+ onChange={(e) => setFilter(e.target.value)}
+ />
+ </div>
+ <div className="px-2 pb-1">
+ <Segmented
+ fill
+ value={railTab}
+ onChange={setRailTab}
+ options={[
+ { value: "classes", label: S.ontology.tabClasses },
+ { value: "properties", label: S.ontology.tabProperties },
+ ]}
+ />
+ </div>
<div
ref={listRef}
className="flex-1 min-h-0 overflow-hidden px-2 pb-2 flex flex-col"
@@ -306,28 +366,11 @@ export function Ontology() {
: S.ontology.newProperty}
</Row>
)}
- {filter.trim() ? (
- <>
- <GroupLabel className="px-2 pt-2 pb-1">{S.ontology.tabClasses}</GroupLabel>
- <ClassTree
- types={entity_types}
- filter={filter}
- collapsed={collapsed}
- onToggle={() => {}}
- selectedId={selectedClass?.id ?? null}
- onSelect={(id) => setSel({ kind: "class", id })}
- pageSize={RAIL_PAGE_MIXED}
- />
- <GroupLabel className="px-2 pt-3 pb-1">{S.ontology.tabProperties}</GroupLabel>
- <PropertyList
- relations={relations}
- filter={filter}
- selectedId={selectedProp?.id ?? null}
- onSelect={(id) => setSel({ kind: "relation", id })}
- pageSize={RAIL_PAGE_MIXED}
- />
- </>
- ) : railTab === "classes" ? (
+ {/* **筛选也认这两档**。从前一有筛选词就两节混排、类与关系一起给,
+ 理由是"搜的时候未必知道要找的是哪一种";代价是标签明明停在
+ Classes 上却不算数,而它就在上面两厘米处。一个选中却被无视的
+ 控件,比多点一下糟。想找关系就切过去,那一下是明的 */}
+ {railTab === "classes" ? (
<ClassTree
types={entity_types}
filter={filter}
@@ -352,6 +395,7 @@ export function Ontology() {
/>
)}
</div>
+ </div>
{/* 底部常驻:关于本体的几个入口——从外部拿一份本体、业务规则、类型消解,
以及数据顶回来的两种信号。一条分隔线说明它们是钉住的,行本身与上面
列表里的行同一副样子 */}
@@ -466,7 +510,26 @@ export function Ontology() {
</div>
) : (
<div className="flex-1 min-w-0 relative">
- <OntologySchemaGraph
+ {view === "table" ? (
+ <OntologyTables
+ entityTypes={entity_types}
+ relationTypes={relation_types}
+ onOpenClass={(t) => setSel({ kind: "class", id: t.id })}
+ onOpenProperty={(r) => setSel({ kind: "relation", id: r.id })}
+ onOpenAttribute={(a) =>
+ setEdit({
+ kind: "attribute",
+ typeId: a.domains[0] ?? "",
+ existing: a,
+ })
+ }
+ onSeeInstances={(t) => {
+ setPanelTab("instances");
+ setSel({ kind: "class", id: t.id });
+ }}
+ />
+ ) : (
+ <OntologySchemaGraph
entityTypes={entity_types}
relationTypes={relation_types}
rules={rules.data?.rules ?? []}
@@ -487,7 +550,8 @@ export function Ontology() {
)
: closePanel()
}
- />
+ />
+ )}
{selectedClass && (
<DockedPanel
onClose={closePanel}
@@ -1035,7 +1099,7 @@ function ClassTree({
}
const children = new Map<string | null, EntityTypeView[]>();
for (const t of types) {
- const p = t.primary_parent ?? null;
+ const p = treeParent(t);
if (!children.has(p)) children.set(p, []);
children.get(p)!.push(t);
}
diff --git a/web/src/pages/ontologyTables.tsx b/web/src/pages/ontologyTables.tsx
new file mode 100644
index 00000000..addba142
--- /dev/null
+++ b/web/src/pages/ontologyTables.tsx
@@ -0,0 +1,540 @@
+// 本体读成三张表(#498)。
+//
+// 从前这一页一次只讲一个类:左栏一列名字,画布一张图,右边一块面板讲你点中的
+// 那一个。凡是横跨本体的问题都没有地方问——哪些属性声明了唯一、导入了九百个类
+// 之后哪些一个实例都没有、哪些关系连 domain 都没写(于是抽取拿不到签名)、
+// 这个库到底有哪些属性。最后一个尤其:属性只出现在某个类的面板里,一次一个类,
+// 「这个库有哪些属性」在界面上没有任何地方回答得了。
+//
+// 这个月别的同类页面都已经是表了——令牌、数据源、成员、部署用户、业务规则
+// (#482 里那句「一列卡片跟我们刚重做的任何东西都不像」)。本体是最后一个,
+// 也是列数最多的一个。
+//
+// **层级怎么办**:`subClassOf` 是本体的骨架,拍平就丢了。所以默认按层级排、
+// 名字列带缩进;按别的列排序就拍平,而父类那一列一直在,拍平不丢信息,只是
+// 换了一种读法。文件管理器就是这么做的。
+
+import { useMemo, useState } from "react";
+
+import type { EntityTypeView, RelationTypeView } from "../api";
+import { S } from "../i18n";
+import {
+ Chip,
+ cn,
+ GroupLabel,
+ Input,
+ LinkButton,
+ ROW_TRAILING,
+ Segmented,
+ Table,
+ TBody,
+ Td,
+ Th,
+ THead,
+ Tr,
+} from "../ui";
+
+export type TableTab = "classes" | "properties" | "attributes";
+
+/** 这一行挂在谁下面。**没有主父类就退回第一个父类**:`primary_parent` 只在
+ * 人手动指定时才写,而导入的包一个都没有——schema.org 那 916 个类里是 0 个。
+ * 只认它的话,任何导入来的本体在树里都是平的一长条,层级完全看不见。
+ *
+ * **一个类可以有多个父类**(`parents` 是个数组;schema.org 这 916 个里有 48 个
+ * 是这样,FOAF 的 Person 同时是 Agent 与 SpatialThing)。一行只能挂在一处,
+ * 所以缩进选的是其中之一——那一列把全部父类都列出来,行上再标一个记号说
+ * 「还有别的」,缩进就不至于冒充成唯一的真相 */
+export function treeParent(t: EntityTypeView): string | null {
+ return t.primary_parent ?? t.parents[0] ?? null;
+}
+
+/** 名字列的缩进:一层 12px。与左栏那棵树同一个做法 */
+const INDENT = 12;
+
+/* ---------- 排序 ---------- */
+
+type Sort = { col: string; dir: "asc" | "desc" } | null;
+
+/** 可排序的表头。**排序把层级拍平**(见文件头)——所以名字列不排序,它就是
+ * 层级本身;点别的列才进入「平铺」那种读法 */
+function SortTh({
+ col,
+ sort,
+ onSort,
+ className,
+ children,
+}: {
+ col: string;
+ sort: Sort;
+ onSort: (s: Sort) => void;
+ className?: string;
+ children: React.ReactNode;
+}) {
+ const active = sort?.col === col;
+ return (
+ <Th className={className}>
+ <LinkButton
+ className="inline-flex items-center gap-1"
+ onClick={() =>
+ onSort(
+ active && sort.dir === "desc"
+ ? null
+ : { col, dir: active ? "desc" : "asc" },
+ )
+ }
+ >
+ {children}
+ {active && <span className="u-num">{sort.dir === "asc" ? "↑" : "↓"}</span>}
+ </LinkButton>
+ </Th>
+ );
+}
+
+function sorted<T>(rows: T[], sort: Sort, key: (r: T) => string | number) {
+ if (!sort) return rows;
+ const out = [...rows].sort((a, b) => {
+ const x = key(a);
+ const y = key(b);
+ return typeof x === "number" && typeof y === "number"
+ ? x - y
+ : String(x).localeCompare(String(y));
+ });
+ return sort.dir === "asc" ? out : out.reverse();
+}
+
+/* ---------- 类 ---------- */
+
+/** 按 primary_parent 排成层级序,带每行的深度。过滤或排序时拍平 */
+function classRows(
+ types: EntityTypeView[],
+ flat: boolean,
+): { t: EntityTypeView; depth: number }[] {
+ if (flat) return types.map((t) => ({ t, depth: 0 }));
+ const children = new Map<string | null, EntityTypeView[]>();
+ for (const t of types) {
+ const p = treeParent(t);
+ if (!children.has(p)) children.set(p, []);
+ children.get(p)!.push(t);
+ }
+ const out: { t: EntityTypeView; depth: number }[] = [];
+ const seen = new Set<string>();
+ const walk = (parent: string | null, depth: number) => {
+ for (const t of children.get(parent) ?? []) {
+ if (seen.has(t.id)) continue; // 父类互指成环也走不死
+ seen.add(t.id);
+ out.push({ t, depth });
+ walk(t.id, depth + 1);
+ }
+ };
+ walk(null, 0);
+ // 父类不在这份清单里的(被过滤掉了)挂不上树,补在末尾——不能因为排不进
+ // 层级就不显示
+ for (const t of types) if (!seen.has(t.id)) out.push({ t, depth: 0 });
+ return out;
+}
+
+function ClassesTable({
+ types,
+ attributes,
+ filter,
+ onOpen,
+ onSeeInstances,
+}: {
+ types: EntityTypeView[];
+ attributes: RelationTypeView[];
+ filter: string;
+ onOpen: (t: EntityTypeView) => void;
+ onSeeInstances: (t: EntityTypeView) => void;
+}) {
+ const [sort, setSort] = useState<Sort>(null);
+ const nameOf = useMemo(
+ () => new Map(types.map((t) => [t.id, t.label])),
+ [types],
+ );
+ const attrCount = useMemo(() => {
+ const m = new Map<string, number>();
+ for (const a of attributes)
+ for (const d of a.domains) m.set(d, (m.get(d) ?? 0) + 1);
+ return m;
+ }, [attributes]);
+
+ const q = filter.trim().toLowerCase();
+ const hit = (t: EntityTypeView) =>
+ !q || t.label.toLowerCase().includes(q) || t.key.toLowerCase().includes(q);
+ const shown = types.filter(hit);
+ // 过滤中或排序中都拍平:两种情况下层级都不再是这份清单的次序
+ const rows = classRows(sorted(shown, sort, (t) =>
+ sort?.col === "usage" ? t.usage
+ : sort?.col === "attrs" ? (attrCount.get(t.id) ?? 0)
+ : sort?.col === "parent" ? (treeParent(t) ? (nameOf.get(treeParent(t)!) ?? "") : "")
+ : t.label,
+ ), !!sort || !!q);
+
+ return (
+ <Table>
+ <THead>
+ <Tr>
+ <Th>{S.ontology.colName}</Th>
+ <Th className="hidden md:table-cell">{S.ontology.colKey}</Th>
+ <SortTh col="parent" sort={sort} onSort={setSort}>
+ {S.ontology.parent}
+ </SortTh>
+ <Th className="hidden lg:table-cell">{S.ontology.disjoint}</Th>
+ <SortTh col="usage" sort={sort} onSort={setSort} className="text-right">
+ {S.ontology.colInstances}
+ </SortTh>
+ <SortTh col="attrs" sort={sort} onSort={setSort} className="text-right">
+ {S.ontology.schemaTabAttributes}
+ </SortTh>
+ </Tr>
+ </THead>
+ <TBody>
+ {rows.map(({ t, depth }) => (
+ <Tr key={t.id} interactive onClick={() => onOpen(t)}>
+ <Td>
+ <span
+ className="flex items-center gap-2"
+ style={{ paddingLeft: depth * INDENT }}
+ >
+ <span
+ className={cn(
+ "h-2 w-2 shrink-0",
+ t.shape === "square" ? "scale-90" : "rounded-full",
+ )}
+ style={{ background: t.color }}
+ />
+ <span className="truncate">{t.label}</span>
+ {/* 多父类:缩进只挂得住一处,这个记号说还有几处,父类那一列
+ 把它们都列着 */}
+ {t.parents.length > 1 && (
+ <span
+ className="u-chip u-chip-neutral shrink-0 !px-2 !text-fine"
+ title={S.ontology.multiParentHint}
+ >
+ +{t.parents.length - 1}
+ </span>
+ )}
+ {t.builtin && <Chip tone="neutral">{S.ontology.builtin}</Chip>}
+ </span>
+ </Td>
+ <Td className="hidden font-mono text-small text-ink-2 md:table-cell">
+ {t.key}
+ </Td>
+ <Td className="text-small text-ink-2">
+ {t.parents.length
+ ? t.parents.map((p) => nameOf.get(p) ?? p).join(", ")
+ : "—"}
+ </Td>
+ <Td className="hidden text-small text-ink-2 lg:table-cell">
+ {t.disjoint.length
+ ? t.disjoint.map((d) => nameOf.get(d) ?? d).join(", ")
+ : "—"}
+ </Td>
+ <Td className="text-right">
+ {t.usage > 0 ? (
+ <LinkButton
+ className="u-num"
+ onClick={(e) => {
+ e.stopPropagation();
+ onSeeInstances(t);
+ }}
+ >
+ {t.usage}
+ </LinkButton>
+ ) : (
+ <span className="u-num text-ink-2">0</span>
+ )}
+ </Td>
+ <Td className="u-num text-right text-ink-2">
+ {attrCount.get(t.id) ?? 0}
+ </Td>
+ </Tr>
+ ))}
+ </TBody>
+ </Table>
+ );
+}
+
+/* ---------- 关系 ---------- */
+
+/** 公理做成几个字母的芯片而不是六个勾:一行里六个复选框读不出「这条关系
+ * 保证了什么」,几个字母能顺着一列扫下去 */
+function Axioms({ r }: { r: RelationTypeView }) {
+ const on: [boolean, string, string][] = [
+ [r.functional, "F", S.ontology.functional],
+ [r.inverse_functional, "IF", S.ontology.inverseFunctional],
+ [r.is_transitive, "T", S.ontology.axiomTransitive],
+ [r.is_symmetric, "S", S.ontology.axiomSymmetric],
+ [r.is_asymmetric, "A", S.ontology.axiomAsymmetric],
+ [r.is_irreflexive, "IR", S.ontology.axiomIrreflexive],
+ ];
+ const shown = on.filter(([v]) => v);
+ if (shown.length === 0) return <span className="text-ink-2">—</span>;
+ return (
+ <span className="flex flex-wrap gap-1">
+ {shown.map(([, mark, title]) => (
+ <span key={mark} className="u-chip u-chip-neutral !px-2 !text-fine" title={title}>
+ {mark}
+ </span>
+ ))}
+ </span>
+ );
+}
+
+function PropertiesTable({
+ relations,
+ types,
+ filter,
+ onOpen,
+}: {
+ relations: RelationTypeView[];
+ types: EntityTypeView[];
+ filter: string;
+ onOpen: (r: RelationTypeView) => void;
+}) {
+ const [sort, setSort] = useState<Sort>(null);
+ const nameOf = useMemo(
+ () => new Map(types.map((t) => [t.id, t.label])),
+ [types],
+ );
+ const relName = useMemo(
+ () => new Map(relations.map((r) => [r.id, r.label])),
+ [relations],
+ );
+ const q = filter.trim().toLowerCase();
+ const shown = relations.filter(
+ (r) =>
+ !q || r.label.toLowerCase().includes(q) || r.key.toLowerCase().includes(q),
+ );
+ const side = (ids: string[]) =>
+ ids.length ? ids.map((i) => nameOf.get(i) ?? i).join(", ") : S.ontology.anyType;
+ const rows = sorted(shown, sort, (r) =>
+ sort?.col === "usage" ? r.usage
+ : sort?.col === "temporal" ? r.temporal
+ : r.label,
+ );
+
+ return (
+ <Table>
+ <THead>
+ <Tr>
+ <Th>{S.ontology.colName}</Th>
+ <Th className="hidden md:table-cell">{S.ontology.colKey}</Th>
+ <Th>{S.ontology.colSignature}</Th>
+ <SortTh col="temporal" sort={sort} onSort={setSort}>
+ {S.ontology.temporal}
+ </SortTh>
+ <Th>{S.ontology.axioms}</Th>
+ <Th className="hidden lg:table-cell">{S.ontology.inverseOf}</Th>
+ <SortTh col="usage" sort={sort} onSort={setSort} className="text-right">
+ {S.ontology.colFacts}
+ </SortTh>
+ </Tr>
+ </THead>
+ <TBody>
+ {rows.map((r) => (
+ <Tr key={r.id} interactive onClick={() => onOpen(r)}>
+ <Td>
+ <span className="flex items-center gap-2">
+ <span className="truncate">{r.label}</span>
+ {r.builtin && <Chip tone="neutral">{S.ontology.builtin}</Chip>}
+ </span>
+ </Td>
+ <Td className="hidden font-mono text-small text-ink-2 md:table-cell">
+ {r.key}
+ </Td>
+ <Td className="text-small text-ink-2">
+ {side(r.domains)} → {side(r.ranges)}
+ </Td>
+ <Td className="text-small text-ink-2">
+ {r.temporal === "event"
+ ? S.ontology.temporalEvent
+ : r.temporal === "eternal"
+ ? S.ontology.temporalEternal
+ : S.ontology.temporalState}
+ </Td>
+ <Td>
+ <Axioms r={r} />
+ </Td>
+ <Td className="hidden text-small text-ink-2 lg:table-cell">
+ {r.inverse_of ? (relName.get(r.inverse_of) ?? "—") : "—"}
+ </Td>
+ <Td className="u-num text-right text-ink-2">{r.usage}</Td>
+ </Tr>
+ ))}
+ </TBody>
+ </Table>
+ );
+}
+
+/* ---------- 属性 ---------- */
+
+/** 属性单开一张表,是这三张里最能说明问题的一张:从前属性只在某个类的面板里
+ * 露面,一次一个类,「这个库有哪些属性」在界面上没有任何地方回答得了 */
+function AttributesTable({
+ attributes,
+ types,
+ filter,
+ onOpen,
+}: {
+ attributes: RelationTypeView[];
+ types: EntityTypeView[];
+ filter: string;
+ onOpen: (a: RelationTypeView) => void;
+}) {
+ const [sort, setSort] = useState<Sort>(null);
+ const nameOf = useMemo(
+ () => new Map(types.map((t) => [t.id, t.label])),
+ [types],
+ );
+ const q = filter.trim().toLowerCase();
+ const shown = attributes.filter(
+ (a) =>
+ !q || a.label.toLowerCase().includes(q) || a.key.toLowerCase().includes(q),
+ );
+ const rows = sorted(shown, sort, (a) =>
+ sort?.col === "usage" ? a.usage
+ : sort?.col === "datatype" ? (a.datatype ?? "")
+ : sort?.col === "domain" ? (a.domains[0] ? (nameOf.get(a.domains[0]) ?? "") : "")
+ : a.label,
+ );
+
+ return (
+ <Table>
+ <THead>
+ <Tr>
+ <Th>{S.ontology.colName}</Th>
+ <Th className="hidden md:table-cell">{S.ontology.colKey}</Th>
+ <SortTh col="domain" sort={sort} onSort={setSort}>
+ {S.ontology.colOnClass}
+ </SortTh>
+ <SortTh col="datatype" sort={sort} onSort={setSort}>
+ {S.ontology.colDatatype}
+ </SortTh>
+ <Th>{S.ontology.colUnit}</Th>
+ <Th>{S.ontology.colSingleValued}</Th>
+ <SortTh col="usage" sort={sort} onSort={setSort} className="text-right">
+ {S.ontology.colFacts}
+ </SortTh>
+ </Tr>
+ </THead>
+ <TBody>
+ {rows.map((a) => (
+ <Tr key={a.id} interactive onClick={() => onOpen(a)}>
+ <Td className="truncate">{a.label}</Td>
+ <Td className="hidden font-mono text-small text-ink-2 md:table-cell">
+ {a.key}
+ </Td>
+ <Td className="text-small text-ink-2">
+ {a.domains.length
+ ? a.domains.map((d) => nameOf.get(d) ?? d).join(", ")
+ : "—"}
+ </Td>
+ <Td className="text-small text-ink-2">{a.datatype ?? "—"}</Td>
+ <Td className="text-small text-ink-2">{a.unit || "—"}</Td>
+ <Td className="text-small text-ink-2">
+ {a.functional ? S.ontology.yes : "—"}
+ </Td>
+ <Td className="u-num text-right text-ink-2">{a.usage}</Td>
+ </Tr>
+ ))}
+ </TBody>
+ </Table>
+ );
+}
+
+/* ---------- 三张表 ---------- */
+
+export function OntologyTables({
+ entityTypes,
+ relationTypes,
+ onOpenClass,
+ onOpenProperty,
+ onOpenAttribute,
+ onSeeInstances,
+}: {
+ entityTypes: EntityTypeView[];
+ relationTypes: RelationTypeView[];
+ onOpenClass: (t: EntityTypeView) => void;
+ onOpenProperty: (r: RelationTypeView) => void;
+ onOpenAttribute: (a: RelationTypeView) => void;
+ onSeeInstances: (t: EntityTypeView) => void;
+}) {
+ const [tab, setTab] = useState<TableTab>("classes");
+ const [filter, setFilter] = useState("");
+ const relations = relationTypes.filter((r) => r.kind === "relation");
+ const attributes = relationTypes.filter((r) => r.kind === "attribute");
+ const counts: Record<TableTab, number> = {
+ classes: entityTypes.length,
+ properties: relations.length,
+ attributes: attributes.length,
+ };
+
+ return (
+ <div className="flex h-full min-w-0 flex-col">
+ {/* 操作表里内容的控件在表**外面**(规矩 6):过滤清空之后表会变成空状态,
+ 而把过滤框放进去就等于把唯一能改回来的东西一起藏了 */}
+ <div className="flex shrink-0 items-center gap-4 px-8 pt-6 pb-3">
+ <Segmented<TableTab>
+ value={tab}
+ onChange={setTab}
+ options={(["classes", "properties", "attributes"] as const).map(
+ (v) => ({
+ value: v,
+ label:
+ v === "classes"
+ ? S.ontology.tabClasses
+ : v === "properties"
+ ? S.ontology.tabProperties
+ : S.ontology.schemaTabAttributes,
+ count: counts[v],
+ }),
+ )}
+ />
+ <Input
+ icon={<span className="text-ink-2">/</span>}
+ className="w-58"
+ placeholder={S.ontology.filter}
+ value={filter}
+ onChange={(e) => setFilter(e.target.value)}
+ />
+ <GroupLabel className={cn(ROW_TRAILING, "shrink-0")}>
+ {S.ontology.rowsShown(
+ tab === "classes"
+ ? counts.classes
+ : tab === "properties"
+ ? counts.properties
+ : counts.attributes,
+ )}
+ </GroupLabel>
+ </div>
+ <div className="u-scroll min-h-0 flex-1 overflow-y-auto px-8 pb-6">
+ {tab === "classes" && (
+ <ClassesTable
+ types={entityTypes}
+ attributes={attributes}
+ filter={filter}
+ onOpen={onOpenClass}
+ onSeeInstances={onSeeInstances}
+ />
+ )}
+ {tab === "properties" && (
+ <PropertiesTable
+ relations={relations}
+ types={entityTypes}
+ filter={filter}
+ onOpen={onOpenProperty}
+ />
+ )}
+ {tab === "attributes" && (
+ <AttributesTable
+ attributes={attributes}
+ types={entityTypes}
+ filter={filter}
+ onOpen={onOpenAttribute}
+ />
+ )}
+ </div>
+ </div>
+ );
+}
diff --git a/web/src/styles.css b/web/src/styles.css
index df4b492f..9552525f 100644
--- a/web/src/styles.css
+++ b/web/src/styles.css
@@ -1152,6 +1152,49 @@ a:hover > .u-mark-arrow {
gap: 2px;
}
+/* 左栏里跟着视图折起来的那一段(筛选框 + 两档 + 清单)。
+ **折的是 flex-grow 不是 height**:这一段是 `flex-1` 撑满剩余空间的,
+ 它没有一个"自然高度"可以从那儿往 0 收;grow 从 1 到 0 是同一件事的
+ 可动画版本,而且不必量任何东西。
+ 收起时一并断掉指针事件——一个透明度为 0 的清单还能点中,是最难查的那种错 */
+.u-rail-fold {
+ display: flex;
+ flex-direction: column;
+ flex: 1 1 0;
+ min-height: 0;
+ overflow: hidden;
+ opacity: 1;
+ transform: translateY(0);
+ /* 展开:与停靠面板、弹层进场同一条曲线、同一档时长(0.18s / 出挑缓动)。
+ **三条通道走同一个时长**——从前高度 260ms、不透明度 120ms,字一下子就没了,
+ 剩一个空盒子慢慢收,读起来就是两件事而不是一件 */
+ transition:
+ flex-grow 0.18s cubic-bezier(0.16, 1, 0.3, 1),
+ opacity 0.18s cubic-bezier(0.16, 1, 0.3, 1),
+ transform 0.18s cubic-bezier(0.16, 1, 0.3, 1);
+}
+.u-rail-fold.is-folded {
+ /* 收起:离场曲线、略快,与 u-dock-out 一对(0.15s)。走的方向不同,
+ 手感就不该是同一条曲线来回放 */
+ transition:
+ flex-grow 0.15s cubic-bezier(0.4, 0, 1, 1),
+ opacity 0.15s cubic-bezier(0.4, 0, 1, 1),
+ transform 0.15s cubic-bezier(0.4, 0, 1, 1);
+ flex-grow: 0;
+ opacity: 0;
+ /* 往上收一点:这一段是被上面那两行「卷」进去的,纯粹缩高度看着像被下面
+ 的东西盖住 */
+ transform: translateY(-6px);
+ pointer-events: none;
+}
+@media (prefers-reduced-motion: reduce) {
+ /* 收起态那条 transition 特异性更高,只写 `.u-rail-fold` 盖不住它 */
+ .u-rail-fold,
+ .u-rail-fold.is-folded {
+ transition: none;
+ }
+}
+
/* ---- numbers in chrome: 默认字体(Geist)+ 等宽数字,不再用 mono ---- */
.u-num {
font-variant-numeric: tabular-nums;