Example #1
0
        // Due to lack of such basic feature as giving list of neighbors,
        // this method builds two mappings:
        //   vertex label -> labels of broader vertices
        //   vertex label -> labels of narrower vertices
        private void BuildNeighborsMappings()
        {
            // contains entries: v label -> set of labels of broaders
            // Dictionary<string, HashSet<String>> brDict = new Dictionary<string, HashSet<String>>();
            // // contains entries: v label -> set of labels of narrowers
            // Dictionary<string, HashSet<String>> nrDict = new Dictionary<string, HashSet<String>>();

            foreach (var arc in Graph.Arcs())
            {
                string src = "";
                src = LabelsMap.TryGetValue(Graph.U(arc), out src) ? src : "";
                src = src.ToLower();
                string target = "";
                target = LabelsMap.TryGetValue(Graph.V(arc), out target) ? target : "";
                target = target.ToLower();
                string broader  = "";
                string narrower = "";
                string edgeType = "";
                EdgeTypeMap.TryGetValue(arc, out edgeType);
                if (edgeType == "broader")
                {
                    // src - broader -> tgt
                    narrower = src;
                    broader  = target;
                }
                else if (edgeType == "narrower")
                {
                    // src - narrower -> tgt    =>   tgt - broader -> src
                    broader  = src;
                    narrower = target;
                }
                else
                {
                    throw new Exception("Unknown relationship type found: '" + edgeType + "'");
                }
                if (IsAppropriateForIndex(broader) && IsAppropriateForIndex(narrower))
                {
                    if (narrower != null && narrower.Trim() != "")
                    {
                        if (!Broaders.ContainsKey(narrower))
                        {
                            Broaders.Add(narrower, new HashSet <string>());
                        }
                        Broaders[narrower].Add(broader);
                    }
                    if (broader != null && broader.Trim() != "")
                    {
                        if (!Narrowers.ContainsKey(broader))
                        {
                            Narrowers.Add(broader, new HashSet <string>());
                        }
                        Narrowers[broader].Add(narrower);
                    }
                }
            }
            Console.WriteLine("Loaded " + Broaders.Count + " broader relations");
            Console.WriteLine("Loaded " + Narrowers.Count + " narrower relations");
        }
Example #2
0
 public void PrintLabels()
 {
     foreach (var node in this.Graph.Nodes())
     {
         string label    = "";
         bool   hasLabel = (LabelsMap != null && LabelsMap.TryGetValue(node, out label));
         Console.WriteLine("Node " + node + ": label is " + (hasLabel ? label.ToString() : node.ToString()));
     }
 }