@memberjunction/core-entities 6.3.0-edge.1 → 6.3.0-edge.2
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/.tsbuildinfo +1 -1
- package/dist/custom/ArtifactPermissionDelegate.d.ts +27 -6
- package/dist/custom/ArtifactPermissionDelegate.d.ts.map +1 -1
- package/dist/custom/ArtifactPermissionDelegate.js +845 -298
- package/dist/custom/ArtifactPermissionDelegate.js.map +1 -1
- package/dist/custom/ConversationWriteAccess.d.ts +9 -0
- package/dist/custom/ConversationWriteAccess.d.ts.map +1 -1
- package/dist/custom/ConversationWriteAccess.js +56 -1
- package/dist/custom/ConversationWriteAccess.js.map +1 -1
- package/dist/custom/Permissions/BaseShareEntityExtended.d.ts +9 -0
- package/dist/custom/Permissions/BaseShareEntityExtended.d.ts.map +1 -1
- package/dist/custom/Permissions/BaseShareEntityExtended.js +11 -0
- package/dist/custom/Permissions/BaseShareEntityExtended.js.map +1 -1
- package/dist/custom/Permissions/MJArtifactPermissionEntityExtended.d.ts.map +1 -1
- package/dist/custom/Permissions/MJArtifactPermissionEntityExtended.js +15 -3
- package/dist/custom/Permissions/MJArtifactPermissionEntityExtended.js.map +1 -1
- package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.d.ts +1 -0
- package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.d.ts.map +1 -1
- package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.js +45 -13
- package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.js.map +1 -1
- package/dist/custom/Permissions/MJDashboardPermissionEntityExtended.d.ts +3 -1
- package/dist/custom/Permissions/MJDashboardPermissionEntityExtended.d.ts.map +1 -1
- package/dist/custom/Permissions/MJDashboardPermissionEntityExtended.js +83 -19
- package/dist/custom/Permissions/MJDashboardPermissionEntityExtended.js.map +1 -1
- package/dist/custom/Permissions/shareNotification.d.ts +14 -1
- package/dist/custom/Permissions/shareNotification.d.ts.map +1 -1
- package/dist/custom/Permissions/shareNotification.js +62 -8
- package/dist/custom/Permissions/shareNotification.js.map +1 -1
- package/dist/custom/ResourcePermissions/MJResourcePermissionEntityExtended.d.ts.map +1 -1
- package/dist/custom/ResourcePermissions/MJResourcePermissionEntityExtended.js +120 -38
- package/dist/custom/ResourcePermissions/MJResourcePermissionEntityExtended.js.map +1 -1
- package/dist/custom/SlideDeckEngine.d.ts +45 -3
- package/dist/custom/SlideDeckEngine.d.ts.map +1 -1
- package/dist/custom/SlideDeckEngine.js +509 -10
- package/dist/custom/SlideDeckEngine.js.map +1 -1
- package/dist/custom/SlideDeckPptxEngine.d.ts.map +1 -1
- package/dist/custom/SlideDeckPptxEngine.js +91 -17
- package/dist/custom/SlideDeckPptxEngine.js.map +1 -1
- package/dist/custom/SpreadsheetEngine.d.ts +7 -0
- package/dist/custom/SpreadsheetEngine.d.ts.map +1 -1
- package/dist/custom/SpreadsheetEngine.js +72 -0
- package/dist/custom/SpreadsheetEngine.js.map +1 -1
- package/dist/custom/approvals.d.ts +24 -0
- package/dist/custom/approvals.d.ts.map +1 -1
- package/dist/custom/approvals.js +34 -1
- package/dist/custom/approvals.js.map +1 -1
- package/dist/engines/CanonGraphEngine.d.ts +114 -1
- package/dist/engines/CanonGraphEngine.d.ts.map +1 -1
- package/dist/engines/CanonGraphEngine.js +240 -20
- package/dist/engines/CanonGraphEngine.js.map +1 -1
- package/dist/engines/conversations.d.ts +20 -4
- package/dist/engines/conversations.d.ts.map +1 -1
- package/dist/engines/conversations.js +61 -12
- package/dist/engines/conversations.js.map +1 -1
- package/dist/generated/entities/__mj.d.ts +6973 -399
- package/dist/generated/entities/__mj.d.ts.map +1 -1
- package/dist/generated/entities/__mj.js +35452 -27348
- package/dist/generated/entities/__mj.js.map +1 -1
- package/dist/generated/remote_operations.d.ts +745 -65
- package/dist/generated/remote_operations.d.ts.map +1 -1
- package/dist/generated/remote_operations.js +248 -8
- package/dist/generated/remote_operations.js.map +1 -1
- package/dist/generated/schemas/__mj.d.ts +2156 -230
- package/dist/generated/schemas/__mj.d.ts.map +1 -1
- package/dist/generated/schemas/__mj.js +3385 -26
- package/dist/generated/schemas/__mj.js.map +1 -1
- package/dist/graph/BaseGraphEdgeProvider.d.ts +33 -1
- package/dist/graph/BaseGraphEdgeProvider.d.ts.map +1 -1
- package/dist/graph/BaseGraphEdgeProvider.js +18 -3
- package/dist/graph/BaseGraphEdgeProvider.js.map +1 -1
- package/dist/graph/CanonDocumentRenderer.d.ts +43 -0
- package/dist/graph/CanonDocumentRenderer.d.ts.map +1 -0
- package/dist/graph/CanonDocumentRenderer.js +627 -0
- package/dist/graph/CanonDocumentRenderer.js.map +1 -0
- package/dist/graph/DomainClustering.d.ts +88 -0
- package/dist/graph/DomainClustering.d.ts.map +1 -0
- package/dist/graph/DomainClustering.js +327 -0
- package/dist/graph/DomainClustering.js.map +1 -0
- package/dist/graph/DomainProposalWriter.d.ts +25 -0
- package/dist/graph/DomainProposalWriter.d.ts.map +1 -0
- package/dist/graph/DomainProposalWriter.js +107 -0
- package/dist/graph/DomainProposalWriter.js.map +1 -0
- package/dist/graph/GraphAccessPolicy.d.ts +111 -0
- package/dist/graph/GraphAccessPolicy.d.ts.map +1 -0
- package/dist/graph/GraphAccessPolicy.js +123 -0
- package/dist/graph/GraphAccessPolicy.js.map +1 -0
- package/dist/graph/GraphEngine.d.ts +99 -10
- package/dist/graph/GraphEngine.d.ts.map +1 -1
- package/dist/graph/GraphEngine.js +359 -53
- package/dist/graph/GraphEngine.js.map +1 -1
- package/dist/graph/RecordRelations.d.ts +52 -0
- package/dist/graph/RecordRelations.d.ts.map +1 -0
- package/dist/graph/RecordRelations.js +90 -0
- package/dist/graph/RecordRelations.js.map +1 -0
- package/dist/graph/index.d.ts +9 -1
- package/dist/graph/index.d.ts.map +1 -1
- package/dist/graph/index.js +13 -1
- package/dist/graph/index.js.map +1 -1
- package/dist/graph/policies/ProvenanceAccessPolicies.d.ts +56 -0
- package/dist/graph/policies/ProvenanceAccessPolicies.d.ts.map +1 -0
- package/dist/graph/policies/ProvenanceAccessPolicies.js +228 -0
- package/dist/graph/policies/ProvenanceAccessPolicies.js.map +1 -0
- package/dist/graph/providers/QueryEdgeProvider.d.ts.map +1 -1
- package/dist/graph/providers/QueryEdgeProvider.js +2 -2
- package/dist/graph/providers/QueryEdgeProvider.js.map +1 -1
- package/dist/graph/providers/RecordLinkEdgeProvider.d.ts.map +1 -1
- package/dist/graph/providers/RecordLinkEdgeProvider.js +2 -2
- package/dist/graph/providers/RecordLinkEdgeProvider.js.map +1 -1
- package/dist/graph/providers/SharedConceptEdgeProvider.d.ts +54 -0
- package/dist/graph/providers/SharedConceptEdgeProvider.d.ts.map +1 -0
- package/dist/graph/providers/SharedConceptEdgeProvider.js +282 -0
- package/dist/graph/providers/SharedConceptEdgeProvider.js.map +1 -0
- package/package.json +6 -6
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { IMetadataProvider, UserInfo } from '@memberjunction/core';
|
|
1
2
|
import type { MJComponentEntity, MJDashboardEntity, MJQueryEntity, MJQueryParameterEntity, MJQuerySQLEntity, MJUserViewEntity } from '../generated/entity_subclasses.js';
|
|
2
3
|
/**
|
|
3
4
|
* Where a record's approval stands.
|
|
@@ -57,5 +58,28 @@ export declare function GetUserViewApprovalStateAsync(view: UserViewDefinitionFi
|
|
|
57
58
|
export declare function GetDashboardApprovalStateAsync(dashboard: DashboardDefinitionFields & Pick<MJDashboardEntity, 'ApprovalStatus' | 'ApprovedFingerprint'>): Promise<ApprovalState>;
|
|
58
59
|
/** Where a component version's approval stands. */
|
|
59
60
|
export declare function GetComponentApprovalStateAsync(component: ComponentDefinitionFields & Pick<MJComponentEntity, 'ApprovalStatus' | 'ApprovedFingerprint'>): Promise<ApprovalState>;
|
|
61
|
+
/**
|
|
62
|
+
* The authorization that lets a user approve a query. Any user with Create on `MJ: Queries` can
|
|
63
|
+
* save one, as a draft (`Pending`); approving it, which makes it MJ canon, needs this.
|
|
64
|
+
*/
|
|
65
|
+
export declare const APPROVE_QUERIES_AUTHORIZATION = "Queries: Approve";
|
|
66
|
+
/** Why the server refused a save that would approve a query. */
|
|
67
|
+
export declare const QUERY_APPROVAL_REFUSAL = "Approving a query needs the 'Queries: Approve' authorization. Save it as Pending, and someone who holds it can approve it.";
|
|
68
|
+
/**
|
|
69
|
+
* Why the server refused a save that sets a query's `CacheValidationSQL`. That SQL runs as written
|
|
70
|
+
* when a client checks its cache, outside the checks the query's own SQL goes through, so only a
|
|
71
|
+
* user who could approve the query may write it.
|
|
72
|
+
*/
|
|
73
|
+
export declare const QUERY_VALIDATION_SQL_REFUSAL = "Setting a query's cache validation SQL needs the 'Queries: Approve' authorization. Save it without one, and someone who holds it can add it.";
|
|
74
|
+
/**
|
|
75
|
+
* Whether this user may approve queries: they hold {@link APPROVE_QUERIES_AUTHORIZATION}, directly
|
|
76
|
+
* or through an ancestor authorization, or they are an `Owner`-type user (the platform's top
|
|
77
|
+
* authority, never locked out of this).
|
|
78
|
+
*
|
|
79
|
+
* False without a user or when the authorization is not defined, so a deployment that has not
|
|
80
|
+
* synced the authorization yet fails closed. The server enforces this on save; clients use it to
|
|
81
|
+
* decide whether to offer approving at all.
|
|
82
|
+
*/
|
|
83
|
+
export declare function UserCanApproveQueries(user: UserInfo | null | undefined, provider: Pick<IMetadataProvider, 'Authorizations'> | null | undefined): boolean;
|
|
60
84
|
export {};
|
|
61
85
|
//# sourceMappingURL=approvals.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approvals.d.ts","sourceRoot":"","sources":["../../src/custom/approvals.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"approvals.d.ts","sourceRoot":"","sources":["../../src/custom/approvals.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAExE,OAAO,KAAK,EACR,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,sBAAsB,EACtB,gB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E,gEAAgE;AAChE,eAAO,MAAM,sBAAsB,+HAC6G,CAAC;AAEjJ;;;;GAIG;AACH,eAAO,MAAM,4BAA4B,iJACyH,CAAC;AAEnK;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACjC,IAAI,EAAE,QAAQ,GAAG,IAAI,GAAG,SAAS,EACjC,QAAQ,EAAE,IAAI,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,GAAG,IAAI,GAAG,SAAS,GACvE,OAAO,CAQT"}
|
package/dist/custom/approvals.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* (a query's dialect variants and parameters) are sorted by a semantic key first, so the same
|
|
13
13
|
* rows read back in a different order give the same fingerprint.
|
|
14
14
|
*/
|
|
15
|
-
import { CONTEXT_TOKEN_CONTRACT_VERSION } from '@memberjunction/core';
|
|
15
|
+
import { AuthorizationEvaluator, CONTEXT_TOKEN_CONTRACT_VERSION } from '@memberjunction/core';
|
|
16
16
|
import { ComputeContentHashAsync, NormalizeUUID, OrdinalCompare, UUIDsEqual } from '@memberjunction/global';
|
|
17
17
|
import { QueryEngine } from '../engines/QueryEngine.js';
|
|
18
18
|
/** Where an approval stands, given its stored status and fingerprint and the current fingerprint. */
|
|
@@ -116,6 +116,39 @@ export async function GetDashboardApprovalStateAsync(dashboard) {
|
|
|
116
116
|
export async function GetComponentApprovalStateAsync(component) {
|
|
117
117
|
return ApprovalStateOf({ Status: component.ApprovalStatus, ApprovedFingerprint: component.ApprovedFingerprint }, await ComputeComponentFingerprintAsync(component));
|
|
118
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* The authorization that lets a user approve a query. Any user with Create on `MJ: Queries` can
|
|
121
|
+
* save one, as a draft (`Pending`); approving it, which makes it MJ canon, needs this.
|
|
122
|
+
*/
|
|
123
|
+
export const APPROVE_QUERIES_AUTHORIZATION = 'Queries: Approve';
|
|
124
|
+
/** Why the server refused a save that would approve a query. */
|
|
125
|
+
export const QUERY_APPROVAL_REFUSAL = `Approving a query needs the '${APPROVE_QUERIES_AUTHORIZATION}' authorization. Save it as Pending, and someone who holds it can approve it.`;
|
|
126
|
+
/**
|
|
127
|
+
* Why the server refused a save that sets a query's `CacheValidationSQL`. That SQL runs as written
|
|
128
|
+
* when a client checks its cache, outside the checks the query's own SQL goes through, so only a
|
|
129
|
+
* user who could approve the query may write it.
|
|
130
|
+
*/
|
|
131
|
+
export const QUERY_VALIDATION_SQL_REFUSAL = `Setting a query's cache validation SQL needs the '${APPROVE_QUERIES_AUTHORIZATION}' authorization. Save it without one, and someone who holds it can add it.`;
|
|
132
|
+
/**
|
|
133
|
+
* Whether this user may approve queries: they hold {@link APPROVE_QUERIES_AUTHORIZATION}, directly
|
|
134
|
+
* or through an ancestor authorization, or they are an `Owner`-type user (the platform's top
|
|
135
|
+
* authority, never locked out of this).
|
|
136
|
+
*
|
|
137
|
+
* False without a user or when the authorization is not defined, so a deployment that has not
|
|
138
|
+
* synced the authorization yet fails closed. The server enforces this on save; clients use it to
|
|
139
|
+
* decide whether to offer approving at all.
|
|
140
|
+
*/
|
|
141
|
+
export function UserCanApproveQueries(user, provider) {
|
|
142
|
+
if (!user)
|
|
143
|
+
return false;
|
|
144
|
+
if (user.Type?.trim().toLowerCase() === 'owner')
|
|
145
|
+
return true;
|
|
146
|
+
const authorizations = provider?.Authorizations ?? [];
|
|
147
|
+
const grant = authorizations.find((a) => a.Name?.trim().toLowerCase() === APPROVE_QUERIES_AUTHORIZATION.toLowerCase());
|
|
148
|
+
if (!grant)
|
|
149
|
+
return false;
|
|
150
|
+
return new AuthorizationEvaluator().UserCanExecuteWithAncestors(grant, user, authorizations);
|
|
151
|
+
}
|
|
119
152
|
/** Empty text means the same as no text. */
|
|
120
153
|
function text(value) {
|
|
121
154
|
return value ? value : null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approvals.js","sourceRoot":"","sources":["../../src/custom/approvals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO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,IAAI,CAAC,IAAI;QAAE,OAAO,KAAK,CAAC;IACxB,IAAI,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC;IAC7D,MAAM,cAAc,GAAG,QAAQ,EAAE,cAAc,IAAI,EAAE,CAAC;IACtD,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CACpC,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,6BAA6B,CAAC,WAAW,EAAE,CAAC,CAAC;IAClF,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IACzB,OAAO,IAAI,sBAAsB,EAAE,CAAC,2BAA2B,CAAC,KAAK,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;AACjG,CAAC;AAED,4CAA4C;AAC5C,SAAS,IAAI,CAAC,KAAgC;IAC1C,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AAChC,CAAC;AAED,iFAAiF;AACjF,SAAS,WAAW,CAAC,EAA6B;IAC9C,OAAO,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACzC,CAAC"}
|
|
@@ -1,7 +1,80 @@
|
|
|
1
1
|
import { IMetadataProvider, UserInfo } from '@memberjunction/core';
|
|
2
2
|
import { BaseSingleton, UUIDSet } from '@memberjunction/global';
|
|
3
|
-
import { type GraphEdgeView, type GraphNodeView, type GraphSubgraph, type GraphTraversalOptions } from '../graph/BaseGraphEdgeProvider.js';
|
|
3
|
+
import { type GraphEdgeView, type GraphNodeRef, type GraphNodeView, type GraphPath, type GraphSubgraph, type GraphTraversalOptions } from '../graph/BaseGraphEdgeProvider.js';
|
|
4
|
+
import { type CanonDocumentOptions } from '../graph/CanonDocumentRenderer.js';
|
|
5
|
+
import { type DomainProposal, type ProposeEntityDomainsOptions } from '../graph/DomainClustering.js';
|
|
4
6
|
import type { GraphExpansionParams, GraphExpansionResult, GraphSeedNode, IGraphExpansionService } from '../graph/GraphExpansion.js';
|
|
7
|
+
/** Score gap within which two non-exact concept matches count as tied (see {@link ClassifyConceptMatches}). */
|
|
8
|
+
export declare const CONCEPT_AMBIGUITY_MARGIN = 0.05;
|
|
9
|
+
/**
|
|
10
|
+
* How a concept matched the text:
|
|
11
|
+
* - `Exact`: the whole text is the concept's name or one of its synonyms.
|
|
12
|
+
* - `Mention`: the text contains the name or a synonym (a question that names the concept).
|
|
13
|
+
* - `Partial`: the text is a fragment of the name or a synonym ("AR" for "Open AR").
|
|
14
|
+
* - `Token`: only some words overlap.
|
|
15
|
+
*/
|
|
16
|
+
export type ConceptMatchKind = 'Exact' | 'Mention' | 'Partial' | 'Token';
|
|
17
|
+
/** One concept that matched the text, with how and how well. */
|
|
18
|
+
export interface ConceptMatch {
|
|
19
|
+
Node: GraphNodeView;
|
|
20
|
+
Score: number;
|
|
21
|
+
Kind: ConceptMatchKind;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The outcome of resolving text to concepts:
|
|
25
|
+
* - `Matched`: use `Matches` (best first). Several `Mention` matches mean the text names several
|
|
26
|
+
* concepts, which is not ambiguity.
|
|
27
|
+
* - `Ambiguous`: the text is a fragment or a shared name that fits `Candidates` about equally well;
|
|
28
|
+
* the caller should ask which one is meant, or pass the concept explicitly.
|
|
29
|
+
* - `NoMatch`: no concept the caller may see matched.
|
|
30
|
+
*/
|
|
31
|
+
export interface ConceptResolution {
|
|
32
|
+
Status: 'Matched' | 'Ambiguous' | 'NoMatch';
|
|
33
|
+
Matches: ConceptMatch[];
|
|
34
|
+
/** The tied best matches when `Status` is `Ambiguous`; empty otherwise. */
|
|
35
|
+
Candidates: ConceptMatch[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Classify visible concept matches (best first) into a {@link ConceptResolution}. Pure.
|
|
39
|
+
*
|
|
40
|
+
* Ambiguous when two or more concepts match the whole text exactly (a name or synonym shared by
|
|
41
|
+
* several concepts), or when the best match is only `Partial` or `Token` and another concept scores
|
|
42
|
+
* within {@link CONCEPT_AMBIGUITY_MARGIN} of it. A `Mention` is never ambiguous: a question that
|
|
43
|
+
* names two concepts is asking about both.
|
|
44
|
+
*/
|
|
45
|
+
export declare function ClassifyConceptMatches(matches: readonly ConceptMatch[]): ConceptResolution;
|
|
46
|
+
/**
|
|
47
|
+
* One end of a path request: a record (`EntityName` + `RecordID`), or a concept (`Concept` = its name,
|
|
48
|
+
* a synonym, or its ID). A record reference wins when both are given.
|
|
49
|
+
*/
|
|
50
|
+
export interface GraphEndpointInput {
|
|
51
|
+
EntityName?: string;
|
|
52
|
+
RecordID?: string;
|
|
53
|
+
Concept?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* How a {@link GraphEndpointInput} resolved. A record reference always resolves; whether the caller
|
|
57
|
+
* may see it is decided during traversal, so an unknown record and a hidden one look the same.
|
|
58
|
+
*/
|
|
59
|
+
export interface GraphEndpointResolution {
|
|
60
|
+
Status: 'Resolved' | 'Ambiguous' | 'NotFound';
|
|
61
|
+
Node?: GraphNodeRef;
|
|
62
|
+
/** The tied concepts when `Status` is `Ambiguous`; empty otherwise. */
|
|
63
|
+
Candidates: ConceptMatch[];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The outcome of {@link CanonGraphEngine.FindPathBetween}:
|
|
67
|
+
* - `Found` / `NoPath`: both endpoints resolved; `Path` is the search result.
|
|
68
|
+
* - `AmbiguousEndpoint` / `EndpointNotFound`: `Endpoint` says which side; `Candidates` lists the
|
|
69
|
+
* concepts an ambiguous one fits. No search ran.
|
|
70
|
+
* - `GraphNotFound`: the graph is unknown or not active.
|
|
71
|
+
*/
|
|
72
|
+
export interface GraphPathRequestResult {
|
|
73
|
+
Status: 'Found' | 'NoPath' | 'AmbiguousEndpoint' | 'EndpointNotFound' | 'GraphNotFound';
|
|
74
|
+
Path: GraphPath;
|
|
75
|
+
Endpoint?: 'From' | 'To';
|
|
76
|
+
Candidates: ConceptMatch[];
|
|
77
|
+
}
|
|
5
78
|
/**
|
|
6
79
|
* Structured Canon explanation for an `MJ: Entities` record (`Get Entity Details` canon section).
|
|
7
80
|
*/
|
|
@@ -54,8 +127,37 @@ export declare class CanonGraphEngine extends BaseSingleton<CanonGraphEngine> {
|
|
|
54
127
|
* `MJ: Graph Concepts` matching `text` by `Name` and `Synonyms` (v1 lexical matching), best match
|
|
55
128
|
* first, limited to concepts the caller — and every audience reader — may see, and to `Approved`
|
|
56
129
|
* concepts (plus `Proposed` ones when `options.IncludeProposed`; see `IsGraphConceptStatusVisible`).
|
|
130
|
+
* Use {@link ResolveConcepts} to also learn whether the text is ambiguous.
|
|
57
131
|
*/
|
|
58
132
|
FindConcepts(text: string, user: UserInfo, options?: FindConceptsOptions): Promise<GraphNodeView[]>;
|
|
133
|
+
/**
|
|
134
|
+
* {@link FindConcepts} with the score and kind of every match, classified by
|
|
135
|
+
* {@link ClassifyConceptMatches} into `Matched`, `Ambiguous` or `NoMatch`. Only concepts the
|
|
136
|
+
* caller and every audience reader may see are scored as candidates, so a hidden concept can
|
|
137
|
+
* never make visible ones look ambiguous.
|
|
138
|
+
*/
|
|
139
|
+
ResolveConcepts(text: string, user: UserInfo, options?: FindConceptsOptions): Promise<ConceptResolution>;
|
|
140
|
+
private scoreVisibleConcepts;
|
|
141
|
+
/**
|
|
142
|
+
* Resolve one end of a path request in `graphName`. A concept given by ID resolves directly; a
|
|
143
|
+
* concept given by name or synonym goes through {@link ResolveConcepts}, so text that fits several
|
|
144
|
+
* concepts comes back `Ambiguous` with the candidates rather than as a guess.
|
|
145
|
+
*/
|
|
146
|
+
ResolveGraphEndpoint(endpoint: GraphEndpointInput, graphName: string, user: UserInfo, options?: Omit<FindConceptsOptions, 'GraphNames'>): Promise<GraphEndpointResolution>;
|
|
147
|
+
/**
|
|
148
|
+
* Resolve both ends of a path request with {@link ResolveGraphEndpoint}, then run
|
|
149
|
+
* {@link GraphEngine.FindPath} between them. An ambiguous or unknown endpoint stops before the
|
|
150
|
+
* search and says which side it was, so a caller can ask instead of guessing.
|
|
151
|
+
*/
|
|
152
|
+
FindPathBetween(graphName: string, from: GraphEndpointInput, to: GraphEndpointInput, options: GraphTraversalOptions, user: UserInfo, provider?: IMetadataProvider): Promise<GraphPathRequestResult>;
|
|
153
|
+
/**
|
|
154
|
+
* Proposed `Domain` concepts for `graphName`, from deterministic community detection over the
|
|
155
|
+
* entity foreign-key and IS-A links (see {@link ProposeEntityDomains}). Only entities `user` may
|
|
156
|
+
* read take part, and a proposal whose name is already a concept in the graph (in any status,
|
|
157
|
+
* so a rejected or renamed one is not proposed again) is left out. Read-only: persisting the
|
|
158
|
+
* proposals is the caller's job.
|
|
159
|
+
*/
|
|
160
|
+
ProposeDomainConcepts(graphName: string, user: UserInfo, options?: ProposeEntityDomainsOptions, provider?: IMetadataProvider): Promise<DomainProposal[]>;
|
|
59
161
|
/**
|
|
60
162
|
* Resolve `MJ: Graph Concepts` matching `question` and expand their bounded Canon neighborhood.
|
|
61
163
|
*/
|
|
@@ -75,6 +177,17 @@ export declare class CanonGraphEngine extends BaseSingleton<CanonGraphEngine> {
|
|
|
75
177
|
* `includeProposed`) returns `null` as well: it is not canon.
|
|
76
178
|
*/
|
|
77
179
|
ExplainConcept(conceptNameOrId: string, user: UserInfo, provider?: IMetadataProvider, includeProposed?: boolean): Promise<CanonConceptExplanation | null>;
|
|
180
|
+
/**
|
|
181
|
+
* Collapse a governed Canon graph (or a question / pre-expanded subgraph slice of it) into a
|
|
182
|
+
* flat, deterministic Markdown domain-knowledge document suitable for DBAutoDoc, Skip Brain,
|
|
183
|
+
* QueryGen, and agent prompts.
|
|
184
|
+
*
|
|
185
|
+
* Every concept, edge, entity, alternate base view, and query is checked as `user` and every
|
|
186
|
+
* principal in `options.AudienceReaders` (row-level and field-level security apply). Artifact
|
|
187
|
+
* edges (`Defines`, `Measures`, `Describes`, `Implements`) follow the canonical
|
|
188
|
+
* artifact → concept direction.
|
|
189
|
+
*/
|
|
190
|
+
RenderCanonDocument(user: UserInfo, options?: CanonDocumentOptions): Promise<string>;
|
|
78
191
|
/**
|
|
79
192
|
* Delegate endpoint constraint check to {@link GraphEngine.ValidateEdgeEndpoint}.
|
|
80
193
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CanonGraphEngine.d.ts","sourceRoot":"","sources":["../../src/engines/CanonGraphEngine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAW,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAmB,OAAO,EAAc,MAAM,wBAAwB,CAAC;AAG7F,OAAO,EAEH,KAAK,aAAa,
|
|
1
|
+
{"version":3,"file":"CanonGraphEngine.d.ts","sourceRoot":"","sources":["../../src/engines/CanonGraphEngine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAW,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAmB,OAAO,EAAc,MAAM,wBAAwB,CAAC;AAG7F,OAAO,EAEH,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC7B,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAA+B,KAAK,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACxG,OAAO,EAAwB,KAAK,cAAc,EAAE,KAAK,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AACxH,OAAO,KAAK,EAGR,oBAAoB,EACpB,oBAAoB,EAEpB,aAAa,EACb,sBAAsB,EACzB,MAAM,yBAAyB,CAAC;AAOjC,+GAA+G;AAC/G,eAAO,MAAM,wBAAwB,OAAO,CAAC;AAI7C;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG,O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AI,EAAE,QAAQ,GAAG,QAAQ,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIrG;;;OAGG;IACI,kBAAkB,IAAI,sBAAsB;IAInD,wGAAwG;IACjG,4BAA4B,IAAI,MAAM;IAU7C,8FAA8F;IACvF,eAAe,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG,OAAO;IAqB1E;;;OAGG;IACH,OAAO,CAAC,aAAa;IAqBrB,OAAO,CAAC,0BAA0B;YAsCpB,iBAAiB;CAiBlC;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,0BAA2B,YAAW,sBAAsB;IAClD,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,gBAAgB;IAE9C,YAAY,CACrB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EACzC,WAAW,EAAE,QAAQ,EACrB,QAAQ,CAAC,EAAE,iBAAiB,EAC5B,eAAe,CAAC,EAAE,SAAS,QAAQ,EAAE,GACtC,OAAO,CAAC,SAAS,aAAa,EAAE,CAAC;IA4BvB,MAAM,CAAC,MAAM,EAAE,oBAAoB,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAoCrI,OAAO,CAAC,WAAW;IAmDnB,kGAAkG;IAClG,OAAO,CAAC,MAAM;IAsBd,uFAAuF;IACvF,OAAO,CAAC,eAAe;CAe1B"}
|
|
@@ -2,10 +2,41 @@ import { RunView } from '@memberjunction/core';
|
|
|
2
2
|
import { BaseSingleton, EscapeSQLString, UUIDSet, UUIDsEqual } from '@memberjunction/global';
|
|
3
3
|
import { IsGraphDataProvider, } from '../graph/BaseGraphEdgeProvider.js';
|
|
4
4
|
import { CanUserReadEntity, ClampGraphDepth, ClampGraphMaxNodes, GraphEngine, IsCanonGraph, IsFieldReadableByAll, IsGraphConceptStatusVisible } from '../graph/GraphEngine.js';
|
|
5
|
+
import { RenderCanonDocumentMarkdown } from '../graph/CanonDocumentRenderer.js';
|
|
6
|
+
import { ProposeEntityDomains } from '../graph/DomainClustering.js';
|
|
5
7
|
const CONCEPT_ENTITY = 'MJ: Graph Concepts';
|
|
6
8
|
const PRIMARY_CANON_GRAPH_NAME = 'MJ Canon';
|
|
7
9
|
/** Concept matches used as seeds for one question. */
|
|
8
10
|
const MAX_CONCEPT_SEEDS = 5;
|
|
11
|
+
/** Score gap within which two non-exact concept matches count as tied (see {@link ClassifyConceptMatches}). */
|
|
12
|
+
export const CONCEPT_AMBIGUITY_MARGIN = 0.05;
|
|
13
|
+
/** Most tied candidates an ambiguous resolution reports. */
|
|
14
|
+
const MAX_AMBIGUOUS_CANDIDATES = 5;
|
|
15
|
+
/**
|
|
16
|
+
* Classify visible concept matches (best first) into a {@link ConceptResolution}. Pure.
|
|
17
|
+
*
|
|
18
|
+
* Ambiguous when two or more concepts match the whole text exactly (a name or synonym shared by
|
|
19
|
+
* several concepts), or when the best match is only `Partial` or `Token` and another concept scores
|
|
20
|
+
* within {@link CONCEPT_AMBIGUITY_MARGIN} of it. A `Mention` is never ambiguous: a question that
|
|
21
|
+
* names two concepts is asking about both.
|
|
22
|
+
*/
|
|
23
|
+
export function ClassifyConceptMatches(matches) {
|
|
24
|
+
if (matches.length === 0) {
|
|
25
|
+
return { Status: 'NoMatch', Matches: [], Candidates: [] };
|
|
26
|
+
}
|
|
27
|
+
const top = matches[0];
|
|
28
|
+
let tied = [];
|
|
29
|
+
if (top.Kind === 'Exact') {
|
|
30
|
+
tied = matches.filter((m) => m.Kind === 'Exact' && m.Score === top.Score);
|
|
31
|
+
}
|
|
32
|
+
else if (top.Kind === 'Partial' || top.Kind === 'Token') {
|
|
33
|
+
tied = matches.filter((m) => m.Score >= top.Score - CONCEPT_AMBIGUITY_MARGIN);
|
|
34
|
+
}
|
|
35
|
+
if (tied.length >= 2) {
|
|
36
|
+
return { Status: 'Ambiguous', Matches: [...matches], Candidates: tied.slice(0, MAX_AMBIGUOUS_CANDIDATES) };
|
|
37
|
+
}
|
|
38
|
+
return { Status: 'Matched', Matches: [...matches], Candidates: [] };
|
|
39
|
+
}
|
|
9
40
|
/**
|
|
10
41
|
* Canon conveniences over {@link GraphEngine} (`GraphType.IsCanon`, `"MJ Canon"` first).
|
|
11
42
|
*
|
|
@@ -28,8 +59,23 @@ export class CanonGraphEngine extends BaseSingleton {
|
|
|
28
59
|
* `MJ: Graph Concepts` matching `text` by `Name` and `Synonyms` (v1 lexical matching), best match
|
|
29
60
|
* first, limited to concepts the caller — and every audience reader — may see, and to `Approved`
|
|
30
61
|
* concepts (plus `Proposed` ones when `options.IncludeProposed`; see `IsGraphConceptStatusVisible`).
|
|
62
|
+
* Use {@link ResolveConcepts} to also learn whether the text is ambiguous.
|
|
31
63
|
*/
|
|
32
64
|
async FindConcepts(text, user, options = {}) {
|
|
65
|
+
const resolution = await this.ResolveConcepts(text, user, options);
|
|
66
|
+
return resolution.Matches.map((m) => m.Node);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* {@link FindConcepts} with the score and kind of every match, classified by
|
|
70
|
+
* {@link ClassifyConceptMatches} into `Matched`, `Ambiguous` or `NoMatch`. Only concepts the
|
|
71
|
+
* caller and every audience reader may see are scored as candidates, so a hidden concept can
|
|
72
|
+
* never make visible ones look ambiguous.
|
|
73
|
+
*/
|
|
74
|
+
async ResolveConcepts(text, user, options = {}) {
|
|
75
|
+
const scored = await this.scoreVisibleConcepts(text, user, options);
|
|
76
|
+
return ClassifyConceptMatches(scored);
|
|
77
|
+
}
|
|
78
|
+
async scoreVisibleConcepts(text, user, options) {
|
|
33
79
|
const query = text?.trim().toLowerCase();
|
|
34
80
|
if (!query || !user) {
|
|
35
81
|
return [];
|
|
@@ -67,11 +113,99 @@ export class CanonGraphEngine extends BaseSingleton {
|
|
|
67
113
|
for (const s of scored) {
|
|
68
114
|
const view = visible.get(GraphEngine.Instance.GetNodeKey({ EntityName: CONCEPT_ENTITY, RecordID: s.Concept.ID }));
|
|
69
115
|
if (view) {
|
|
70
|
-
result.push(view);
|
|
116
|
+
result.push({ Node: view, Score: s.Score, Kind: s.Kind });
|
|
71
117
|
}
|
|
72
118
|
}
|
|
73
119
|
return result;
|
|
74
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Resolve one end of a path request in `graphName`. A concept given by ID resolves directly; a
|
|
123
|
+
* concept given by name or synonym goes through {@link ResolveConcepts}, so text that fits several
|
|
124
|
+
* concepts comes back `Ambiguous` with the candidates rather than as a guess.
|
|
125
|
+
*/
|
|
126
|
+
async ResolveGraphEndpoint(endpoint, graphName, user, options = {}) {
|
|
127
|
+
const entityName = endpoint.EntityName?.trim();
|
|
128
|
+
const recordId = endpoint.RecordID?.trim();
|
|
129
|
+
if (entityName && recordId) {
|
|
130
|
+
return { Status: 'Resolved', Node: { EntityName: entityName, RecordID: recordId }, Candidates: [] };
|
|
131
|
+
}
|
|
132
|
+
const concept = endpoint.Concept?.trim();
|
|
133
|
+
if (!concept) {
|
|
134
|
+
return { Status: 'NotFound', Candidates: [] };
|
|
135
|
+
}
|
|
136
|
+
const graph = GraphEngine.Instance.GetGraph(graphName);
|
|
137
|
+
const byId = graph ? GraphEngine.Instance.Concepts.find((c) => UUIDsEqual(c.ID, concept) && UUIDsEqual(c.GraphID, graph.ID)) : undefined;
|
|
138
|
+
if (byId) {
|
|
139
|
+
if (!IsGraphConceptStatusVisible(byId.Status, options.IncludeProposed === true)) {
|
|
140
|
+
return { Status: 'NotFound', Candidates: [] };
|
|
141
|
+
}
|
|
142
|
+
const ref = { EntityName: CONCEPT_ENTITY, RecordID: byId.ID };
|
|
143
|
+
const visible = await GraphEngine.Instance.FilterNodesForUser([ref], user, options.AudienceReaders, {
|
|
144
|
+
IncludeProposed: options.IncludeProposed === true,
|
|
145
|
+
Provider: options.provider,
|
|
146
|
+
});
|
|
147
|
+
const view = visible.get(GraphEngine.Instance.GetNodeKey(ref));
|
|
148
|
+
if (!view) {
|
|
149
|
+
return { Status: 'NotFound', Candidates: [] };
|
|
150
|
+
}
|
|
151
|
+
return { Status: 'Resolved', Node: { EntityName: view.EntityName, EntityID: view.EntityID, RecordID: view.RecordID }, Candidates: [] };
|
|
152
|
+
}
|
|
153
|
+
const resolution = await this.ResolveConcepts(concept, user, { ...options, GraphNames: [graphName] });
|
|
154
|
+
if (resolution.Status === 'Ambiguous') {
|
|
155
|
+
return { Status: 'Ambiguous', Candidates: resolution.Candidates };
|
|
156
|
+
}
|
|
157
|
+
const top = resolution.Matches[0];
|
|
158
|
+
if (!top) {
|
|
159
|
+
return { Status: 'NotFound', Candidates: [] };
|
|
160
|
+
}
|
|
161
|
+
return { Status: 'Resolved', Node: { EntityName: top.Node.EntityName, EntityID: top.Node.EntityID, RecordID: top.Node.RecordID }, Candidates: [] };
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Resolve both ends of a path request with {@link ResolveGraphEndpoint}, then run
|
|
165
|
+
* {@link GraphEngine.FindPath} between them. An ambiguous or unknown endpoint stops before the
|
|
166
|
+
* search and says which side it was, so a caller can ask instead of guessing.
|
|
167
|
+
*/
|
|
168
|
+
async FindPathBetween(graphName, from, to, options, user, provider) {
|
|
169
|
+
await this.EnsureConfigured(user, provider);
|
|
170
|
+
const graph = GraphEngine.Instance.GetGraph(graphName);
|
|
171
|
+
if (!graph) {
|
|
172
|
+
return { Status: 'GraphNotFound', Path: emptyPath(`Graph "${graphName}" was not found or is not active.`), Candidates: [] };
|
|
173
|
+
}
|
|
174
|
+
const endpointOptions = { IncludeProposed: options.IncludeProposed === true, AudienceReaders: options.AudienceReaders, provider };
|
|
175
|
+
const [start, end] = await Promise.all([
|
|
176
|
+
this.ResolveGraphEndpoint(from, graph.Name, user, endpointOptions),
|
|
177
|
+
this.ResolveGraphEndpoint(to, graph.Name, user, endpointOptions),
|
|
178
|
+
]);
|
|
179
|
+
for (const [side, resolution] of [['From', start], ['To', end]]) {
|
|
180
|
+
if (resolution.Status !== 'Resolved' || !resolution.Node) {
|
|
181
|
+
const status = resolution.Status === 'Ambiguous' ? 'AmbiguousEndpoint' : 'EndpointNotFound';
|
|
182
|
+
return { Status: status, Path: emptyPath(undefined), Endpoint: side, Candidates: resolution.Candidates };
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (!start.Node || !end.Node) {
|
|
186
|
+
return { Status: 'EndpointNotFound', Path: emptyPath(undefined), Candidates: [] };
|
|
187
|
+
}
|
|
188
|
+
const path = await GraphEngine.Instance.FindPath(graph.Name, start.Node, end.Node, options, user, provider);
|
|
189
|
+
return { Status: path.Found ? 'Found' : 'NoPath', Path: path, Candidates: [] };
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Proposed `Domain` concepts for `graphName`, from deterministic community detection over the
|
|
193
|
+
* entity foreign-key and IS-A links (see {@link ProposeEntityDomains}). Only entities `user` may
|
|
194
|
+
* read take part, and a proposal whose name is already a concept in the graph (in any status,
|
|
195
|
+
* so a rejected or renamed one is not proposed again) is left out. Read-only: persisting the
|
|
196
|
+
* proposals is the caller's job.
|
|
197
|
+
*/
|
|
198
|
+
async ProposeDomainConcepts(graphName, user, options = {}, provider) {
|
|
199
|
+
await this.EnsureConfigured(user, provider);
|
|
200
|
+
const graph = GraphEngine.Instance.GetGraph(graphName);
|
|
201
|
+
if (!graph) {
|
|
202
|
+
return [];
|
|
203
|
+
}
|
|
204
|
+
const md = provider ?? GraphEngine.Instance.ProviderToUse;
|
|
205
|
+
const readable = md.Entities.filter((e) => CanUserReadEntity(e, user));
|
|
206
|
+
const existing = new Set(GraphEngine.Instance.Concepts.filter((c) => UUIDsEqual(c.GraphID, graph.ID)).map((c) => c.Name.trim().toLowerCase()));
|
|
207
|
+
return ProposeEntityDomains(readable, options).filter((p) => !existing.has(p.Name.trim().toLowerCase()));
|
|
208
|
+
}
|
|
75
209
|
/**
|
|
76
210
|
* Resolve `MJ: Graph Concepts` matching `question` and expand their bounded Canon neighborhood.
|
|
77
211
|
*/
|
|
@@ -149,6 +283,45 @@ export class CanonGraphEngine extends BaseSingleton {
|
|
|
149
283
|
Subgraph: subgraph,
|
|
150
284
|
};
|
|
151
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* Collapse a governed Canon graph (or a question / pre-expanded subgraph slice of it) into a
|
|
288
|
+
* flat, deterministic Markdown domain-knowledge document suitable for DBAutoDoc, Skip Brain,
|
|
289
|
+
* QueryGen, and agent prompts.
|
|
290
|
+
*
|
|
291
|
+
* Every concept, edge, entity, alternate base view, and query is checked as `user` and every
|
|
292
|
+
* principal in `options.AudienceReaders` (row-level and field-level security apply). Artifact
|
|
293
|
+
* edges (`Defines`, `Measures`, `Describes`, `Implements`) follow the canonical
|
|
294
|
+
* artifact → concept direction.
|
|
295
|
+
*/
|
|
296
|
+
async RenderCanonDocument(user, options = {}) {
|
|
297
|
+
if (!user) {
|
|
298
|
+
return '';
|
|
299
|
+
}
|
|
300
|
+
await this.EnsureConfigured(user, options.Provider);
|
|
301
|
+
const graphName = options.GraphName?.trim() || this.ResolvePrimaryCanonGraphName();
|
|
302
|
+
return RenderCanonDocumentMarkdown(graphName, user, options, async (question, resolvedGraphName) => {
|
|
303
|
+
const matched = await this.FindConcepts(question, user, {
|
|
304
|
+
GraphNames: [resolvedGraphName],
|
|
305
|
+
AudienceReaders: options.AudienceReaders,
|
|
306
|
+
IncludeProposed: options.IncludeProposed,
|
|
307
|
+
provider: options.Provider,
|
|
308
|
+
});
|
|
309
|
+
if (matched.length === 0) {
|
|
310
|
+
return { Nodes: [], Edges: [] };
|
|
311
|
+
}
|
|
312
|
+
const seeds = matched.slice(0, MAX_CONCEPT_SEEDS).map((c) => ({
|
|
313
|
+
EntityName: c.EntityName,
|
|
314
|
+
EntityID: c.EntityID,
|
|
315
|
+
RecordID: c.RecordID,
|
|
316
|
+
}));
|
|
317
|
+
return GraphEngine.Instance.Subgraph(resolvedGraphName, seeds, {
|
|
318
|
+
Depth: 2,
|
|
319
|
+
MaxNodes: 50,
|
|
320
|
+
IncludeProposed: options.IncludeProposed,
|
|
321
|
+
AudienceReaders: options.AudienceReaders,
|
|
322
|
+
}, user, options.Provider);
|
|
323
|
+
});
|
|
324
|
+
}
|
|
152
325
|
/**
|
|
153
326
|
* Delegate endpoint constraint check to {@link GraphEngine.ValidateEdgeEndpoint}.
|
|
154
327
|
*/
|
|
@@ -199,14 +372,15 @@ export class CanonGraphEngine extends BaseSingleton {
|
|
|
199
372
|
*/
|
|
200
373
|
scoreConcepts(query, graphIds, includeProposed, matchable) {
|
|
201
374
|
const queryTokens = tokenizeAlphanumeric(query);
|
|
375
|
+
const queryWords = tokenizeAlphanumeric(query, 1);
|
|
202
376
|
const scored = [];
|
|
203
377
|
for (const concept of GraphEngine.Instance.Concepts) {
|
|
204
378
|
if (!IsGraphConceptStatusVisible(concept.Status, includeProposed) || !graphIds.Has(concept.GraphID)) {
|
|
205
379
|
continue;
|
|
206
380
|
}
|
|
207
|
-
const
|
|
208
|
-
if (
|
|
209
|
-
scored.push({ Concept: concept, Score:
|
|
381
|
+
const match = scoreConceptMatch(concept, query, queryWords, queryTokens, matchable);
|
|
382
|
+
if (match.Score > 0) {
|
|
383
|
+
scored.push({ Concept: concept, Score: match.Score, Kind: match.Kind });
|
|
210
384
|
}
|
|
211
385
|
}
|
|
212
386
|
return scored.sort((a, b) => b.Score - a.Score || a.Concept.Name.localeCompare(b.Concept.Name) || compareText(a.Concept.ID, b.Concept.ID));
|
|
@@ -433,33 +607,79 @@ function classifyNodeKind(entityName) {
|
|
|
433
607
|
}
|
|
434
608
|
return 'Record';
|
|
435
609
|
}
|
|
436
|
-
function
|
|
610
|
+
function emptyPath(message) {
|
|
611
|
+
return { Found: false, Nodes: [], Edges: [], PathWeight: 0, Message: message };
|
|
612
|
+
}
|
|
613
|
+
function scoreConceptMatch(concept, queryLower, queryWords, queryTokens, matchable) {
|
|
437
614
|
const nameLower = matchable.Name ? concept.Name.trim().toLowerCase() : '';
|
|
438
615
|
if (nameLower && nameLower === queryLower) {
|
|
439
|
-
return 1.0;
|
|
440
|
-
}
|
|
441
|
-
if (nameLower && (queryLower.includes(nameLower) || nameLower.startsWith(queryLower))) {
|
|
442
|
-
return 0.9;
|
|
616
|
+
return { Score: 1.0, Kind: 'Exact' };
|
|
443
617
|
}
|
|
444
618
|
const synonyms = matchable.Synonyms ? parseSynonyms(concept.Synonyms).map((s) => s.toLowerCase()) : [];
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
619
|
+
if (synonyms.some((syn) => syn === queryLower)) {
|
|
620
|
+
return { Score: 0.95, Kind: 'Exact' };
|
|
621
|
+
}
|
|
622
|
+
const nameWords = nameLower ? tokenizeAlphanumeric(nameLower, 1) : [];
|
|
623
|
+
if (nameWords.length > 0 && containsTokenSequence(queryWords, nameWords)) {
|
|
624
|
+
return { Score: 0.9, Kind: 'Mention' };
|
|
625
|
+
}
|
|
626
|
+
if (queryLower.length >= 2 && nameWords.length > 0 && isPrefixFragmentOf(nameWords, queryWords)) {
|
|
627
|
+
return { Score: 0.9, Kind: 'Partial' };
|
|
628
|
+
}
|
|
629
|
+
const synonymWords = synonyms.map((s) => tokenizeAlphanumeric(s, 1));
|
|
630
|
+
if (synonymWords.some((words) => containsTokenSequence(queryWords, words))) {
|
|
631
|
+
return { Score: 0.85, Kind: 'Mention' };
|
|
632
|
+
}
|
|
633
|
+
if (queryLower.length >= 2 && synonymWords.some((words) => isPrefixFragmentOf(words, queryWords))) {
|
|
634
|
+
return { Score: 0.85, Kind: 'Partial' };
|
|
452
635
|
}
|
|
453
636
|
if (queryTokens.length > 0) {
|
|
454
637
|
const candidateTokens = new Set(tokenizeAlphanumeric([nameLower, ...synonyms].join(' ')));
|
|
455
638
|
const hits = queryTokens.filter((t) => candidateTokens.has(t)).length;
|
|
456
639
|
if (hits > 0) {
|
|
457
|
-
return 0.5 * (hits / queryTokens.length);
|
|
640
|
+
return { Score: 0.5 * (hits / queryTokens.length), Kind: 'Token' };
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
return { Score: 0, Kind: 'Token' };
|
|
644
|
+
}
|
|
645
|
+
function containsTokenSequence(haystack, needle) {
|
|
646
|
+
if (needle.length === 0 || needle.length > haystack.length) {
|
|
647
|
+
return false;
|
|
648
|
+
}
|
|
649
|
+
for (let i = 0; i <= haystack.length - needle.length; i++) {
|
|
650
|
+
let allMatch = true;
|
|
651
|
+
for (let k = 0; k < needle.length; k++) {
|
|
652
|
+
if (haystack[i + k] !== needle[k]) {
|
|
653
|
+
allMatch = false;
|
|
654
|
+
break;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
if (allMatch) {
|
|
658
|
+
return true;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
return false;
|
|
662
|
+
}
|
|
663
|
+
function isPrefixFragmentOf(candidate, query) {
|
|
664
|
+
if (query.length === 0 || query.length > candidate.length) {
|
|
665
|
+
return false;
|
|
666
|
+
}
|
|
667
|
+
const lastIdx = query.length - 1;
|
|
668
|
+
for (let i = 0; i <= candidate.length - query.length; i++) {
|
|
669
|
+
let prefixMatch = true;
|
|
670
|
+
for (let k = 0; k < lastIdx; k++) {
|
|
671
|
+
if (candidate[i + k] !== query[k]) {
|
|
672
|
+
prefixMatch = false;
|
|
673
|
+
break;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
if (prefixMatch && candidate[i + lastIdx].startsWith(query[lastIdx])) {
|
|
677
|
+
return true;
|
|
458
678
|
}
|
|
459
679
|
}
|
|
460
|
-
return
|
|
680
|
+
return false;
|
|
461
681
|
}
|
|
462
|
-
function tokenizeAlphanumeric(input) {
|
|
682
|
+
function tokenizeAlphanumeric(input, minLength = 2) {
|
|
463
683
|
const tokens = [];
|
|
464
684
|
let start = -1;
|
|
465
685
|
for (let i = 0; i <= input.length; i++) {
|
|
@@ -471,7 +691,7 @@ function tokenizeAlphanumeric(input) {
|
|
|
471
691
|
}
|
|
472
692
|
}
|
|
473
693
|
else if (start !== -1) {
|
|
474
|
-
if (i - start >=
|
|
694
|
+
if (i - start >= minLength) {
|
|
475
695
|
tokens.push(input.slice(start, i));
|
|
476
696
|
}
|
|
477
697
|
start = -1;
|