11from dataclasses import dataclass
2- from typing import List
2+ from typing import Dict , List
33
44from more_itertools import chunked
55
88 DomainGraphSchema ,
99)
1010from elimity_insights_client ._util import map_list
11- from elimity_insights_client .api .entities ._entity import Entity , Link
11+ from elimity_insights_client .api .entities ._entity import Entity , EntityType , Link
1212from elimity_insights_client .api .entities ._schema import (
1313 attribute_types as schema_attribute_types ,
1414)
@@ -32,24 +32,26 @@ class _AttributeAssignment:
3232
3333@dataclass
3434class _LinkGroup :
35- entity_type : str
35+ entity_type : EntityType
3636 links : List [Link ]
3737
3838
3939def parse_query_results_page (
40- entity_type : str , page : QueryResultsPage , schema : DomainGraphSchema
40+ entity_type : EntityType ,
41+ page : QueryResultsPage ,
42+ schemas : Dict [int , DomainGraphSchema ],
4143) -> List [Entity ]:
4244 def make_entity (result : QueryResult ) -> Entity :
43- entity = _link (entity_type , schema , result )
45+ entity = _link (entity_type , result , schemas )
4446
45- def make_group (entity_type : str , page : QueryResultsPage ) -> _LinkGroup :
47+ def make_group (entity_type : EntityType , page : QueryResultsPage ) -> _LinkGroup :
4648 def make_link (result : QueryResult ) -> Link :
47- return _link (entity_type , schema , result )
49+ return _link (entity_type , result , schemas )
4850
4951 links = map_list (make_link , page .results )
5052 return _LinkGroup (entity_type , links )
5153
52- link_entity_types = schema_link_entity_types (entity_type , schema )
54+ link_entity_types = schema_link_entity_types (entity_type , schemas )
5355 group_iter = map (make_group , link_entity_types , result .link_pages )
5456 links = {group .entity_type : group .links for group in group_iter }
5557 return Entity (entity .attribute_assignments , entity .id , links , entity .name )
@@ -65,9 +67,11 @@ def _attribute_assignment(
6567 return _AttributeAssignment (assigned , type .id , value_inclusion )
6668
6769
68- def _link (entity_type : str , schema : DomainGraphSchema , result : QueryResult ) -> Link :
70+ def _link (
71+ entity_type : EntityType , result : QueryResult , schemas : Dict [int , DomainGraphSchema ]
72+ ) -> Link :
6973 inclusions_iter = chunked (result .inclusions , 2 )
70- attribute_types = schema_attribute_types (entity_type , schema )
74+ attribute_types = schema_attribute_types (entity_type , schemas )
7175 assignment_iter = map (_attribute_assignment , inclusions_iter , attribute_types )
7276 assignments = {
7377 assignment .attribute_type : assignment .value
0 commit comments