ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Data.Knowledge Namespace / KnowledgeGraphDataModel Class / GetMetaEntityTypes Method
Example

In This Topic
    GetMetaEntityTypes Method
    In This Topic
    Gets a dictionary, with the keys being the names of the meta entity types in the data model, and the values being objects containing information about each meta entity type. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Example
    Get Data Model MetaEntityTypes/Provenance
    {
      //Provenance entity type is stored as a MetaEntityType 
      QueuedTask.Run(() =>
      {
        //Create a connection properties
        var kg_props =
            new KnowledgeGraphConnectionProperties(new Uri(url));
        using (var kg = new KnowledgeGraph(kg_props))
        {
          //Get the KnowledgeGraph Data Model
          using (var kg_dm = kg.GetDataModel())
          {
            var dict_types = kg_dm.GetMetaEntityTypes();
            //If there is no provenance then MetaEntityTypes will be
            //an empty collection
            foreach (var kvp in dict_types)
            {
              var meta_entity_type = kvp.Value;
              if (meta_entity_type.GetRole() ==
                  KnowledgeGraphNamedObjectTypeRole.Provenance)
              {
                //TODO - use the provenance entity type
                var name = meta_entity_type.GetName();
    
              }
            }
    
          }
        }
      });
    }
    Get Whether KG Supports Provenance
    string GetProvenanceEntityTypeName(KnowledgeGraphDataModel kg_dm)
    {
      var entity_types = kg_dm.GetMetaEntityTypes();
      foreach (var entity_type in entity_types)
      {
        if (entity_type.Value.GetRole() == KnowledgeGraphNamedObjectTypeRole.Provenance)
          return entity_type.Value.GetName();
      }
      return "";
    }
    bool KnowledgeGraphSupportsProvenance(KnowledgeGraph kg)
    {
      //if there is a provenance entity type then the KnowledgeGraph
      //supports provenance
      return !string.IsNullOrEmpty(
        GetProvenanceEntityTypeName(kg.GetDataModel()));
    
      // OR use the KnowledgeGraphPropertyInfo
      var propInfo = kg.GetPropertyNameInfo();
      return propInfo.SupportsProvenance;
    }
    Get Whether KG Has a Document Type
    string GetDocumentEntityTypeName(KnowledgeGraphDataModel kg_dm)
    {
      var entity_types = kg_dm.GetEntityTypes();
      foreach (var entity_type in entity_types)
      {
        var role = entity_type.Value.GetRole();
        if (role == KnowledgeGraphNamedObjectTypeRole.Document)
          return entity_type.Value.GetName();
      }
      return "";//Unusual - probably Neo4j user-managed
    }
    
    bool KnowledgeGraphHasDocumentType(KnowledgeGraph kg)
    {
      //uncommon for there not to be a document type
      return !string.IsNullOrEmpty(
        GetDocumentEntityTypeName(kg.GetDataModel()));
    
      // OR use the KnowledgeGraphPropertyInfo
      var propInfo = kg.GetPropertyNameInfo();
      return propInfo.SupportsDocuments;
    }
    Get All KnowledgeGraph Graph Types
    {
      await QueuedTask.Run(() =>
      {
        //Create a connection properties
        var kg_props =
            new KnowledgeGraphConnectionProperties(new Uri(url));
        using (var kg = new KnowledgeGraph(kg_props))
        {
          //Get the KnowledgeGraph Data Model
          using (var kg_datamodel = kg.GetDataModel())
          {
            var entities = kg_datamodel.GetEntityTypes();
            var relationships = kg_datamodel.GetRelationshipTypes();
            var provenance = kg_datamodel.GetMetaEntityTypes();
    
            var all_graph_types = new List<KnowledgeGraphNamedObjectType>();
            all_graph_types.AddRange(entities.Values);
            all_graph_types.AddRange(relationships.Values);
            all_graph_types.AddRange(provenance.Values);
    
            System.Diagnostics.Debug.WriteLine("\r\nGraph Types");
    
            int c = 0;
            foreach (var graph_type in all_graph_types)
            {
              var type_name = graph_type.GetName();
              var role = graph_type.GetRole().ToString();
    
              //equivalent to:
              //var fields = featClassDef.GetFields().Select(f => f.Name).ToList();
              //var field_names = string.Join(",", fields);
              var props = graph_type.GetProperties().Select(p => p.Name).ToList();
              var prop_names = string.Join(",", props);
    
              System.Diagnostics.Debug.WriteLine($"[{c++}]: " +
                  $"{type_name}, {role}, {prop_names}");
            }
          }
        }
      });
    }
    Requirements

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

    ArcGIS Pro version: 3.2 or higher.
    See Also