handle missing edge types in graph data
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from pydantic import BaseModel
|
||||
from typing import List, Dict, Any
|
||||
from typing import List, Dict, Any, Optional
|
||||
|
||||
|
||||
class GPTKeywordExtractionFormat(BaseModel):
|
||||
@@ -15,7 +15,7 @@ class KnowledgeGraphNode(BaseModel):
|
||||
|
||||
class KnowledgeGraphEdge(BaseModel):
|
||||
id: str
|
||||
type: str
|
||||
type: Optional[str]
|
||||
source: str # id of source node
|
||||
target: str # id of target node
|
||||
properties: Dict[str, Any] # anything else goes here
|
||||
|
@@ -200,7 +200,7 @@ const EdgePropertiesView = ({ edge }: { edge: EdgeType }) => {
|
||||
<label className="text-md pl-1 font-bold tracking-wide text-teal-600">Relationship</label>
|
||||
<div className="bg-primary/5 max-h-96 overflow-auto rounded p-1">
|
||||
<PropertyRow name={'Id'} value={edge.id} />
|
||||
<PropertyRow name={'Type'} value={edge.type} />
|
||||
{edge.type && <PropertyRow name={'Type'} value={edge.type} />}
|
||||
<PropertyRow
|
||||
name={'Source'}
|
||||
value={edge.sourceNode ? edge.sourceNode.labels.join(', ') : edge.source}
|
||||
|
@@ -24,7 +24,7 @@ const validateGraph = (graph: RawGraph) => {
|
||||
}
|
||||
|
||||
for (const edge of graph.edges) {
|
||||
if (!edge.id || !edge.source || !edge.target || !edge.type || !edge.properties) {
|
||||
if (!edge.id || !edge.source || !edge.target) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -88,6 +88,14 @@ const fetchGraph = async (label: string) => {
|
||||
if (source !== undefined && source !== undefined) {
|
||||
const sourceNode = rawData.nodes[source]
|
||||
const targetNode = rawData.nodes[target]
|
||||
if (!sourceNode) {
|
||||
console.error(`Source node ${edge.source} is undefined`)
|
||||
continue
|
||||
}
|
||||
if (!targetNode) {
|
||||
console.error(`Target node ${edge.target} is undefined`)
|
||||
continue
|
||||
}
|
||||
sourceNode.degree += 1
|
||||
targetNode.degree += 1
|
||||
}
|
||||
@@ -146,7 +154,7 @@ const createSigmaGraph = (rawGraph: RawGraph | null) => {
|
||||
|
||||
for (const rawEdge of rawGraph?.edges ?? []) {
|
||||
rawEdge.dynamicId = graph.addDirectedEdge(rawEdge.source, rawEdge.target, {
|
||||
label: rawEdge.type
|
||||
label: rawEdge.type || undefined
|
||||
})
|
||||
}
|
||||
|
||||
|
@@ -19,7 +19,7 @@ export type RawEdgeType = {
|
||||
id: string
|
||||
source: string
|
||||
target: string
|
||||
type: string
|
||||
type?: string
|
||||
properties: Record<string, any>
|
||||
|
||||
dynamicId: string
|
||||
|
Reference in New Issue
Block a user