forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKnowledgeGraphRecord.swift
More file actions
71 lines (61 loc) · 1.74 KB
/
Copy pathKnowledgeGraphRecord.swift
File metadata and controls
71 lines (61 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import Foundation
@preconcurrency import GRDB
// MARK: - Local Knowledge Graph Node Record
struct LocalKGNodeRecord: Codable, FetchableRecord, PersistableRecord, Identifiable {
var id: Int64?
var nodeId: String
var label: String
var nodeType: String
var aliasesJson: String?
var sourceFileIds: String?
var createdAt: Date
var updatedAt: Date
static let databaseTableName = "local_kg_nodes"
mutating func didInsert(_ inserted: InsertionSuccess) {
id = inserted.rowID
}
/// Convert to API-compatible KnowledgeGraphNode
func toKnowledgeGraphNode() -> KnowledgeGraphNode {
let aliases: [String]
if let json = aliasesJson, let data = json.data(using: .utf8),
let parsed = try? JSONDecoder().decode([String].self, from: data)
{
aliases = parsed
} else {
aliases = []
}
return KnowledgeGraphNode(
id: nodeId,
label: label,
nodeType: KnowledgeGraphNodeType(rawValue: nodeType) ?? .concept,
aliases: aliases,
memoryIds: [],
createdAt: createdAt,
updatedAt: updatedAt
)
}
}
// MARK: - Local Knowledge Graph Edge Record
struct LocalKGEdgeRecord: Codable, FetchableRecord, PersistableRecord, Identifiable {
var id: Int64?
var edgeId: String
var sourceNodeId: String
var targetNodeId: String
var label: String
var createdAt: Date
static let databaseTableName = "local_kg_edges"
mutating func didInsert(_ inserted: InsertionSuccess) {
id = inserted.rowID
}
/// Convert to API-compatible KnowledgeGraphEdge
func toKnowledgeGraphEdge() -> KnowledgeGraphEdge {
KnowledgeGraphEdge(
id: edgeId,
sourceId: sourceNodeId,
targetId: targetNodeId,
label: label,
memoryIds: [],
createdAt: createdAt
)
}
}