-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathincludes.php
2371 lines (2135 loc) · 87.3 KB
/
includes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
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
<?php
/***** FUNCTIONS *****/
function generate_nuds($row, $project, $eXist_credentials, $obverses, $reverses, $count, $mode){
$indexable = false;
$uri_space = $project['uri_space'];
$recordId = trim($row['ID']);
if (strlen($recordId) > 0 && ($mode == 'test' || $mode == 'prod')){
echo "Processing {$recordId}\n";
$doc = new XMLWriter();
if ($mode == 'test'){
$doc->openUri('php://output');
} elseif ($mode == 'prod'){
$doc->openUri('nuds/' . $project['name'] . '/'. $recordId . '.xml');
}
$doc->setIndent(true);
//now we need to define our Indent string,which is basically how many blank spaces we want to have for the indent
$doc->setIndentString(" ");
$doc->startDocument('1.0','UTF-8');
$doc->startElement('nuds');
$doc->writeAttribute('xmlns', 'http://nomisma.org/nuds');
$doc->writeAttribute('xmlns:xs', 'http://www.w3.org/2001/XMLSchema');
$doc->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$doc->writeAttribute('xmlns:tei', 'http://www.tei-c.org/ns/1.0');
$doc->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$doc->writeAttribute('xsi:schemaLocation', 'http://nomisma.org/nuds http://nomisma.org/nuds.xsd');
$doc->writeAttribute('recordType', 'conceptual');
//control
$doc->startElement('control');
$doc->writeElement('recordId', $recordId);
//insert typeNumber just to capture the num.
$doc->startElement('otherRecordId');
$doc->writeAttribute('localType', 'typeNumber');
if (array_key_exists('Type Number', $row) && strlen($row['Type Number']) > 0){
$doc->text(trim($row['Type Number']));
} else {
$doc->text(get_typeNumber($recordId, $project));
}
$doc->endElement();
//hierarchy
if (array_key_exists('Parent ID', $row) && strlen($row['Parent ID']) > 0){
$doc->startElement('otherRecordId');
$doc->writeAttribute('semantic', 'skos:broader');
$doc->text(trim($row['Parent ID']));
$doc->endElement();
} else {
//insert a sortID
$doc->startElement('otherRecordId');
$doc->writeAttribute('localType', 'sortId');
if (array_key_exists('sortId', $row) && strlen($row['sortId']) > 0){
$doc->text($row['sortId']);
} else {
$doc->text(number_pad(intval($count), 5));
}
$doc->endElement();
}
if (array_key_exists('Matching URI', $row) && strlen(trim($row['Matching URI'])) > 0){
$uris = explode('|', trim($row['Matching URI']));
foreach ($uris as $uri){
$uri = trim($uri);
$doc->startElement('otherRecordId');
$doc->writeAttribute('semantic', 'skos:exactMatch');
$doc->text($uri);
$doc->endElement();
}
}
if (array_key_exists('replaces ID', $row) && strlen(trim($row['replaces ID'])) > 0){
$replaces = explode('|', $row['replaces ID']);
foreach ($replaces as $replacesID){
$replacesID = trim($replacesID);
$doc->startElement('otherRecordId');
$doc->writeAttribute('semantic', 'dcterms:replaces');
$doc->text($replacesID);
$doc->endElement();
$doc->startElement('otherRecordId');
$doc->writeAttribute('semantic', 'skos:exactMatch');
$doc->text($uri_space . $replacesID);
$doc->endElement();
}
}
//handle semantic relation with other record
if (array_key_exists('isReplacedBy ID', $row) && strlen($row['isReplacedBy ID']) > 0){
$replaces = explode('|', $row['isReplacedBy ID']);
$doc->writeElement('publicationStatus', 'deprecatedType');
//if there is more than one replacement, then the status is cancelledSplit, otherwise cancelledReplaced
if (count($replaces) > 1) {
$doc->writeElement('maintenanceStatus', 'cancelledSplit');
} else {
$doc->writeElement('maintenanceStatus', 'cancelledReplaced');
}
foreach ($replaces as $deprecatedID){
$deprecatedID = trim($deprecatedID);
$doc->startElement('otherRecordId');
$doc->writeAttribute('semantic', 'dcterms:isReplacedBy');
$doc->text($deprecatedID);
$doc->endElement();
//only insert skos:exactMatch if there is a 1:1 relationship
if (count($replaces) == 1) {
$doc->startElement('otherRecordId');
$doc->writeAttribute('semantic', 'skos:exactMatch');
$doc->text($uri_space . $deprecatedID);
$doc->endElement();
}
}
} else {
//set the maintenanceStatus and publicationStatus values
if (array_key_exists('maintenanceStatus', $row) && $row['maintenanceStatus'] == 'cancelled') {
$doc->writeElement('publicationStatus', 'deprecatedType');
$doc->writeElement('maintenanceStatus', 'cancelled');
} elseif (array_key_exists('Parent ID', $row) && strlen($row['Parent ID']) > 0) {
$doc->writeElement('publicationStatus', 'approvedSubtype');
$doc->writeElement('maintenanceStatus', 'derived');
$indexable = true;
} else {
$doc->writeElement('publicationStatus', 'approved');
$doc->writeElement('maintenanceStatus', 'derived');
$indexable = true;
}
}
$doc->startElement('maintenanceAgency');
$doc->writeElement('agencyName', 'American Numismatic Society');
$doc->endElement();
//maintenanceHistory
$doc->startElement('maintenanceHistory');
$doc->startElement('maintenanceEvent');
$doc->writeElement('eventType', 'derived');
$doc->startElement('eventDateTime');
$doc->writeAttribute('standardDateTime', date(DATE_W3C));
$doc->text(date(DATE_RFC2822));
$doc->endElement();
$doc->writeElement('agentType', 'machine');
$doc->writeElement('agent', 'PHP');
$doc->writeElement('eventDescription', 'Generated from CSV from ANS Curatorial Google Drive.');
$doc->writeElement('source', $project['types']);
$doc->endElement();
$doc->endElement();
//rightsStmt
$doc->startElement('rightsStmt');
$doc->writeElement('copyrightHolder', 'American Numismatic Society');
$doc->startElement('license');
$doc->writeAttribute('xlink:type', 'simple');
$doc->writeAttribute('xlink:href', 'http://opendatacommons.org/licenses/odbl/');
$doc->endElement();
$doc->endElement();
//semanticDeclaration
$doc->startElement('semanticDeclaration');
$doc->writeElement('prefix', 'dcterms');
$doc->writeElement('namespace', 'http://purl.org/dc/terms/');
$doc->endElement();
$doc->startElement('semanticDeclaration');
$doc->writeElement('prefix', 'nmo');
$doc->writeElement('namespace', 'http://nomisma.org/ontology#');
$doc->endElement();
$doc->startElement('semanticDeclaration');
$doc->writeElement('prefix', 'skos');
$doc->writeElement('namespace', 'http://www.w3.org/2004/02/skos/core#');
$doc->endElement();
//end control
$doc->endElement();
//start descMeta
$doc->startElement('descMeta');
/***** TITLE *****/
$doc->startElement('title');
$doc->writeAttribute('xml:lang', 'en');
if (array_key_exists('Title', $row)){
$doc->text($row['Title']);
} else {
$doc->text(get_title($recordId, $project));
}
$doc->endElement();
/***** NOTES *****/
//look for any column where the first four letters begin with lower-case 'note'
$hasNotes = false;
foreach ($row as $k=>$v){
if (substr(strtolower($k), 0, 4) == 'note' && strlen(trim($v)) > 0){
$hasNotes = true;
}
}
if ($hasNotes == true){
$doc->startElement('noteSet');
foreach ($row as $k=>$v){
if (substr(strtolower($k), 0, 4) == 'note' && strlen(trim($v)) > 0){
$doc->startElement('note');
$doc->writeAttribute('xml:lang', 'en');
$doc->text(trim($v));
$doc->endElement();
}
}
$doc->endElement();
}
/***** SUBJECTS *****/
$hasSubjects = false;
foreach ($row as $k=>$v){
if (substr(strtolower($k), 0, 7) == 'subject' && strlen(trim($v)) > 0){
$hasSubjects= true;
}
}
if ($hasSubjects == true){
$doc->startElement('subjectSet');
foreach ($row as $k=>$v){
if (substr(strtolower($k), 0, 7) == 'subject' && strlen(trim($v)) > 0){
$localType = strlen($k) > 7 ? $k : null;
$vals = explode('|', trim($v));
foreach ($vals as $val){
$val = trim($val);
$doc->startElement('subject');
if (isset($localType)){
$doc->writeAttribute('localType', $localType);
if (preg_match('/^https?:\/\//', $val)){
$uri = $val;
$content = processUri($uri);
$doc->writeAttribute('xlink:type', 'simple');
$doc->writeAttribute('xlink:href', $uri);
$doc->text($content['label']);
} else {
$doc->text($v);
}
}
$doc->endElement();
}
}
}
$doc->endElement();
}
/***** TYPEDESC *****/
$doc->startElement('typeDesc');
//objectType
if (array_key_exists('Object Type URI', $row) && strlen($row['Object Type URI']) > 0){
$vals = explode('|', $row['Object Type URI']);
foreach ($vals as $val){
if (substr($val, -1) == '?'){
$uri = substr($val, 0, -1);
$uncertainty = true;
$content = processUri($uri);
} else {
$uri = $val;
$uncertainty = false;
$content = processUri($uri);
}
$doc->startElement('objectType');
$doc->writeAttribute('xlink:type', 'simple');
$doc->writeAttribute('xlink:href', $uri);
if($uncertainty == true){
$doc->writeAttribute('certainty', 'http://nomisma.org/id/uncertain_value');
}
$doc->text($content['label']);
$doc->endElement();
}
}
//sort dates
if (array_key_exists('From Date', $row) && array_key_exists('To Date', $row)){
//evaluate textual "fuzzy dates" first
if (array_key_exists('Textual Date', $row) && strlen($row['Textual Date']) > 0){
$doc->startElement('date');
if (strlen($row['From Date']) > 0) {
$fromDate = intval(trim($row['From Date']));
$doc->writeAttribute('notBefore', number_pad($fromDate, 4));
}
if (strlen($row['To Date']) > 0){
$toDate = intval(trim($row['To Date']));
$doc->writeAttribute('notAfter', number_pad($toDate, 4));
}
$doc->text(trim($row['Textual Date']));
$doc->endElement();
} else {
//otherwise evaluate just the integer values for dates
if (strlen($row['From Date']) > 0 || strlen($row['To Date']) > 0){
if (($row['From Date'] == $row['To Date']) || (strlen($row['From Date']) > 0 && strlen($row['To Date']) == 0)){
if (is_numeric(trim($row['From Date']))){
$fromDate = intval(trim($row['From Date']));
$doc->startElement('date');
$doc->writeAttribute('standardDate', number_pad($fromDate, 4));
if (array_key_exists('From Date Certainty', $row) && strlen($row['From Date Certainty']) > 0){
$doc->writeAttribute('certainty', 'http://nomisma.org/id/' . $row['From Date Certainty']);
}
$doc->text(get_date_textual($fromDate));
$doc->endElement();
}
} else {
$fromDate = intval(trim($row['From Date']));
$toDate= intval(trim($row['To Date']));
//only write date if both are integers
if (is_int($fromDate) && is_int($toDate)){
$doc->startElement('dateRange');
$doc->startElement('fromDate');
$doc->writeAttribute('standardDate', number_pad($fromDate, 4));
if (array_key_exists('From Date Certainty', $row) && strlen($row['From Date Certainty']) > 0){
$doc->writeAttribute('certainty', 'http://nomisma.org/id/' . $row['From Date Certainty']);
}
$doc->text(get_date_textual($fromDate));
$doc->endElement();
$doc->startElement('toDate');
$doc->writeAttribute('standardDate', number_pad($toDate, 4));
if (array_key_exists('To Date Certainty', $row) && strlen($row['To Date Certainty']) > 0){
$doc->writeAttribute('certainty', 'http://nomisma.org/id/' . $row['To Date Certainty']);
}
$doc->text(get_date_textual($toDate));
$doc->endElement();
$doc->endElement();
}
}
}
}
}
if (array_key_exists('Date on Object', $row) && strlen($row['Date on Object']) > 0){
$doc->startElement('dateOnObject');
$doc->startElement('date');
if (preg_match('/^\d{4}$/', $row['Date on Object'])){
$doc->writeAttribute('standardDate', $row['Date on Object']);
}
$doc->text($row['Date on Object']);
$doc->endElement();
$doc->endElement();
}
if (array_key_exists('Denomination URI', $row) && strlen($row['Denomination URI']) > 0){
$vals = explode('|', $row['Denomination URI']);
foreach ($vals as $val){
if (substr($val, -1) == '?'){
$uri = substr($val, 0, -1);
$uncertainty = true;
$content = processUri($uri);
} else {
$uri = $val;
$uncertainty = false;
$content = processUri($uri);
}
$doc->startElement('denomination');
$doc->writeAttribute('xlink:type', 'simple');
$doc->writeAttribute('xlink:href', $uri);
if($uncertainty == true){
$doc->writeAttribute('certainty', 'http://nomisma.org/id/uncertain_value');
}
$doc->text($content['label']);
$doc->endElement();
}
}
if (array_key_exists('Manufacture URI', $row) && strlen($row['Manufacture URI']) > 0){
$vals = explode('|', $row['Manufacture URI']);
foreach ($vals as $val){
if (substr($val, -1) == '?'){
$uri = substr($val, 0, -1);
$uncertainty = true;
$content = processUri($uri);
} else {
$uri = $val;
$uncertainty = false;
$content = processUri($uri);
}
$doc->startElement('manufacture');
$doc->writeAttribute('xlink:type', 'simple');
$doc->writeAttribute('xlink:href', $uri);
if($uncertainty == true){
$doc->writeAttribute('certainty', 'http://nomisma.org/id/uncertain_value');
}
$doc->text($content['label']);
$doc->endElement();
}
}
if (array_key_exists('Material URI', $row) && strlen($row['Material URI']) > 0){
$vals = explode('|', $row['Material URI']);
foreach ($vals as $val){
if (substr($val, -1) == '?'){
$uri = substr($val, 0, -1);
$uncertainty = true;
$content = processUri($uri);
} else {
$uri = $val;
$uncertainty = false;
$content = processUri($uri);
}
$doc->startElement('material');
$doc->writeAttribute('xlink:type', 'simple');
$doc->writeAttribute('xlink:href', $uri);
if($uncertainty == true){
$doc->writeAttribute('certainty', 'http://nomisma.org/id/uncertain_value');
}
$doc->text($content['label']);
$doc->endElement();
}
}
if (array_key_exists('Shape URI', $row) && strlen($row['Shape URI']) > 0){
$vals = explode('|', $row['Shape URI']);
foreach ($vals as $val){
if (substr($val, -1) == '?'){
$uri = substr($val, 0, -1);
$uncertainty = true;
$content = processUri($uri);
} else {
$uri = $val;
$uncertainty = false;
$content = processUri($uri);
}
$doc->startElement('shape');
$doc->writeAttribute('xlink:type', 'simple');
$doc->writeAttribute('xlink:href', $uri);
if($uncertainty == true){
$doc->writeAttribute('certainty', 'http://nomisma.org/id/uncertain_value');
}
$doc->text($content['label']);
$doc->endElement();
}
}
//authority
if (array_key_exists('Authority URI', $row) || array_key_exists('Stated Authority URI', $row) || array_key_exists('Issuer URI', $row) || array_key_exists('Artist URI', $row) || array_key_exists('Maker URI', $row) || array_key_exists('Authenticity URI', $row)){
$doc->startElement('authority');
if (array_key_exists('Authority URI', $row) && strlen($row['Authority URI']) > 0){
$vals = explode('|', $row['Authority URI']);
foreach ($vals as $val){
if (substr($val, -1) == '?'){
$uri = substr($val, 0, -1);
$uncertainty = true;
$content = processUri($uri);
} else {
$uri = $val;
$uncertainty = false;
$content = processUri($uri);
}
$role = 'authority';
$doc->startElement($content['element']);
$doc->writeAttribute('xlink:type', 'simple');
$doc->writeAttribute('xlink:role', $role);
$doc->writeAttribute('xlink:href', $uri);
if($uncertainty == true){
$doc->writeAttribute('certainty', 'http://nomisma.org/id/uncertain_value');
}
$doc->text($content['label']);
$doc->endElement();
}
}
if (array_key_exists('Stated Authority URI', $row) && strlen($row['Stated Authority URI']) > 0){
$vals = explode('|', $row['Stated Authority URI']);
foreach ($vals as $val){
if (substr($val, -1) == '?'){
$uri = substr($val, 0, -1);
$uncertainty = true;
$content = processUri($uri);
} else {
$uri = $val;
$uncertainty = false;
$content = processUri($uri);
}
$role = 'statedAuthority';
$doc->startElement($content['element']);
$doc->writeAttribute('xlink:type', 'simple');
$doc->writeAttribute('xlink:role', $role);
$doc->writeAttribute('xlink:href', $uri);
if($uncertainty == true){
$doc->writeAttribute('certainty', 'http://nomisma.org/id/uncertain_value');
}
$doc->text($content['label']);
$doc->endElement();
}
}
if (array_key_exists('Issuer URI', $row) && strlen($row['Issuer URI']) > 0){
$vals = explode('|', $row['Issuer URI']);
foreach ($vals as $val){
if (substr($val, -1) == '?'){
$uri = substr($val, 0, -1);
$uncertainty = true;
$content = processUri($uri);
} else {
$uri = $val;
$uncertainty = false;
$content = processUri($uri);
}
$role = 'issuer';
$doc->startElement($content['element']);
$doc->writeAttribute('xlink:type', 'simple');
$doc->writeAttribute('xlink:role', $role);
$doc->writeAttribute('xlink:href', $uri);
if($uncertainty == true){
$doc->writeAttribute('certainty', 'http://nomisma.org/id/uncertain_value');
}
$doc->text($content['label']);
$doc->endElement();
}
}
if (array_key_exists('Artist URI', $row) && strlen($row['Artist URI']) > 0){
$vals = explode('|', $row['Artist URI']);
foreach ($vals as $val){
if (substr($val, -1) == '?'){
$uri = substr($val, 0, -1);
$uncertainty = true;
$content = processUri($uri);
} else {
$uri = $val;
$uncertainty = false;
$content = processUri($uri);
}
$role = 'artist';
$doc->startElement($content['element']);
$doc->writeAttribute('xlink:type', 'simple');
$doc->writeAttribute('xlink:role', $role);
$doc->writeAttribute('xlink:href', $uri);
if($uncertainty == true){
$doc->writeAttribute('certainty', 'http://nomisma.org/id/uncertain_value');
}
$doc->text($content['label']);
$doc->endElement();
}
}
if (array_key_exists('Maker URI', $row) && strlen($row['Maker URI']) > 0){
$vals = explode('|', $row['Maker URI']);
foreach ($vals as $val){
if (substr($val, -1) == '?'){
$uri = substr($val, 0, -1);
$uncertainty = true;
$content = processUri($uri);
} else {
$uri = $val;
$uncertainty = false;
$content = processUri($uri);
}
$role = 'maker';
$doc->startElement($content['element']);
$doc->writeAttribute('xlink:type', 'simple');
$doc->writeAttribute('xlink:role', $role);
$doc->writeAttribute('xlink:href', $uri);
if($uncertainty == true){
$doc->writeAttribute('certainty', 'http://nomisma.org/id/uncertain_value');
}
$doc->text($content['label']);
$doc->endElement();
}
}
if (array_key_exists('Authenticity URI', $row) && strlen($row['Authenticity URI']) > 0){
$vals = explode('|', $row['Authenticity URI']);
foreach ($vals as $val){
if (substr($val, -1) == '?'){
$uri = substr($val, 0, -1);
$uncertainty = true;
$content = processUri($uri);
} else {
$uri = $val;
$uncertainty = false;
$content = processUri($uri);
}
$doc->startElement('authenticity');
$doc->writeAttribute('xlink:type', 'simple');
$doc->writeAttribute('xlink:href', $uri);
if($uncertainty == true){
$doc->writeAttribute('certainty', 'http://nomisma.org/id/uncertain_value');
}
$doc->text($content['label']);
$doc->endElement();
}
}
$doc->endElement();
}
//geography
//mint
if ((array_key_exists('Mint URI', $row) && strlen($row['Mint URI']) > 0) || (array_key_exists('Region URI', $row) && strlen($row['Region URI']) > 0)){
$doc->startElement('geographic');
if (array_key_exists('Mint URI', $row) && strlen($row['Mint URI']) > 0){
$vals = explode('|', $row['Mint URI']);
foreach ($vals as $val){
if (substr($val, -1) == '?'){
$uri = substr($val, 0, -1);
$uncertainty = true;
$content = processUri($uri);
} else {
$uri = $val;
$uncertainty = false;
$content = processUri($uri);
}
$doc->startElement('geogname');
$doc->writeAttribute('xlink:type', 'simple');
$doc->writeAttribute('xlink:role', 'mint');
$doc->writeAttribute('xlink:href', $uri);
if($uncertainty == true){
$doc->writeAttribute('certainty', 'http://nomisma.org/id/uncertain_value');
}
$doc->text($content['label']);
$doc->endElement();
unset($uncertainty);
}
}
if (array_key_exists('Region URI', $row) && strlen($row['Region URI']) > 0){
$vals = explode('|', $row['Region URI']);
foreach ($vals as $val){
if (substr($val, -1) == '?'){
$uri = substr($val, 0, -1);
$uncertainty = true;
$content = processUri($uri);
} else {
$uri = $val;
$uncertainty = false;
$content = processUri($uri);
}
$doc->startElement('geogname');
$doc->writeAttribute('xlink:type', 'simple');
$doc->writeAttribute('xlink:role', 'region');
$doc->writeAttribute('xlink:href', $uri);
if($uncertainty == true){
$doc->writeAttribute('certainty', 'http://nomisma.org/id/uncertain_value');
}
$doc->text($content['label']);
$doc->endElement();
unset($uncertainty);
}
}
$doc->endElement();
}
//obverse
if (array_key_exists('Obverse Type Code', $row) || array_key_exists('Obverse Legend', $row) || array_key_exists('Obverse Portrait URI', $row) || array_key_exists('Obverse Deity URI', $row)) {
$doc->startElement('obverse');
//legend
render_legend($doc, $row, 'Obverse');
//multilingual type descriptions
if (array_key_exists('Obverse Type Code', $row) && strlen($row['Obverse Type Code']) > 0) {
$key = $row['Obverse Type Code'];
$doc->startElement('type');
foreach ($obverses as $desc){
if ($desc['code'] == $key){
foreach ($desc as $k=>$v){
if ($k != 'code'){
if (strlen($v) > 0){
$doc->startElement('description');
$doc->writeAttribute('xml:lang', $k);
$doc->text(trim($v));
$doc->endElement();
}
}
}
break;
}
}
$doc->endElement();
}
//try single obverse symbol column first before looking for O: columns
if (array_key_exists('Obverse Symbol', $row) && strlen($row['Obverse Symbol']) > 0){
$doc->startElement('symbol');
parse_symbol($doc, trim($row['Obverse Symbol']));
$doc->endElement();
} else {
//symbols
foreach ($row as $k=>$v){
//reverse symbols are preceded with R:
if (substr($k, 0, 2) == 'O:'){
if (strlen(trim($v)) > 0){
$position = trim(str_replace('O:', '', $k));
$position = strpos($position, '_') !== FALSE ? substr($position, 0, strpos($position, '_')) : $position;
$doc->startElement('symbol');
//differentiate before positions and semantic types
if ($position == 'officinaMark' || $position == 'mintMark'){
$doc->writeAttribute('localType', $position);
} else {
$doc->writeAttribute('position', $position);
}
parse_symbol($doc, trim($v));
$doc->endElement();
}
}
}
}
//deity
if (array_key_exists('Obverse Deity URI', $row) && strlen($row['Obverse Deity URI']) > 0){
$vals = explode('|', $row['Obverse Deity URI']);
foreach ($vals as $val){
$val = trim($val);
if (substr($val, -1) == '?'){
$uri = substr($val, 0, -1);
$uncertainty = true;
$content = processUri($uri);
} else {
$uri = $val;
$uncertainty = false;
$content = processUri($uri);
}
$doc->startElement($content['element']);
$doc->writeAttribute('xlink:type', 'simple');
$doc->writeAttribute('xlink:role', 'deity');
$doc->writeAttribute('xlink:href', $uri);
if($uncertainty == true){
$doc->writeAttribute('certainty', 'http://nomisma.org/id/uncertain_value');
}
$doc->text($content['label']);
$doc->endElement();
}
}
//portrait
if (array_key_exists('Obverse Portrait URI', $row) && strlen($row['Obverse Portrait URI']) > 0){
$vals = explode('|', $row['Obverse Portrait URI']);
foreach ($vals as $val){
if (substr($val, -1) == '?'){
$uri = substr($val, 0, -1);
$uncertainty = true;
$content = processUri($uri);
} else {
$uri = $val;
$uncertainty = false;
$content = processUri($uri);
}
$role = 'portrait';
$doc->startElement('persname');
$doc->writeAttribute('xlink:type', 'simple');
$doc->writeAttribute('xlink:role', $role);
$doc->writeAttribute('xlink:href', $uri);
if($uncertainty == true){
$doc->writeAttribute('certainty', 'http://nomisma.org/id/uncertain_value');
}
$doc->text($content['label']);
$doc->endElement();
}
}
//end obverse
$doc->endElement();
}
//reverse
if (array_key_exists('Reverse Type Code', $row) || array_key_exists('Reverse Legend', $row) || array_key_exists('Reverse Portrait URI', $row) || array_key_exists('Reverse Deity URI', $row)) {
$doc->startElement('reverse');
//legend
render_legend($doc, $row, 'Reverse');
//multilingual type descriptions
if (array_key_exists('Reverse Type Code', $row) && strlen($row['Reverse Type Code']) > 0) {
$key = $row['Reverse Type Code'];
$doc->startElement('type');
foreach ($reverses as $desc){
if ($desc['code'] == $key){
foreach ($desc as $k=>$v){
if ($k != 'code'){
if (strlen($v) > 0){
$doc->startElement('description');
$doc->writeAttribute('xml:lang', $k);
$doc->text(trim($v));
$doc->endElement();
}
}
}
break;
}
}
$doc->endElement();
}
//portrait
if (array_key_exists('Reverse Portrait URI', $row) && strlen($row['Reverse Portrait URI']) > 0){
$vals = explode('|', $row['Reverse Portrait URI']);
foreach ($vals as $val){
if (substr($val, -1) == '?'){
$uri = substr($val, 0, -1);
$uncertainty = true;
$content = processUri($uri);
} else {
$uri = $val;
$uncertainty = false;
$content = processUri($uri);
}
$role = 'portrait';
$doc->startElement('persname');
$doc->writeAttribute('xlink:type', 'simple');
$doc->writeAttribute('xlink:role', $role);
$doc->writeAttribute('xlink:href', $uri);
if($uncertainty == true){
$doc->writeAttribute('certainty', 'http://nomisma.org/id/uncertain_value');
}
$doc->text($content['label']);
$doc->endElement();
}
}
//deity
if (array_key_exists('Reverse Deity URI', $row) && strlen($row['Reverse Deity URI']) > 0){
$vals = explode('|', $row['Reverse Deity URI']);
foreach ($vals as $val){
$val = trim($val);
if (substr($val, -1) == '?'){
$uri = substr($val, 0, -1);
$uncertainty = true;
$content = processUri($uri);
} else {
$uri = $val;
$uncertainty = false;
$content = processUri($uri);
}
$doc->startElement($content['element']);
$doc->writeAttribute('xlink:type', 'simple');
$doc->writeAttribute('xlink:role', 'deity');
$doc->writeAttribute('xlink:href', $uri);
if($uncertainty == true){
$doc->writeAttribute('certainty', 'http://nomisma.org/id/uncertain_value');
}
$doc->text($content['label']);
$doc->endElement();
}
}
//symbols
foreach ($row as $k=>$v){
//reverse symbols are preceded with R:
if (substr($k, 0, 2) == 'R:'){
if (strlen(trim($v)) > 0){
$position = trim(str_replace('R:', '', $k));
$position = strpos($position, '_') !== FALSE ? substr($position, 0, strpos($position, '_')) : $position;
$doc->startElement('symbol');
//differentiate before positions and semantic types
if ($position == 'officinaMark' || $position == 'mintMark' || $position == 'controlMark'){
$doc->writeAttribute('localType', $position);
} else {
$doc->writeAttribute('position', $position);
}
parse_symbol($doc, trim($v));
$doc->endElement();
}
}
}
//end reverse
$doc->endElement();
}
//Explicit Type Series
if (array_key_exists('Type Series URI', $row) && strlen(trim($row['Type Series URI'])) > 0){
$uri = $row['Type Series URI'];
$content = processUri($uri);
$doc->startElement('typeSeries');
$doc->writeAttribute('xlink:type', 'simple');
$doc->writeAttribute('xlink:href', $uri);
$doc->text($content['label']);
$doc->endElement();
}
//end typeDesc
$doc->endElement();
/***** REFDESC *****/
//evaluate any column beginning with the string 'Reference'
$references = array();
foreach ($row as $k=>$v){
if (strpos($k, 'Reference') === 0){
if (preg_match('/^Reference\s\((.*)\)$/', $k, $matches)){
$ref = trim($v);
if (strlen($ref) > 0 && isset($matches[1])) {
$references[] = array('refCode'=>$matches[1], 'value'=>$ref);
}
} else {
$ref = trim($v);
if (strlen($ref) > 0) {
$references[] = array('value'=>$v);
}
}
}
}
//create references to previous volumes
if ((array_key_exists('Deprecated ID', $row) && strlen($row['Deprecated ID']) > 0) || (array_key_exists('Matching URI', $row) && strlen($row['Matching URI']) > 0) || count($references) > 0){
$doc->startElement('refDesc');
if (array_key_exists('Deprecated ID', $row) && strlen($row['Deprecated ID']) > 0){
$replaces = explode('|', $row['Deprecated ID']);
foreach ($replaces as $deprecatedID){
$deprecatedID = trim($deprecatedID);
$doc->startElement('reference');
$doc->writeAttribute('xlink:type', 'simple');
$doc->writeAttribute('xlink:href', $uri_space . $deprecatedID);
$doc->text(get_title($deprecatedID, $project));
$doc->endElement();
}
}
if (array_key_exists('Matching URI', $row) && strlen($row['Matching URI']) > 0){
$matches = explode('|', $row['Matching URI']);
foreach ($matches as $uri){
$uri = trim($uri);
//get title via RDF
$content = processUri($uri);
$doc->startElement('reference');
$doc->writeAttribute('xlink:type', 'simple');
$doc->writeAttribute('xlink:href', $uri);
$doc->text($content['label']);
$doc->endElement();
}
}
//parse text-based, not URI references, linking them to Nomisma IDs for type series, if applicable
foreach ($references as $reference) {
$doc->startElement('reference');
if (array_key_exists('refCode', $reference)) {
$refMetadata = parse_refCode($reference['refCode']);
//if the reference code returns an array of metadata, then generate TEI, otherwise output the text of the column value
if (isset($refMetadata)){
$doc->startElement('tei:title');
if (array_key_exists('typeSeries', $refMetadata)){
$doc->writeAttribute('key', $refMetadata['typeSeries']);
}
$doc->text($refMetadata['title']);
$doc->endElement();
$doc->startElement('tei:idno');
$doc->text($reference['value']);
$doc->endElement();
} else {
$doc->text($reference['value']);
}
} else {
$doc->text($reference['value']);
}