Coverage for lode / viewer / rdf_viewer.py: 18%

28 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-10-05 16:02 +0000

1# viewer/rdf_viewer.py 

2from typing import Dict, Optional 

3from lode.viewer.base_viewer import BaseViewer 

4 

5 

6class RdfViewer(BaseViewer): 

7 """Viewer RDF / RDFS""" 

8 

9 TYPE_MAP = { 

10 'concept': {'singular': 'Class', 'plural': 'Classes', 'abb': 'c'}, 

11 'property': {'singular': 'Property', 'plural': 'Properties', 'abb': 'p'}, 

12 'container': {'singular': 'Container', 'plural': 'Containers', 'abb': 'cont'}, 

13 'resource': {'singular': 'Resource', 'plural': 'Resources', 'abb': 'r'}, 

14 'model': {'singular': 'Vocabulary','plural': 'Vocabularies','abb': 'v'}, 

15 } 

16 

17 def get_view_data(self, resource_uri: Optional[str] = None, language: Optional[str] = None) -> Dict: 

18 all_instances = self.get_all_instances() 

19 metadata_dict = self._find_and_format_metadata(all_instances, language) 

20 

21 if resource_uri: 

22 data = super().get_view_data(resource_uri, language) 

23 data['metadata'] = metadata_dict 

24 data['type_map'] = self.TYPE_MAP 

25 return data 

26 

27 # title in SINGOLARE per matchare le chiavi di TYPE_MAP 

28 toc_config = [ 

29 ('Concept', 'concepts', 'Concept'), 

30 ('Property', 'properties', 'Property'), 

31 ('Container', 'containers', 'Container'), 

32 ] 

33 

34 data = self._build_grouped_view(toc_config, language) 

35 data['metadata'] = metadata_dict 

36 data['type_map'] = self.TYPE_MAP 

37 

38 # DEBUG — togliere dopo 

39 print("=" * 60) 

40 print(f"DEBUG RDF VIEWER") 

41 print(f" grouped_view = {data.get('grouped_view')}") 

42 print(f" sections count = {len(data.get('sections') or [])}") 

43 for s in data.get('sections') or []: 

44 print(f" [{s['id']}] title={s['title']!r} entities={len(s['entities'])}") 

45 print(f" type_map keys = {list(data['type_map'].keys())}") 

46 # Conta i tipi reali nel cache 

47 from collections import Counter 

48 types = Counter(type(i).__name__ for i in self.get_all_instances()) 

49 print(f" instances by type = {dict(types)}") 

50 print("=" * 60) 

51 

52 return data