Commit b48baaa6 authored by MRodz's avatar MRodz Committed by mrodzis
Browse files

Enhance draft for index information

parent ce8cf896
......@@ -17,6 +17,27 @@ import module namespace simpleHelpers="http://fontane-nb.dariah.eu/teisimplehelp
declare namespace map = "http://www.w3.org/2005/xpath-functions/map";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare variable $index-info:event-map :=
map:merge(for $entry in doc("/db/sade-projects/textgrid/data/xml/data/253t0.xml")//tei:event
return
map:entry(string($entry/@xml:id),
map {
"regular-name" : string-join($entry/tei:label[not(@type)], ", "),
"place" : string-join($entry/@where),
"occs-in-nbs" : ""
}
));
declare variable $index-info:org-map :=
map:merge(for $entry in doc("/db/sade-projects/textgrid/data/xml/data/253t1.xml")//tei:org
return
map:entry(string($entry/@xml:id),
map {
"regular-name" : string-join($entry/tei:orgName, ", "),
"occs-in-nbs" : ""
}
));
declare variable $index-info:place-map :=
map:merge(for $entry in doc("/db/sade-projects/textgrid/data/xml/data/253t2.xml")//tei:place
return
......@@ -28,26 +49,77 @@ declare variable $index-info:place-map :=
}
));
declare function index-info:get-full-place-ref($node as element(tei:rs)) as xs:string {
let $main-entry := local:get-main-entry($node)
declare variable $index-info:psn-map :=
map:merge(for $entry in doc("/db/sade-projects/textgrid/data/xml/data/253sx.xml")//*[self::tei:person or self::tei:personGrp]
return
map:entry(string($entry/@xml:id),
map {
"regular-name" : string-join($entry/tei:persName, ", "),
"birth" : string($entry/tei:birth),
"death" : string($entry/tei:death),
"occpuation" : string($entry/tei:occupation),
"occs-in-nbs" : ""
}
));
declare variable $index-info:wrk-map :=
map:merge(for $entry in doc("/db/sade-projects/textgrid/data/xml/data/253t3.xml")//tei:item
return
map:entry(string($entry/@xml:id),
map {
"regular-name" : string-join($entry/tei:name, ", "),
"subref-of" : string-join($entry/parent::tei:item/tei:name, ", "),
"occs-in-nbs" : ""
}
));
(: generic functions :)
declare function index-info:get-full-ref($ref as xs:string,
$index-type as xs:string) as xs:string {
let $main-entry := local:get-main-entry($ref, $index-type)
return map:get($main-entry, "regular-name")
};
declare function index-info:get-place-sub-ref($node as element(tei:rs)) as xs:string* {
let $main-entry := local:get-main-entry($node)
return map:get($main-entry, "subref-of")
declare function index-info:get-occs($ref as xs:string,
$index-type as xs:string) as xs:string* {
let $main-entry := local:get-main-entry($ref, $index-type)
return map:get($main-entry, "occs-in-nbs")
};
declare function index-info:get-place-occs($node as element(tei:rs)) as xs:string* {
let $main-entry := local:get-main-entry($node)
return map:get($main-entry, "occs-in-nbs")
(: index specific functions :)
declare function index-info:get-event-place($ref as xs:string) as xs:string {
let $main-entry := local:get-main-entry($ref, "eve")
return map:get($main-entry, "place")
};
declare function index-info:get-full-map() {
$index-info:place-map
declare function index-info:get-place-sub-ref($ref as xs:string) as xs:string* {
let $main-entry := local:get-main-entry($ref, "plc")
return map:get($main-entry, "subref-of")
};
declare function local:get-main-entry($node as element(tei:rs)) as map()* {
let $key := $node/@ref => substring-after(":")
return map:get($index-info:place-map, $key)
(: auxiliary functions :)
declare function index-info:get-full-maps() {
$index-info:wrk-map
};
declare function local:get-main-entry($ref as xs:string,
$index-type as xs:string) as map()* {
let $key := substring-after($ref, ":")
return
switch ($index-type)
case "eve" return
map:get($index-info:event-map, $key)
case "org" return
map:get($index-info:org-map, $key)
case "plc" return
map:get($index-info:place-map, $key)
case "psn" return
map:get($index-info:psn-map, $key)
case "wrk" return
map:get($index-info:wrk-map, $key)
default return ()
};
\ No newline at end of file
......@@ -637,16 +637,14 @@ declare function fontaneSimple:transform($nodes as node()*) as node()* {
fontaneSimple:copy-element($node)
case element(tei:rs) return
element tei:rs {
$node/@*,
if(matches($node/@ref, "plc")) then
(attribute full-ref {index-info:get-full-place-ref($node)},
attribute subtype-of {index-info:get-place-sub-ref($node)},
attribute occs {index-info:get-place-occs($node)})
else
(),
fontaneSimple:transform($node/node())
}
let $index-type := substring-before($node/@ref, ":")
let $bla := console:log($node)
return
(element tei:rs {
$node/@*,
fontaneSimple:make-index-attributes($node, $index-type),
fontaneSimple:transform($node/node())
}, console:log(fontaneSimple:transform($node/node())))
case element(tei:date) return
element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
......@@ -875,4 +873,29 @@ as xs:boolean {
some $prev in $node/preceding::*[@next]
satisfies contains($prev/@next, $node/descendant::*/@xml:id)
or contains($prev/@next, $node/following::*/@xml:id)
};
declare function fontaneSimple:make-index-attributes($node as element(tei:rs),
$index-type as xs:string) as attribute()* {
let $refs := tokenize($node/@ref, " ")
let $no-of-refs := count($refs)
return
for $iii in 1 to $no-of-refs
let $ref := $refs[$iii]
return
(attribute {"full-ref-" || $iii} {index-info:get-full-ref($ref, $index-type)},
attribute {"occs-" || $iii} {index-info:get-occs($ref, $index-type)},
switch ($index-type)
case "eve" return
attribute {"place-" || $iii} {index-info:get-event-place($ref)}
case "org" return
()
case "plc" return
attribute {"subref-of-" || $iii} {index-info:get-place-sub-ref($ref)}
case "psn" return
()
case "wrk" return
()
default return
())
};
\ No newline at end of file
......@@ -6,6 +6,7 @@ xquery version "3.1";
module namespace index-info-test = "http://fontane-nb.dariah.eu/index-info-test";
import module namespace index-info ="http://fontane-nb.dariah.eu/index-info" at "../index-info.xqm";
import module namespace fontaneSimple="http://fontane-nb.dariah.eu/teisimple" at "../tei2teisimple.xqm";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace test="http://exist-db.org/xquery/xqsuite";
......@@ -19,26 +20,53 @@ declare
};
declare
%test:name("Full references")
%test:args("<rs xmlns=""http://www.tei-c.org/ns/1.0"" type=""direct"" ref=""plc:Thueringen"">ein Bundesland</rs>")
%test:name("Events: Full references")
%test:args("eve:Thesenanschlag", "eve")
%test:assertEquals("Thesenanschlag")
function index-info-test:places-full-reference($node as xs:string, $type as xs:string) {
index-info:get-full-ref($node, $type)
};
declare
%test:name("Events: Full references - transformation result")
%test:args("<rs xmlns=""http://www.tei-c.org/ns/1.0"" type=""direct"" ref=""eve:Thesenanschlag""/>")
%test:assertEquals("<rs xmlns=""http://www.tei-c.org/ns/1.0"" type=""direct"" ref=""eve:Thesenanschlag"" full-ref-1=""Thesenanschlag"" place-1=""plc:Kirche_Wittenberg"" occs-1=""""/>")
function index-info-test:places-full-reference-xml($node as element(*)) {
fontaneSimple:transform($node)
};
declare
%test:name("Events: Places")
%test:args("eve:Thesenanschlag")
%test:assertEquals("plc:Kirche_Wittenberg")
function index-info-test:places-full-reference($node as xs:string) {
index-info:get-event-place($node)
};
declare
%test:name("Places: Full references")
%test:args("plc:Thueringen", "plc")
%test:assertEquals("Thüringen")
(: entry with several variant names :)
%test:args("<rs xmlns=""http://www.tei-c.org/ns/1.0"" type=""direct"" ref=""plc:Albaner_Berge"">Berge</rs>")
%test:args("plc:Albaner_Berge", "plc")
%test:assertEquals("Albaner Berge (ital.: Colli Albani), Albanergebirge")
function index-info-test:full-reference($node as element(*)) {
index-info:get-full-place-ref($node)
function index-info-test:places-full-reference($node as xs:string, $type as xs:string) {
index-info:get-full-ref($node, $type)
};
declare
%test:name("Subreferences")
%test:args("<rs xmlns=""http://www.tei-c.org/ns/1.0"" type=""direct"" ref=""plc:Sacro_Convento_Assisi"">ein Ort</rs>")
%test:name("Places: Subreferences")
%test:args("plc:Sacro_Convento_Assisi")
%test:assertEquals("Assisi")
%test:args("<rs xmlns=""http://www.tei-c.org/ns/1.0"" type=""direct"" ref=""plc:Thueringen"">ein Bundesland</rs>")
%test:args("plc:Thueringen")
%test:assertEquals("")
function index-info-test:sub-reference($node as element(*)) {
function index-info-test:places-sub-reference($node as xs:string) {
index-info:get-place-sub-ref($node)
};
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
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