Commit a3c5066e authored by Mathias Goebel's avatar Mathias Goebel 🎠
Browse files

Merge branch 'release/4.7.0'

parents 1197fa06 b0140ce1
project.name=http://textgrid.de/ns/SADE-fontane-develop
project.version=4.6.0
project.version=4.7.0
project.title=[Fontane] SADE
project.abbrev=SADE-fontane-develop
project.processorversion=4.7.0
......
xquery version "3.1";
(:~
: This module is responsible for getting an XML version of the abbreviations
: index which can be converted to TeX. This XML version is appended to
: fontane-full.xml during the creation of the intermediate format in etTransfo.xmq.
:
: @author Michelle Weidling
: @version 0.1
: @since v4.0.
:)
module namespace abbrev-index="http://fontane-nb.dariah.eu/abbrev-index";
import module namespace config="http://textgrid.de/ns/SADE/config" at "../../config/config.xqm";
declare namespace map = "http://www.w3.org/2005/xpath-functions/map";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace xhtml="http://www.w3.org/1999/xhtml";
declare function abbrev-index:main() as element(tei:div) {
let $docs-coll := collection("/db/sade-projects/textgrid/data/xml/doku/")
let $file := $docs-coll[matches(base-uri(.), "verzeichnis_der_abkuerzungen")]/*
let $transformed :=
abbrev-index:transform($file)
=> abbrev-index:tidy()
return
element tei:div {
attribute type {"abbrev-index"},
$transformed
}
};
(:~
: Handles the transformation from XHTML to XML.
:
: @param $nodes The nodes currently processed
: @return The transformed nodes
:)
declare function abbrev-index:transform($nodes as node()*) as node()* {
for $node in $nodes return
typeswitch ($node)
case text() return
if(matches($node, "important")
or matches($node, "Gesamtdokumentation")) then
()
else
text {
replace($node, "ſ", "s")
=> replace("m̄", "mm")
=> replace("n̄", "nn")
}
case element(xhtml:h2) return
()
case element(xhtml:h3) return
element tei:head {
attribute type {"table-head"},
abbrev-index:transform($node/node())
}
case element(xhtml:tr) return
element tei:row {
if($node/ancestor::xhtml:thead
or $node/child::xhtml:th) then
attribute role {"head"}
else
(),
abbrev-index:transform($node/node())
}
case element(xhtml:td) return
element tei:cell {
abbrev-index:transform($node/node())
}
case element(xhtml:th) return
element tei:cell {
abbrev-index:transform($node/node())
}
case element(xhtml:thead) return
abbrev-index:transform($node/node())
case element(xhtml:br) return
element tei:lb {
abbrev-index:transform($node/node())
}
case element(xhtml:i) return
()
case element(xhtml:a) return
if($node/text()) then
abbrev-index:transform($node/node())
else
()
case element(xhtml:span) return
abbrev-index:transform($node/node())
default return
element {QName("http://www.tei-c.org/ns/1.0", $node/local-name())} {
abbrev-index:transform($node/node())
}
};
(:~
: Removes empty elements.
:
: @param $nodes The nodes currently processed
: @return The transformed nodes
:)
declare function abbrev-index:tidy($nodes as node()*) as node()* {
for $node in $nodes return
typeswitch ($node)
case text() return
$node
default return
if($node//text()[matches(., "[\w\d]") and not(normalize-space(.) = "")]
or $node[self::tei:lb]) then
element {QName("http://www.tei-c.org/ns/1.0", $node/local-name())} {
$node/@*,
abbrev-index:tidy($node/node())
}
else
()
};
......@@ -16,10 +16,12 @@ module namespace etTransfo="http://fontane-nb.dariah.eu/etTransfo";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace xi="http://www.w3.org/2001/XInclude";
import module namespace abbrev-index="http://fontane-nb.dariah.eu/abbrev-index" at "abbrev-index.xqm";
import module namespace config="http://textgrid.de/ns/SADE/config" at "../../config/config.xqm";
import module namespace fontaneSimple="http://fontane-nb.dariah.eu/teisimple" at "tei2teisimple.xqm";
import module namespace fsort="http://fontane-nb.dariah.eu/sort" at "sort.xqm";
import module namespace functx = "http://www.functx.com";
import module namespace macro-sort="http://fontane-nb.dariah.eu/macro-sort" at "macro-sort.xqm";
import module namespace prepCom="http://fontane-nb.dariah.eu/prepCom" at "prepcom.xqm";
import module namespace presort="http://fontane-nb.dariah.eu/presort" at "presort.xqm";
import module namespace simple2xhtml="http://fontane-nb.dariah.eu/simple2xhtml" at "simple2xhtml.xqm";
......@@ -27,13 +29,15 @@ import module namespace tidySimple ="http://fontane-nb.dariah.eu/tidysimple" at
declare variable $etTransfo:cases :=
(
"3qtcz.xml", (: case C :)
(: "3qtcz.xml", (: case C :):)
"3qtqv.xml" (: case A :)
(: "3qtqw.xml" (: case B :) :)
(: "3qtqx.xml" (: case D :):)
(: "3qtqz.xml" (: case E :):)
);
declare variable $etTransfo:dir := "/db/apps/SADE/modules/fontane/edited-text/";
(:~
: The main function
......@@ -51,18 +55,11 @@ declare function etTransfo:complete() {
etTransfo:create-print-tei()
} catch * {
error(QName("error", "ETTRANSFO02"), "An error occured while creating the whole TEI base for print.")
}
},
etTransfo:tidy-logs()
};
declare function etTransfo:transform-on-publish($notebook) {
try {
etTransfo:transform-tei($notebook//tei:TEI)
} catch * {
error(QName("error", "ETTRANSFO05"), "Could not transform " || $notebook//tei:title[1]/string() || " to XHTML.")
}
};
(:~
: Resolves all XIncludes in a given case file and copies all notebooks belonging to a case into one file.
:
......@@ -99,11 +96,11 @@ declare function etTransfo:create-case($showcase as xs:string) as xs:string {
error(QName("error", "ETTRANSFO04"), "Couldn't find the node tei:TEI of " || $uri || ".")
}
let $updated-notebook :=
element {QName("http://www.tei-c.org/ns/1.0", "TEI")} {
attribute id {$uri},
$tei-referred-to/@*,
$tei-referred-to/*
}
element tei:TEI {
attribute id {$uri},
$tei-referred-to/@*,
$tei-referred-to/*
}
return update replace $xi with $updated-notebook
return
......@@ -144,20 +141,32 @@ declare function etTransfo:create-htmls($showcase as xs:string) as xs:string+ {
let $teis := etTransfo:get-teis($showcase)
for $tei in $teis return
etTransfo:transform-tei($tei)
let $log := etTransfo:create-log(substring-after($tei//tei:idno[@type = "TextGrid"], "textgrid:"))
return
etTransfo:transform-tei($tei, $log)
};
declare function etTransfo:transform-tei($tei as element(tei:TEI)) {
fsort:main($tei)
(:~
: Handles the transformation to the intermediate format and the XHTML
: representation.
:
: @param $tei The current notebook as element(tei:TEI)
:)
declare function etTransfo:transform-tei($tei as element(tei:TEI), $log as xs:string) {
(: macro-sort:main($tei, $tei/@id):)
(: => fsort:main():)
fsort:main($tei, $log)
=> prepCom:main($tei/@id)
=> fontaneSimple:main($tei/@id)
=> fontaneSimple:main($tei/@id, $log)
=> tidySimple:main($tei/@id)
(: => simple2xhtml:main($tei/@id):)
=> simple2xhtml:main($tei/@id)
};
(:~
: Assembles the intermediate format version of each notebook and copies them into one file called "fontane-full.xml".
: Furthermore, additional data needed for the print is appended.
:
: @author Michelle Weidling
: @return A string indicating the location where the full TEI/XML of the edition was stored to.
......@@ -171,6 +180,12 @@ declare function etTransfo:create-print-tei() as xs:string {
etTransfo:get-literature()
} catch * {
error(QName("error", "ETTRANSFO06"), "An error occured while creating the bibliography.")
},
try {
abbrev-index:main()
} catch * {
error(QName("error", "ETTRANSFO07"), "An error occured while creating the index of abbreviations.")
}
}
return
......@@ -183,16 +198,10 @@ declare function etTransfo:create-print-tei() as xs:string {
: @author Michelle Weidling
: @return All available final intermediate format TEI/XML files as opened documents
:)
declare function etTransfo:get-all-xmls() {
declare function etTransfo:get-all-xmls() as node()+ {
for $res in collection($config:data-root || "/print/xml/")
[contains(base-uri(.), ".xml")
and not(contains(base-uri(.), "tmp"))
and not(contains(base-uri(.), "presort"))
and not(contains(base-uri(.), "prepared"))
and not(contains(base-uri(.), "prepcom"))
and not(contains(base-uri(.), "fontane"))
and not(contains(base-uri(.), "all-headers"))
and not(contains(base-uri(.), "Kasten"))]
and not(contains(substring-after(base-uri(.), "/print/xml/"), "-"))]
order by $res/tei:TEI/@key1, number($res/tei:TEI/@key2)
return
$res
......@@ -210,52 +219,38 @@ declare function etTransfo:get-literature() as element(tei:div) {
element {QName("http://www.tei-c.org/ns/1.0", "text")} {
attribute type {"bibliography"},
element {QName("http://www.tei-c.org/ns/1.0", "div")} {
element tei:div {
attribute n {"Fontanes_Werke"},
element {QName("http://www.tei-c.org/ns/1.0", "div")} {
attribute n {"Erstausgaben"},
etTransfo:make-bib-entries("Erstausgaben")
},
element {QName("http://www.tei-c.org/ns/1.0", "div")} {
attribute n {"Werkausgaben"},
etTransfo:make-bib-entries("Werkausgaben")
},
element {QName("http://www.tei-c.org/ns/1.0", "div")} {
attribute n {"Briefausgaben"},
etTransfo:make-bib-entries("Briefausgaben")
},
element {QName("http://www.tei-c.org/ns/1.0", "div")} {
attribute n {"Postume_Einzelausgaben"},
etTransfo:make-bib-entries("Postume_Einzelausgaben")
},
element {QName("http://www.tei-c.org/ns/1.0", "div")} {
attribute n {"Populaere_postume_Einzelausgaben"},
etTransfo:make-bib-entries("Populaere_postume_Einzelausgaben")
}
},
element {QName("http://www.tei-c.org/ns/1.0", "div")} {
attribute n {"Fontanes_Quellen"},
etTransfo:make-bib-entries("Fontanes_Quellen")
},
element {QName("http://www.tei-c.org/ns/1.0", "div")} {
attribute n {"Allgemeine_Nachschlagewerke"},
etTransfo:make-bib-entries("Allgemeine_Nachschlagewerke")
local:make-bib-div("Erstausgaben"),
local:make-bib-div("Werkausgaben"),
local:make-bib-div("Briefausgaben"),
local:make-bib-div("Postume_Einzelausgaben"),
local:make-bib-div("Populaere_postume_Einzelausgaben")
},
local:make-bib-div("Fontanes_Quellen"),
local:make-bib-div("Allgemeine_Nachschlagewerke"),
local:make-bib-div("Nachschlagewerke_der_Fontane-Forschung"),
local:make-bib-div("Forschungsliteratur")
}
};
element {QName("http://www.tei-c.org/ns/1.0", "div")} {
attribute n {"Nachschlagewerke_der_Fontane-Forschung"},
etTransfo:make-bib-entries("Nachschlagewerke_der_Fontane-Forschung")
},
element {QName("http://www.tei-c.org/ns/1.0", "div")} {
attribute n {"Forschungsliteratur"},
etTransfo:make-bib-entries("Forschungsliteratur")
}
(:~
: An auxiliary function to create the tei:div elements in the bibliography.
:
: @author Michelle Weidling
: @param $identifier An identifier for a subtype of scholarly literature
: @return a tei:div containing all bibliographic information of the literatur's subtype
:)
declare function local:make-bib-div($identifier as xs:string) as element(tei:div) {
element tei:div {
attribute n {$identifier},
etTransfo:make-bib-entries($identifier)
}
};
(:~
: Creates a div containing all the scholarly literature ("Forschungsliteratur")
: of a kind that's listed in the respective index. Examples for this are
......@@ -277,14 +272,14 @@ declare function etTransfo:make-bib-entries($type as xs:string) as element(tei:d
let $bib-no := count($entry/ancestor::tei:bibl)
return
element {QName("http://www.tei-c.org/ns/1.0", "div")} {
element tei:div {
attribute type {"entry"},
element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
element tei:seg {
attribute type {"abbr"},
$abbr
},
if($full-ref) then
element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
element tei:seg {
attribute type {"full"},
$full-ref
}
......@@ -296,11 +291,11 @@ declare function etTransfo:make-bib-entries($type as xs:string) as element(tei:d
let $same-as-loc := $referenced-entry/ancestor::tei:listBibl[1]/@type/string()
return
(element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
(element tei:seg {
attribute type {"same-as"},
$same-as
},
element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
element tei:seg {
attribute type {"same-as-loc"},
$same-as-loc
})
......@@ -308,7 +303,7 @@ declare function etTransfo:make-bib-entries($type as xs:string) as element(tei:d
else
(),
if($bib-no gt 0) then
element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
element tei:seg {
attribute type {"sub-entry"},
$bib-no
}
......@@ -316,3 +311,34 @@ declare function etTransfo:make-bib-entries($type as xs:string) as element(tei:d
()
}
};
declare function etTransfo:create-log($uri as xs:string) as xs:string {
let $assure-dir-available := etTransfo:assure-dir-available("logs")
let $log-name := $uri || "-log.xml"
return xmldb:store($etTransfo:dir || "logs", $log-name, <log/>)
};
declare function etTransfo:assure-dir-available($dir-name as xs:string) {
if(xmldb:collection-available($etTransfo:dir || "logs")) then
$etTransfo:dir || "logs"
else
xmldb:create-collection($etTransfo:dir, "logs")
};
(:~
: Only the logs which acutally contain info should be kept.
:
:)
declare function etTransfo:tidy-logs() {
for $log in collection($etTransfo:dir || "logs/") return
if($log//LogEntry) then
()
else
let $uri := substring-after(base-uri($log), "logs/")
return
xmldb:remove($etTransfo:dir || "logs/", $uri)
};
......@@ -49,7 +49,7 @@ declare variable $index-info:place-map :=
declare variable $index-info:psn-map :=
map:merge(for $entry in doc($config:data-root ||"/data/253sx.xml")//*[self::tei:person or self::tei:personGrp]
let $same-as := $entry/ancestor::tei:listPerson//tei:person[not(@xml:id)][descendant::tei:ptr[contains(@target, $entry/@xml:id)]]/tei:persName
let $same-as := $entry/ancestor::tei:listPerson//tei:person[not(@xml:id)][descendant::tei:ptr[@target = concat("#", $entry/@xml:id)]]/tei:persName
return
map:entry(string($entry/@xml:id),
......@@ -85,50 +85,54 @@ declare variable $index-info:wrk-map :=
else
"false"
let $same-as :=
if($periodical) then
$entry/ancestor::tei:list[@type = "periodicals"]//tei:item[not(@xml:id)][descendant::tei:ptr[@target = concat("#", $entry/@xml:id)]]/tei:name
else
()
let $same-as :=
if(count($same-as) gt 1) then
string-join($same-as/string(), ", ")
else if(count($same-as) = 1) then
$same-as/string()
else
()
let $general-map :=
map {
"regular-name" : string-join($entry/tei:name[not(@type)], ", "),
"periodical" : $is-periodical,
"type" : "work"
}
return
if($creators and $periodical) then
map:entry(string($entry/@xml:id),
map {
"regular-name" : string-join($entry/tei:name[not(@type)], ", "),
"creator-ids" : string-join($creator-ids, " "),
"periodical" : $is-periodical,
"type" : "work"
}
)
else if($creators) then
map:entry(string($entry/@xml:id),
map {
"regular-name" : string-join($entry/tei:name[not(@type)], ", "),
"creator-ids" : string-join($creator-ids, " "),
"periodical" : $is-periodical,
"type" : "work"
}
)
if($creators and $periodical
or $creators) then
let $updated-map := map:put($general-map, "creator-ids", string-join($creator-ids, " "))
return
map:entry(string($entry/@xml:id),
if($same-as) then
map:put($updated-map, "same-as", $same-as)
else
$updated-map
)
else if($created-by-fontane) then
map:entry(string($entry/@xml:id),
map {
"regular-name" : string-join($entry/tei:name[not(@type)], ", "),
"creator" : "Fontane",
"periodical" : $is-periodical,
"type" : "work"
}
map:put($general-map, "creator", "Fontane")
)
else if($periodical) then
map:entry(string($entry/@xml:id),
map {
"regular-name" : string-join($entry/tei:name[not(@type)], ", "),
"periodical" : $is-periodical,
"type" : "work"
}
if($same-as) then
map:put($general-map, "same-as", $same-as)
else
$general-map
)
else
map:entry(string($entry/@xml:id),
map {
"regular-name" : string-join($entry/tei:name[not(@type)], ", "),
"creator" : "Anonym/nicht ermittelt",
"periodical" : $is-periodical,
"type" : "work"
}
map:put($general-map, "creator", "Anonym/nicht ermittelt")
),
(: (fictional) characters mentioned/depicted in works :)
for $person in doc($config:data-root || "/data/253t3.xml")//tei:person
......
xquery version "3.1";
module namespace macro-sort="http://fontane-nb.dariah.eu/macro-sort";
import module namespace config="http://textgrid.de/ns/SADE/config" at "../../config/config.xqm";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace xi="http://www.w3.org/2001/XInclude";
declare function macro-sort:main($tei as node()*, $uri as xs:string) as node()* {
let $header := $tei//tei:teiHeader
let $sorted := macro-sort:sort($tei//tei:sourceDoc)
(: let $cleared := macro-sort:clear($sorted):)
let $cleared := $sorted
let $final-tei :=
element tei:TEI {
$header,
$cleared
}
let $store := xmldb:store($config:data-root || "/print/xml/", $uri || "-macrosort.xml", $final-tei)
return
$final-tei
};
declare function macro-sort:sort($nodes as node()*) as node()* {
for $node in $nodes return
typeswitch ($node)
case text() return
$node
case comment() return
$node
case element(tei:milestone) return
if($node/@unit = "section") then
let $end-point-id := replace($node/@spanTo, "#", "")
let $end-point := $node/root()//tei:anchor[@xml:id = $end-point-id]
let $number := substring-after($node/@type, "Text_")
let $handshift := $node/preceding::tei:milestone[@unit = "handshift"][1]
return
element tei:div {
attribute n {$number},
(: $node/(@* except @spanTo),:)
$node/@*,
$handshift,
(: all nodes on the current surface :)
$node/following-sibling::node()[. << $end-point],
$node/../following-sibling::node()[. << $end-point],
(: all complete surfaces before the anchor :)
$node/ancestor::tei:surface/following-sibling::tei:surface[. << $end-point],
(: all elements on the surface that contains the anchor which are before the anchor :)
$node/ancestor::tei:surface/following-sibling::tei:surface[descendant::tei:anchor[@xml:id = $end-point-id]]//tei:anchor[@xml:id = $end-point-id]/preceding-sibling::*
}
else
macro-sort:copy-element($node)
default return
let $section-marker := $node/preceding::tei:milestone[@unit = "section"][1]
let $end-point-id := replace($section-marker/@spanTo, "#", "")
let $end-point := $node/root()//tei:anchor[@xml:id = $end-point-id]
return
if($node[. >> $section-marker and . << $end-point]) then
()
else
macro-sort:copy-element($node)
};
declare function macro-sort:copy-element($node as element(*)) as element(*) {
element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
$node/@*,
macro-sort:sort($node/node())
}
};
declare function macro-sort:clear($nodes as node()*) as node()* {
for $node in $nodes return
typeswitch ($node)
case text() return
$node
case comment() return
$node
default return
if($node/@outside-section = "true") then
()
else
$node
};
......@@ -75,7 +75,7 @@ declare function prepCom:recursion($nodes as node()*) as node()* {
or contains($node, "Schlusslinie")) then
()
else
element {QName("http://www.tei-c.org/ns/1.0", "ptr")} {
element tei:ptr {
attribute type {"editorial-commentary"},
attribute subtype {"figure"}