Exemplo n.º 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");
        }
Exemplo n.º 2
0
 // Build word -> labels index. It's crucial, because of big size of graph
 // we cannot compare each word with all labels in graph
 private void BuildWordIndex(int wordMinLen = 4)
 {
     foreach (var n in Graph.Nodes())
     {
         var label = LabelsMap[n];
         // avoid adding labels which are not related with any document in index
         if (label != null && IsAppropriateForIndex(label))
         {
             label = label.ToLower();
             var words = Regex.Split(label, @"\s");
             foreach (var w in words)
             {
                 if (w.Length >= wordMinLen)
                 {
                     if (!WordLabels.ContainsKey(w))
                     {
                         WordLabels.Add(w, new HashSet <string>());
                     }
                     WordLabels[w].Add(label);
                 }
             }
         }
     }
 }