@aehrc/ecl-core 1.6.1 → 1.7.0
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/README.md +181 -8
- package/dist/derive/compress-expression.d.ts +55 -0
- package/dist/derive/compress-expression.d.ts.map +1 -0
- package/dist/derive/cover-optimiser.d.ts +20 -0
- package/dist/derive/cover-optimiser.d.ts.map +1 -0
- package/dist/derive/critique.d.ts +25 -0
- package/dist/derive/critique.d.ts.map +1 -0
- package/dist/derive/derive-ecl.d.ts +262 -0
- package/dist/derive/derive-ecl.d.ts.map +1 -0
- package/dist/derive/greedy-grouping.d.ts +15 -0
- package/dist/derive/greedy-grouping.d.ts.map +1 -0
- package/dist/derive/hierarchy-clauses.d.ts +35 -0
- package/dist/derive/hierarchy-clauses.d.ts.map +1 -0
- package/dist/derive/refinements.d.ts +39 -0
- package/dist/derive/refinements.d.ts.map +1 -0
- package/dist/derive/set-queries.d.ts +53 -0
- package/dist/derive/set-queries.d.ts.map +1 -0
- package/dist/derive/taxonomy-graph.d.ts +38 -0
- package/dist/derive/taxonomy-graph.d.ts.map +1 -0
- package/dist/formatter/comments.d.ts +15 -0
- package/dist/formatter/comments.d.ts.map +1 -1
- package/dist/formatter/formatter.d.ts.map +1 -1
- package/dist/formatter/rules.d.ts +2 -0
- package/dist/formatter/rules.d.ts.map +1 -1
- package/dist/index.cjs +3280 -965
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +3274 -966
- package/dist/refactoring/index.d.ts +2 -1
- package/dist/refactoring/index.d.ts.map +1 -1
- package/dist/refactoring/simplify-expression.d.ts +50 -0
- package/dist/refactoring/simplify-expression.d.ts.map +1 -1
- package/dist/terminology/fhir-service.d.ts +23 -1
- package/dist/terminology/fhir-service.d.ts.map +1 -1
- package/dist/terminology/types.d.ts +58 -0
- package/dist/terminology/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -64,7 +64,7 @@ const refined = refineParseError({ line, column, message, expression });
|
|
|
64
64
|
```typescript
|
|
65
65
|
import { validateSemantics, FhirTerminologyService } from '@aehrc/ecl-core';
|
|
66
66
|
|
|
67
|
-
const terminology = new FhirTerminologyService('https://tx.ontoserver.csiro.au/fhir');
|
|
67
|
+
const terminology = new FhirTerminologyService({ baseUrl: 'https://tx.ontoserver.csiro.au/fhir' });
|
|
68
68
|
const diagnostics = await validateSemantics(ast, text, terminology);
|
|
69
69
|
```
|
|
70
70
|
|
|
@@ -90,24 +90,197 @@ const actions = getRefactoringActions({ text, range, ast, errors });
|
|
|
90
90
|
// history supplement, description filter
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
+
The Simplify action's engine is also available as a plain function. It never
|
|
94
|
+
changes the set of concepts the expression selects, and it reports each step it
|
|
95
|
+
applied. Without a terminology service only the syntactic techniques run
|
|
96
|
+
(`subsumption: 'not-run'`).
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
import { simplifyExpression } from '@aehrc/ecl-core';
|
|
100
|
+
|
|
101
|
+
const result = await simplifyExpression('< 404684003 OR << 404684003', terminologyService);
|
|
102
|
+
// result.expression → '<< 404684003'
|
|
103
|
+
// result.steps → [{ technique: 'rankOperators', removed: ['< 404684003'], ... }]
|
|
104
|
+
// result.subsumption → 'complete' | 'partial' | 'not-applicable' (no AND/OR left to check) | 'not-run' (no service)
|
|
105
|
+
```
|
|
106
|
+
|
|
93
107
|
### Terminology
|
|
94
108
|
|
|
95
109
|
```typescript
|
|
96
110
|
import { FhirTerminologyService } from '@aehrc/ecl-core';
|
|
97
111
|
|
|
98
|
-
const fhir = new FhirTerminologyService(
|
|
99
|
-
'https://tx.ontoserver.csiro.au/fhir', //
|
|
100
|
-
2000, // lookup timeout (ms)
|
|
101
|
-
'', // SNOMED version URI (empty = server default)
|
|
102
|
-
);
|
|
112
|
+
const fhir = new FhirTerminologyService({
|
|
113
|
+
baseUrl: 'https://tx.ontoserver.csiro.au/fhir', // default
|
|
114
|
+
timeout: 2000, // lookup timeout (ms)
|
|
115
|
+
snomedVersion: '', // SNOMED version URI (empty = server default)
|
|
116
|
+
});
|
|
103
117
|
|
|
104
|
-
const concept = await fhir.
|
|
105
|
-
// { id, fsn, pt, active }
|
|
118
|
+
const concept = await fhir.getConceptInfo('404684003');
|
|
119
|
+
// { id, fsn, pt, active } or null when the server does not know it
|
|
106
120
|
|
|
107
121
|
const results = await fhir.evaluateEcl('< 404684003');
|
|
108
122
|
// { concepts: [...], total }
|
|
109
123
|
```
|
|
110
124
|
|
|
125
|
+
### Deriving ECL from a Concept List
|
|
126
|
+
|
|
127
|
+
The opposite of `$expand`: given a code list or a reference set, propose ECL
|
|
128
|
+
that selects it, ranked, each with exact counts and samples of what it adds and
|
|
129
|
+
misses. The server does every set operation (`expandCompose`, a POSTed inline
|
|
130
|
+
ValueSet), so lists of 100,000 codes work. No language model is involved.
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { deriveEcl, FhirTerminologyService } from '@aehrc/ecl-core';
|
|
134
|
+
|
|
135
|
+
const result = await deriveEcl({ conceptIds: ['46635009', '44054006' /* … */] }, new FhirTerminologyService());
|
|
136
|
+
// or: deriveEcl({ refsetId: '929360061000036106' }, terminology)
|
|
137
|
+
|
|
138
|
+
result.input; // { members, inactive, unknown, malformed, duplicates } — what was left out, and why
|
|
139
|
+
result.candidates[0];
|
|
140
|
+
// { expression: '<< 73211009 | Diabetes |', ecl: '<< 73211009',
|
|
141
|
+
// covered: 121, additions: { count: 0, sample: [] }, misses: { count: 0, sample: [] },
|
|
142
|
+
// exact: true, clauses: 1, construction: { kind: 'hierarchy', roots: ['73211009'], … } }
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Candidates come from the IS-A hierarchy: an exact cover of the set's roots with
|
|
146
|
+
`MINUS` exclusions, cheaper covers by ancestors outside the set (with their
|
|
147
|
+
additions reported), a greedy grouping, a cost-based cover, and always the
|
|
148
|
+
enumeration or `^ refset` itself. They are ranked by clauses + additions +
|
|
149
|
+
misses.
|
|
150
|
+
|
|
151
|
+
The hierarchy candidates are built from one IS-A subgraph around the set,
|
|
152
|
+
fetched in about four expansions that return each concept's parents
|
|
153
|
+
(`expandCompose` with `parents: true`, FHIR `property=parent`): the set, its
|
|
154
|
+
ancestors, their children, and the descendants of the ancestors worth trying
|
|
155
|
+
as groupers. Candidates are built and ranked on that graph without further
|
|
156
|
+
requests, and only the best are counted again on the server, so every count
|
|
157
|
+
reported comes from the server. A graph candidate that by its local counts
|
|
158
|
+
costs at least as much as the input itself (listing every member, or the
|
|
159
|
+
expression given) is not counted, with a note.
|
|
160
|
+
|
|
161
|
+
The cost-based cover treats the set as a weighted set cover: a grouper costs its own clause plus the exclusions that
|
|
162
|
+
make it exact, a listed member costs one clause, and groupers are taken while
|
|
163
|
+
they cover more members per clause than listing them would. When the server
|
|
164
|
+
does not return parents, or a fetch would hold more than `maxGraphConcepts`
|
|
165
|
+
concepts (default 200,000), the hierarchy candidates fall back to a query per
|
|
166
|
+
count, with a note. Set `useGraph: false` to always use that path. When only
|
|
167
|
+
the descendants of every root and grouper are too many, they are loaded for
|
|
168
|
+
greedy grouping's groupers alone: the graph is partial, forms that need the
|
|
169
|
+
others are left out, and a note says so. `maxAncestorRoots` and
|
|
170
|
+
`maxAncestorCandidates` limit the per-query path only. `maxRoots` limits the
|
|
171
|
+
per-query path's hierarchy candidates, and on either path how many roots are
|
|
172
|
+
used for refinement candidates.
|
|
173
|
+
|
|
174
|
+
The greedy grouping follows REFACTOR, the grouping algorithm in NHS England's
|
|
175
|
+
DMWB (Jeremy Rogers). It scores every ancestor of the set by how much of it is
|
|
176
|
+
in the set, picks groupers while it relaxes its fit threshold, and lists the
|
|
177
|
+
members left over. It then excludes what the groupers add, so it is always
|
|
178
|
+
exact. It is not limited by the number of roots, so it also works on clinical
|
|
179
|
+
sets with hundreds of roots. It is offered only on the graph path: it needs
|
|
180
|
+
the subgraph, so without a server that returns parents, or with
|
|
181
|
+
`useGraph: false`, it is skipped. Set `greedyGrouping: false` to leave
|
|
182
|
+
it out.
|
|
183
|
+
|
|
184
|
+
Sets that cut across the hierarchy (many roots and no short exact IS-A cover,
|
|
185
|
+
e.g. AMT products) also
|
|
186
|
+
get attribute refinement candidates, `focus : attribute = values`. The
|
|
187
|
+
attributes come from the relationships of a sample of members
|
|
188
|
+
(`getDefiningRelationships`). Their values are compressed with the IS-A
|
|
189
|
+
candidates. The focus is the most specific concept above every member, or a
|
|
190
|
+
refset named in an ECL input, or `refinementFocus`. Set `refinements: 'always'`
|
|
191
|
+
or `'never'` to override.
|
|
192
|
+
|
|
193
|
+
Refinement values can be concepts (`<< x`), concrete values (`#500`, a shared
|
|
194
|
+
value, a range with `>=` and `<=`, or `= *`) and cardinalities
|
|
195
|
+
(`[2..*] attribute = *`). When no refinement is exact, a subtraction
|
|
196
|
+
`(C) MINUS (D)` is also tried, with D describing what the refinement C adds.
|
|
197
|
+
|
|
198
|
+
`deriveEcl({ ecl }, terminology)` takes the set an expression selects. For
|
|
199
|
+
pasted text, `deriveInputFromText(text)` picks the input: a list of bare
|
|
200
|
+
concepts joined by OR, AND or commas becomes `{ conceptIds }` (so inactive and
|
|
201
|
+
unknown ids are reported), any other valid expression `{ ecl }`, and anything
|
|
202
|
+
else is read by `parseConceptIdList` (one id per line or CSV rows; a line of
|
|
203
|
+
only ids, such as `id id id` or a JSON array, gives all of them). Text holding
|
|
204
|
+
several expressions separated by `/* ECL-END */` is refused. The language
|
|
205
|
+
server's derive request uses it.
|
|
206
|
+
To make
|
|
207
|
+
an expression shorter, use `compressExpression`. It compresses the expression's
|
|
208
|
+
OR group, keeps what surrounds the group (`AND ^ refset`, a refinement) as
|
|
209
|
+
written, and counts what the whole expression then adds and misses. The
|
|
210
|
+
original and its exact simplification are always among the candidates.
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
import { compressExpression } from '@aehrc/ecl-core';
|
|
214
|
+
|
|
215
|
+
const { candidates } = await compressExpression('(<< 372594008 OR << 372767007 OR …) AND ^ 929360081000036101', fhir);
|
|
216
|
+
// candidates[i]: { expression, ecl, additions, misses, exact, clauses, source: 'derived' | 'simplified' | 'original' }
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
#### Critique of the list
|
|
220
|
+
|
|
221
|
+
With `critique: true` (or an object of limits), `deriveEcl` also returns
|
|
222
|
+
`result.critique`: structural checks that point to a list worth fixing before
|
|
223
|
+
it is turned into ECL. They follow checks of the NHS ValueSet Management Tool
|
|
224
|
+
(CHK numbers below), and all are advisory. `formatDeriveReport` prints them
|
|
225
|
+
under "Review:". The checks:
|
|
226
|
+
|
|
227
|
+
| Field | Check | Flags | Limit (default) |
|
|
228
|
+
| ------------------ | ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
|
|
229
|
+
| `clauses` | CHK16 | The best exact candidate needs more clauses than the limit | `maxClauses` (35) |
|
|
230
|
+
| `nearMisses` | CHK12 | Concepts X where the list holds most, but not all, of `<< X`, with the missing concepts counted on the server. Only the outermost of nested ones is listed | `nearMissShare` (0.9), `nearMissMinSize` (5), `maxNearMisses` (5) |
|
|
231
|
+
| `spansHierarchies` | CHK15 | Members in more than one top-level hierarchy (`hierarchies` gives the counts) | |
|
|
232
|
+
| `inactive` | CHK07 | Inactive ids in the input, or a reference set's inactive members | |
|
|
233
|
+
| `impliedInactive` | CHK08 | Inactive concepts the members' history implies but the input leaves out. Off unless asked for; needs ECL history supplements on the server | `impliedInactive` (false; `true` is `'HISTORY-MOD'`) |
|
|
234
|
+
|
|
235
|
+
Near misses need the IS-A subgraph (see `useGraph`); without it they are
|
|
236
|
+
skipped with a note. Only groupers whose subtree the subgraph loaded are judged:
|
|
237
|
+
those the covers and greedy grouping consider, which have mostly members below
|
|
238
|
+
them. A grouper over mostly non-members is not, even if the list holds enough
|
|
239
|
+
of it.
|
|
240
|
+
|
|
241
|
+
Cost: on the graph path, the clause limit, hierarchies and a list's inactive ids
|
|
242
|
+
need no extra request (off it, the hierarchies need the summary's queries, even
|
|
243
|
+
with `hierarchySummary: false`, which only leaves them out of
|
|
244
|
+
`result.hierarchies`). Near misses take one request per concept reported, plus
|
|
245
|
+
one for their terms; a reference set's inactive members one count (and two
|
|
246
|
+
listings when there are any); implied inactive codes one. The language server's
|
|
247
|
+
derive request turns the critique on.
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
const result = await deriveEcl({ conceptIds }, fhir, { critique: { maxClauses: 40, impliedInactive: true } });
|
|
251
|
+
// result.critique: { clauses, nearMisses, hierarchies, spansHierarchies, inactive, impliedInactive? }
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
#### Benchmark
|
|
255
|
+
|
|
256
|
+
`scripts/derive-benchmark.cjs` runs `deriveEcl` over a file of reference sets
|
|
257
|
+
and, optionally, judges reference ECL for the same sets on the same release.
|
|
258
|
+
It reads the compiled library, so run `npm run compile` first.
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
node scripts/derive-benchmark.cjs \
|
|
262
|
+
--sets members.tsv --reference refactor.tsv \
|
|
263
|
+
--version http://snomed.info/sct/83821000000107/version/20230830 \
|
|
264
|
+
--base-url https://tx.ontoserver.csiro.au/fhir --max-size 10000 \
|
|
265
|
+
--out results.jsonl
|
|
266
|
+
node scripts/derive-benchmark.cjs --out results.jsonl --summary
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
The input files use the layout of the NHS England DMWB export (tab-separated,
|
|
270
|
+
latin1, with `ID`, `DESCRIPTION` and `SCTRULE` columns, `SCTRULE` holding the
|
|
271
|
+
ECL). The UK clinical reference sets used in development came from the DMWB
|
|
272
|
+
export of the 37.0.0 release, with REFACTOR's intensional definitions as the
|
|
273
|
+
reference; the data files are not part of this repository. Results are judged
|
|
274
|
+
on the release given with `--version`, so a reference made on another release
|
|
275
|
+
can add or miss concepts there. Each output line holds the set's top
|
|
276
|
+
candidate, its best exact candidate, the reference, the time taken and the
|
|
277
|
+
number of `expandCompose` requests. The run is resumable (sets already in
|
|
278
|
+
`--out` are skipped), retries a failed set once after 30 s, and pauses 1.5 s
|
|
279
|
+
between sets to stay inside public servers' rate limits. `--no-graph` runs the
|
|
280
|
+
per-query path for comparison, and `--only id,id` limits the run to some sets.
|
|
281
|
+
`--summary` prints win/tie/loss against the reference by cost and by exact
|
|
282
|
+
clauses, total clauses, and median and maximum time and requests.
|
|
283
|
+
|
|
111
284
|
### Canonical Comparison
|
|
112
285
|
|
|
113
286
|
```typescript
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ITerminologyService } from '../terminology/types';
|
|
2
|
+
import { CandidateConstruction, DeriveOptions } from './derive-ecl';
|
|
3
|
+
import { SetDifference } from './set-queries';
|
|
4
|
+
export interface CompressCandidate {
|
|
5
|
+
/** The candidate, formatted, with display terms unless `omitTerms`. */
|
|
6
|
+
expression: string;
|
|
7
|
+
/** The same expression without terms, as built. */
|
|
8
|
+
ecl: string;
|
|
9
|
+
/** Concepts it selects that the original does not. */
|
|
10
|
+
additions: SetDifference;
|
|
11
|
+
/** Concepts the original selects that it does not. */
|
|
12
|
+
misses: SetDifference;
|
|
13
|
+
exact: boolean;
|
|
14
|
+
/** Concept references in `ecl`. */
|
|
15
|
+
clauses: number;
|
|
16
|
+
/**
|
|
17
|
+
* True when the form can stand as an operand of a larger expression as it is
|
|
18
|
+
* (one sub-expression); otherwise it needs brackets there, since ECL does not
|
|
19
|
+
* mix AND, OR and MINUS without them.
|
|
20
|
+
*/
|
|
21
|
+
standalone: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* - `original`: the expression as given
|
|
24
|
+
* - `simplified`: the exact simplification (`simplifyExpression`)
|
|
25
|
+
* - `derived`: a `deriveEcl` candidate for the group, put back in place
|
|
26
|
+
*/
|
|
27
|
+
source: 'original' | 'simplified' | 'derived';
|
|
28
|
+
/** For `derived`: how the replacement for the group was built. */
|
|
29
|
+
construction?: CandidateConstruction;
|
|
30
|
+
}
|
|
31
|
+
export interface CompressResult {
|
|
32
|
+
/** Concepts the original selects. */
|
|
33
|
+
members: number;
|
|
34
|
+
/** The part of the expression that was compressed, or null when nothing could be. */
|
|
35
|
+
group: {
|
|
36
|
+
text: string;
|
|
37
|
+
start: number;
|
|
38
|
+
end: number;
|
|
39
|
+
} | null;
|
|
40
|
+
/** Best first: by clauses + additions + misses, exact first on a tie. */
|
|
41
|
+
candidates: CompressCandidate[];
|
|
42
|
+
notes: string[];
|
|
43
|
+
/** Syntax errors; the expression is not compressed when there are any. */
|
|
44
|
+
errors: string[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Propose shorter forms of an ECL expression, each with exact counts and
|
|
48
|
+
* samples of what it adds to and misses from the original's result set.
|
|
49
|
+
*
|
|
50
|
+
* Needs a terminology service with `expandCompose`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function compressExpression(ecl: string, terminology: ITerminologyService, options?: DeriveOptions): Promise<CompressResult>;
|
|
53
|
+
/** A plain-text report of a {@link CompressResult}, for an output channel or a chat message. */
|
|
54
|
+
export declare function formatCompressReport(result: CompressResult): string;
|
|
55
|
+
//# sourceMappingURL=compress-expression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compress-expression.d.ts","sourceRoot":"","sources":["../../src/derive/compress-expression.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAIL,KAAK,qBAAqB,EAE1B,KAAK,aAAa,EACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAuC,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAExF,MAAM,WAAW,iBAAiB;IAChC,uEAAuE;IACvE,UAAU,EAAE,MAAM,CAAC;IACnB,mDAAmD;IACnD,GAAG,EAAE,MAAM,CAAC;IACZ,sDAAsD;IACtD,SAAS,EAAE,aAAa,CAAC;IACzB,sDAAsD;IACtD,MAAM,EAAE,aAAa,CAAC;IACtB,KAAK,EAAE,OAAO,CAAC;IACf,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,UAAU,EAAE,OAAO,CAAC;IACpB;;;;OAIG;IACH,MAAM,EAAE,UAAU,GAAG,YAAY,GAAG,SAAS,CAAC;IAC9C,kEAAkE;IAClE,YAAY,CAAC,EAAE,qBAAqB,CAAC;CACtC;AAED,MAAM,WAAW,cAAc;IAC7B,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,qFAAqF;IACrF,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC3D,yEAAyE;IACzE,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAChC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,0EAA0E;IAC1E,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,mBAAmB,EAChC,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,cAAc,CAAC,CAsEzB;AAuHD,gGAAgG;AAChG,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAoBnE"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ClauseForm } from './hierarchy-clauses';
|
|
2
|
+
import { TaxonomyGraph } from './taxonomy-graph';
|
|
3
|
+
/** Roots as `<< r`, with exact exclusions: today's hierarchy cover, computed locally. */
|
|
4
|
+
export declare function rootsCover(g: TaxonomyGraph): ClauseForm;
|
|
5
|
+
/**
|
|
6
|
+
* Exact cover, a greedy approximation of the fewest clauses (includes plus
|
|
7
|
+
* exclusions). Lazy greedy: a grouper's count of members not yet covered only
|
|
8
|
+
* falls, so the count it was queued with bounds its current one, and a
|
|
9
|
+
* grouper whose count is still current when it comes first is the best.
|
|
10
|
+
*/
|
|
11
|
+
export declare function costCover(g: TaxonomyGraph, candidates: string[]): ClauseForm;
|
|
12
|
+
/** `coverDescend`: which ancestors costCover considers (passed to loadTaxonomyGraph). */
|
|
13
|
+
export declare function coverDescend(id: string, g: Pick<TaxonomyGraph, 'truePos' | 'children' | 'members'>): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* The best `k` single clauses by clauses + additions + misses (lossy allowed),
|
|
16
|
+
* each counted from the graph: `<< a` or `< a` selects the members at or below
|
|
17
|
+
* a (a is in it only when it is a member) and adds the rest of what it selects.
|
|
18
|
+
*/
|
|
19
|
+
export declare function bestSingles(g: TaxonomyGraph, candidates: string[], k: number): ClauseForm[];
|
|
20
|
+
//# sourceMappingURL=cover-optimiser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cover-optimiser.d.ts","sourceRoot":"","sources":["../../src/derive/cover-optimiser.ts"],"names":[],"mappings":"AAUA,OAAO,EAA0B,KAAK,UAAU,EAAwB,MAAM,qBAAqB,CAAC;AAEpG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAMtD,yFAAyF;AACzF,wBAAgB,UAAU,CAAC,CAAC,EAAE,aAAa,GAAG,UAAU,CAGvD;AAUD;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,UAAU,CAyB5E;AAED,yFAAyF;AACzF,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC,GAAG,OAAO,CAK5G;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,UAAU,EAAE,CAU3F"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TaxonomyGraph } from './taxonomy-graph';
|
|
2
|
+
/** A grouper the list nearly fills, counted on the graph. */
|
|
3
|
+
export interface LocalNearMiss {
|
|
4
|
+
conceptId: string;
|
|
5
|
+
/** Concepts in `<< conceptId`. */
|
|
6
|
+
descendants: number;
|
|
7
|
+
/** Members in `<< conceptId`. */
|
|
8
|
+
listed: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Concepts X whose `<< X` has at least `minSize` concepts, of which the list
|
|
12
|
+
* holds at least `share` but not all; largest first, nested ones included.
|
|
13
|
+
* Only concepts with their descendants loaded are considered.
|
|
14
|
+
*/
|
|
15
|
+
export declare function nearMissCandidates(g: TaxonomyGraph, share: number, minSize: number): LocalNearMiss[];
|
|
16
|
+
/**
|
|
17
|
+
* The first `max` of `items` (largest first) that are not inside one already
|
|
18
|
+
* taken: its missing members are among that one's.
|
|
19
|
+
*/
|
|
20
|
+
export declare function outermost<T extends {
|
|
21
|
+
conceptId: string;
|
|
22
|
+
}>(g: TaxonomyGraph, items: T[], max: number): T[];
|
|
23
|
+
/** The near misses on the graph alone: {@link nearMissCandidates}, outermost first, at most `max`. */
|
|
24
|
+
export declare function findNearMisses(g: TaxonomyGraph, share: number, minSize: number, max: number): LocalNearMiss[];
|
|
25
|
+
//# sourceMappingURL=critique.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"critique.d.ts","sourceRoot":"","sources":["../../src/derive/critique.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,6DAA6D;AAC7D,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,kCAAkC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,aAAa,EAAE,CAWpG;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,EAAE,CAUzG;AAED,sGAAsG;AACtG,wBAAgB,cAAc,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,aAAa,EAAE,CAE7G"}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { ITerminologyService } from '../terminology/types';
|
|
2
|
+
import { SetDifference } from './set-queries';
|
|
3
|
+
import { HierarchyClause } from './hierarchy-clauses';
|
|
4
|
+
import { RefinementClause } from './refinements';
|
|
5
|
+
/** The set to derive ECL for: an enumerated list of concept ids, or a reference set's members. */
|
|
6
|
+
/**
|
|
7
|
+
* The set to derive ECL for: an enumerated list of concept ids, a reference
|
|
8
|
+
* set's members, or the concepts an ECL expression selects (to find a shorter
|
|
9
|
+
* form of it, issue #149).
|
|
10
|
+
*/
|
|
11
|
+
export type DeriveInput = {
|
|
12
|
+
conceptIds: string[];
|
|
13
|
+
} | {
|
|
14
|
+
refsetId: string;
|
|
15
|
+
} | {
|
|
16
|
+
ecl: string;
|
|
17
|
+
};
|
|
18
|
+
export interface DeriveOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Per-query path: above this many roots, hierarchy candidates are skipped as
|
|
21
|
+
* not compact (on the graph path they cost no query per root). On either
|
|
22
|
+
* path, the most roots refinement candidates take as their basis. Default 200.
|
|
23
|
+
*/
|
|
24
|
+
maxRoots?: number;
|
|
25
|
+
/** Most `MINUS << x` subtree exclusions in an exact hierarchy cover. Default 32. */
|
|
26
|
+
maxExclusions?: number;
|
|
27
|
+
/** Most literal ids the exact cover may exclude before it is reported as lossy instead. Default 50. */
|
|
28
|
+
maxResidualLiterals?: number;
|
|
29
|
+
/** Per-query path: above this many roots, ancestor covers are skipped (they cost a query per root). Default 50. */
|
|
30
|
+
maxAncestorRoots?: number;
|
|
31
|
+
/** Per-query path: most ancestors whose counts are fetched for ancestor covers. Default 30. */
|
|
32
|
+
maxAncestorCandidates?: number;
|
|
33
|
+
/** Concepts returned in each additions/misses sample. Default 10. */
|
|
34
|
+
sampleSize?: number;
|
|
35
|
+
/** Most candidates returned. Default 8. */
|
|
36
|
+
maxCandidates?: number;
|
|
37
|
+
/** Leave display terms out of `expression`. Default false. */
|
|
38
|
+
omitTerms?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Attribute refinement candidates (`focus : attribute = value`):
|
|
41
|
+
* `'auto'` builds them when the set cuts across the IS-A hierarchy: more than
|
|
42
|
+
* 20 roots, or more than 3 with no exact IS-A candidate of 3 clauses or fewer.
|
|
43
|
+
* Default `'auto'`. Needs `getDefiningRelationships`.
|
|
44
|
+
*/
|
|
45
|
+
refinements?: 'auto' | 'always' | 'never';
|
|
46
|
+
/**
|
|
47
|
+
* The focus for refinement candidates, e.g. `^ 929360081000036101` for AMT
|
|
48
|
+
* MPUUs. Default: `<<` the most specific concept above every member.
|
|
49
|
+
*/
|
|
50
|
+
refinementFocus?: string;
|
|
51
|
+
/** Count members by top-level hierarchy. Default true. */
|
|
52
|
+
hierarchySummary?: boolean;
|
|
53
|
+
/** Timeout for each set query, in milliseconds. Default 60,000. */
|
|
54
|
+
queryTimeoutMs?: number;
|
|
55
|
+
/**
|
|
56
|
+
* When no refinement is exact, try `C MINUS D` for the best lossy refinements
|
|
57
|
+
* C, with D describing what C adds. Default true.
|
|
58
|
+
*/
|
|
59
|
+
subtractions?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Count a candidate's additions only inside this expression (used for the D
|
|
62
|
+
* in `C MINUS D`). Default: everywhere.
|
|
63
|
+
*/
|
|
64
|
+
within?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Add a REFACTOR-style greedy grouping candidate. Offered only on the graph
|
|
67
|
+
* path (see `useGraph`), including a partial graph. Default true.
|
|
68
|
+
*/
|
|
69
|
+
greedyGrouping?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Build hierarchy candidates from one fetched subgraph. Default true. Needs a
|
|
72
|
+
* server that returns parents in an expansion (`property=parent`); without
|
|
73
|
+
* them, or when `false`, each count is a query.
|
|
74
|
+
*/
|
|
75
|
+
useGraph?: boolean;
|
|
76
|
+
/** Most concepts in any fetched subgraph. Default 200,000. */
|
|
77
|
+
maxGraphConcepts?: number;
|
|
78
|
+
/**
|
|
79
|
+
* Add `critique`: structural checks on the list (see {@link CodelistCritique}).
|
|
80
|
+
* `true` uses the defaults of {@link CritiqueOptions}. Default false.
|
|
81
|
+
*/
|
|
82
|
+
critique?: boolean | CritiqueOptions;
|
|
83
|
+
}
|
|
84
|
+
/** Limits for {@link CodelistCritique}. */
|
|
85
|
+
export interface CritiqueOptions {
|
|
86
|
+
/** CHK16: the most clauses the best exact form may need before it is flagged. Default 35. */
|
|
87
|
+
maxClauses?: number;
|
|
88
|
+
/** CHK12: the share of `<< X` the list must hold for X to be a near miss. Default 0.9. */
|
|
89
|
+
nearMissShare?: number;
|
|
90
|
+
/** CHK12: the fewest concepts in `<< X` for X to be considered. Default 5. */
|
|
91
|
+
nearMissMinSize?: number;
|
|
92
|
+
/** CHK12: the most near misses reported. Default 5. */
|
|
93
|
+
maxNearMisses?: number;
|
|
94
|
+
/**
|
|
95
|
+
* CHK08: look for inactive concepts the members' history implies but the
|
|
96
|
+
* input leaves out, with this history profile (`true` means `'HISTORY-MOD'`).
|
|
97
|
+
* Needs a server that supports ECL history supplements. Default false.
|
|
98
|
+
*/
|
|
99
|
+
impliedInactive?: boolean | 'HISTORY-MIN' | 'HISTORY-MOD' | 'HISTORY-MAX';
|
|
100
|
+
}
|
|
101
|
+
/** A concept the list holds most, but not all, of `<< conceptId` of (CHK12). */
|
|
102
|
+
export interface NearMiss {
|
|
103
|
+
conceptId: string;
|
|
104
|
+
display?: string;
|
|
105
|
+
/** Concepts in `<< conceptId`. */
|
|
106
|
+
descendants: number;
|
|
107
|
+
/** Members in `<< conceptId`. */
|
|
108
|
+
listed: number;
|
|
109
|
+
/** `<< conceptId` concepts the list leaves out, counted on the server. */
|
|
110
|
+
missing: SetDifference;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Structural checks on the list, after the NHS ValueSet Management Tool's
|
|
114
|
+
* (CHK numbers are its checks). Advisory: each can be intended.
|
|
115
|
+
*/
|
|
116
|
+
export interface CodelistCritique {
|
|
117
|
+
/** CHK16: clauses the best exact candidate needs, against the limit. */
|
|
118
|
+
clauses: {
|
|
119
|
+
best: number;
|
|
120
|
+
limit: number;
|
|
121
|
+
exceeded: boolean;
|
|
122
|
+
};
|
|
123
|
+
/** CHK12: groupers the list nearly fills; empty when the IS-A subgraph was not loaded. */
|
|
124
|
+
nearMisses: NearMiss[];
|
|
125
|
+
/** CHK15: members by top-level hierarchy. */
|
|
126
|
+
hierarchies: DeriveResult['hierarchies'];
|
|
127
|
+
spansHierarchies: boolean;
|
|
128
|
+
/** CHK07: inactive ids in the input. */
|
|
129
|
+
inactive: string[];
|
|
130
|
+
/** CHK08: inactive concepts the history implies but the input leaves out (when asked for). */
|
|
131
|
+
impliedInactive?: SetDifference;
|
|
132
|
+
}
|
|
133
|
+
export type { SetDifference } from './set-queries';
|
|
134
|
+
/** How a candidate was built, so a caller can explain it. */
|
|
135
|
+
export type CandidateConstruction = {
|
|
136
|
+
kind: 'enumeration';
|
|
137
|
+
members: number;
|
|
138
|
+
} | {
|
|
139
|
+
kind: 'refset';
|
|
140
|
+
refsetId: string;
|
|
141
|
+
} | {
|
|
142
|
+
kind: 'expression';
|
|
143
|
+
} | {
|
|
144
|
+
kind: 'hierarchy';
|
|
145
|
+
/** Members with no ancestor in the set, each included as `<< root`. */
|
|
146
|
+
roots: string[];
|
|
147
|
+
/** Subtrees with no member, each excluded as `MINUS << x`. */
|
|
148
|
+
exclusions: string[];
|
|
149
|
+
/** Remaining non-members excluded one by one. */
|
|
150
|
+
literalExclusions: string[];
|
|
151
|
+
} | {
|
|
152
|
+
kind: 'refinement';
|
|
153
|
+
focus: string;
|
|
154
|
+
/** The clauses after `:`, all required. */
|
|
155
|
+
attributes: RefinementClause[];
|
|
156
|
+
} | {
|
|
157
|
+
kind: 'subtraction';
|
|
158
|
+
/** A lossy candidate and, subtracted from it, a description of what it adds. */
|
|
159
|
+
from: string;
|
|
160
|
+
minus: string;
|
|
161
|
+
} | {
|
|
162
|
+
kind: 'greedy-grouping';
|
|
163
|
+
/** Clauses ORed together; `=` is the concept alone. */
|
|
164
|
+
includes: HierarchyClause[];
|
|
165
|
+
/** Clauses subtracted with MINUS. */
|
|
166
|
+
exclusions: HierarchyClause[];
|
|
167
|
+
} | {
|
|
168
|
+
/** The cost-based exact cover: groupers chosen by members covered per clause, the rest listed. */
|
|
169
|
+
kind: 'cover';
|
|
170
|
+
/** Clauses ORed together; `=` is the concept alone. */
|
|
171
|
+
includes: HierarchyClause[];
|
|
172
|
+
/** Clauses subtracted with MINUS. */
|
|
173
|
+
exclusions: HierarchyClause[];
|
|
174
|
+
} | {
|
|
175
|
+
kind: 'ancestor-cover';
|
|
176
|
+
/** The clauses, in the order chosen: `<< member` or `< ancestor` (a non-member). */
|
|
177
|
+
foci: {
|
|
178
|
+
conceptId: string;
|
|
179
|
+
operator: '<' | '<<';
|
|
180
|
+
member: boolean;
|
|
181
|
+
}[];
|
|
182
|
+
};
|
|
183
|
+
export interface DeriveCandidate {
|
|
184
|
+
/** The candidate, formatted, with display terms unless `omitTerms`. */
|
|
185
|
+
expression: string;
|
|
186
|
+
/** The same expression on one line without terms, for evaluation and comparison. */
|
|
187
|
+
ecl: string;
|
|
188
|
+
/** Set members it selects. */
|
|
189
|
+
covered: number;
|
|
190
|
+
/** Non-members it selects. */
|
|
191
|
+
additions: SetDifference;
|
|
192
|
+
/** Set members it does not select. */
|
|
193
|
+
misses: SetDifference;
|
|
194
|
+
/** True when it selects exactly the set. */
|
|
195
|
+
exact: boolean;
|
|
196
|
+
/** Concept references in `ecl`: the length part of the ranking cost. */
|
|
197
|
+
clauses: number;
|
|
198
|
+
construction: CandidateConstruction;
|
|
199
|
+
}
|
|
200
|
+
export interface DeriveInputReport {
|
|
201
|
+
/** Distinct ids given (after trimming), or the refset id. */
|
|
202
|
+
given: number;
|
|
203
|
+
/** Active concepts the server knows: the set candidates are compared with. */
|
|
204
|
+
members: number;
|
|
205
|
+
/** Ids the server knows but that are inactive; left out of the set. */
|
|
206
|
+
inactive: string[];
|
|
207
|
+
/** Well-formed ids the server does not know; left out of the set. */
|
|
208
|
+
unknown: string[];
|
|
209
|
+
/** Strings that are not valid SNOMED CT concept ids; left out of the set. */
|
|
210
|
+
malformed: string[];
|
|
211
|
+
/** Ids given more than once. */
|
|
212
|
+
duplicates: number;
|
|
213
|
+
}
|
|
214
|
+
export interface DeriveResult {
|
|
215
|
+
input: DeriveInputReport;
|
|
216
|
+
/** Members by top-level hierarchy, largest first. */
|
|
217
|
+
hierarchies: {
|
|
218
|
+
conceptId: string;
|
|
219
|
+
display: string;
|
|
220
|
+
count: number;
|
|
221
|
+
}[];
|
|
222
|
+
/** Members with no ancestor in the set: how many `<< root` clauses an IS-A cover needs at least. */
|
|
223
|
+
roots: number;
|
|
224
|
+
/** Candidates, best first. */
|
|
225
|
+
candidates: DeriveCandidate[];
|
|
226
|
+
/** What was skipped or limited, and why. */
|
|
227
|
+
notes: string[];
|
|
228
|
+
/** Structural checks on the list, when the `critique` option asks for them. */
|
|
229
|
+
critique?: CodelistCritique;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Propose ECL expressions for a set of concepts, ranked, each with exact counts
|
|
233
|
+
* of what it adds to and misses from the set.
|
|
234
|
+
*
|
|
235
|
+
* @throws Error when `terminology` does not implement `expandCompose`.
|
|
236
|
+
* @throws `TerminologyTransportError` / `TerminologyHttpError` when the server fails.
|
|
237
|
+
*/
|
|
238
|
+
export declare function deriveEcl(input: DeriveInput, terminology: ITerminologyService, options?: DeriveOptions): Promise<DeriveResult>;
|
|
239
|
+
export declare function displayTerms(candidates: {
|
|
240
|
+
ecl: string;
|
|
241
|
+
clauses: number;
|
|
242
|
+
}[], terminology: ITerminologyService): Promise<Map<string, string>>;
|
|
243
|
+
/** Add display terms and format, unless the candidate is too long to be worth it. */
|
|
244
|
+
export declare function decorate(ecl: string, terms: Map<string, string>): string;
|
|
245
|
+
/**
|
|
246
|
+
* The concept ids in a pasted code list, in order: one per line, comma or tab
|
|
247
|
+
* separated, or `id |term|` / `id,term` rows. Any run of 6-18 digits counts, so
|
|
248
|
+
* a header row or terms are skipped; numbers inside terms are rare but possible,
|
|
249
|
+
* and `deriveEcl` reports any that are not concepts.
|
|
250
|
+
*/
|
|
251
|
+
export declare function parseConceptIdList(text: string): string[];
|
|
252
|
+
/**
|
|
253
|
+
* The derive input for pasted text: an OR list of bare concepts (one line or
|
|
254
|
+
* formatted) as its concepts, so inactive and unknown ids are reported; any
|
|
255
|
+
* other valid expression (operators, MINUS, refinements) as `{ ecl }`, so it is
|
|
256
|
+
* derived from what it selects; anything else, such as a code list one per
|
|
257
|
+
* line or as CSV, by {@link parseConceptIdList}.
|
|
258
|
+
*/
|
|
259
|
+
export declare function deriveInputFromText(text: string): DeriveInput;
|
|
260
|
+
/** A plain-text report of a {@link DeriveResult}, for an output channel or a chat message. */
|
|
261
|
+
export declare function formatDeriveReport(result: DeriveResult): string;
|
|
262
|
+
//# sourceMappingURL=derive-ecl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derive-ecl.d.ts","sourceRoot":"","sources":["../../src/derive/derive-ecl.ts"],"names":[],"mappings":"AAoDA,OAAO,KAAK,EAAe,mBAAmB,EAAmB,MAAM,sBAAsB,CAAC;AAE9F,OAAO,EASL,KAAK,aAAa,EACnB,MAAM,eAAe,CAAC;AAIvB,OAAO,EAAuC,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BAAmB,GAC/B,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAW9B;AAED,qFAAqF;AACrF,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAOxE;AAID;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAczD;AAeD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAW7D;AAuBD,8FAA8F;AAC9F,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAsC/D"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { HierarchyClause } from './hierarchy-clauses';
|
|
2
|
+
import { TaxonomyGraph } from './taxonomy-graph';
|
|
3
|
+
export interface GreedyGrouping {
|
|
4
|
+
ecl: string;
|
|
5
|
+
includes: HierarchyClause[];
|
|
6
|
+
exclusions: HierarchyClause[];
|
|
7
|
+
}
|
|
8
|
+
/** A greedy grouping of the members, counted in `graph` (loaded with {@link refactorDescend}). */
|
|
9
|
+
export declare function greedyGrouping(graph: TaxonomyGraph, maxClauses: number): GreedyGrouping;
|
|
10
|
+
/**
|
|
11
|
+
* The discard rules that need no descendant counts: which concepts of `>> list`
|
|
12
|
+
* are worth loading descendants for, so ALL is counted only for those.
|
|
13
|
+
*/
|
|
14
|
+
export declare function refactorDescend(id: string, graph: Pick<TaxonomyGraph, 'truePos' | 'children' | 'members'>): boolean;
|
|
15
|
+
//# sourceMappingURL=greedy-grouping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"greedy-grouping.d.ts","sourceRoot":"","sources":["../../src/derive/greedy-grouping.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAkC,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,UAAU,EAAE,eAAe,EAAE,CAAC;CAC/B;AAqBD,kGAAkG;AAClG,wBAAgB,cAAc,CAAC,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,GAAG,cAAc,CAYvF;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC,GAAG,OAAO,CAMnH"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { TaxonomyGraph } from './taxonomy-graph';
|
|
2
|
+
export interface HierarchyClause {
|
|
3
|
+
conceptId: string;
|
|
4
|
+
/** `=` is the concept alone, written without an operator. */
|
|
5
|
+
operator: '<<' | '<' | '=';
|
|
6
|
+
}
|
|
7
|
+
export interface ClauseForm {
|
|
8
|
+
includes: HierarchyClause[];
|
|
9
|
+
exclusions: HierarchyClause[];
|
|
10
|
+
}
|
|
11
|
+
/** The concepts a clause selects. Complete only when the graph has the clause's descendants. */
|
|
12
|
+
export declare function selection(c: HierarchyClause, g: TaxonomyGraph): string[];
|
|
13
|
+
/** What the form selects, or null when a clause needs descendants the graph did not load. */
|
|
14
|
+
export declare function evaluate(form: ClauseForm, g: TaxonomyGraph): Set<string> | null;
|
|
15
|
+
/** What the form adds to and misses of the members, and its clause count; null when it cannot be evaluated. */
|
|
16
|
+
export declare function localScore(form: ClauseForm, g: TaxonomyGraph): {
|
|
17
|
+
additions: number;
|
|
18
|
+
misses: number;
|
|
19
|
+
clauses: number;
|
|
20
|
+
} | null;
|
|
21
|
+
/**
|
|
22
|
+
* Drop clauses another clause already selects (`< x` with `= x` becomes
|
|
23
|
+
* `<< x`), then clauses everything they select is selected by the others,
|
|
24
|
+
* smallest first: `< y` is redundant when each of y's descendants falls under
|
|
25
|
+
* another clause, though y does not.
|
|
26
|
+
*/
|
|
27
|
+
export declare function prune(includes: HierarchyClause[], g: TaxonomyGraph): HierarchyClause[];
|
|
28
|
+
/**
|
|
29
|
+
* Exact exclusions for `includes`: what they select outside the set. A concept
|
|
30
|
+
* with no member at or below it is outside `>> list`; the highest of them go
|
|
31
|
+
* as `<< y`. A non-member above a member goes alone, as `= x`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function exactExclusions(includes: HierarchyClause[], g: TaxonomyGraph): HierarchyClause[];
|
|
34
|
+
export declare function render(form: ClauseForm): string;
|
|
35
|
+
//# sourceMappingURL=hierarchy-clauses.d.ts.map
|