ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / KnowledgeGraphLayerIDSet Class / FromDictionary Method / FromDictionary(KnowledgeGraph,Dictionary<String,List<Object>>) Method
A knowledge graph datastore.
The collection of named types and their corresponding UIDs.
Example Version

FromDictionary(KnowledgeGraph,Dictionary<String,List<Object>>) Method
Creates a KnowledgeGraphLayerIDSet object from a dictionary of records. This method must be called on the MCT. Use QueuedTask.Run.
Syntax

Parameters

knowledgeGraph
A knowledge graph datastore.
dict
The collection of named types and their corresponding UIDs.

Return Value

Exceptions
ExceptionDescription
This method or property must be called within the lambda passed to QueuedTask.Run.
knowledgeGraph or dict is null.
Example
Create a KG Layer containing a subset of Entity and Relate types
QueuedTask.Run(() =>
{
  //To create a KG layer (on a map or link chart) with a subset of
  //entities and relates, you must create an "id set". The workflow
  //is very similar to how you would create a SelectionSet.

  //First, create a dictionary containing the names of the types to be
  //added plus a corresponding list of ids (just like with a selection set).
  //Note: null or an empty list means add all records for "that" type..
  var kg_datamodel = kg.GetDataModel();
  //Arbitrarily get the name of the first entity and relate type
  var first_entity = kg_datamodel.GetEntityTypes().Keys.First();
  var first_relate = kg_datamodel.GetRelationshipTypes().Keys.First();

  //Make entries in the dictionary for each
  var dict = new Dictionary<string, List<long>>();
  dict.Add(first_entity, new List<long>());//Empty list means all records
  dict.Add(first_relate, null);//null list means all records
  //or specific records - however the ids are obtained
  //dict.Add(entity_or_relate_name, new List<long>() { 1, 5, 18, 36, 78});

  //Create the id set...
  var idSet = KnowledgeGraphLayerIDSet.FromDictionary(kg, dict);

  //Create the layer params and assign the id set
  var kg_params = new KnowledgeGraphLayerCreationParams(kg)
  {
    Name = "KG_With_ID_Set",
    IsVisible = false,
    IDSet = idSet
  };

  //Call layer factory with map or group layer container
  //A KG layer containing just the feature layer(s) and/or standalone table(s)
  //for the entity and/or relate types + associated records will be created
  var kg_layer = LayerFactory.Instance.CreateLayer<KnowledgeGraphLayer>(
      kg_params, map);

});
Create a Link Chart from a query
//use the results of a query to create an idset. Create the link chart
//containing just records corresponding to the query results
var qry = @"MATCH (p1:PhoneNumber)-[r1:MADE_CALL|RECEIVED_CALL]->(c1:PhoneCall)<-" +
          @"[r2:MADE_CALL|RECEIVED_CALL]-(p2:PhoneNumber)-[r3:MADE_CALL|RECEIVED_CALL]" +
          @"->(c2:PhoneCall)<-[r4:MADE_CALL|RECEIVED_CALL]-(p3:PhoneNumber) " +
          @"WHERE p1.FULL_NAME = ""Robert Johnson"" AND " +
          @"p3.FULL_NAME= ""Dan Brown"" AND " +
          @"p1.globalid <> p2.globalid AND " +
          @"p2.globalid <> p3.globalid " +
          @"RETURN p1, r1, c1, r2, p2, r3, c2, r4, p3";

var dict = new Dictionary<string, List<long>>();

QueuedTask.Run(async () =>
{
  using (var kg = kg_layer.GetDatastore())
  {
    var graphQuery = new KnowledgeGraphQueryFilter()
    {
      QueryText = qry
    };

    using (var kgRowCursor = kg.SubmitQuery(graphQuery))
    {
      while (await kgRowCursor.WaitForRowsAsync())
      {
        while (kgRowCursor.MoveNext())
        {
          using (var graphRow = kgRowCursor.Current)
          {
            // process the row
            var cnt_val = (int)graphRow.GetCount();
            for (int v = 0; v < cnt_val; v++)
            {
              var obj_val = graphRow[v] as KnowledgeGraphNamedObjectValue;
              var type_name = obj_val.GetTypeName();
              var oid = (long)obj_val.GetObjectID();
              if (!dict.ContainsKey(type_name))
              {
                dict[type_name] = new List<long>();
              }
              if (!dict[type_name].Contains(oid))
                dict[type_name].Add(oid);
            }
          }
        }
      }
    }
    //make an ID Set to create the LinkChart
    var idSet = KnowledgeGraphLayerIDSet.FromDictionary(kg, dict);

    //Create the link chart and show it
    var linkChart = MapFactory.Instance.CreateLinkChart(
                      "KG With ID Set", kg, idSet);
    FrameworkApplication.Panes.CreateMapPaneAsync(linkChart);
  }
});
Requirements

Target Platforms: Windows 11, Windows 10

ArcGIS Pro version: 3.3 or higher.
See Also