Commit 328f97c2 authored by mrodzis's avatar mrodzis 🐸
Browse files

Remove surplus modules, esp. console

parent c8d7f42d
xquery version "3.1";
(:~
(:~
: This module creates an SVG image of call graph of
:
:
: * a given module
: * the modules of a given collection
: * the modules of the whole SADE app
:
:
: A module is defined as a file that ends with '.xqm'.
: While the SVG image is stored to /db/apps/sade/modules/callgraph/svg,
: the intermediate GraphML representation of the call graph is saved to
: /db/apps/sade/modules/callgraph/graphml and could be re-used in other
: the intermediate GraphML representation of the call graph is saved to
: /db/apps/sade/modules/callgraph/graphml and could be re-used in other
: applications.
:
:
: This module was roughly inspired by the graphviz app for eXist-db which can be
: found at https://github.com/KitWallace/graphviz.
:
:
: @author Michelle Weidling
: @since v3.1.0
: @since v3.1.1
: @see https://github.com/KitWallace/graphviz
:
:
: :)
module namespace callgraph="https://sade.textgrid.de/ns/callgraph";
import module namespace config="https://sade.textgrid.de/ns/config" at "../config.xqm";
import module namespace console="http://exist-db.org/xquery/console";
import module namespace functx="http://www.functx.com";
import module namespace inspect="http://exist-db.org/xquery/inspection";
import module namespace inspect2graphml="https://sade.textgrid.de/ns/inspect2graphml" at "inspect2graphml.xqm";
......@@ -47,7 +45,7 @@ declare variable $callgraph:colors :=
: * an URI of a single module, e.g. "/db/apps/sade/modules/callgraph/tests/xqm/inspect2graphml-testmodule.xqm"
: * a collection URI, e.g. "/db/apps/sade/modules/callgraph/tests/xqm/"
: * "full" which will consider all *.xqm in the SADE app
:
:
: @author Michelle Weidling
: @since v3.1.0
: @param $option Selects the modules which should be displayed in the output SVG file
......@@ -62,17 +60,17 @@ declare function callgraph:main($option as xs:string, $filename as xs:string) as
or xmldb:collection-available($option)) then
let $filename :=
if(contains($filename, ".")) then
error( QName("https://sade.textgrid.de/ns/app", "CALLGRAPH01"),
error( QName("https://sade.textgrid.de/ns/app", "CALLGRAPH01"),
"Invalid filename '" || $filename || "'. Please enter a filename without file extension.")
else
$filename
let $dot := callgraph:get-dot($option, $filename)
let $svg-output := callgraph:get-svg($dot)
let $svg := callgraph:clear-svg($svg-output, $filename)
return "Call graph creation successfull."
else
error( QName("https://sade.textgrid.de/ns/app", "CALLGRAPH02"),
error( QName("https://sade.textgrid.de/ns/app", "CALLGRAPH02"),
"Invalid option '" || $option || "'. Please enter a base URI, a collection path or 'full' as argument.")
};
......@@ -80,7 +78,7 @@ declare function callgraph:main($option as xs:string, $filename as xs:string) as
(:~
: Gets a DOT representation of the given module, the modules of a collection or
: all modules of the SADE app.
:
:
: @author Michelle Weidling
: @since v3.1.0
: @see https://en.wikipedia.org/wiki/DOT_(graph_description_language)
......@@ -89,32 +87,32 @@ declare function callgraph:main($option as xs:string, $filename as xs:string) as
: @error GraphML couldn't be transformed to DOT
: @error The DOT file is empty
: :)
declare function callgraph:get-dot($option as xs:string, $filename as xs:string)
declare function callgraph:get-dot($option as xs:string, $filename as xs:string)
as xs:string {
let $graphml := inspect2graphml:main($option, $filename)
let $dot :=
try {
(: $graphml[1] is graphml:graphml,
(: $graphml[1] is graphml:graphml,
$graphml[2] is path to stored XML :)
callgraph:transform2dot($graphml[1])
=> string-join("")
} catch * {
error( QName("https://sade.textgrid.de/ns/app", "CALLGRAPH03"),
error( QName("https://sade.textgrid.de/ns/app", "CALLGRAPH03"),
"Could not transform GraphML to DOT.")
}
return
if(normalize-space($dot) != "") then
$dot
else
error( QName("https://sade.textgrid.de/ns/app", "CALLGRAPH04"),
"DOT file is empty.")
error( QName("https://sade.textgrid.de/ns/app", "CALLGRAPH04"),
"DOT file is empty.")
};
(:~
: Transforms the given GraphML elements to DOT.
:
:
: @author Michelle Weidling
: @since v3.1.0
: @see https://en.wikipedia.org/wiki/DOT_(graph_description_language)
......@@ -124,12 +122,12 @@ as xs:string {
declare function callgraph:transform2dot($nodes as element()*) as node()* {
for $node in $nodes return
typeswitch ($node)
case element(graphml:graphml) return
(text{"digraph g {"},
callgraph:transform2dot($node/node()),
text{"}"})
case element(graphml:graph) return
if($node/@id = "base-graph") then
callgraph:transform2dot($node/node())
......@@ -138,7 +136,7 @@ declare function callgraph:transform2dot($nodes as element()*) as node()* {
text{$callgraph:colors[count($node/preceding::graphml:graph) + 1]},
text{"""];"},
callgraph:transform2dot($node/node()))
case element(graphml:node) return
if($node/parent::graphml:graph[@id = "base-graph"]) then
callgraph:transform2dot($node/node())
......@@ -146,7 +144,7 @@ declare function callgraph:transform2dot($nodes as element()*) as node()* {
(text{""""},
text{$node/@id},
text{""" [shape=box];"})
case element(graphml:edge) return
(text{""""},
text{$node/@source},
......@@ -155,7 +153,7 @@ declare function callgraph:transform2dot($nodes as element()*) as node()* {
text{""""},
text{$node/@target},
text{""";"})
default return
callgraph:transform2dot($node/node())
};
......@@ -164,7 +162,7 @@ declare function callgraph:transform2dot($nodes as element()*) as node()* {
(:~
: Creates an SVG file based of a given DOT file.
:
:
: @author Michelle Weidling
: @since v3.1.0
: @see https://en.wikipedia.org/wiki/DOT_(graph_description_language)
......@@ -182,19 +180,19 @@ declare function callgraph:get-svg($dot as xs:string) as element(line)+ {
<workingDir>{$target-dir}</workingDir>
<stdin><line>{$dot}</line></stdin>
</options>
let $output :=
let $output :=
try {
process:execute(($cmd, "-Tsvg"), $options)
} catch * {
error( QName("https://sade.textgrid.de/ns/app", "CALLGRAPH05"),
"Could not transform the given DOT file to SVG.")
error( QName("https://sade.textgrid.de/ns/app", "CALLGRAPH05"),
"Could not transform the given DOT file to SVG.")
}
return
if($output//stdout/line) then
$output
else
error( QName("https://sade.textgrid.de/ns/app", "CALLGRAPH06"),
"SVG output empty.")
error( QName("https://sade.textgrid.de/ns/app", "CALLGRAPH06"),
"SVG output empty.")
};
......@@ -202,7 +200,7 @@ declare function callgraph:get-svg($dot as xs:string) as element(line)+ {
: Since the output of callgraph:get-svg consists of multiple line elements that
: contain the XML representation of the SVG, this function extracts the SVG data
: and creates a valid SVG file.
:
:
: @author Michelle Weidling
: @since v3.1.0
: @param $svg Multiple line elements that hold the SVG data
......@@ -212,10 +210,10 @@ declare function callgraph:get-svg($dot as xs:string) as element(line)+ {
declare function callgraph:clear-svg($svg as element(execution), $filename as
xs:string) as xs:string {
let $lines := $svg//line
let $content :=
let $content :=
for $line in subsequence($lines, 7) return
$line/string()
let $cleared-svg := string-join($content, "")
return
xmldb:store($config:app-root || "/modules/callgraph/svg/", $filename || ".svg", $cleared-svg)
};
\ No newline at end of file
};
xquery version "3.1";
(:~
(:~
: This module creates a GraphML representation of one or more given modules or
: even the whole SADE app. To achieve this we take the information retrieved by
: inspect:inspect-module and convert the relevant nodes to GraphML.
:
: The process was roughly inspired by the graphviz app for eXist-db which can
:
: The process was roughly inspired by the graphviz app for eXist-db which can
: be found at https://github.com/KitWallace/graphviz.
:
:
: @author Michelle Weidling
: @since v3.1.0
: @since v3.1.1
: @see https://github.com/KitWallace/graphviz
: @see http://graphml.graphdrawing.org/specification.html
:
:
: :)
module namespace inspect2graphml="https://sade.textgrid.de/ns/inspect2graphml";
import module namespace config="https://sade.textgrid.de/ns/config" at "../config.xqm";
import module namespace console="http://exist-db.org/xquery/console";
import module namespace functx="http://www.functx.com";
import module namespace inspect="http://exist-db.org/xquery/inspection";
declare namespace graphml="http://graphml.graphdrawing.org/xmlns";
......@@ -28,14 +26,14 @@ declare namespace xsi="http://www.w3.org/2001/XMLSchema-instance";
(:~
: The interface for other modules.
:
:
: @author Michelle Weidling
: @since v3.1.0
: @param $option Selects the modules which should be displayed in the output SVG file (cf. callgraph:main for valid options)
: @return The graph representation as element(graphml:graphml)
: @return The path to the stored GraphML file
: :)
declare function inspect2graphml:main($option as xs:string, $filename
declare function inspect2graphml:main($option as xs:string, $filename
as xs:string) as item()+ {
let $graphml := inspect2graphml:get-graphml($option)
return
......@@ -45,14 +43,14 @@ as xs:string) as item()+ {
(:~
: Creates a GraphML representation of one or more given modules or even the
: Creates a GraphML representation of one or more given modules or even the
: whole SADE app.
:
:
: @author Michelle Weidling
: @since v3.1.0
: @param $option Selects the modules which should be displayed in the output SVG file (cf. callgraph:main for valid options)
: :)
declare function inspect2graphml:get-graphml($option as xs:string) as
declare function inspect2graphml:get-graphml($option as xs:string) as
element(graphml:graphml) {
let $xqms := inspect2graphml:get-xqms($option)
return
......@@ -63,7 +61,7 @@ element(graphml:graphml) {
let $transformed-subgraph := inspect2graphml:transform($inspect-result, true())
return local:sort-edges-and-nodes($transformed-subgraph)
}
else
element graphml:graphml {
attribute xsi:schemaLocation {"http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd"},
......@@ -73,7 +71,7 @@ element(graphml:graphml) {
for $xqm in $xqms return
let $inspect-result := inspect:inspect-module(xs:anyURI($xqm))
let $transformed-subgraph := inspect2graphml:transform($inspect-result, false())
return
element graphml:node {
attribute id {util:hash($xqm, "md5")},
......@@ -87,7 +85,7 @@ element(graphml:graphml) {
(:~
: Transforms the relevant nodes that have been generated by inspect:inspect-module
: to GraphML elements.
:
:
: @author Michelle Weidling
: @since v3.1.0
: @param $nodes The nodes that are the result of inspect:inspect-module
......@@ -97,18 +95,18 @@ element(graphml:graphml) {
declare function inspect2graphml:transform($nodes as node()*, $single-module as xs:boolean) as node()* {
for $node in $nodes return
typeswitch ($node)
case element(module) return
element graphml:graph {
attribute id {$node/@prefix},
attribute edgedefault {"directed"},
inspect2graphml:transform($node/node(), $single-module)
}
case element(function) return
(local:make-node($node),
inspect2graphml:transform($node/node(), $single-module))
case element(calls) return
let $source-function := $node/ancestor::function[1]
let $prefix := substring-before($source-function/@name, ":")
......@@ -123,7 +121,7 @@ declare function inspect2graphml:transform($nodes as node()*, $single-module as
local:make-node($called)
else
())
default return
()
};
......@@ -131,7 +129,7 @@ declare function inspect2graphml:transform($nodes as node()*, $single-module as
(:~
: Gets all relevant *.xqm files.
:
:
: @author Michelle Weidling
: @since v3.1.0
: @param $option Selects the modules which should be displayed in the output SVG file (cf. callgraph:main for valid options)
......@@ -140,7 +138,7 @@ declare function inspect2graphml:transform($nodes as node()*, $single-module as
declare function inspect2graphml:get-xqms($option as xs:string) as xs:string* {
switch ($option)
case "full" return (collection($config:app-root)/base-uri())[ends-with(., ".xqm")]
default return
if(ends-with($option, ".xqm")) then
$option
......@@ -155,7 +153,7 @@ declare function inspect2graphml:get-xqms($option as xs:string) as xs:string* {
(:~
: Creates a graphml:node element.
:
:
: @author Michelle Weidling
: @since v3.1.0
: @param $node The current result node of inspect:inspect-module
......@@ -169,12 +167,12 @@ declare function local:make-node($node as node()) as element(graphml:node) {
(:~
: As the output of inspect2graphml:transform mixes up graphml:node and
: As the output of inspect2graphml:transform mixes up graphml:node and
: graphml:edge, this function sorts them: We want all graphml:node to be listed
: first, followed by all graphml:edge elements. The order depend on the node ID
: and the source and target attribute respectively.
:
:
:
:
: @author Michelle Weidling
: @since v3.1.0
: @param $graph A (sub-)graph with nodes and edges
......@@ -191,4 +189,4 @@ as element(graphml:graph) {
order by $edge/@source, $edge/@target
return $edge
}
};
\ No newline at end of file
};
......@@ -2,7 +2,6 @@ xquery version "3.1";
module namespace fsearch="https://sade.textgrid.de/ns/faceted-search";
import module namespace config="https://sade.textgrid.de/ns/config" at "config.xqm";
import module namespace console="http://exist-db.org/xquery/console";
import module namespace kwic="http://exist-db.org/xquery/kwic";
declare namespace bol="http://blumenbach-online.de/blumenbachiana";
......@@ -146,8 +145,7 @@ declare function fsearch:result-kwic($node as node(), $model as map(*)) {
for $i in 1 to xs:integer(config:get("kwic-hits", "faceted-search"))
return
if(($expanded//exist:match)[$i]) then
let $summary := kwic:get-summary($expanded, ($expanded//exist:match)[$i], <config width="{$kwic-width}"/>),
$console := console:log($summary)
let $summary := kwic:get-summary($expanded, ($expanded//exist:match)[$i], <config width="{$kwic-width}"/>)
return
<p class="kwic"><span class="kwic-prev">{$summary/span[@class="previous"]/node()}</span> <span class="kwic-hit">{$summary/span[@class="hi"]/node()}</span> <span>{$summary/span[@class="following"]/node()}</span></p>
else ()
......
......@@ -3,9 +3,7 @@ xquery version "3.1";
module namespace lang="https://sade.textgrid.de/ns/lang";
import module namespace app="https://sade.textgrid.de/ns/app" at "app.xqm";
import module namespace functx="http://www.functx.com";
import module namespace config="https://sade.textgrid.de/ns/config" at "config.xqm";
import module namespace console="http://exist-db.org/xquery/console";
declare namespace lf="https://sade.textgrid.de/ns/langfile";
......@@ -24,7 +22,7 @@ declare function local:switchLanguage($to) as xs:string {
declare function local:multiLangSwitcher($langconfig, $lang) as node(){
let $test := "test"
return element a {
return element a {
attribute href {local:switchLanguage($lang)},
$langconfig//lf:word[@key="Language"]/lf:lang[@key=$lang]
}
......
Supports Markdown
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