Changesets · Branches · Tags · Compare
| Changeset | 0dc0623dcff5dca4cbecf9a3a74314523ae16b992e8a1bab81ce58a3f1ab1b06 |
|---|---|
| Author | WaylandYang <145302500+WaylandYang@users.noreply.github.com> · 2026-09-02 17:42 +08:00 |
| Committer | GitHub <noreply@github.com> · 2026-09-02 17:42 +08:00 |
| Parents | 19a371c73146 |
6 files changed
modified web/src/api.ts +12 −5
| @@ -291,7 +291,8 @@ | ||
| 291 | 291 | object: string; |
| 292 | 292 | predicate: string; |
| 293 | 293 | /** 靠哪条规则推的 */ |
| 294 | - rule: "transitive" | "symmetric"; | |
| 294 | + /** 靠哪条规则推的。后两种是 0017 补上的跨谓词规则 */ | |
| 295 | + rule: "transitive" | "symmetric" | "inverse" | "sub_property"; | |
| 295 | 296 | valid_from: string | null; |
| 296 | 297 | valid_to: string | null; |
| 297 | 298 | confidence: number; |
| @@ -446,7 +447,11 @@ | ||
| 446 | 447 | | "transitive_and_functional" |
| 447 | 448 | | "subclass_cycle" |
| 448 | 449 | | "disjoint_with_ancestor" |
| 449 | - | "inherits_disjoint"; | |
| 450 | + | "inherits_disjoint" | |
| 451 | + // 0017 加的三类:都在谓词上,前两类关于逆,第三类是子属性成环 | |
| 452 | + | "inverse_of_itself" | |
| 453 | + | "inverse_not_mutual" | |
| 454 | + | "sub_property_cycle"; | |
| 450 | 455 | subject_label: string | null; |
| 451 | 456 | other_label: string | null; |
| 452 | 457 | path_labels: string[]; |
| @@ -642,6 +647,10 @@ | ||
| 642 | 647 | is_symmetric: boolean; |
| 643 | 648 | is_asymmetric: boolean; |
| 644 | 649 | is_irreflexive: boolean; |
| 650 | + /** 指向另一个关系的两条:`p⁻¹ = q` 与 `p ⊑ q`。是 id 不是布尔, | |
| 651 | + * 所以界面上是下拉框 */ | |
| 652 | + inverse_of: string | null; | |
| 653 | + sub_property_of: string | null; | |
| 645 | 654 | builtin: boolean; |
| 646 | 655 | description: string; |
| 647 | 656 | /** relation(宾语是实体)| attribute(宾语是字面值) */ |
| @@ -1193,9 +1202,7 @@ | ||
| 1193 | 1202 | * 那一批,把上限当成规模显示是这个接口从前最误导人的地方 */ |
| 1194 | 1203 | total_nodes?: number; |
| 1195 | 1204 | total_edges?: number; |
| 1196 | - }>( | |
| 1197 | - `/api/v1/kbs/${kbId}/graph/overview${limit ? `?limit=${limit}` : ""}`, | |
| 1198 | - ), | |
| 1205 | + }>(`/api/v1/kbs/${kbId}/graph/overview${limit ? `?limit=${limit}` : ""}`), | |
| 1199 | 1206 | /** 邻域视图**没有总数**:它本来就只是一小片,说「共 325 个」没有意义。 |
| 1200 | 1207 | * 两个字段声明成可选,好让调用方与总览共用一个类型 */ |
| 1201 | 1208 | graphNeighborhood: (kbId: string, entityId: string) => |
modified web/src/i18n/en.ts +31 −4
| @@ -47,6 +47,12 @@ | ||
| 47 | 47 | "That class is already below this one — the hierarchy would loop.", |
| 48 | 48 | bad_lang: "Pick a supported language.", |
| 49 | 49 | attr_needs_class: "An attribute has to belong to a class.", |
| 50 | + attr_has_no_link: | |
| 51 | + "An attribute has no inverse and no super-property — its value is a literal, not something to point back from.", | |
| 52 | + link_target_is_attr: | |
| 53 | + "Pick a relation, not an attribute — an attribute's value is a literal.", | |
| 54 | + sub_property_self: "A relation cannot be its own super-property.", | |
| 55 | + unknown_relation: "That relation is not in this knowledge base.", | |
| 50 | 56 | entity_name_required: "Name cannot be empty.", |
| 51 | 57 | entity_name_too_long: "Name is too long — 100 characters at most.", |
| 52 | 58 | unknown_entity_type: "That class is not in this ontology.", |
| @@ -357,9 +363,11 @@ | ||
| 357 | 363 | object_missing: "Relation had no object", |
| 358 | 364 | malformed_item: "The model's item did not fit the schema", |
| 359 | 365 | truncated_reply: "The model's reply was cut off", |
| 360 | - domain_mismatch: "The subject does not fit the relation, and swapping would not help", | |
| 366 | + domain_mismatch: | |
| 367 | + "The subject does not fit the relation, and swapping would not help", | |
| 361 | 368 | not_an_entity_name: "That name is a sentence, not a thing", |
| 362 | - direction_corrected: "Subject and object were swapped to match the signature", | |
| 369 | + direction_corrected: | |
| 370 | + "Subject and object were swapped to match the signature", | |
| 363 | 371 | } as Record<string, string>, |
| 364 | 372 | // 来源级重抽:不危险,只是费时费钱——轻确认,文案直说成本与保留项 |
| 365 | 373 | reExtractSource: "Re-extract", |
| @@ -660,8 +668,14 @@ | ||
| 660 | 668 | `${added} added · ${gone} retracted`, |
| 661 | 669 | derivedCapped: (n: number) => `${n} predicate(s) not closed fully`, |
| 662 | 670 | close: "Close", |
| 663 | - ruleTransitive: "transitive", | |
| 664 | - ruleSymmetric: "symmetric", | |
| 671 | + // 派生边靠哪条规则来的。**四种都要有**——查不到的会退回原始 kind 串, | |
| 672 | + // 而那对读的人没有意义 | |
| 673 | + ruleNames: { | |
| 674 | + transitive: "transitive", | |
| 675 | + symmetric: "symmetric", | |
| 676 | + inverse: "inverse", | |
| 677 | + sub_property: "sub-property", | |
| 678 | + } as Record<string, string | undefined>, | |
| 665 | 679 | historyHint: "How this entity's record changed — and who changed it.", |
| 666 | 680 | historyEmpty: "Nothing recorded for this entity yet.", |
| 667 | 681 | historyKind: { |
| @@ -930,6 +944,16 @@ | ||
| 930 | 944 | irreflexiveHint: "Nothing can point at itself through this relation.", |
| 931 | 945 | axiomConflict: |
| 932 | 946 | "Symmetric and asymmetric together hold only for a relation with no facts at all — one of the two is wrong.", |
| 947 | + noLink: "None", | |
| 948 | + inverseOf: "Inverse", | |
| 949 | + inverseOfHint: | |
| 950 | + "The relation that says the same thing the other way round. Declare it on one side only — the other direction follows.", | |
| 951 | + subPropertyOf: "Super-property", | |
| 952 | + subPropertyOfHint: | |
| 953 | + "The broader relation this one is a special case of. Stating the specific one also states the broader one.", | |
| 954 | + linkMeansInverse: (p: string, q: string) => | |
| 955 | + `A ${p} B also means B ${q} A.`, | |
| 956 | + linkMeansSuper: (p: string, q: string) => `A ${p} B also means A ${q} B.`, | |
| 933 | 957 | usage: (n: number) => `${n} in use`, |
| 934 | 958 | builtin: "built-in", |
| 935 | 959 | save: "Save", |
| @@ -1181,6 +1205,9 @@ | ||
| 1181 | 1205 | defectCycle: "subClassOf runs in a circle", |
| 1182 | 1206 | defectDisjointAncestor: "Disjoint with its own ancestor", |
| 1183 | 1207 | defectInheritsDisjoint: "Inherits from two disjoint classes", |
| 1208 | + defectInverseSelf: "Its own inverse — say symmetric instead", | |
| 1209 | + defectInverseNotMutual: "The inverse does not point back", | |
| 1210 | + defectSubPropertyCycle: "subPropertyOf runs in a circle", | |
| 1184 | 1211 | defectNeverInstantiable: "no instance can ever satisfy it", |
| 1185 | 1212 | defectFixed: "I fixed the ontology", |
| 1186 | 1213 | defectAccepted: "Leave it", |
modified web/src/i18n/zh.ts +23 −2
| @@ -44,6 +44,11 @@ | ||
| 44 | 44 | parent_cycle: "那个类已经在这个类下面了——层级会成环。", |
| 45 | 45 | bad_lang: "选一个支持的语言。", |
| 46 | 46 | attr_needs_class: "属性必须挂在某个类上。", |
| 47 | + attr_has_no_link: | |
| 48 | + "属性没有逆,也没有父属性——它的宾语是字面值,谈不上反过来指回来。", | |
| 49 | + link_target_is_attr: "要选一条关系,不是属性——属性的值是字面量。", | |
| 50 | + sub_property_self: "一条关系不能是自己的父属性。", | |
| 51 | + unknown_relation: "这个知识库里没有这条关系。", | |
| 47 | 52 | entity_name_required: "名称不能为空。", |
| 48 | 53 | entity_name_too_long: "名称太长了——最多 100 个字符。", |
| 49 | 54 | unknown_entity_type: "这个类不在当前本体里。", |
| @@ -609,8 +614,12 @@ | ||
| 609 | 614 | `新增 ${added} · 作废 ${gone}`, |
| 610 | 615 | derivedCapped: (n: number) => `${n} 个谓词没推完`, |
| 611 | 616 | close: "关闭", |
| 612 | - ruleTransitive: "传递", | |
| 613 | - ruleSymmetric: "对称", | |
| 617 | + ruleNames: { | |
| 618 | + transitive: "传递", | |
| 619 | + symmetric: "对称", | |
| 620 | + inverse: "互逆", | |
| 621 | + sub_property: "子属性", | |
| 622 | + } as Record<string, string | undefined>, | |
| 614 | 623 | historyHint: "这个实体的记录如何变化——以及是谁改的。", |
| 615 | 624 | historyEmpty: "这个实体还没有记录。", |
| 616 | 625 | historyKind: { |
| @@ -854,6 +863,15 @@ | ||
| 854 | 863 | irreflexiveHint: "任何东西不能通过这条关系指向自己。", |
| 855 | 864 | axiomConflict: |
| 856 | 865 | "对称与反对称同时成立,只对一条事实都没有的关系为真——两者必有一个写错了。", |
| 866 | + noLink: "无", | |
| 867 | + inverseOf: "逆关系", | |
| 868 | + inverseOfHint: | |
| 869 | + "反过来说同一件事的那条关系。只需在一侧声明,另一个方向自动成立。", | |
| 870 | + subPropertyOf: "父属性", | |
| 871 | + subPropertyOfHint: "这条关系是谁的特例。说了具体的那条,宽泛的那条也成立。", | |
| 872 | + linkMeansInverse: (p: string, q: string) => | |
| 873 | + `A ${p} B 同时也是 B ${q} A。`, | |
| 874 | + linkMeansSuper: (p: string, q: string) => `A ${p} B 同时也是 A ${q} B。`, | |
| 857 | 875 | usage: (n: number) => `${n} 处在用`, |
| 858 | 876 | builtin: "内置", |
| 859 | 877 | save: "保存", |
| @@ -1067,6 +1085,9 @@ | ||
| 1067 | 1085 | defectCycle: "subClassOf 绕成了环", |
| 1068 | 1086 | defectDisjointAncestor: "与自己的祖先互斥", |
| 1069 | 1087 | defectInheritsDisjoint: "继承了两个互斥的类", |
| 1088 | + defectInverseSelf: "自己是自己的逆——写成「对称」更直白", | |
| 1089 | + defectInverseNotMutual: "逆关系没有指回来", | |
| 1090 | + defectSubPropertyCycle: "子属性绕成了环", | |
| 1070 | 1091 | defectNeverInstantiable: "这个类永远不可能有实例", |
| 1071 | 1092 | defectFixed: "已去本体里改了", |
| 1072 | 1093 | defectAccepted: "先放着", |
modified web/src/pages/Graph.tsx +3 −4
| @@ -2550,10 +2550,9 @@ | ||
| 2550 | 2550 | >(); |
| 2551 | 2551 | for (const d of derived) { |
| 2552 | 2552 | const direction = d.subject_id === entityId ? "out" : "in"; |
| 2553 | - const rule = | |
| 2554 | - d.rule === "transitive" | |
| 2555 | - ? S.graph.ruleTransitive | |
| 2556 | - : S.graph.ruleSymmetric; | |
| 2553 | + // 四条规则各有名字。**查不到就退回原始 kind 串**——那对读的人没有 | |
| 2554 | + // 意义,但比显示成另一条规则的名字诚实 | |
| 2555 | + const rule = S.graph.ruleNames[d.rule] ?? d.rule; | |
| 2557 | 2556 | const key = `${direction}|${d.predicate}|${d.rule}`; |
| 2558 | 2557 | const cur = map.get(key); |
| 2559 | 2558 | if (cur) cur.rows.push(d); |
modified web/src/pages/Ontology.tsx +101 −0
| @@ -39,6 +39,7 @@ | ||
| 39 | 39 | Pager, |
| 40 | 40 | PageTitle, |
| 41 | 41 | RAIL_CLS, |
| 42 | + SearchSelect, | |
| 42 | 43 | cn, |
| 43 | 44 | pageSlice, |
| 44 | 45 | } from "../ui"; |
| @@ -355,6 +356,7 @@ | ||
| 355 | 356 | kbId={kb.id} |
| 356 | 357 | existing={selectedProp} |
| 357 | 358 | allTypes={entity_types} |
| 359 | + allRelations={relations} | |
| 358 | 360 | onDone={(createdId) => { |
| 359 | 361 | if (sel?.kind === "new-relation") |
| 360 | 362 | setSel( |
| @@ -1150,12 +1152,16 @@ | ||
| 1150 | 1152 | kbId, |
| 1151 | 1153 | existing, |
| 1152 | 1154 | allTypes, |
| 1155 | + allRelations, | |
| 1153 | 1156 | onDone, |
| 1154 | 1157 | onError, |
| 1155 | 1158 | }: { |
| 1156 | 1159 | kbId: string; |
| 1157 | 1160 | existing: RelationTypeView | null; |
| 1158 | 1161 | allTypes: EntityTypeView[]; |
| 1162 | + /** 本库的关系(不含属性)。逆与子属性的下拉从这里取——**属性不在其中**, | |
| 1163 | + * 它的宾语是字面值,反过来无从谈起 */ | |
| 1164 | + allRelations: RelationTypeView[]; | |
| 1159 | 1165 | onDone: (createdId?: string) => void; |
| 1160 | 1166 | onError: (e: unknown) => void; |
| 1161 | 1167 | }) { |
| @@ -1174,6 +1180,11 @@ | ||
| 1174 | 1180 | const [irreflexive, setIrreflexive] = useState( |
| 1175 | 1181 | existing?.is_irreflexive ?? false, |
| 1176 | 1182 | ); |
| 1183 | + // 同一族的后两条,形状不同:指向另一个关系。空串 = 没声明 | |
| 1184 | + const [inverseOf, setInverseOf] = useState(existing?.inverse_of ?? ""); | |
| 1185 | + const [subPropertyOf, setSubPropertyOf] = useState( | |
| 1186 | + existing?.sub_property_of ?? "", | |
| 1187 | + ); | |
| 1177 | 1188 | const [description, setDescription] = useState(existing?.description ?? ""); |
| 1178 | 1189 | const [domains, setDomains] = useState<string[]>(existing?.domains ?? []); |
| 1179 | 1190 | const [ranges, setRanges] = useState<string[]>(existing?.ranges ?? []); |
| @@ -1184,6 +1195,28 @@ | ||
| 1184 | 1195 | () => parentOptions(allTypes, undefined), |
| 1185 | 1196 | [allTypes], |
| 1186 | 1197 | ); |
| 1198 | + // 两个下拉的选项:本库的其它关系。 | |
| 1199 | + // | |
| 1200 | + // **自己不进列表**,两条都是。子属性指向自己数据库直接拒(那是个环); | |
| 1201 | + // 逆指向自己在语义上合法——但它等于 `symmetric`,而那个复选框就在上面, | |
| 1202 | + // 在这里提供第二条路只会让人写出 R0 要报的东西。 | |
| 1203 | + // | |
| 1204 | + // 唯一的例外是**当前值就是自己**:OWL 导入进来的可以长这样,从列表里漏掉 | |
| 1205 | + // 它就会让下拉显示空白,而空白一保存就把已声明的抹了 | |
| 1206 | + const linkOptions = (current: string) => [ | |
| 1207 | + { value: "", label: S.ontology.noLink }, | |
| 1208 | + // 当前值就是自己时把自己补回列表,否则下拉显示空白, | |
| 1209 | + // 而空白一保存就把已声明的抹了 | |
| 1210 | + ...(existing && current === existing.id | |
| 1211 | + ? [{ value: existing.id, label: existing.label, hint: existing.key }] | |
| 1212 | + : []), | |
| 1213 | + ...allRelations | |
| 1214 | + .filter((r) => r.id !== existing?.id) | |
| 1215 | + .map((r) => ({ value: r.id, label: r.label, hint: r.key })), | |
| 1216 | + ]; | |
| 1217 | + /** 下拉里选中那条的显示名。找不到就回落到 id——宁可难看,不要空着 */ | |
| 1218 | + const nameOf = (id: string) => | |
| 1219 | + allRelations.find((r) => r.id === id)?.label ?? id; | |
| 1187 | 1220 | const toggle = ( |
| 1188 | 1221 | set: React.Dispatch<React.SetStateAction<string[]>>, |
| 1189 | 1222 | id: string, |
| @@ -1201,6 +1234,10 @@ | ||
| 1201 | 1234 | is_symmetric: symmetric, |
| 1202 | 1235 | is_asymmetric: asymmetric, |
| 1203 | 1236 | is_irreflexive: irreflexive, |
| 1237 | + // 空串要变成 null 再送——服务端收 `Option<Uuid>`, | |
| 1238 | + // `""` 解不成 UUID,会是一个 422 而不是「清空」 | |
| 1239 | + inverse_of: inverseOf || null, | |
| 1240 | + sub_property_of: subPropertyOf || null, | |
| 1204 | 1241 | description, |
| 1205 | 1242 | domains, |
| 1206 | 1243 | ranges, |
| @@ -1215,6 +1252,10 @@ | ||
| 1215 | 1252 | is_symmetric: symmetric, |
| 1216 | 1253 | is_asymmetric: asymmetric, |
| 1217 | 1254 | is_irreflexive: irreflexive, |
| 1255 | + // 空串要变成 null 再送——服务端收 `Option<Uuid>`, | |
| 1256 | + // `""` 解不成 UUID,会是一个 422 而不是「清空」 | |
| 1257 | + inverse_of: inverseOf || null, | |
| 1258 | + sub_property_of: subPropertyOf || null, | |
| 1218 | 1259 | description, |
| 1219 | 1260 | domains, |
| 1220 | 1261 | ranges, |
| @@ -1371,6 +1412,66 @@ | ||
| 1371 | 1412 | {S.ontology.axiomConflict} |
| 1372 | 1413 | </p> |
| 1373 | 1414 | )} |
| 1415 | + {/* 同一组的后两条,只是形状不同:它们指向**另一个关系**,所以是下拉 | |
| 1416 | + 不是复选框。放在这里而不是单开一节——推理机的四种规则源里,两条是 | |
| 1417 | + 上面的勾,两条是下面的选,分开会让人以为它们是两回事(0002) */} | |
| 1418 | + <div className="mt-3 space-y-2.5 border-t border-white/5 pt-3"> | |
| 1419 | + {( | |
| 1420 | + [ | |
| 1421 | + [ | |
| 1422 | + inverseOf, | |
| 1423 | + setInverseOf, | |
| 1424 | + S.ontology.inverseOf, | |
| 1425 | + S.ontology.inverseOfHint, | |
| 1426 | + linkOptions(inverseOf), | |
| 1427 | + ], | |
| 1428 | + [ | |
| 1429 | + subPropertyOf, | |
| 1430 | + setSubPropertyOf, | |
| 1431 | + S.ontology.subPropertyOf, | |
| 1432 | + S.ontology.subPropertyOfHint, | |
| 1433 | + linkOptions(subPropertyOf), | |
| 1434 | + ], | |
| 1435 | + ] as const | |
| 1436 | + ).map(([value, set, title, hint, options], i) => ( | |
| 1437 | + <div key={i}> | |
| 1438 | + <div className="text-[13px] text-neutral-200">{title}</div> | |
| 1439 | + <p className="text-[11px] leading-relaxed text-neutral-500 mb-1"> | |
| 1440 | + {hint} | |
| 1441 | + </p> | |
| 1442 | + <SearchSelect | |
| 1443 | + value={value} | |
| 1444 | + onChange={set} | |
| 1445 | + options={options} | |
| 1446 | + size="sm" | |
| 1447 | + className="w-full" | |
| 1448 | + placeholder={S.ontology.noLink} | |
| 1449 | + /> | |
| 1450 | + </div> | |
| 1451 | + ))} | |
| 1452 | + {/* 选了之后当场把话说全。**这两条推出来的事实主宾未必同向**—— | |
| 1453 | + 逆要对调,子属性不对调,只看名字分不出来,写出来就分得出 */} | |
| 1454 | + {(inverseOf || subPropertyOf) && ( | |
| 1455 | + <div className="text-[11px] leading-relaxed text-neutral-500 space-y-0.5"> | |
| 1456 | + {inverseOf && ( | |
| 1457 | + <div> | |
| 1458 | + {S.ontology.linkMeansInverse( | |
| 1459 | + label.trim() || key || "?", | |
| 1460 | + nameOf(inverseOf), | |
| 1461 | + )} | |
| 1462 | + </div> | |
| 1463 | + )} | |
| 1464 | + {subPropertyOf && ( | |
| 1465 | + <div> | |
| 1466 | + {S.ontology.linkMeansSuper( | |
| 1467 | + label.trim() || key || "?", | |
| 1468 | + nameOf(subPropertyOf), | |
| 1469 | + )} | |
| 1470 | + </div> | |
| 1471 | + )} | |
| 1472 | + </div> | |
| 1473 | + )} | |
| 1474 | + </div> | |
| 1374 | 1475 | </div> |
| 1375 | 1476 | <div> |
| 1376 | 1477 | <label className={lbl}>{S.ontology.description}</label> |
modified web/src/pages/Review.tsx +3 −0
| @@ -476,6 +476,9 @@ | ||
| 476 | 476 | subclass_cycle: S.review.defectCycle, |
| 477 | 477 | disjoint_with_ancestor: S.review.defectDisjointAncestor, |
| 478 | 478 | inherits_disjoint: S.review.defectInheritsDisjoint, |
| 479 | + inverse_of_itself: S.review.defectInverseSelf, | |
| 480 | + inverse_not_mutual: S.review.defectInverseNotMutual, | |
| 481 | + sub_property_cycle: S.review.defectSubPropertyCycle, | |
| 479 | 482 | }[d.kind]; |
| 480 | 483 | // 后两类的后果值得写出来:不可满足的类不会报错,它只是永远空着 |
| 481 | 484 | const unsatisfiable = |