-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupdate-cbss-browse-links-in-persons-and-places.xq
More file actions
124 lines (100 loc) · 4.19 KB
/
update-cbss-browse-links-in-persons-and-places.xq
File metadata and controls
124 lines (100 loc) · 4.19 KB
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
(:
: Given an input CSV and a directory of TEI files,
: inserts editor, respStmt, and/or change log messages
: for work done based on the file name and editor info
: supplied in the CSV
:
:
:)
(:
BASEX OPTIONS (pre v.10, whitespace handling has since changed):
- set writeback true
- set chop off
- set exporter omit-xml-declaration=no
:)
import module namespace functx="http://www.functx.com";
declare default element namespace "http://www.tei-c.org/ns/1.0";
declare option output:omit-xml-declaration "no";
declare variable $path-to-repo := "/home/arren/Documents/GitHub/syriaca-data";
declare variable $collections :=
map {
"persons": collection($path-to-repo||"/data/persons/tei/"),
"places": collection($path-to-repo||"/data/places/tei/")
};
declare variable $xpaths :=
map {
"persons": map {
"idnos": "TEI/text/body/listPerson/person/idno",
"bibls": "TEI/text/body/listPerson/person/bibl"
},
"places": map {
"idnos": "TEI/text/body/listPlace/place/idno",
"bibls": "TEI/text/body/listPlace/place/bibl"
}
};
declare variable $cbss-zotero-tag-uri-base := "https://www.zotero.org/groups/4861694/tags/";
declare variable $cbss-zotero-tag-uri-postfix := "/library";
declare variable $cbss-syriaca-browse-facet-url-base := "https://dev.syriaca.org/cbss/search.html?facet-cbssKeywords=";
declare function local:update-cbsc-idno($idnos as element()+, $uriPrefix as xs:string?, $uriPostfix as xs:string?)
as element() + {
for $id in $idnos
let $newUri := local:update-cbsc-uri($id/text(), $uriPrefix, $uriPostfix)
return element {node-name($id)} {$id/@*, $newUri}
};
declare function local:update-cbsc-bibl($bibls as element()+, $uriPrefix as xs:string?, $uriPostfix as xs:string?)
as element() + {
for $bib in $bibls
return element {node-name($bib)} {
$bib/@*,
$bib/title,
$bib/ptr,
for $cRange in $bib/citedRange
return
if($cRange[@unit="entry"]) then
let $newUri := local:update-cbsc-uri($cRange/@target/string(), $uriPrefix, $uriPostfix)
return
element {node-name($cRange)} {
$cRange/@unit,
attribute {"target"} {$newUri},
$cRange/text()
}
else $cRange
}
};
(:
Format of an old URI: http://www.csc.org.il/db/browse.aspx?db=SB&sL=T&sK=Theodore bar Zarudi&sT=keywords
Extracts the keyword (beetween '&sK=' and the following '&')
Adds the prefix and postfix for the new uri
:)
declare function local:update-cbsc-uri($oldUri as xs:string?, $newUriPrefix as xs:string?, $newUriPostfix as xs:string?)
as xs:string
{
if($oldUri = "") then ()
else
let $newUri := $oldUri
=> normalize-space()
=> substring-after("&sK=")
=> substring-before("&")
return $newUriPrefix||$newUri||$newUriPostfix
};
(:~ ~~~~~~~~~~~~~~~~ ~:)
(: OPTION TO RUN ON PERSONS OR PLACES
Value must be either the string "persons" or "places"
:)
let $personOrPlace := "persons"
for $doc in $collections($personOrPlace)
where contains($doc, "csc.org")
(: let $idnos := functx:dynamic-path($doc, $xpaths($personOrPlace)("idnos"))
let $oldCbscIdnos := $idnos[contains(text(), "csc.org")]
let $newCbssZoteroTagIdnos := local:update-cbsc-idno($oldCbscIdnos, $cbss-zotero-tag-uri-base, $cbss-zotero-tag-uri-postfix)
let $newCbssFacetedBrowseIdnos := local:update-cbsc-idno($oldCbscIdnos, $cbss-syriaca-browse-facet-url-base, ())
let $bibls := functx:dynamic-path($doc, $xpaths($personOrPlace)("bibls"))
let $oldCbscBibls := $bibls[ptr[@target="http://syriaca.org/bibl/5"]]
let $newCbssZoteroTagBibls := local:update-cbsc-bibl($oldCbscBibls, $cbss-zotero-tag-uri-base, $cbss-zotero-tag-uri-postfix)
let $newCbssFacetedBrowseBibls := local:update-cbsc-bibl($oldCbscBibls, $cbss-syriaca-browse-facet-url-base, ()) :)
return (
for $idno in functx:dynamic-path($doc, $xpaths($personOrPlace)("idnos"))[contains(text(), "csc.org")]
return replace node $idno with local:update-cbsc-idno($idno, $cbss-zotero-tag-uri-base, $cbss-zotero-tag-uri-postfix),
for $bibl in functx:dynamic-path($doc, $xpaths($personOrPlace)("bibls"))[ptr[@target="http://syriaca.org/bibl/5"]]
return replace node $bibl with local:update-cbsc-bibl($bibl, $cbss-zotero-tag-uri-base, $cbss-zotero-tag-uri-postfix)
)