Coverage for lode / models / property.py: 96%

46 statements  

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

1"""Property: the base class of RDF/OWL properties.""" 

2from .resource import Resource 

3 

4class Property(Resource): 

5 """Represents an RDF Property""" 

6 

7 def __init__(self, **kwargs): 

8 """Create a property that is not functional, with empty hierarchy, domain and range.""" 

9 

10 super().__init__(**kwargs) 

11 

12 # Attributes 

13 self.is_functional = False # bool [1] 

14 

15 # Relations with Properties (0..*) 

16 self.is_sub_property_of = [] 

17 self.is_super_property_of = [] 

18 self.is_disjoint_with = [] 

19 self.is_equivalent_to = [] 

20 

21 # Relation with Resource (1..*)  

22 self.has_range = [] 

23 

24 # Relations with Concept (1..*) 

25 self.has_domain = [] 

26 

27 # Methods foris_functional 

28 def set_is_functional(self, bool): 

29 """Set is_functional.""" 

30 self.is_functional = bool 

31 

32 def get_is_functional(self): 

33 """Return is_functional.""" 

34 return self.is_functional 

35 

36 # Methods foris_sub_property_of / is_super_property_of 

37 def set_is_sub_property_of(self, property_obj): 

38 """Add a super property to is_sub_property_of and register self as its sub property. 

39 

40 The inverse link is set only when the target supports it. 

41 """ 

42 if property_obj not in self.is_sub_property_of: 

43 self.is_sub_property_of.append(property_obj) 

44 inv = getattr(property_obj, 'is_super_property_of', None) 

45 if inv is not None and self not in inv: 

46 inv.append(self) 

47 

48 def get_is_sub_property_of(self): 

49 """Return a copy of is_sub_property_of.""" 

50 return list(self.is_sub_property_of) 

51 

52 def set_is_super_property_of(self, property_obj): 

53 """Add a property to is_super_property_of, ignoring duplicates.""" 

54 if property_obj not in self.is_super_property_of: 

55 self.is_super_property_of.append(property_obj) 

56 

57 def get_is_super_property_of(self): 

58 """Return a copy of is_super_property_of.""" 

59 return list(self.is_super_property_of) 

60 

61 # Methods foris_disjoint_with 

62 def set_is_disjoint_with(self, property_obj): 

63 """Add a property to is_disjoint_with.""" 

64 self.is_disjoint_with.append(property_obj) 

65 

66 def get_is_disjoint_with(self): 

67 """Return a de-duplicated copy of is_disjoint_with (order is not preserved).""" 

68 return list(set(self.is_disjoint_with)) 

69 

70 def set_is_equivalent_to(self, property_obj): 

71 """Add a property to is_equivalent_to.""" 

72 self.is_equivalent_to.append(property_obj) 

73 

74 def get_is_equivalent_to(self): 

75 """Return a de-duplicated copy of is_equivalent_to (order is not preserved).""" 

76 return list(set(self.is_equivalent_to)) 

77 

78 # Methods forhas_range 

79 def set_has_range(self, resource): 

80 """Add a resource to has_range, ignoring duplicates.""" 

81 if resource not in self.has_range: 

82 self.has_range.append(resource) 

83 

84 def get_has_range(self): 

85 """Return a copy of has_range.""" 

86 return list(self.has_range) 

87 

88 def set_has_domain(self, concept): 

89 """Add a concept to has_domain, ignoring duplicates.""" 

90 if concept not in self.has_domain: 

91 self.has_domain.append(concept) 

92 

93 def get_has_domain(self): 

94 """Return a copy of has_domain.""" 

95 return list(self.has_domain) 

96