Commit 63dce65c authored by mrodzis's avatar mrodzis 🌿 Committed by Mathias Goebel
Browse files

Feature/#91-automatically-create-edited-text

parent 8c8f5d93
......@@ -29,11 +29,11 @@ import module namespace tidySimple ="http://fontane-nb.dariah.eu/tidysimple" at
declare variable $etTransfo:cases :=
(
(: "3qtcz.xml", (: case C :):)
"3qtqv.xml" (: case A :)
(: "3qtqw.xml" (: case B :) :)
(: "3qtqx.xml" (: case D :):)
(: "3qtqz.xml" (: case E :):)
"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/";
......@@ -56,7 +56,8 @@ declare function etTransfo:complete() {
} catch * {
error(QName("error", "ETTRANSFO02"), "An error occured while creating the whole TEI base for print.")
},
etTransfo:tidy-logs()
etTransfo:tidy-logs(),
etTransfo:report-errors()
};
......@@ -74,6 +75,10 @@ declare function etTransfo:create-case($showcase as xs:string) as xs:string {
} catch * {
error(QName("error", "ETTRANSFO03"), "An error occured while opening " || $showcase || ".")
}
let $log := etTransfo:create-log($doc//tei:title[1] => replace(" ", "-"))
let $log := util:log-system-out("Start creating case " || $showcase || " (" || $doc//tei:title[1] || ").")
let $new-filename := $doc//tei:title[1] => replace(" ", "-") || ".xml"
let $assure-dir-available :=
if(xmldb:collection-available($config:data-root || "/print/")) then
......@@ -93,7 +98,7 @@ declare function etTransfo:create-case($showcase as xs:string) as xs:string {
try {
doc("/db/sade-projects/textgrid/data/xml/data/" || $uri || ".xml")/tei:TEI
} catch * {
error(QName("error", "ETTRANSFO04"), "Couldn't find the node tei:TEI of " || $uri || ".")
etTransfo:add-log-entry($log, "ETTRANSFO04: Couldn't find the node tei:TEI of " || $uri || ".")
}
let $updated-notebook :=
element tei:TEI {
......@@ -115,18 +120,16 @@ declare function etTransfo:create-case($showcase as xs:string) as xs:string {
: @param $showcase The filename of a showcase, e.g. "12345.xml"
: @return All notebooks of a showcase in-memory, i.e. a sequence of tei:TEI
:)
declare function etTransfo:get-teis($showcase as xs:string) as element(tei:TEI)+ {
declare function etTransfo:get-teis($showcase as xs:string) as element(tei:TEI)* {
let $doc := doc("/db/sade-projects/textgrid/data/xml/data/" || $showcase)
let $summary-file-name := $doc//tei:title[1] => replace(" ", "-") || ".xml"
let $summary-file :=
let $log := doc($etTransfo:dir || "logs/" || $doc//tei:title[1] => replace(" ", "-") || "-log.xml")
return
try {
doc($config:data-root || "/print/xml/" || $summary-file-name)
doc($config:data-root || "/print/xml/" || $summary-file-name)//tei:TEI
} catch * {
error(QName("error", "ETTRANSFO04"), "Summary file for case " || $showcase || "couldn't be opened.")
etTransfo:add-log-entry($log, "ETTRANSFO05: Summary file for case " || $showcase || "couldn't be opened.")
}
return
$summary-file//tei:TEI
};
......@@ -137,13 +140,18 @@ declare function etTransfo:get-teis($showcase as xs:string) as element(tei:TEI)+
: @param $showcase The filename of a showcase, e.g. "12345.xml"
: @return One or more strings indicating the location where the XHTML(s) have been stored to.
:)
declare function etTransfo:create-htmls($showcase as xs:string) as xs:string+ {
declare function etTransfo:create-htmls($showcase as xs:string) as xs:string* {
let $teis := etTransfo:get-teis($showcase)
for $tei in $teis return
let $log := util:log-system-out("Start creating edited text for " || $tei//tei:idno[@type = "TextGrid"])
let $log := etTransfo:create-log(substring-after($tei//tei:idno[@type = "TextGrid"], "textgrid:"))
return
etTransfo:transform-tei($tei, $log)
try {
etTransfo:transform-tei($tei, $log)
} catch * {
etTransfo:add-log-entry($log, "ETTRANSFO08: Couldn't transform TEI. ")
}
};
......@@ -156,11 +164,40 @@ declare function etTransfo:create-htmls($showcase as xs:string) as xs:string+ {
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, $log)
=> tidySimple:main($tei/@id)
=> simple2xhtml:main($tei/@id)
let $sorted :=
try {
fsort:main($tei, $log)
} catch * {
etTransfo:add-log-entry($log, "ETTRANSFO09: Error while sorting this notebook. ")
}
let $prepare-comment :=
try {
prepCom:main($sorted, $tei/@id)
} catch * {
etTransfo:add-log-entry($log, "ETTRANSFO10: Error while preparing commentary for this notebook. ")
}
let $transform-to-interform :=
try {
fontaneSimple:main($prepare-comment, $tei/@id, $log)
} catch * {
etTransfo:add-log-entry($log, "ETTRANSFO11: Error while transforming this notebook to an intermediate format. ")
}
let $tidy-interform :=
try {
tidySimple:main($transform-to-interform, $tei/@id)
} catch * {
etTransfo:add-log-entry($log, "ETTRANSFO12: Error while tidying up the intermediate format for this notebook. ")
}
return
try {
simple2xhtml:main($tidy-interform, $tei/@id)
} catch * {
etTransfo:add-log-entry($log, "ETTRANSFO13: Error while creating XHTML for this notebook. ")
}
};
......@@ -173,19 +210,20 @@ declare function etTransfo:transform-tei($tei as element(tei:TEI), $log as xs:st
:)
declare function etTransfo:create-print-tei() as xs:string {
let $xmls := etTransfo:get-all-xmls()
let $log := etTransfo:create-log("general-print-creation")
let $complete-print-file :=
element {QName("http://www.tei-c.org/ns/1.0", "teiCorpus")} {
$xmls,
try {
etTransfo:get-literature()
} catch * {
error(QName("error", "ETTRANSFO06"), "An error occured while creating the bibliography.")
etTransfo:add-log-entry($log, "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.")
etTransfo:add-log-entry($log, "ETTRANSFO07: An error occured while creating the index of abbreviations.")
}
}
return
......@@ -329,6 +367,13 @@ declare function etTransfo:assure-dir-available($dir-name as xs:string) {
};
declare function etTransfo:add-log-entry($log-file as xs:string,
$message as xs:string) as empty-sequence() {
let $entry := <LogEntry timestamp="{util:system-time()}">{$message}</LogEntry>
return update insert $entry into doc($log-file)/*
};
(:~
: Only the logs which acutally contain info should be kept.
:
......@@ -342,3 +387,23 @@ declare function etTransfo:tidy-logs() {
return
xmldb:remove($etTransfo:dir || "logs/", $uri)
};
declare function etTransfo:report-errors() as item()* {
let $log-path := $etTransfo:dir || "logs/"
return
if(xmldb:get-child-resources($log-path) = "") then
util:log-system-out("No errors found while creating the edited text! Yay!")
else
(
util:log-system-out("Errors detected in the following notebooks:"),
for $log in collection($log-path) return
(
util:log-system-out("*&#8195;" ||
substring-after(base-uri($log), "logs/")
=> substring-before("-log")),
util:log-system-out($log)
),
util:log-system-out("Total: " || count(xmldb:get-child-resources($log-path)) || " notebook(s).")
)
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment