-
Notifications
You must be signed in to change notification settings - Fork 0
/
SKOSHyperGraphExample.cs
60 lines (52 loc) · 2.02 KB
/
SKOSHyperGraphExample.cs
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
using System;
using System.Collections.Generic;
using Trinity;
using Trinity.Storage;
using RUB.TS.IG.GEAppServices.RPC.Protocols;
namespace SKOSHyperGraphExample
{
public class BFS
{
public static List<long> BreadthFirstSearch(long startConceptId, Func<SKOSConcept_Accessor, bool> goalPredicate)
{
HashSet<long> visited = new HashSet<long>();
Queue<long> queue = new Queue<long>();
List<long> path = new List<long>();
queue.Enqueue(startConceptId);
while (queue.Count > 0)
{
long currentId = queue.Dequeue();
visited.Add(currentId);
using (SKOSConcept_Accessor currentConcept = Global.LocalStorage.UseSKOSConcept(currentId))
{
if (currentConcept != null)
{
path.Add(currentId);
if (goalPredicate(currentConcept))
{
return path;
}
foreach (var hyperEdgeId in currentConcept.HyperEdges)
{
using (SKOSHyperEdge_Accessor hyperEdge = Global.LocalStorage.UseSKOSHyperEdge(hyperEdgeId))
{
if (hyperEdge != null)
{
foreach (var relatedConceptId in hyperEdge.RelatedConcepts)
{
if (!visited.Contains(relatedConceptId))
{
queue.Enqueue(relatedConceptId);
}
}
}
}
}
}
}
path.RemoveAt(path.Count - 1);
}
return null; // No path found
}
}
}