Coverage for lode / models / model.py: 97%

39 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-11-22 15:54 +0000

1"""Model: the documented ontology (or vocabulary) itself, with its versions and imports.""" 

2from .resource import Resource 

3 

4class Model(Resource): 

5 """An ontology or vocabulary: versioning, compatibility, imports and namespaces.""" 

6 

7 def __init__(self, **kwargs): 

8 """Create a model with no versions, imports or namespaces.""" 

9 super().__init__(**kwargs) 

10 self.has_version = [] # 0..* 

11 self.is_backward_compatible_with = [] # 0..*  

12 self.imports = [] # 0..* 

13 self.is_incompatible_with = [] # 0..* 

14 self.has_top_concept = [] # 0..* 

15 self.has_prior_version = None # 0..1 

16 self.has_namespaces = {} # 1 (prefix -> URI) 

17 

18 def get_has_version(self): 

19 """Return a copy of has_version.""" 

20 return list(self.has_version) 

21 

22 def set_has_version(self, model): 

23 """Add a model to has_version.""" 

24 self.has_version.append(model) 

25 

26 def get_is_backward_compatible_with(self): 

27 """Return a copy of is_backward_compatible_with.""" 

28 return list(self.is_backward_compatible_with) 

29 

30 def set_is_backward_compatible_with(self, model): 

31 """Add a model to is_backward_compatible_with.""" 

32 self.is_backward_compatible_with.append(model) 

33 

34 def get_imports(self): 

35 """Return a copy of imports.""" 

36 return list(self.imports) 

37 

38 def set_imports(self, model): 

39 """Add a model to imports.""" 

40 self.imports.append(model) 

41 

42 def get_is_incompatible_with(self): 

43 """Return a copy of is_incompatible_with.""" 

44 return list(self.is_incompatible_with) 

45 

46 def set_is_incompatible_with(self, model): 

47 """Add a model to is_incompatible_with.""" 

48 self.is_incompatible_with.append(model) 

49 

50 def get_has_top_concept(self): 

51 """Return has_top_concept (a single concept, or None).""" 

52 return list(self.has_top_concept) 

53 

54 def set_has_top_concept(self, concept): 

55 """Add a concept to has_top_concept""" 

56 self.has_top_concept.append(concept) 

57 

58 def get_has_prior_version(self): 

59 """Return has_prior_version (a single model, or None).""" 

60 return self.has_prior_version 

61 

62 def set_has_prior_version(self, model): 

63 """Set has_prior_version, replacing any previous value.""" 

64 self.has_prior_version = model 

65 

66 def get_has_namespaces(self): 

67 """Return a copy of the prefix -> URI dictionary.""" 

68 return dict(self.has_namespaces) 

69 

70 def set_has_namespaces(self, namespaces: dict): 

71 """Set the prefix -> URI dictionary of the namespaces.""" 

72 self.has_namespaces = namespaces 

73