Generate report about FRUS publication status & output formats
xquery version "3.1";
(: Generate report about FRUS publication status & output formats
: Assumes full installation of https://github.com/HistoryAtState/hsg-project and cached s3 resources (not public)
:)
import module namespace config="http://history.state.gov/ns/site/hsg/config" at "xmldb:exist:///db/apps/hsg-shell/modules/config.xqm";
import module namespace fh="http://history.state.gov/ns/site/hsg/frus-html" at "xmldb:exist:///db/apps/hsg-shell/modules/frus-html.xqm";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare function local:tsv($column-headings, $rows as array(*)*) {
let $cell-separator := '	' (: tab :)
let $row-separator := ' ' (: newline :)
let $heading-row := string-join($column-headings, $cell-separator)
let $body-rows :=
for $row in $rows
return
string-join($row?*, $cell-separator)
let $all-rows := ($heading-row, $body-rows)
let $tsv := string-join($all-rows, $row-separator)
return
$tsv
};
let $rows :=
let $volumes := collection($config:FRUS_METADATA_COL)/volume
for $volume in $volumes
let $volume-id := $volume/@id
let $full-text := if (fh:exists-volume-in-db($volume-id)) then 1 else 0
let $ebook := if (fh:exists-ebook($volume-id)) then 1 else 0
let $pdf := if (fh:exists-pdf($volume-id)) then 1 else 0
let $document-ids := doc($config:FRUS_VOLUMES_COL || "/" || $volume-id || ".xml")//tei:div[@type="document"]/@xml:id
let $per-document-pdf := $document-ids[fh:exists-pdf($volume-id, .)]
let $pdf-document-pdf-summary := if (exists($per-document-pdf)) then 1 else 0
let $publication-status := $volume/publication-status
let $publication-status-label := doc($config:FRUS_CODE_TABLES_COL || '/publication-status-codes.xml')//item[value = $publication-status]/label/string()
order by $volume-id
return
array { $volume-id, $publication-status-label, $full-text, $ebook, $pdf, $pdf-document-pdf-summary }
let $column-labels := ('Volume ID', 'Publication Status', 'Full Text TEI XML', 'Ebook', 'Whole Volume PDF', 'Per-Document PDF')
let $tsv := local:tsv($column-labels, $rows)
return
file:serialize-binary(util:string-to-binary($tsv), 'file:/Users/joe/Desktop/volumes.tsv')