ArcGIS Pro 3.6 API Reference Guide
ArcGIS.Core.CIM Namespace / CIMKnowledgeGraphNamedTypeFilter Class / FilterType Property
Example

In This Topic
    FilterType Property (CIMKnowledgeGraphNamedTypeFilter)
    In This Topic
    Gets or sets the filter type, i.e whether to include or exclude the instances represented by the filter.
    Syntax
    public KGFilterType FilterType {get; set;}
    Public Property FilterType As KGFilterType
    Example
    Configure Centrality Entity SubGraph Filters
          //using ArcGIS.Core.Data.Knowledge.Extensions;
    
          await QueuedTask.Run(() =>
    {
    
              //Assume KG contains Entity NamedTypes "A","B","C", and "D"
              //
              //We can use either of a CIMKnowledgeGraphNamedTypeFilterByInstances
              //or CIMKnowledgeGraphNamedTypeFilterByType to filter instances for
              //_including_ in or _excluding_ from entities and relates wrt the subgraph.
              //
              //Use CIMKnowledgeGraphNamedTypeFilterByInstances to filter by instance id
              //Use CIMKnowledgeGraphNamedTypeFilterByType to filter by type name and with
              //an optional property filter predicate to filter by property value(s)
    
              //Example 1.
              //Include all entities (and relates) from the kg in the subgraph
              //Leave kg_subgraph.EntityFilters null.
              //(kg_subgraph.RelationshipFilters is also null)
    
              //The collection of Entity and Relate filters are both empty
      //Everything is included
              var kg_subgraph = new CIMKnowledgeGraphSubGraph();
    
              //Example 2
              //Include a set of Entities from A (all of B, C, D will be implicitly excluded)
              var kg_filter2 = new CIMKnowledgeGraphNamedTypeFilterByInstances()
      {
        FilterType = KGFilterType.Include,
        NamedType = "A",
                  InstancesIDs = list_of_ids.ToArray() //list_of_ids contains desired uids for "A"
                                                                                           //note: -if list_of_ids is empty then -no-
                                             //instances of A will be included.
              };
    
              var entity_filters2 = new List<CIMKnowledgeGraphNamedTypeFilter>();
      entity_filters2.Add(kg_filter2);
    
      //note: All relates are included as no RelationshipFilters are specified
      //var kg_subgraph = ...
      kg_subgraph.EntityFilters = entity_filters2.ToArray();
    
      //Example 3
      //Exclude a set of Entities from A (all of B, C, D will be implicitly included)
      var kg_filter3 = new CIMKnowledgeGraphNamedTypeFilterByInstances()
      {
                  FilterType = KGFilterType.Exclude,
                  NamedType = "A",
                  InstancesIDs = list_of_ids.ToArray() //list_of_ids contains desired uids for "A"
                                                                                           //note: -if list_of_ids is empty then -no-
                                                                                           //instances of A will be excluded.
              };
    
      var entity_filters3 = new List<CIMKnowledgeGraphNamedTypeFilter>();
      entity_filters3.Add(kg_filter3);
    
      //note: All relates are included as no RelationshipFilters are specified
      //var kg_subgraph = ...
      kg_subgraph.EntityFilters = entity_filters3.ToArray();
    
      //Example 4
      //Include all Entities from A via named type (all of B, C, D
      //will be implicitly excluded)
    
      var kg_filter4 = new CIMKnowledgeGraphNamedTypeFilterByType()
      {
                  FilterType = KGFilterType.Include,
        NamedType = "A" //all of A will be included
                        //predicate is empty
      };
    
      var entity_filters4 = new List<CIMKnowledgeGraphNamedTypeFilter>();
      entity_filters4.Add(kg_filter4);
    
      //note: All relates are included as no RelationshipFilters are specified
      //var kg_subgraph = ...
      kg_subgraph.EntityFilters = entity_filters4.ToArray();
    
              //Example 5
              //Exclude all Entities from A via named type (all of B, C, D
              //will be implicitly included)
    
              var kg_filter5 = new CIMKnowledgeGraphNamedTypeFilterByType()
              {
                  FilterType = KGFilterType.Exclude,
                  NamedType = "A" //all of A will be excluded
                        //predicate is empty
              };
    
              var entity_filters5 = new List<CIMKnowledgeGraphNamedTypeFilter>();
      entity_filters5.Add(kg_filter5);
    
      //note: All relates are included as no RelationshipFilters are specified
      //var kg_subgraph = ...
      kg_subgraph.EntityFilters = entity_filters5.ToArray();
    
      //Example 6
      //Include all entities from B and C and
      //a subset from D via a set of ids (A is implicitly excluded)
      var kg_filter6_b = new CIMKnowledgeGraphNamedTypeFilterByType();
      var kg_filter6_c = new CIMKnowledgeGraphNamedTypeFilterByType();
      
      kg_filter6_b.NamedType = "B";//Include is default, predicate is empty
              kg_filter6_c.NamedType = "C";//Include is default, predicate is empty
    
              //TODO... populate list with uids from "D"...
              var kg_filter6_d = new CIMKnowledgeGraphNamedTypeFilterByInstances();
              kg_filter6_d.NamedType = "D";//Include is default
              kg_filter6_d.InstancesIDs = list_of_ids.ToArray();
    
      var entity_filters6 = new List<CIMKnowledgeGraphNamedTypeFilter>();
      entity_filters6.Add(kg_filter6_b);//order doesn't matter
      entity_filters6.Add(kg_filter6_c);
      entity_filters6.Add(kg_filter6_d);
    
      //note: All relates are included as no RelationshipFilters are specified
      //var kg_subgraph = ...
      kg_subgraph.EntityFilters = entity_filters6.ToArray();
    
      //Example 7
      //Exclude all entities from B and C and
      //a subset from D (A is implicitly included)
      var kg_filter7_b = new CIMKnowledgeGraphNamedTypeFilterByType();
      var kg_filter7_c = new CIMKnowledgeGraphNamedTypeFilterByType();
    
      kg_filter7_b.NamedType = "B";//predicate is empty
              kg_filter7_c.NamedType = "C";//predicate is empty
              kg_filter7_b.FilterType = KGFilterType.Exclude;
      kg_filter7_c.FilterType = KGFilterType.Exclude;
    
              var kg_filter7_d = new CIMKnowledgeGraphNamedTypeFilterByInstances();
              kg_filter7_d.NamedType = "D";
      kg_filter7_d.FilterType = KGFilterType.Exclude;
      kg_filter7_d.InstancesIDs = list_of_ids.ToArray();//ids to be excluded
    
      var entity_filters7 = new List<CIMKnowledgeGraphNamedTypeFilter>();
      entity_filters7.Add(kg_filter7_b);//order doesn't matter
      entity_filters7.Add(kg_filter7_c);
      entity_filters7.Add(kg_filter7_d);
    
      //note: All relates are included as no RelationshipFilters are specified
      //var kg_subgraph = ...
      kg_subgraph.EntityFilters = entity_filters7.ToArray();
    
      //Example 8
      //Include a subset of Entities from A using a property
      //filter predicate (all of B, C, D will be implicitly excluded)
    
              //we -must- use a predicate prefix in our expression
              //select instances of A w/ Material = 'Steel'
              var expr8 = $"a.Material = 'Steel'";//prefix can be anything - foo, bar, fred, etc.
    
              var kg_filter8 = new CIMKnowledgeGraphNamedTypeFilterByType()
      {
        NamedType = "A",//Include is default
                  PropertyFilterPredicate = expr8 //include ids w/Material='Steel'
              };
    
      var entity_filters8 = new List<CIMKnowledgeGraphNamedTypeFilter>();
      entity_filters8.Add(kg_filter8);
    
      //note: All relates are included as no RelationshipFilters are specified
      //var kg_subgraph = ...
      kg_subgraph.EntityFilters = entity_filters8.ToArray();
    
      //Example 9
      //Exclude a subset of Entities from A using a property
      //filter predicate (all of B, C, D will be implicitly included)
    
      //we -must- use a predicate prefix in our expression
              //select instances of A with Material <> 'Steel'
              var expr9 = $"a.Material <> 'Steel'";//prefix can be anything - foo, bar, fred, etc.
    
              var kg_filter9 = new CIMKnowledgeGraphNamedTypeFilterByType()
      {
        FilterType = KGFilterType.Exclude,
                  NamedType = "A",
                  PropertyFilterPredicate = expr9 //exclude ids w/Material <> 'Steel'
              };
    
      var entity_filters9 = new List<CIMKnowledgeGraphNamedTypeFilter>();
      entity_filters9.Add(kg_filter9);
    
              //Note: All relates are included as no RelationshipFilters are specified
              //var kg_subgraph = ...
              kg_subgraph.EntityFilters = entity_filters9.ToArray();
          });
    Configure Centrality Relationship SubGraph Filters
          //using ArcGIS.Core.Data.Knowledge.Extensions;
    
          await QueuedTask.Run(() =>
    {
    
              //Assume Relationship NamedTypes "R1","R2",and "R3"
              //
              //We can use either of a CIMKnowledgeGraphNamedTypeFilterByInstances
              //or CIMKnowledgeGraphNamedTypeFilterByType to filter instances for
              //_including_ in or _excluding_ from entities and relates wrt the subgraph.
              //
              //Use CIMKnowledgeGraphNamedTypeFilterByInstances to filter by instance id
              //Use CIMKnowledgeGraphNamedTypeFilterByType to filter by type name and with
              //an optional property filter predicate to filter by property value(s)
    
              //Example 1.
              //Include all relates (and entities) from the kg in the subgraph
              //Leave kg_subgraph.RelationshipFilters null
              //(kg_subgraph.EntityFilters is also null)
    
              //The collection of Entity and Relate filters are both empty
      //Everything is included
              var kg_subgraph = new CIMKnowledgeGraphSubGraph();
              //note - relates can only be included if their corresponding entity end points
              //are also included in the subgraph.
    
              //Example 2
              //Include a set of Relates from R1 (all of R2, R3 will be implicitly excluded)
              var kg_filter_r2 = new CIMKnowledgeGraphNamedTypeFilterByInstances()
      {
                  FilterType = KGFilterType.Include,
                  NamedType = "R1",
                  InstancesIDs = list_of_ids.ToArray() //list_of_ids contains desired uids for "R1"
                                                                                           //note: -if list_of_ids is empty then -no-
                                                                                           //instances of R1 will be included.
              };
    
      //var kg_subgraph = ...
      var relate_filters2 = new List<CIMKnowledgeGraphNamedTypeFilter>();
      relate_filters2.Add(kg_filter_r2);
    
      //note: All entities are included as no EntityFilters are specified
      //var kg_subgraph = ...
      kg_subgraph.RelationshipFilters = relate_filters2.ToArray();
    
      //Example 3
      //Exclude a set of Relates from R1 (all of R2, R3 will be implicitly included)
      var kg_filter_r3 = new CIMKnowledgeGraphNamedTypeFilterByInstances()
      {
                  FilterType = KGFilterType.Exclude,
                  NamedType = "R1",
                  InstancesIDs = list_of_ids.ToArray() //list_of_ids contains desired uids for "R1"
                                                                                           //note: -if list_of_ids is empty then -no-
                                                                                           //instances of R1 will be excluded.
              };
    
      var relate_filters3 = new List<CIMKnowledgeGraphNamedTypeFilter>();
      relate_filters3.Add(kg_filter_r3);
      //note: All entities are included as no EntityFilters are specified
      //var kg_subgraph = ...
      kg_subgraph.RelationshipFilters = relate_filters3.ToArray();
    
      //Example 4
      //Include all Relates from R1 via named type (all of R2, R3
      //will be implicitly excluded)
      var kg_filter_r4 = new CIMKnowledgeGraphNamedTypeFilterByType()
      {
                  FilterType = KGFilterType.Include,
                  NamedType = "R1",//all of R1 will be included
                                                   //predicate is empty
              };
    
      var relate_filters4 = new List<CIMKnowledgeGraphNamedTypeFilter>();
      relate_filters4.Add(kg_filter_r4);
    
      //note: All entities are included as no EntityFilters are specified
      //var kg_subgraph = ...
      kg_subgraph.RelationshipFilters = relate_filters4.ToArray();
    
      //Example 5
      //Exclude all Relates from R1 via named type (all of R2, R3
      //will be implicitly included)
    
      var kg_filter_r5 = new CIMKnowledgeGraphNamedTypeFilterByType()
      {
                  FilterType = KGFilterType.Exclude,
                  NamedType = "R1" //all of R1 will be excluded
      };
    
      var relate_filters5 = new List<CIMKnowledgeGraphNamedTypeFilter>();
      relate_filters5.Add(kg_filter_r5);
    
      //note: All entities are included as no EntityFilters are specified
      //var kg_subgraph = ...
      kg_subgraph.RelationshipFilters = relate_filters5.ToArray();
    
      //Example 6
      //Include all relates from R2 and
      //a subset from R3 (R1 is implicitly excluded)
      var kg_filter_r6_r2 = new CIMKnowledgeGraphNamedTypeFilterByType();
      kg_filter_r6_r2.NamedType = "R2"; //Include is default, predicate is empty
    
              //TODO... populate list with uids from "R3"...
              var kg_filter_r6_r3 = new CIMKnowledgeGraphNamedTypeFilterByInstances();
              kg_filter_r6_r3.NamedType = "R3"; //Include is default
              kg_filter_r6_r3.InstancesIDs = list_of_ids.ToArray();
    
      var relate_filters6 = new List<CIMKnowledgeGraphNamedTypeFilter>();
      relate_filters6.Add(kg_filter_r6_r2);//order doesn't matter
      relate_filters6.Add(kg_filter_r6_r3);
    
              //note: All entities are included as no EntityFilters are specified
              //var kg_subgraph = ...
              kg_subgraph.RelationshipFilters = relate_filters6.ToArray();
    
      //Example 7
      //Exclude all relates from R2 and
      //a subset from R3 (R1 is implicitly included)
      var kg_filter_r7_r2 = new CIMKnowledgeGraphNamedTypeFilterByType();
      kg_filter_r7_r2.NamedType = "R2";
      kg_filter_r7_r2.FilterType = KGFilterType.Exclude;
    
              //TODO... populate list with uids from "R3"...
              var kg_filter_r7_r3 = new CIMKnowledgeGraphNamedTypeFilterByInstances();
              kg_filter_r7_r3.NamedType = "R3";
              kg_filter_r7_r3.FilterType = KGFilterType.Exclude;
              kg_filter_r7_r3.InstancesIDs = list_of_ids.ToArray();
    
      var relate_filters7 = new List<CIMKnowledgeGraphNamedTypeFilter>();
      relate_filters7.Add(kg_filter_r7_r2);//order doesn't matter
      relate_filters7.Add(kg_filter_r7_r3);
    
      //note: All entities are included as no EntityFilters are specified
      //var kg_subgraph = ...
      kg_subgraph.RelationshipFilters = relate_filters6.ToArray();
    
              //Example 8
              //Include a subset of Relates from R1 using a property
              //filter predicate (all of R2, R3 will be implicitly excluded)
    
              //we -must- use a predicate prefix in our expression
              //select instances of R1 w/Distance = 2000
              var expr8 = $"r1.Distance = 2000";//prefix can be anything - foo, bar, fred, etc.
    
              var kg_filter_r8 = new CIMKnowledgeGraphNamedTypeFilterByType()
      {
        NamedType = "R1", //Include is default
                  PropertyFilterPredicate = expr8
      };
    
      var relate_filters8 = new List<CIMKnowledgeGraphNamedTypeFilter>();
      relate_filters8.Add(kg_filter_r8);
    
              //note: All entities are included as no EntityFilters are specified
              //var kg_subgraph = ...
              kg_subgraph.RelationshipFilters = relate_filters8.ToArray();
    
              //Example 9
              //Exclude a subset of Relates from R1 using a property
              //filter predicate (all of R2, R3 will be implicitly included)
    
              //we -must- use a predicate prefix in our expression
              //select instances of R1 w/ Distance <> 2000
              var expr9 = $"r1.Distance <> 2000";//prefix can be anything - foo, bar, fred, etc.
    
              var kg_filter_r9 = new CIMKnowledgeGraphNamedTypeFilterByType()
      {
                  FilterType = KGFilterType.Exclude,
                  NamedType = "R1",
                  PropertyFilterPredicate = expr9 //exclude ids w/ Distance <> 2000
              };
    
      var relate_filters9 = new List<CIMKnowledgeGraphNamedTypeFilter>();
      relate_filters9.Add(kg_filter_r9);
    
              //Note: All entities are included as no EntityFilters are specified
              //var kg_subgraph = ...
              kg_subgraph.RelationshipFilters = relate_filters9.ToArray();
          });
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.6 or higher.
    See Also