Documentation for the Cite2Urn class
urn_citation.Cite2Urn
Bases: Urn
A class representing a CITE2URN, which is a specific type of URN used in the CITE architecture.
Source code in src/urn_citation/cite2urn.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | |
__str__()
Serialize the Cite2Urn to its canonical string form.
Source code in src/urn_citation/cite2urn.py
111 112 113 114 115 116 117 118 119 | |
collection_contains(other)
Check if the collection hierarchy contains another Cite2Urn.
Returns True if all non-None values of namespace, collection, and version in this Cite2Urn equal the corresponding values in the other Cite2Urn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Cite2Urn
|
The Cite2Urn to compare with. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if all non-None collection hierarchy fields match, False otherwise. |
Source code in src/urn_citation/cite2urn.py
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
collection_equals(other)
Check if the collection hierarchy equals another Cite2Urn.
Compares the namespace, collection, and version fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Cite2Urn
|
The Cite2Urn to compare with. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if all collection hierarchy fields are equal, False otherwise. |
Source code in src/urn_citation/cite2urn.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
contains(other)
Check if this Cite2Urn contains another Cite2Urn.
Returns True if the collection hierarchy contains the other's collection hierarchy AND the object identifiers are exactly equal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Cite2Urn
|
The Cite2Urn to compare with. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if collection_contains and object_equals are both True, False otherwise. |
Source code in src/urn_citation/cite2urn.py
348 349 350 351 352 353 354 355 356 357 358 359 360 | |
drop_objectid()
Create a new Cite2Urn without the object_id component.
Returns a new Cite2Urn instance with the same collection hierarchy but with the object_id set to None.
Returns:
| Name | Type | Description |
|---|---|---|
Cite2Urn |
'Cite2Urn'
|
A new Cite2Urn instance without the object_id component. |
Source code in src/urn_citation/cite2urn.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | |
drop_subreference()
Create a new Cite2Urn with all subreferences removed.
Returns a new Cite2Urn instance with subreferences (text after @) removed from the object_id component. Works on both single objects and ranges. If there are no subreferences, returns a new instance with the same object_id.
Returns:
| Name | Type | Description |
|---|---|---|
Cite2Urn |
'Cite2Urn'
|
A new Cite2Urn instance without subreferences in the object_id. |
Source code in src/urn_citation/cite2urn.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | |
drop_version()
Create a new Cite2Urn without the version component.
Returns a new Cite2Urn instance with the same collection and object but with the version set to None.
Returns:
| Name | Type | Description |
|---|---|---|
Cite2Urn |
'Cite2Urn'
|
A new Cite2Urn instance without the version component. |
Source code in src/urn_citation/cite2urn.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
from_string(raw_string)
classmethod
Parse a urn:cite2 string into a Cite2Urn instance.
The string must be in the form urn:cite2:<namespace>:<collection[.version]>:<object[-range]>.
Source code in src/urn_citation/cite2urn.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
has_subreference()
Check if the object identifier has a subreference.
An object identifier has a subreference if it contains at least one @ character, which may appear on either or both parts of a range reference, or on a single reference.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the object identifier contains a subreference (@ character), False otherwise. |
Source code in src/urn_citation/cite2urn.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
has_subreference1()
Check if the range begin part has a subreference.
Returns True if the URN is a range and the range begin part contains a @ character indicating a subreference.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the range begin part has a subreference, False otherwise. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the URN is not a range. |
Source code in src/urn_citation/cite2urn.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
has_subreference2()
Check if the range end part has a subreference.
Returns True if the URN is a range and the range end part contains a @ character indicating a subreference.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the range end part has a subreference, False otherwise. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the URN is not a range. |
Source code in src/urn_citation/cite2urn.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
is_range()
Return True when the object component encodes a range (single hyphen).
Source code in src/urn_citation/cite2urn.py
121 122 123 124 125 126 127 | |
object_equals(other)
Check if the object identifier equals another Cite2Urn.
Compares the object_id field of this Cite2Urn with the object_id field of another.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Cite2Urn
|
The Cite2Urn to compare with. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the object_id fields are equal, False otherwise. |
Source code in src/urn_citation/cite2urn.py
335 336 337 338 339 340 341 342 343 344 345 346 | |
range_begin()
Return the first identifier when the object component is a range.
Source code in src/urn_citation/cite2urn.py
129 130 131 132 133 | |
range_end()
Return the second identifier when the object component is a range.
Source code in src/urn_citation/cite2urn.py
135 136 137 138 139 | |
subreference()
Get the subreference part of an object identifier.
Returns the subreference part (the text after @) if the object identifier has a subreference. Returns None if the object identifier has no subreference.
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The subreference part, or None if no subreference exists. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the URN is a range reference. |
Source code in src/urn_citation/cite2urn.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
subreference1()
Get the subreference part of the range begin reference.
Returns the subreference part (the text after @) of the range begin part if it has a subreference. Returns None if the range begin part has no subreference.
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The subreference part of the range begin, or None if no subreference exists. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the URN is not a range reference. |
Source code in src/urn_citation/cite2urn.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
subreference2()
Get the subreference part of the range end reference.
Returns the subreference part (the text after @) of the range end part if it has a subreference. Returns None if the range end part has no subreference.
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The subreference part of the range end, or None if no subreference exists. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the URN is not a range reference. |
Source code in src/urn_citation/cite2urn.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
valid_string(raw_string)
classmethod
Return True when the string can be parsed into a Cite2Urn.
Source code in src/urn_citation/cite2urn.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
validate_subreferences()
Validate subreferences in object identifier.
Ensures that: - object_id component has at most one @ per range part - subreferences are not empty
Raises:
| Type | Description |
|---|---|
ValueError
|
If the subreference constraints are violated. |
Source code in src/urn_citation/cite2urn.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |