ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Data.Knowledge.Analytics Namespace / KnowledgeGraphCentralityResults Class / RawUids Property
Example

In This Topic
    RawUids Property
    In This Topic
    Gets an array of all uids for all entities in the centrality analysis.
    Syntax
    Public ReadOnly Property RawUids As Object()
    public object[] RawUids {get;}
    Remarks
    Uids are ordered in the array in the same order as their results in the KnowledgeGraphCentralityScores.RawScores array. Use RawUids and RawScores to do your own indexing of the result scores.
    Example
    Get Max and Min Centrality Result Scores No Sort or LINQ
    {
      //using ArcGIS.Core.Data.Knowledge.Extensions;
    
      await QueuedTask.Run(() =>
      {
        //using(var kg = ...) {
        //var kgResults = kg.ComputeCentrality(...);
        var count_entities = kgResults.RawUids.Count();
        var score_len = kgResults.Scores.RawScores.Length;
        //Find the max and min score for each measure w/out
        //using LINQ or sorting
        for (int m = 0; m < kgResults.Scores.Measures.Length; m++)
        {
          //index into the scores array for the current measure
          var start_idx = count_entities * m;
          var end_idx = start_idx + count_entities;
    
          double max_score = double.MinValue;
          double min_score = double.MaxValue;
          List<object> max_uids = new List<object>();
          List<object> min_uids = new List<object>();
    
          for (int i = 0, s = start_idx; s < end_idx; i++, s++)
          {
            var score = kgResults.Scores.RawScores[s];
            //max
            if (score > max_score)
            {
              max_score = score;
              max_uids.Clear();
              max_uids.Add(kgResults.RawUids[i]);
            }
            else if (score == max_score)
            {
              //Collect all uids with the max score
              max_uids.Add(kgResults.RawUids[i]);
            }
            //min
            if (score < min_score)
            {
              min_score = score;
              min_uids.Clear();
              min_uids.Add(kgResults.RawUids[i]);
            }
            else if (score == min_score)
            {
              //Collect all uids with the min score
              min_uids.Add(kgResults.RawUids[i]);
            }
          }
          //TODO - use the max and min scores and uids for
          //the current measure "measures[m]"
          //max_score, max_uids
          //min_score, min_uids
    
        }
      });
    }
    Get Max and Min Centrality Result Scores With Sort and Linq
    {
      //using ArcGIS.Core.Data.Knowledge.Extensions;
    
      await QueuedTask.Run(() =>
      {
        //using(var kg = ...) {
        //var kgResults = kg.ComputeCentrality(...);
    
        var count_entities = kgResults.RawUids.Count();
        var score_len = kgResults.Scores.RawScores.Length;
        //Find the max and min score for each measure using LINQ
        for (int m = 0; m < kgResults.Scores.Measures.Length; m++)
        {
          //index into the scores array for the current measure
          var start_idx = count_entities * m;
          var end_idx = start_idx + count_entities;
    
          //Get the scores for the specified measure
          var scores = Enumerable.Range(start_idx, count_entities)
            .Select(i => kgResults.Scores.RawScores[i]).ToArray();
    
          //max + min
          var max_score = scores.Max();
          var min_score = scores.Min();
    
          //uids with the max score
          var max_uids = Enumerable.Range(0, count_entities)
          .Where(i => scores[i] == max_score)
                           .Select(i => kgResults.RawUids[i])
                           .ToList();
    
          //uids with the min score
          var min_uids = Enumerable.Range(0, count_entities)
                           .Where(i => scores[i] == min_score)
                           .Select(i => kgResults.RawUids[i])
                           .ToList();
          //TODO - use the max and min scores and uids for
          //the current measure "measures[m]"
          //max_score, max_uids
          //min_score, min_uids
        }
      });
    }
    Get Top or Bottom N Centrality Result Scores
    {
      //using ArcGIS.Core.Data.Knowledge.Extensions;
    
      //Note: logic uses the following custom class:
      //
      //public class KG_Score_Value {
      //   public KG_Score_Value(double score, int uid_idx) {
      //      Score = score;
      //      Uid_idx = uid_idx;
      //   }
      //
      //   public double Score { get; set; }
      //   public int Uid_idx { get; set; }
      //}
    
      //var kgResults = kg.ComputeCentrality(...);
    
      var count_entities = kgResults.RawUids.Count();
      var score_len = kgResults.Scores.RawScores.Length;
      int n = 100;
    
      //Find the top and bottom "n" scores for each measure
      for (int m = 0; m < kgResults.Scores.Measures.Length; m++)
      {
        //index into the scores array for the current measure
        var start_idx = count_entities * m;
        var end_idx = start_idx + count_entities;
    
        //Get the scores for the specified measure
        var scores = Enumerable.Range(start_idx, count_entities)
          .Select(i => kgResults.Scores.RawScores[i]).ToArray();
    
        //use "KG_Score_Value" to hold the score and uid index
        var uid_idx = 0;
        var kg_score_vals = Enumerable.Range(start_idx, count_entities)
               .Select(i => new KG_Score_Value(kgResults.Scores.RawScores[i], uid_idx++))
               .OrderByDescending(k => k.Score)
               .ToArray();
    
        //get up to the top or bottom N scores
        if (n > kg_score_vals.Length)
          n = kg_score_vals.Length;
    
        //get the top N scores and uids - largest first
        var top_n = kg_score_vals.Take(n).ToList();
    
        //get the bottom N scores and uids - smallest first
        var bottom_n = kg_score_vals.TakeLast(n)
                          .Reverse().ToList();
    
        foreach (var kg_score in top_n)
        {
          //TODO - use top "n" scores
          var score = kg_score.Score;
          var uid1 = kgResults.RawUids[kg_score.Uid_idx];
          //...use it
        }
    
        foreach (var kg_score in bottom_n)
        {
          //TODO - use bottom "n" scores
          var score = kg_score.Score;
          var uid1 = kgResults.RawUids[kg_score.Uid_idx];
          //...use it
        }
      }
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.6 or higher.
    See Also