Documentation for the CtsUrn class
urn_citation.CtsUrn
Bases: Urn
A CTS URN identifying a passage of a canonically citable text.
Canonical Text Service (CTS) URNs model passages of texts with two overlapping hierarchies: a work hierarchy, and a passage hierarchy. Values in the work hierarchy belong to a specified namespace. The work hierarchy is required to identify at least a text group; optionally, it may specify a work, a version (edition or translation) of the work, and exemplar (specific copy of the version). The passage hierarchy may be empty, in which case the URN refers to the entire contents of the work identified in the work hierarchy. Otherwise, the passage hierarchy identifies a specific passage of the work, at any depth of the citation hierarchy appropriate for the work (e.g., book, chapter, verse, line, token.) The passage hierarchy may identify either a single passage or a range of passages.
Attributes:
| Name | Type | Description |
|---|---|---|
namespace |
str
|
Required identifier for the namespace of the text (e.g., "greekLit" or "latinLit") where values for the work hierarchy are defined. |
text_group |
str
|
Required identifier for text group. |
work |
str
|
Optional identifier for work. |
version |
str
|
Optional identifier for version (edition or translation) of the work. |
exemplar |
str
|
Optional identifier for exemplar (specific copy of the version) of the work. |
passage |
str
|
Optional identifier for passage of the work, at any depth of the citation hierarchy appropriate for the work (e.g., book, chapter, verse, line, token). May identify either a single passage or a range of passages. |
Source code in src/urn_citation/ctsurn.py
6 7 8 9 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 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | |
__str__()
Serialize the CtsUrn to its string representation.
Returns a CTS URN string in the format: urn:cts:namespace:work.hierarchy:passage
Where work.hierarchy is constructed from the text_group, work, version, and exemplar, and passage is the passage component (or empty string if None).
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The serialized CTS URN string. |
Source code in src/urn_citation/ctsurn.py
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 | |
contains(other)
Check if this CtsUrn contains another CtsUrn.
Returns True if both the work hierarchy and passage contain the other.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
CtsUrn
|
The CtsUrn to compare with. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if both work_contains and passage_contains are True, False otherwise. |
Source code in src/urn_citation/ctsurn.py
438 439 440 441 442 443 444 445 446 447 448 449 | |
drop_exemplar()
Create a new CtsUrn without the exemplar component.
Returns a new CtsUrn instance with the same work hierarchy but with the exemplar set to None.
Returns:
| Name | Type | Description |
|---|---|---|
CtsUrn |
CtsUrn
|
A new CtsUrn instance without the exemplar component. |
Source code in src/urn_citation/ctsurn.py
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 | |
drop_passage()
Create a new CtsUrn without the passage component.
Returns a new CtsUrn instance with the same work hierarchy but with the passage set to None.
Returns:
| Name | Type | Description |
|---|---|---|
CtsUrn |
CtsUrn
|
A new CtsUrn instance without the passage component. |
Source code in src/urn_citation/ctsurn.py
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 | |
drop_subreference()
Create a new CtsUrn with all subreferences removed.
Returns a new CtsUrn instance with subreferences (text after @) removed from the passage component. Works on both single passages and ranges. If there are no subreferences, returns a new instance with the same passage.
Returns:
| Name | Type | Description |
|---|---|---|
CtsUrn |
CtsUrn
|
A new CtsUrn instance without subreferences in the passage. |
Source code in src/urn_citation/ctsurn.py
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | |
drop_version()
Create a new CtsUrn without the version component.
Returns a new CtsUrn instance with the same work hierarchy but with the version set to None. Note: exemplar will also be set to None since exemplar cannot exist without a version.
Returns:
| Name | Type | Description |
|---|---|---|
CtsUrn |
CtsUrn
|
A new CtsUrn instance without the version component. |
Source code in src/urn_citation/ctsurn.py
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 | |
has_subreference()
Check if the passage component has a subreference.
A passage 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 passage contains a subreference (@ character), False otherwise. |
Source code in src/urn_citation/ctsurn.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
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/ctsurn.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
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/ctsurn.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
is_range()
Check if the passage component represents a range.
A passage is a range if it contains exactly one hyphen, indicating both a range beginning and range end separated by that hyphen.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the passage is a range, False otherwise. |
Source code in src/urn_citation/ctsurn.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
passage_contains(other)
Check if the passage component contains another CtsUrn.
Returns True if: - The passages are exactly equal, OR - The other passage is at least 2 characters longer and starts with this passage followed by a period character.
Raises ValueError if either passage is a range.
Examples: - passage="1", other.passage="1.11" -> True - passage="1", other.passage="12" -> False
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
CtsUrn
|
The CtsUrn to compare with. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the passages match the similarity criteria, False otherwise. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If either passage is a range (contains a hyphen). |
Source code in src/urn_citation/ctsurn.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 435 436 | |
passage_equals(other)
Check if the passage component is equal to another CtsUrn.
Compares the passage field of this CtsUrn with the passage field of another.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
CtsUrn
|
The CtsUrn to compare with. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the passage fields are equal, False otherwise. |
Source code in src/urn_citation/ctsurn.py
383 384 385 386 387 388 389 390 391 392 393 394 | |
range_begin()
Get the beginning of a passage range.
Returns the first range piece if the passage component represents a range (i.e., contains exactly one hyphen). Returns None if the passage is not a range or if passage is None.
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The beginning of the range, or None if not a range. |
Source code in src/urn_citation/ctsurn.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
range_end()
Get the end of a passage range.
Returns the second range piece if the passage component represents a range (i.e., contains exactly one hyphen). Returns None if the passage is not a range or if passage is None.
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The end of the range, or None if not a range. |
Source code in src/urn_citation/ctsurn.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
set_exemplar(new_exemplar)
Create a new CtsUrn with a specified exemplar component.
Returns a new CtsUrn instance with the same work hierarchy but with the exemplar set to the provided new_exemplar value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_exemplar
|
str | None
|
The new exemplar component to set. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
CtsUrn |
CtsUrn
|
A new CtsUrn instance with the updated exemplar component. |
Source code in src/urn_citation/ctsurn.py
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | |
set_passage(new_passage)
Create a new CtsUrn with a specified passage component.
Returns a new CtsUrn instance with the same work hierarchy but with the passage set to the provided new_passage value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_passage
|
str | None
|
The new passage component to set. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
CtsUrn |
CtsUrn
|
A new CtsUrn instance with the updated passage component. |
Source code in src/urn_citation/ctsurn.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | |
set_version(new_version)
Create a new CtsUrn with a specified version component.
Returns a new CtsUrn instance with the same work hierarchy but with the version set to the provided new_version value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_version
|
str | None
|
The new version component to set. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
CtsUrn |
CtsUrn
|
A new CtsUrn instance with the updated version component. |
Source code in src/urn_citation/ctsurn.py
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 | |
subreference()
Get the subreference part of a passage reference.
Returns the subreference part (the text after @) if the passage has a subreference. Returns None if the passage 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/ctsurn.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
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/ctsurn.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
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/ctsurn.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
valid_string(raw_string)
classmethod
Check if a string is valid for constructing a CtsUrn.
A valid CTS URN string must: - Split into exactly 5 colon-delimited components - Have a passage component with at most 1 hyphen (for ranges) - Have a work component with at most 4 dot-delimited parts
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_string
|
str
|
The string to validate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the string is valid, False otherwise. |
Source code in src/urn_citation/ctsurn.py
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 | |
validate_work_hierarchy()
Validate the work hierarchy structure.
Ensures that: - version cannot be set if work is None - exemplar cannot be set if version or work is None - passage component has at most one @ per range part
Raises:
| Type | Description |
|---|---|
ValueError
|
If the hierarchy constraints are violated. |
Source code in src/urn_citation/ctsurn.py
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 | |
work_contains(other)
Check if the work hierarchy contains another CtsUrn.
Returns True if all non-None values of text_group, work, version, and exemplar in this CtsUrn equal the corresponding values in the other CtsUrn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
CtsUrn
|
The CtsUrn to compare with. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if all non-None work hierarchy fields match, False otherwise. |
Source code in src/urn_citation/ctsurn.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | |
work_equals(other)
Check if the work hierarchy is equal to another CtsUrn.
Compares the text_group, work, version, and exemplar fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
CtsUrn
|
The CtsUrn to compare with. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if all work hierarchy fields are equal, False otherwise. |
Source code in src/urn_citation/ctsurn.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |