@ontology-kit/okb 0.2.0 → 0.3.0-alpha.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +11 -819
- package/dist/clidocs.d.ts +0 -2
- package/dist/clidocs.js +5 -27
- package/dist/command-table.d.ts +134 -0
- package/dist/command-table.js +82 -0
- package/dist/commands/documents.d.ts +3 -0
- package/dist/commands/documents.js +250 -0
- package/dist/commands/getting-started.d.ts +3 -0
- package/dist/commands/getting-started.js +135 -0
- package/dist/commands/housekeeping.d.ts +3 -0
- package/dist/commands/housekeeping.js +203 -0
- package/dist/commands/modeling.d.ts +3 -0
- package/dist/commands/modeling.js +433 -0
- package/dist/commands/planning.d.ts +3 -0
- package/dist/commands/planning.js +212 -0
- package/dist/commands/reviewing.d.ts +3 -0
- package/dist/commands/reviewing.js +177 -0
- package/dist/commands/skills.d.ts +3 -0
- package/dist/commands/skills.js +52 -0
- package/dist/commands.d.ts +10 -22
- package/dist/commands.js +15 -716
- package/dist/help.d.ts +11 -2
- package/dist/help.js +51 -64
- package/dist/release.d.ts +4 -0
- package/dist/release.js +22 -3
- package/dist/render.d.ts +61 -1
- package/dist/render.js +219 -1
- package/dist/runner.d.ts +3 -0
- package/dist/runner.js +79 -0
- package/dist/workflows.d.ts +256 -0
- package/dist/workflows.js +223 -0
- package/package.json +4 -3
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
/** Modeling: conventions, classes, slots, links and instances (steps 4 to 7). */
|
|
2
|
+
import { NAME_DESC, opt, tri } from "../command-table.js";
|
|
3
|
+
import * as ops from "../ops.js";
|
|
4
|
+
import { renderConvention, show, tree } from "../render.js";
|
|
5
|
+
import { setInstance, showData } from "../workflows.js";
|
|
6
|
+
const { str, strs, bool } = opt;
|
|
7
|
+
/** The slot options both `slot add` and `slot set` take, as the op wants them. */
|
|
8
|
+
const slotOpts = (ctx) => {
|
|
9
|
+
const o = ctx.opts;
|
|
10
|
+
return {
|
|
11
|
+
on: o.on, off: o.off, type: o.type, values: o.values, range: o.range, addRange: o["add-range"], removeRange: o["remove-range"],
|
|
12
|
+
card: o.card, min: ctx.int("min"), max: ctx.int("max"), default: o.default, description: o.desc, force: o.force, onRules: o["on-rules"], offRules: o["off-rules"],
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
/** `okb relationship ...` is `okb slot ...` for a slot whose values are instances; `--from`/`--to` are `--on`/`--range`. */
|
|
16
|
+
const relationshipRewrite = (rest) => {
|
|
17
|
+
const words = rest.map((w, i) => (i === 0 ? w : w === "--from" ? "--on" : w === "--to" ? "--range" : w));
|
|
18
|
+
if (rest[0] === "add")
|
|
19
|
+
words.push("--type", "Instance");
|
|
20
|
+
return [rest[0] === "property" ? "edgeprop" : "slot", ...words];
|
|
21
|
+
};
|
|
22
|
+
export const modeling = [
|
|
23
|
+
{
|
|
24
|
+
name: "convention",
|
|
25
|
+
group: "Modeling",
|
|
26
|
+
summary: "set how names are written",
|
|
27
|
+
description: "Sets how names are written, so the validator can check them. With no flags it shows the current choices.",
|
|
28
|
+
forms: [
|
|
29
|
+
{
|
|
30
|
+
description: "Sets any of the options you pass.",
|
|
31
|
+
examples: ["okb convention --class-case PascalCase --slot-case camelCase --number singular"],
|
|
32
|
+
args: [
|
|
33
|
+
["--class-case", "text", "Case for class names, such as PascalCase."],
|
|
34
|
+
["--slot-case", "text", "Case for slot names, such as camelCase."],
|
|
35
|
+
["--instance-case", "text", "Case for instance names."],
|
|
36
|
+
["--number", "singular or plural", "Whether class names are singular or plural."],
|
|
37
|
+
["--slot-affix", "text", "A prefix or suffix every slot name carries, if any."],
|
|
38
|
+
],
|
|
39
|
+
options: { "class-case": str, "slot-case": str, "instance-case": str, number: str, "slot-affix": str },
|
|
40
|
+
run: (ctx) => {
|
|
41
|
+
const o = ctx.opts;
|
|
42
|
+
ctx.mutate((ont) => {
|
|
43
|
+
const notes = ops.setConventions(ont, { classCase: o["class-case"], slotCase: o["slot-case"], instanceCase: o["instance-case"], classNumber: o.number, slotAffix: o["slot-affix"] });
|
|
44
|
+
return [renderConvention(ont), ...notes];
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "class",
|
|
52
|
+
group: "Modeling",
|
|
53
|
+
summary: "create and change classes",
|
|
54
|
+
description: "Creates and changes classes, the kinds of things in your domain.",
|
|
55
|
+
forms: [
|
|
56
|
+
{
|
|
57
|
+
sub: "add",
|
|
58
|
+
description: "Adds a class.",
|
|
59
|
+
examples: ["okb class add RedWine --parent Wine --desc \"Wine made with dark grapes\""],
|
|
60
|
+
args: [
|
|
61
|
+
["<Name>", "text", NAME_DESC],
|
|
62
|
+
["--parent", "class", "A parent class. Repeat it for more."],
|
|
63
|
+
["--desc", "text", "A one-line description."],
|
|
64
|
+
["--synonym", "text", "Another name for it. Repeat it for more."],
|
|
65
|
+
["--abstract", "flag", "Mark it as a grouping with no members of its own."],
|
|
66
|
+
["--terminological", "flag", "Mark it as terminological."],
|
|
67
|
+
["--force", "flag", "Add it even if the name breaks your convention."],
|
|
68
|
+
],
|
|
69
|
+
options: { parent: strs, desc: str, synonym: strs, abstract: bool, terminological: bool, force: bool },
|
|
70
|
+
usage: "Usage: okb class add <Name> [--parent P] [--desc ...]",
|
|
71
|
+
min: 1,
|
|
72
|
+
cheat: { example: "okb class add RedWine --parent Wine", description: "Add a class" },
|
|
73
|
+
run: (ctx) => {
|
|
74
|
+
const o = ctx.opts;
|
|
75
|
+
ctx.mutate((ont) => ops.addClass(ont, ctx.args[0], { parents: o.parent, description: o.desc, synonyms: o.synonym, abstract: o.abstract, terminological: o.terminological, force: o.force }));
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
sub: "set",
|
|
80
|
+
description: "Changes a class.",
|
|
81
|
+
examples: ["okb class set RedWine --add-parent Beverage"],
|
|
82
|
+
args: [
|
|
83
|
+
["<Class>", "class", "The class to change."],
|
|
84
|
+
["--desc", "text", "New description."],
|
|
85
|
+
["--add-parent", "class", "Add a parent."],
|
|
86
|
+
["--remove-parent", "class", "Remove a parent."],
|
|
87
|
+
["--synonym", "text", "Add a synonym."],
|
|
88
|
+
["--abstract", "true or false", "Whether it is abstract."],
|
|
89
|
+
["--terminological", "true or false", "Whether it is terminological."],
|
|
90
|
+
],
|
|
91
|
+
options: { desc: str, "add-parent": strs, "remove-parent": strs, synonym: strs, abstract: str, terminological: str },
|
|
92
|
+
usage: "Usage: okb class set <Class> [--desc ...] [--add-parent P] [--remove-parent P] [--synonym S] [--abstract true|false]",
|
|
93
|
+
min: 1,
|
|
94
|
+
run: (ctx) => {
|
|
95
|
+
const o = ctx.opts;
|
|
96
|
+
ctx.mutate((ont) => ops.setClass(ont, ctx.args[0], { description: o.desc, addParents: o["add-parent"], removeParents: o["remove-parent"], synonyms: o.synonym, abstract: tri(o.abstract), terminological: tri(o.terminological) }));
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
sub: "disjoint",
|
|
101
|
+
description: "Says that no one thing can belong to more than one of these classes.",
|
|
102
|
+
examples: ["okb class disjoint RedWine WhiteWine RoseWine"],
|
|
103
|
+
args: [
|
|
104
|
+
["<Class>...", "classes", "Two or more classes."],
|
|
105
|
+
],
|
|
106
|
+
run: (ctx) => ctx.mutate((ont) => ops.disjoint(ont, ctx.args)),
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
sub: "fix",
|
|
110
|
+
description: "Gives every member of a class the same value for a slot.",
|
|
111
|
+
examples: ["okb class fix DessertWine sugar=sweet"],
|
|
112
|
+
args: [
|
|
113
|
+
["<Class>", "class", "The class."],
|
|
114
|
+
["<slot=value>...", "slot=value", "The values every member has."],
|
|
115
|
+
],
|
|
116
|
+
usage: "Usage: okb class fix <Class> slot=value ...",
|
|
117
|
+
min: 2,
|
|
118
|
+
run: (ctx) => ctx.mutate((ont) => ops.assign(ont, ont.find(ctx.args[0], "Class").id, ctx.args.slice(1), "fixed")),
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
sub: "default",
|
|
122
|
+
description: "Gives a class a starting value for a slot that individual members can override.",
|
|
123
|
+
examples: ["okb class default Wine body=full"],
|
|
124
|
+
args: [
|
|
125
|
+
["<Class>", "class", "The class."],
|
|
126
|
+
["<slot=value>...", "slot=value", "The starting values."],
|
|
127
|
+
],
|
|
128
|
+
usage: "Usage: okb class default <Class> slot=value ...",
|
|
129
|
+
min: 2,
|
|
130
|
+
run: (ctx) => ctx.mutate((ont) => ops.classDefault(ont, ctx.args[0], ctx.args.slice(1))),
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
sub: "restrict",
|
|
134
|
+
description: "Narrows a slot for one class: fewer values, a limit on how many, or a narrower range.",
|
|
135
|
+
examples: ["okb class restrict SingleVarietal grape --max 1"],
|
|
136
|
+
args: [
|
|
137
|
+
["<Class>", "class", "The class."],
|
|
138
|
+
["<slot>", "slot", "The slot to narrow."],
|
|
139
|
+
["--values", "list", "Allowed values."],
|
|
140
|
+
["--min", "number", "The fewest values allowed."],
|
|
141
|
+
["--max", "number", "The most values allowed."],
|
|
142
|
+
["--range", "class", "Allowed classes, for a relationship."],
|
|
143
|
+
["--clear", "flag", "Remove the restriction."],
|
|
144
|
+
],
|
|
145
|
+
options: { values: strs, min: str, max: str, range: strs, clear: bool },
|
|
146
|
+
usage: "Usage: okb class restrict <Class> <slot> [--values a,b] [--min N] [--max N] [--range C] [--clear]",
|
|
147
|
+
min: 2,
|
|
148
|
+
run: (ctx) => {
|
|
149
|
+
const o = ctx.opts;
|
|
150
|
+
ctx.mutate((ont) => ops.restrict(ont, ctx.args[0], ctx.args[1], { values: o.values, min: ctx.int("min"), max: ctx.int("max"), range: o.range, clear: o.clear }));
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: "tree",
|
|
157
|
+
group: "Modeling",
|
|
158
|
+
summary: "show the class hierarchy",
|
|
159
|
+
description: "Prints the class hierarchy as an indented tree.",
|
|
160
|
+
forms: [
|
|
161
|
+
{
|
|
162
|
+
description: "Shows each class under its parents.",
|
|
163
|
+
examples: ["okb tree", "okb tree --instances"],
|
|
164
|
+
args: [
|
|
165
|
+
["--instances", "flag", "Show instances under their classes."],
|
|
166
|
+
],
|
|
167
|
+
options: { instances: bool },
|
|
168
|
+
cheat: { example: "okb tree", description: "See the class hierarchy" },
|
|
169
|
+
run: (ctx) => ctx.print(tree(ctx.load(), ctx.opts.instances)),
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
name: "property",
|
|
175
|
+
group: "Modeling",
|
|
176
|
+
summary: "add a slot that holds a plain value",
|
|
177
|
+
description: "A slot that holds a plain value, such as a number, text or one of a fixed list. It takes the same subcommands as `okb slot`.",
|
|
178
|
+
rewrite: (rest) => ["slot", ...rest],
|
|
179
|
+
forms: [
|
|
180
|
+
{
|
|
181
|
+
sub: "add",
|
|
182
|
+
description: "Adds a property to a class.",
|
|
183
|
+
examples: ["okb property add body --on Wine --type Enumerated --values light,medium,full --card single"],
|
|
184
|
+
args: [
|
|
185
|
+
["<name>", "text", NAME_DESC],
|
|
186
|
+
["--on", "class", "The class it belongs to."],
|
|
187
|
+
["--type", "String, Integer, Float, Boolean or Enumerated", "What kind of value it holds."],
|
|
188
|
+
["--values", "list", "The allowed values, for Enumerated."],
|
|
189
|
+
["--card", "single or multiple", "Whether it holds one value or several."],
|
|
190
|
+
["--desc", "text", "A one-line description."],
|
|
191
|
+
],
|
|
192
|
+
cheat: { example: "okb property add body --on Wine --type Enumerated --values light,full", description: "Add a plain-value slot" },
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
name: "relationship",
|
|
198
|
+
group: "Modeling",
|
|
199
|
+
summary: "add a slot that links things",
|
|
200
|
+
description: "A slot that links one thing to another, such as a wine to its winery. Okb stores it as edges, so `maker` becomes `:MAKER`.",
|
|
201
|
+
rewrite: relationshipRewrite,
|
|
202
|
+
forms: [
|
|
203
|
+
{
|
|
204
|
+
sub: "add",
|
|
205
|
+
description: "Adds a relationship between two classes.",
|
|
206
|
+
examples: ["okb relationship add maker --from Wine --to Winery --card single"],
|
|
207
|
+
args: [
|
|
208
|
+
["<name>", "text", NAME_DESC],
|
|
209
|
+
["--from", "class", "The class the relationship starts at."],
|
|
210
|
+
["--to", "class", "The class it points to."],
|
|
211
|
+
["--card", "single or multiple", "Whether it holds one target or several."],
|
|
212
|
+
],
|
|
213
|
+
cheat: { example: "okb relationship add maker --from Wine --to Winery", description: "Add a link between classes" },
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
sub: "inverse",
|
|
217
|
+
description: "Declares that two relationships are the same link read from opposite ends.",
|
|
218
|
+
examples: ["okb relationship inverse maker produces"],
|
|
219
|
+
args: [
|
|
220
|
+
["<slotA>", "slot", "The relationship that is stored."],
|
|
221
|
+
["<slotB>", "slot", "Its inverse."],
|
|
222
|
+
],
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
sub: "property",
|
|
226
|
+
description: "Adds a property to a relationship itself, such as the condition under which one thing is preferred over another.",
|
|
227
|
+
examples: ["okb relationship property preferredOver condition --type String"],
|
|
228
|
+
args: [
|
|
229
|
+
["<relationship>", "slot", "The relationship."],
|
|
230
|
+
["<name>", "text", "The property's name."],
|
|
231
|
+
["--type", "String, Integer, Float, Boolean or Enumerated", "What kind of value it holds."],
|
|
232
|
+
["--values", "list", "The allowed values, for Enumerated."],
|
|
233
|
+
["--required", "flag", "Every link must give it a value."],
|
|
234
|
+
["--desc", "text", "A one-line description."],
|
|
235
|
+
["--remove", "flag", "Remove the property."],
|
|
236
|
+
],
|
|
237
|
+
},
|
|
238
|
+
],
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
name: "slot",
|
|
242
|
+
group: "Modeling",
|
|
243
|
+
summary: "create and change slots",
|
|
244
|
+
description: "Creates and changes slots, the properties and relationships of a class. `okb property` and `okb relationship` are friendlier names for the same command.",
|
|
245
|
+
forms: [
|
|
246
|
+
{
|
|
247
|
+
sub: "add",
|
|
248
|
+
description: "Adds a slot to a class.",
|
|
249
|
+
examples: ["okb slot add body --on Wine --type Enumerated --values light,medium,full"],
|
|
250
|
+
args: [
|
|
251
|
+
["<name>", "text", NAME_DESC],
|
|
252
|
+
["--on", "class", "A class it belongs to. Repeat it for more."],
|
|
253
|
+
["--type", "String, Integer, Float, Boolean, Enumerated or Instance", "What it holds. `Instance` makes it a relationship."],
|
|
254
|
+
["--values", "list", "The allowed values, for Enumerated."],
|
|
255
|
+
["--range", "class", "The class a relationship points to."],
|
|
256
|
+
["--card", "single or multiple", "Whether it holds one value or several."],
|
|
257
|
+
["--min", "number", "The fewest values allowed."],
|
|
258
|
+
["--max", "number", "The most values allowed."],
|
|
259
|
+
["--default", "text", "A starting value."],
|
|
260
|
+
["--desc", "text", "A one-line description."],
|
|
261
|
+
["--force", "flag", "Add it even if the name breaks your convention."],
|
|
262
|
+
],
|
|
263
|
+
options: { on: strs, off: strs, type: str, values: strs, range: strs, "add-range": strs, "remove-range": strs, card: str, min: str, max: str, default: str, desc: str, force: bool, "on-rules": bool, "off-rules": bool },
|
|
264
|
+
usage: "Usage: okb slot add <name> --on <Class> --type <Type> [--card single|multiple] ...",
|
|
265
|
+
min: 1,
|
|
266
|
+
run: (ctx) => ctx.mutate((ont) => ops.addSlot(ont, ctx.args[0], slotOpts(ctx))),
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
sub: "set",
|
|
270
|
+
description: "Changes a slot. It takes every flag `add` takes, plus the ones below.",
|
|
271
|
+
examples: ["okb slot set maker --card single --min 1", "okb slot set body --off Beverage"],
|
|
272
|
+
args: [
|
|
273
|
+
["<slot>", "slot", "The slot to change."],
|
|
274
|
+
["--off", "class", "Take the slot off a class."],
|
|
275
|
+
["--add-range", "class", "Add a class a relationship can point to."],
|
|
276
|
+
["--remove-range", "class", "Remove one."],
|
|
277
|
+
["--on-rules", "flag", "Let rules set this slot."],
|
|
278
|
+
["--off-rules", "flag", "Stop rules setting this slot."],
|
|
279
|
+
],
|
|
280
|
+
options: { on: strs, off: strs, type: str, values: strs, range: strs, "add-range": strs, "remove-range": strs, card: str, min: str, max: str, default: str, desc: str, force: bool, "on-rules": bool, "off-rules": bool },
|
|
281
|
+
usage: "Usage: okb slot set <slot> [--on C] [--type T] [--values a,b] [--range C] [--card single|multiple] ...",
|
|
282
|
+
min: 1,
|
|
283
|
+
cheat: { example: "okb slot set maker --card single --min 1", description: "Tighten a slot" },
|
|
284
|
+
run: (ctx) => ctx.mutate((ont) => ops.updateSlot(ont, ctx.args[0], slotOpts(ctx))),
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
sub: "inverse",
|
|
288
|
+
description: "Declares that two relationships are the same link read from opposite ends.",
|
|
289
|
+
examples: ["okb slot inverse maker produces"],
|
|
290
|
+
args: [
|
|
291
|
+
["<slotA>", "slot", "The relationship that is stored."],
|
|
292
|
+
["<slotB>", "slot", "Its inverse."],
|
|
293
|
+
],
|
|
294
|
+
usage: "Usage: okb slot inverse <slotA> <slotB>",
|
|
295
|
+
min: 2,
|
|
296
|
+
max: 2,
|
|
297
|
+
run: (ctx) => ctx.mutate((ont) => ops.inverse(ont, ctx.args[0], ctx.args[1])),
|
|
298
|
+
},
|
|
299
|
+
],
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
name: "show",
|
|
303
|
+
group: "Modeling",
|
|
304
|
+
summary: "everything about one class, slot or instance",
|
|
305
|
+
description: "Shows everything about one class, slot or instance: its parents, slots, values and links.",
|
|
306
|
+
forms: [
|
|
307
|
+
{
|
|
308
|
+
description: "With no name it shows the ontology itself.",
|
|
309
|
+
examples: ["okb show Wine", "okb show class:Genre"],
|
|
310
|
+
args: [
|
|
311
|
+
["[name]", "text", "The thing to show. When a class and a slot share a name, write `class:Genre` or `slot:genre`."],
|
|
312
|
+
],
|
|
313
|
+
cheat: { example: "okb show Wine", description: "See everything about one class, slot or instance" },
|
|
314
|
+
run: (ctx) => {
|
|
315
|
+
const ont = ctx.load();
|
|
316
|
+
const n = ont.find(ctx.args[0] ?? "ontology");
|
|
317
|
+
ctx.emit(() => showData(ont, n), () => show(ont, n));
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
],
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
name: "link",
|
|
324
|
+
group: "Modeling",
|
|
325
|
+
summary: "connect two instances",
|
|
326
|
+
description: "Connects two instances (or an instance and a class) with a relationship.",
|
|
327
|
+
forms: [
|
|
328
|
+
{
|
|
329
|
+
description: "Adds one link. Values for the relationship's own properties go at the end.",
|
|
330
|
+
examples: ["okb link Radio preferredOver SegmentedControl condition=\"2 to 7 options\""],
|
|
331
|
+
args: [
|
|
332
|
+
["<from>", "name", "Where the link starts."],
|
|
333
|
+
["<relationship>", "slot", "The relationship."],
|
|
334
|
+
["<to>", "name", "Where it ends."],
|
|
335
|
+
["<name=value>...", "name=value", "Values for the relationship's own properties."],
|
|
336
|
+
["--rule", "rule id", "The extracted rule this link comes from."],
|
|
337
|
+
["--clear", "text", "Remove a property value from the link."],
|
|
338
|
+
],
|
|
339
|
+
options: { rule: str, clear: strs },
|
|
340
|
+
usage: 'Usage: okb link <from> <relationship> <to> [name=value ...] [--rule <rule id>] [--clear name]',
|
|
341
|
+
min: 3,
|
|
342
|
+
cheat: { example: "okb link Radio preferredOver SegmentedControl", description: "Connect two instances" },
|
|
343
|
+
run: (ctx) => {
|
|
344
|
+
const [from, relationship, to, ...props] = ctx.args;
|
|
345
|
+
ctx.mutate((ont) => ops.link(ont, from, relationship, to, { props, rule: ctx.opts.rule, clear: ctx.opts.clear }));
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
],
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
name: "unlink",
|
|
352
|
+
group: "Modeling",
|
|
353
|
+
summary: "remove a link",
|
|
354
|
+
description: "Removes a link.",
|
|
355
|
+
forms: [
|
|
356
|
+
{
|
|
357
|
+
description: "Removes one link.",
|
|
358
|
+
examples: ["okb unlink Radio preferredOver SegmentedControl"],
|
|
359
|
+
args: [
|
|
360
|
+
["<from>", "name", "Where the link starts."],
|
|
361
|
+
["<relationship>", "slot", "The relationship."],
|
|
362
|
+
["<to>", "name", "Where it ends."],
|
|
363
|
+
],
|
|
364
|
+
usage: "Usage: okb unlink <from> <relationship> <to>",
|
|
365
|
+
min: 3,
|
|
366
|
+
max: 3,
|
|
367
|
+
run: (ctx) => ctx.mutate((ont) => ops.unlink(ont, ctx.args[0], ctx.args[1], ctx.args[2])),
|
|
368
|
+
},
|
|
369
|
+
],
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
name: "instance",
|
|
373
|
+
group: "Modeling",
|
|
374
|
+
summary: "add and change instances",
|
|
375
|
+
description: "Adds and changes instances, the individual things your classes describe.",
|
|
376
|
+
forms: [
|
|
377
|
+
{
|
|
378
|
+
sub: "add",
|
|
379
|
+
description: "Adds an instance and sets its values.",
|
|
380
|
+
examples: ["okb instance add \"Chateau Morgon Beaujolais\" --of Beaujolais body=light maker=\"Chateau Morgon\""],
|
|
381
|
+
args: [
|
|
382
|
+
["<Name>", "text", "The instance's name. Quote it if it has spaces."],
|
|
383
|
+
["--of", "class", "A class it belongs to. Repeat it for more."],
|
|
384
|
+
["--desc", "text", "A one-line description."],
|
|
385
|
+
["<slot=value>...", "slot=value", "Values for its slots."],
|
|
386
|
+
],
|
|
387
|
+
options: { of: strs, desc: str },
|
|
388
|
+
usage: 'Usage: okb instance add "Name" --of <Class> [slot=value ...]',
|
|
389
|
+
min: 1,
|
|
390
|
+
cheat: { example: "okb instance add \"Chateau Morgon\" --of Beaujolais body=light", description: "Add an instance" },
|
|
391
|
+
run: (ctx) => ctx.mutate((ont) => ops.addInstance(ont, ctx.args[0], { of: ctx.opts.of, description: ctx.opts.desc, assignments: ctx.args.slice(1) })),
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
sub: "set",
|
|
395
|
+
description: "Changes an instance's values. Use `+=` to add a value, `-=` to remove one, and `slot=` to clear it.",
|
|
396
|
+
examples: ["okb instance set \"Chateau Morgon Beaujolais\" grape+=Gamay", "okb instance set \"Chateau Morgon Beaujolais\" --of Beaujolais"],
|
|
397
|
+
args: [
|
|
398
|
+
["<Name>", "text", "The instance."],
|
|
399
|
+
["<slot=value>...", "slot=value", "The changes."],
|
|
400
|
+
["--of", "class", "Move it to another class."],
|
|
401
|
+
["--desc", "text", "New description."],
|
|
402
|
+
],
|
|
403
|
+
options: { of: strs, desc: str },
|
|
404
|
+
usage: 'Usage: okb instance set "Name" slot=value ... [--of <Class>]',
|
|
405
|
+
min: 1,
|
|
406
|
+
run: (ctx) => ctx.mutate((ont) => setInstance(ont, ctx.args[0], { of: ctx.opts.of, desc: ctx.opts.desc, assignments: ctx.args.slice(1) })),
|
|
407
|
+
},
|
|
408
|
+
],
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
name: "edgeprop",
|
|
412
|
+
group: "Modeling",
|
|
413
|
+
description: "Declares a property on a relationship. Reached through okb relationship property.",
|
|
414
|
+
hidden: true,
|
|
415
|
+
forms: [
|
|
416
|
+
{
|
|
417
|
+
sub: "property",
|
|
418
|
+
description: "",
|
|
419
|
+
examples: [],
|
|
420
|
+
args: [],
|
|
421
|
+
options: { type: str, values: strs, required: bool, desc: str, remove: bool },
|
|
422
|
+
usage: "Usage: okb relationship property <relationship> <name> --type String|Integer|Float|Boolean|Enumerated [--values a,b] [--required] [--desc ...] [--remove]",
|
|
423
|
+
min: 2,
|
|
424
|
+
max: 2,
|
|
425
|
+
hidden: true,
|
|
426
|
+
run: (ctx) => {
|
|
427
|
+
const o = ctx.opts;
|
|
428
|
+
ctx.mutate((ont) => ops.declareEdgeProperty(ont, ctx.args[0], ctx.args[1], { type: o.type, values: o.values, required: o.required, description: o.desc, remove: o.remove }));
|
|
429
|
+
},
|
|
430
|
+
},
|
|
431
|
+
],
|
|
432
|
+
},
|
|
433
|
+
];
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/** Planning: scope, competency questions, reuse and terms (steps 1 to 3). */
|
|
2
|
+
import { opt } from "../command-table.js";
|
|
3
|
+
import {} from "@ontology-kit/reader";
|
|
4
|
+
import * as ops from "../ops.js";
|
|
5
|
+
import { renderQuestions, renderReuse, renderScope, renderTerms } from "../render.js";
|
|
6
|
+
const { str, strs } = opt;
|
|
7
|
+
const SCOPE_OPTIONS = { name: str, domain: str, purpose: str, users: strs, maintainers: strs, "out-of-scope": strs, kind: str };
|
|
8
|
+
export const planning = [
|
|
9
|
+
{
|
|
10
|
+
name: "scope",
|
|
11
|
+
group: "Planning",
|
|
12
|
+
summary: "record the domain, purpose and users",
|
|
13
|
+
description: "Records the domain, purpose, users and boundaries of the ontology. With no flags it shows what you have.",
|
|
14
|
+
forms: [
|
|
15
|
+
{
|
|
16
|
+
description: "Sets any of the fields you pass and prints the result.",
|
|
17
|
+
examples: ["okb scope --domain \"Wine and food pairing\" --purpose \"Recommend wines for a meal\" --users sommeliers,cooks"],
|
|
18
|
+
args: [
|
|
19
|
+
["--domain", "text", "What the ontology covers."],
|
|
20
|
+
["--purpose", "text", "What it is for."],
|
|
21
|
+
["--users", "list", "Who will use it."],
|
|
22
|
+
["--maintainers", "list", "Who keeps it up to date."],
|
|
23
|
+
["--out-of-scope", "list", "What it deliberately leaves out."],
|
|
24
|
+
["--kind", "text", "The kind of ontology, such as a domain ontology."],
|
|
25
|
+
["--name", "text", "Rename the ontology."],
|
|
26
|
+
],
|
|
27
|
+
options: SCOPE_OPTIONS,
|
|
28
|
+
cheat: { example: "okb scope --domain \"...\" --purpose \"...\"", description: "Record what the ontology is for" },
|
|
29
|
+
run: (ctx) => {
|
|
30
|
+
const o = ctx.opts;
|
|
31
|
+
const touched = Object.keys(SCOPE_OPTIONS).some((k) => o[k] !== undefined);
|
|
32
|
+
const ont = touched
|
|
33
|
+
? ctx.edit((ont) => {
|
|
34
|
+
ops.setScope(ont, { name: o.name, domain: o.domain, purpose: o.purpose, users: o.users, maintainers: o.maintainers, outOfScope: o["out-of-scope"], kind: o.kind });
|
|
35
|
+
ont.save();
|
|
36
|
+
return ont;
|
|
37
|
+
})
|
|
38
|
+
: ctx.load();
|
|
39
|
+
ctx.emit(() => ont.meta, () => renderScope(ont.meta));
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "cq",
|
|
46
|
+
group: "Planning",
|
|
47
|
+
summary: "competency questions",
|
|
48
|
+
description: "Manages competency questions: the questions your ontology must be able to answer.",
|
|
49
|
+
bare: "list",
|
|
50
|
+
forms: [
|
|
51
|
+
{
|
|
52
|
+
sub: "add",
|
|
53
|
+
description: "Adds one or more questions.",
|
|
54
|
+
examples: ["okb cq add \"Which wines go with fish?\""],
|
|
55
|
+
args: [
|
|
56
|
+
["<question>", "text", "The question. Quote it."],
|
|
57
|
+
],
|
|
58
|
+
usage: 'Usage: okb cq add "Your question?"',
|
|
59
|
+
min: 1,
|
|
60
|
+
cheat: { example: "okb cq add \"Which wines go with fish?\"", description: "Add a competency question" },
|
|
61
|
+
run: (ctx) => ctx.mutate((ont) => ctx.args.flatMap((t) => ops.addCQ(ont, t))),
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
sub: "list",
|
|
65
|
+
description: "Lists the questions and what each one needs. Bare `okb cq` does the same.",
|
|
66
|
+
examples: ["okb cq list"],
|
|
67
|
+
args: [],
|
|
68
|
+
run: (ctx) => {
|
|
69
|
+
const ont = ctx.load();
|
|
70
|
+
const qs = ont.numbered("CompetencyQuestion");
|
|
71
|
+
ctx.emit(() => qs.map((q) => ({ ...q, needs: ont.targets(q.id, "NEEDS") })), () => renderQuestions(ont, qs));
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
sub: "link",
|
|
76
|
+
description: "Says which classes, slots or instances a question needs. Use `unlink` to undo it.",
|
|
77
|
+
examples: ["okb cq link 1 Wine Food goesWellWith"],
|
|
78
|
+
args: [
|
|
79
|
+
["<number>", "number", "The question's number."],
|
|
80
|
+
["<name>...", "names", "The classes, slots or instances it needs."],
|
|
81
|
+
],
|
|
82
|
+
usage: "Usage: okb cq link <question number> <Class|slot|instance>...",
|
|
83
|
+
min: 2,
|
|
84
|
+
run: (ctx) => ctx.mutate((ont) => ops.linkCQ(ont, ctx.args[0], ctx.args.slice(1), false)),
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
sub: "set",
|
|
88
|
+
description: "Changes a question's text or marks it answerable.",
|
|
89
|
+
examples: ["okb cq set 1 --status answerable"],
|
|
90
|
+
args: [
|
|
91
|
+
["<number>", "number", "The question's number."],
|
|
92
|
+
["--text", "text", "New wording."],
|
|
93
|
+
["--status", "draft or answerable", "Whether the ontology can answer it yet."],
|
|
94
|
+
],
|
|
95
|
+
options: { text: str, status: str },
|
|
96
|
+
run: (ctx) => ctx.mutate((ont) => ops.setCQ(ont, ctx.args[0], { text: ctx.opts.text, status: ctx.opts.status })),
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
sub: "remove",
|
|
100
|
+
description: "Deletes a question.",
|
|
101
|
+
examples: ["okb cq remove 3"],
|
|
102
|
+
args: [
|
|
103
|
+
["<number>", "number", "The question's number."],
|
|
104
|
+
],
|
|
105
|
+
run: (ctx) => ctx.mutate((ont) => ops.remove(ont, ctx.args[0], ["CompetencyQuestion"])),
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
sub: "unlink",
|
|
109
|
+
description: "",
|
|
110
|
+
examples: [],
|
|
111
|
+
args: [],
|
|
112
|
+
usage: "Usage: okb cq unlink <question number> <Class|slot|instance>...",
|
|
113
|
+
min: 2,
|
|
114
|
+
hidden: true,
|
|
115
|
+
run: (ctx) => ctx.mutate((ont) => ops.linkCQ(ont, ctx.args[0], ctx.args.slice(1), true)),
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: "reuse",
|
|
121
|
+
group: "Planning",
|
|
122
|
+
summary: "record existing ontologies you considered",
|
|
123
|
+
description: "Records which existing ontologies you looked at and what you decided about each.",
|
|
124
|
+
bare: "list",
|
|
125
|
+
forms: [
|
|
126
|
+
{
|
|
127
|
+
sub: "add",
|
|
128
|
+
description: "Records one ontology you considered.",
|
|
129
|
+
examples: ["okb reuse add --name FOAF --url http://xmlns.com/foaf/spec/ --decision reference"],
|
|
130
|
+
args: [
|
|
131
|
+
["--name", "text", "The ontology's name."],
|
|
132
|
+
["--decision", "reuse, adapt, reference or rejected", "What you decided."],
|
|
133
|
+
["--url", "url", "Where it lives."],
|
|
134
|
+
["--notes", "text", "Why."],
|
|
135
|
+
],
|
|
136
|
+
options: { name: str, url: str, decision: str, notes: str },
|
|
137
|
+
usage: "Usage: okb reuse add --name ... --decision reuse|adapt|reference|rejected [--url ...] [--notes ...]",
|
|
138
|
+
require: ["name", "decision"],
|
|
139
|
+
run: (ctx) => ctx.mutate((ont) => ops.addReuse(ont, { name: ctx.opts.name, url: ctx.opts.url, decision: ctx.opts.decision, notes: ctx.opts.notes })),
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
sub: "none",
|
|
143
|
+
description: "Records that you looked and found nothing that fits.",
|
|
144
|
+
examples: ["okb reuse none --why \"Checked schema.org and FOAF; neither covers wine.\""],
|
|
145
|
+
args: [
|
|
146
|
+
["--why", "text", "What you looked at and why nothing fit."],
|
|
147
|
+
],
|
|
148
|
+
options: { why: str },
|
|
149
|
+
usage: 'Usage: okb reuse none --why "what you looked at and why nothing fit"',
|
|
150
|
+
require: ["why"],
|
|
151
|
+
cheat: { example: "okb reuse none --why \"...\"", description: "Record that nothing existing fits" },
|
|
152
|
+
run: (ctx) => ctx.mutate((ont) => ops.reuseNone(ont, ctx.opts.why)),
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
sub: "list",
|
|
156
|
+
description: "Lists what you recorded. Bare `okb reuse` does the same.",
|
|
157
|
+
examples: ["okb reuse list"],
|
|
158
|
+
args: [],
|
|
159
|
+
run: (ctx) => ctx.print(renderReuse(ctx.load())),
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: "term",
|
|
165
|
+
group: "Planning",
|
|
166
|
+
summary: "collect the words of your domain",
|
|
167
|
+
description: "Collects the important words of your domain, then decides what each one becomes.",
|
|
168
|
+
bare: "list",
|
|
169
|
+
forms: [
|
|
170
|
+
{
|
|
171
|
+
sub: "add",
|
|
172
|
+
description: "Adds terms to the list.",
|
|
173
|
+
examples: ["okb term add wine grape winery color"],
|
|
174
|
+
args: [
|
|
175
|
+
["<term>...", "text", "One or more terms. Quote multi-word terms."],
|
|
176
|
+
["--note", "text", "A note to keep with them."],
|
|
177
|
+
],
|
|
178
|
+
options: { note: str },
|
|
179
|
+
usage: "Usage: okb term add <term> [<term>...] (quote multi-word terms)",
|
|
180
|
+
min: 1,
|
|
181
|
+
cheat: { example: "okb term add wine grape winery", description: "Collect the words of your domain" },
|
|
182
|
+
run: (ctx) => ctx.mutate((ont) => ops.addTerms(ont, ctx.args, ctx.opts.note)),
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
sub: "list",
|
|
186
|
+
description: "Lists terms grouped by what you decided. Bare `okb term` does the same.",
|
|
187
|
+
examples: ["okb term list"],
|
|
188
|
+
args: [],
|
|
189
|
+
run: (ctx) => {
|
|
190
|
+
const ont = ctx.load();
|
|
191
|
+
ctx.emit(() => ont.ofType("Term"), () => renderTerms(ont));
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
sub: "set",
|
|
196
|
+
description: "Decides what a term becomes.",
|
|
197
|
+
examples: ["okb term set wine --as class", "okb term set vintage --as synonym --node Year"],
|
|
198
|
+
args: [
|
|
199
|
+
["<term>", "text", "The term."],
|
|
200
|
+
["--as", "class, slot, instance, value, synonym or out-of-scope", "What it becomes."],
|
|
201
|
+
["--node", "name", "The class, slot or instance it became or points to."],
|
|
202
|
+
["--note", "text", "A note about the decision."],
|
|
203
|
+
],
|
|
204
|
+
options: { as: str, node: str, note: str },
|
|
205
|
+
usage: "Usage: okb term set <term> --as class|slot|instance|value|synonym|out-of-scope [--node Name]",
|
|
206
|
+
min: 1,
|
|
207
|
+
require: ["as"],
|
|
208
|
+
run: (ctx) => ctx.mutate((ont) => ops.setTerm(ont, ctx.args[0], ctx.opts.as, ctx.opts.node, ctx.opts.note)),
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
},
|
|
212
|
+
];
|