deleteRelations removes specific relations from the graph.
(relations []Relation)
| 327 | |
| 328 | // deleteRelations removes specific relations from the graph. |
| 329 | func (k knowledgeBase) deleteRelations(relations []Relation) error { |
| 330 | graph, err := k.loadGraph() |
| 331 | if err != nil { |
| 332 | return err |
| 333 | } |
| 334 | |
| 335 | // Filter relations using slices.DeleteFunc and slices.ContainsFunc |
| 336 | graph.Relations = slices.DeleteFunc(graph.Relations, func(existingRelation Relation) bool { |
| 337 | return slices.ContainsFunc(relations, func(relationToDelete Relation) bool { |
| 338 | return existingRelation.From == relationToDelete.From && |
| 339 | existingRelation.To == relationToDelete.To && |
| 340 | existingRelation.RelationType == relationToDelete.RelationType |
| 341 | }) |
| 342 | }) |
| 343 | return k.saveGraph(graph) |
| 344 | } |
| 345 | |
| 346 | // searchNodes filters entities and relations matching the query string. |
| 347 | func (k knowledgeBase) searchNodes(query string) (KnowledgeGraph, error) { |