@@ -6,14 +6,16 @@ namespace TypeAgent.KnowPro;
66public interface ISemanticRefCollection : IAsyncCollection < SemanticRef >
77{
88 ValueTask < TextRange > GetTextRangeAsync ( int ordinal , CancellationToken cancellationToken = default ) ;
9+
910 ValueTask < IList < TextRange > > GetTextRangeAsync ( IList < int > ordinals , CancellationToken cancellationToken = default ) ;
1011
1112 ValueTask < KnowledgeType > GetKnowledgeTypeAsync ( int ordinal , CancellationToken cancellation = default ) ;
13+
1214 ValueTask < IList < KnowledgeType > > GetKnowledgeTypeAsync ( IList < int > ordinal , CancellationToken cancellation = default ) ;
1315
14- // TODO
15- // Add methods to enumerate by knowledge Type, casting appropriately.
16- // More efficient than looping over all
16+ ValueTask < IList < SemanticRef > > GetAllAsync ( KnowledgeType ? kType = null , CancellationToken cancellationToken = default ) ;
17+
18+ ValueTask < IList < ScoredSemanticRefOrdinal > > GetAllOrdinalsAsync ( KnowledgeType ? kType = null , CancellationToken cancellationToken = default ) ;
1719
1820 event Action < BatchProgress > OnKnowledgeExtracted ;
1921 void NotifyKnowledgeProgress ( BatchProgress progress ) ;
@@ -90,4 +92,30 @@ public static async ValueTask<IList<Scored<ConcreteEntity>>> GetDistinctEntities
9092 ? entitites . GetTopK ( topK . Value )
9193 : [ .. entitites ] ;
9294 }
95+
96+ public static async ValueTask < IList < ConcreteEntity > > GetAllEntitiesAsync (
97+ this ISemanticRefCollection semanticRefs ,
98+ CancellationToken cancellation = default
99+ )
100+ {
101+ var list = await semanticRefs . GetAllAsync (
102+ KnowledgeType . Entity ,
103+ cancellation
104+ ) . ConfigureAwait ( false ) ;
105+
106+ return [ .. list . Select ( ( sr ) => sr . AsEntity ( ) ) ] ;
107+ }
108+
109+ public static async ValueTask < IList < Topic > > GetAllTopicsAsync (
110+ this ISemanticRefCollection semanticRefs ,
111+ CancellationToken cancellation = default
112+ )
113+ {
114+ var list = await semanticRefs . GetAllAsync (
115+ KnowledgeType . Topic ,
116+ cancellation
117+ ) . ConfigureAwait ( false ) ;
118+
119+ return [ .. list . Select ( ( sr ) => sr . AsTopic ( ) ) ] ;
120+ }
93121}
0 commit comments