Coverage for lode / models / resource.py: 100%
116 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-11-22 15:54 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-11-22 15:54 +0000
1"""Root of the LODE model: the RDF resource every other entity extends."""
4class Resource():
5 """An RDF resource, with its annotations (labels, notes, ...) and links to other resources.
7 Cardinalities are noted next to each field in __init__. Multi-valued fields
8 are plain lists filled by the setters; most getters return a copy so callers
9 cannot alter the model by accident.
10 """
12 def __init__(self):
13 """Create an empty resource: no identifier, not deprecated, all lists empty."""
14 # Init Attributes
15 self.has_identifier = None
16 self.is_deprecated = False
18 # Relations with Literals (0..*)
19 self.has_comment = []
20 self.has_label = []
21 self.has_preferred_label = []
22 self.has_alternative_label = []
23 self.has_hidden_label = []
24 self.has_notation = []
25 self.has_note = []
26 self.has_change_note = []
27 self.has_definition = []
28 self.has_editorial_note = []
29 self.has_example = []
30 self.has_history_note = []
31 self.has_scope_note = []
33 # Relations with Resources (0..*)
34 self.see_also = []
35 self.is_defined_by = []
36 self.has_version_info = []
37 self.also_defined_as = []
39 # Relation with Concepts (0..*)
40 self.has_type = []
42 # Relation with Models (1..*)
43 self.is_included_in = [] # NEEDS TO BE CHECKED
45 # Relation with Resources (0..*)
46 self.is_in_range_of = []
48 def __repr__(self):
49 """Return the class name and the identifier, e.g. Concept('http://example.org/cat').
51 Only the identifier is shown, never the relations: they point to other resources
52 and would recurse. __eq__ and __hash__ are left alone on purpose, because the
53 getters de-duplicate by object identity.
54 """
55 return f"{type(self).__name__}({self.has_identifier!r})"
57 def set_has_identifier(self, value):
58 """Set has_identifier."""
59 self.has_identifier = value
61 def get_has_identifier(self):
62 """Return has_identifier."""
63 return self.has_identifier
65 def set_is_deprecated(self, value):
66 """Set is_deprecated."""
67 self.is_deprecated = value
69 def get_is_deprecated(self):
70 """Return is_deprecated."""
71 return self.is_deprecated
73 def set_has_comment(self, literal):
74 """Add a literal to has_comment."""
75 self.has_comment.append(literal)
77 def get_has_comment(self):
78 """Return a de-duplicated copy of has_comment, in insertion order."""
79 return list(dict.fromkeys(self.has_comment))
81 def set_has_label(self, literal):
82 """Add a literal to has_label."""
83 self.has_label.append(literal)
85 def get_has_label(self):
86 """Return a de-duplicated copy of has_label, in insertion order."""
87 return list(dict.fromkeys(self.has_label))
89 def set_has_preferred_label(self, literal):
90 """Add a literal to has_preferred_label."""
91 self.has_preferred_label.append(literal)
93 def get_has_preferred_label(self):
94 """Return a de-duplicated copy of has_preferred_label, in insertion order."""
95 return list(dict.fromkeys(self.has_preferred_label))
97 def set_has_alternative_label(self, literal):
98 """Add a literal to has_alternative_label."""
99 self.has_alternative_label.append(literal)
101 def get_has_alternative_label(self):
102 """Return a de-duplicated copy of has_alternative_label, in insertion order."""
103 return list(dict.fromkeys(self.has_alternative_label))
105 def set_has_hidden_label(self, literal):
106 """Add a literal to has_hidden_label."""
107 self.has_hidden_label.append(literal)
109 def get_has_hidden_label(self):
110 """Return a de-duplicated copy of has_hidden_label, in insertion order."""
111 return list(dict.fromkeys(self.has_hidden_label))
113 def set_has_notation(self, literal):
114 """Add a literal to has_notation."""
115 self.has_notation.append(literal)
117 def get_has_notation(self):
118 """Return a de-duplicated copy of has_notation, in insertion order."""
119 return list(dict.fromkeys(self.has_notation))
121 def set_has_note(self, literal):
122 """Add a literal to has_note."""
123 self.has_note.append(literal)
125 def get_has_note(self):
126 """Return a de-duplicated copy of has_note, in insertion order."""
127 return list(dict.fromkeys(self.has_note))
129 def set_has_change_note(self, literal):
130 """Add a literal to has_change_note."""
131 self.has_change_note.append(literal)
133 def get_has_change_note(self):
134 """Return a de-duplicated copy of has_change_note, in insertion order."""
135 return list(dict.fromkeys(self.has_change_note))
137 def set_has_definition(self, literal):
138 """Add a literal to has_definition."""
139 self.has_definition.append(literal)
141 def get_has_definition(self):
142 """Return a de-duplicated copy of has_definition, in insertion order."""
143 return list(dict.fromkeys(self.has_definition))
145 def set_has_editorial_note(self, literal):
146 """Add a literal to has_editorial_note."""
147 self.has_editorial_note.append(literal)
149 def get_has_editorial_note(self):
150 """Return a de-duplicated copy of has_editorial_note, in insertion order."""
151 return list(dict.fromkeys(self.has_editorial_note))
153 def set_has_example(self, literal):
154 """Add a literal to has_example."""
155 self.has_example.append(literal)
157 def get_has_example(self):
158 """Return a de-duplicated copy of has_example, in insertion order."""
159 return list(dict.fromkeys(self.has_example))
161 def set_has_history_note(self, literal):
162 """Add a literal to has_history_note."""
163 self.has_history_note.append(literal)
165 def get_has_history_note(self):
166 """Return a de-duplicated copy of has_history_note, in insertion order."""
167 return list(dict.fromkeys(self.has_history_note))
169 def set_has_scope_note(self, literal):
170 """Add a literal to has_scope_note."""
171 self.has_scope_note.append(literal)
173 def get_has_scope_note(self):
174 """Return a de-duplicated copy of has_scope_note, in insertion order."""
175 return list(dict.fromkeys(self.has_scope_note))
177 def set_see_also(self, resource):
178 """Add a resource to see_also."""
179 self.see_also.append(resource)
181 def get_see_also(self):
182 """Return a de-duplicated copy of see_also, in insertion order."""
183 return list(dict.fromkeys(self.see_also))
185 def set_is_defined_by(self, resource):
186 """Add a resource to is_defined_by."""
187 self.is_defined_by.append(resource)
189 def get_is_defined_by(self):
190 """Return a de-duplicated copy of is_defined_by, in insertion order."""
191 return list(dict.fromkeys(self.is_defined_by))
193 def set_has_version_info(self, resource):
194 """Add a resource to has_version_info."""
195 self.has_version_info.append(resource)
197 def get_has_version_info(self):
198 """Return a de-duplicated copy of has_version_info, in insertion order."""
199 return list(dict.fromkeys(self.has_version_info))
201 def set_has_type(self, concept):
202 """Add a concept to has_type, ignoring duplicates."""
203 if concept not in self.has_type:
204 self.has_type.append(concept)
206 def get_has_type(self):
207 """Return a copy of has_type."""
208 return list(self.has_type)
210 def set_is_included_in(self, model):
211 """Add a model to is_included_in."""
212 self.is_included_in.append(model)
214 def get_is_included_in(self):
215 """Return a de-duplicated copy of is_included_in, in insertion order."""
216 return list(dict.fromkeys(self.is_included_in))
218 def get_also_defined_as(self):
219 """Return a copy of also_defined_as."""
220 return list(self.also_defined_as)
222 def set_also_defined_as(self, resource):
223 """Add a resource to also_defined_as."""
224 self.also_defined_as.append(resource)
226 def set_is_in_range_of(self, prop):
227 """Add a property to is_in_range_of, ignoring duplicates."""
228 if prop not in self.is_in_range_of:
229 self.is_in_range_of.append(prop)
231 def get_is_in_range_of(self):
232 """Return a copy of is_in_range_of."""
233 return list(self.is_in_range_of)