Skip to content

Commit d115c89

Browse files
node id check (#663)
1 parent 97f6e38 commit d115c89

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

frontend/src/utils/Utils.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,25 +170,36 @@ export const filterData = (
170170
allNodes: ExtendedNode[],
171171
allRelationships: Relationship[],
172172
scheme: Scheme
173-
) => {
173+
) => {
174174
let filteredNodes: ExtendedNode[] = [];
175175
let filteredRelations: Relationship[] = [];
176176
let filteredScheme: Scheme = {};
177177
const entityTypes = Object.keys(scheme).filter((type) => type !== 'Document' && type !== 'Chunk');
178-
179178
if (graphType.includes('DocumentChunk') && !graphType.includes('Entities')) {
180179
// Document + Chunk
181-
filteredNodes = allNodes.filter((node) => node.labels.includes('Document') || node.labels.includes('Chunk'));
182-
filteredRelations = allRelationships.filter((rel) =>
183-
['PART_OF', 'FIRST_CHUNK', 'SIMILAR', 'NEXT_CHUNK'].includes(rel.caption ?? '')
180+
filteredNodes = allNodes.filter(
181+
(node) => node.labels.includes('Document') || node.labels.includes('Chunk')
182+
);
183+
const nodeIds = new Set(filteredNodes.map((node) => node.id));
184+
filteredRelations = allRelationships.filter(
185+
(rel) =>
186+
['PART_OF', 'FIRST_CHUNK', 'SIMILAR', 'NEXT_CHUNK'].includes(rel.caption ?? '') &&
187+
nodeIds.has(rel.from) &&
188+
nodeIds.has(rel.to)
184189
);
185190
filteredScheme = { Document: scheme.Document, Chunk: scheme.Chunk };
186191
} else if (graphType.includes('Entities') && !graphType.includes('DocumentChunk')) {
187192
// Only Entity
188-
const entityNode = allNodes.filter((node) => !node.labels.includes('Document') && !node.labels.includes('Chunk'));
189-
filteredNodes = entityNode ? entityNode : [];
193+
const entityNodes = allNodes.filter(
194+
(node) => !node.labels.includes('Document') && !node.labels.includes('Chunk')
195+
);
196+
filteredNodes = entityNodes ? entityNodes : [];
197+
const nodeIds = new Set(filteredNodes.map((node) => node.id));
190198
filteredRelations = allRelationships.filter(
191-
(rel) => !['PART_OF', 'FIRST_CHUNK', 'HAS_ENTITY', 'SIMILAR', 'NEXT_CHUNK'].includes(rel?.caption ?? '')
199+
(rel) =>
200+
!['PART_OF', 'FIRST_CHUNK', 'HAS_ENTITY', 'SIMILAR', 'NEXT_CHUNK'].includes(rel.caption ?? '') &&
201+
nodeIds.has(rel.from) &&
202+
nodeIds.has(rel.to)
192203
);
193204
filteredScheme = Object.fromEntries(entityTypes.map((key) => [key, scheme[key]])) as Scheme;
194205
} else if (graphType.includes('DocumentChunk') && graphType.includes('Entities')) {
@@ -198,7 +209,7 @@ export const filterData = (
198209
filteredScheme = scheme;
199210
}
200211
return { filteredNodes, filteredRelations, filteredScheme };
201-
};
212+
};
202213

203214
export const getDateTime = () => {
204215
const date = new Date();

0 commit comments

Comments
 (0)