Skip to content

Resource

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
  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
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
@dataclass
class Resource:
    res_id: str
    restype: str
    label: str
    values: list[Value] = field(default_factory=list)
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS
    file_value: AbstractFileValue | None = None
    migration_metadata: MigrationMetadata | None = None

    def __post_init__(self) -> None:
        msg = []
        if not is_string_like(str(self.label)):
            msg.append(f"Label '{self.label}'")
        if not is_string_like(str(self.res_id)):
            msg.append(f"Resource ID '{self.res_id}'")
        if not is_string_like(str(self.restype)):
            msg.append(f"Resource Type '{self.restype}'")
        if msg:
            out_msg = (
                f"The Resource with the ID '{self.res_id}' should have strings in the following field(s), "
                f"the input is not a valid string.:{LIST_SEPARATOR}{LIST_SEPARATOR.join(msg)}"
            )
            warnings.warn(DspToolsUserWarning(out_msg))

    @staticmethod
    def create_new(
        res_id: str,
        restype: str,
        label: str,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    ) -> Resource:
        """
        Create a new resource.

        Args:
            res_id: resource ID
            restype: resource type
            label: resource label
            permissions: optional permissions of this resource

        Returns:
            Resource
        """
        return Resource(
            res_id=res_id,
            restype=restype,
            label=label,
            permissions=permissions,
        )

    def serialise(self) -> etree._Element:
        res_ele = self._serialise_resource_element()
        if self.file_value:
            res_ele.append(self.file_value.serialise())
        res_ele.extend(self._serialise_values())
        return res_ele

    def _serialise_resource_element(self) -> etree._Element:
        attribs = {"label": self.label, "restype": self.restype, "id": self.res_id}
        if self.permissions != Permissions.PROJECT_SPECIFIC_PERMISSIONS:
            attribs["permissions"] = self.permissions.value
        return etree.Element(f"{DASCH_SCHEMA}resource", attrib=attribs, nsmap=XML_NAMESPACE_MAP)

    def _serialise_values(self) -> list[etree._Element]:
        grouped = defaultdict(list)
        for val in self.values:
            grouped[val.prop_name].append(val)
        return [self._combine_values(prop_values) for prop_values in grouped.values()]

    def _combine_values(self, prop_values: list[Value]) -> etree._Element:
        prop_ = prop_values[0].make_prop()
        prop_eles = [x.make_element() for x in prop_values]
        prop_.extend(prop_eles)
        return prop_

    #######################
    # BooleanValue
    #######################

    def add_bool(
        self,
        prop_name: str,
        value: bool | str | int | float,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add a boolean value to the resource.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#boolean)

        Conversions:
         - The conversion is case-insensitive, meaning that the words can also be capitalised.
         - "false", "0", "0.0", "no", "non", "nein" -> "false"
         - "true", "1", "1.0", "yes", "oui", "ja" -> "true"

        Args:
            prop_name: name of the property
            value: value to add
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added value
        """
        self.values.append(BooleanValue(value, prop_name, permissions, comment, self.res_id))
        return self

    def add_bool_optional(
        self,
        prop_name: str,
        value: Any,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        If the value is not empty, add it to the resource, otherwise return the resource unchanged.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#boolean)

        Conversions:
         - The conversion is case-insensitive, meaning that the words can also be capitalised.
         - "false", "0", "0.0", "no", "non", "nein" -> "false"
         - "true", "1", "1.0", "yes", "oui", "ja" -> "true"

        Args:
            prop_name: name of the property
            value: value to add or empty value
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added value if it was not empty, else the unchanged original resource.
        """
        if is_nonempty_value(value):
            self.values.append(BooleanValue(value, prop_name, permissions, comment, self.res_id))
        return self

    #######################
    # ColorValue
    #######################

    def add_color(
        self,
        prop_name: str,
        value: str,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add a color value to the resource.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#color)

        Args:
            prop_name: name of the property
            value: value to add
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added value
        """
        self.values.append(ColorValue(value, prop_name, permissions, comment, self.res_id))
        return self

    def add_color_multiple(
        self,
        prop_name: str,
        values: Collection[str],
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add several color values to the resource.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#color)

        Args:
            prop_name: name of the property
            values: values to add
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added values
        """
        self.values.extend([ColorValue(v, prop_name, permissions, comment, self.res_id) for v in values])
        return self

    def add_color_optional(
        self,
        prop_name: str,
        value: Any,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        If the value is not empty, add it to the resource, otherwise return the resource unchanged.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#color)

        Args:
            prop_name: name of the property
            value: value to add or empty value
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added value if it was not empty, else the unchanged original resource.
        """
        if is_nonempty_value(value):
            self.values.append(ColorValue(value, prop_name, permissions, comment, self.res_id))
        return self

    #######################
    # DateValue
    #######################

    def add_date(
        self,
        prop_name: str,
        value: str,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add a date value to the resource.
        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#date)

        Args:
            prop_name: name of the property
            value: value to add
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added value
        """
        self.values.append(DateValue(value, prop_name, permissions, comment, self.res_id))
        return self

    def add_date_multiple(
        self,
        prop_name: str,
        values: Collection[str],
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add several date values to the resource.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#date)

        Args:
            prop_name: name of the property
            values: values to add
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added values
        """
        self.values.extend([DateValue(v, prop_name, permissions, comment, self.res_id) for v in values])
        return self

    def add_date_optional(
        self,
        prop_name: str,
        value: Any,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        If the value is not empty, add it to the resource, otherwise return the resource unchanged.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#date)

        Args:
            prop_name: name of the property
            value: value to add or empty value
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added value if it was not empty, else the unchanged original resource.
        """
        if is_nonempty_value(value):
            self.values.append(DateValue(value, prop_name, permissions, comment, self.res_id))
        return self

    #######################
    # DecimalValue
    #######################

    def add_decimal(
        self,
        prop_name: str,
        value: float | int | str,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add a decimal value to the resource.
        If the value is provided as string, it must be convertible to integer or float.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#decimal)

        Args:
            prop_name: name of the property
            value: value to add
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added value
        """
        self.values.append(DecimalValue(value, prop_name, permissions, comment, self.res_id))
        return self

    def add_decimal_multiple(
        self,
        prop_name: str,
        values: Collection[float | int | str],
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add several decimal values to the resource.
        If the values are provided as string, they must be convertible to integer or float.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#decimal)

        Args:
            prop_name: name of the property
            values: values to add
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added values
        """
        self.values.extend([DecimalValue(v, prop_name, permissions, comment, self.res_id) for v in values])
        return self

    def add_decimal_optional(
        self,
        prop_name: str,
        value: Any,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        If the value is not empty, add it to the resource, otherwise return the resource unchanged.
        If the value is provided as string, it must be convertible to integer or float.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#decimal)

        Args:
            prop_name: name of the property
            value: value to add or empty value
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added value if it was not empty, else the unchanged original resource.
        """
        if is_nonempty_value(value):
            self.values.append(DecimalValue(value, prop_name, permissions, comment, self.res_id))
        return self

    #######################
    # GeonameValue
    #######################

    def add_geoname(
        self,
        prop_name: str,
        value: int | str,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add a [geonames.org](https://www.geonames.org/) value to the resource.
        The [geonames.org](https://www.geonames.org/) identifier must be provided as integer
        or string that is convertible to integer.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#geoname)


        Args:
            prop_name: name of the property
            value: value to add
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added value
        """
        self.values.append(GeonameValue(value, prop_name, permissions, comment, self.res_id))
        return self

    def add_geoname_multiple(
        self,
        prop_name: str,
        values: Collection[int | str],
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add several [geonames.org](https://www.geonames.org/) values to the resource.
        The [geonames.org](https://www.geonames.org/) identifiers must be provided as integers
        or strings that are convertible to integers.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#geoname)

        Args:
            prop_name: name of the property
            values: values to add
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added values
        """
        self.values.extend([GeonameValue(v, prop_name, permissions, comment, self.res_id) for v in values])
        return self

    def add_geoname_optional(
        self,
        prop_name: str,
        value: Any,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        If the value is not empty, add it to the resource, otherwise return the resource unchanged.
        The [geonames.org](https://www.geonames.org/) identifier must be provided as integer
        or string that is convertible to integer.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#geoname)

        Args:
            prop_name: name of the property
            value: value to add or empty value
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added value if it was not empty, else the unchanged original resource.
        """
        if is_nonempty_value(value):
            self.values.append(GeonameValue(value, prop_name, permissions, comment, self.res_id))
        return self

    #######################
    # IntValue
    #######################

    def add_integer(
        self,
        prop_name: str,
        value: int | str,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add an integer value to the resource.
        If the value is provided as string, it must be convertible to integer.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#integer)

        Args:
            prop_name: name of the property
            value: value to add
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added value
        """
        self.values.append(IntValue(value, prop_name, permissions, comment, self.res_id))
        return self

    def add_integer_multiple(
        self,
        prop_name: str,
        values: Collection[int | str],
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add several integer values to the resource.
        If the values are provided as string, they must be convertible to integer.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#integer)

        Args:
            prop_name: name of the property
            values: values to add
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added values
        """
        self.values.extend([IntValue(v, prop_name, permissions, comment, self.res_id) for v in values])
        return self

    def add_integer_optional(
        self,
        prop_name: str,
        value: Any,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        If the value is not empty, add it to the resource, otherwise return the resource unchanged.
        If the value is provided as string, it must be convertible to integer.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#integer)

        Args:
            prop_name: name of the property
            value: value to add or empty value
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added value if it was not empty, else the unchanged original resource.
        """
        if is_nonempty_value(value):
            self.values.append(IntValue(value, prop_name, permissions, comment, self.res_id))
        return self

    #######################
    # LinkValue
    #######################

    def add_link(
        self,
        prop_name: str,
        value: str,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add a link value to the resource, in the form of an ID of another resource.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#resptr)

        Args:
            prop_name: name of the property
            value: target resource ID
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added value
        """
        self.values.append(LinkValue(value, prop_name, permissions, comment, self.res_id))
        return self

    def add_link_multiple(
        self,
        prop_name: str,
        values: Collection[str],
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add several link values to the resource, in the form of IDs of other resources.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#resptr)

        Args:
            prop_name: name of the property
            values: list of target resources IDs
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added values
        """
        self.values.extend([LinkValue(v, prop_name, permissions, comment, self.res_id) for v in values])
        return self

    def add_link_optional(
        self,
        prop_name: str,
        value: Any,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        If the value is not empty, add it to the resource, otherwise return the resource unchanged.
        If non-empty, the value must be an ID of another resource.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#resptr)

        Args:
            prop_name: name of the property
            value: target resource ID or empty value
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added value if it was not empty, else the unchanged original resource.
        """
        if is_nonempty_value(value):
            self.values.append(LinkValue(value, prop_name, permissions, comment, self.res_id))
        return self

    #######################
    # ListValue
    #######################

    def add_list(
        self,
        prop_name: str,
        list_name: str | int | float,
        value: str | int | float,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add a list value to the resource, i.e. a name of a list node.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#list)

        Args:
            prop_name: name of the property
            list_name: name of the list (N.B. not the label, but the name of the list)
            value: name of a list node (N.B. not the label, but the name of the list node)
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added value
        """
        self.values.append(ListValue(value, list_name, prop_name, permissions, comment, self.res_id))
        return self

    def add_list_multiple(
        self,
        prop_name: str,
        list_name: str | int | float,
        values: Collection[str | int | float],
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add several list values to the resource, i.e. names of list nodes.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#list)

        Args:
            prop_name: name of the property
            list_name: name of the list (N.B. not the label, but the name of the list)
            values: names of list nodes (N.B. not the labels, but the names of the list nodes)
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added values
        """
        self.values.extend([ListValue(v, list_name, prop_name, permissions, comment, self.res_id) for v in values])
        return self

    def add_list_optional(
        self,
        prop_name: str,
        list_name: str | int | float,
        value: Any,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        If the value is not empty, add it to the resource, otherwise return the resource unchanged.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#list)

        Args:
            prop_name: name of the property
            list_name: name of the list (N.B. not the label, but the name of the list)
            value: name of a list node (N.B. not the label, but the name of the list node) or empty value
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added value if it was not empty, else the unchanged original resource.
        """
        if is_nonempty_value(value):
            self.values.append(ListValue(value, list_name, prop_name, permissions, comment, self.res_id))
        return self

    #######################
    # TextValue: SimpleText
    #######################

    def add_simpletext(
        self,
        prop_name: str,
        value: str,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add a simple text value to the resource.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#text)

        Args:
            prop_name: name of the property
            value: value to add
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added value
        """
        self.values.append(SimpleText(value, prop_name, permissions, comment, self.res_id))
        return self

    def add_simpletext_multiple(
        self,
        prop_name: str,
        values: Collection[str],
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add several simple text values to the resource.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#text)

        Args:
            prop_name: name of the property
            values: values to add
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added values
        """
        self.values.extend([SimpleText(v, prop_name, permissions, comment, self.res_id) for v in values])
        return self

    def add_simpletext_optional(
        self,
        prop_name: str,
        value: Any,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        If the value is not empty, add it to the resource, otherwise return the resource unchanged.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#text)

        Args:
            prop_name: name of the property
            value: value to add or empty value
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added value if it was not empty, else the unchanged original resource.
        """
        if is_nonempty_value(value):
            self.values.append(SimpleText(value, prop_name, permissions, comment, self.res_id))
        return self

    #######################
    # TextValue: Richtext
    #######################

    def add_richtext(
        self,
        prop_name: str,
        value: str,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
        newline_replacement: NewlineReplacement = NewlineReplacement.LINEBREAK,
    ) -> Resource:
        """
        Add a rich text value to the resource.
        Rich text values must be provided as strings, potentially containing DSP Standard Standoff Markup XML tags
        as [documented here.](https://docs.dasch.swiss/latest/DSP-API/03-endpoints/api-v2/text/standard-standoff/)
        Only the documented tags are allowed.

        Conversions:
            By default, replace newline characters inside the text value with `<br/>`, which preserves the linebreak.
            Without this replacement, the newline would disappear, because `\\n` is meaningless in an XML file.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#text)

        Args:
            prop_name: name of the property
            value: value to add
            permissions: optional permissions of this value
            comment: optional comment
            newline_replacement: options how to deal with `\\n` inside the text value. Default: replace with `<br/>`

        Returns:
            The original resource, with the added value
        """
        value = replace_newlines_with_tags(str(value), newline_replacement)
        self.values.append(Richtext(value, prop_name, permissions, comment, self.res_id))
        return self

    def add_richtext_multiple(
        self,
        prop_name: str,
        values: Collection[str],
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
        newline_replacement: NewlineReplacement = NewlineReplacement.LINEBREAK,
    ) -> Resource:
        """
        Add several rich text values to the resource.
        Rich text values must be provided as strings, potentially containing DSP Standard Standoff Markup XML tags
        as [documented here.](https://docs.dasch.swiss/latest/DSP-API/03-endpoints/api-v2/text/standard-standoff/)
        Only the documented tags are allowed.

        Conversions:
            By default, replace newline characters inside the text value with `<br/>`, which preserves the linebreak.
            Without this replacement, the newline would disappear, because `\\n` is meaningless in an XML file.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#text)

        Args:
            prop_name: name of the property
            values: values to add
            permissions: optional permissions of this value
            comment: optional comment
            newline_replacement: options how to deal with `\\n` inside the text value. Default: replace with `<br/>`

        Returns:
            The original resource, with the added values
        """
        values = [replace_newlines_with_tags(str(v), newline_replacement) for v in values]
        self.values.extend([Richtext(v, prop_name, permissions, comment, self.res_id) for v in values])
        return self

    def add_richtext_optional(
        self,
        prop_name: str,
        value: Any,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
        newline_replacement: NewlineReplacement = NewlineReplacement.LINEBREAK,
    ) -> Resource:
        """
        If the value is not empty, add it to the resource, otherwise return the resource unchanged.
        Rich text values must be provided as strings, potentially containing DSP Standard Standoff Markup XML tags
        as [documented here.](https://docs.dasch.swiss/latest/DSP-API/03-endpoints/api-v2/text/standard-standoff/)
        Only the documented tags are allowed.

        Conversions:
            By default, replace newline characters inside the text value with `<br/>`, which preserves the linebreak.
            Without this replacement, the newline would disappear, because `\\n` is meaningless in an XML file.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#text)

        Args:
            prop_name: name of the property
            value: value to add or empty value
            permissions: optional permissions of this value
            comment: optional comment
            newline_replacement: options how to deal with `\\n` inside the text value. Default: replace with `<br/>`

        Returns:
            The original resource, with the added value if it was not empty, else the unchanged original resource.
        """
        if is_nonempty_value(value):
            value = replace_newlines_with_tags(str(value), newline_replacement)
            self.values.append(Richtext(value, prop_name, permissions, comment, self.res_id))
        return self

    #######################
    # TimeValue
    #######################

    def add_time(
        self,
        prop_name: str,
        value: str,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add a time value to the resource.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#time)

        Args:
            prop_name: name of the property
            value: value to add
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added value
        """
        self.values.append(TimeValue(value, prop_name, permissions, comment, self.res_id))
        return self

    def add_time_multiple(
        self,
        prop_name: str,
        values: Collection[str],
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add several time values to the resource.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#time)

        Args:
            prop_name: name of the property
            values: values to add
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added values
        """
        self.values.extend([TimeValue(v, prop_name, permissions, comment, self.res_id) for v in values])
        return self

    def add_time_optional(
        self,
        prop_name: str,
        value: Any,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        If the value is not empty, add it to the resource, otherwise return the resource unchanged.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#time)

        Args:
            prop_name: name of the property
            value: value to add or empty value
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added value if it was not empty, else the unchanged original resource.
        """
        if is_nonempty_value(value):
            self.values.append(TimeValue(value, prop_name, permissions, comment, self.res_id))
        return self

    #######################
    # UriValue
    #######################

    def add_uri(
        self,
        prop_name: str,
        value: str,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add a URI value to the resource.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#uri)

        Args:
            prop_name: name of the property
            value: value to add
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added value
        """
        self.values.append(UriValue(value, prop_name, permissions, comment, self.res_id))
        return self

    def add_uri_multiple(
        self,
        prop_name: str,
        values: Collection[str],
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add several URI values to the resource.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#uri)

        Args:
            prop_name: name of the property
            values: values to add
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added values
        """
        self.values.extend([UriValue(v, prop_name, permissions, comment, self.res_id) for v in values])
        return self

    def add_uri_optional(
        self,
        prop_name: str,
        value: Any,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        If the value is not empty, add it to the resource, otherwise return the resource unchanged.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#uri)

        Args:
            prop_name: name of the property
            value: value to add or empty value
            permissions: optional permissions of this value
            comment: optional comment

        Returns:
            The original resource, with the added value if it was not empty, else the unchanged original resource.
        """
        if is_nonempty_value(value):
            self.values.append(UriValue(value, prop_name, permissions, comment, self.res_id))
        return self

    #######################
    # AbstractFileValue
    #######################

    def add_file(
        self,
        filename: str,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add a file (bitstream) to the resource.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#bitstream)

        Args:
            filename: path to the file
            permissions: optional permissions of this file
            comment: optional comment

        Raises:
            InputError: If the resource already has a file or IIIF URI value

        Returns:
            The original resource, with the added value
        """
        if self.file_value:
            raise InputError(
                f"The resource with the ID '{self.res_id}' already contains a file with the name: "
                f"'{self.file_value.value}'.\n"
                f"The new file with the name '{filename}' cannot be added."
            )
        self.file_value = FileValue(filename, permissions, comment, self.res_id)
        return self

    def add_iiif_uri(
        self,
        iiif_uri: str,
        permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
        comment: str | None = None,
    ) -> Resource:
        """
        Add a IIIF URI to the resource.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#iiif-uri)

        Args:
            iiif_uri: valid IIIF URI
            permissions: optional permissions of this value
            comment: optional comment

        Raises:
            InputError: If the resource already has a file or IIIF URI value

        Returns:
            The original resource, with the added value
        """
        if self.file_value:
            raise InputError(
                f"The resource with the ID '{self.res_id}' already contains a file with the name: "
                f"'{self.file_value.value}'.\n"
                f"The new file with the name '{iiif_uri}' cannot be added."
            )
        self.file_value = IIIFUri(iiif_uri, permissions, comment, self.res_id)
        return self

    #######################
    # Migration Metadata
    #######################

    def add_migration_metadata(
        self, creation_date: str | None, iri: str | None = None, ark: str | None = None
    ) -> Resource:
        """
        Add metadata from a SALSAH migration.

        [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#describing-resources-with-the-resource-element)

        Args:
            creation_date: creation date of the resource in SALSAH
            iri: Original IRI in SALSAH
            ark: Original ARK in SALSAH

        Raises:
            InputError: if metadata already exists

        Returns:
            The original resource, with the added migration metadata
        """
        if self.migration_metadata:
            raise InputError(
                f"The resource with the ID '{self.res_id}' already contains migration metadata, "
                f"no new data can be added."
            )
        self.migration_metadata = MigrationMetadata(creation_date=creation_date, iri=iri, ark=ark, res_id=self.res_id)
        return self

create_new

Create a new resource.

Parameters:

Name Type Description Default
res_id str

resource ID

required
restype str

resource type

required
label str

resource label

required
permissions Permissions

optional permissions of this resource

PROJECT_SPECIFIC_PERMISSIONS

Returns:

Type Description
Resource

Resource

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
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
@staticmethod
def create_new(
    res_id: str,
    restype: str,
    label: str,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
) -> Resource:
    """
    Create a new resource.

    Args:
        res_id: resource ID
        restype: resource type
        label: resource label
        permissions: optional permissions of this resource

    Returns:
        Resource
    """
    return Resource(
        res_id=res_id,
        restype=restype,
        label=label,
        permissions=permissions,
    )

add_bool

Add a boolean value to the resource.

See XML documentation for details

Conversions
  • The conversion is case-insensitive, meaning that the words can also be capitalised.
  • "false", "0", "0.0", "no", "non", "nein" -> "false"
  • "true", "1", "1.0", "yes", "oui", "ja" -> "true"

Parameters:

Name Type Description Default
prop_name str

name of the property

required
value bool | str | int | float

value to add

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
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
def add_bool(
    self,
    prop_name: str,
    value: bool | str | int | float,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add a boolean value to the resource.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#boolean)

    Conversions:
     - The conversion is case-insensitive, meaning that the words can also be capitalised.
     - "false", "0", "0.0", "no", "non", "nein" -> "false"
     - "true", "1", "1.0", "yes", "oui", "ja" -> "true"

    Args:
        prop_name: name of the property
        value: value to add
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added value
    """
    self.values.append(BooleanValue(value, prop_name, permissions, comment, self.res_id))
    return self

add_bool_optional

If the value is not empty, add it to the resource, otherwise return the resource unchanged.

See XML documentation for details

Conversions
  • The conversion is case-insensitive, meaning that the words can also be capitalised.
  • "false", "0", "0.0", "no", "non", "nein" -> "false"
  • "true", "1", "1.0", "yes", "oui", "ja" -> "true"

Parameters:

Name Type Description Default
prop_name str

name of the property

required
value Any

value to add or empty value

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value if it was not empty, else the unchanged original resource.

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
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
def add_bool_optional(
    self,
    prop_name: str,
    value: Any,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    If the value is not empty, add it to the resource, otherwise return the resource unchanged.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#boolean)

    Conversions:
     - The conversion is case-insensitive, meaning that the words can also be capitalised.
     - "false", "0", "0.0", "no", "non", "nein" -> "false"
     - "true", "1", "1.0", "yes", "oui", "ja" -> "true"

    Args:
        prop_name: name of the property
        value: value to add or empty value
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added value if it was not empty, else the unchanged original resource.
    """
    if is_nonempty_value(value):
        self.values.append(BooleanValue(value, prop_name, permissions, comment, self.res_id))
    return self

add_color

Add a color value to the resource.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
value str

value to add

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
def add_color(
    self,
    prop_name: str,
    value: str,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add a color value to the resource.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#color)

    Args:
        prop_name: name of the property
        value: value to add
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added value
    """
    self.values.append(ColorValue(value, prop_name, permissions, comment, self.res_id))
    return self

add_color_multiple

Add several color values to the resource.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
values Collection[str]

values to add

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added values

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
def add_color_multiple(
    self,
    prop_name: str,
    values: Collection[str],
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add several color values to the resource.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#color)

    Args:
        prop_name: name of the property
        values: values to add
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added values
    """
    self.values.extend([ColorValue(v, prop_name, permissions, comment, self.res_id) for v in values])
    return self

add_color_optional

If the value is not empty, add it to the resource, otherwise return the resource unchanged.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
value Any

value to add or empty value

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value if it was not empty, else the unchanged original resource.

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
def add_color_optional(
    self,
    prop_name: str,
    value: Any,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    If the value is not empty, add it to the resource, otherwise return the resource unchanged.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#color)

    Args:
        prop_name: name of the property
        value: value to add or empty value
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added value if it was not empty, else the unchanged original resource.
    """
    if is_nonempty_value(value):
        self.values.append(ColorValue(value, prop_name, permissions, comment, self.res_id))
    return self

add_date

Add a date value to the resource. See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
value str

value to add

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
def add_date(
    self,
    prop_name: str,
    value: str,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add a date value to the resource.
    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#date)

    Args:
        prop_name: name of the property
        value: value to add
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added value
    """
    self.values.append(DateValue(value, prop_name, permissions, comment, self.res_id))
    return self

add_date_multiple

Add several date values to the resource.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
values Collection[str]

values to add

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added values

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
def add_date_multiple(
    self,
    prop_name: str,
    values: Collection[str],
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add several date values to the resource.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#date)

    Args:
        prop_name: name of the property
        values: values to add
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added values
    """
    self.values.extend([DateValue(v, prop_name, permissions, comment, self.res_id) for v in values])
    return self

add_date_optional

If the value is not empty, add it to the resource, otherwise return the resource unchanged.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
value Any

value to add or empty value

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value if it was not empty, else the unchanged original resource.

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
def add_date_optional(
    self,
    prop_name: str,
    value: Any,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    If the value is not empty, add it to the resource, otherwise return the resource unchanged.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#date)

    Args:
        prop_name: name of the property
        value: value to add or empty value
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added value if it was not empty, else the unchanged original resource.
    """
    if is_nonempty_value(value):
        self.values.append(DateValue(value, prop_name, permissions, comment, self.res_id))
    return self

add_decimal

Add a decimal value to the resource. If the value is provided as string, it must be convertible to integer or float.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
value float | int | str

value to add

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
def add_decimal(
    self,
    prop_name: str,
    value: float | int | str,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add a decimal value to the resource.
    If the value is provided as string, it must be convertible to integer or float.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#decimal)

    Args:
        prop_name: name of the property
        value: value to add
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added value
    """
    self.values.append(DecimalValue(value, prop_name, permissions, comment, self.res_id))
    return self

add_decimal_multiple

Add several decimal values to the resource. If the values are provided as string, they must be convertible to integer or float.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
values Collection[float | int | str]

values to add

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added values

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
def add_decimal_multiple(
    self,
    prop_name: str,
    values: Collection[float | int | str],
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add several decimal values to the resource.
    If the values are provided as string, they must be convertible to integer or float.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#decimal)

    Args:
        prop_name: name of the property
        values: values to add
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added values
    """
    self.values.extend([DecimalValue(v, prop_name, permissions, comment, self.res_id) for v in values])
    return self

add_decimal_optional

If the value is not empty, add it to the resource, otherwise return the resource unchanged. If the value is provided as string, it must be convertible to integer or float.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
value Any

value to add or empty value

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value if it was not empty, else the unchanged original resource.

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
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
def add_decimal_optional(
    self,
    prop_name: str,
    value: Any,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    If the value is not empty, add it to the resource, otherwise return the resource unchanged.
    If the value is provided as string, it must be convertible to integer or float.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#decimal)

    Args:
        prop_name: name of the property
        value: value to add or empty value
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added value if it was not empty, else the unchanged original resource.
    """
    if is_nonempty_value(value):
        self.values.append(DecimalValue(value, prop_name, permissions, comment, self.res_id))
    return self

add_geoname

Add a geonames.org value to the resource. The geonames.org identifier must be provided as integer or string that is convertible to integer.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
value int | str

value to add

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
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
def add_geoname(
    self,
    prop_name: str,
    value: int | str,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add a [geonames.org](https://www.geonames.org/) value to the resource.
    The [geonames.org](https://www.geonames.org/) identifier must be provided as integer
    or string that is convertible to integer.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#geoname)


    Args:
        prop_name: name of the property
        value: value to add
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added value
    """
    self.values.append(GeonameValue(value, prop_name, permissions, comment, self.res_id))
    return self

add_geoname_multiple

Add several geonames.org values to the resource. The geonames.org identifiers must be provided as integers or strings that are convertible to integers.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
values Collection[int | str]

values to add

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added values

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
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
def add_geoname_multiple(
    self,
    prop_name: str,
    values: Collection[int | str],
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add several [geonames.org](https://www.geonames.org/) values to the resource.
    The [geonames.org](https://www.geonames.org/) identifiers must be provided as integers
    or strings that are convertible to integers.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#geoname)

    Args:
        prop_name: name of the property
        values: values to add
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added values
    """
    self.values.extend([GeonameValue(v, prop_name, permissions, comment, self.res_id) for v in values])
    return self

add_geoname_optional

If the value is not empty, add it to the resource, otherwise return the resource unchanged. The geonames.org identifier must be provided as integer or string that is convertible to integer.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
value Any

value to add or empty value

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value if it was not empty, else the unchanged original resource.

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
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
def add_geoname_optional(
    self,
    prop_name: str,
    value: Any,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    If the value is not empty, add it to the resource, otherwise return the resource unchanged.
    The [geonames.org](https://www.geonames.org/) identifier must be provided as integer
    or string that is convertible to integer.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#geoname)

    Args:
        prop_name: name of the property
        value: value to add or empty value
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added value if it was not empty, else the unchanged original resource.
    """
    if is_nonempty_value(value):
        self.values.append(GeonameValue(value, prop_name, permissions, comment, self.res_id))
    return self

add_integer

Add an integer value to the resource. If the value is provided as string, it must be convertible to integer.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
value int | str

value to add

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
def add_integer(
    self,
    prop_name: str,
    value: int | str,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add an integer value to the resource.
    If the value is provided as string, it must be convertible to integer.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#integer)

    Args:
        prop_name: name of the property
        value: value to add
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added value
    """
    self.values.append(IntValue(value, prop_name, permissions, comment, self.res_id))
    return self

add_integer_multiple

Add several integer values to the resource. If the values are provided as string, they must be convertible to integer.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
values Collection[int | str]

values to add

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added values

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
def add_integer_multiple(
    self,
    prop_name: str,
    values: Collection[int | str],
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add several integer values to the resource.
    If the values are provided as string, they must be convertible to integer.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#integer)

    Args:
        prop_name: name of the property
        values: values to add
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added values
    """
    self.values.extend([IntValue(v, prop_name, permissions, comment, self.res_id) for v in values])
    return self

add_integer_optional

If the value is not empty, add it to the resource, otherwise return the resource unchanged. If the value is provided as string, it must be convertible to integer.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
value Any

value to add or empty value

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value if it was not empty, else the unchanged original resource.

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
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
def add_integer_optional(
    self,
    prop_name: str,
    value: Any,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    If the value is not empty, add it to the resource, otherwise return the resource unchanged.
    If the value is provided as string, it must be convertible to integer.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#integer)

    Args:
        prop_name: name of the property
        value: value to add or empty value
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added value if it was not empty, else the unchanged original resource.
    """
    if is_nonempty_value(value):
        self.values.append(IntValue(value, prop_name, permissions, comment, self.res_id))
    return self

Add a link value to the resource, in the form of an ID of another resource.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
value str

target resource ID

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
def add_link(
    self,
    prop_name: str,
    value: str,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add a link value to the resource, in the form of an ID of another resource.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#resptr)

    Args:
        prop_name: name of the property
        value: target resource ID
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added value
    """
    self.values.append(LinkValue(value, prop_name, permissions, comment, self.res_id))
    return self

Add several link values to the resource, in the form of IDs of other resources.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
values Collection[str]

list of target resources IDs

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added values

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
def add_link_multiple(
    self,
    prop_name: str,
    values: Collection[str],
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add several link values to the resource, in the form of IDs of other resources.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#resptr)

    Args:
        prop_name: name of the property
        values: list of target resources IDs
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added values
    """
    self.values.extend([LinkValue(v, prop_name, permissions, comment, self.res_id) for v in values])
    return self

If the value is not empty, add it to the resource, otherwise return the resource unchanged. If non-empty, the value must be an ID of another resource.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
value Any

target resource ID or empty value

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value if it was not empty, else the unchanged original resource.

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
def add_link_optional(
    self,
    prop_name: str,
    value: Any,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    If the value is not empty, add it to the resource, otherwise return the resource unchanged.
    If non-empty, the value must be an ID of another resource.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#resptr)

    Args:
        prop_name: name of the property
        value: target resource ID or empty value
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added value if it was not empty, else the unchanged original resource.
    """
    if is_nonempty_value(value):
        self.values.append(LinkValue(value, prop_name, permissions, comment, self.res_id))
    return self

add_list

Add a list value to the resource, i.e. a name of a list node.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
list_name str | int | float

name of the list (N.B. not the label, but the name of the list)

required
value str | int | float

name of a list node (N.B. not the label, but the name of the list node)

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
def add_list(
    self,
    prop_name: str,
    list_name: str | int | float,
    value: str | int | float,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add a list value to the resource, i.e. a name of a list node.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#list)

    Args:
        prop_name: name of the property
        list_name: name of the list (N.B. not the label, but the name of the list)
        value: name of a list node (N.B. not the label, but the name of the list node)
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added value
    """
    self.values.append(ListValue(value, list_name, prop_name, permissions, comment, self.res_id))
    return self

add_list_multiple

Add several list values to the resource, i.e. names of list nodes.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
list_name str | int | float

name of the list (N.B. not the label, but the name of the list)

required
values Collection[str | int | float]

names of list nodes (N.B. not the labels, but the names of the list nodes)

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added values

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
def add_list_multiple(
    self,
    prop_name: str,
    list_name: str | int | float,
    values: Collection[str | int | float],
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add several list values to the resource, i.e. names of list nodes.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#list)

    Args:
        prop_name: name of the property
        list_name: name of the list (N.B. not the label, but the name of the list)
        values: names of list nodes (N.B. not the labels, but the names of the list nodes)
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added values
    """
    self.values.extend([ListValue(v, list_name, prop_name, permissions, comment, self.res_id) for v in values])
    return self

add_list_optional

If the value is not empty, add it to the resource, otherwise return the resource unchanged.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
list_name str | int | float

name of the list (N.B. not the label, but the name of the list)

required
value Any

name of a list node (N.B. not the label, but the name of the list node) or empty value

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value if it was not empty, else the unchanged original resource.

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
def add_list_optional(
    self,
    prop_name: str,
    list_name: str | int | float,
    value: Any,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    If the value is not empty, add it to the resource, otherwise return the resource unchanged.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#list)

    Args:
        prop_name: name of the property
        list_name: name of the list (N.B. not the label, but the name of the list)
        value: name of a list node (N.B. not the label, but the name of the list node) or empty value
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added value if it was not empty, else the unchanged original resource.
    """
    if is_nonempty_value(value):
        self.values.append(ListValue(value, list_name, prop_name, permissions, comment, self.res_id))
    return self

add_simpletext

Add a simple text value to the resource.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
value str

value to add

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
def add_simpletext(
    self,
    prop_name: str,
    value: str,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add a simple text value to the resource.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#text)

    Args:
        prop_name: name of the property
        value: value to add
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added value
    """
    self.values.append(SimpleText(value, prop_name, permissions, comment, self.res_id))
    return self

add_simpletext_multiple

Add several simple text values to the resource.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
values Collection[str]

values to add

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added values

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
def add_simpletext_multiple(
    self,
    prop_name: str,
    values: Collection[str],
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add several simple text values to the resource.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#text)

    Args:
        prop_name: name of the property
        values: values to add
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added values
    """
    self.values.extend([SimpleText(v, prop_name, permissions, comment, self.res_id) for v in values])
    return self

add_simpletext_optional

If the value is not empty, add it to the resource, otherwise return the resource unchanged.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
value Any

value to add or empty value

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value if it was not empty, else the unchanged original resource.

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
def add_simpletext_optional(
    self,
    prop_name: str,
    value: Any,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    If the value is not empty, add it to the resource, otherwise return the resource unchanged.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#text)

    Args:
        prop_name: name of the property
        value: value to add or empty value
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added value if it was not empty, else the unchanged original resource.
    """
    if is_nonempty_value(value):
        self.values.append(SimpleText(value, prop_name, permissions, comment, self.res_id))
    return self

add_richtext

Add a rich text value to the resource. Rich text values must be provided as strings, potentially containing DSP Standard Standoff Markup XML tags as documented here. Only the documented tags are allowed.

Conversions

By default, replace newline characters inside the text value with <br/>, which preserves the linebreak. Without this replacement, the newline would disappear, because \n is meaningless in an XML file.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
value str

value to add

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None
newline_replacement NewlineReplacement

options how to deal with \n inside the text value. Default: replace with <br/>

LINEBREAK

Returns:

Type Description
Resource

The original resource, with the added value

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
def add_richtext(
    self,
    prop_name: str,
    value: str,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
    newline_replacement: NewlineReplacement = NewlineReplacement.LINEBREAK,
) -> Resource:
    """
    Add a rich text value to the resource.
    Rich text values must be provided as strings, potentially containing DSP Standard Standoff Markup XML tags
    as [documented here.](https://docs.dasch.swiss/latest/DSP-API/03-endpoints/api-v2/text/standard-standoff/)
    Only the documented tags are allowed.

    Conversions:
        By default, replace newline characters inside the text value with `<br/>`, which preserves the linebreak.
        Without this replacement, the newline would disappear, because `\\n` is meaningless in an XML file.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#text)

    Args:
        prop_name: name of the property
        value: value to add
        permissions: optional permissions of this value
        comment: optional comment
        newline_replacement: options how to deal with `\\n` inside the text value. Default: replace with `<br/>`

    Returns:
        The original resource, with the added value
    """
    value = replace_newlines_with_tags(str(value), newline_replacement)
    self.values.append(Richtext(value, prop_name, permissions, comment, self.res_id))
    return self

add_richtext_multiple

Add several rich text values to the resource. Rich text values must be provided as strings, potentially containing DSP Standard Standoff Markup XML tags as documented here. Only the documented tags are allowed.

Conversions

By default, replace newline characters inside the text value with <br/>, which preserves the linebreak. Without this replacement, the newline would disappear, because \n is meaningless in an XML file.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
values Collection[str]

values to add

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None
newline_replacement NewlineReplacement

options how to deal with \n inside the text value. Default: replace with <br/>

LINEBREAK

Returns:

Type Description
Resource

The original resource, with the added values

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
def add_richtext_multiple(
    self,
    prop_name: str,
    values: Collection[str],
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
    newline_replacement: NewlineReplacement = NewlineReplacement.LINEBREAK,
) -> Resource:
    """
    Add several rich text values to the resource.
    Rich text values must be provided as strings, potentially containing DSP Standard Standoff Markup XML tags
    as [documented here.](https://docs.dasch.swiss/latest/DSP-API/03-endpoints/api-v2/text/standard-standoff/)
    Only the documented tags are allowed.

    Conversions:
        By default, replace newline characters inside the text value with `<br/>`, which preserves the linebreak.
        Without this replacement, the newline would disappear, because `\\n` is meaningless in an XML file.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#text)

    Args:
        prop_name: name of the property
        values: values to add
        permissions: optional permissions of this value
        comment: optional comment
        newline_replacement: options how to deal with `\\n` inside the text value. Default: replace with `<br/>`

    Returns:
        The original resource, with the added values
    """
    values = [replace_newlines_with_tags(str(v), newline_replacement) for v in values]
    self.values.extend([Richtext(v, prop_name, permissions, comment, self.res_id) for v in values])
    return self

add_richtext_optional

If the value is not empty, add it to the resource, otherwise return the resource unchanged. Rich text values must be provided as strings, potentially containing DSP Standard Standoff Markup XML tags as documented here. Only the documented tags are allowed.

Conversions

By default, replace newline characters inside the text value with <br/>, which preserves the linebreak. Without this replacement, the newline would disappear, because \n is meaningless in an XML file.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
value Any

value to add or empty value

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None
newline_replacement NewlineReplacement

options how to deal with \n inside the text value. Default: replace with <br/>

LINEBREAK

Returns:

Type Description
Resource

The original resource, with the added value if it was not empty, else the unchanged original resource.

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
def add_richtext_optional(
    self,
    prop_name: str,
    value: Any,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
    newline_replacement: NewlineReplacement = NewlineReplacement.LINEBREAK,
) -> Resource:
    """
    If the value is not empty, add it to the resource, otherwise return the resource unchanged.
    Rich text values must be provided as strings, potentially containing DSP Standard Standoff Markup XML tags
    as [documented here.](https://docs.dasch.swiss/latest/DSP-API/03-endpoints/api-v2/text/standard-standoff/)
    Only the documented tags are allowed.

    Conversions:
        By default, replace newline characters inside the text value with `<br/>`, which preserves the linebreak.
        Without this replacement, the newline would disappear, because `\\n` is meaningless in an XML file.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#text)

    Args:
        prop_name: name of the property
        value: value to add or empty value
        permissions: optional permissions of this value
        comment: optional comment
        newline_replacement: options how to deal with `\\n` inside the text value. Default: replace with `<br/>`

    Returns:
        The original resource, with the added value if it was not empty, else the unchanged original resource.
    """
    if is_nonempty_value(value):
        value = replace_newlines_with_tags(str(value), newline_replacement)
        self.values.append(Richtext(value, prop_name, permissions, comment, self.res_id))
    return self

add_time

Add a time value to the resource.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
value str

value to add

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
def add_time(
    self,
    prop_name: str,
    value: str,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add a time value to the resource.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#time)

    Args:
        prop_name: name of the property
        value: value to add
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added value
    """
    self.values.append(TimeValue(value, prop_name, permissions, comment, self.res_id))
    return self

add_time_multiple

Add several time values to the resource.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
values Collection[str]

values to add

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added values

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
def add_time_multiple(
    self,
    prop_name: str,
    values: Collection[str],
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add several time values to the resource.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#time)

    Args:
        prop_name: name of the property
        values: values to add
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added values
    """
    self.values.extend([TimeValue(v, prop_name, permissions, comment, self.res_id) for v in values])
    return self

add_time_optional

If the value is not empty, add it to the resource, otherwise return the resource unchanged.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
value Any

value to add or empty value

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value if it was not empty, else the unchanged original resource.

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
def add_time_optional(
    self,
    prop_name: str,
    value: Any,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    If the value is not empty, add it to the resource, otherwise return the resource unchanged.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#time)

    Args:
        prop_name: name of the property
        value: value to add or empty value
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added value if it was not empty, else the unchanged original resource.
    """
    if is_nonempty_value(value):
        self.values.append(TimeValue(value, prop_name, permissions, comment, self.res_id))
    return self

add_uri

Add a URI value to the resource.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
value str

value to add

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
def add_uri(
    self,
    prop_name: str,
    value: str,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add a URI value to the resource.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#uri)

    Args:
        prop_name: name of the property
        value: value to add
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added value
    """
    self.values.append(UriValue(value, prop_name, permissions, comment, self.res_id))
    return self

add_uri_multiple

Add several URI values to the resource.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
values Collection[str]

values to add

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added values

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
def add_uri_multiple(
    self,
    prop_name: str,
    values: Collection[str],
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add several URI values to the resource.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#uri)

    Args:
        prop_name: name of the property
        values: values to add
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added values
    """
    self.values.extend([UriValue(v, prop_name, permissions, comment, self.res_id) for v in values])
    return self

add_uri_optional

If the value is not empty, add it to the resource, otherwise return the resource unchanged.

See XML documentation for details

Parameters:

Name Type Description Default
prop_name str

name of the property

required
value Any

value to add or empty value

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value if it was not empty, else the unchanged original resource.

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
def add_uri_optional(
    self,
    prop_name: str,
    value: Any,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    If the value is not empty, add it to the resource, otherwise return the resource unchanged.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#uri)

    Args:
        prop_name: name of the property
        value: value to add or empty value
        permissions: optional permissions of this value
        comment: optional comment

    Returns:
        The original resource, with the added value if it was not empty, else the unchanged original resource.
    """
    if is_nonempty_value(value):
        self.values.append(UriValue(value, prop_name, permissions, comment, self.res_id))
    return self

add_file

Add a file (bitstream) to the resource.

See XML documentation for details

Parameters:

Name Type Description Default
filename str

path to the file

required
permissions Permissions

optional permissions of this file

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
def add_file(
    self,
    filename: str,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add a file (bitstream) to the resource.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#bitstream)

    Args:
        filename: path to the file
        permissions: optional permissions of this file
        comment: optional comment

    Raises:
        InputError: If the resource already has a file or IIIF URI value

    Returns:
        The original resource, with the added value
    """
    if self.file_value:
        raise InputError(
            f"The resource with the ID '{self.res_id}' already contains a file with the name: "
            f"'{self.file_value.value}'.\n"
            f"The new file with the name '{filename}' cannot be added."
        )
    self.file_value = FileValue(filename, permissions, comment, self.res_id)
    return self

add_iiif_uri

Add a IIIF URI to the resource.

See XML documentation for details

Parameters:

Name Type Description Default
iiif_uri str

valid IIIF URI

required
permissions Permissions

optional permissions of this value

PROJECT_SPECIFIC_PERMISSIONS
comment str | None

optional comment

None

Returns:

Type Description
Resource

The original resource, with the added value

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
def add_iiif_uri(
    self,
    iiif_uri: str,
    permissions: Permissions = Permissions.PROJECT_SPECIFIC_PERMISSIONS,
    comment: str | None = None,
) -> Resource:
    """
    Add a IIIF URI to the resource.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#iiif-uri)

    Args:
        iiif_uri: valid IIIF URI
        permissions: optional permissions of this value
        comment: optional comment

    Raises:
        InputError: If the resource already has a file or IIIF URI value

    Returns:
        The original resource, with the added value
    """
    if self.file_value:
        raise InputError(
            f"The resource with the ID '{self.res_id}' already contains a file with the name: "
            f"'{self.file_value.value}'.\n"
            f"The new file with the name '{iiif_uri}' cannot be added."
        )
    self.file_value = IIIFUri(iiif_uri, permissions, comment, self.res_id)
    return self

add_migration_metadata

Add metadata from a SALSAH migration.

See XML documentation for details

Parameters:

Name Type Description Default
creation_date str | None

creation date of the resource in SALSAH

required
iri str | None

Original IRI in SALSAH

None
ark str | None

Original ARK in SALSAH

None

Returns:

Type Description
Resource

The original resource, with the added migration metadata

Source code in dsp/dsp-tools/src/dsp_tools/xmllib/models/resource.py
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
def add_migration_metadata(
    self, creation_date: str | None, iri: str | None = None, ark: str | None = None
) -> Resource:
    """
    Add metadata from a SALSAH migration.

    [See XML documentation for details](https://docs.dasch.swiss/latest/DSP-TOOLS/file-formats/xml-data-file/#describing-resources-with-the-resource-element)

    Args:
        creation_date: creation date of the resource in SALSAH
        iri: Original IRI in SALSAH
        ark: Original ARK in SALSAH

    Raises:
        InputError: if metadata already exists

    Returns:
        The original resource, with the added migration metadata
    """
    if self.migration_metadata:
        raise InputError(
            f"The resource with the ID '{self.res_id}' already contains migration metadata, "
            f"no new data can be added."
        )
    self.migration_metadata = MigrationMetadata(creation_date=creation_date, iri=iri, ark=ark, res_id=self.res_id)
    return self